OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05i18n
[pettanr/pettanr.git] / spec / models / speech_balloon_template_spec.rb
index 18b4352..e0f4e88 100644 (file)
@@ -15,12 +15,12 @@ describe SpeechBalloonTemplate do
     @jes = JSON.parse @tes
     
     @admin = FactoryGirl.create :admin
-    @user = FactoryGirl.create( :user_yas)\r
-    @author = @user.author\r
-    @artist = FactoryGirl.create :artist_yas, :author_id => @author.id\r
-    @other_user = FactoryGirl.create( :user_yas)\r
-    @other_author = @other_user.author\r
-    @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
+    @user = FactoryGirl.create( :user_yas)
+    @author = FactoryGirl.create :author, :user_id => @user.id
+    @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
+    @other_user = FactoryGirl.create( :user_yas)
+    @other_author = FactoryGirl.create :author, :user_id => @other_user.id
+    @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
   end
   
   describe '検証に於いて' do
@@ -126,28 +126,37 @@ describe SpeechBalloonTemplate do
       @st.overwrite
       @st.t.should eq 2
     end
+    context 'つつがなく終わるとき' do
+      before do
+        @st = FactoryGirl.create :speech_balloon_template, :t => 0
+      end
+      it '更新のときは補充しない' do
+        @st.overwrite
+        @st.t.should eq 0
+      end
+    end
   end
   
   describe '閲覧許可に於いて' do
     before do
       @st = FactoryGirl.build :speech_balloon_template
     end
-    it '許可する' do\r
+    it '許可する' do
       @st.visible?(@author).should == true
-    end\r
+    end
   end
   
   describe '一覧取得に於いて' do
     before do
       @st = FactoryGirl.create :speech_balloon_template
     end
-    context 'つつがなく終わるとき' do\r
-      it '一覧取得オプションを利用している' do\r
-        SpeechBalloonTemplate.stub(:list_opt).with(any_args).and_return({})\r
-        SpeechBalloonTemplate.should_receive(:list_opt).with(any_args).exactly(1)\r
+    context 'つつがなく終わるとき' do
+      it '一覧取得オプションを利用している' do
+        SpeechBalloonTemplate.stub(:list_opt).with(any_args).and_return({})
+        SpeechBalloonTemplate.should_receive(:list_opt).with(any_args).exactly(1)
         r = SpeechBalloonTemplate.list
-      end\r
-    end\r
+      end
+    end
     it 'リストを返す' do
       l = SpeechBalloonTemplate.list
       l.should eq [@st]
@@ -177,13 +186,13 @@ describe SpeechBalloonTemplate do
     before do
       @st = FactoryGirl.create :speech_balloon_template
     end
-    context 'つつがなく終わるとき' do\r
-      it '単体取得オプションを利用している' do\r
-        SpeechBalloonTemplate.stub(:show_opt).with(any_args).and_return({})\r
-        SpeechBalloonTemplate.should_receive(:show_opt).with(any_args).exactly(1)\r
+    context 'つつがなく終わるとき' do
+      it '単体取得オプションを利用している' do
+        SpeechBalloonTemplate.stub(:show_opt).with(any_args).and_return({})
+        SpeechBalloonTemplate.should_receive(:show_opt).with(any_args).exactly(1)
         r = SpeechBalloonTemplate.show @st.id, @author
-      end\r
-    end\r
+      end
+    end
     it '指定のフキダシテンプレートを返す' do
       l = SpeechBalloonTemplate.show @st.id, @author
       l.should eq @st
@@ -196,13 +205,13 @@ describe SpeechBalloonTemplate do
         }.should raise_error(ActiveRecord::Forbidden)
       end
     end
-    context '存在しないフキダシテンプレートを開こうとしたとき' do\r
-      it '404RecordNotFound例外を返す' do\r
-        lambda{\r
-          SpeechBalloonTemplate.show 110, @author\r
-        }.should raise_error(ActiveRecord::RecordNotFound)\r
-      end\r
-    end\r
+    context '存在しないフキダシテンプレートを開こうとしたとき' do
+      it '404RecordNotFound例外を返す' do
+        lambda{
+          SpeechBalloonTemplate.show 110, @author
+        }.should raise_error(ActiveRecord::RecordNotFound)
+      end
+    end
   end
   describe '単体出力オプションに於いて' do
     it '空のHashを返す' do
@@ -219,97 +228,29 @@ describe SpeechBalloonTemplate do
     end
   end
   
-  describe '拡張データ補充に於いて' do
-    #置換まわりが破壊的でテストしにくいので、外部と連携したテストが多い。
-    #特にシステム画像データはidを直接記述して置換させないようにテストしている。
-    before do
-      @sp = FactoryGirl.create :system_picture
-      @st = FactoryGirl.build :speech_balloon_template
-      @templates = {
-        "one" => {"balloon" => {"system_picture" => 'BASE64'}}
-      }
-      @sp_replaced_templates = {
-        "one" => {"balloon" => {"system_picture_id" => @sp.id}}
-      }
-      @attr = {"classname" => 'store', "caption" => 'store test',
-        "templates" => @templates
-      }
-      @sp_replaced_attr = {"classname" => 'store', "caption" => 'store test',
-        "templates" => @sp_replaced_templates
-      }
-    end
-    context '事前チェック' do
-      it 'システム画像置換に依頼して、テキストの画像データをシステム画像idに置換している' do
-        SpeechBalloonTemplate.stub(:replace_system_picture).with(any_args).and_return(true)
-        SpeechBalloonTemplate.should_receive(:replace_system_picture).exactly(1)
-        r = SpeechBalloonTemplate.templates_json_from @attr
-      end
-    end
-    context 'つつがなく終わるとき' do
-      before do
-      end
-      it 'templates以下をjsonテキスト化して返す' do
-        r = SpeechBalloonTemplate.templates_json_from @sp_replaced_attr
-        r.should eq @sp_replaced_templates.to_json.to_s
-      end
-    end
-    context 'システム画像の作成に失敗したとき' do
-      before do
-        SpeechBalloonTemplate.stub(:replace_system_picture).with(any_args).and_return(false)
-      end
-      it 'nilを返す' do
-        r = SpeechBalloonTemplate.templates_json_from @attr
-        r.should be_nil
-      end
-    end
-    context 'カラム値にtemplatesがないとき' do
-      before do
-        @attr.delete "templates"
-        SpeechBalloonTemplate.stub(:replace_system_picture).with(any_args).and_return(true)
-      end
-      it '{}をjsonテキスト化して返す' do
-        r = SpeechBalloonTemplate.templates_json_from @attr
-        r.should eq '{}'
-      end
-    end
-    context 'templateにballoonがないとき' do
-      before do
-        @templates = {
-          "one" => {}
-        }
-        @attr = {"classname" => 'store', "caption" => 'store test',
-          "templates" => @templates
-        }
-      end
-      it 'templates以下をjsonテキスト化してを返す' do
-        r = SpeechBalloonTemplate.templates_json_from @attr
-        r.should eq @templates.to_json.to_s
-      end
-    end
-  end
-  
   describe '更新に於いて' do
     #置換まわりが破壊的でテストしにくいので、外部と連携したテストが多い。
     #特にシステム画像データはidを直接記述して置換させないようにテストしている。
     before do
       @sp = FactoryGirl.create :system_picture
       @st = FactoryGirl.create :speech_balloon_template
-      @templates = {
+      @settings = {
+        "speech_balloon" => {"default" => 1}, 
         "one" => {"balloon" => {"system_picture_id" => @sp.id}}
       }
       @attr = {"classname" => 'store', "caption" => 'store test',
-        "templates" => @templates
+        "settings" => @settings
       }
     end
     context '事前チェック' do
       before do
-        SpeechBalloonTemplate.stub(:templates_json_from).with(any_args).and_return('{}')
+        SpeechBalloonTemplate.stub(:replace_system_picture).with(@settings).and_return(@settings)
         SpeechBalloonTemplate.stub(:modify_object).with(any_args).and_return(@st)
         SpeechBalloonTemplate.any_instance.stub(:overwrite).with(any_args).and_return(true)
         SpeechBalloonTemplate.any_instance.stub(:save).with(any_args).and_return(true)
       end
-      it 'ã\83\86ã\83³ã\83\97ã\83¬ã\83¼ã\83\88æ\8b¡å¼µã\83\87ã\83¼ã\82¿ç½®æ\8f\9bã\81«å\95\8fã\81\84å\90\88ã\82\8fã\81\9bている' do
-        SpeechBalloonTemplate.should_receive(:templates_json_from).exactly(1)
+      it 'ã\82·ã\82¹ã\83\86ã\83 ç\94»å\83\8fç½®æ\8f\9bã\81«ä¾\9dé ¼ã\81\97ている' do
+        SpeechBalloonTemplate.should_receive(:replace_system_picture).with(@settings).exactly(1)
         r = SpeechBalloonTemplate.store 'circle_v01', @attr
       end
       it 'インポート処理のデータ更新準備に依頼している' do
@@ -330,7 +271,7 @@ describe SpeechBalloonTemplate do
       end
       it 'カラム値のsettingsをセットしている' do
         r = SpeechBalloonTemplate.store 'circle_v01', @attr
-        r.settings.should eq @templates.to_json.to_s
+        r.settings.should eq @settings.to_json.to_s
       end
       it 'モデルが作成されている' do
         lambda {