OSDN Git Service

t#31566:add mylist sb
[pettanr/pettanr.git] / spec / models / speech_balloon_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #フキダシ
4
5 describe SpeechBalloon do
6   before 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
17     
18     @panel = FactoryGirl.create :panel, :author_id => @author.id
19     @speech_balloon_template = FactoryGirl.create :speech_balloon_template
20   end
21   
22   describe '検証に於いて' do
23     before do
24       @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
25     end
26     
27     context 'オーソドックスなデータのとき' do
28       it '下限データが通る' do
29         @sb.classname = 'a'
30         @sb.z = 1
31         @sb.t = 0
32         @sb.should be_valid
33       end
34       it '上限データが通る' do
35         @sb.classname = 'a'*50
36         @sb.z = 99999
37         @sb.t = 99999
38         @sb.should be_valid
39       end
40     end
41     
42     context 'panel_idを検証するとき' do
43       #ネストの保存はnilを許可しなければならないので数値チェックだけ
44       it '数値でなければ失敗する' do
45         @sb.panel_id = 'a'
46         @sb.should_not be_valid
47       end
48     end
49     context 'speech_balloon_template_idを検証するとき' do
50       it 'nullなら失敗する' do
51         @sb.speech_balloon_template_id = nil
52         @sb.should_not be_valid
53       end
54       it '数値でなければ失敗する' do
55         @sb.speech_balloon_template_id = 'a'
56         @sb.should_not be_valid
57       end
58       it '存在するフキダシテンプレートでなければ失敗する' do
59         @sb.speech_balloon_template_id = 0
60         @sb.should_not be_valid
61       end
62     end
63     context 'classnameを検証するとき' do
64       it 'nullなら失敗する' do
65         @sb.classname = ''
66         @sb.should_not be_valid
67       end
68       it '51文字以上なら失敗する' do
69         @sb.classname = 'a'*51
70         @sb.should_not be_valid
71       end
72     end
73     context 'tを検証するとき' do
74       it 'nullなら失敗する' do
75         @sb.t = nil
76         @sb.should_not be_valid
77       end
78       it '数値でなければ失敗する' do
79         @sb.t = 'a'
80         @sb.should_not be_valid
81       end
82       it '負なら失敗する' do
83         @sb.t = -1
84         @sb.should_not be_valid
85       end
86     end
87     context 'settingsを検証するとき' do
88     end
89   end
90   
91   describe '文字コード検証に於いて' do
92     before do
93       @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
94     end
95     
96     context 'classnameを検証するとき' do
97       it 'Shift JISなら失敗する' do
98         @sb.classname = "\x83G\x83r\x83]\x83D"
99         lambda{
100           @sb.valid_encode
101         }.should raise_error(Pettanr::BadRequest)
102       end
103     end
104     
105     context 'settingsを検証するとき' do
106       it 'Shift JISなら失敗する' do
107         @sb.settings = "\x83G\x83r\x83]\x83D"
108         lambda{
109           @sb.valid_encode
110         }.should raise_error(Pettanr::BadRequest)
111       end
112     end
113     
114     context 'captionを検証するとき' do
115       it 'Shift JISなら失敗する' do
116         @sb.caption = "\x83G\x83r\x83]\x83D"
117         lambda{
118           @sb.valid_encode
119         }.should raise_error(Pettanr::BadRequest)
120       end
121     end
122     
123   end
124   
125   describe '閲覧許可に於いて' do
126     before do
127       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
128     end
129     context 'オープンモードのとき' do
130       before do
131         MagicNumber['run_mode'] = 0
132       end
133       it '自身にゲスト用ロールチェックを問い合わせしている' do
134         SpeechBalloon.any_instance.stub(:guest_role_check).and_return(true)
135         SpeechBalloon.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
136         r = @sb.visible?([@author])
137       end
138       it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
139         SpeechBalloon.any_instance.stub(:guest_role_check).and_return(false)
140         r = @sb.visible?([@author])
141         r.should be_false
142       end
143     end
144     context 'クローズドモードのとき' do
145       before do
146         MagicNumber['run_mode'] = 1
147       end
148       it '自身に読者用ロールチェックを問い合わせしている' do
149         SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
150         SpeechBalloon.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
151         r = @sb.visible?([@author])
152       end
153       it '読者用ロールチェックが失敗したとき、falseを返す' do
154         SpeechBalloon.any_instance.stub(:reader_role_check).and_return(false)
155         r = @sb.visible?([@author])
156         r.should be_false
157       end
158     end
159     context '事前チェックする' do
160       before do
161         MagicNumber['run_mode'] = 1
162         SpeechBalloon.any_instance.stub(:reader_role_check).and_return(true)
163       end
164       it '自身のコマに所持判定を問い合わせしている' do
165         Panel.any_instance.stub(:own?).and_return(true)
166         Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
167         r = @sb.visible?([@author])
168       end
169       it '自身のコマに閲覧許可を問い合わせしている' do
170         Panel.any_instance.stub(:own?).and_return(false)
171         Panel.any_instance.stub(:visible?).and_return(true)
172         Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
173         r = @sb.visible?([@author])
174       end
175     end
176     context 'つつがなく終わるとき' do
177       before do
178         MagicNumber['run_mode'] = 1
179         Panel.any_instance.stub(:reader_role_check).and_return(true)
180       end
181       it '自分のコマのフキダシなら許可する' do
182         Panel.any_instance.stub(:own?).and_return(true)
183         Panel.any_instance.stub(:visible?).and_return(false)
184         r = @sb.visible?([@author])
185         r.should be_true
186       end
187       it '他人の非公開コマのフキダシなら許可しない' do
188         Panel.any_instance.stub(:own?).and_return(false)
189         Panel.any_instance.stub(:visible?).and_return(false)
190         r = @sb.visible?([@author])
191         r.should be_false
192       end
193       it '他人のコマのフキダシでも公開なら許可する' do
194         Panel.any_instance.stub(:own?).and_return(false)
195         Panel.any_instance.stub(:visible?).and_return(true)
196         r = @sb.visible?([@author])
197         r.should be_true
198       end
199     end
200   end
201   
202   describe '一覧取得に於いて' do
203     before do
204       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
205       @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
206       @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
207     end
208     context 'page補正について' do
209       it '文字列から数値に変換される' do
210         SpeechBalloon.page('8').should eq 8
211       end
212       it 'nilの場合は1になる' do
213         SpeechBalloon.page().should eq 1
214       end
215       it '0以下の場合は1になる' do
216         SpeechBalloon.page('0').should eq 1
217       end
218     end
219     context 'page_size補正について' do
220       it '文字列から数値に変換される' do
221         SpeechBalloon.page_size('7').should eq 7
222       end
223       it 'nilの場合はSpeechBalloon.default_page_sizeになる' do
224         SpeechBalloon.page_size().should eq SpeechBalloon.default_page_size
225       end
226       it '0以下の場合はSpeechBalloon.default_page_sizeになる' do
227         SpeechBalloon.page_size('0').should eq SpeechBalloon.default_page_size
228       end
229       it 'SpeechBalloon.max_page_sizeを超えた場合はSpeechBalloon.max_page_sizeになる' do
230         SpeechBalloon.page_size('1000').should eq SpeechBalloon.max_page_size
231       end
232     end
233     context 'つつがなく終わるとき' do
234       it '一覧取得オプションを利用している' do
235         SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
236         SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
237         r = SpeechBalloon.list
238       end
239     end
240     it 'リストを返す' do
241       r = SpeechBalloon.list
242       r.should eq [@sb]
243     end
244     it '時系列で並んでいる' do
245       #公開されたコマのフキダシは(他人のフキダシであっても)含んでいる
246       hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
247       npl = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
248       r = SpeechBalloon.list
249       r.should eq [npl, @sb]
250     end
251     it '非公開のコマのフキダシは自分のフキダシであっても含まない' do
252       hc = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
253       npl = FactoryGirl.create :speech_balloon, :panel_id => hc.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
254       pl = SpeechBalloon.list
255       pl.should eq [@sb]
256     end
257     context 'DBに5件あって1ページの件数を2件に変えたとして' do
258       before do
259         @sb2 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 1, :updated_at => Time.now + 100
260         @sb3 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 2, :updated_at => Time.now + 200
261         @sb4 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 3, :updated_at => Time.now + 300
262         @sb5 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :t => 4, :updated_at => Time.now + 400
263         SpeechBalloon.stub(:default_page_size).and_return(2)
264       end
265       it '通常は2件を返す' do
266         pl = SpeechBalloon.list
267         pl.should have(2).items 
268       end
269       it 'page=1なら末尾2件を返す' do
270         #時系列で並んでいる
271         pl = SpeechBalloon.list(1)
272         pl.should eq [@sb5, @sb4]
273       end
274       it 'page=2なら中間2件を返す' do
275         pl = SpeechBalloon.list(2)
276         pl.should eq [@sb3, @sb2]
277       end
278       it 'page=3なら先頭1件を返す' do
279         pl = SpeechBalloon.list(3)
280         pl.should eq [@sb]
281       end
282     end
283   end
284   
285   describe '自分のフキダシ一覧取得に於いて' do
286     before do
287       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
288       @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
289       @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
290     end
291     context 'つつがなく終わるとき' do
292       it '一覧取得オプションを利用している' do
293         SpeechBalloon.stub(:list_opt).with(any_args).and_return({:include => :panel})
294         SpeechBalloon.should_receive(:list_opt).with(any_args).exactly(1)
295         r = SpeechBalloon.mylist @author
296       end
297     end
298     it 'リストを返す' do
299       pl = SpeechBalloon.mylist @author
300       pl.should eq [@sb]
301     end
302     it '時系列で並んでいる' do
303       npl = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
304       pl = SpeechBalloon.mylist @author
305       pl.should eq [npl, @sb]
306     end
307     it '他人のコマのフキダシは公開コマでも含まない' do
308       hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
309       npl = FactoryGirl.create :speech_balloon, :panel_id => hpl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
310       pl = SpeechBalloon.mylist @author
311       pl.should eq [@sb]
312     end
313     it '自分のコマのフキダシは非公開コマでも含んでいる' do
314       pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
315       ni = FactoryGirl.create :speech_balloon, :panel_id => pl.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
316       r = SpeechBalloon.mylist @author
317       r.should eq [ni, @sb]
318     end
319     context 'DBに5件あって1ページの件数を2件に変えたとして' do
320       before do
321         @npl2 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
322         @npl3 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
323         @npl4 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
324         @npl5 = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
325       end
326       it '通常は2件を返す' do
327         r = SpeechBalloon.mylist @author, 1, 2
328         r.should have(2).items 
329       end
330       it 'page=1なら末尾2件を返す' do
331         #時系列で並んでいる
332         r = SpeechBalloon.mylist(@author, 1, 2)
333         r.should eq [@npl5, @npl4]
334       end
335       it 'page=2なら中間2件を返す' do
336         r = SpeechBalloon.mylist(@author, 2, 2)
337         r.should eq [@npl3, @npl2]
338       end
339       it 'page=3なら先頭1件を返す' do
340         r = SpeechBalloon.mylist(@author, 3, 2)
341         r.should eq [@sb]
342       end
343     end
344   end
345   
346   describe '他作家のフキダシ一覧取得に於いて' do
347     before do
348       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
349       @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
350       @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
351       @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
352       @other_sb = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
353     end
354     it 'リストを返す' do
355       r = SpeechBalloon.himlist @other_author
356       r.should eq [@other_sb]
357     end
358     it '時系列で並んでいる' do
359       new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
360       new_sb = FactoryGirl.create :speech_balloon, :panel_id => new_panel.id, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
361       r = SpeechBalloon.himlist @other_author
362       r.should eq [new_sb, @other_sb]
363     end
364     it '公開コマに限る' do
365       hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
366       hidden_sb = FactoryGirl.create :speech_balloon, :panel_id => hidden_panel.id, :speech_balloon_template_id => @speech_balloon_template.id
367       r = SpeechBalloon.himlist @other_author
368       r.should eq [@other_sb]
369     end
370     context 'DBに5件あって1ページの件数を2件に変えたとして' do
371       before do
372         @other_sb2 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 1, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 100
373         @other_sb3 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 2, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 200
374         @other_sb4 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 3, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 300
375         @other_sb5 = FactoryGirl.create :speech_balloon, :panel_id => @other_panel.id, :t => 4, :speech_balloon_template_id => @speech_balloon_template.id, :updated_at => Time.now + 400
376       end
377       it '通常は2件を返す' do
378         r = SpeechBalloon.himlist @other_author, 1, 2
379         r.should have(2).items 
380       end
381       it 'page=1なら末尾2件を返す' do
382         #時系列で並んでいる
383         r = SpeechBalloon.himlist @other_author, 1, 2
384         r.should eq [@other_sb5, @other_sb4]
385       end
386       it 'page=2なら中間2件を返す' do
387         r = SpeechBalloon.himlist @other_author, 2, 2
388         r.should eq [@other_sb3, @other_sb2]
389       end
390       it 'page=3なら先頭1件を返す' do
391         r = SpeechBalloon.himlist @other_author, 3, 2
392         r.should eq [@other_sb]
393       end
394     end
395   end
396   
397   describe 'フキダシ一覧ページ制御に於いて' do
398     before do
399       SpeechBalloon.stub(:count).with(any_args).and_return(100)
400     end
401     it 'ページ制御を返す' do
402       r = SpeechBalloon.list_paginate 
403       r.is_a?(Kaminari::PaginatableArray).should be_true
404     end
405     it 'フキダシ一覧の取得条件を利用している' do
406       SpeechBalloon.stub(:list_where).with(any_args).and_return('')
407       SpeechBalloon.should_receive(:list_where).with(any_args).exactly(1)
408       r = SpeechBalloon.list_paginate 
409     end
410     it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
411       r = SpeechBalloon.list_paginate 3, 10
412       r.limit_value.should eq 10
413       r.offset_value.should eq 20
414     end
415   end
416   
417   describe '自分のフキダシ一覧ページ制御に於いて' do
418     before do
419       SpeechBalloon.stub(:count).with(any_args).and_return(100)
420     end
421     it 'ページ制御を返す' do
422       r = SpeechBalloon.mylist_paginate @author
423       r.is_a?(Kaminari::PaginatableArray).should be_true
424     end
425     it '自分のフキダシ一覧の取得条件を利用している' do
426       SpeechBalloon.stub(:mylist_where).with(any_args).and_return('')
427       SpeechBalloon.should_receive(:mylist_where).with(any_args).exactly(1)
428       r = SpeechBalloon.mylist_paginate @author
429     end
430     it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
431       r = SpeechBalloon.mylist_paginate @author, 3, 10
432       r.limit_value.should eq 10
433       r.offset_value.should eq 20
434     end
435   end
436   
437   describe '他作家のフキダシ一覧ページ制御に於いて' do
438     before do
439       SpeechBalloon.stub(:count).with(any_args).and_return(100)
440     end
441     it 'ページ制御を返す' do
442       r = SpeechBalloon.himlist_paginate @other_author
443       r.is_a?(Kaminari::PaginatableArray).should be_true
444     end
445     it '他作家のフキダシ一覧の取得条件を利用している' do
446       SpeechBalloon.stub(:himlist_where).with(any_args).and_return('')
447       SpeechBalloon.should_receive(:himlist_where).with(any_args).exactly(1)
448       r = SpeechBalloon.himlist_paginate @other_author
449     end
450     it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
451       r = SpeechBalloon.himlist_paginate @other_author, 3, 10
452       r.limit_value.should eq 10
453       r.offset_value.should eq 20
454     end
455   end
456   
457   describe '一覧取得オプションに於いて' do
458     it '4つの項目を含んでいる' do
459       r = SpeechBalloon.list_opt
460       r.should have(4).items
461     end
462     it 'コマを含んでいる' do
463       r = SpeechBalloon.list_opt
464       r.has_key?(:panel).should be_true
465     end
466       it 'コマは作家を含んでいる' do
467         r = SpeechBalloon.list_opt
468         r[:panel].has_key?(:author).should be_true
469       end
470     it 'フキダシ枠を含んでいる' do
471       r = SpeechBalloon.list_opt
472       r.has_key?(:balloon).should be_true
473     end
474     it 'セリフを含んでいる' do
475       r = SpeechBalloon.list_opt
476       r.has_key?(:speech).should be_true
477     end
478     it 'フキダシテンプレートを含んでいる' do
479       r = SpeechBalloon.list_opt
480       r.has_key?(:speech_balloon_template).should be_true
481     end
482   end
483   describe 'json一覧出力オプションに於いて' do
484     before do
485       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
486       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
487       @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
488       @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
489     end
490     it 'コマを含んでいる' do
491       r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
492       j = JSON.parse r
493       i = j.first
494       i.has_key?('panel').should be_true
495     end
496       it 'コマは作家を含んでいる' do
497         r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
498         j = JSON.parse r
499         i = j.first
500         s = i['panel']
501         s.has_key?('author').should be_true
502       end
503     it 'フキダシ枠を含んでいる' do
504       r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
505       j = JSON.parse r
506       i = j.first
507       i.has_key?('balloon').should be_true
508     end
509     it 'セリフを含んでいる' do
510       r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
511       j = JSON.parse r
512       i = j.first
513       i.has_key?('speech').should be_true
514     end
515     it 'フキダシテンプレートを含んでいる' do
516       r = SpeechBalloon.list.to_json SpeechBalloon.list_json_opt
517       j = JSON.parse r
518       i = j.first
519       i.has_key?('speech_balloon_template').should be_true
520     end
521   end
522   
523   describe '単体取得に於いて' do
524     before do
525       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
526       @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
527       @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
528     end
529     context 'つつがなく終わるとき' do
530       it '単体取得オプションを利用している' do
531         SpeechBalloon.stub(:show_opt).with(any_args).and_return({:include => :panel})
532         SpeechBalloon.should_receive(:show_opt).with(any_args).exactly(1)
533         r = SpeechBalloon.show @sb.id, @author
534       end
535       it '閲覧許可を問い合わせている' do
536         SpeechBalloon.any_instance.stub(:visible?).with(any_args).and_return(true)
537         SpeechBalloon.any_instance.should_receive(:visible?).with(any_args).exactly(1)
538         r = SpeechBalloon.show @sb.id, @author
539       end
540     end
541     it '指定のフキダシを返す' do
542       SpeechBalloon.any_instance.stub(:visible?).and_return(true)
543       pl = SpeechBalloon.show @sb.id, @author
544       pl.should eq @sb
545     end
546     context '閲覧許可が出なかったとき' do
547       it '403Forbidden例外を返す' do
548         SpeechBalloon.any_instance.stub(:visible?).and_return(false)
549         lambda{
550           SpeechBalloon.show @sb.id, @author
551         }.should raise_error(ActiveRecord::Forbidden)
552       end
553     end
554     context '存在しないフキダシを開こうとしたとき' do
555       it '404RecordNotFound例外を返す' do
556         lambda{
557           SpeechBalloon.show 110, @author
558         }.should raise_error(ActiveRecord::RecordNotFound)
559       end
560     end
561   end
562   describe '単体取得オプションに於いて' do
563     it 'includeキーを含んでいる' do
564       r = SpeechBalloon.show_opt
565       r.has_key?(:include).should be_true
566     end
567     it '4つの項目を含んでいる' do
568       r = SpeechBalloon.show_opt[:include]
569       r.should have(4).items
570     end
571     it 'コマを含んでいる' do
572       r = SpeechBalloon.show_opt[:include]
573       r.has_key?(:panel).should be_true
574     end
575       it 'コマは作家を含んでいる' do
576         r = SpeechBalloon.show_opt[:include]
577         r[:panel].has_key?(:author).should be_true
578       end
579     it 'フキダシ枠を含んでいる' do
580       r = SpeechBalloon.show_opt[:include]
581       r.has_key?(:balloon).should be_true
582     end
583     it 'セリフを含んでいる' do
584       r = SpeechBalloon.show_opt[:include]
585       r.has_key?(:speech).should be_true
586     end
587     it 'フキダシテンプレートを含んでいる' do
588       r = SpeechBalloon.show_opt[:include]
589       r.has_key?(:speech_balloon_template).should be_true
590     end
591   end
592   describe 'json単体出力オプションに於いて' do
593     before do
594       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
595       @sb = FactoryGirl.create :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
596       @balloon = FactoryGirl.create :balloon, :speech_balloon_id => @sb.id, :system_picture_id => @sp.id
597       @speech = FactoryGirl.create :speech, :speech_balloon_id => @sb.id
598     end
599     it 'コマを含んでいる' do
600       r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
601       j = JSON.parse r
602       i = j
603       i.has_key?('panel').should be_true
604     end
605       it 'コマは作家を含んでいる' do
606         r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
607         j = JSON.parse r
608         i = j
609         s = i['panel']
610         s.has_key?('author').should be_true
611       end
612     it 'フキダシ枠を含んでいる' do
613       r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
614       j = JSON.parse r
615       i = j
616       i.has_key?('balloon').should be_true
617     end
618     it 'セリフを含んでいる' do
619       r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
620       j = JSON.parse r
621       i = j
622       i.has_key?('speech').should be_true
623     end
624     it 'フキダシテンプレートを含んでいる' do
625       r = SpeechBalloon.show(@sb.id, @author).to_json SpeechBalloon.show_json_opt
626       j = JSON.parse r
627       i = j
628       i.has_key?('speech_balloon_template').should be_true
629     end
630   end
631 end