X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=spec%2Fmodels%2Fground_picture_spec.rb;h=886982ae1f4756f2d7ac4758bc0f7b07b4ab73a9;hb=eb397c27a98c59c856b91a5b09d1316b1135a15c;hp=e2e449f3706caa408b231bab245b977555ef3372;hpb=c2af7cf1ff49dcf8f3c902a718d6842793af4f39;p=pettanr%2Fpettanr.git diff --git a/spec/models/ground_picture_spec.rb b/spec/models/ground_picture_spec.rb index e2e449f3..886982ae 100644 --- a/spec/models/ground_picture_spec.rb +++ b/spec/models/ground_picture_spec.rb @@ -1,15 +1,16 @@ # -*- encoding: utf-8 -*- require 'spec_helper' -#コマの画像背景 +#絵地 describe GroundPicture do before do - FactoryGirl.create :admin + SpeechBalloonTemplate.delete_all + @admin = FactoryGirl.create :admin @user = FactoryGirl.create( :user_yas) - @author = @user.author + @author = FactoryGirl.create :author, :user_id => @user.id @artist = FactoryGirl.create :artist_yas, :author_id => @author.id @other_user = FactoryGirl.create( :user_yas) - @other_author = @other_user.author + @other_author = FactoryGirl.create :author, :user_id => @other_user.id @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id @sp = FactoryGirl.create :system_picture @lg = FactoryGirl.create :license_group @@ -27,16 +28,23 @@ describe GroundPicture do context 'オーソドックスなデータのとき' do it '下限データが通る' do + @gp.repeat = 0 + @gp.x = -99999 + @gp.y = -99999 @gp.z = 1 + @gp.t = 0 @gp.should be_valid end it '上限データが通る' do + @gp.repeat = 3 + @gp.x = 99999 + @gp.y = 99999 @gp.z = 99999 + @gp.t = 99999 @gp.should be_valid end end - context 'panel_idを検証するとき' do #ネストの保存はnilを許可しなければならないので数値チェックだけ it '数値でなければ失敗する' do @@ -58,6 +66,44 @@ describe GroundPicture do @gp.should_not be_valid end end + context 'repeatを検証するとき' do + it 'nullなら失敗する' do + @gp.repeat = nil + @gp.should_not be_valid + end + it '数値でなければ失敗する' do + @gp.repeat = 'a' + @gp.should_not be_valid + end + it '-1なら失敗する' do + @gp.repeat = -1 + @gp.should_not be_valid + end + it '4なら失敗する' do + @gp.repeat = 4 + @gp.should_not be_valid + end + end + context 'xを検証するとき' do + it 'nullなら失敗する' do + @gp.x = nil + @gp.should_not be_valid + end + it '数値でなければ失敗する' do + @gp.x = 'a' + @gp.should_not be_valid + end + end + context 'yを検証するとき' do + it 'nullなら失敗する' do + @gp.y = nil + @gp.should_not be_valid + end + it '数値でなければ失敗する' do + @gp.y = 'a' + @gp.should_not be_valid + end + end context 'zを検証するとき' do it 'nullなら失敗する' do @gp.z = nil @@ -76,19 +122,137 @@ describe GroundPicture do @gp.should_not be_valid end end + context 'tを検証するとき' do + it 'nullなら失敗する' do + @gp.t = nil + @gp.should_not be_valid + end + it '数値でなければ失敗する' do + @gp.t = 'a' + @gp.should_not be_valid + end + it '負なら失敗する' do + @gp.t = -1 + @gp.should_not be_valid + end + end + end + + describe '文字コード検証に於いて' do + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + end + + context 'captionを検証するとき' do + it 'Shift JISなら失敗する' do + @gp.caption = "\x83G\x83r\x83]\x83D" + lambda{ + @gp.valid_encode + }.should raise_error(Pettanr::BadRequest) + end + end end describe 'デフォルト値補充に於いて' do - it 'defined' do - @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + end + it 'xに0を補充している' do + @gp.supply_default + @gp.x.should eq 0 + end + it 'yに0を補充している' do + @gp.supply_default + @gp.y.should eq 0 + end + it '繰り返しに0を補充している' do @gp.supply_default + @gp.repeat.should eq 0 end end describe '上書き補充に於いて' do - it 'defined' do + it 'panel_idが設定されている' do @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id - @gp.overwrite + @gp.overwrite @panel.id + @gp.panel_id.should eq @panel.id + end + end + + describe '閲覧許可に於いて' do + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + end + context 'オープンモードのとき' do + before do + MagicNumber['run_mode'] = 0 + end + it '自身にゲスト用ロールチェックを問い合わせしている' do + GroundPicture.any_instance.stub(:guest_role_check).and_return(true) + GroundPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1) + r = @gp.visible?([@author]) + end + it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do + GroundPicture.any_instance.stub(:guest_role_check).and_return(false) + r = @gp.visible?([@author]) + r.should be_false + end + end + context 'クローズドモードのとき' do + before do + MagicNumber['run_mode'] = 1 + end + it '自身に読者用ロールチェックを問い合わせしている' do + GroundPicture.any_instance.stub(:reader_role_check).and_return(true) + GroundPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1) + r = @gp.visible?([@author]) + end + it '読者用ロールチェックが失敗したとき、falseを返す' do + GroundPicture.any_instance.stub(:reader_role_check).and_return(false) + r = @gp.visible?([@author]) + r.should be_false + end + end + context '事前チェックする' do + before do + MagicNumber['run_mode'] = 1 + GroundPicture.any_instance.stub(:reader_role_check).and_return(true) + end + it '自身のコマに所持判定を問い合わせしている' do + Panel.any_instance.stub(:own?).and_return(true) + Panel.any_instance.should_receive(:own?).with(any_args).exactly(1) + r = @gp.visible?([@author]) + end + it '自身のコマに閲覧許可を問い合わせしている' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:visible?).and_return(true) + Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1) + r = @gp.visible?([@author]) + end + end + context 'つつがなく終わるとき' do + before do + MagicNumber['run_mode'] = 1 + Panel.any_instance.stub(:reader_role_check).and_return(true) + end + it '自分のコマの絵地なら許可する' do + Panel.any_instance.stub(:own?).and_return(true) + Panel.any_instance.stub(:visible?).and_return(false) + r = @gp.visible?([@author]) + r.should be_true + end + it '他人の非公開コマの絵地なら許可しない' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:visible?).and_return(false) + r = @gp.visible?([@author]) + r.should be_false + end + it '他人のコマの絵地でも公開なら許可する' do + Panel.any_instance.stub(:own?).and_return(false) + Panel.any_instance.stub(:visible?).and_return(true) + r = @gp.visible?([@author]) + r.should be_true + end end end @@ -121,13 +285,13 @@ describe GroundPicture do GroundPicture.page_size('1000').should eq GroundPicture.max_page_size end end - context 'つつがなく終わるとき' do - it '一覧取得オプションを利用している' do - GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) - GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) + GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) r = GroundPicture.list - end - end + end + end it 'リストを返す' do pl = GroundPicture.list pl.should eq [@gp] @@ -139,7 +303,7 @@ describe GroundPicture do pl = GroundPicture.list pl.should eq [npl, @gp] end - it '非公開のコマの景色は含まない' do + it '非公開のコマの絵地は含まない' do hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100 pl = GroundPicture.list @@ -171,59 +335,211 @@ describe GroundPicture do pl.should eq [@gp] end end - context 'DBに5件あって1ページの件数を0件に変えたとして' do + end + + describe '自分のコマで使った絵地一覧取得に於いて' do + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + end + context 'つつがなく終わるとき' do + it '一覧取得オプションを利用している' do + GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) + GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) + r = GroundPicture.mylist @author + end + end + it 'リストを返す' do + pl = GroundPicture.mylist @author + pl.should eq [@gp] + end + it '時系列で並んでいる' do + npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100 + pl = GroundPicture.mylist @author + pl.should eq [npl, @gp] + end + it '他人のコマの絵地は公開でも含まない' do + hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id + pl = GroundPicture.mylist @author + pl.should eq [@gp] + end + it '自分のコマの絵地は非公開でも含んでいる' do + hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 + npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100 + pl = GroundPicture.mylist @author + pl.should eq [npl, @gp] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do before do @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 - GroundPicture.stub(:default_page_size).and_return(2) end - it '通常は全件(5件)を返す' do - r = GroundPicture.list 5, 0 - r.should have(5).items + it '通常は2件を返す' do + c = GroundPicture.mylist @author, 1, 2 + c.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + c = GroundPicture.mylist(@author, 1, 2) + c.should eq [@gp5, @gp4] + end + it 'page=2なら中間2件を返す' do + c = GroundPicture.mylist(@author, 2, 2) + c.should eq [@gp3, @gp2] + end + it 'page=3なら先頭1件を返す' do + c = GroundPicture.mylist(@author, 3, 2) + c.should eq [@gp] end end end - describe '一覧取得オプションに於いて' do - it 'includeキーを含んでいる' do - r = GroundPicture.list_opt - r.has_key?(:include).should be_true + + describe '他作家の絵地一覧取得に於いて' do + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 + @other_gp = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id + end + it 'リストを返す' do + r = GroundPicture.himlist @other_author + r.should eq [@other_gp] + end + it '時系列で並んでいる' do + new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100 + new_gp = FactoryGirl.create :ground_picture, :panel_id => new_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100 + r = GroundPicture.himlist @other_author + r.should eq [new_gp, @other_gp] end + it '公開コマに限る' do + hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0 + hidden_gp = FactoryGirl.create :ground_picture, :panel_id => hidden_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100 + r = GroundPicture.himlist @other_author + r.should eq [@other_gp] + end + context 'DBに5件あって1ページの件数を2件に変えたとして' do + before do + @other_gp2 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100 + @other_gp3 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 200 + @other_gp4 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 300 + @other_gp5 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 400 + end + it '通常は2件を返す' do + pl = GroundPicture.himlist @other_author, 1, 2 + pl.should have(2).items + end + it 'page=1なら末尾2件を返す' do + #時系列で並んでいる + pl = GroundPicture.himlist @other_author, 1, 2 + pl.should eq [@other_gp5, @other_gp4] + end + it 'page=2なら中間2件を返す' do + pl = GroundPicture.himlist @other_author, 2, 2 + pl.should eq [@other_gp3, @other_gp2] + end + it 'page=3なら先頭1件を返す' do + pl = GroundPicture.himlist @other_author, 3, 2 + pl.should eq [@other_gp] + end + end + end + + describe '絵地一覧ページ制御に於いて' do + before do + GroundPicture.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = GroundPicture.list_paginate + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it '絵地一覧の取得条件を利用している' do + GroundPicture.stub(:list_where).with(any_args).and_return('') + GroundPicture.should_receive(:list_where).with(any_args).exactly(1) + r = GroundPicture.list_paginate + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = GroundPicture.list_paginate 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 + end + end + + describe '自分の絵地一覧ページ制御に於いて' do + before do + GroundPicture.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = GroundPicture.mylist_paginate @author + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it '自分の絵地一覧の取得条件を利用している' do + GroundPicture.stub(:mylist_where).with(any_args).and_return('') + GroundPicture.should_receive(:mylist_where).with(any_args).exactly(1) + r = GroundPicture.mylist_paginate @author + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = GroundPicture.mylist_paginate @author, 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 + end + end + + describe '他作家の絵地一覧ページ制御に於いて' do + before do + GroundPicture.stub(:count).with(any_args).and_return(100) + end + it 'ページ制御を返す' do + r = GroundPicture.himlist_paginate @other_author + r.is_a?(Kaminari::PaginatableArray).should be_true + end + it '他作家の絵地一覧の取得条件を利用している' do + GroundPicture.stub(:himlist_where).with(any_args).and_return('') + GroundPicture.should_receive(:himlist_where).with(any_args).exactly(1) + r = GroundPicture.himlist_paginate @other_author + end + it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do + r = GroundPicture.himlist_paginate @other_author, 3, 10 + r.limit_value.should eq 10 + r.offset_value.should eq 20 + end + end + + describe '一覧取得オプションに於いて' do it '2つの項目を含んでいる' do - r = GroundPicture.list_opt[:include] + r = GroundPicture.list_opt r.should have(2).items end it 'コマを含んでいる' do - r = GroundPicture.list_opt[:include] + r = GroundPicture.list_opt r.has_key?(:panel).should be_true end it 'コマは作家を含んでいる' do - r = GroundPicture.list_opt[:include] + r = GroundPicture.list_opt r[:panel].has_key?(:author).should be_true end it '実素材を含んでいる' do - r = GroundPicture.list_opt[:include] + r = GroundPicture.list_opt r.has_key?(:picture).should be_true end it '実素材は絵師を含んでいる' do - r = GroundPicture.list_opt[:include] + r = GroundPicture.list_opt r[:picture].has_key?(:artist).should be_true end it '実素材はライセンスを含んでいる' do - r = GroundPicture.list_opt[:include] + r = GroundPicture.list_opt r[:picture].has_key?(:license).should be_true end end describe 'json一覧出力オプションに於いて' do before do - @op = FactoryGirl.create :original_picture, :artist_id => @artist.id - @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id - @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id - @sbt = FactoryGirl.create :speech_balloon_template - @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1 + @op = FactoryGirl.create :original_picture, :artist_id => @artist.id + @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id + @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id + @sbt = FactoryGirl.create :speech_balloon_template + @scroll = FactoryGirl.create :scroll, :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 + @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id end it 'コマを含んでいる' do @@ -261,77 +577,108 @@ describe GroundPicture do end end - describe '自分のコマで使った景色画像一覧取得に於いて' do + describe '単体取得に於いて' do before do @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id end - context 'つつがなく終わるとき' do - it '一覧取得オプションを利用している' do - GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel}) - GroundPicture.should_receive(:list_opt).with(any_args).exactly(1) - r = GroundPicture.mylist @author - end - end - it 'リストを返す' do - pl = GroundPicture.mylist @author - pl.should eq [@gp] - end - it '時系列で並んでいる' do - npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100 - pl = GroundPicture.mylist @author - pl.should eq [npl, @gp] + context 'つつがなく終わるとき' do + it '単体取得オプションを利用している' do + GroundPicture.stub(:show_opt).with(any_args).and_return({:include => :panel}) + GroundPicture.should_receive(:show_opt).with(any_args).exactly(1) + r = GroundPicture.show @gp.id, @author + end + it '閲覧許可を問い合わせている' do + GroundPicture.any_instance.stub(:visible?).with(any_args).and_return(true) + GroundPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1) + r = GroundPicture.show @gp.id, @author + end end - it '他人のコマの景色は公開でも含まない' do - hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1 - npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id - pl = GroundPicture.mylist @author - pl.should eq [@gp] + it '指定の絵地を返す' do + GroundPicture.any_instance.stub(:visible?).and_return(true) + pl = GroundPicture.show @gp.id, @author + pl.should eq @gp end - it '自分のコマの景色は非公開でも含んでいる' do - hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0 - npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100 - pl = GroundPicture.mylist @author - pl.should eq [npl, @gp] + context '閲覧許可が出なかったとき' do + it '403Forbidden例外を返す' do + GroundPicture.any_instance.stub(:visible?).and_return(false) + lambda{ + GroundPicture.show @gp.id, @author + }.should raise_error(ActiveRecord::Forbidden) + end end - context 'DBに5件あって1ページの件数を2件に変えたとして' do - before do - @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100 - @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 - @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 - @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 + context '存在しない絵地を開こうとしたとき' do + it '404RecordNotFound例外を返す' do + lambda{ + GroundPicture.show 110, @author + }.should raise_error(ActiveRecord::RecordNotFound) end - it '通常は2件を返す' do - c = GroundPicture.mylist @author, 1, 2 - c.should have(2).items + end + end + describe '単体取得オプションに於いて' do + it 'includeキーを含んでいる' do + r = GroundPicture.show_opt + r.has_key?(:include).should be_true + end + it '2つの項目を含んでいる' do + r = GroundPicture.show_opt[:include] + r.should have(2).items + end + it 'コマを含んでいる' do + r = GroundPicture.show_opt[:include] + r.has_key?(:panel).should be_true + end + it 'コマは作家を含んでいる' do + r = GroundPicture.show_opt[:include] + r[:panel].has_key?(:author).should be_true end - it 'page=1なら末尾2件を返す' do - #時系列で並んでいる - c = GroundPicture.mylist(@author, 1, 2) - c.should eq [@gp5, @gp4] + it '実素材を含んでいる' do + r = GroundPicture.show_opt[:include] + r.has_key?(:picture).should be_true + end + it '実素材は絵師を含んでいる' do + r = GroundPicture.show_opt[:include] + r[:picture].has_key?(:artist).should be_true end - it 'page=2なら中間2件を返す' do - c = GroundPicture.mylist(@author, 2, 2) - c.should eq [@gp3, @gp2] + it '実素材はライセンスを含んでいる' do + r = GroundPicture.show_opt[:include] + r[:picture].has_key?(:license).should be_true end - it 'page=3なら先頭1件を返す' do - c = GroundPicture.mylist(@author, 3, 2) - c.should eq [@gp] + end + describe 'json単体出力オプションに於いて' do + before do + @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id + end + it 'コマを含んでいる' do + r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt + j = JSON.parse r + i = j + i.has_key?('panel').should be_true + end + it 'コマは作家を含んでいる' do + r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt + j = JSON.parse r + i = j + s = i['panel'] + s.has_key?('author').should be_true end + it '実素材を含んでいる' do + r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt + j = JSON.parse r + i = j + i.has_key?('picture').should be_true end - context 'DBに5件あって1ページの件数を0件に変えたとして' do - before do - @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100 - @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200 - @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300 - @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400 - Author.stub(:default_ground_picture_page_size).and_return(2) + it '実素材は絵師を含んでいる' do + r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt + j = JSON.parse r + i = j['picture'] + i.has_key?('artist').should be_true end - it '通常は全件(5件)を返す' do - r = GroundPicture.mylist @author, 5, 0 - r.should have(5).items + it '実素材はライセンスを含んでいる' do + r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt + j = JSON.parse r + i = j['picture'] + i.has_key?('license').should be_true end - end end - end