OSDN Git Service

t#31470:create pager
[pettanr/pettanr.git] / spec / models / resource_picture_spec.rb
index 11ac80f..8fd9a97 100644 (file)
@@ -6,10 +6,10 @@ describe ResourcePicture do
   before do\r
     @admin = FactoryGirl.create :admin\r
     @user = FactoryGirl.create( :user_yas)\r
-    @author = @user.author\r
+    @author = FactoryGirl.create :author, :user_id => @user.id\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_author = FactoryGirl.create :author, :user_id => @other_user.id\r
     @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
     @sp = FactoryGirl.create :system_picture\r
     @lg = FactoryGirl.create :license_group\r
@@ -30,27 +30,27 @@ describe ResourcePicture do
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
     end\r
     \r
-    context 'オーソドックスなデータのとき' do
-      it '下限データが通る' do
-        @rp.ext = 'png' #リストにない拡張子は通らないし
-        @rp.width = 1
-        @rp.height = 1
-        @rp.filesize = 1
-        @rp.md5 = 'a'*32
-        @rp.classname = 'a'*1
-        @rp.should be_valid
-      end
-      it '上限データが通る' do
-        @rp.ext = 'jpeg'
-        @rp.width = 99999
-        @rp.height = 99999
-        @rp.filesize = 2000000
-        @rp.md5 = 'a'*32
-        @rp.classname = 'a'*50
-        @rp.should be_valid
-      end
-    end
-    
+    context 'オーソドックスなデータのとき' do\r
+      it '下限データが通る' do\r
+        @rp.ext = 'png' #リストにない拡張子は通らないし\r
+        @rp.width = 1\r
+        @rp.height = 1\r
+        @rp.filesize = 1\r
+        @rp.md5 = 'a'*32\r
+        @rp.classname = 'a'*1\r
+        @rp.should be_valid\r
+      end\r
+      it '上限データが通る' do\r
+        @rp.ext = 'jpeg'\r
+        @rp.width = 99999\r
+        @rp.height = 99999\r
+        @rp.filesize = 2000000\r
+        @rp.md5 = 'a'*32\r
+        @rp.classname = 'a'*50\r
+        @rp.should be_valid\r
+      end\r
+    end\r
+    \r
     context 'extを検証するとき' do\r
       it 'nullなら失敗する' do\r
         @rp.ext = ''\r
@@ -138,10 +138,10 @@ describe ResourcePicture do
         @rp.md5 = ''\r
         @rp.should_not be_valid\r
       end\r
-      it '31文字なら失敗する' do
-        @rp.md5 = 'a'*31
-        @rp.should_not be_valid
-      end
+      it '31文字なら失敗する' do\r
+        @rp.md5 = 'a'*31\r
+        @rp.should_not be_valid\r
+      end\r
       it '32文字以上なら失敗する' do\r
         @rp.md5 = 'a'*33\r
         @rp.should_not be_valid\r
@@ -211,119 +211,196 @@ describe ResourcePicture do
     end\r
   end\r
   \r
-  describe 'デフォルト値補充に於いて' do
-    it 'defined' do
+  describe '文字コード検証に於いて' do\r
+    before do\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
+    end\r
+    \r
+    context 'artist_nameを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @rp.artist_name = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @rp.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+    context 'classnameを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @rp.classname = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @rp.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+    context 'creditを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @rp.credit = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @rp.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+    context 'settingsを検証するとき' do\r
+      it 'Shift JISなら失敗する' do\r
+        @rp.settings = "\x83G\x83r\x83]\x83D"\r
+        lambda{\r
+          @rp.valid_encode\r
+        }.should raise_error(Pettanr::BadRequest)\r
+      end\r
+    end\r
+    \r
+  end\r
+  \r
+  describe 'デフォルト値補充に於いて' do\r
+    it 'defined' do\r
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
-      @rp.supply_default
-    end
-  end
-  
-  describe '上書き補充に於いて' do
-    before do
-      @original_picture.attributes = {:ext => 'gif', :width => 267, :height => 268, :filesize => 269, 
-        :artist_id => @artist.id }
-      @rp = FactoryGirl.build :resource_picture, :original_picture_id => @original_picture.id
-    end
-    it 'width, height, ext, filesize, md5, original_picture_id, artist_idが設定されている' do
-      @rp.overwrite @original_picture
-      @rp.width.should eq 267
-      @rp.height.should eq 268
-      @rp.ext.should eq 'gif'
-      @rp.filesize.should eq 269
-      @rp.md5.should eq @rp.md5
-      @rp.original_picture_id.should eq @original_picture.id
-      @rp.artist_id.should eq @artist.id
-    end
-  end
-  
-  describe '所持判定に於いて' do
-    before do
+      @rp.supply_default\r
+    end\r
+  end\r
+  \r
+  describe '上書き補充に於いて' do\r
+    before do\r
+      @original_picture.attributes = {:ext => 'gif', :width => 267, :height => 268, :filesize => 269, \r
+        :artist_id => @artist.id }\r
+      @rp = FactoryGirl.build :resource_picture, :original_picture_id => @original_picture.id\r
+    end\r
+    it 'width, height, ext, filesize, md5, original_picture_id, artist_idが設定されている' do\r
+      @rp.overwrite @original_picture\r
+      @rp.width.should eq 267\r
+      @rp.height.should eq 268\r
+      @rp.ext.should eq 'gif'\r
+      @rp.filesize.should eq 269\r
+      @rp.md5.should eq @rp.md5\r
+      @rp.original_picture_id.should eq @original_picture.id\r
+      @rp.artist_id.should eq @artist.id\r
+    end\r
+  end\r
+  \r
+  describe '所持判定に於いて' do\r
+    before do\r
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
-    end
-    it '素材を更新することはないので、Falseを返す' do
-      @rp.own?(@author).should == false
-    end
-  end
-  
-  describe '閲覧許可に於いて' do
-    before do
+    end\r
+    context '事前チェックする' do\r
+      it '自身にロールリストからの絵師取得を依頼している' do\r
+        ResourcePicture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)\r
+        r = @rp.own?([@author])\r
+      end\r
+    end\r
+    context 'ロール内絵師が取得できるとき' do\r
+      before do\r
+      end\r
+      it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)\r
+        r = @rp.own?([@author])\r
+        r.should be_true\r
+      end\r
+      it 'ロール内絵師のidが自身の絵師idと一致しないならno' do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)\r
+        @rp.own?(@other_artist).should be_false\r
+      end\r
+    end\r
+    context 'ロール内絵師が取得できないとき' do\r
+      before do\r
+        ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(nil)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.own?([@author])\r
+        r.should be_false\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '閲覧許可に於いて' do\r
+    before do\r
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
-    end
-    context '検査対象がnil(ゲスト)のとき' do
-      context 'クローズドモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 1
-        end
-        it '不許可を返す。' do\r
-          r = @rp.visible?(nil)
-          r.should be_false
-        end\r
-      end\r
-      context 'オープンモードのとき' do
-        before do
-          MagicNumber['run_mode'] = 0
-        end
-        it '許可する' do\r
-          r = @rp.visible?(nil)
-          r.should be_true
-        end\r
-      end\r
-    end\r
-    context '検査対象が作家のとき' do
-      it '許可する' do\r
-        r = @rp.visible?(@author)
-        r.should == true
+    end\r
+    context 'オープンモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 0\r
+      end\r
+      it '自身にゲスト用ロールチェックを問い合わせしている' do\r
+        ResourcePicture.any_instance.stub(:guest_role_check).and_return(true)\r
+        ResourcePicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
+        r = @rp.visible?([@author])\r
+      end\r
+      it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
+        ResourcePicture.any_instance.stub(:guest_role_check).and_return(false)\r
+        r = @rp.visible?([@author])\r
+        r.should be_false\r
       end\r
     end\r
-    context '検査対象がそれ以外のとき' do
-      it '不許可を返す。' do\r
-        r = @rp.visible?(@admin)
-        r.should be_false
+    context 'クローズドモードのとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+      end\r
+      it '自身に素材読者用ロールチェックを問い合わせしている' do\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(true)\r
+        ResourcePicture.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)\r
+        r = @rp.visible?([@author])\r
+      end\r
+      it '素材読者用ロールチェックが失敗したとき、falseを返す' do\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(false)\r
+        r = @rp.visible?([@author])\r
+        r.should be_false\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      before do\r
+        MagicNumber['run_mode'] = 1\r
+        ResourcePicture.any_instance.stub(:resource_reader_role_check).and_return(true)\r
+      end\r
+      it '許可する' do\r
+        r = @rp.visible?([@author])\r
+        r.should be_true\r
       end\r
     end\r
-  end
-  
-  describe 'ファイル名に於いて' do
-    before do
+  end\r
+  \r
+  describe 'ファイル名に於いて' do\r
+    before do\r
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
-    end
-    it 'id+拡張子のフォーマットで返す' do
-      r = @rp.filename
-      r.should eq "#{@rp.id}.png"
-    end
-  end
-  
-  describe 'MimeTypeに於いて' do
-    before do
+    end\r
+    it 'id+拡張子のフォーマットで返す' do\r
+      r = @rp.filename\r
+      r.should eq "#{@rp.id}.png"\r
+    end\r
+  end\r
+  \r
+  describe 'MimeTypeに於いて' do\r
+    before do\r
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
-    end
-    it 'image/拡張子のフォーマットで返す' do
-      r = @rp.mime_type
-      r.should eq "image/png"
-    end
-  end
-  
-  describe 'ファイルのurlに於いて' do
-    before do
+    end\r
+    it 'image/拡張子のフォーマットで返す' do\r
+      r = @rp.mime_type\r
+      r.should eq "image/png"\r
+    end\r
+  end\r
+  \r
+  describe 'ファイルのurlに於いて' do\r
+    before do\r
       @p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
-      ResourcePicture.any_instance.stub(:filename).and_return('3.gif')
-    end
-    it 'ファイル名取得を依頼している' do
-      ResourcePicture.any_instance.should_receive(:filename).exactly(1)
-      @rp.url
-    end
-    it '/resource_pictures/3.gifのフォーマットで返す' do
-      r = @rp.url
-      r.should eq "/resource_pictures/3.gif"
-    end
-  end
-  
+      ResourcePicture.any_instance.stub(:filename).and_return('3.gif')\r
+    end\r
+    it 'ファイル名取得を依頼している' do\r
+      ResourcePicture.any_instance.should_receive(:filename).exactly(1)\r
+      @rp.url\r
+    end\r
+    it '/resource_pictures/3.gifのフォーマットで返す' do\r
+      r = @rp.url\r
+      r.should eq "/resource_pictures/3.gif"\r
+    end\r
+  end\r
+  \r
   describe '一覧取得に於いて' do\r
     before do\r
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
@@ -395,75 +472,227 @@ describe ResourcePicture do
         r.should eq [@rp]\r
       end\r
     end\r
-    context 'DBに5件あって1ページの件数を2件に変えたとして' do
-      before do
-        nop2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @nrp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
-        nop3 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @nrp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
-        nop4 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @nrp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
-        nop5 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
-        @nrp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
-        ResourcePicture.stub(:default_page_size).and_return(2)\r
-      end
-      it '件数0は全件(5件)を返す' do
-        r = ResourcePicture.list 5, 0
-        r.should have(5).items 
-      end
-    end
   end\r
+  \r
+  describe '自分の素材一覧取得に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '一覧取得オプションを利用している' do\r
+        ResourcePicture.stub(:list_opt).with(any_args).and_return({})\r
+        ResourcePicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+        r = ResourcePicture.mylist @artist\r
+      end\r
+    end\r
+    it 'リストを返す' do\r
+      c = ResourcePicture.mylist @artist\r
+      c.should eq [@rp]\r
+    end\r
+    it '時系列で並んでいる' do\r
+      nop = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      nrp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+      cl = ResourcePicture.mylist @artist\r
+      cl.should eq [nrp, @rp]\r
+    end\r
+    it '他人の素材は含まない' do\r
+      nop = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+      nrp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+      cl = ResourcePicture.mylist @artist\r
+      cl.should eq [@rp]\r
+    end\r
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+      before do\r
+        @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+        @op3 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @rp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
+        @op4 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @rp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
+        @op5 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+        @rp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
+      end\r
+      it '通常は2件を返す' do\r
+        c = ResourcePicture.mylist @artist, 1, 2\r
+        c.should have(2).items \r
+      end\r
+      it 'page=1なら末尾2件を返す' do\r
+        #時系列で並んでいる\r
+        c = ResourcePicture.mylist(@artist, 1, 2)\r
+        c.should eq [@rp5, @rp4]\r
+      end\r
+      it 'page=2なら中間2件を返す' do\r
+        c = ResourcePicture.mylist(@artist, 2, 2)\r
+        c.should eq [@rp3, @rp2]\r
+      end\r
+      it 'page=3なら先頭1件を返す' do\r
+        c = ResourcePicture.mylist(@artist, 3, 2)\r
+        c.should eq [@rp]\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '他作家の素材一覧取得に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+      @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+      @other_p = FactoryGirl.create :picture, :original_picture_id => @other_op.id, :license_id => @license.id, :artist_id => @other_artist.id\r
+      @other_rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @other_op.id, :picture_id => @other_p.id\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '一覧取得オプションを利用している' do\r
+        ResourcePicture.stub(:list_opt).with(any_args).and_return({})\r
+        ResourcePicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+        r = ResourcePicture.himlist @other_artist\r
+      end\r
+    end\r
+    it '指定した作家のリストを返す' do\r
+      r = ResourcePicture.himlist @other_artist\r
+      r.should eq [@other_rp]\r
+    end\r
+    it '時系列で並んでいる' do\r
+      nop = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+      nrp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @other_p.id, :updated_at => Time.now + 100\r
+      r = ResourcePicture.himlist @other_artist\r
+      r.should eq [nrp, @other_rp]\r
+    end\r
+    context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+      before do\r
+        @op2 = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+        @rp2 = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p.id, :updated_at => Time.now + 100\r
+        @op3 = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+        @rp3 = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
+        @op4 = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+        @rp4 = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
+        @op5 = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+        @rp5 = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @op5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
+      end\r
+      it '通常は2件を返す' do\r
+        r = ResourcePicture.himlist @other_artist, 1, 2\r
+        r.should have(2).items \r
+      end\r
+      it 'page=1なら末尾2件を返す' do\r
+        #時系列で並んでいる\r
+        r = ResourcePicture.himlist(@other_artist, 1, 2)\r
+        r.should eq [@rp5, @rp4]\r
+      end\r
+      it 'page=2なら中間2件を返す' do\r
+        r = ResourcePicture.himlist(@other_artist, 2, 2)\r
+        r.should eq [@rp3, @rp2]\r
+      end\r
+      it 'page=3なら先頭1件を返す' do\r
+        r = ResourcePicture.himlist(@other_artist, 3, 2)\r
+        r.should eq [@other_rp]\r
+      end\r
+    end\r
+  end\r
+  \r
+  describe '一覧ページ制御に於いて' do\r
+    before do\r
+      ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = ResourcePicture.list_paginate\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = ResourcePicture.list_paginate 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
+  describe '自分の素材一覧ページ制御に於いて' do\r
+    before do\r
+      ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = ResourcePicture.mylist_paginate @artist\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it '自分の素材一覧の取得条件を利用している' do\r
+      ResourcePicture.stub(:mylist_where).with(any_args).and_return('')\r
+      ResourcePicture.should_receive(:mylist_where).with(any_args).exactly(1)\r
+      r = ResourcePicture.mylist_paginate @artist\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = ResourcePicture.mylist_paginate @artist, 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
+  describe '他作家の素材一覧ページ制御に於いて' do\r
+    before do\r
+      ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+    end\r
+    it 'ページ制御を返す' do\r
+      r = ResourcePicture.himlist_paginate @other_artist\r
+      r.is_a?(Kaminari::PaginatableArray).should be_true\r
+    end\r
+    it '他作家の素材一覧の取得条件を利用している' do\r
+      ResourcePicture.stub(:himlist_where).with(any_args).and_return('')\r
+      ResourcePicture.should_receive(:himlist_where).with(any_args).exactly(1)\r
+      r = ResourcePicture.himlist_paginate @other_artist\r
+    end\r
+    it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+      r = ResourcePicture.himlist_paginate @other_artist, 3, 10\r
+      r.limit_value.should eq 10\r
+      r.offset_value.should eq 20\r
+    end\r
+  end\r
+  \r
   describe '一覧取得オプションに於いて' do\r
-    it 'includeキーを含んでいる' do
-      r = ResourcePicture.list_opt
-      r.has_key?(:include).should be_true
-    end
-    it '3つの項目を含んでいる' do
-      r = ResourcePicture.list_opt[:include]
-      r.should have(3).items
-    end
-    it 'ライセンスを含んでいる' do
-      r = ResourcePicture.list_opt[:include]
-      r.has_key?(:license).should be_true
-    end
-    it '絵師を含んでいる' do
-      r = ResourcePicture.list_opt[:include]
-      r.has_key?(:artist).should be_true
-    end
-    it '実素材を含んでいる' do
-      r = ResourcePicture.list_opt[:include]
-      r.has_key?(:picture).should be_true
-    end
+    it '3つの項目を含んでいる' do\r
+      r = ResourcePicture.list_opt\r
+      r.should have(3).items\r
+    end\r
+    it 'ライセンスを含んでいる' do\r
+      r = ResourcePicture.list_opt\r
+      r.has_key?(:license).should be_true\r
+    end\r
+    it '絵師を含んでいる' do\r
+      r = ResourcePicture.list_opt\r
+      r.has_key?(:artist).should be_true\r
+    end\r
+    it '実素材を含んでいる' do\r
+      r = ResourcePicture.list_opt\r
+      r.has_key?(:picture).should be_true\r
+    end\r
   end\r
-  describe 'json一覧出力オプションに於いて' do
-    before do
+  describe 'json一覧出力オプションに於いて' do\r
+    before do\r
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
       @sbt = FactoryGirl.create :speech_balloon_template\r
-      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
-      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
-    end
-    it 'ライセンスを含んでいる' do
-      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('license').should be_true
-    end
-    it '絵師を含んでいる' do
-      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('artist').should be_true
-    end
-    it '実素材を含んでいる' do
-      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
-      j = JSON.parse r
-      i = j.first
-      i.has_key?('picture').should be_true
-    end
-  end
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1\r
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
+    end\r
+    it 'ライセンスを含んでいる' do\r
+      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+      j = JSON.parse r\r
+      i = j.first\r
+      i.has_key?('license').should be_true\r
+    end\r
+    it '絵師を含んでいる' do\r
+      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+      j = JSON.parse r\r
+      i = j.first\r
+      i.has_key?('artist').should be_true\r
+    end\r
+    it '実素材を含んでいる' do\r
+      r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+      j = JSON.parse r\r
+      i = j.first\r
+      i.has_key?('picture').should be_true\r
+    end\r
+  end\r
   \r
   describe '単体取得に於いて' do\r
     before do\r
@@ -471,30 +700,30 @@ describe ResourcePicture do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\r
     end\r
-    context 'つつがなく終わるとき' do
-      it '単体取得オプションを利用している' do
-        ResourcePicture.stub(:show_opt).with(any_args).and_return({})
-        ResourcePicture.should_receive(:show_opt).with(any_args).exactly(1)
-        r = ResourcePicture.show @rp.id, @author
-      end
-      it '閲覧許可を問い合わせている' do
-        ResourcePicture.any_instance.stub(:visible?).with(any_args).and_return(true)
-        ResourcePicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
-        r = ResourcePicture.show @rp.id, @author
-      end
-    end
+    context 'つつがなく終わるとき' do\r
+      it '単体取得オプションを利用している' do\r
+        ResourcePicture.stub(:show_opt).with(any_args).and_return({})\r
+        ResourcePicture.should_receive(:show_opt).with(any_args).exactly(1)\r
+        r = ResourcePicture.show @rp.id, @author\r
+      end\r
+      it '閲覧許可を問い合わせている' do\r
+        ResourcePicture.any_instance.stub(:visible?).with(any_args).and_return(true)\r
+        ResourcePicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
+        r = ResourcePicture.show @rp.id, @author\r
+      end\r
+    end\r
     it '指定の素材を返す' do\r
       r = ResourcePicture.show @rp.id, @author\r
       r.should eq @rp\r
     end\r
-    context '他人の素材を開こうとしたとき' do
-      it '403Forbidden例外を返す' do
-        ResourcePicture.any_instance.stub(:visible?).and_return(false)
-        lambda{
-          r = ResourcePicture.show @rp.id, @other_author
-        }.should raise_error(ActiveRecord::Forbidden)
-      end
-    end
+    context '他人の素材を開こうとしたとき' do\r
+      it '403Forbidden例外を返す' do\r
+        ResourcePicture.any_instance.stub(:visible?).and_return(false)\r
+        lambda{\r
+          r = ResourcePicture.show @rp.id, @other_author\r
+        }.should raise_error(ActiveRecord::Forbidden)\r
+      end\r
+    end\r
     context '存在しない素材を開こうとしたとき' do\r
       it '404RecordNotFound例外を返す' do\r
         lambda{\r
@@ -504,55 +733,55 @@ describe ResourcePicture do
     end\r
   end\r
   describe '単体取得オプションに於いて' do\r
-    it 'includeキーを含んでいる' do
-      r = ResourcePicture.show_opt
-      r.has_key?(:include).should be_true
-    end
-    it '3つの項目を含んでいる' do
-      r = ResourcePicture.show_opt[:include]
-      r.should have(3).items
-    end
-    it 'ライセンスを含んでいる' do
-      r = ResourcePicture.show_opt[:include]
-      r.has_key?(:license).should be_true
-    end
-    it '絵師を含んでいる' do
-      r = ResourcePicture.show_opt[:include]
-      r.has_key?(:artist).should be_true
-    end
-    it '実素材を含んでいる' do
-      r = ResourcePicture.show_opt[:include]
-      r.has_key?(:picture).should be_true
-    end
+    it 'includeキーを含んでいる' do\r
+      r = ResourcePicture.show_opt\r
+      r.has_key?(:include).should be_true\r
+    end\r
+    it '3つの項目を含んでいる' do\r
+      r = ResourcePicture.show_opt[:include]\r
+      r.should have(3).items\r
+    end\r
+    it 'ライセンスを含んでいる' do\r
+      r = ResourcePicture.show_opt[:include]\r
+      r.has_key?(:license).should be_true\r
+    end\r
+    it '絵師を含んでいる' do\r
+      r = ResourcePicture.show_opt[:include]\r
+      r.has_key?(:artist).should be_true\r
+    end\r
+    it '実素材を含んでいる' do\r
+      r = ResourcePicture.show_opt[:include]\r
+      r.has_key?(:picture).should be_true\r
+    end\r
   end\r
   describe 'json単体出力オプションに於いて' do\r
-    before do
+    before do\r
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
       @sbt = FactoryGirl.create :speech_balloon_template\r
-      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
-      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
-      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
-    end
-    it 'ライセンスを含んでいる' do
-      r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
-      j = JSON.parse r
-      i = j
-      i.has_key?('license').should be_true
-    end
-    it '絵師を含んでいる' do
-      r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
-      j = JSON.parse r
-      i = j
-      i.has_key?('artist').should be_true
-    end
-    it '実素材を含んでいる' do
-      r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
-      j = JSON.parse r
-      i = j
-      i.has_key?('picture').should be_true
-    end
+      @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1\r
+      @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+      @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
+    end\r
+    it 'ライセンスを含んでいる' do\r
+      r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt\r
+      j = JSON.parse r\r
+      i = j\r
+      i.has_key?('license').should be_true\r
+    end\r
+    it '絵師を含んでいる' do\r
+      r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt\r
+      j = JSON.parse r\r
+      i = j\r
+      i.has_key?('artist').should be_true\r
+    end\r
+    it '実素材を含んでいる' do\r
+      r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt\r
+      j = JSON.parse r\r
+      i = j\r
+      i.has_key?('picture').should be_true\r
+    end\r
   end\r
   \r
   describe 'フォーマット変換対象判定に於いて' do\r
@@ -588,7 +817,7 @@ describe ResourcePicture do
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', \r
         :credit => '{}', :settings => {:reverse => 1, :gif_convert => 1}.to_json.to_s}\r
       @rp = FactoryGirl.build :resource_picture, attr\r
-      @imager = ImagerTest.load "abc\ndef\nghi"
+      @imager = ImagerTest.load "abc\ndef\nghi"\r
     end\r
     context '事前チェック' do\r
       before do\r
@@ -635,15 +864,20 @@ describe ResourcePicture do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :picture_id => nil, :license_id => @license.id, :artist_name => 'tester', :classname => 'StandardLicense', :credit => '{}', :settings => {}.to_json.to_s}\r
       @rp = FactoryGirl.build :resource_picture, attr\r
-      @imager = ImagerTest.load "abc\ndef\nghi"
+      @imager = ImagerTest.load "abc\ndef\nghi"\r
     end\r
     context '事前チェック' do\r
       before do\r
         #すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
         #それで外部のメソッド呼び出しだけに着目してテストする。\r
+        OriginalPicture.any_instance.stub(:save).and_return(true)\r
         ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
         ResourcePicture.any_instance.stub(:store_picture_with_gif).with(any_args).and_return(true)\r
       end\r
+      it '原画に保存を依頼している' do\r
+        OriginalPicture.any_instance.should_receive(:save).exactly(1)\r
+        r = @rp.store @imager\r
+      end\r
       it '新規実素材の取得を依頼している' do\r
         ResourcePicture.any_instance.should_receive(:new_picture).with(any_args).exactly(1)\r
         r = @rp.store @imager\r
@@ -667,6 +901,15 @@ describe ResourcePicture do
         r = @rp.store @imager\r
         r.should be_true\r
       end\r
+      it '原画の停止日時をクリアする' do\r
+        r = @rp.store @imager\r
+        @rp.original_picture.stopped_at.should be_nil\r
+      end\r
+      it '原画の公開日時に現在時刻をセットする' do\r
+        lambda {\r
+          r = @rp.store @imager\r
+        }.should change(@rp.original_picture, :published_at)\r
+      end\r
       it '実素材idから最新画像idを取得してセットしている' do\r
         r = @rp.store @imager\r
         @rp.picture_id.should eq @p.id\r
@@ -678,6 +921,20 @@ describe ResourcePicture do
       end\r
     end\r
     #以下から例外ケース。処理先頭から失敗させていく\r
+    context '原画の保存に失敗したとき' do\r
+      before do\r
+        OriginalPicture.any_instance.stub(:save).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.unpublish\r
+        r.should be_false\r
+      end\r
+      it 'ロールバックしている' do\r
+        lambda {\r
+          r = @rp.unpublish\r
+        }.should_not change(ResourcePicture, :count)\r
+      end\r
+    end\r
     context '画像オブジェクトの取得に失敗したとき' do\r
       before do\r
         @imager = false\r
@@ -760,7 +1017,7 @@ describe ResourcePicture do
       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
       @rp = FactoryGirl.build :resource_picture, attr\r
-      @imager = ImagerTest.load "abc\ndef\nghi"
+      @imager = ImagerTest.load "abc\ndef\nghi"\r
     end\r
     context '事前チェック' do\r
       before do\r
@@ -824,6 +1081,11 @@ describe ResourcePicture do
         r = @rp.store_picture_with_gif @imager\r
         r.should be_false\r
       end\r
+      it '全体エラーメッセージがセットされている' do\r
+        lambda {\r
+          r = @rp.store_picture_with_gif @imager\r
+        }.should change(@rp.errors[:base], :count)\r
+      end\r
       it 'gif変換判定は呼ばれていない' do\r
         ResourcePicture.any_instance.should_not_receive(:to_gif?).with(any_args)\r
         r = @rp.store_picture_with_gif @imager\r
@@ -839,6 +1101,11 @@ describe ResourcePicture do
         r = @rp.store_picture_with_gif @imager\r
         r.should be_false\r
       end\r
+      it '全体エラーメッセージがセットされている' do\r
+        lambda {\r
+          r = @rp.store_picture_with_gif @imager\r
+        }.should change(@rp.errors[:base], :count)\r
+      end\r
       it 'gif画像の保存は呼ばれていない' do\r
         #本画像の保存があるので、一度は呼ばれる\r
         ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
@@ -859,6 +1126,11 @@ describe ResourcePicture do
         r = @rp.store_picture_with_gif @imager\r
         r.should be_false\r
       end\r
+      it '全体エラーメッセージがセットされている' do\r
+        lambda {\r
+          r = @rp.store_picture_with_gif @imager\r
+        }.should change(@rp.errors[:base], :count)\r
+      end\r
     end\r
   end\r
   \r
@@ -870,7 +1142,7 @@ describe ResourcePicture do
       attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :credit => '{}', :settings => {}.to_json.to_s}\r
       @rp = FactoryGirl.build :resource_picture, attr\r
       @rp.overwrite @op\r
-      @imager = ImagerTest.load "abc\ndef\nghi"
+      @imager = ImagerTest.load "abc\ndef\nghi"\r
     end\r
     context '事前チェック' do\r
       before do\r
@@ -926,7 +1198,7 @@ describe ResourcePicture do
         ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
         @tmbimager = @imager.to_thumbnail\r
         ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(@tmbimager)\r
-        PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_return(false)\r
+        PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_raise(PictureIO::Error)\r
       end\r
       it 'Falseを返す' do\r
         r = @rp.store_picture(@imager, '1.gif')\r
@@ -943,7 +1215,7 @@ describe ResourcePicture do
         @tmbimager = @imager.to_thumbnail\r
         ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(@tmbimager)\r
         PictureIO.resource_picture_io.stub(:put).with(@tmbimager.binary, '1.gif').and_return(true)\r
-        PictureIO.resource_picture_io.stub(:put).with(@imager.binary, '1.gif', 'full').and_return(false)\r
+        PictureIO.resource_picture_io.stub(:put).with(@imager.binary, '1.gif', 'full').and_raise(PictureIO::Error)\r
       end\r
       it 'Falseを返す' do\r
         r = @rp.store_picture(@imager, '1.gif')\r
@@ -953,6 +1225,121 @@ describe ResourcePicture do
     \r
   end\r
   \r
+  describe '公開停止に於いて' do\r
+    before do\r
+      @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+      @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+      @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+      PictureIO.resource_picture_io.stub(:exist?).with(@rp.filename).and_return(true)\r
+      PictureIO.resource_picture_io.stub(:exist?).with(@rp.filename, 'full').and_return(true)\r
+    end\r
+    context '事前チェックしておく' do\r
+      before do\r
+        OriginalPicture.any_instance.stub(:save).and_return(true)\r
+        ResourcePicture.any_instance.stub(:destroy).and_return(true)\r
+        PictureIO.resource_picture_io.stub(:delete).with(@rp.filename).and_return(true)\r
+        PictureIO.resource_picture_io.stub(:delete).with(@rp.filename, 'full').and_return(true)\r
+      end\r
+      it '原画に保存を依頼している' do\r
+        OriginalPicture.any_instance.should_receive(:save).exactly(1)\r
+        r = @rp.unpublish\r
+      end\r
+      it '素材モデルに削除を依頼している' do\r
+        ResourcePicture.any_instance.should_receive(:destroy).exactly(1)\r
+        r = @rp.unpublish\r
+      end\r
+      it '保管庫にサムネイルの画像データ削除を依頼している' do\r
+        PictureIO.resource_picture_io.should_receive(:delete).with(@rp.filename).exactly(1)\r
+        r = @rp.unpublish\r
+      end\r
+      it '保管庫にフルサイズの画像データ削除を依頼している' do\r
+        PictureIO.resource_picture_io.should_receive(:delete).with(@rp.filename, 'full').exactly(1)\r
+        r = @rp.unpublish\r
+      end\r
+    end\r
+    context 'つつがなく終わるとき' do\r
+      it '自身を削除する' do\r
+        lambda {\r
+          r = @rp.unpublish\r
+        }.should change(ResourcePicture, :count).by(-1)\r
+        lambda {\r
+          r = ResourcePicture.find @rp.id\r
+        }.should raise_error\r
+      end\r
+      it '原画の公開日時をクリアする' do\r
+        r = @rp.store @imager\r
+        @rp.original_picture.published_at.should be_nil\r
+      end\r
+      it '原画の停止日時に現在時刻をセットする' do\r
+        lambda {\r
+          r = @rp.unpublish\r
+        }.should change(@rp.original_picture, :stopped_at)\r
+      end\r
+      it 'Trueを返す' do\r
+        r = @rp.unpublish\r
+        r.should be_true\r
+      end\r
+    end\r
+    context '原画の保存に失敗したとき' do\r
+      before do\r
+        OriginalPicture.any_instance.stub(:save).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.unpublish\r
+        r.should be_false\r
+      end\r
+      it 'ロールバックしている' do\r
+        lambda {\r
+          r = @rp.unpublish\r
+        }.should_not change(ResourcePicture, :count)\r
+      end\r
+    end\r
+    context '自身の削除に失敗したとき' do\r
+      before do\r
+        ResourcePicture.any_instance.stub(:destroy).with(any_args).and_return(false)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.unpublish\r
+        r.should be_false\r
+      end\r
+      it 'ロールバックしている' do\r
+        lambda {\r
+          r = @rp.unpublish\r
+        }.should_not change(ResourcePicture, :count)\r
+      end\r
+    end\r
+    context 'サムネイル画像の削除に失敗したとき' do\r
+      before do\r
+        PictureIO.resource_picture_io.stub(:delete).with(@rp.filename).and_raise(PictureIO::Error)\r
+        PictureIO.resource_picture_io.stub(:delete).with(@rp.filename, 'full').and_return(true)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.unpublish\r
+        r.should be_false\r
+      end\r
+      it 'ロールバックしている' do\r
+        lambda {\r
+          r = @rp.unpublish\r
+        }.should_not change(ResourcePicture, :count)\r
+      end\r
+    end\r
+    context 'フルサイズ画像の削除に失敗したとき' do\r
+      before do\r
+        PictureIO.resource_picture_io.stub(:delete).with(@rp.filename).and_return(true)\r
+        PictureIO.resource_picture_io.stub(:delete).with(@rp.filename, 'full').and_raise(PictureIO::Error)\r
+      end\r
+      it 'Falseを返す' do\r
+        r = @rp.unpublish\r
+        r.should be_false\r
+      end\r
+      it 'ロールバックしている' do\r
+        lambda {\r
+          r = @rp.unpublish\r
+        }.should_not change(ResourcePicture, :count)\r
+      end\r
+    end\r
+  end\r
+  \r
   describe 'クレジットデータに於いて' do\r
     before do\r
       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r