before do\r
@admin = FactoryGirl.create :admin\r
@user = FactoryGirl.create( :user_yas)\r
- @author = @user.author\r
+ @author = FactoryGirl.create :author, :user_id => @user.id\r
@artist = FactoryGirl.create :artist_yas, :author_id => @author.id\r
@other_user = FactoryGirl.create( :user_yas)\r
- @other_author = @other_user.author\r
+ @other_author = FactoryGirl.create :author, :user_id => @other_user.id\r
@other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
@sp = FactoryGirl.create :system_picture\r
@lg = FactoryGirl.create :license_group\r
@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
- context '検査対象がnil(ゲスト)のとき' do
- context 'クローズドモードのとき' do
- before do
- MagicNumber['run_mode'] = 1
- end
+ 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.should be_false
+ r = @rp.visible?(nil)\r
+ r.should be_false\r
end\r
end\r
- context 'オープンモードのとき' do
- before do
- MagicNumber['run_mode'] = 0
- end
+ context 'オープンモードのとき' do\r
+ before do\r
+ MagicNumber['run_mode'] = 0\r
+ end\r
it '許可する' do\r
- r = @rp.visible?(nil)
- r.should be_true
+ r = @rp.visible?(nil)\r
+ r.should be_true\r
end\r
end\r
end\r
- context '検査対象が作家のとき' do
+ context '検査対象が作家のとき' do\r
it '許可する' do\r
- r = @rp.visible?(@author)
- r.should == true
+ r = @rp.visible?(@author)\r
+ r.should == true\r
end\r
end\r
- context '検査対象がそれ以外のとき' do
+ context '検査対象がそれ以外のとき' do\r
it '不許可を返す。' do\r
- r = @rp.visible?(@admin)
- r.should be_false
+ r = @rp.visible?(@admin)\r
+ r.should be_false\r
end\r
end\r
- end
-
- describe 'ファイル名に於いて' do
- before do
+ end\r
+ \r
+ describe 'ファイル名に於いて' do\r
+ before do\r
@p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
@rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
- end
- it 'id+拡張子のフォーマットで返す' do
- r = @rp.filename
- r.should eq "#{@rp.id}.png"
- end
- end
-
- describe 'MimeTypeに於いて' do
- before do
+ end\r
+ it 'id+拡張子のフォーマットで返す' do\r
+ r = @rp.filename\r
+ r.should eq "#{@rp.id}.png"\r
+ end\r
+ end\r
+ \r
+ describe 'MimeTypeに於いて' do\r
+ before do\r
@p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
@rp = FactoryGirl.build :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
- end
- it 'image/拡張子のフォーマットで返す' do
- r = @rp.mime_type
- r.should eq "image/png"
- end
- end
-
- describe 'ファイルのurlに於いて' do
- before do
+ end\r
+ it 'image/拡張子のフォーマットで返す' do\r
+ r = @rp.mime_type\r
+ r.should eq "image/png"\r
+ end\r
+ end\r
+ \r
+ describe 'ファイルのurlに於いて' do\r
+ before do\r
@p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
@rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :original_picture_id => @original_picture.id, :license_id => @license.id, :picture_id => @p.id\r
- ResourcePicture.any_instance.stub(:filename).and_return('3.gif')
- end
- it 'ファイル名取得を依頼している' do
- ResourcePicture.any_instance.should_receive(:filename).exactly(1)
- @rp.url
- end
- it '/resource_pictures/3.gifのフォーマットで返す' do
- r = @rp.url
- r.should eq "/resource_pictures/3.gif"
- end
- end
-
+ ResourcePicture.any_instance.stub(:filename).and_return('3.gif')\r
+ end\r
+ it 'ファイル名取得を依頼している' do\r
+ ResourcePicture.any_instance.should_receive(:filename).exactly(1)\r
+ @rp.url\r
+ end\r
+ it '/resource_pictures/3.gifのフォーマットで返す' do\r
+ r = @rp.url\r
+ r.should eq "/resource_pictures/3.gif"\r
+ end\r
+ end\r
+ \r
describe '一覧取得に於いて' do\r
before do\r
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
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 '一覧取得オプションに於いて' do\r
- it 'includeキーを含んでいる' do
- r = ResourcePicture.list_opt
- r.has_key?(:include).should be_true
- end
- it '3つの項目を含んでいる' do
- r = ResourcePicture.list_opt[:include]
- r.should have(3).items
- end
- it 'ライセンスを含んでいる' do
- r = ResourcePicture.list_opt[:include]
- r.has_key?(:license).should be_true
- end
- it '絵師を含んでいる' do
- r = ResourcePicture.list_opt[:include]
- r.has_key?(:artist).should be_true
- end
- it '実素材を含んでいる' do
- r = ResourcePicture.list_opt[:include]
- r.has_key?(:picture).should be_true
- end
+ it '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
- before do
+ describe 'json一覧出力オプションに於いて' do\r
+ before do\r
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
@p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
@rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
@sbt = FactoryGirl.create :speech_balloon_template\r
- @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
- @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
- @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
- end
- it 'ライセンスを含んでいる' do
- r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
- j = JSON.parse r
- i = j.first
- i.has_key?('license').should be_true
- end
- it '絵師を含んでいる' do
- r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
- j = JSON.parse r
- i = j.first
- i.has_key?('artist').should be_true
- end
- it '実素材を含んでいる' do
- r = ResourcePicture.list.to_json ResourcePicture.list_json_opt
- j = JSON.parse r
- i = j.first
- i.has_key?('picture').should be_true
- end
- end
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
+ end\r
+ it 'ライセンスを含んでいる' do\r
+ r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ i.has_key?('license').should be_true\r
+ end\r
+ it '絵師を含んでいる' do\r
+ r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ i.has_key?('artist').should be_true\r
+ end\r
+ it '実素材を含んでいる' do\r
+ r = ResourcePicture.list.to_json ResourcePicture.list_json_opt\r
+ j = JSON.parse r\r
+ i = j.first\r
+ i.has_key?('picture').should be_true\r
+ end\r
+ end\r
\r
describe '単体取得に於いて' do\r
before do\r
@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
describe '単体取得オプションに於いて' do\r
- it 'includeキーを含んでいる' do
- r = ResourcePicture.show_opt
- r.has_key?(:include).should be_true
- end
- it '3つの項目を含んでいる' do
- r = ResourcePicture.show_opt[:include]
- r.should have(3).items
- end
- it 'ライセンスを含んでいる' do
- r = ResourcePicture.show_opt[:include]
- r.has_key?(:license).should be_true
- end
- it '絵師を含んでいる' do
- r = ResourcePicture.show_opt[:include]
- r.has_key?(:artist).should be_true
- end
- it '実素材を含んでいる' do
- r = ResourcePicture.show_opt[:include]
- r.has_key?(:picture).should be_true
- end
+ it 'includeキーを含んでいる' do\r
+ r = ResourcePicture.show_opt\r
+ r.has_key?(:include).should be_true\r
+ end\r
+ it '3つの項目を含んでいる' do\r
+ r = ResourcePicture.show_opt[:include]\r
+ r.should have(3).items\r
+ end\r
+ it 'ライセンスを含んでいる' do\r
+ r = ResourcePicture.show_opt[:include]\r
+ r.has_key?(:license).should be_true\r
+ end\r
+ it '絵師を含んでいる' do\r
+ r = ResourcePicture.show_opt[:include]\r
+ r.has_key?(:artist).should be_true\r
+ end\r
+ it '実素材を含んでいる' do\r
+ r = ResourcePicture.show_opt[:include]\r
+ r.has_key?(:picture).should be_true\r
+ end\r
end\r
describe 'json単体出力オプションに於いて' do\r
- before do
+ before do\r
@op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
@p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
@rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
@sbt = FactoryGirl.create :speech_balloon_template\r
- @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
- @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
- @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
- end
- it 'ライセンスを含んでいる' do
- r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
- j = JSON.parse r
- i = j
- i.has_key?('license').should be_true
- end
- it '絵師を含んでいる' do
- r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
- j = JSON.parse r
- i = j
- i.has_key?('artist').should be_true
- end
- it '実素材を含んでいる' do
- r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt
- j = JSON.parse r
- i = j
- i.has_key?('picture').should be_true
- end
+ @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1\r
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
+ @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
+ end\r
+ it 'ライセンスを含んでいる' do\r
+ r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt\r
+ j = JSON.parse r\r
+ i = j\r
+ i.has_key?('license').should be_true\r
+ end\r
+ it '絵師を含んでいる' do\r
+ r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt\r
+ j = JSON.parse r\r
+ i = j\r
+ i.has_key?('artist').should be_true\r
+ end\r
+ it '実素材を含んでいる' do\r
+ r = ResourcePicture.show(@rp.id, @author).to_json ResourcePicture.show_json_opt\r
+ j = JSON.parse r\r
+ i = j\r
+ i.has_key?('picture').should be_true\r
+ end\r
end\r
\r
describe 'フォーマット変換対象判定に於いて' do\r
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
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