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
+ 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
+ context 'DBに5件あって1ページの件数を0件に変えたとして' 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
+ Author.stub(:default_resource_picture_page_size).and_return(2)\r
+ end\r
+ it '通常は全件(5件)を返す' do\r
+ r = ResourcePicture.mylist @artist, 5, 0\r
+ r.should have(5).items \r
+ end\r
+ end\r
+ end\r
+ \r
describe '単体取得に於いて' do\r
before do\r
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
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
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
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
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
@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
\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
+ 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
+ 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 'Trueを返す' do\r
+ r = @rp.unpublish\r
+ r.should be_true\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