OSDN Git Service

merge v04
[pettanr/pettanr.git] / spec / models / original_picture_spec.rb
index dd685ea..333fd64 100644 (file)
@@ -10,7 +10,9 @@ describe OriginalPicture do
     @other_user = Factory( :user_yas)
     @other_author = @other_user.author
     @other_artist = Factory :artist_yas, :author_id => @other_author.id
-    @license = Factory :license
+    @sp = Factory :system_picture
+    @lg = Factory :license_group
+    @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
   end
   
   describe '検証に於いて' do
@@ -18,13 +20,13 @@ describe OriginalPicture do
     end
     
     it 'オーソドックスなデータなら通る' do
-      @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+      @op = Factory.build :original_picture, :artist_id => @artist.id
       @op.should be_valid
     end
     
     context 'extを検証するとき' do
       before do
-        @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+        @op = Factory.build :original_picture, :artist_id => @artist.id
       end
       it 'テストデータの確認' do
         @op.ext = 'jpeg'
@@ -45,7 +47,7 @@ describe OriginalPicture do
     end
     context 'widthを検証するとき' do
       before do
-        @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+        @op = Factory.build :original_picture, :artist_id => @artist.id
       end
       it 'テストデータの確認' do
         @op.width = 1
@@ -70,7 +72,7 @@ describe OriginalPicture do
     end
     context 'heightを検証するとき' do
       before do
-        @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+        @op = Factory.build :original_picture, :artist_id => @artist.id
       end
       it 'テストデータの確認' do
         @op.height = 1
@@ -95,7 +97,7 @@ describe OriginalPicture do
     end
     context 'filesizeを検証するとき' do
       before do
-        @op = Factory.build :original_picture, :artist_id => @artist.id, :license_id => @license.id
+        @op = Factory.build :original_picture, :artist_id => @artist.id
       end
       it 'テストデータの確認' do
         @op.filesize = 1
@@ -120,7 +122,7 @@ describe OriginalPicture do
     end
     context 'artist_idを検証するとき' do
       before do
-        @op = Factory.build :original_picture, :license_id => @license.id
+        @op = Factory.build :original_picture
       end
       it 'テストデータの確認' do
         @op.artist_id = @artist.id
@@ -139,27 +141,6 @@ describe OriginalPicture do
         @op.should_not be_valid
       end
     end
-    context 'license_idを検証するとき' do
-      before do
-        @op = Factory.build :original_picture, :artist_id => @artist.id
-      end
-      it 'テストデータの確認' do
-        @op.license_id = @license.id
-        @op.should be_valid
-      end
-      it 'nullなら失敗する' do
-        @op.license_id = nil
-        @op.should_not be_valid
-      end
-      it '数値でなければ失敗する' do
-        @op.license_id = 'a'
-        @op.should_not be_valid
-      end
-      it '存在するlicenseでなければ失敗する' do
-        @op.license_id = 0
-        @op.should_not be_valid
-      end
-    end
   end
   
   describe 'データ補充に於いて' do
@@ -197,18 +178,6 @@ describe OriginalPicture do
       pic = OriginalPicture.show @op.id, @artist
       pic.should eq @op
     end
-    context '関連テーブルオプションがないとき' do
-      it 'ライセンスと素材を含んでいる' do
-        r = OriginalPicture.show_include_opt
-        r.should eq [:license, :resource_picture]
-      end
-    end
-    context '関連テーブルオプションで絵師を含ませたとき' do
-      it 'ライセンスと素材と作者データを含んでいる' do
-        r = OriginalPicture.show_include_opt(:include => :artist)
-        r.should eq [:license, :resource_picture, :artist]
-      end
-    end
     context '他人の原画を開こうとしたとき' do
       it '403Forbidden例外を返す' do
         lambda{
@@ -232,18 +201,6 @@ describe OriginalPicture do
       pic = OriginalPicture.edit @op.id, @artist
       pic.should eq @op
     end
-    context '関連テーブルオプションがないとき' do
-      it 'ライセンスと素材を含んでいる' do
-        r = OriginalPicture.show_include_opt
-        r.should eq [:license, :resource_picture]
-      end
-    end
-    context '関連テーブルオプションで絵師を含ませたとき' do
-      it 'ライセンスと素材と作者データを含んでいる' do
-        r = OriginalPicture.show_include_opt(:include => :artist)
-        r.should eq [:license, :resource_picture, :artist]
-      end
-    end
     context '他人の原画を開こうとしたとき' do
       it '403Forbidden例外を返す' do
         lambda{
@@ -260,10 +217,18 @@ describe OriginalPicture do
     end
   end
   describe 'json単体出力オプションに於いて' do
-    it 'includeキーがライセンスと素材を含んでいる' do
-      r = OriginalPicture.show_json_include_opt
-      r[:include].should eq [:license, :resource_picture]
-    end
+    it 'includeキーを含んでいる' do\r
+      r = OriginalPicture.show_json_include_opt\r
+      r.has_key?(:include).should be_true\r
+    end\r
+    it '1つの項目を含んでいる' do\r
+      r = OriginalPicture.show_json_include_opt[:include]\r
+      r.should have(1).items\r
+    end\r
+    it '素材を含んでいる' do\r
+      r = OriginalPicture.show_json_include_opt[:include]\r
+      r.has_key?(:resource_picture).should be_true\r
+    end\r
   end
   describe '一覧取得に於いて' do
     before do
@@ -335,12 +300,34 @@ describe OriginalPicture do
       end
     end
   end
-  describe 'json一覧出力オプションに於いて' do
-    it 'includeキーがライセンスと素材を含んでいる' do
-      r = OriginalPicture.list_json_opt
-      r[:include].should eq [:license, :resource_picture]
-    end
+  describe 'list関連テーブルプションに於いて' do\r
+    it 'includeキーを含んでいる' do\r
+      r = OriginalPicture.list_opt\r
+      r.has_key?(:include).should be_true\r
+    end\r
+    it '1つの項目を含んでいる' do\r
+      r = OriginalPicture.list_opt[:include]\r
+      r.should have(1).items\r
+    end\r
+    it '素材を含んでいる' do\r
+      r = OriginalPicture.list_opt[:include]\r
+      r.has_key?(:resource_picture).should be_true\r
+    end\r
   end
+  describe 'json一覧出力オプションに於いて' do\r
+    it 'includeキーを含んでいる' do\r
+      r = OriginalPicture.list_json_opt\r
+      r.has_key?(:include).should be_true\r
+    end\r
+    it '1つの項目を含んでいる' do\r
+      r = OriginalPicture.list_json_opt[:include]\r
+      r.should have(1).items\r
+    end\r
+    it '素材を含んでいる' do\r
+      r = OriginalPicture.list_json_opt[:include]\r
+      r.has_key?(:resource_picture).should be_true\r
+    end\r
+  end\r
   describe 'RMagick変換に於いて' do
     before do
       @op = Factory.build :original_picture, :artist_id => @artist.id
@@ -390,31 +377,22 @@ describe OriginalPicture do
         OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
         OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)\r
         PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
-        ResourcePicture.any_instance.stub(:store).with(any_args).and_return(true)
       end
       it 'RMagick変換を依頼している' do
         OriginalPicture.any_instance.should_receive(:data_to_mgk).exactly(1)
-        @op.store 'bindata', @artist, @license.id\r
+        @op.store 'bindata', @artist\r
       end
       it '自身に属性をセットしている' do
         OriginalPicture.any_instance.should_receive(:attributes=).exactly(1)
-        @op.store 'bindata', @artist, @license.id\r
+        @op.store 'bindata', @artist\r
       end
       it '自身が保存されている' do
         OriginalPicture.any_instance.should_receive(:save).exactly(1)\r
-        @op.store 'bindata', @artist, @license.id\r
+        @op.store 'bindata', @artist\r
       end
       it 'PictureIoに画像データの保存を依頼している' do
         PictureIO::LocalPicture.any_instance.should_receive(:put).with(any_args).exactly(1)
-        @op.store 'bindata', @artist, @license.id\r
-      end
-      it '素材モデルに対象素材を問い合わせている' do
-        ResourcePicture.should_receive(:update_picture).with(any_args).exactly(1)
-        @op.store 'bindata', @artist, @license.id\r
-      end
-      it '対象素材オブジェクトに保存を依頼している' do
-        ResourcePicture.any_instance.should_receive(:store).with(any_args).exactly(1)
-        @op.store 'bindata', @artist, @license.id\r
+        @op.store 'bindata', @artist\r
       end
     end
     context 'つつがなく終わるとき' do
@@ -423,24 +401,23 @@ describe OriginalPicture do
         OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
 #        OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)\r
         PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
-        ResourcePicture.any_instance.stub(:store).with(any_args).and_return(true)
       end
       it '自身に属性をセットしている' do
         lambda {
-          @op.store 'bindata', @artist, @license.id\r
+          @op.store 'bindata', @artist\r
         }.should change @op, :filesize
       end
       it '原画モデルが作成されている' do
         lambda {
-          @op.store 'bindata', @artist, @license.id
+          @op.store 'bindata', @artist
         }.should change OriginalPicture, :count
       end
       it '原画が保存されている' do
-        @op.store 'bindata', @artist, @license.id
+        @op.store 'bindata', @artist
         OriginalPicture.find(@op).should_not be_nil\r
       end
       it 'Trueを返す' do
-        @op.store('bindata', @artist, @license.id).should eq true\r
+        @op.store('bindata', @artist).should eq true\r
       end
     end
     #以下から例外ケース。処理先頭から失敗させていく
@@ -449,10 +426,11 @@ describe OriginalPicture do
         OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(false)
       end
       it 'falseを返す' do
-        @op.store('bindata', @artist, @license.id).should be_false\r
+        @op.store('bindata', @artist).should be_false\r
       end
       it '自身の保存は呼ばれていない' do
         OriginalPicture.any_instance.should_not_receive(:save)\r
+        @op.store('bindata', @artist)\r
       end
     end
     context '自身の保存に失敗したとき' do
@@ -461,10 +439,10 @@ describe OriginalPicture do
         OriginalPicture.any_instance.stub(:save).with(any_args).and_return(false)\r
       end
       it 'falseを返す' do
-        @op.store('bindata', @artist, @license.id).should be_false\r
+        @op.store('bindata', @artist).should be_false\r
       end
       it '更新されていない' do
-        @op.store('bindata', @artist, @license.id)
+        @op.store('bindata', @artist)
         @op.should be_a_new OriginalPicture\r
       end
       it '原画の保存は呼ばれていない' do
@@ -478,39 +456,19 @@ describe OriginalPicture do
         PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(false)
       end
       it 'falseを返す' do
-        @op.store('bindata', @artist, @license.id).should be_false\r
+        @op.store('bindata', @artist).should be_false\r
       end
       it '更新されていない' do
-        @op.store('bindata', @artist, @license.id)\r
+        @op.store('bindata', @artist)\r
         @op.should be_a_new OriginalPicture\r
       end
       it '対象素材オブジェクトの保存は呼ばれていない' do
         ResourcePicture.any_instance.should_not_receive(:save)\r
-        @op.store('bindata', @artist, @license.id)\r
-      end
-      it '全体エラーメッセージがセットされている' do
-        lambda {
-          @op.store('bindata', @artist, @license.id)\r
-        }.should change(@op.errors[:base], :count)
-      end
-    end
-    context '対象素材オブジェクトの保存に失敗したとき' do
-      before do
-        OriginalPicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)
-        OriginalPicture.any_instance.stub(:save).with(any_args).and_return(true)\r
-        PictureIO::LocalPicture.any_instance.stub(:put).with(any_args).and_return(true)
-        ResourcePicture.any_instance.stub(:store).with(any_args).and_return(false)
-      end
-      it 'falseを返す' do
-        @op.store('bindata', @artist, @license.id).should be_false\r
-      end
-      it '更新されていない' do
-        @op.store('bindata', @artist, @license.id)\r
-        @op.should be_a_new OriginalPicture\r
+        @op.store('bindata', @artist)\r
       end
       it '全体エラーメッセージがセットされている' do
         lambda {
-          @op.store('bindata', @artist, @license.id)\r
+          @op.store('bindata', @artist)\r
         }.should change(@op.errors[:base], :count)
       end
     end