1 # -*- encoding: utf-8 -*-
5 describe SpeechBalloon do
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @user = FactoryGirl.create( :user_yas)
10 @author = FactoryGirl.create :author, :user_id => @user.id
11 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
12 @other_user = FactoryGirl.create( :user_yas)
13 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
14 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
15 @sp = FactoryGirl.create :system_picture
16 @lg = FactoryGirl.create :license_group
17 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
19 @panel = FactoryGirl.create :panel, :author_id => @author.id
20 @writing_format = FactoryGirl.create :writing_format
21 @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
26 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
27 @speech = @sb.build_speech(
28 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
30 @balloon = @sb.build_balloon(
31 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
37 context 'オーソドックスなデータのとき' do
45 @sb.classname = 'a'*50
52 context 'panel_idを検証するとき' do
53 #ネストの保存はnilを許可しなければならないので数値チェックだけ
56 @sb.should_not be_valid
59 context 'speech_balloon_template_idを検証するとき' do
61 @sb.speech_balloon_template_id = nil
62 @sb.should_not be_valid
65 @sb.speech_balloon_template_id = 'a'
66 @sb.should_not be_valid
68 it '存在するフキダシテンプレートでなければ失敗する' do
69 @sb.speech_balloon_template_id = 0
70 @sb.should_not be_valid
73 context 'classnameを検証するとき' do
76 @sb.should_not be_valid
79 @sb.classname = 'a'*51
80 @sb.should_not be_valid
86 @sb.should_not be_valid
90 @sb.should_not be_valid
94 @sb.should_not be_valid
97 context 'settingsを検証するとき' do
101 describe '文字コード検証に於いて' do
103 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
106 context 'classnameを検証するとき' do
107 it 'Shift JISなら失敗する' do
108 @sb.classname = "\x83G\x83r\x83]\x83D"
111 }.should raise_error(Pettanr::BadRequest)
115 context 'settingsを検証するとき' do
116 it 'Shift JISなら失敗する' do
117 @sb.settings = "\x83G\x83r\x83]\x83D"
120 }.should raise_error(Pettanr::BadRequest)
124 context 'captionを検証するとき' do
125 it 'Shift JISなら失敗する' do
126 @sb.caption = "\x83G\x83r\x83]\x83D"
129 }.should raise_error(Pettanr::BadRequest)
135 describe '閲覧許可に於いて' do
137 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
138 @speech = @sb.build_speech(
139 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
141 @balloon = @sb.build_balloon(
142 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
147 context 'オープンモードのとき' do
149 MagicNumber['run_mode'] = 0
151 it '自身にゲスト用ロールチェックを問い合わせしている' do
152 SpeechBalloon.any_instance.stub(:guest_role_check).and_return(true)
153 SpeechBalloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
154 r = @sb.visible?([@author])
156 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
157 SpeechBalloon.any_instance.stub(:guest_role_check).and_return(false)
158 r = @sb.visible?([@author])
162 context 'クローズドモードのとき' do
164 MagicNumber['run_mode'] = 1
166 it '自身に読者用ロールチェックを問い合わせしている' do
167 SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
168 SpeechBalloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
169 r = @sb.visible?([@author])
171 it '読者用ロールチェックが失敗したとき、falseを返す' do
172 SpeechBalloon.any_instance.stub(:reader_role_check).and_return(false)
173 r = @sb.visible?([@author])
177 context '事前チェックする' do
179 MagicNumber['run_mode'] = 1
180 SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
182 it '自身のコマに所持判定を問い合わせしている' do
183 Panel.any_instance.stub(:own?).and_return(true)
184 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
185 r = @sb.visible?([@author])
187 it '自身のコマに閲覧許可を問い合わせしている' do
188 Panel.any_instance.stub(:own?).and_return(false)
189 Panel.any_instance.stub(:visible?).and_return(true)
190 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
191 r = @sb.visible?([@author])
194 context 'つつがなく終わるとき' do
196 MagicNumber['run_mode'] = 1
197 Panel.any_instance.stub(:reader_role_check).and_return(true)
199 it '自分のコマのフキダシなら許可する' do
200 Panel.any_instance.stub(:own?).and_return(true)
201 Panel.any_instance.stub(:visible?).and_return(false)
202 r = @sb.visible?([@author])
205 it '他人の非公開コマのフキダシなら許可しない' do
206 Panel.any_instance.stub(:own?).and_return(false)
207 Panel.any_instance.stub(:visible?).and_return(false)
208 r = @sb.visible?([@author])
211 it '他人のコマのフキダシでも公開なら許可する' do
212 Panel.any_instance.stub(:own?).and_return(false)
213 Panel.any_instance.stub(:visible?).and_return(true)
214 r = @sb.visible?([@author])
220 describe '一覧取得に於いて' do
222 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
223 @speech = @sb.build_speech(
224 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
226 @balloon = @sb.build_balloon(
227 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
232 context 'page補正について' do
233 it '文字列から数値に変換される' do
234 SpeechBalloon.page('8').should eq 8
237 SpeechBalloon.page().should eq 1
240 SpeechBalloon.page('0').should eq 1
243 context 'page_size補正について' do
244 it '文字列から数値に変換される' do
245 SpeechBalloon.page_size('7').should eq 7
247 it 'nilの場合はSpeechBalloon.default_page_sizeになる' do
248 SpeechBalloon.page_size().should eq SpeechBalloon.default_page_size
250 it '0以下の場合はSpeechBalloon.default_page_sizeになる' do
251 SpeechBalloon.page_size('0').should eq SpeechBalloon.default_page_size
253 it 'SpeechBalloon.max_page_sizeを超えた場合はSpeechBalloon.max_page_sizeになる' do
254 SpeechBalloon.page_size('1000').should eq SpeechBalloon.max_page_size
257 context 'つつがなく終わるとき' do
258 it '一覧取得オプションを利用している' do
259 SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
260 SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
261 r = SpeechBalloon.list
265 r = SpeechBalloon.list
269 #公開されたコマのフキダシは(他人のフキダシであっても)含んでいる
270 hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
271 npl = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
273 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
276 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
280 r = SpeechBalloon.list
281 r.should eq [npl, @sb]
283 it '非公開のコマのフキダシは自分のフキダシであっても含まない' do
284 hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
285 npl = FactoryGirl.build :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
287 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
290 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
294 pl = SpeechBalloon.list
297 context 'DBに5件あって1ページの件数を2件に変えたとして' do
299 @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
300 @speech2 = @sb2.build_speech(
301 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
303 @balloon2 = @sb2.build_balloon(
304 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
308 @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
309 @speech3 = @sb3.build_speech(
310 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
312 @balloon3 = @sb3.build_balloon(
313 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
317 @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
318 @speech4 = @sb4.build_speech(
319 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
321 @balloon4 = @sb4.build_balloon(
322 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
326 @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
327 @speech5 = @sb5.build_speech(
328 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
330 @balloon5 = @sb5.build_balloon(
331 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
335 SpeechBalloon.stub(:default_page_size).and_return(2)
338 pl = SpeechBalloon.list
339 pl.should have(2).items
341 it 'page=1なら末尾2件を返す' do
343 pl = SpeechBalloon.list(1)
344 pl.should eq [@sb5, @sb4]
346 it 'page=2なら中間2件を返す' do
347 pl = SpeechBalloon.list(2)
348 pl.should eq [@sb3, @sb2]
350 it 'page=3なら先頭1件を返す' do
351 pl = SpeechBalloon.list(3)
357 describe '自分のフキダシ一覧取得に於いて' do
359 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
360 @speech = @sb.build_speech(
361 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
363 @balloon = @sb.build_balloon(
364 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
369 context 'つつがなく終わるとき' do
370 it '一覧取得オプションを利用している' do
371 SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
372 SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
373 r = SpeechBalloon.mylist @author
377 pl = SpeechBalloon.mylist @author
381 nsb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
383 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
386 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
390 pl = SpeechBalloon.mylist @author
391 pl.should eq [nsb, @sb]
393 it '他人のコマのフキダシは公開コマでも含まない' do
394 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
395 nsb = FactoryGirl.build :speech_balloon, :panel_id => hpl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
397 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
400 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
404 pl = SpeechBalloon.mylist @author
407 it '自分のコマのフキダシは非公開コマでも含んでいる' do
408 pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
409 nsb = FactoryGirl.build :speech_balloon, :panel_id => pl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
411 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
414 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
418 r = SpeechBalloon.mylist @author
419 r.should eq [nsb, @sb]
421 context 'DBに5件あって1ページの件数を2件に変えたとして' do
423 @sb2 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
424 @speech2 = @sb2.build_speech(
425 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
427 @balloon2 = @sb2.build_balloon(
428 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
432 @sb3 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
433 @speech3 = @sb3.build_speech(
434 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
436 @balloon3 = @sb3.build_balloon(
437 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
441 @sb4 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
442 @speech4 = @sb4.build_speech(
443 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
445 @balloon4 = @sb4.build_balloon(
446 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
450 @sb5 = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
451 @speech5 = @sb5.build_speech(
452 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
454 @balloon5 = @sb5.build_balloon(
455 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
461 r = SpeechBalloon.mylist @author, 1, 2
462 r.should have(2).items
464 it 'page=1なら末尾2件を返す' do
466 r = SpeechBalloon.mylist(@author, 1, 2)
467 r.should eq [@sb5, @sb4]
469 it 'page=2なら中間2件を返す' do
470 r = SpeechBalloon.mylist(@author, 2, 2)
471 r.should eq [@sb3, @sb2]
473 it 'page=3なら先頭1件を返す' do
474 r = SpeechBalloon.mylist(@author, 3, 2)
480 describe '他作家のフキダシ一覧取得に於いて' do
482 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
483 @speech = @sb.build_speech(
484 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
486 @balloon = @sb.build_balloon(
487 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
491 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
492 @other_sb = FactoryGirl.build :speech_balloon, :panel_id => @other_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
493 @other_speech = @other_sb.build_speech(
494 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
496 @other_balloon = @other_sb.build_balloon(
497 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
503 r = SpeechBalloon.himlist @other_author
504 r.should eq [@other_sb]
507 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
508 new_sb = FactoryGirl.build :speech_balloon, :panel_id => new_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
510 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
512 new_sb.build_balloon(
513 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
517 r = SpeechBalloon.himlist @other_author
518 r.should eq [new_sb, @other_sb]
521 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
522 hidden_sb = FactoryGirl.build :speech_balloon, :panel_id => hidden_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
523 hidden_sb.build_speech(
524 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
526 hidden_sb.build_balloon(
527 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
531 r = SpeechBalloon.himlist @other_author
532 r.should eq [@other_sb]
534 context 'DBに5件あって1ページの件数を2件に変えたとして' do
536 @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
537 @other_sb2.build_speech(
538 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
540 @other_sb2.build_balloon(
541 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 100)
545 @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
546 @other_sb3.build_speech(
547 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
549 @other_sb3.build_balloon(
550 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 200)
554 @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
555 @other_sb4.build_speech(
556 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
558 @other_sb4.build_balloon(
559 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 300)
563 @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
564 @other_sb5.build_speech(
565 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
567 @other_sb5.build_balloon(
568 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id, :updated_at => Time.now + 400)
574 r = SpeechBalloon.himlist @other_author, 1, 2
575 r.should have(2).items
577 it 'page=1なら末尾2件を返す' do
579 r = SpeechBalloon.himlist @other_author, 1, 2
580 r.should eq [@other_sb5, @other_sb4]
582 it 'page=2なら中間2件を返す' do
583 r = SpeechBalloon.himlist @other_author, 2, 2
584 r.should eq [@other_sb3, @other_sb2]
586 it 'page=3なら先頭1件を返す' do
587 r = SpeechBalloon.himlist @other_author, 3, 2
588 r.should eq [@other_sb]
593 describe 'フキダシ一覧ページ制御に於いて' do
595 SpeechBalloon.stub(:count).with(any_args).and_return(100)
598 r = SpeechBalloon.list_paginate
599 r.is_a?(Kaminari::PaginatableArray).should be_true
601 it 'フキダシ一覧の取得条件を利用している' do
602 SpeechBalloon.stub(:list_where).with(any_args).and_return('')
603 SpeechBalloon.should_receive(:list_where).with(any_args).exactly(1)
604 r = SpeechBalloon.list_paginate
606 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
607 r = SpeechBalloon.list_paginate 3, 10
608 r.limit_value.should eq 10
609 r.offset_value.should eq 20
613 describe '自分のフキダシ一覧ページ制御に於いて' do
615 SpeechBalloon.stub(:count).with(any_args).and_return(100)
618 r = SpeechBalloon.mylist_paginate @author
619 r.is_a?(Kaminari::PaginatableArray).should be_true
621 it '自分のフキダシ一覧の取得条件を利用している' do
622 SpeechBalloon.stub(:mylist_where).with(any_args).and_return('')
623 SpeechBalloon.should_receive(:mylist_where).with(any_args).exactly(1)
624 r = SpeechBalloon.mylist_paginate @author
626 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
627 r = SpeechBalloon.mylist_paginate @author, 3, 10
628 r.limit_value.should eq 10
629 r.offset_value.should eq 20
633 describe '他作家のフキダシ一覧ページ制御に於いて' do
635 SpeechBalloon.stub(:count).with(any_args).and_return(100)
638 r = SpeechBalloon.himlist_paginate @other_author
639 r.is_a?(Kaminari::PaginatableArray).should be_true
641 it '他作家のフキダシ一覧の取得条件を利用している' do
642 SpeechBalloon.stub(:himlist_where).with(any_args).and_return('')
643 SpeechBalloon.should_receive(:himlist_where).with(any_args).exactly(1)
644 r = SpeechBalloon.himlist_paginate @other_author
646 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
647 r = SpeechBalloon.himlist_paginate @other_author, 3, 10
648 r.limit_value.should eq 10
649 r.offset_value.should eq 20
653 describe '一覧取得オプションに於いて' do
655 r = SpeechBalloon.list_opt
656 r.should have(4).items
659 r = SpeechBalloon.list_opt
660 r.has_key?(:panel).should be_true
663 r = SpeechBalloon.list_opt
664 r[:panel].has_key?(:author).should be_true
667 r = SpeechBalloon.list_opt
668 r.has_key?(:balloon).should be_true
671 r = SpeechBalloon.list_opt
672 r.has_key?(:speech).should be_true
674 it 'フキダシテンプレートを含んでいる' do
675 r = SpeechBalloon.list_opt
676 r.has_key?(:speech_balloon_template).should be_true
679 describe 'json一覧出力オプションに於いて' do
681 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
682 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
683 @speech = @sb.build_speech(
684 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
686 @balloon = @sb.build_balloon(
687 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
693 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
696 i.has_key?('panel').should be_true
699 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
703 s.has_key?('author').should be_true
706 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
709 i.has_key?('balloon').should be_true
712 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
715 i.has_key?('speech').should be_true
717 it 'フキダシテンプレートを含んでいる' do
718 r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
721 i.has_key?('speech_balloon_template').should be_true
725 describe '単体取得に於いて' do
727 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
728 @speech = @sb.build_speech(
729 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
731 @balloon = @sb.build_balloon(
732 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
737 context 'つつがなく終わるとき' do
738 it '単体取得オプションを利用している' do
739 SpeechBalloon.stub(:show_opt).with(any_args).and_return({:include => :panel})
740 SpeechBalloon.should_receive(:show_opt).with(any_args).exactly(1)
741 r = SpeechBalloon.show @sb.id, @author
743 it '閲覧許可を問い合わせている' do
744 SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)
745 SpeechBalloon.any_instance.should_receive(:visible?).with(any_args).exactly(1)
746 r = SpeechBalloon.show @sb.id, @author
750 SpeechBalloon.any_instance.stub(:visible?).and_return(true)
751 pl = SpeechBalloon.show @sb.id, @author
754 context '閲覧許可が出なかったとき' do
755 it '403Forbidden例外を返す' do
756 SpeechBalloon.any_instance.stub(:visible?).and_return(false)
758 SpeechBalloon.show @sb.id, @author
759 }.should raise_error(ActiveRecord::Forbidden)
762 context '存在しないフキダシを開こうとしたとき' do
763 it '404RecordNotFound例外を返す' do
765 SpeechBalloon.show 110, @author
766 }.should raise_error(ActiveRecord::RecordNotFound)
770 describe '単体取得オプションに於いて' do
771 it 'includeキーを含んでいる' do
772 r = SpeechBalloon.show_opt
773 r.has_key?(:include).should be_true
776 r = SpeechBalloon.show_opt[:include]
777 r.should have(4).items
780 r = SpeechBalloon.show_opt[:include]
781 r.has_key?(:panel).should be_true
784 r = SpeechBalloon.show_opt[:include]
785 r[:panel].has_key?(:author).should be_true
788 r = SpeechBalloon.show_opt[:include]
789 r.has_key?(:balloon).should be_true
792 r = SpeechBalloon.show_opt[:include]
793 r.has_key?(:speech).should be_true
795 it 'フキダシテンプレートを含んでいる' do
796 r = SpeechBalloon.show_opt[:include]
797 r.has_key?(:speech_balloon_template).should be_true
800 describe 'json単体出力オプションに於いて' do
802 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
803 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
804 @speech = @sb.build_speech(
805 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
807 @balloon = @sb.build_balloon(
808 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
814 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
817 i.has_key?('panel').should be_true
820 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
824 s.has_key?('author').should be_true
827 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
830 i.has_key?('balloon').should be_true
833 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
836 i.has_key?('speech').should be_true
838 it 'フキダシテンプレートを含んでいる' do
839 r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
842 i.has_key?('speech_balloon_template').should be_true