\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
@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
@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
end\r
end\r
\r
- describe 'デフォルト値補充に於いて' do
- it 'defined' do
+ 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
+ it '素材を更新することはないので、Falseを返す' do\r
+ @rp.own?(@author).should == false\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 '必ず許可となる' do\r
- r = @rp.visible?(@author)
- r.should == true
- end\r
- end
-
- describe 'ファイル名に於いて' do
- before do
+ end\r
+ context '検査対象がnil(ゲスト)のとき' do\r
+ context 'クローズドモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 1\r
+ end\r
+ it '不許可を返す。' do\r
+ r = @rp.visible?(nil)\r
+ r.should be_false\r
+ end\r
+ end\r
+ context 'オープンモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 0\r
+ end\r
+ it '許可する' do\r
+ r = @rp.visible?(nil)\r
+ r.should be_true\r
+ end\r
+ end\r
+ end\r
+ context '検査対象が作家のとき' do\r
+ it '許可する' do\r
+ r = @rp.visible?(@author)\r
+ r.should == true\r
+ end\r
+ end\r
+ context '検査対象がそれ以外のとき' do\r
+ it '不許可を返す。' do\r
+ r = @rp.visible?(@admin)\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.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
r.should eq [@rp]\r
end\r
end\r
- context 'DBに5件あって1ページの件数を2件に変えたとして' do
- before do
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
+ before do\r
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
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
+ it '件数0は全件(5件)を返す' do\r
+ r = ResourcePicture.list 5, 0\r
+ r.should have(5).items \r
+ end\r
+ end\r
end\r
- describe 'ä¸\80覧å\87ºå\8a\9bオプションに於いて' 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
+ describe 'ä¸\80覧å\8f\96å¾\97オプションに於いて' do\r
+ it 'includeキーを含んでいる' do\r
+ r = ResourcePicture.list_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '3つの項目を含んでいる' do\r
+ r = ResourcePicture.list_opt[:include]\r
+ r.should have(3).items\r
+ end\r
+ it 'ライセンスを含んでいる' do\r
+ r = ResourcePicture.list_opt[:include]\r
+ r.has_key?(:license).should be_true\r
+ end\r
+ it '絵師を含んでいる' do\r
+ r = ResourcePicture.list_opt[:include]\r
+ r.has_key?(:artist).should be_true\r
+ end\r
+ it '実素材を含んでいる' do\r
+ r = ResourcePicture.list_opt[:include]\r
+ r.has_key?(:picture).should be_true\r
+ end\r
end\r
describe 'json一覧出力オプションに於いて' do\r
- it 'includeキーを含んでいる' do
- r = ResourcePicture.list_json_opt
- r.has_key?(:include).should be_true
- end
- it '3つの項目を含んでいる' do
- r = ResourcePicture.list_json_opt[:include]
- r.should have(3).items
- end
- it 'ライセンスを含んでいる' do
- r = ResourcePicture.list_json_opt[:include]
- r.has_key?(:license).should be_true
- end
- it '絵師を含んでいる' do
- r = ResourcePicture.list_json_opt[:include]
- r.has_key?(:artist).should be_true
- end
- it '実素材を含んでいる' do
- r = ResourcePicture.list_json_opt[:include]
- r.has_key?(:picture).should be_true
- end
+ 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\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
+ @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
@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
end\r
end\r
end\r
- describe 'å\8d\98ä½\93å\87ºå\8a\9bオプションに於いて' 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
+ describe 'å\8d\98ä½\93å\8f\96å¾\97オプションに於いて' 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
- it 'includeキーを含んでいる' do
- r = ResourcePicture.show_json_opt
- r.has_key?(:include).should be_true
- end
- it '3つの項目を含んでいる' do
- r = ResourcePicture.show_json_opt[:include]
- r.should have(3).items
- end
- it 'ライセンスを含んでいる' do
- r = ResourcePicture.show_json_opt[:include]
- r.has_key?(:license).should be_true
- end
- it '絵師を含んでいる' do
- r = ResourcePicture.show_json_opt[:include]
- r.has_key?(:artist).should be_true
- end
- it '実素材を含んでいる' do
- r = ResourcePicture.show_json_opt[:include]
- r.has_key?(:picture).should be_true
- end
+ 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\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
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
@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
@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
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
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
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