OSDN Git Service

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