#コマ絵
describe PanelPicture 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
before do
@pp = FactoryGirl.build :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
:width => @p.width, :height => @p.height
+ Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
+ Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
+ Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
end
- it 'オーソドックスなデータなら通る' do
- @pp.save!
- @pp.should be_valid
+
+ context 'オーソドックスなデータのとき' do
+ it '下限データが通る' do
+ @pp.link = 'http://test.jp/'
+ @pp.x = -99999
+ @pp.y = -99999
+ @pp.z = 1
+ @pp.t = 0
+ @pp.width = -99999
+ @pp.height = -99999
+ @pp.should be_valid
+ end
+ it '上限データが通る' do
+ @pp.link = 'http://test.jp/aaaaa' + 'a' * 180
+ @pp.x = 99999
+ @pp.y = 99999
+ @pp.z = 99999
+ @pp.t = 99999
+ @pp.width = 99999
+ @pp.height = 99999
+ @pp.should be_valid
+ end
end
context 'panel_idを検証するとき' do
#ネストの保存はnilを許可しなければならないので数値チェックだけ
- it 'テストデータの確認' do
- @pp.panel_id = @panel.id
- @pp.should be_valid
- end
it '数値でなければ失敗する' do
@pp.panel_id = 'a'
@pp.should_not be_valid
end
end
context 'linkを検証するとき' do
- it 'テストデータの確認' do
- @pp.link = 'abcdefghi0abcdefghi0abcdefghi0abcdefghi0abcdefghi0'*4
- @pp.should be_valid
- end
it 'nullでも通る' do
@pp.link = ''
@pp.should be_valid
@pp.link = 'a'*201
@pp.should_not be_valid
end
+ it 'url形式でないなら失敗する' do
+ @pp.link = 'a'*200
+ @pp.should_not be_valid
+ end
end
context 'xを検証するとき' do
- it 'テストデータの確認' do
- @pp.x = '1'
- @pp.should be_valid
- end
it 'nullなら失敗する' do
@pp.x = nil
@pp.should_not be_valid
end
end
context 'yを検証するとき' do
- it 'テストデータの確認' do
- @pp.y = '1'
- @pp.should be_valid
- end
it 'nullなら失敗する' do
@pp.y = nil
@pp.should_not be_valid
end
end
context 'widthを検証するとき' do
- before do
- Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
- Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
- Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
- end
- it 'テストデータの確認' do
- @pp.width = 1
- @pp.should be_valid
- end
it 'nullなら失敗する' do
@pp.width = nil
@pp.should_not be_valid
end
context '反転許可のとき' do
before do
- Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
end
it '負でも通る' do
@pp.width = -1
end
context 'サイズ変更許可のとき' do
before do
- Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
end
it '実素材のサイズと違っても通る' do
@pp.width = @p.width-1
end
context '縦横比変更許可のとき' do
before do
- Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
end
it '実素材の縦横比と違っても通る' do
@pp.width = @p.width / 2
end
end
context 'heightを検証するとき' do
- before do
- Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
- Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
- Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
- end
- it 'テストデータの確認' do
- @pp.height = '1'
- @pp.should be_valid
- end
it 'nullなら失敗する' do
@pp.height = nil
@pp.should_not be_valid
end
context '反転許可のとき' do
before do
- Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
end
it '負でも通る' do
@pp.height = -1
end
context 'サイズ変更許可のとき' do
before do
- Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
end
it '実素材のサイズと違っても通る' do
@pp.height = @p.height-1
end
context '縦横比変更許可のとき' do
before do
- Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
end
it '実素材の縦横比と違っても通る' do
@pp.height = @p.height / 2
end
end
context 'zを検証するとき' do
- it 'テストデータの確認' do
- @pp.z = 1
- @pp.should be_valid
- end
it 'nullなら失敗する' do
@pp.z = nil
@pp.should_not be_valid
end
end
context 'tを検証するとき' do
- it 'テストデータの確認' do
- @pp.t = 0
- @pp.should be_valid
- end
it 'nullなら失敗する' do
@pp.t = nil
@pp.should_not be_valid
@pp.should_not be_valid
end
end
+ context 'picture_idを検証するとき' do
+ it 'nullなら失敗する' do
+ @pp.picture_id = nil
+ @pp.should_not be_valid
+ end
+ it '数値でなければ失敗する' do
+ @pp.picture_id = 'a'
+ @pp.should_not be_valid
+ end
+ it '存在する実素材でなければ失敗する' do
+ @pp.picture_id = 0
+ @pp.should_not be_valid
+ end
+ end
+ end
+
+ describe '文字コード検証に於いて' do
+ before do
+ @pp = FactoryGirl.build :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ end
+
+ context 'linkを検証するとき' do
+ it 'Shift JISなら失敗する' do
+ @pp.link = "\x83G\x83r\x83]\x83D"
+ lambda{
+ @pp.valid_encode
+ }.should raise_error(Pettanr::BadRequest)
+ end
+ end
+
+ context 'captionを検証するとき' do
+ it 'Shift JISなら失敗する' do
+ @pp.caption = "\x83G\x83r\x83]\x83D"
+ lambda{
+ @pp.valid_encode
+ }.should raise_error(Pettanr::BadRequest)
+ end
+ end
+ end
+
+ describe '閲覧許可に於いて' do
+ before do
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '自身にゲスト用ロールチェックを問い合わせしている' do
+ PanelPicture.any_instance.stub(:guest_role_check).and_return(true)
+ PanelPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+ r = @pp.visible?([@author])
+ end
+ it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
+ PanelPicture.any_instance.stub(:guest_role_check).and_return(false)
+ r = @pp.visible?([@author])
+ r.should be_false
+ end
+ end
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '自身に読者用ロールチェックを問い合わせしている' do
+ PanelPicture.any_instance.stub(:reader_role_check).and_return(true)
+ PanelPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+ r = @pp.visible?([@author])
+ end
+ it '読者用ロールチェックが失敗したとき、falseを返す' do
+ PanelPicture.any_instance.stub(:reader_role_check).and_return(false)
+ r = @pp.visible?([@author])
+ r.should be_false
+ end
+ end
+ context '事前チェックする' do
+ before do
+ MagicNumber['run_mode'] = 1
+ PanelPicture.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 = @pp.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 = @pp.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 = @pp.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 = @pp.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 = @pp.visible?([@author])
+ r.should be_true
+ end
+ end
end
+
describe '一覧取得に於いて' do
before do
@pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
PanelPicture.page_size('1000').should eq PanelPicture.max_page_size
end
end
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
+ PanelPicture.should_receive(:list_opt).with(any_args).exactly(1)
+ r = PanelPicture.list
+ end
+ end
it 'リストを返す' do
- pl = PanelPicture.list
- pl.should eq [@pp]
+ r = PanelPicture.list
+ r.should eq [@pp]
end
it '時系列で並んでいる' do
- npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
+ #公開されたコマのコマ絵は(他人のコマ絵であっても)含んでいる
+ hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ npl = FactoryGirl.create :panel_picture, :panel_id => hc.id, :t => 0, :picture_id => @p.id,
:width => @p.width, :height => @p.height, :updated_at => Time.now + 100
- pl = PanelPicture.list
- pl.should eq [npl, @pp]
+ r = PanelPicture.list
+ r.should eq [npl, @pp]
end
- it 'é\9d\9eå\85¬é\96\8bã\81®ã\82³ã\83\9eã\81¯含まない' do
+ it 'é\9d\9eå\85¬é\96\8bã\81®ã\82³ã\83\9eã\81®ã\82³ã\83\9eçµµã\81¯è\87ªå\88\86ã\81®ã\82³ã\83\9eçµµã\81§ã\81\82ã\81£ã\81¦ã\82\82含まない' do
hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
:width => @p.width, :height => @p.height
context 'DBに5件あって1ページの件数を2件に変えたとして' do
before do
@npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
- :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
@npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
- :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
@npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
- :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
@npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
- :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
PanelPicture.stub(:default_page_size).and_return(2)
end
it '通常は2件を返す' do
end
it 'page=1なら末尾2件を返す' do
#時系列で並んでいる
- pl = PanelPicture.list( {}, 1)
+ pl = PanelPicture.list(1)
pl.should eq [@npl5, @npl4]
end
it 'page=2なら中間2件を返す' do
- pl = PanelPicture.list({}, 2)
+ pl = PanelPicture.list(2)
pl.should eq [@npl3, @npl2]
end
it 'page=3なら先頭1件を返す' do
- pl = PanelPicture.list({}, 3)
+ pl = PanelPicture.list(3)
pl.should eq [@pp]
end
end
end
- describe 'list関連テーブルプションに於いて' do
- it 'includeキーを含んでいる' do
- r = PanelPicture.list_opt
- r.has_key?(:include).should be_true
+
+ describe '自分のコマ絵一覧取得に於いて' do
+ before do
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
end
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
+ PanelPicture.should_receive(:list_opt).with(any_args).exactly(1)
+ r = PanelPicture.mylist @author
+ end
+ end
+ it 'リストを返す' do
+ pl = PanelPicture.mylist @author
+ pl.should eq [@pp]
+ end
+ it '時系列で並んでいる' do
+ npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
+ pl = PanelPicture.mylist @author
+ pl.should eq [npl, @pp]
+ end
+ it '他人のコマのコマ絵は公開コマでも含まない' do
+ hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ pl = PanelPicture.mylist @author
+ pl.should eq [@pp]
+ end
+ it '自分のコマのコマ絵は非公開コマでも含んでいる' do
+ pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
+ ni = FactoryGirl.create :panel_picture, :panel_id => pl.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
+ r = PanelPicture.mylist @author
+ r.should eq [ni, @pp]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
+ before do
+ @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
+ @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
+ @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
+ @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
+ end
+ it '通常は2件を返す' do
+ r = PanelPicture.mylist @author, 1, 2
+ r.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ r = PanelPicture.mylist(@author, 1, 2)
+ r.should eq [@npl5, @npl4]
+ end
+ it 'page=2なら中間2件を返す' do
+ r = PanelPicture.mylist(@author, 2, 2)
+ r.should eq [@npl3, @npl2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ r = PanelPicture.mylist(@author, 3, 2)
+ r.should eq [@pp]
+ end
+ end
+ end
+
+ describe '他作家のコマ絵一覧取得に於いて' do
+ before do
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ @other_pp = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ end
+ it 'リストを返す' do
+ r = PanelPicture.himlist @other_author
+ r.should eq [@other_pp]
+ end
+ it '時系列で並んでいる' do
+ new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
+ new_pc = FactoryGirl.create :panel_picture, :panel_id => new_panel.id, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
+ r = PanelPicture.himlist @other_author
+ r.should eq [new_pc, @other_pp]
+ end
+ it '公開コマに限る' do
+ hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
+ hidden_pp = FactoryGirl.create :panel_picture, :panel_id => hidden_panel.id, :picture_id => @p.id, :width => @p.width, :height => @p.height
+ r = PanelPicture.himlist @other_author
+ r.should eq [@other_pp]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
+ before do
+ @other_pp2 = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :t => 1, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
+ @other_pp3 = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :t => 2, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
+ @other_pp4 = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :t => 3, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
+ @other_pp5 = FactoryGirl.create :panel_picture, :panel_id => @other_panel.id, :t => 4, :picture_id => @p.id, :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
+ end
+ it '通常は2件を返す' do
+ pl = PanelPicture.himlist @other_author, 1, 2
+ pl.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ pl = PanelPicture.himlist @other_author, 1, 2
+ pl.should eq [@other_pp5, @other_pp4]
+ end
+ it 'page=2なら中間2件を返す' do
+ pl = PanelPicture.himlist @other_author, 2, 2
+ pl.should eq [@other_pp3, @other_pp2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ pl = PanelPicture.himlist @other_author, 3, 2
+ pl.should eq [@other_pp]
+ end
+ end
+ end
+
+ describe 'コマ絵一覧ページ制御に於いて' do
+ before do
+ PanelPicture.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = PanelPicture.list_paginate
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'コマ絵一覧の取得条件を利用している' do
+ PanelPicture.stub(:list_where).with(any_args).and_return('')
+ PanelPicture.should_receive(:list_where).with(any_args).exactly(1)
+ r = PanelPicture.list_paginate
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = PanelPicture.list_paginate 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '自分のコマ絵一覧ページ制御に於いて' do
+ before do
+ PanelPicture.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = PanelPicture.mylist_paginate @author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '自分のコマ絵一覧の取得条件を利用している' do
+ PanelPicture.stub(:mylist_where).with(any_args).and_return('')
+ PanelPicture.should_receive(:mylist_where).with(any_args).exactly(1)
+ r = PanelPicture.mylist_paginate @author
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = PanelPicture.mylist_paginate @author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '他作家のコマ絵一覧ページ制御に於いて' do
+ before do
+ PanelPicture.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = PanelPicture.himlist_paginate @other_author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '他作家のコマ絵一覧の取得条件を利用している' do
+ PanelPicture.stub(:himlist_where).with(any_args).and_return('')
+ PanelPicture.should_receive(:himlist_where).with(any_args).exactly(1)
+ r = PanelPicture.himlist_paginate @other_author
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = PanelPicture.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 = PanelPicture.list_opt[:include]
+ r = PanelPicture.list_opt
r.should have(2).items
end
it 'コマを含んでいる' do
- r = PanelPicture.list_opt[:include]
+ r = PanelPicture.list_opt
r.has_key?(:panel).should be_true
end
it 'コマは作家を含んでいる' do
- r = PanelPicture.list_opt[:include]
+ r = PanelPicture.list_opt
r[:panel].has_key?(:author).should be_true
end
it '実素材を含んでいる' do
- r = PanelPicture.list_opt[:include]
+ r = PanelPicture.list_opt
r.has_key?(:picture).should be_true
end
it '実素材は絵師を含んでいる' do
- r = PanelPicture.list_opt[:include]
+ r = PanelPicture.list_opt
r[:picture].has_key?(:artist).should be_true
end
it '実素材はライセンスを含んでいる' do
- r = PanelPicture.list_opt[:include]
+ r = PanelPicture.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
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ end
+ it 'コマを含んでいる' do
+ r = PanelPicture.list.to_json PanelPicture.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('panel').should be_true
+ end
+ it 'コマは作家を含んでいる' do
+ r = PanelPicture.list.to_json PanelPicture.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it '実素材を含んでいる' do
+ r = PanelPicture.list.to_json PanelPicture.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ i.has_key?('picture').should be_true
+ end
+ it '実素材は絵師を含んでいる' do
+ r = PanelPicture.list.to_json PanelPicture.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ s = i['picture']
+ s.has_key?('artist').should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = PanelPicture.list.to_json PanelPicture.list_json_opt
+ j = JSON.parse r
+ i = j.first
+ s = i['picture']
+ s.has_key?('license').should be_true
+ end
+ end
+
+ describe '単体取得に於いて' do
+ before do
+ @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
+ :width => @p.width, :height => @p.height
+ end
+ context 'つつがなく終わるとき' do
+ it '単体取得オプションを利用している' do
+ PanelPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
+ PanelPicture.should_receive(:show_opt).with(any_args).exactly(1)
+ r = PanelPicture.show @pp.id, @author
+ end
+ it '閲覧許可を問い合わせている' do
+ PanelPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
+ PanelPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
+ r = PanelPicture.show @pp.id, @author
+ end
+ end
+ it '指定のコマ絵を返す' do
+ PanelPicture.any_instance.stub(:visible?).and_return(true)
+ pl = PanelPicture.show @pp.id, @author
+ pl.should eq @pp
+ end
+ context '閲覧許可が出なかったとき' do
+ it '403Forbidden例外を返す' do
+ PanelPicture.any_instance.stub(:visible?).and_return(false)
+ lambda{
+ PanelPicture.show @pp.id, @author
+ }.should raise_error(ActiveRecord::Forbidden)
+ end
+ end
+ context '存在しないコマ絵を開こうとしたとき' do
+ it '404RecordNotFound例外を返す' do
+ lambda{
+ PanelPicture.show 110, @author
+ }.should raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+ describe '単体取得オプションに於いて' do
it 'includeキーを含んでいる' do
- r = PanelPicture.list_json_opt
+ r = PanelPicture.show_opt
r.has_key?(:include).should be_true
end
it '2つの項目を含んでいる' do
- r = PanelPicture.list_json_opt[:include]
+ r = PanelPicture.show_opt[:include]
r.should have(2).items
end
it 'コマを含んでいる' do
- r = PanelPicture.list_json_opt[:include]
+ r = PanelPicture.show_opt[:include]
r.has_key?(:panel).should be_true
end
it 'コマは作家を含んでいる' do
- r = PanelPicture.list_json_opt[:include]
+ r = PanelPicture.show_opt[:include]
r[:panel].has_key?(:author).should be_true
end
it '実素材を含んでいる' do
- r = PanelPicture.list_json_opt[:include]
+ r = PanelPicture.show_opt[:include]
r.has_key?(:picture).should be_true
end
it '実素材は絵師を含んでいる' do
- r = PanelPicture.list_json_opt[:include]
+ r = PanelPicture.show_opt[:include]
r[:picture].has_key?(:artist).should be_true
end
it '実素材はライセンスを含んでいる' do
- r = PanelPicture.list_json_opt[:include]
+ r = PanelPicture.show_opt[:include]
r[:picture].has_key?(:license).should be_true
end
end
-
- describe '自分のコマ一覧取得に於いて' do
+ 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
+ @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
@pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
:width => @p.width, :height => @p.height
end
- it 'リストを返す' do
- pl = PanelPicture.mylist @author
- pl.should eq [@pp]
- end
- it '時系列で並んでいる' do
- npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
- :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
- pl = PanelPicture.mylist @author
- pl.should eq [npl, @pp]
+ it 'コマを含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('panel').should be_true
end
- it '他人のコマは公開でも含まない' do
- hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
- npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
- :width => @p.width, :height => @p.height
- pl = PanelPicture.mylist @author
- pl.should eq [@pp]
+ it 'コマは作家を含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['panel']
+ s.has_key?('author').should be_true
+ end
+ it '実素材を含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ i.has_key?('picture').should be_true
end
+ it '実素材は絵師を含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['picture']
+ s.has_key?('artist').should be_true
+ end
+ it '実素材はライセンスを含んでいる' do
+ r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
+ j = JSON.parse r
+ i = j
+ s = i['picture']
+ s.has_key?('license').should be_true
+ end
end
-
end