OSDN Git Service

Merge branch 'v05' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v05client
[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   
293   describe '閲覧許可に於いて' do
294     before do
295       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
296         :width => @p.width, :height => @p.height
297     end
298     context 'オープンモードのとき' do
299       before do
300         MagicNumber['run_mode'] = 0
301       end
302       it '自身にゲスト用ロールチェックを問い合わせしている' do
303         PanelPicture.any_instance.stub(:guest_role_check).and_return(true)
304         PanelPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
305         r = @pp.visible?([@author])
306       end
307       it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
308         PanelPicture.any_instance.stub(:guest_role_check).and_return(false)
309         r = @pp.visible?([@author])
310         r.should be_false
311       end
312     end
313     context 'クローズドモードのとき' do
314       before do
315         MagicNumber['run_mode'] = 1
316       end
317       it '自身に読者用ロールチェックを問い合わせしている' do
318         PanelPicture.any_instance.stub(:reader_role_check).and_return(true)
319         PanelPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
320         r = @pp.visible?([@author])
321       end
322       it '読者用ロールチェックが失敗したとき、falseを返す' do
323         PanelPicture.any_instance.stub(:reader_role_check).and_return(false)
324         r = @pp.visible?([@author])
325         r.should be_false
326       end
327     end
328     context '事前チェックする' do
329       before do
330         MagicNumber['run_mode'] = 1
331         PanelPicture.any_instance.stub(:reader_role_check).and_return(true)
332       end
333       it '自身のコマに所持判定を問い合わせしている' do
334         Panel.any_instance.stub(:own?).and_return(true)
335         Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
336         r = @pp.visible?([@author])
337       end
338       it '自身のコマに閲覧許可を問い合わせしている' do
339         Panel.any_instance.stub(:own?).and_return(false)
340         Panel.any_instance.stub(:visible?).and_return(true)
341         Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
342         r = @pp.visible?([@author])
343       end
344     end
345     context 'つつがなく終わるとき' do
346       before do
347         MagicNumber['run_mode'] = 1
348         Panel.any_instance.stub(:reader_role_check).and_return(true)
349       end
350       it '自分のコマのコマ絵なら許可する' do
351         Panel.any_instance.stub(:own?).and_return(true)
352         Panel.any_instance.stub(:visible?).and_return(false)
353         r = @pp.visible?([@author])
354         r.should be_true
355       end
356       it '他人の非公開コマのコマ絵なら許可しない' do
357         Panel.any_instance.stub(:own?).and_return(false)
358         Panel.any_instance.stub(:visible?).and_return(false)
359         r = @pp.visible?([@author])
360         r.should be_false
361       end
362       it '他人のコマのコマ絵でも公開なら許可する' do
363         Panel.any_instance.stub(:own?).and_return(false)
364         Panel.any_instance.stub(:visible?).and_return(true)
365         r = @pp.visible?([@author])
366         r.should be_true
367       end
368     end
369   end
370   
371   
372   describe '一覧取得に於いて' do
373     before do
374       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
375         :width => @p.width, :height => @p.height
376     end
377     context 'page補正について' do
378       it '文字列から数値に変換される' do
379         PanelPicture.page('8').should eq 8
380       end
381       it 'nilの場合は1になる' do
382         PanelPicture.page().should eq 1
383       end
384       it '0以下の場合は1になる' do
385         PanelPicture.page('0').should eq 1
386       end
387     end
388     context 'page_size補正について' do
389       it '文字列から数値に変換される' do
390         PanelPicture.page_size('7').should eq 7
391       end
392       it 'nilの場合はPanelPicture.default_page_sizeになる' do
393         PanelPicture.page_size().should eq PanelPicture.default_page_size
394       end
395       it '0以下の場合はPanelPicture.default_page_sizeになる' do
396         PanelPicture.page_size('0').should eq PanelPicture.default_page_size
397       end
398       it 'PanelPicture.max_page_sizeを超えた場合はPanelPicture.max_page_sizeになる' do
399         PanelPicture.page_size('1000').should eq PanelPicture.max_page_size
400       end
401     end
402     context 'つつがなく終わるとき' do
403       it '一覧取得オプションを利用している' do
404         PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
405         PanelPicture.should_receive(:list_opt).with(any_args).exactly(1)
406         r = PanelPicture.list
407       end
408     end
409     it 'リストを返す' do
410       r = PanelPicture.list
411       r.should eq [@pp]
412     end
413     it '時系列で並んでいる' do
414       #公開されたコマのコマ絵は(他人のコマ絵であっても)含んでいる
415       hc = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
416       npl = FactoryGirl.create :panel_picture, :panel_id => hc.id, :t => 0, :picture_id => @p.id,
417         :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
418       r = PanelPicture.list
419       r.should eq [npl, @pp]
420     end
421     it '非公開のコマのコマ絵は自分のコマ絵であっても含まない' do
422       hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
423       npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
424         :width => @p.width, :height => @p.height
425       pl = PanelPicture.list
426       pl.should eq [@pp]
427     end
428     context 'DBに5件あって1ページの件数を2件に変えたとして' do
429       before do
430         @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
431           :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
432         @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
433           :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
434         @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
435           :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
436         @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
437           :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
438         PanelPicture.stub(:default_page_size).and_return(2)
439       end
440       it '通常は2件を返す' do
441         pl = PanelPicture.list
442         pl.should have(2).items 
443       end
444       it 'page=1なら末尾2件を返す' do
445         #時系列で並んでいる
446         pl = PanelPicture.list(1)
447         pl.should eq [@npl5, @npl4]
448       end
449       it 'page=2なら中間2件を返す' do
450         pl = PanelPicture.list(2)
451         pl.should eq [@npl3, @npl2]
452       end
453       it 'page=3なら先頭1件を返す' do
454         pl = PanelPicture.list(3)
455         pl.should eq [@pp]
456       end
457     end
458     context 'DBに5件あって1ページの件数を0件に変えたとして' do
459       before do
460         @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
461           :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
462         @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
463           :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
464         @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
465           :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
466         @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
467           :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
468         PanelPicture.stub(:default_page_size).and_return(2)
469       end
470       it '通常は全件(5件)を返す' do
471         r = PanelPicture.list 5, 0
472         r.should have(5).items 
473       end
474     end
475   end
476   describe '一覧取得オプションに於いて' do
477     it 'includeキーを含んでいる' do
478       r = PanelPicture.list_opt
479       r.has_key?(:include).should be_true
480     end
481     it '2つの項目を含んでいる' do
482       r = PanelPicture.list_opt[:include]
483       r.should have(2).items
484     end
485     it 'コマを含んでいる' do
486       r = PanelPicture.list_opt[:include]
487       r.has_key?(:panel).should be_true
488     end
489       it 'コマは作家を含んでいる' do
490         r = PanelPicture.list_opt[:include]
491         r[:panel].has_key?(:author).should be_true
492       end
493     it '実素材を含んでいる' do
494       r = PanelPicture.list_opt[:include]
495       r.has_key?(:picture).should be_true
496     end
497       it '実素材は絵師を含んでいる' do
498         r = PanelPicture.list_opt[:include]
499         r[:picture].has_key?(:artist).should be_true
500       end
501       it '実素材はライセンスを含んでいる' do
502         r = PanelPicture.list_opt[:include]
503         r[:picture].has_key?(:license).should be_true
504       end
505   end
506   describe 'json一覧出力オプションに於いて' do
507     before do
508       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
509       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
510       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
511       @sbt = FactoryGirl.create :speech_balloon_template
512       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
513       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
514         :width => @p.width, :height => @p.height
515     end
516     it 'コマを含んでいる' do
517       r = PanelPicture.list.to_json PanelPicture.list_json_opt
518       j = JSON.parse r
519       i = j.first
520       i.has_key?('panel').should be_true
521     end
522       it 'コマは作家を含んでいる' do
523         r = PanelPicture.list.to_json PanelPicture.list_json_opt
524         j = JSON.parse r
525         i = j.first
526         s = i['panel']
527         s.has_key?('author').should be_true
528       end
529     it '実素材を含んでいる' do
530       r = PanelPicture.list.to_json PanelPicture.list_json_opt
531       j = JSON.parse r
532       i = j.first
533       i.has_key?('picture').should be_true
534     end
535       it '実素材は絵師を含んでいる' do
536         r = PanelPicture.list.to_json PanelPicture.list_json_opt
537         j = JSON.parse r
538         i = j.first
539         s = i['picture']
540         s.has_key?('artist').should be_true
541       end
542       it '実素材はライセンスを含んでいる' do
543         r = PanelPicture.list.to_json PanelPicture.list_json_opt
544         j = JSON.parse r
545         i = j.first
546         s = i['picture']
547         s.has_key?('license').should be_true
548       end
549   end
550   
551   describe '自分のコマ絵一覧取得に於いて' do
552     before do
553       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
554         :width => @p.width, :height => @p.height
555     end
556     context 'つつがなく終わるとき' do
557       it '一覧取得オプションを利用している' do
558         PanelPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
559         PanelPicture.should_receive(:list_opt).with(any_args).exactly(1)
560         r = PanelPicture.mylist @author
561       end
562     end
563     it 'リストを返す' do
564       pl = PanelPicture.mylist @author
565       pl.should eq [@pp]
566     end
567     it '時系列で並んでいる' do
568       npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
569         :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
570       pl = PanelPicture.mylist @author
571       pl.should eq [npl, @pp]
572     end
573     it '他人のコマのコマ絵は公開コマでも含まない' do
574       hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
575       npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
576         :width => @p.width, :height => @p.height
577       pl = PanelPicture.mylist @author
578       pl.should eq [@pp]
579     end
580     it '自分のコマのコマ絵は非公開コマでも含んでいる' do
581       pl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
582       ni = FactoryGirl.create :panel_picture, :panel_id => pl.id, :picture_id => @p.id,
583         :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
584       r = PanelPicture.mylist @author
585       r.should eq [ni, @pp]
586     end
587     context 'DBに5件あって1ページの件数を2件に変えたとして' do
588       before do
589         @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
590           :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
591         @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
592           :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
593         @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
594           :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
595         @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
596           :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
597       end
598       it '通常は2件を返す' do
599         r = PanelPicture.mylist @author, 1, 2
600         r.should have(2).items 
601       end
602       it 'page=1なら末尾2件を返す' do
603         #時系列で並んでいる
604         r = PanelPicture.mylist(@author, 1, 2)
605         r.should eq [@npl5, @npl4]
606       end
607       it 'page=2なら中間2件を返す' do
608         r = PanelPicture.mylist(@author, 2, 2)
609         r.should eq [@npl3, @npl2]
610       end
611       it 'page=3なら先頭1件を返す' do
612         r = PanelPicture.mylist(@author, 3, 2)
613         r.should eq [@pp]
614       end
615     end
616     context 'DBに5件あって1ページの件数を0件に変えたとして' do
617       before do
618         @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
619           :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
620         @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
621           :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
622         @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
623           :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
624         @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
625           :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
626         Author.stub(:default_panel_picture_page_size).and_return(2)
627       end
628       it '通常は全件(5件)を返す' do
629         r = PanelPicture.mylist @author, 5, 0
630         r.should have(5).items 
631       end
632     end
633   end
634   
635   describe '単体取得に於いて' do
636     before do
637       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
638         :width => @p.width, :height => @p.height
639     end
640     context 'つつがなく終わるとき' do
641       it '単体取得オプションを利用している' do
642         PanelPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
643         PanelPicture.should_receive(:show_opt).with(any_args).exactly(1)
644         r = PanelPicture.show @pp.id, @author
645       end
646       it '閲覧許可を問い合わせている' do
647         PanelPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
648         PanelPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
649         r = PanelPicture.show @pp.id, @author
650       end
651     end
652     it '指定のコマ絵を返す' do
653       PanelPicture.any_instance.stub(:visible?).and_return(true)
654       pl = PanelPicture.show @pp.id, @author
655       pl.should eq @pp
656     end
657     context '閲覧許可が出なかったとき' do
658       it '403Forbidden例外を返す' do
659         PanelPicture.any_instance.stub(:visible?).and_return(false)
660         lambda{
661           PanelPicture.show @pp.id, @author
662         }.should raise_error(ActiveRecord::Forbidden)
663       end
664     end
665     context '存在しないコマ絵を開こうとしたとき' do
666       it '404RecordNotFound例外を返す' do
667         lambda{
668           PanelPicture.show 110, @author
669         }.should raise_error(ActiveRecord::RecordNotFound)
670       end
671     end
672   end
673   describe '単体取得オプションに於いて' do
674     it 'includeキーを含んでいる' do
675       r = PanelPicture.show_opt
676       r.has_key?(:include).should be_true
677     end
678     it '2つの項目を含んでいる' do
679       r = PanelPicture.show_opt[:include]
680       r.should have(2).items
681     end
682     it 'コマを含んでいる' do
683       r = PanelPicture.show_opt[:include]
684       r.has_key?(:panel).should be_true
685     end
686       it 'コマは作家を含んでいる' do
687         r = PanelPicture.show_opt[:include]
688         r[:panel].has_key?(:author).should be_true
689       end
690     it '実素材を含んでいる' do
691       r = PanelPicture.show_opt[:include]
692       r.has_key?(:picture).should be_true
693     end
694       it '実素材は絵師を含んでいる' do
695         r = PanelPicture.show_opt[:include]
696         r[:picture].has_key?(:artist).should be_true
697       end
698       it '実素材はライセンスを含んでいる' do
699         r = PanelPicture.show_opt[:include]
700         r[:picture].has_key?(:license).should be_true
701       end
702   end
703   describe 'json単体出力オプションに於いて' do
704     before do
705       @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
706       @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
707       @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
708       @sbt = FactoryGirl.create :speech_balloon_template
709       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
710       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
711         :width => @p.width, :height => @p.height
712     end
713     it 'コマを含んでいる' do
714       r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
715       j = JSON.parse r
716       i = j
717       i.has_key?('panel').should be_true
718     end
719       it 'コマは作家を含んでいる' do
720         r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
721         j = JSON.parse r
722         i = j
723         s = i['panel']
724         s.has_key?('author').should be_true
725       end
726     it '実素材を含んでいる' do
727       r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
728       j = JSON.parse r
729       i = j
730       i.has_key?('picture').should be_true
731     end
732       it '実素材は絵師を含んでいる' do
733         r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
734         j = JSON.parse r
735         i = j
736         s = i['picture']
737         s.has_key?('artist').should be_true
738       end
739       it '実素材はライセンスを含んでいる' do
740         r = PanelPicture.show(@pp.id, @author).to_json PanelPicture.show_json_opt
741         j = JSON.parse r
742         i = j
743         s = i['picture']
744         s.has_key?('license').should be_true
745       end
746   end
747 end