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\r
+ \r
+ context 'artist_nameを検証するとき' do\r
+ it 'Shift JISなら失敗する' do\r
+ @rp.artist_name = "\x83G\x83r\x83]\x83D"\r
+ lambda{\r
+ @rp.valid_encode\r
+ }.should raise_error(Pettanr::BadRequest)\r
+ end\r
+ end\r
+ \r
+ context 'classnameを検証するとき' do\r
+ it 'Shift JISなら失敗する' do\r
+ @rp.classname = "\x83G\x83r\x83]\x83D"\r
+ lambda{\r
+ @rp.valid_encode\r
+ }.should raise_error(Pettanr::BadRequest)\r
+ end\r
+ end\r
+ \r
+ context 'creditを検証するとき' do\r
+ it 'Shift JISなら失敗する' do\r
+ @rp.credit = "\x83G\x83r\x83]\x83D"\r
+ lambda{\r
+ @rp.valid_encode\r
+ }.should raise_error(Pettanr::BadRequest)\r
+ end\r
+ end\r
+ \r
+ context 'settingsを検証するとき' do\r
+ it 'Shift JISなら失敗する' do\r
+ @rp.settings = "\x83G\x83r\x83]\x83D"\r
+ lambda{\r
+ @rp.valid_encode\r
+ }.should raise_error(Pettanr::BadRequest)\r
+ end\r
+ end\r
+ \r
+ end\r
+ \r
describe 'デフォルト値補充に於いて' do\r
it 'defined' do\r
@p = FactoryGirl.create :picture, :original_picture_id => @original_picture.id, :license_id => @license.id, :artist_id => @artist.id\r
@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 '素材を更新することはないので、Falseを返す' do\r
- @rp.own?(@author).should == false\r
+ context '事前チェックする' do\r
+ it '自身にロールリストからの絵師取得を依頼している' do\r
+ ResourcePicture.should_receive(:get_artist_from_roles).with(any_args).exactly(1)\r
+ r = @rp.own?([@author])\r
+ end\r
+ end\r
+ context 'ロール内絵師が取得できるとき' do\r
+ before do\r
+ end\r
+ it 'ロール内絵師のidが自身の絵師idと一致するなら許可する' do\r
+ ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@artist)\r
+ r = @rp.own?([@author])\r
+ r.should be_true\r
+ end\r
+ it 'ロール内絵師のidが自身の絵師idと一致しないならno' do\r
+ ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(@other_artist)\r
+ @rp.own?(@other_artist).should be_false\r
+ end\r
+ end\r
+ context 'ロール内絵師が取得できないとき' do\r
+ before do\r
+ ResourcePicture.stub(:get_artist_from_roles).with(any_args).and_return(nil)\r
+ end\r
+ it 'Falseを返す' do\r
+ r = @rp.own?([@author])\r
+ r.should be_false\r
+ end\r
end\r
end\r
\r
@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 '検査対象が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
+ 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
- it '不許可を返す。' do\r
- r = @rp.visible?(@admin)\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
r.should eq [@rp]\r
end\r
end\r
- 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
- @nrp3 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop3.id, :picture_id => @p.id, :updated_at => Time.now + 200\r
- nop4 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
- @nrp4 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop4.id, :picture_id => @p.id, :updated_at => Time.now + 300\r
- nop5 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
- @nrp5 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => nop5.id, :picture_id => @p.id, :updated_at => Time.now + 400\r
- ResourcePicture.stub(:default_page_size).and_return(2)\r
- end\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
- 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
- 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
c.should eq [@rp]\r
end\r
end\r
- context 'DBに5件あって1ページの件数を0件に変えたとして' do\r
+ end\r
+ \r
+ describe '他作家の素材一覧取得に於いて' do\r
+ before do\r
+ @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
+ @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
+ @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
+ @other_op = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+ @other_p = FactoryGirl.create :picture, :original_picture_id => @other_op.id, :license_id => @license.id, :artist_id => @other_artist.id\r
+ @other_rp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => @other_op.id, :picture_id => @other_p.id\r
+ end\r
+ context 'つつがなく終わるとき' do\r
+ it '一覧取得オプションを利用している' do\r
+ ResourcePicture.stub(:list_opt).with(any_args).and_return({})\r
+ ResourcePicture.should_receive(:list_opt).with(any_args).exactly(1)\r
+ r = ResourcePicture.himlist @other_artist\r
+ end\r
+ end\r
+ it '指定した作家のリストを返す' do\r
+ r = ResourcePicture.himlist @other_artist\r
+ r.should eq [@other_rp]\r
+ end\r
+ it '時系列で並んでいる' do\r
+ nop = FactoryGirl.create :original_picture, :artist_id => @other_artist.id\r
+ nrp = FactoryGirl.create :resource_picture, :artist_id => @other_artist.id, :license_id => @license.id, :original_picture_id => nop.id, :picture_id => @other_p.id, :updated_at => Time.now + 100\r
+ r = ResourcePicture.himlist @other_artist\r
+ r.should eq [nrp, @other_rp]\r
+ end\r
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
before do\r
- @op2 = FactoryGirl.create :original_picture, :artist_id => @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
+ @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 '通常は全件(5件)を返す' do\r
- r = ResourcePicture.mylist @artist, 5, 0\r
- r.should have(5).items \r
+ it 'page=1なら末尾2件を返す' do\r
+ #時系列で並んでいる\r
+ r = ResourcePicture.himlist(@other_artist, 1, 2)\r
+ r.should eq [@rp5, @rp4]\r
+ end\r
+ it 'page=2なら中間2件を返す' do\r
+ r = ResourcePicture.himlist(@other_artist, 2, 2)\r
+ r.should eq [@rp3, @rp2]\r
end\r
+ it 'page=3なら先頭1件を返す' do\r
+ r = ResourcePicture.himlist(@other_artist, 3, 2)\r
+ r.should eq [@other_rp]\r
+ end\r
+ end\r
+ end\r
+ \r
+ describe '一覧ページ制御に於いて' do\r
+ before do\r
+ ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+ end\r
+ it 'ページ制御を返す' do\r
+ r = ResourcePicture.list_paginate\r
+ r.is_a?(Kaminari::PaginatableArray).should be_true\r
+ end\r
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+ r = ResourcePicture.list_paginate 3, 10\r
+ r.limit_value.should eq 10\r
+ r.offset_value.should eq 20\r
+ end\r
+ end\r
+ \r
+ describe '自分の素材一覧ページ制御に於いて' do\r
+ before do\r
+ ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+ end\r
+ it 'ページ制御を返す' do\r
+ r = ResourcePicture.mylist_paginate @artist\r
+ r.is_a?(Kaminari::PaginatableArray).should be_true\r
+ end\r
+ it '自分の素材一覧の取得条件を利用している' do\r
+ ResourcePicture.stub(:mylist_where).with(any_args).and_return('')\r
+ ResourcePicture.should_receive(:mylist_where).with(any_args).exactly(1)\r
+ r = ResourcePicture.mylist_paginate @artist\r
+ end\r
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+ r = ResourcePicture.mylist_paginate @artist, 3, 10\r
+ r.limit_value.should eq 10\r
+ r.offset_value.should eq 20\r
+ end\r
+ end\r
+ \r
+ describe '他作家の素材一覧ページ制御に於いて' do\r
+ before do\r
+ ResourcePicture.stub(:count).with(any_args).and_return(100)\r
+ end\r
+ it 'ページ制御を返す' do\r
+ r = ResourcePicture.himlist_paginate @other_artist\r
+ r.is_a?(Kaminari::PaginatableArray).should be_true\r
+ end\r
+ it '他作家の素材一覧の取得条件を利用している' do\r
+ ResourcePicture.stub(:himlist_where).with(any_args).and_return('')\r
+ ResourcePicture.should_receive(:himlist_where).with(any_args).exactly(1)\r
+ r = ResourcePicture.himlist_paginate @other_artist\r
+ end\r
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
+ r = ResourcePicture.himlist_paginate @other_artist, 3, 10\r
+ r.limit_value.should eq 10\r
+ r.offset_value.should eq 20\r
+ end\r
+ end\r
+ \r
+ describe '一覧取得オプションに於いて' do\r
+ it '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
+ @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