\r
describe ResourcePicture do\r
before do\r
- FactoryGirl.create :admin\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
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
@original_picture = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
\r
- class Mgk ; class Image ; end ; end\r
- Mgk::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])\r
- Mgk.any_instance.stub(:format).with(any_args).and_return('png')\r
- Mgk.any_instance.stub(:format=).with(any_args)\r
- Mgk.any_instance.stub(:rows).with(any_args).and_return(200)\r
- Mgk.any_instance.stub(:columns).with(any_args).and_return(100)\r
- Mgk.any_instance.stub(:filesize).with(any_args).and_return(20000)\r
- Mgk.any_instance.stub(:to_blob).with(any_args).and_return('data')\r
#原画ファイル削除だけは必ず成功するものとしておく\r
PictureIO::LocalPicture.any_instance.stub(:delete).with(any_args).and_return(true)\r
Picture.any_instance.stub(:subdirs).with(any_args).and_return(['', 'v', 'h', 'vh'])\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
- it 'オーソドックスなデータなら通る' do\r
- @rp.should be_valid\r
- end\r
- \r
- context 'extを検証するとき' do\r
- it 'テストデータの確認' do\r
+ 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
@rp.should_not be_valid\r
end\r
end\r
context 'widthを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.width = 1\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.width = nil\r
@rp.should_not be_valid\r
end\r
end\r
context 'heightを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.height = '1'\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.height = nil\r
@rp.should_not be_valid\r
end\r
end\r
context 'filesizeを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.filesize = '1'\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.filesize = nil\r
@rp.should_not be_valid\r
end\r
end\r
context 'artist_idを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.artist_id = @artist.id\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.artist_id = nil\r
@rp.should_not be_valid\r
end\r
end\r
context 'md5を検証するとき' do\r
- before do\r
- @rp = FactoryGirl.build :picture\r
- end\r
- it 'テストデータの確認' do\r
- @rp.md5 = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.md5 = ''\r
@rp.should_not be_valid\r
end\r
+ 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
end\r
end\r
context 'license_idを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.license_id = @license.id\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.license_id = nil\r
@rp.should_not be_valid\r
end\r
end\r
context 'original_picture_idを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.original_picture_id = @original_picture.id\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.original_picture_id = nil\r
@rp.should_not be_valid\r
end\r
end\r
context 'artist_nameを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.artist_name = 'a'\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.artist_name = nil\r
@rp.should_not be_valid\r
end\r
end\r
context 'classnameを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.classname = 'a'*50\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.classname = ''\r
@rp.should_not be_valid\r
end\r
end\r
context 'creditを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.credit = 'a'\r
- @rp.should be_valid\r
- end\r
end\r
context 'settingsを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.settings = 'a'\r
- @rp.should be_valid\r
- end\r
end\r
context 'picture_idを検証するとき' do\r
- it 'テストデータの確認' do\r
- @rp.picture_id = @p.id\r
- @rp.should be_valid\r
- end\r
it 'nullなら失敗する' do\r
@rp.picture_id = nil\r
@rp.should_not be_valid\r
end\r
end\r
\r
- describe 'データ補充に於いて' do\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\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
+ 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\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, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\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
- it '指定の素材を返す' do\r
- pic = ResourcePicture.show @rp.id\r
- pic.should eq @rp\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\r
- context '関連テーブルオプションがないとき' do\r
- it 'ライセンスと絵師を含んでいる' do\r
- r = ResourcePicture.show_include_opt\r
- r.should eq [:license, :artist]\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
- it 'ライセンスと絵師と原画データを含んでいる' do\r
- r = ResourcePicture.show_include_opt(:include => :original_picture)\r
- r.should eq [:license, :artist, :original_picture]\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
- it '404RecordNotFound例外を返す' do\r
- lambda{\r
- pic = ResourcePicture.show 0\r
- }.should raise_error(ActiveRecord::RecordNotFound)\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
- describe 'json単体出力オプションに於いて' do\r
- it 'includeキーがライセンスと絵師を含んでいる' do\r
- r = ResourcePicture.show_json_include_opt\r
- r[:include].should eq [:license, :artist]\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\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\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\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\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\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')\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
end\r
end\r
it 'リストを返す' do\r
- pic = ResourcePicture.list\r
- pic.should eq [@rp]\r
+ r = ResourcePicture.list\r
+ r.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
- pic = ResourcePicture.list\r
- pic.should eq [nrp, @rp]\r
+ r = ResourcePicture.list\r
+ r.should eq [nrp, @rp]\r
end\r
context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
before do\r
ResourcePicture.stub(:default_page_size).and_return(2)\r
end\r
it '通常は2件を返す' do\r
- pic = ResourcePicture.list\r
- pic.should have(2).items \r
+ r = ResourcePicture.list\r
+ r.should have(2).items \r
end\r
it 'page=1なら末尾2件を返す' do\r
#時系列で並んでいる\r
- pic = ResourcePicture.list({}, 1)\r
- pic.should eq [@nrp5, @nrp4]\r
+ r = ResourcePicture.list(1)\r
+ r.should eq [@nrp5, @nrp4]\r
end\r
it 'page=2なら中間2件を返す' do\r
- pic = ResourcePicture.list({}, 2)\r
- pic.should eq [@nrp3, @nrp2]\r
+ r = ResourcePicture.list(2)\r
+ r.should eq [@nrp3, @nrp2]\r
end\r
it 'page=3なら先頭1件を返す' do\r
- pic = ResourcePicture.list({}, 3)\r
- pic.should eq [@rp]\r
+ r = ResourcePicture.list(3)\r
+ r.should eq [@rp]\r
end\r
end\r
end\r
- describe 'json一覧出力オプションに於いて' do\r
- it 'includeキーがライセンスと絵師を含んでいる' do\r
- r = ResourcePicture.list_json_opt\r
- r[:include].should eq [:license, :artist]\r
- end\r
- end\r
\r
- describe 'サイズの調整に於いて' do\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
- \r
- it 'サイズに収まるときはそのまま使う' do\r
- ResourcePicture.fix_size_both(64, 64, 64, 64).should eq [64, 64]\r
- end\r
- it '小さくても拡大しない' do\r
- ResourcePicture.fix_size_both(64, 64, 32, 32).should eq [32, 32]\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
- ResourcePicture.fix_size_both(64, 64, 64, 128).should eq [32, 64]\r
+ it 'リストを返す' do\r
+ c = ResourcePicture.mylist @artist\r
+ c.should eq [@rp]\r
end\r
- it '横長のときは横に合わせて縮小' do\r
- ResourcePicture.fix_size_both(64, 64, 128, 64).should eq [64, 32]\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
- end\r
- \r
- describe 'フォーマット変換対象判定に於いて' do\r
- before do\r
- @rp = FactoryGirl.build :resource_picture, \r
- :artist_id => @artist.id, :license_id => @license.id\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 '変換するケース' do\r
- it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do\r
- ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
- @rp.ext = 'png'\r
- @rp.to_gif?.should be_true\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
- end\r
- context '変換しないケース' do\r
- it '画像フォーマットがでない' do\r
- ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
- @rp.ext = 'gif'\r
- @rp.to_gif?.should be_false\r
+ it '通常は2件を返す' do\r
+ c = ResourcePicture.mylist @artist, 1, 2\r
+ c.should have(2).items \r
end\r
- it '変換禁止フラグが無効' do\r
- ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)\r
- @rp.ext = 'png'\r
- @rp.to_gif?.should be_false\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 'Gifフォーマット変換に於いて' do\r
+ describe '他作家の素材一覧取得に於いて' do\r
before do\r
- Magick::Image.stub(:from_blob).with(any_args).and_return([Mgk.new])\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 'Mgkオブジェクトが返る' do\r
- mgk = ResourcePicture.png_to_gif('mgkbin')\r
- mgk.is_a?(Mgk).should be_true\r
- end\r
- it 'Mgkオブジェクトはgif変換されている' do\r
- #スタブばかりで変換できないので代入されているかでチェックする\r
- Mgk.any_instance.should_receive(:format=).with('gif').exactly(1)\r
- ResourcePicture.png_to_gif('mgkbin')\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
- context 'RMagick変換が失敗したとき' do\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
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\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 'falseを返す' do\r
- res = ResourcePicture.png_to_gif('mgkbin')\r
- res.should be_false\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
+ describe '一覧ページ制御に於いて' do\r
before do\r
- @op = FactoryGirl.create :original_picture, :ext => 'jpeg', :width => 264, :height => 265, :filesize => 266, \r
- :artist_id => @artist.id\r
- @rp = FactoryGirl.build :resource_picture, \r
- :artist_id => @artist.id\r
- end\r
- it '原画オブジェクトから属性を取り出して対象素材にセットしている' do\r
- res = @rp.copy_data(@op)\r
- @rp.ext.should eq 'jpeg'\r
- @rp.width.should eq 264\r
- @rp.height.should eq 265\r
- @rp.filesize.should eq 266\r
- @rp.md5.should eq @op.md5\r
- @rp.artist_id.should eq @artist.id\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 'RMagick変換に於いて' do\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 '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\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
- 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 = 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
+ @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+ @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.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
+ @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, :original_picture_id => @op.id, :license_id => @license.id, :picture_id => @p.id\r
end\r
context 'つつがなく終わるとき' do\r
- it '画像データをオブジェクト化している' do\r
- Magick::Image.stub(:from_blob).and_return(['mgkobj'])\r
- @rp.data_to_mgk('mgkbin').should eq 'mgkobj'\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
- context '失敗するとき' do\r
- it 'Falseを返す' do\r
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
- @rp.data_to_mgk('mgkbin').should be_false\r
+ it '指定の素材を返す' do\r
+ r = ResourcePicture.show @rp.id, @author\r
+ r.should eq @rp\r
+ end\r
+ 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
- it '全体エラーがセットされている' do\r
- Magick::Image.should_receive(:from_blob).with(any_args).and_raise('StandardError')\r
- lambda {\r
- @rp.data_to_mgk('mgkbin')\r
- }.should change(@rp.errors[:base], :count)\r
+ end\r
+ context '存在しない素材を開こうとしたとき' do\r
+ it '404RecordNotFound例外を返す' do\r
+ lambda{\r
+ r = ResourcePicture.show 0, @author\r
+ }.should raise_error(ActiveRecord::RecordNotFound)\r
end\r
end\r
end\r
- describe '画像オブジェクトの取得に於いて' do\r
+ describe '単体取得オプションに於いて' do\r
+ 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\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
- 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 = 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
+ @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+ @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.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
- context '事前チェック' do\r
- before do\r
- OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
- ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(Mgk.new)\r
- end\r
- it '原画から画像データを取得している' do\r
- OriginalPicture.any_instance.should_receive(:restore).with(any_args).exactly(1)\r
- res = @rp.op_mgk\r
- end\r
- it '素材に原画データのRMagick変換を依頼している' do\r
- ResourcePicture.any_instance.should_receive(:data_to_mgk).with(any_args).exactly(1)\r
- res = @rp.op_mgk\r
+ end\r
+ \r
+ describe 'フォーマット変換対象判定に於いて' do\r
+ before do\r
+ @rp = FactoryGirl.build :resource_picture, \r
+ :artist_id => @artist.id, :license_id => @license.id\r
+ end\r
+ context '変換するケース' do\r
+ it '画像フォーマットがpngかつライセンスの変換禁止フラグが無効のときTrue' do\r
+ ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
+ @rp.ext = 'png'\r
+ @rp.to_gif?.should be_true\r
end\r
end\r
- context 'つつがなく終わるとき' do\r
- #原画から画像データを取得する。\r
- #素材に原画データのRMagick変換を依頼し、画像オブジェクトを返す。 \r
- before do\r
- @mgk = Mgk.new\r
- OriginalPicture.any_instance.stub(:restore).with(any_args).and_return('data')\r
- ResourcePicture.any_instance.stub(:data_to_mgk).with(any_args).and_return(@mgk)\r
+ context '変換しないケース' do\r
+ it '画像フォーマットがでない' do\r
+ ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(0)\r
+ @rp.ext = 'gif'\r
+ @rp.to_gif?.should be_false\r
end\r
- it '画像オブジェクトを返す' do\r
- res = @rp.op_mgk\r
- res.should eq @mgk\r
+ it '変換禁止フラグが無効' do\r
+ ResourcePicture.any_instance.stub(:flag_gif_convert).with(any_args).and_return(-1)\r
+ @rp.ext = 'png'\r
+ @rp.to_gif?.should be_false\r
end\r
end\r
end\r
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
- @mgk = Mgk.new\r
+ @imager = ImagerTest.load "abc\ndef\nghi"\r
end\r
context '事前チェック' do\r
before do\r
- Picture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
Picture.any_instance.stub(:store).with(any_args).and_return(true)\r
end\r
- it '実素材に原画からのコピーデータを依頼している' do\r
- Picture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)\r
- res = @rp.new_picture @mgk\r
+ it '実素材モデルにデフォルト値補充を依頼している' do\r
+ Picture.any_instance.should_receive(:supply_default).with(any_args).exactly(1)\r
+ r = @rp.new_picture @imager\r
+ end\r
+ it '実素材モデルに上書き補充を依頼している' do\r
+ Picture.any_instance.should_receive(:overwrite).with(any_args).exactly(1)\r
+ r = @rp.new_picture @imager\r
end\r
it '実素材を保存している' do\r
Picture.any_instance.should_receive(:store).with(any_args).exactly(1)\r
- res = @rp.new_picture @mgk\r
+ r = @rp.new_picture @imager\r
end\r
end\r
context 'つつがなく終わるとき' do\r
- it '実素材に原画からのコピーデータをセットしている' do\r
- res = @rp.new_picture @mgk\r
- @rp.ext.should eq @op.ext\r
- @rp.width.should eq @op.width\r
- @rp.height.should eq @op.height\r
- @rp.filesize.should eq @op.filesize\r
- @rp.artist_id.should eq @op.artist_id\r
- @rp.original_picture_id.should eq @op.id\r
+ it '保存された実素材を返す' do\r
+ r = @rp.new_picture @imager\r
+ r.is_a?(Picture).should be_true\r
end\r
- it '実素材を返す' do\r
- res = @rp.new_picture @mgk\r
- res.is_a?(Picture).should be_true\r
+ end\r
+ #以下から例外ケース。処理先頭から失敗させていく\r
+ context '実素材の保存に失敗したとき' do\r
+ before do\r
+ Picture.any_instance.stub(:store).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.new_picture @imager\r
+ r.should be_false\r
+ end\r
+ it '自身の全体エラーメッセージにその旨をセットしている' do\r
+ r = @rp.new_picture @imager\r
+ @rp.errors[:base].should_not be_empty\r
end\r
end\r
end\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
- attr = {:original_picture_id => @op.id, :license_id => @license.id, :artist_name => 'tester', :classname => 'StandardLicense', :credit => '{}', :settings => {}.to_json.to_s}\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"\r
end\r
context '事前チェック' do\r
before do\r
#すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
#それで外部のメソッド呼び出しだけに着目してテストする。\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\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
- ResourcePicture.any_instance.stub(:copy_data).with(any_args).and_return(true)\r
- ResourcePicture.any_instance.should_receive(:copy_data).with(any_args).exactly(1)\r
- res = @rp.store\r
- end\r
- it '画像オブジェクトの取得を依頼している' do\r
- ResourcePicture.any_instance.should_receive(:op_mgk).with(any_args).exactly(1)\r
- res = @rp.store\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
- res = @rp.store\r
+ r = @rp.store @imager\r
end\r
it '自身を保存している' do\r
ResourcePicture.any_instance.should_receive(:save).with(any_args).exactly(1)\r
- res = @rp.store\r
+ r = @rp.store @imager\r
end\r
- it '画像ファイルの作成・更新機能で画像を保存している' do\r
- ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@mgk).exactly(1)\r
- res = @rp.store\r
+ it 'gif付き画像ファイルの作成・更新機能で画像を保存している' do\r
+ ResourcePicture.any_instance.should_receive(:store_picture_with_gif).with(@imager).exactly(1)\r
+ r = @rp.store @imager\r
end\r
end\r
context 'つつがなく終わるとき' do\r
before do\r
#すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\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
+ ResourcePicture.any_instance.stub(:store_picture_with_gif).with(@imager).and_return(true)\r
end\r
it 'Trueを返す' do\r
- res = @rp.store\r
- res.should be_true\r
+ r = @rp.store @imager\r
+ r.should be_true\r
end\r
- it '実素材idをセットしている' do\r
- res = @rp.store\r
- @rp.picture_id.should_not be_nil\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
- res = @rp.store\r
+ r = @rp.store @imager\r
@rp.picture_id.should eq @p.id\r
end\r
it '自身が保存されている' do\r
lambda {\r
- res = @rp.store\r
+ r = @rp.store @imager\r
}.should change ResourcePicture, :count\r
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
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(false)\r
+ @imager = false\r
end\r
it 'Falseを返す' do\r
- res = @rp.store\r
- res.should be_false\r
+ r = @rp.store @imager\r
+ r.should be_false\r
end\r
it '更新されていない' do\r
- @rp.store\r
+ r = @rp.store @imager\r
@rp.should be_a_new ResourcePicture\r
end\r
+ it '処理を中断してロールバックする' do\r
+ lambda {\r
+ r = @rp.store @imager\r
+ }.should_not change Picture, :count\r
+ end\r
end\r
context '新規実素材の取得に失敗したとき' do\r
before do\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
- ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
- Picture.any_instance.stub(:valid?).with(any_args).and_return(false)\r
+ ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(false)\r
end\r
it 'Falseを返す' do\r
- res = @rp.store\r
- res.should be_false\r
+ r = @rp.store @imager\r
+ r.should be_false\r
end\r
it '更新されていない' do\r
- @rp.store\r
+ r = @rp.store @imager\r
@rp.should be_a_new ResourcePicture\r
end\r
+ it '処理を中断してロールバックする' do\r
+ lambda {\r
+ r = @rp.store @imager\r
+ }.should_not change Picture, :count\r
+ end\r
end\r
context '自身の保存に失敗したとき' do\r
before do\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
- ResourcePicture.any_instance.stub(:op_mgk).with(any_args).and_return(@mgk)\r
ResourcePicture.any_instance.stub(:new_picture).with(any_args).and_return(@p)\r
ResourcePicture.any_instance.stub(:save).with(any_args).and_return(false)\r
end\r
it 'Falseを返す' do\r
- res = @rp.store\r
- res.should be_false\r
+ r = @rp.store @imager\r
+ r.should be_false\r
end\r
it '更新されていない' do\r
- @rp.store\r
+ r = @rp.store @imager\r
@rp.should be_a_new ResourcePicture\r
end\r
it '処理を中断してロールバックする' do\r
lambda {\r
- res = @rp.store\r
+ r = @rp.store @imager\r
+ }.should_not change Picture, :count\r
+ end\r
+ end\r
+ context 'gif付き画像ファイルの作成・更新機能に失敗したとき' do\r
+ before do\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(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.store @imager\r
+ r.should be_false\r
+ end\r
+ it '更新されていない' do\r
+ r = @rp.store @imager\r
+ @rp.should be_a_new ResourcePicture\r
+ end\r
+ it '処理を中断してロールバックする' do\r
+ lambda {\r
+ r = @rp.store @imager\r
}.should_not change Picture, :count\r
end\r
end\r
end\r
\r
- describe '画像ファイルの作成・更新に於いて' do\r
+ describe 'gif付き画像ファイルの作成・更新に於いて' 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
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"\r
end\r
context '事前チェック' do\r
before do\r
#すべての処理が正常パターンで通過すれば、一番深い分岐まで通る。\r
#それで外部のメソッド呼び出しだけに着目してテストする。\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
- class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
- @gifmgk = GifMgk.new #パラメータを二種類用意する。\r
- ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
+ ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
+ ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
end\r
it '画像ファイルの作成・更新機能で画像を保存している' do\r
- ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
- ResourcePicture.any_instance.should_receive(:store_picture).with(@mgk, '1.png').exactly(1)\r
- res = @rp.store_picture_with_gif @mgk\r
+ #二回目の保存はgif変換の結果を渡す。\r
+ ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(2)\r
+ r = @rp.store_picture_with_gif @imager\r
end\r
it '自身にフォーマット変換対象かを問い合わせている' do\r
ResourcePicture.any_instance.should_receive(:to_gif?).with(any_args).exactly(1)\r
- res = @rp.store_picture_with_gif @mgk\r
- end\r
- it '自身にGifフォーマット変換を依頼している' do\r
- ResourcePicture.should_receive(:png_to_gif).with(any_args).exactly(1)\r
- res = @rp.store_picture_with_gif @mgk\r
+ r = @rp.store_picture_with_gif @imager\r
end\r
- it '画像ファイルの作成・更新機能でgif画像を保存している' do\r
- #二回目の保存はgif変換の結果を渡す。\r
- ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
- ResourcePicture.any_instance.should_receive(:store_picture).with(@gifmgk, '1.gif').exactly(1)\r
- res = @rp.store_picture_with_gif @mgk\r
+ it '画像ライブラリにGifフォーマット変換を依頼している' do\r
+ ImagerTest.any_instance.should_receive(:to_gif).with(any_args).exactly(1)\r
+ r = @rp.store_picture_with_gif @imager\r
end\r
end\r
context 'つつがなく終わるとき' do\r
before do\r
#すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
- class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
- @gifmgk = GifMgk.new #パラメータを二種類用意する。\r
- ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
+ ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
+ ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
end\r
it 'Trueを返す' do\r
- res = @rp.store_picture_with_gif @mgk\r
- res.should be_true\r
+ r = @rp.store_picture_with_gif @imager\r
+ r.should be_true\r
end\r
end\r
context 'gif変換なしで、つつがなく終わるとき' do\r
before do\r
#すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(false)\r
+ ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
+ ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
end\r
it 'Trueを返す' do\r
- res = @rp.store_picture_with_gif @mgk\r
- res.should be_true\r
+ r = @rp.store_picture_with_gif @imager\r
+ r.should be_true\r
end\r
it 'gif保存は呼ばれていない' do\r
ResourcePicture.any_instance.should_receive(:store_picture).with(any_args).exactly(1)\r
- res = @rp.store_picture_with_gif @mgk\r
+ r = @rp.store_picture_with_gif @imager\r
end\r
end\r
#以下から例外ケース。処理先頭から失敗させていく\r
context '画像の保存に失敗したとき' do\r
before do\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(false)\r
end\r
it 'Falseを返す' do\r
- res = @rp.store_picture_with_gif @mgk\r
- res.should be_false\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
- res = @rp.store_picture_with_gif @mgk\r
+ r = @rp.store_picture_with_gif @imager\r
end\r
end\r
context 'gif変換に失敗したとき' do\r
before do\r
- @mgk = Mgk.new #一回目の本画像保存は与えたオブジェクトを使って保存する。\r
ResourcePicture.any_instance.stub(:store_picture).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
- ResourcePicture.stub(:png_to_gif).with(any_args).and_return(false)\r
+ ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(false)\r
end\r
it 'Falseを返す' do\r
- res = @rp.store_picture_with_gif @mgk\r
- res.should be_false\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
- res = @rp.store_picture_with_gif @mgk\r
+ r = @rp.store_picture_with_gif @imager\r
end\r
end\r
context 'gif画像の保存に失敗したとき' do\r
before do\r
+ ResourcePicture.any_instance.stub(:store_picture).with(@imager, '1.png').and_return(true)\r
+ ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
+ @gifimager = @imager.to_gif\r
+ ImagerTest.any_instance.stub(:to_gif).with(any_args).and_return(@gifimager)\r
+ ResourcePicture.any_instance.stub(:store_picture).with(@gifimager, '1.gif').and_return(false)\r
ResourcePicture.any_instance.stub(:filename).with(any_args).and_return('1.png')\r
ResourcePicture.any_instance.stub(:gifname).with(any_args).and_return('1.gif')\r
- @mgk = Mgk.new\r
- ResourcePicture.any_instance.stub(:store_picture).with(@mgk, '1.png').and_return(true)\r
- ResourcePicture.any_instance.stub(:to_gif?).with(any_args).and_return(true)\r
- class GifMgk < Mgk ; end #store_pictureは二回呼び出される。区別をつけるために\r
- @gifmgk = GifMgk.new #パラメータを二種類用意する。\r
- ResourcePicture.stub(:png_to_gif).with(any_args).and_return(@gifmgk)\r
- ResourcePicture.any_instance.stub(:store_picture).with(@gifmgk, '1.gif').and_return(false)\r
end\r
it 'Falseを返す' do\r
- res = @rp.store_picture_with_gif @mgk\r
- res.should be_false\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
@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
- @rp.copy_data @op\r
+ @rp.overwrite @op\r
+ @imager = ImagerTest.load "abc\ndef\nghi"\r
end\r
context '事前チェック' do\r
before do\r
#すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
- ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')\r
end\r
it 'サムネイル化が1回呼ばれる' do\r
- ResourcePicture.any_instance.should_receive(:thumbnail).with(any_args).exactly(1)\r
- res = @rp.store_picture(Mgk.new, '1.gif')\r
+ ImagerTest.any_instance.should_receive(:to_thumbnail).with(any_args).exactly(1)\r
+ r = @rp.store_picture(@imager, '1.png')\r
end\r
it '画像ファイルの保存が2回呼ばれる' do\r
PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(2)\r
- res = @rp.store_picture(Mgk.new, '1.gif')\r
+ r = @rp.store_picture(@imager, '1.gif')\r
end\r
it '画像ファイルのベースへのサムネイル保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('tmbdata', '1.gif').exactly(1)\r
- res = @rp.store_picture(Mgk.new, '1.gif')\r
+ PictureIO.resource_picture_io.should_receive(:put).with(@imager.to_thumbnail.binary, '1.gif').exactly(1)\r
+ r = @rp.store_picture(@imager, '1.gif')\r
end\r
it '画像ファイルのfullへの保存が1回呼ばれる' do\r
- PictureIO.resource_picture_io.should_receive(:put).with('data', '1.gif', 'full').exactly(1)\r
- res = @rp.store_picture(Mgk.new, '1.gif')\r
+ PictureIO.resource_picture_io.should_receive(:put).with(@imager.binary, '1.gif', 'full').exactly(1)\r
+ r = @rp.store_picture(@imager, '1.gif')\r
end\r
end\r
context 'つつがなく終わるとき' do\r
#すべての処理を正常パターンで通過させ、保存機能をチェックする。\r
PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(true)\r
ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
- ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')\r
end\r
it 'Trueを返す' do\r
- res = @rp.store_picture(Mgk.new, '1.gif')\r
- res.should be_true\r
+ r = @rp.store_picture(@imager, '1.gif')\r
+ r.should be_true\r
+ end\r
+ end\r
+ #以下から例外ケース。処理先頭から失敗させていく\r
+ context 'サムネイル化に失敗したとき' do\r
+ before do\r
+ ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
+ ImagerTest.any_instance.stub(:to_thumbnail).with(any_args).and_return(false)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.store_picture(@imager, '1.gif')\r
+ r.should be_false\r
+ end\r
+ it '画像ファイルの保存は呼ばれていない' do\r
+ PictureIO.resource_picture_io.should_not_receive(:put).with(any_args)\r
+ r = @rp.store_picture(@imager, '1.gif')\r
+ end\r
+ end\r
+ context 'サムネイル画像の保存に失敗したとき' do\r
+ before do\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_raise(PictureIO::Error)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.store_picture(@imager, '1.gif')\r
+ r.should be_false\r
+ end\r
+ it '画像ファイルの保存は呼ばれていない' do\r
+ PictureIO.resource_picture_io.should_receive(:put).with(any_args).exactly(1)\r
+ r = @rp.store_picture(@imager, '1.gif')\r
end\r
end\r
- context '例外ケース' do\r
+ context '画像の保存に失敗したとき' do\r
before do\r
ResourcePicture.any_instance.stub(:flag_thumbnail).with(any_args).and_return(1)\r
- ResourcePicture.any_instance.stub(:thumbnail).with(any_args).and_return('tmbdata')\r
- PictureIO.resource_picture_io.stub(:put).with(any_args).and_return(false)\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_raise(PictureIO::Error)\r
end\r
- it '画像の保存に失敗したならFalseを返す' do\r
- res = @rp.store_picture(Mgk.new, '1.gif')\r
- res.should be_false\r
+ it 'Falseを返す' do\r
+ r = @rp.store_picture(@imager, '1.gif')\r
+ r.should be_false\r
end\r
end\r
\r
end\r
\r
- describe 'サムネイル変換に於いて' do\r
- #サムネイル化した画像データを返すが、スタブをおくので、リサイズと画像データ化を試みるかをチェックする\r
+ describe '公開停止に於いて' do\r
before do\r
- ResourcePicture.stub(:resize).with(any_args).and_return(Mgk.new)\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
- 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 = 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
- it 'サムネイルサイズに縮小した画像データを返す' do\r
- ResourcePicture.should_receive(:resize).with(any_args).exactly(1)\r
- @rp.thumbnail(Mgk.new)\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
- it 'データが返る' do\r
- #全体スタブより\r
- @rp.thumbnail(Mgk.new).should eq 'data'\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