1 # -*- encoding: utf-8 -*-
5 describe SpeechBalloon do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @other_user = FactoryGirl.create( :user_yas)
12 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
13 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
14 @sp = FactoryGirl.create :system_picture
15 @lg = FactoryGirl.create :license_group
16 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
18 @panel = FactoryGirl.create :panel, :author_id => @author.id
19 @writing_format = FactoryGirl.create :writing_format
20 @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
25 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
26 @speech = @sb.build_speech(
27 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
29 @balloon = @sb.build_balloon(
30 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
36 context 'オーソドックスなデータのとき' do
44 @sb.classname = 'a'*50
51 context 'panel_idを検証するとき' do
52 #ネストの保存はnilを許可しなければならないので数値チェックだけ
55 @sb.should_not be_valid
58 context 'speech_balloon_template_idを検証するとき' do
60 @sb.speech_balloon_template_id = nil
61 @sb.should_not be_valid
64 @sb.speech_balloon_template_id = 'a'
65 @sb.should_not be_valid
67 it '存在するフキダシテンプレートでなければ失敗する' do
68 @sb.speech_balloon_template_id = 0
69 @sb.should_not be_valid
72 context 'classnameを検証するとき' do
75 @sb.should_not be_valid
78 @sb.classname = 'a'*51
79 @sb.should_not be_valid
85 @sb.should_not be_valid
89 @sb.should_not be_valid
93 @sb.should_not be_valid
96 context 'settingsを検証するとき' do
100 describe '文字コード検証に於いて' do
102 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
105 context 'classnameを検証するとき' do
106 it 'Shift JISなら失敗する' do
107 @sb.classname = "\x83G\x83r\x83]\x83D"
110 }.should raise_error(Pettanr::BadRequest)
114 context 'settingsを検証するとき' do
115 it 'Shift JISなら失敗する' do
116 @sb.settings = "\x83G\x83r\x83]\x83D"
119 }.should raise_error(Pettanr::BadRequest)
123 context 'captionを検証するとき' do
124 it 'Shift JISなら失敗する' do
125 @sb.caption = "\x83G\x83r\x83]\x83D"
128 }.should raise_error(Pettanr::BadRequest)
134 describe '閲覧許可に於いて' do
136 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
137 @speech = @sb.build_speech(
138 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
140 @balloon = @sb.build_balloon(
141 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
146 context 'オープンモードのとき' do
148 MagicNumber['run_mode'] = 0
150 it '自身にゲスト用ロールチェックを問い合わせしている' do
151 SpeechBalloon.any_instance.stub(:guest_role_check).and_return(true)
152 SpeechBalloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
153 r = @sb.visible?([@author])
155 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
156 SpeechBalloon.any_instance.stub(:guest_role_check).and_return(false)
157 r = @sb.visible?([@author])
161 context 'クローズドモードのとき' do
163 MagicNumber['run_mode'] = 1
165 it '自身に読者用ロールチェックを問い合わせしている' do
166 SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
167 SpeechBalloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
168 r = @sb.visible?([@author])
170 it '読者用ロールチェックが失敗したとき、falseを返す' do
171 SpeechBalloon.any_instance.stub(:reader_role_check).and_return(false)
172 r = @sb.visible?([@author])
176 context '事前チェックする' do
178 MagicNumber['run_mode'] = 1
179 SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
181 it '自身のコマに所持判定を問い合わせしている' do
182 Panel.any_instance.stub(:own?).and_return(true)
183 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
184 r = @sb.visible?([@author])
186 it '自身のコマに閲覧許可を問い合わせしている' do
187 Panel.any_instance.stub(:own?).and_return(false)
188 Panel.any_instance.stub(:visible?).and_return(true)
189 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
190 r = @sb.visible?([@author])
193 context 'つつがなく終わるとき' do
195 MagicNumber['run_mode'] = 1
196 Panel.any_instance.stub(:reader_role_check).and_return(true)
198 it '自分のコマのフキダシなら許可する' do
199 Panel.any_instance.stub(:own?).and_return(true)
200 Panel.any_instance.stub(:visible?).and_return(false)
201 r = @sb.visible?([@author])
204 it '他人の非公開コマのフキダシなら許可しない' do
205 Panel.any_instance.stub(:own?).and_return(false)
206 Panel.any_instance.stub(:visible?).and_return(false)
207 r = @sb.visible?([@author])
210 it '他人のコマのフキダシでも公開なら許可する' do
211 Panel.any_instance.stub(:own?).and_return(false)
212 Panel.any_instance.stub(:visible?).and_return(true)
213 r = @sb.visible?([@author])
219 describe '一覧取得に於いて' do
221 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
222 @speech = @sb.build_speech(
223 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
225 @balloon = @sb.build_balloon(
226 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
231 context 'page補正について' do
232 it '文字列から数値に変換される' do
233 SpeechBalloon.page('8').should eq 8
236 SpeechBalloon.page().should eq 1
239 SpeechBalloon.page('0').should eq 1
242 context 'page_size補正について' do
243 it '文字列から数値に変換される' do
244 SpeechBalloon.page_size('7').should eq 7
246 it 'nilの場合はSpeechBalloon.default_page_sizeになる' do
247 SpeechBalloon.page_size().should eq SpeechBalloon.default_page_size
249 it '0以下の場合はSpeechBalloon.default_page_sizeになる' do
250 SpeechBalloon.page_size('0').should eq SpeechBalloon.default_page_size
252 it 'SpeechBalloon.max_page_sizeを超えた場合はSpeechBalloon.max_page_sizeになる' do
253 SpeechBalloon.page_size('1000').should eq SpeechBalloon.max_page_size
256 context 'つつがなく終わるとき' do
257 it '一覧取得オプションを利用している' do
258 SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
259 SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
260 r = SpeechBalloon.list
264 r = SpeechBalloon.list
268 #公開されたコマのフキダシは(他人のフキダシであっても)含んでいる
269 hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
270 npl = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
272 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
275 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
279 r = SpeechBalloon.list
280 r.should eq [npl, @sb]
282 it '非公開のコマのフキダシは自分のフキダシであっても含まない' do
283 hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
284 npl = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
286 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
289 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
293 pl = SpeechBalloon.list
296 context 'DBに5件あって1ページの件数を2件に変えたとして' do
298 @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id
299 @speech2 = @sb2.build_speech(
300 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
302 @balloon2 = @sb2.build_balloon(
303 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
307 @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id
308 @speech3 = @sb3.build_speech(
309 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
311 @balloon3 = @sb3.build_balloon(
312 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
316 @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id
317 @speech4 = @sb4.build_speech(
318 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
320 @balloon4 = @sb4.build_balloon(
321 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
325 @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id
326 @speech5 = @sb5.build_speech(
327 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
329 @balloon5 = @sb5.build_balloon(
330 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
334 SpeechBalloon.stub(:default_page_size).and_return(2)
337 pl = SpeechBalloon.list
338 pl.should have(2).items
340 it 'page=1なら末尾2件を返す' do
342 pl = SpeechBalloon.list(1)
343 pl.should eq [@sb5, @sb4]
345 it 'page=2なら中間2件を返す' do
346 pl = SpeechBalloon.list(2)
347 pl.should eq [@sb3, @sb2]
349 it 'page=3なら先頭1件を返す' do
350 pl = SpeechBalloon.list(3)
356 describe '自分のフキダシ一覧取得に於いて' do
358 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
359 @speech = @sb.build_speech(
360 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
362 @balloon = @sb.build_balloon(
363 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
368 context 'つつがなく終わるとき' do
369 it '一覧取得オプションを利用している' do
370 SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
371 SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
372 r = SpeechBalloon.mylist @author
376 pl = SpeechBalloon.mylist @author
380 nsb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
382 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
385 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
389 pl = SpeechBalloon.mylist @author
390 pl.should eq [nsb, @sb]
392 it '他人のコマのフキダシは公開コマでも含まない' do
393 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
394 nsb = FactoryGirl.build :speech_balloon, :panel_id => hpl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
396 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
399 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
403 pl = SpeechBalloon.mylist @author
406 it '自分のコマのフキダシは非公開コマでも含んでいる' do
407 pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
408 nsb = FactoryGirl.build :speech_balloon, :panel_id => pl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
410 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
413 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
417 r = SpeechBalloon.mylist @author
418 r.should eq [nsb, @sb]
420 context 'DBに5件あって1ページの件数を2件に変えたとして' do
422 @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id
423 @speech2 = @sb2.build_speech(
424 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
426 @balloon2 = @sb2.build_balloon(
427 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
431 @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id
432 @speech3 = @sb3.build_speech(
433 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
435 @balloon3 = @sb3.build_balloon(
436 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
440 @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id
441 @speech4 = @sb4.build_speech(
442 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
444 @balloon4 = @sb4.build_balloon(
445 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
449 @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id
450 @speech5 = @sb5.build_speech(
451 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
453 @balloon5 = @sb5.build_balloon(
454 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
460 r = SpeechBalloon.mylist @author, 1, 2
461 r.should have(2).items
463 it 'page=1なら末尾2件を返す' do
465 r = SpeechBalloon.mylist(@author, 1, 2)
466 r.should eq [@sb5, @sb4]
468 it 'page=2なら中間2件を返す' do
469 r = SpeechBalloon.mylist(@author, 2, 2)
470 r.should eq [@sb3, @sb2]
472 it 'page=3なら先頭1件を返す' do
473 r = SpeechBalloon.mylist(@author, 3, 2)
479 describe '他作家のフキダシ一覧取得に於いて' do
481 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
482 @speech = @sb.build_speech(
483 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
485 @balloon = @sb.build_balloon(
486 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
490 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
491 @other_sb = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
492 @other_speech = @other_sb.build_speech(
493 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
495 @other_balloon = @other_sb.build_balloon(
496 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
502 r = SpeechBalloon.himlist @other_author
503 r.should eq [@other_sb]
506 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
507 new_sb = FactoryGirl.build :speech_balloon, :panel_id => new_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
509 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
511 new_sb.build_balloon(
512 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
516 r = SpeechBalloon.himlist @other_author
517 r.should eq [new_sb, @other_sb]
520 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
521 hidden_sb = FactoryGirl.build :speech_balloon, :panel_id => hidden_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
522 hidden_sb.build_speech(
523 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
525 hidden_sb.build_balloon(
526 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
530 r = SpeechBalloon.himlist @other_author
531 r.should eq [@other_sb]
533 context 'DBに5件あって1ページの件数を2件に変えたとして' do
535 @other_sb2 = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id
536 @other_sb2.build_speech(
537 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
539 @other_sb2.build_balloon(
540 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
544 @other_sb3 = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id
545 @other_sb3.build_speech(
546 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
548 @other_sb3.build_balloon(
549 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
553 @other_sb4 = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id
554 @other_sb4.build_speech(
555 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
557 @other_sb4.build_balloon(
558 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
562 @other_sb5 = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id
563 @other_sb5.build_speech(
564 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
566 @other_sb5.build_balloon(
567 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
573 r = SpeechBalloon.himlist @other_author, 1, 2
574 r.should have(2).items
576 it 'page=1なら末尾2件を返す' do
578 r = SpeechBalloon.himlist @other_author, 1, 2
579 r.should eq [@other_sb5, @other_sb4]
581 it 'page=2なら中間2件を返す' do
582 r = SpeechBalloon.himlist @other_author, 2, 2
583 r.should eq [@other_sb3, @other_sb2]
585 it 'page=3なら先頭1件を返す' do
586 r = SpeechBalloon.himlist @other_author, 3, 2
587 r.should eq [@other_sb]
592 describe 'フキダシ一覧ページ制御に於いて' do
594 SpeechBalloon.stub(:count).with(any_args).and_return(100)
597 r = SpeechBalloon.list_paginate
598 r.is_a?(Kaminari::PaginatableArray).should be_true
600 it 'フキダシ一覧の取得条件を利用している' do
601 SpeechBalloon.stub(:list_where).with(any_args).and_return('')
602 SpeechBalloon.should_receive(:list_where).with(any_args).exactly(1)
603 r = SpeechBalloon.list_paginate
605 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
606 r = SpeechBalloon.list_paginate 3, 10
607 r.limit_value.should eq 10
608 r.offset_value.should eq 20
612 describe '自分のフキダシ一覧ページ制御に於いて' do
614 SpeechBalloon.stub(:count).with(any_args).and_return(100)
617 r = SpeechBalloon.mylist_paginate @author
618 r.is_a?(Kaminari::PaginatableArray).should be_true
620 it '自分のフキダシ一覧の取得条件を利用している' do
621 SpeechBalloon.stub(:mylist_where).with(any_args).and_return('')
622 SpeechBalloon.should_receive(:mylist_where).with(any_args).exactly(1)
623 r = SpeechBalloon.mylist_paginate @author
625 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
626 r = SpeechBalloon.mylist_paginate @author, 3, 10
627 r.limit_value.should eq 10
628 r.offset_value.should eq 20
632 describe '他作家のフキダシ一覧ページ制御に於いて' do
634 SpeechBalloon.stub(:count).with(any_args).and_return(100)
637 r = SpeechBalloon.himlist_paginate @other_author
638 r.is_a?(Kaminari::PaginatableArray).should be_true
640 it '他作家のフキダシ一覧の取得条件を利用している' do
641 SpeechBalloon.stub(:himlist_where).with(any_args).and_return('')
642 SpeechBalloon.should_receive(:himlist_where).with(any_args).exactly(1)
643 r = SpeechBalloon.himlist_paginate @other_author
645 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
646 r = SpeechBalloon.himlist_paginate @other_author, 3, 10
647 r.limit_value.should eq 10
648 r.offset_value.should eq 20
652 describe '一覧取得オプションに於いて' do
654 r = SpeechBalloon.list_opt
655 r.should have(4).items
658 r = SpeechBalloon.list_opt
659 r.has_key?(:panel).should be_true
662 r = SpeechBalloon.list_opt
663 r[:panel].has_key?(:author).should be_true
666 r = SpeechBalloon.list_opt
667 r.has_key?(:balloon).should be_true
670 r = SpeechBalloon.list_opt
671 r.has_key?(:speech).should be_true
673 it 'フキダシテンプレートを含んでいる' do
674 r = SpeechBalloon.list_opt
675 r.has_key?(:speech_balloon_template).should be_true
678 describe 'json一覧出力オプションに於いて' do
680 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
681 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
682 @speech = @sb.build_speech(
683 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
685 @balloon = @sb.build_balloon(
686 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
692 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
695 i.has_key?('panel').should be_true
698 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
702 s.has_key?('author').should be_true
705 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
708 i.has_key?('balloon').should be_true
711 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
714 i.has_key?('speech').should be_true
716 it 'フキダシテンプレートを含んでいる' do
717 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
720 i.has_key?('speech_balloon_template').should be_true
724 describe '単体取得に於いて' do
726 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
727 @speech = @sb.build_speech(
728 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
730 @balloon = @sb.build_balloon(
731 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
736 context 'つつがなく終わるとき' do
737 it '単体取得オプションを利用している' do
738 SpeechBalloon.stub(:show_opt).with(any_args).and_return({:include => :panel})
739 SpeechBalloon.should_receive(:show_opt).with(any_args).exactly(1)
740 r = SpeechBalloon.show @sb.id, @author
742 it '閲覧許可を問い合わせている' do
743 SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)
744 SpeechBalloon.any_instance.should_receive(:visible?).with(any_args).exactly(1)
745 r = SpeechBalloon.show @sb.id, @author
749 SpeechBalloon.any_instance.stub(:visible?).and_return(true)
750 pl = SpeechBalloon.show @sb.id, @author
753 context '閲覧許可が出なかったとき' do
754 it '403Forbidden例外を返す' do
755 SpeechBalloon.any_instance.stub(:visible?).and_return(false)
757 SpeechBalloon.show @sb.id, @author
758 }.should raise_error(ActiveRecord::Forbidden)
761 context '存在しないフキダシを開こうとしたとき' do
762 it '404RecordNotFound例外を返す' do
764 SpeechBalloon.show 110, @author
765 }.should raise_error(ActiveRecord::RecordNotFound)
769 describe '単体取得オプションに於いて' do
770 it 'includeキーを含んでいる' do
771 r = SpeechBalloon.show_opt
772 r.has_key?(:include).should be_true
775 r = SpeechBalloon.show_opt[:include]
776 r.should have(4).items
779 r = SpeechBalloon.show_opt[:include]
780 r.has_key?(:panel).should be_true
783 r = SpeechBalloon.show_opt[:include]
784 r[:panel].has_key?(:author).should be_true
787 r = SpeechBalloon.show_opt[:include]
788 r.has_key?(:balloon).should be_true
791 r = SpeechBalloon.show_opt[:include]
792 r.has_key?(:speech).should be_true
794 it 'フキダシテンプレートを含んでいる' do
795 r = SpeechBalloon.show_opt[:include]
796 r.has_key?(:speech_balloon_template).should be_true
799 describe 'json単体出力オプションに於いて' do
801 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
802 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
803 @speech = @sb.build_speech(
804 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
806 @balloon = @sb.build_balloon(
807 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
813 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
816 i.has_key?('panel').should be_true
819 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
823 s.has_key?('author').should be_true
826 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
829 i.has_key?('balloon').should be_true
832 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
835 i.has_key?('speech').should be_true
837 it 'フキダシテンプレートを含んでいる' do
838 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
841 i.has_key?('speech_balloon_template').should be_true