OSDN Git Service

add OriginalPictureLicenseGroup
[pettanr/pettanr.git] / spec / models / original_picture_spec.rb
index 0ccc021..2fa0f8e 100644 (file)
@@ -20,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'
@@ -47,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
@@ -72,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
@@ -97,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
@@ -122,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
@@ -141,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
@@ -199,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{
@@ -226,11 +193,41 @@ describe OriginalPicture do
       end
     end
   end
+  describe '関連テーブルプションに於いて' do\r
+    context 'オプションがないとき' do\r
+      it '1つの項目を含んでいる' do\r
+        r = OriginalPicture.show_include_opt\r
+        r.should have(1).items\r
+      end\r
+      it '素材を含んでいる' do\r
+        r = OriginalPicture.show_include_opt\r
+        r.has_key?(:resource_picture).should be_true\r
+      end\r
+    end\r
+    context 'オプションでtestを含ませたとき' do\r
+      it '2つの項目を含んでいる' do\r
+        r = OriginalPicture.show_include_opt(:include => {:test => {}})\r
+        r.should have(2).items\r
+      end\r
+      it 'testを含んでいる' do\r
+        r = OriginalPicture.show_include_opt(:include => {:test => {}})\r
+        r.has_key?(:test).should be_true\r
+      end\r
+    end\r
+  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
@@ -302,12 +299,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
@@ -357,31 +376,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
@@ -390,24 +400,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
     #以下から例外ケース。処理先頭から失敗させていく
@@ -416,10 +425,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
@@ -428,10 +438,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
@@ -445,39 +455,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