OSDN Git Service

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