OSDN Git Service

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