describe SpeechBalloon do
before do
+ SpeechBalloonTemplate.delete_all
@admin = FactoryGirl.create :admin
@user = FactoryGirl.create( :user_yas)
@author = FactoryGirl.create :author, :user_id => @user.id
@license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
@panel = FactoryGirl.create :panel, :author_id => @author.id
- @speech_balloon_template = FactoryGirl.create :speech_balloon_template
+ @writing_format = FactoryGirl.create :writing_format
+ @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
end
describe '検証に於いて' do
before do
@sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @speech = @sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon = @sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @sb.boost
+ @sb.save!
end
context 'オーソドックスなデータのとき' do
end
end
+ describe '文字コード検証に於いて' do
+ before do
+ @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ end
+
+ context 'classnameを検証するとき' do
+ it 'Shift JISなら失敗する' do
+ @sb.classname = "\x83G\x83r\x83]\x83D"
+ lambda{
+ @sb.valid_encode
+ }.should raise_error(Pettanr::BadRequest)
+ end
+ end
+
+ context 'settingsを検証するとき' do
+ it 'Shift JISなら失敗する' do
+ @sb.settings = "\x83G\x83r\x83]\x83D"
+ lambda{
+ @sb.valid_encode
+ }.should raise_error(Pettanr::BadRequest)
+ end
+ end
+
+ context 'captionを検証するとき' do
+ it 'Shift JISなら失敗する' do
+ @sb.caption = "\x83G\x83r\x83]\x83D"
+ lambda{
+ @sb.valid_encode
+ }.should raise_error(Pettanr::BadRequest)
+ end
+ end
+
+ end
+
describe '閲覧許可に於いて' do
before do
- @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
- @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
- @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
- end
- context '検査対象がnil(ゲスト)のとき' do
- context 'クローズドモードのとき' do
- before do
- MagicNumber['run_mode'] = 1
- end
- it '不許可を返す。' do
- r = @sb.visible?(nil)
- r.should be_false
- end
- end
- context 'オープンモードのとき' do
- before do
- MagicNumber['run_mode'] = 0
- end
- it '公開されたコマのフキダシなら許可する' do
- Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
- r = @sb.visible?(nil)
- r.should be_true
- end
- it 'れ以外なら不許可を返す' do
- Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
- r = @sb.visible?(nil)
- r.should be_false
- end
- end
- end
- context '検査対象が作家のとき' do
- it '公開されたコマのフキダシなら許可する' do
- Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
- r = @sb.visible?(@author)
- r.should be_true
+ @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @speech = @sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon = @sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @sb.boost
+ @sb.save!
+ end
+ context 'オープンモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 0
+ end
+ it '自身にゲスト用ロールチェックを問い合わせしている' do
+ SpeechBalloon.any_instance.stub(:guest_role_check).and_return(true)
+ SpeechBalloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
+ r = @sb.visible?([@author])
end
- it 'ã\82\8c以å¤\96ã\81ªã\82\89ä¸\8d許å\8f¯を返す' do
- Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
- r = @sb.visible?(@author)
+ it 'ã\82²ã\82¹ã\83\88ç\94¨ã\83ã\83¼ã\83«ã\83\81ã\82§ã\83\83ã\82¯ã\81\8c失æ\95\97ã\81\97ã\81\9fã\81¨ã\81\8dã\80\81falseを返す' do
+ SpeechBalloon.any_instance.stub(:guest_role_check).and_return(false)
+ r = @sb.visible?([@author])
r.should be_false
end
end
- context '検査対象が管理者のとき' do
- it '許可を返す。' do
- Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
- r = @sb.visible?(@admin)
- r.should be_true
+ context 'クローズドモードのとき' do
+ before do
+ MagicNumber['run_mode'] = 1
+ end
+ it '自身に読者用ロールチェックを問い合わせしている' do
+ SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
+ SpeechBalloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
+ r = @sb.visible?([@author])
+ end
+ it '読者用ロールチェックが失敗したとき、falseを返す' do
+ SpeechBalloon.any_instance.stub(:reader_role_check).and_return(false)
+ r = @sb.visible?([@author])
+ r.should be_false
+ end
+ end
+ context '事前チェックする' do
+ before do
+ MagicNumber['run_mode'] = 1
+ SpeechBalloon.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 = @sb.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 = @sb.visible?([@author])
end
end
- context '検査対象がそれ以外のとき' do
- it '不許可を返す。' do
- r = @sb.visible?(1)
+ 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 = @sb.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 = @sb.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 = @sb.visible?([@author])
+ r.should be_true
+ end
end
end
+
describe '一覧取得に於いて' do
before do
- @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
- @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
- @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+ @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @speech = @sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon = @sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @sb.boost
+ @sb.save!
end
context 'page補正について' do
it '文字列から数値に変換される' do
it '時系列で並んでいる' do
#公開されたコマのフキダシは(他人のフキダシであっても)含んでいる
hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
- npl = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ npl = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ npl.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ npl.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ npl.boost
+ npl.save!
r = SpeechBalloon.list
r.should eq [npl, @sb]
end
it '非公開のコマのフキダシは自分のフキダシであっても含まない' do
hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
- npl = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ npl = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ npl.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ npl.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ npl.boost
+ npl.save!
pl = SpeechBalloon.list
pl.should eq [@sb]
end
context 'DBに5件あって1ページの件数を2件に変えたとして' do
before do
- @sb2 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 1, :updated_at => Time.now + 100
- @sb3 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 2, :updated_at => Time.now + 200
- @sb4 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 3, :updated_at => Time.now + 300
- @sb5 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 4, :updated_at => Time.now + 400
+ @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ @speech2 = @sb2.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon2 = @sb2.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
+ )
+ @sb2.boost
+ @sb2.save!
+ @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
+ @speech3 = @sb3.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon3 = @sb3.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
+ )
+ @sb3.boost
+ @sb3.save!
+ @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
+ @speech4 = @sb4.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon4 = @sb4.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
+ )
+ @sb4.boost
+ @sb4.save!
+ @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
+ @speech5 = @sb5.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon5 = @sb5.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
+ )
+ @sb5.boost
+ @sb5.save!
SpeechBalloon.stub(:default_page_size).and_return(2)
end
it '通常は2件を返す' do
pl.should eq [@sb]
end
end
- context 'DBに5件あって1ページの件数を0件に変えたとして' do
+ end
+
+ describe '自分のフキダシ一覧取得に於いて' do
+ before do
+ @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @speech = @sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon = @sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @sb.boost
+ @sb.save!
+ end
+ context 'つつがなく終わるとき' do
+ it '一覧取得オプションを利用している' do
+ SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
+ SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
+ r = SpeechBalloon.mylist @author
+ end
+ end
+ it 'リストを返す' do
+ pl = SpeechBalloon.mylist @author
+ pl.should eq [@sb]
+ end
+ it '時系列で並んでいる' do
+ nsb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ nsb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ nsb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ nsb.boost
+ nsb.save!
+ pl = SpeechBalloon.mylist @author
+ pl.should eq [nsb, @sb]
+ end
+ it '他人のコマのフキダシは公開コマでも含まない' do
+ hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ nsb = FactoryGirl.build :speech_balloon, :panel_id => hpl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ nsb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ nsb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ nsb.boost
+ nsb.save!
+ pl = SpeechBalloon.mylist @author
+ pl.should eq [@sb]
+ end
+ it '自分のコマのフキダシは非公開コマでも含んでいる' do
+ pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
+ nsb = FactoryGirl.build :speech_balloon, :panel_id => pl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ nsb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ nsb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ nsb.boost
+ nsb.save!
+ r = SpeechBalloon.mylist @author
+ r.should eq [nsb, @sb]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
before do
- @sb2 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 1, :updated_at => Time.now + 100
- @sb3 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 2, :updated_at => Time.now + 200
- @sb4 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 3, :updated_at => Time.now + 300
- @sb5 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 4, :updated_at => Time.now + 400
- SpeechBalloon.stub(:default_page_size).and_return(2)
+ @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ @speech2 = @sb2.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon2 = @sb2.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
+ )
+ @sb2.boost
+ @sb2.save!
+ @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
+ @speech3 = @sb3.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon3 = @sb3.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
+ )
+ @sb3.boost
+ @sb3.save!
+ @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
+ @speech4 = @sb4.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon4 = @sb4.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
+ )
+ @sb4.boost
+ @sb4.save!
+ @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
+ @speech5 = @sb5.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon5 = @sb5.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
+ )
+ @sb5.boost
+ @sb5.save!
end
- it '通常は全件(5件)を返す' do
- r = SpeechBalloon.list 5, 0
- r.should have(5).items
+ it '通常は2件を返す' do
+ r = SpeechBalloon.mylist @author, 1, 2
+ r.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ r = SpeechBalloon.mylist(@author, 1, 2)
+ r.should eq [@sb5, @sb4]
+ end
+ it 'page=2なら中間2件を返す' do
+ r = SpeechBalloon.mylist(@author, 2, 2)
+ r.should eq [@sb3, @sb2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ r = SpeechBalloon.mylist(@author, 3, 2)
+ r.should eq [@sb]
end
end
end
- describe '一覧取得オプションに於いて' do
- it 'includeキーを含んでいる' do
- r = SpeechBalloon.list_opt
- r.has_key?(:include).should be_true
+
+ describe '他作家のフキダシ一覧取得に於いて' do
+ before do
+ @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @speech = @sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon = @sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @sb.boost
+ @sb.save!
+ @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
+ @other_sb = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @other_speech = @other_sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @other_balloon = @other_sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @other_sb.boost
+ @other_sb.save!
+ end
+ it 'リストを返す' do
+ r = SpeechBalloon.himlist @other_author
+ r.should eq [@other_sb]
end
+ it '時系列で並んでいる' do
+ new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
+ new_sb = FactoryGirl.build :speech_balloon, :panel_id => new_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ new_sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ new_sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ new_sb.boost
+ new_sb.save!
+ r = SpeechBalloon.himlist @other_author
+ r.should eq [new_sb, @other_sb]
+ end
+ it '公開コマに限る' do
+ hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
+ hidden_sb = FactoryGirl.build :speech_balloon, :panel_id => hidden_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ hidden_sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ hidden_sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ hidden_sb.boost
+ hidden_sb.save!
+ r = SpeechBalloon.himlist @other_author
+ r.should eq [@other_sb]
+ end
+ context 'DBに5件あって1ページの件数を2件に変えたとして' do
+ before do
+ @other_sb2 = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
+ @other_sb2.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @other_sb2.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
+ )
+ @other_sb2.boost
+ @other_sb2.save!
+ @other_sb3 = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
+ @other_sb3.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @other_sb3.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
+ )
+ @other_sb3.boost
+ @other_sb3.save!
+ @other_sb4 = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
+ @other_sb4.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @other_sb4.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
+ )
+ @other_sb4.boost
+ @other_sb4.save!
+ @other_sb5 = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
+ @other_sb5.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @other_sb5.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
+ )
+ @other_sb5.boost
+ @other_sb5.save!
+ end
+ it '通常は2件を返す' do
+ r = SpeechBalloon.himlist @other_author, 1, 2
+ r.should have(2).items
+ end
+ it 'page=1なら末尾2件を返す' do
+ #時系列で並んでいる
+ r = SpeechBalloon.himlist @other_author, 1, 2
+ r.should eq [@other_sb5, @other_sb4]
+ end
+ it 'page=2なら中間2件を返す' do
+ r = SpeechBalloon.himlist @other_author, 2, 2
+ r.should eq [@other_sb3, @other_sb2]
+ end
+ it 'page=3なら先頭1件を返す' do
+ r = SpeechBalloon.himlist @other_author, 3, 2
+ r.should eq [@other_sb]
+ end
+ end
+ end
+
+ describe 'フキダシ一覧ページ制御に於いて' do
+ before do
+ SpeechBalloon.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = SpeechBalloon.list_paginate
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it 'フキダシ一覧の取得条件を利用している' do
+ SpeechBalloon.stub(:list_where).with(any_args).and_return('')
+ SpeechBalloon.should_receive(:list_where).with(any_args).exactly(1)
+ r = SpeechBalloon.list_paginate
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = SpeechBalloon.list_paginate 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '自分のフキダシ一覧ページ制御に於いて' do
+ before do
+ SpeechBalloon.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = SpeechBalloon.mylist_paginate @author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '自分のフキダシ一覧の取得条件を利用している' do
+ SpeechBalloon.stub(:mylist_where).with(any_args).and_return('')
+ SpeechBalloon.should_receive(:mylist_where).with(any_args).exactly(1)
+ r = SpeechBalloon.mylist_paginate @author
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = SpeechBalloon.mylist_paginate @author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '他作家のフキダシ一覧ページ制御に於いて' do
+ before do
+ SpeechBalloon.stub(:count).with(any_args).and_return(100)
+ end
+ it 'ページ制御を返す' do
+ r = SpeechBalloon.himlist_paginate @other_author
+ r.is_a?(Kaminari::PaginatableArray).should be_true
+ end
+ it '他作家のフキダシ一覧の取得条件を利用している' do
+ SpeechBalloon.stub(:himlist_where).with(any_args).and_return('')
+ SpeechBalloon.should_receive(:himlist_where).with(any_args).exactly(1)
+ r = SpeechBalloon.himlist_paginate @other_author
+ end
+ it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
+ r = SpeechBalloon.himlist_paginate @other_author, 3, 10
+ r.limit_value.should eq 10
+ r.offset_value.should eq 20
+ end
+ end
+
+ describe '一覧取得オプションに於いて' do
it '4つの項目を含んでいる' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r.should have(4).items
end
it 'コマを含んでいる' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r.has_key?(:panel).should be_true
end
it 'コマは作家を含んでいる' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r[:panel].has_key?(:author).should be_true
end
it 'フキダシ枠を含んでいる' do
- r = SpeechBalloon.list_opt[:include]
- r.has_key?(:balloons).should be_true
+ r = SpeechBalloon.list_opt
+ r.has_key?(:balloon).should be_true
end
it 'セリフを含んでいる' do
- r = SpeechBalloon.list_opt[:include]
- r.has_key?(:speeches).should be_true
+ r = SpeechBalloon.list_opt
+ r.has_key?(:speech).should be_true
end
it 'フキダシテンプレートを含んでいる' do
- r = SpeechBalloon.list_opt[:include]
+ r = SpeechBalloon.list_opt
r.has_key?(:speech_balloon_template).should be_true
end
end
describe 'json一覧出力オプションに於いて' do
before do
@panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
- @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
- @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
- @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+ @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @speech = @sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon = @sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @sb.boost
+ @sb.save!
end
it 'コマを含んでいる' do
r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
j = JSON.parse r
i = j.first
- i.has_key?('balloons').should be_true
+ i.has_key?('balloon').should be_true
end
it 'セリフを含んでいる' do
r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
j = JSON.parse r
i = j.first
- i.has_key?('speeches').should be_true
+ i.has_key?('speech').should be_true
end
it 'フキダシテンプレートを含んでいる' do
r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
describe '単体取得に於いて' do
before do
- @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
- @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
- @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+ @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @speech = @sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon = @sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @sb.boost
+ @sb.save!
end
context 'つつがなく終わるとき' do
it '単体取得オプションを利用している' do
end
it 'フキダシ枠を含んでいる' do
r = SpeechBalloon.show_opt[:include]
- r.has_key?(:balloons).should be_true
+ r.has_key?(:balloon).should be_true
end
it 'セリフを含んでいる' do
r = SpeechBalloon.show_opt[:include]
- r.has_key?(:speeches).should be_true
+ r.has_key?(:speech).should be_true
end
it 'フキダシテンプレートを含んでいる' do
r = SpeechBalloon.show_opt[:include]
describe 'json単体出力オプションに於いて' do
before do
@panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
- @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
- @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
- @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
+ @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
+ @speech = @sb.build_speech(
+ FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
+ )
+ @balloon = @sb.build_balloon(
+ FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
+ )
+ @sb.boost
+ @sb.save!
end
it 'コマを含んでいる' do
r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
j = JSON.parse r
i = j
- i.has_key?('balloons').should be_true
+ i.has_key?('balloon').should be_true
end
it 'セリフを含んでいる' do
r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
j = JSON.parse r
i = j
- i.has_key?('speeches').should be_true
+ i.has_key?('speech').should be_true
end
it 'フキダシテンプレートを含んでいる' do
r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt