OSDN Git Service

t#30286:artist separates outer artist
[pettanr/pettanr.git] / spec / models / panel_picture_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #コマ絵
4 describe PanelPicture do
5   before do
6     @admin = FactoryGirl.create :admin
7     @user = FactoryGirl.create( :user_yas)
8     @author = FactoryGirl.create :author, :user_id => @user.id
9     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
10     @other_user = FactoryGirl.create( :user_yas)
11     @other_author = FactoryGirl.create :author, :user_id => @other_user.id
12     @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
13     @sp = FactoryGirl.create :system_picture
14     @lg = FactoryGirl.create :license_group
15     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
16     @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
17     @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
18     @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
19     @panel = FactoryGirl.create :panel, :author_id => @author.id
20   end
21   
22   describe '検証に於いて' do
23     before do
24       @pp = FactoryGirl.build :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
25         :width => @p.width, :height => @p.height
26       Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
27       Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
28       Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
29     end
30     
31     context 'オーソドックスなデータのとき' do
32       it '下限データが通る' do
33         @pp.link = 'http://test.jp/'
34         @pp.x = -99999
35         @pp.y = -99999
36         @pp.z = 1
37         @pp.t = 0
38         @pp.width = -99999
39         @pp.height = -99999
40         @pp.should be_valid
41       end
42       it '上限データが通る' do
43         @pp.link = 'http://test.jp/aaaaa' + 'a' * 180
44         @pp.x = 99999
45         @pp.y = 99999
46         @pp.z = 99999
47         @pp.t = 99999
48         @pp.width = 99999
49         @pp.height = 99999
50         @pp.should be_valid
51       end
52     end
53     
54     context 'panel_idを検証するとき' do
55       #ネストの保存はnilを許可しなければならないので数値チェックだけ
56       it '数値でなければ失敗する' do
57         @pp.panel_id = 'a'
58         @pp.should_not be_valid
59       end
60     end
61     context 'linkを検証するとき' do
62       it 'nullでも通る' do
63         @pp.link = ''
64         @pp.should be_valid
65       end
66       it '201文字以上なら失敗する' do
67         @pp.link = 'a'*201
68         @pp.should_not be_valid
69       end
70       it 'url形式でないなら失敗する' do
71         @pp.link = 'a'*200
72         @pp.should_not be_valid
73       end
74     end
75     context 'xを検証するとき' do
76       it 'nullなら失敗する' do
77         @pp.x = nil
78         @pp.should_not be_valid
79       end
80       it '数値でなければ失敗する' do
81         @pp.x = 'a'
82         @pp.should_not be_valid
83       end
84       it '0なら通る' do
85         @pp.x = '0'
86         @pp.should be_valid
87       end
88       it '負でも通る' do
89         @pp.x = -1
90         @pp.should be_valid
91       end
92     end
93     context 'yを検証するとき' do
94       it 'nullなら失敗する' do
95         @pp.y = nil
96         @pp.should_not be_valid
97       end
98       it '数値でなければ失敗する' do
99         @pp.y = 'a'
100         @pp.should_not be_valid
101       end
102       it '0なら通る' do
103         @pp.y = '0'
104         @pp.should be_valid
105       end
106       it '負でも通る' do
107         @pp.y = -1
108         @pp.should be_valid
109       end
110     end
111     context 'widthを検証するとき' do
112       it 'nullなら失敗する' do
113         @pp.width = nil
114         @pp.should_not be_valid
115       end
116       it '数値でなければ失敗する' do
117         @pp.width = 'a'
118         @pp.should_not be_valid
119       end
120       it '0なら失敗する' do
121         @pp.width = '0'
122         @pp.should_not be_valid
123       end
124       context  '反転許可のとき' do
125         before do
126         end
127         it '負でも通る' do
128           @pp.width = -1
129           @pp.should be_valid
130         end
131       end
132       context  '反転禁止のとき' do
133         before do
134           Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
135         end
136         it '負なら失敗する' do
137           @pp.width = -1
138           @pp.should_not be_valid
139         end
140       end
141       context  'サイズ変更許可のとき' do
142         before do
143         end
144         it '実素材のサイズと違っても通る' do
145           @pp.width = @p.width-1
146           @pp.should be_valid
147         end
148       end
149       context  'サイズ変更禁止のとき' do
150         before do
151           Picture.any_instance.stub(:flag_resize).with(any_args).and_return(-1)
152         end
153         it '実素材のサイズと違うなら失敗する' do
154           @pp.width = @p.width-1
155           @pp.should_not be_valid
156         end
157       end
158       context  '縦横比変更許可のとき' do
159         before do
160         end
161         it '実素材の縦横比と違っても通る' do
162           @pp.width = @p.width / 2
163           @pp.should be_valid
164         end
165       end
166       context  '縦横比変更禁止のとき' do
167         before do
168           Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(-1)
169         end
170         it '実素材の縦横比と違うなら失敗する' do
171           @pp.width = @p.width / 2
172           @pp.should_not be_valid
173         end
174       end
175     end
176     context 'heightを検証するとき' do
177       it 'nullなら失敗する' do
178         @pp.height = nil
179         @pp.should_not be_valid
180       end
181       it '数値でなければ失敗する' do
182         @pp.height = 'a'
183         @pp.should_not be_valid
184       end
185       it '0なら失敗する' do
186         @pp.height = '0'
187         @pp.should_not be_valid
188       end
189       it '負でも通る' do
190         @pp.height = -1
191         @pp.should be_valid
192       end
193       context  '反転許可のとき' do
194         before do
195         end
196         it '負でも通る' do
197           @pp.height = -1
198           @pp.should be_valid
199         end
200       end
201       context  '反転禁止のとき' do
202         before do
203           Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
204         end
205         it '負なら失敗する' do
206           @pp.height = -1
207           @pp.should_not be_valid
208         end
209       end
210       context  'サイズ変更許可のとき' do
211         before do
212         end
213         it '実素材のサイズと違っても通る' do
214           @pp.height = @p.height-1
215           @pp.should be_valid
216         end
217       end
218       context  'サイズ変更禁止のとき' do
219         before do
220           Picture.any_instance.stub(:flag_resize).with(any_args).and_return(-1)
221         end
222         it '実素材のサイズと違うなら失敗する' do
223           @pp.height = @p.height-1
224           @pp.should_not be_valid
225         end
226       end
227       context  '縦横比変更許可のとき' do
228         before do
229         end
230         it '実素材の縦横比と違っても通る' do
231           @pp.height = @p.height / 2
232           @pp.should be_valid
233         end
234       end
235       context  '縦横比変更禁止のとき' do
236         before do
237           Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(-1)
238         end
239         it '実素材の縦横比と違うなら失敗する' do
240           @pp.height = @p.height / 2
241           @pp.should_not be_valid
242         end
243       end
244     end
245     context 'zを検証するとき' do
246       it 'nullなら失敗する' do
247         @pp.z = nil
248         @pp.should_not be_valid
249       end
250       it '数値でなければ失敗する' do
251         @pp.z = 'a'
252         @pp.should_not be_valid
253       end
254       it '負なら失敗する' do
255         @pp.z = -1
256         @pp.should_not be_valid
257       end
258       it '負なら失敗する' do
259         @pp.z = 0
260         @pp.should_not be_valid
261       end
262     end
263     context 'tを検証するとき' do
264       it 'nullなら失敗する' do
265         @pp.t = nil
266         @pp.should_not be_valid
267       end
268       it '数値でなければ失敗する' do
269         @pp.t = 'a'
270         @pp.should_not be_valid
271       end
272       it '負なら失敗する' do
273         @pp.t = -1
274         @pp.should_not be_valid
275       end
276     end
277     context 'picture_idを検証するとき' do
278       it 'nullなら失敗する' do
279         @pp.picture_id = nil
280         @pp.should_not be_valid
281       end
282       it '数値でなければ失敗する' do
283         @pp.picture_id = 'a'
284         @pp.should_not be_valid
285       end
286       it '存在する実素材でなければ失敗する' do
287         @pp.picture_id = 0
288         @pp.should_not be_valid
289       end
290     end
291   end
292   describe '閲覧許可に於いて' do
293     before do
294       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
295         :width => @p.width, :height => @p.height
296     end
297     context '検査対象がnil(ゲスト)のとき' do
298       context 'クローズドモードのとき' do
299         before do
300           MagicNumber['run_mode'] = 1
301         end
302         it '不許可を返す。' do
303           r = @pp.visible?(nil)
304           r.should be_false
305         end
306       end
307       context 'オープンモードのとき' do
308         before do
309           MagicNumber['run_mode'] = 0
310         end
311         it '公開されたコマのコマ絵なら許可する' do
312           Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
313           r = @pp.visible?(nil)
314           r.should be_true
315         end
316         it 'れ以外なら不許可を返す' do
317           Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
318           r = @pp.visible?(nil)
319           r.should be_false
320         end
321       end
322     end
323     context '検査対象が作家のとき' do
324       it '公開されたコマのコマ絵なら許可する' do
325         Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
326         r = @pp.visible?(@author)
327         r.should be_true
328       end
329       it 'れ以外なら不許可を返す' do
330         Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
331         r = @pp.visible?(@author)
332         r.should be_false
333       end
334     end
335     context '検査対象が管理者のとき' do
336       it '許可を返す。' do
337         Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
338         r = @pp.visible?(@admin)
339         r.should be_true
340       end
341     end
342     context '検査対象がそれ以外のとき' do
343       it '不許可を返す。' do
344         r = @pp.visible?(1)
345         r.should be_false
346       end
347     end
348   end
349   describe '一覧取得に於いて' do
350     before do
351       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
352         :width => @p.width, :height => @p.height
353     end
354     context 'page補正について' do
355       it '文字列から数値に変換される' do
356         PanelPicture.page('8').should eq 8
357       end
358       it 'nilの場合は1になる' do
359         PanelPicture.page().should eq 1
360       end
361       it '0以下の場合は1になる' do
362         PanelPicture.page('0').should eq 1
363       end
364     end
365     context 'page_size補正について' do
366       it '文字列から数値に変換される' do
367         PanelPicture.page_size('7').should eq 7
368       end
369       it 'nilの場合はPanelPicture.default_page_sizeになる' do
370         PanelPicture.page_size().should eq PanelPicture.default_page_size
371       end
372       it '0以下の場合はPanelPicture.default_page_sizeになる' do
373         PanelPicture.page_size('0').should eq PanelPicture.default_page_size
374       end
375       it 'PanelPicture.max_page_sizeを超えた場合はPanelPicture.max_page_sizeになる' do
376         PanelPicture.page_size('1000').should eq PanelPicture.max_page_size
377       end
378     end
379     context 'つつがなく終わるとき' do
380       it '一覧取得オプションを利用している' do
381         PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
382         PanelPicture.should_receive(:list_opt).with(any_args).exactly(1)
383         r = PanelPicture.list
384       end
385     end
386     it 'リストを返す' do
387       r = PanelPicture.list
388       r.should eq [@pp]
389     end
390     it '時系列で並んでいる' do
391       #公開されたコマのコマ絵は(他人のコマ絵であっても)含んでいる
392       hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
393       npl = FactoryGirl.create :panel_picture, :panel_id => hc.id, :t => 0, :picture_id => @p.id,
394         :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
395       r = PanelPicture.list
396       r.should eq [npl, @pp]
397     end
398     it '非公開のコマのコマ絵は自分のコマ絵であっても含まない' do
399       hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
400       npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
401         :width => @p.width, :height => @p.height
402       pl = PanelPicture.list
403       pl.should eq [@pp]
404     end
405     context 'DBに5件あって1ページの件数を2件に変えたとして' do
406       before do
407         @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
408           :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
409         @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
410           :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
411         @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
412           :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
413         @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
414           :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
415         PanelPicture.stub(:default_page_size).and_return(2)
416       end
417       it '通常は2件を返す' do
418         pl = PanelPicture.list
419         pl.should have(2).items 
420       end
421       it 'page=1なら末尾2件を返す' do
422         #時系列で並んでいる
423         pl = PanelPicture.list(1)
424         pl.should eq [@npl5, @npl4]
425       end
426       it 'page=2なら中間2件を返す' do
427         pl = PanelPicture.list(2)
428         pl.should eq [@npl3, @npl2]
429       end
430       it 'page=3なら先頭1件を返す' do
431         pl = PanelPicture.list(3)
432         pl.should eq [@pp]
433       end
434     end
435     context 'DBに5件あって1ページの件数を0件に変えたとして' do
436       before do
437         @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
438           :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
439         @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
440           :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
441         @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
442           :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
443         @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
444           :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
445         PanelPicture.stub(:default_page_size).and_return(2)
446       end
447       it '通常は全件(5件)を返す' do
448         r = PanelPicture.list 5, 0
449         r.should have(5).items 
450       end
451     end
452   end
453   describe '一覧取得オプションに於いて' do
454     it 'includeキーを含んでいる' do
455       r = PanelPicture.list_opt
456       r.has_key?(:include).should be_true
457     end
458     it '2つの項目を含んでいる' do
459       r = PanelPicture.list_opt[:include]
460       r.should have(2).items
461     end
462     it 'コマを含んでいる' do
463       r = PanelPicture.list_opt[:include]
464       r.has_key?(:panel).should be_true
465     end
466       it 'コマは作家を含んでいる' do
467         r = PanelPicture.list_opt[:include]
468         r[:panel].has_key?(:author).should be_true
469       end
470     it '実素材を含んでいる' do
471       r = PanelPicture.list_opt[:include]
472       r.has_key?(:picture).should be_true
473     end
474       it '実素材は絵師を含んでいる' do
475         r = PanelPicture.list_opt[:include]
476         r[:picture].has_key?(:artist).should be_true
477       end
478       it '実素材はライセンスを含んでいる' do
479         r = PanelPicture.list_opt[:include]
480         r[:picture].has_key?(:license).should be_true
481       end
482   end
483   describe 'json一覧出力オプションに於いて' do
484     before do
485       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
486       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
487       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
488       @sbt = FactoryGirl.create :speech_balloon_template
489       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
490       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
491         :width => @p.width, :height => @p.height
492     end
493     it 'コマを含んでいる' do
494       r = PanelPicture.list.to_json PanelPicture.list_json_opt
495       j = JSON.parse r
496       i = j.first
497       i.has_key?('panel').should be_true
498     end
499       it 'コマは作家を含んでいる' do
500         r = PanelPicture.list.to_json PanelPicture.list_json_opt
501         j = JSON.parse r
502         i = j.first
503         s = i['panel']
504         s.has_key?('author').should be_true
505       end
506     it '実素材を含んでいる' do
507       r = PanelPicture.list.to_json PanelPicture.list_json_opt
508       j = JSON.parse r
509       i = j.first
510       i.has_key?('picture').should be_true
511     end
512       it '実素材は絵師を含んでいる' do
513         r = PanelPicture.list.to_json PanelPicture.list_json_opt
514         j = JSON.parse r
515         i = j.first
516         s = i['picture']
517         s.has_key?('artist').should be_true
518       end
519       it '実素材はライセンスを含んでいる' do
520         r = PanelPicture.list.to_json PanelPicture.list_json_opt
521         j = JSON.parse r
522         i = j.first
523         s = i['picture']
524         s.has_key?('license').should be_true
525       end
526   end
527   
528   describe '自分のコマ絵一覧取得に於いて' do
529     before do
530       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
531         :width => @p.width, :height => @p.height
532     end
533     context 'つつがなく終わるとき' do
534       it '一覧取得オプションを利用している' do
535         PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
536         PanelPicture.should_receive(:list_opt).with(any_args).exactly(1)
537         r = PanelPicture.mylist @author
538       end
539     end
540     it 'リストを返す' do
541       pl = PanelPicture.mylist @author
542       pl.should eq [@pp]
543     end
544     it '時系列で並んでいる' do
545       npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
546         :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
547       pl = PanelPicture.mylist @author
548       pl.should eq [npl, @pp]
549     end
550     it '他人のコマのコマ絵は公開コマでも含まない' do
551       hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
552       npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
553         :width => @p.width, :height => @p.height
554       pl = PanelPicture.mylist @author
555       pl.should eq [@pp]
556     end
557     it '自分のコマのコマ絵は非公開コマでも含んでいる' do
558       pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
559       ni = FactoryGirl.create :panel_picture, :panel_id => pl.id, :picture_id => @p.id,
560         :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
561       r = PanelPicture.mylist @author
562       r.should eq [ni, @pp]
563     end
564     context 'DBに5件あって1ページの件数を2件に変えたとして' do
565       before do
566         @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
567           :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
568         @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
569           :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
570         @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
571           :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
572         @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
573           :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
574       end
575       it '通常は2件を返す' do
576         r = PanelPicture.mylist @author, 1, 2
577         r.should have(2).items 
578       end
579       it 'page=1なら末尾2件を返す' do
580         #時系列で並んでいる
581         r = PanelPicture.mylist(@author, 1, 2)
582         r.should eq [@npl5, @npl4]
583       end
584       it 'page=2なら中間2件を返す' do
585         r = PanelPicture.mylist(@author, 2, 2)
586         r.should eq [@npl3, @npl2]
587       end
588       it 'page=3なら先頭1件を返す' do
589         r = PanelPicture.mylist(@author, 3, 2)
590         r.should eq [@pp]
591       end
592     end
593     context 'DBに5件あって1ページの件数を0件に変えたとして' do
594       before do
595         @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
596           :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
597         @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
598           :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
599         @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
600           :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
601         @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
602           :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
603         Author.stub(:default_panel_picture_page_size).and_return(2)
604       end
605       it '通常は全件(5件)を返す' do
606         r = PanelPicture.mylist @author, 5, 0
607         r.should have(5).items 
608       end
609     end
610   end
611   
612   describe '単体取得に於いて' do
613     before do
614       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
615         :width => @p.width, :height => @p.height
616     end
617     context 'つつがなく終わるとき' do
618       it '単体取得オプションを利用している' do
619         PanelPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
620         PanelPicture.should_receive(:show_opt).with(any_args).exactly(1)
621         r = PanelPicture.show @pp.id, @author
622       end
623       it '閲覧許可を問い合わせている' do
624         PanelPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
625         PanelPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
626         r = PanelPicture.show @pp.id, @author
627       end
628     end
629     it '指定のコマ絵を返す' do
630       PanelPicture.any_instance.stub(:visible?).and_return(true)
631       pl = PanelPicture.show @pp.id, @author
632       pl.should eq @pp
633     end
634     context '閲覧許可が出なかったとき' do
635       it '403Forbidden例外を返す' do
636         PanelPicture.any_instance.stub(:visible?).and_return(false)
637         lambda{
638           PanelPicture.show @pp.id, @author
639         }.should raise_error(ActiveRecord::Forbidden)
640       end
641     end
642     context '存在しないコマ絵を開こうとしたとき' do
643       it '404RecordNotFound例外を返す' do
644         lambda{
645           PanelPicture.show 110, @author
646         }.should raise_error(ActiveRecord::RecordNotFound)
647       end
648     end
649   end
650   describe '単体取得オプションに於いて' do
651     it 'includeキーを含んでいる' do
652       r = PanelPicture.show_opt
653       r.has_key?(:include).should be_true
654     end
655     it '2つの項目を含んでいる' do
656       r = PanelPicture.show_opt[:include]
657       r.should have(2).items
658     end
659     it 'コマを含んでいる' do
660       r = PanelPicture.show_opt[:include]
661       r.has_key?(:panel).should be_true
662     end
663       it 'コマは作家を含んでいる' do
664         r = PanelPicture.show_opt[:include]
665         r[:panel].has_key?(:author).should be_true
666       end
667     it '実素材を含んでいる' do
668       r = PanelPicture.show_opt[:include]
669       r.has_key?(:picture).should be_true
670     end
671       it '実素材は絵師を含んでいる' do
672         r = PanelPicture.show_opt[:include]
673         r[:picture].has_key?(:artist).should be_true
674       end
675       it '実素材はライセンスを含んでいる' do
676         r = PanelPicture.show_opt[:include]
677         r[:picture].has_key?(:license).should be_true
678       end
679   end
680   describe 'json単体出力オプションに於いて' do
681     before do
682       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
683       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
684       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
685       @sbt = FactoryGirl.create :speech_balloon_template
686       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
687       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
688         :width => @p.width, :height => @p.height
689     end
690     it 'コマを含んでいる' do
691       r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
692       j = JSON.parse r
693       i = j
694       i.has_key?('panel').should be_true
695     end
696       it 'コマは作家を含んでいる' do
697         r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
698         j = JSON.parse r
699         i = j
700         s = i['panel']
701         s.has_key?('author').should be_true
702       end
703     it '実素材を含んでいる' do
704       r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
705       j = JSON.parse r
706       i = j
707       i.has_key?('picture').should be_true
708     end
709       it '実素材は絵師を含んでいる' do
710         r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
711         j = JSON.parse r
712         i = j
713         s = i['picture']
714         s.has_key?('artist').should be_true
715       end
716       it '実素材はライセンスを含んでいる' do
717         r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
718         j = JSON.parse r
719         i = j
720         s = i['picture']
721         s.has_key?('license').should be_true
722       end
723   end
724 end