OSDN Git Service

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