OSDN Git Service

Merge branch 'v04' of git.sourceforge.jp:/gitroot/pettanr/pettanr into v04license
[pettanr/pettanr.git] / spec / models / panel_spec.rb
1 # -*- encoding: utf-8 -*-\r
2 require 'spec_helper'\r
3 #コマ\r
4 describe Panel do\r
5   before do\r
6     Factory :admin\r
7     @sp = Factory :system_picture
8     @lg = Factory :license_group
9     @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10     @user = Factory( :user_yas)\r
11     @author = @user.author\r
12     @artist = Factory :artist_yas, :author_id => @author.id\r
13     @other_user = Factory( :user_yas)\r
14     @other_author = @other_user.author\r
15     @other_artist = Factory :artist_yas, :author_id => @other_author.id\r
16     @op = Factory :original_picture, :artist_id => @artist.id, :license_id => @license.id\r
17     @rp = Factory :resource_picture, :original_picture_id => @op.id, :license_id => @license.id\r
18     @sbt = Factory :speech_balloon_template\r
19   end\r
20   \r
21   describe '検証に於いて' do\r
22     before do\r
23       @comic = Factory :comic, :author_id => @author.id\r
24     end\r
25     \r
26     it 'オーソドックスなデータなら通る' do\r
27       @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
28       @panel.should be_valid\r
29     end\r
30     \r
31     context 'comic_idを検証するとき' do\r
32       before do\r
33         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => nil\r
34       end\r
35       it 'テストデータの確認' do\r
36         @panel.comic_id = @comic.id\r
37         @panel.should be_valid\r
38       end\r
39     end\r
40     context 'widthを検証するとき' do\r
41       before do\r
42         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
43       end\r
44       it 'テストデータの確認' do\r
45         @panel.width = 1\r
46         @panel.should be_valid\r
47       end\r
48       it 'nullなら失敗する' do\r
49         @panel.width = nil\r
50         @panel.should_not be_valid\r
51       end\r
52       it '数値でなければ失敗する' do\r
53         @panel.width = 'a'\r
54         @panel.should_not be_valid\r
55       end\r
56       it '0なら失敗する' do\r
57         @panel.width = '0'\r
58         @panel.should_not be_valid\r
59       end\r
60       it '負でも失敗する' do\r
61         @panel.width = -1\r
62         @panel.should_not be_valid\r
63       end\r
64     end\r
65     context 'heightを検証するとき' do\r
66       before do\r
67         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
68       end\r
69       it 'テストデータの確認' do\r
70         @panel.height = '1'\r
71         @panel.should be_valid\r
72       end\r
73       it 'nullなら失敗する' do\r
74         @panel.height = nil\r
75         @panel.should_not be_valid\r
76       end\r
77       it '数値でなければ失敗する' do\r
78         @panel.height = 'a'\r
79         @panel.should_not be_valid\r
80       end\r
81       it '0なら失敗する' do\r
82         @panel.height = '0'\r
83         @panel.should_not be_valid\r
84       end\r
85       it '負でも失敗する' do\r
86         @panel.height = -1\r
87         @panel.should_not be_valid\r
88       end\r
89     end\r
90     context 'borderを検証するとき' do\r
91       before do\r
92         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
93       end\r
94       it 'テストデータの確認' do\r
95         @panel.border = '1'\r
96         @panel.should be_valid\r
97       end\r
98       it 'nullなら失敗する' do\r
99         @panel.border = nil\r
100         @panel.should_not be_valid\r
101       end\r
102       it '数値でなければ失敗する' do\r
103         @panel.border = 'a'\r
104         @panel.should_not be_valid\r
105       end\r
106       it '負なら失敗する' do\r
107         @panel.border = '-1'\r
108         @panel.should_not be_valid\r
109       end\r
110       it '0なら通る' do\r
111         @panel.border = 0\r
112         @panel.should be_valid\r
113       end\r
114     end\r
115     context 'xを検証するとき' do\r
116       before do\r
117         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
118       end\r
119       it 'テストデータの確認' do\r
120         @panel.x = '1'\r
121         @panel.should be_valid\r
122       end\r
123       it '数値でなければ失敗する' do\r
124         @panel.x = 'a'\r
125         @panel.should_not be_valid\r
126       end\r
127       it '0なら通る' do\r
128         @panel.x = '0'\r
129         @panel.should be_valid\r
130       end\r
131       it '負でも通る' do\r
132         @panel.x = -1\r
133         @panel.should be_valid\r
134       end\r
135     end\r
136     context 'yを検証するとき' do\r
137       before do\r
138         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
139       end\r
140       it 'テストデータの確認' do\r
141         @panel.y = '1'\r
142         @panel.should be_valid\r
143       end\r
144       it '数値でなければ失敗する' do\r
145         @panel.y = 'a'\r
146         @panel.should_not be_valid\r
147       end\r
148       it '0なら通る' do\r
149         @panel.y = '0'\r
150         @panel.should be_valid\r
151       end\r
152       it '負でも通る' do\r
153         @panel.y = -1\r
154         @panel.should be_valid\r
155       end\r
156     end\r
157     context 'zを検証するとき' do\r
158       before do\r
159         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
160       end\r
161       it 'テストデータの確認' do\r
162         @panel.z = '1'\r
163         @panel.should be_valid\r
164       end\r
165       it '数値でなければ失敗する' do\r
166         @panel.z = 'a'\r
167         @panel.should_not be_valid\r
168       end\r
169       it '0なら失敗する' do\r
170         @panel.z = '0'\r
171         @panel.should_not be_valid\r
172       end\r
173       it '負なら失敗する' do\r
174         @panel.z = -1\r
175         @panel.should_not be_valid\r
176       end\r
177     end\r
178     context 'tを検証するとき' do\r
179       before do\r
180         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
181       end\r
182       it 'テストデータの確認' do\r
183         @panel.t = '1'\r
184         @panel.should be_valid\r
185       end\r
186       it '数値でなければ失敗する' do\r
187         @panel.t = 'a'\r
188         @panel.should_not be_valid\r
189       end\r
190       it '0なら通る' do\r
191         @panel.t = '0'\r
192         @panel.should be_valid\r
193       end\r
194       it '負でも失敗する' do\r
195         @panel.t = -1\r
196         @panel.should_not be_valid\r
197       end\r
198     end\r
199     context 'author_idを検証するとき' do\r
200       before do\r
201         @panel = Factory.build :panel, :author_id => @author.id, :comic_id => @comic.id\r
202       end\r
203       it 'テストデータの確認' do\r
204         @panel.author_id = @author.id\r
205         @panel.should be_valid\r
206       end\r
207       it 'nullなら失敗する' do\r
208         @panel.author_id = nil\r
209         @panel.should_not be_valid\r
210       end\r
211       it '数値でなければ失敗する' do\r
212         @panel.author_id = 'a'\r
213         @panel.should_not be_valid\r
214       end\r
215       it '存在する絵師でなければ失敗する' do\r
216         @panel.author_id = 0\r
217         @panel.should_not be_valid\r
218       end\r
219     end\r
220     context '全体を検証するとき' do\r
221       before do\r
222         @panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id\r
223       end\r
224     end\r
225   end\r
226   \r
227   describe 'データ補充に於いて' do\r
228     before do\r
229       @comic = Factory :comic, :author_id => @author.id\r
230       @panel = Factory.build :panel, :comic_id => @comic.id\r
231     end\r
232     context 'widthを補充' do\r
233       it '空の時はコミックから補充する' do\r
234         @panel.width = nil\r
235         @panel.supply_default @author\r
236         @panel.width.should eq @comic.width\r
237       end\r
238       it '空の時でもコミックが不在なら補充しない' do\r
239         @panel.width = nil\r
240         @panel.comic_id = nil\r
241         @panel.supply_default @author\r
242         @panel.width.should be_nil\r
243       end\r
244       it '空でない時は変化しない' do\r
245         @panel.width = 45\r
246         lambda {\r
247           @panel.supply_default @author\r
248         }.should_not change @panel, :width\r
249       end\r
250     end\r
251     context 'heightを補充' do\r
252       it '空の時はコミックから補充する' do\r
253         @panel.height = nil\r
254         @panel.supply_default @author\r
255         @panel.height.should eq @comic.height\r
256       end\r
257       it '空の時でもコミックが不在なら補充しない' do\r
258         @panel.height = nil\r
259         @panel.comic_id = nil\r
260         @panel.supply_default @author\r
261         @panel.height.should be_nil\r
262       end\r
263       it '空でない時は変化しない' do\r
264         @panel.height = 87\r
265         lambda {\r
266           @panel.supply_default @author\r
267         }.should_not change @panel, :height\r
268       end\r
269     end\r
270     context 'borderを補充' do\r
271       it '空の時は0を補充する' do\r
272         @panel.border = nil\r
273         @panel.supply_default @author\r
274         @panel.border.should eq 0\r
275       end\r
276       it '空でない時は変化しない' do\r
277         @panel.border = 1\r
278         lambda {\r
279           @panel.supply_default @author\r
280         }.should_not change @panel, :border\r
281       end\r
282     end\r
283     context 'tを補充' do\r
284       it '空の時はコミック内のtの最大値+1を補充する' do\r
285         pl = Factory :panel, :author_id => @author.id, :comic_id => @comic.id, :t => 0\r
286         @panel.t = nil\r
287         @panel.supply_default @author\r
288         @panel.t.should eq 1\r
289       end\r
290       it '空でコミック初のコマなら0を補充する' do\r
291         @panel.t = nil\r
292         @panel.supply_default @author\r
293         @panel.t.should eq 0\r
294       end\r
295       it '空の時でも更新ケースなら補充しない' do\r
296         pl = Factory :panel, :author_id => @author.id, :comic_id => @comic.id, :t => 1\r
297         pl.t = nil\r
298         lambda {\r
299           pl.supply_default @author\r
300         }.should_not change pl, :t\r
301       end\r
302       it '空でない時は変化しない' do\r
303         @panel.t = 1\r
304         lambda {\r
305           @panel.supply_default @author\r
306         }.should_not change @panel, :t\r
307       end\r
308     end\r
309     context 'author_idを補充' do\r
310       it 'ログイン中の作家idを補充する' do\r
311         @panel.author_id = nil\r
312         @panel.supply_default @author\r
313         @panel.author_id.should eq @author.id\r
314       end\r
315     end\r
316     \r
317   end\r
318   \r
319   describe '作者判定に於いて' do\r
320     before do\r
321       @comic = Factory :comic, :author_id => @author.id\r
322     end\r
323     it '自作のコマならyes' do\r
324       panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id\r
325       panel.own?(@author).should == true\r
326     end\r
327     it '他人のコマならno' do\r
328       panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id\r
329       panel.own?(@author).should == false\r
330     end\r
331     it '作家が不明ならno' do\r
332       panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id\r
333       panel.own?(nil).should == false\r
334     end\r
335   end\r
336   describe '閲覧許可に於いて' do\r
337     before do\r
338       @comic = Factory :comic, :author_id => @author.id\r
339     end\r
340     it '自作の公開コミックのコマを見るときは許可する' do\r
341       Comic.any_instance.stub(:visible?).and_return(true)\r
342       panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id\r
343       panel.visible?(@author).should == true\r
344     end\r
345     it '自作のコマは非公開コミックでも許可する' do\r
346       Comic.any_instance.stub(:visible?).and_return(false)\r
347       panel = Factory :panel, :author_id => @author.id, :comic_id => @comic.id\r
348       panel.visible?(@author).should == true\r
349     end\r
350     it '他人のコマでも公開コミックなら許可する' do\r
351       Comic.any_instance.stub(:visible?).and_return(true)\r
352       panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id\r
353       panel.visible?(@author).should == true\r
354     end\r
355     it '他人のコマで非公開コミックなら許可しない' do\r
356       Comic.any_instance.stub(:visible?).and_return(false)\r
357       panel = Factory :panel, :author_id => @other_author.id, :comic_id => @comic.id\r
358       panel.visible?(@author).should == false\r
359     end\r
360   end\r
361   describe '単体取得に於いて' do\r
362     before do\r
363       @comic = Factory :comic, :author_id => @author.id\r
364       @panel = Factory :panel, :comic_id => @comic.id, :author_id => @author.id\r
365     end\r
366     it '指定のコマを返す' do\r
367       Comic.any_instance.stub(:visible?).and_return(true)\r
368       pl = Panel.show @panel.id, @author\r
369       pl.should eq @panel\r
370     end\r
371     context '他人の非公開コミックのコマを開こうとしたとき' do\r
372       it '403Forbidden例外を返す' do\r
373         Panel.any_instance.stub(:visible?).and_return(false)\r
374         lambda{\r
375           Panel.show @panel.id, @author\r
376         }.should raise_error(ActiveRecord::Forbidden)\r
377       end\r
378     end\r
379     context '存在しないコマを開こうとしたとき' do\r
380       it '404RecordNotFound例外を返す' do\r
381         lambda{\r
382           Panel.show 110, @author\r
383         }.should raise_error(ActiveRecord::RecordNotFound)\r
384       end\r
385     end\r
386   end\r
387   describe '関連テーブルプションに於いて' do\r
388     context 'オプションがないとき' do\r
389       it '4つの項目を含んでいる' do\r
390         r = Panel.show_include_opt\r
391         r.should have(4).items\r
392       end\r
393       it 'コミックを含んでいる' do\r
394         r = Panel.show_include_opt\r
395         r.has_key?(:comic).should be_true\r
396       end\r
397       it 'コマ絵を含んでいる' do\r
398         r = Panel.show_include_opt\r
399         r.has_key?(:panel_pictures).should be_true\r
400       end\r
401         it 'コマ絵は素材を含んでいる' do\r
402           r = Panel.show_include_opt\r
403           r[:panel_pictures].has_key?(:resource_picture).should be_true\r
404         end\r
405           it '素材は絵師を含んでいる' do\r
406             r = Panel.show_include_opt\r
407             r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true\r
408           end\r
409           it '素材はライセンスを含んでいる' do\r
410             r = Panel.show_include_opt\r
411             r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
412           end\r
413       it 'フキダシを含んでいる' do\r
414         r = Panel.show_include_opt\r
415         r.has_key?(:speech_balloons).should be_true\r
416       end\r
417         it 'フキダシはフキダシ枠を含んでいる' do\r
418           r = Panel.show_include_opt\r
419           r[:speech_balloons].has_key?(:balloons).should be_true\r
420         end\r
421         it 'フキダシはセリフを含んでいる' do\r
422           r = Panel.show_include_opt\r
423           r[:speech_balloons].has_key?(:speeches).should be_true\r
424         end\r
425       it '作家を含んでいる' do\r
426         r = Panel.show_include_opt\r
427         r.has_key?(:author).should be_true\r
428       end\r
429     end\r
430     context 'オプションで原画を含ませたとき' do\r
431       it '5つの項目を含んでいる' do\r
432         r = Panel.show_include_opt(:include => {:test => {}})\r
433         r.should have(5).items\r
434       end\r
435       it 'testを含んでいる' do\r
436         r = Panel.show_include_opt(:include => {:test => {}})\r
437         r.has_key?(:test).should be_true\r
438       end\r
439     end\r
440   end\r
441   describe 'json単体出力オプションに於いて' do\r
442     it 'includeキーを含んでいる' do\r
443       r = Panel.show_json_include_opt\r
444       r.has_key?(:include).should be_true\r
445     end\r
446     it '4つの項目を含んでいる' do\r
447       r = Panel.show_json_include_opt[:include]\r
448       r.should have(4).items\r
449     end\r
450     it 'コミックを含んでいる' do\r
451       r = Panel.show_json_include_opt[:include]\r
452       r.has_key?(:comic).should be_true\r
453     end\r
454     it 'コマ絵を含んでいる' do\r
455       r = Panel.show_json_include_opt[:include]\r
456       r.has_key?(:panel_pictures).should be_true\r
457     end\r
458       it 'コマ絵は素材を含んでいる' do\r
459         r = Panel.show_json_include_opt[:include]\r
460         r[:panel_pictures].has_key?(:resource_picture).should be_true\r
461       end\r
462         it '素材は絵師を含んでいる' do\r
463           r = Panel.show_json_include_opt[:include]\r
464           r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true\r
465         end\r
466         it '素材はライセンスを含んでいる' do\r
467           r = Panel.show_json_include_opt[:include]\r
468           r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
469         end\r
470     it 'フキダシを含んでいる' do\r
471       r = Panel.show_include_opt\r
472       r.has_key?(:speech_balloons).should be_true\r
473     end\r
474       it 'フキダシはフキダシ枠を含んでいる' do\r
475         r = Panel.show_include_opt\r
476         r[:speech_balloons].has_key?(:balloons).should be_true\r
477       end\r
478       it 'フキダシはセリフを含んでいる' do\r
479         r = Panel.show_include_opt\r
480         r[:speech_balloons].has_key?(:speeches).should be_true\r
481       end\r
482     it '作家を含んでいる' do\r
483       r = Panel.show_json_include_opt[:include]\r
484       r.has_key?(:author).should be_true\r
485     end\r
486   end\r
487   describe '一覧取得に於いて' do\r
488     before do\r
489       @comic = Factory :comic, :author_id => @author.id\r
490       @panel = Factory :panel, :comic_id => @comic.id, :author_id => @author.id\r
491     end\r
492     context 'page補正について' do\r
493       it '文字列から数値に変換される' do\r
494         Panel.page('8').should eq 8\r
495       end\r
496       it 'nilの場合は1になる' do\r
497         Panel.page().should eq 1\r
498       end\r
499       it '0以下の場合は1になる' do\r
500         Panel.page('0').should eq 1\r
501       end\r
502     end\r
503     context 'page_size補正について' do\r
504       it '文字列から数値に変換される' do\r
505         Panel.page_size('7').should eq 7\r
506       end\r
507       it 'nilの場合はPanel.default_page_sizeになる' do\r
508         Panel.page_size().should eq Panel.default_page_size\r
509       end\r
510       it '0以下の場合はPanel.default_page_sizeになる' do\r
511         Panel.page_size('0').should eq Panel.default_page_size\r
512       end\r
513       it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do\r
514         Panel.page_size('1000').should eq Panel.max_page_size\r
515       end\r
516     end\r
517     it 'リストを返す' do\r
518       pl = Panel.list\r
519       pl.should eq [@panel]\r
520     end\r
521     it '時系列で並んでいる' do\r
522       npl = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 1, :updated_at => Time.now + 100\r
523       pl = Panel.list\r
524       pl.should eq [npl, @panel]\r
525     end\r
526     context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
527       before do\r
528         @npl2 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 1, :updated_at => Time.now + 100\r
529         @npl3 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 2, :updated_at => Time.now + 200\r
530         @npl4 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 3, :updated_at => Time.now + 300\r
531         @npl5 = Factory :panel, :comic_id => @comic.id, :author_id => @author.id, :t => 4, :updated_at => Time.now + 400\r
532         Panel.stub(:default_page_size).and_return(2)\r
533       end\r
534       it '通常は2件を返す' do\r
535         pl = Panel.list\r
536         pl.should have(2).items \r
537       end\r
538       it 'page=1なら末尾2件を返す' do\r
539         #時系列で並んでいる\r
540         pl = Panel.list( {}, 1)\r
541         pl.should eq [@npl5, @npl4]\r
542       end\r
543       it 'page=2なら中間2件を返す' do\r
544         pl = Panel.list({}, 2)\r
545         pl.should eq [@npl3, @npl2]\r
546       end\r
547       it 'page=3なら先頭1件を返す' do\r
548         pl = Panel.list({}, 3)\r
549         pl.should eq [@panel]\r
550       end\r
551     end\r
552   end\r
553   describe 'list関連テーブルプションに於いて' do\r
554     it 'includeキーを含んでいる' do\r
555       r = Panel.list_opt\r
556       r.has_key?(:include).should be_true\r
557     end\r
558     it '4つの項目を含んでいる' do\r
559       r = Panel.list_opt[:include]\r
560       r.should have(4).items\r
561     end\r
562     it 'コミックを含んでいる' do\r
563       r = Panel.list_opt[:include]\r
564       r.has_key?(:comic).should be_true\r
565     end\r
566     it 'コマ絵を含んでいる' do\r
567       r = Panel.list_opt[:include]\r
568       r.has_key?(:panel_pictures).should be_true\r
569     end\r
570       it 'コマ絵は素材を含んでいる' do\r
571         r = Panel.list_opt[:include]\r
572         r[:panel_pictures].has_key?(:resource_picture).should be_true\r
573       end\r
574         it '素材は絵師を含んでいる' do\r
575           r = Panel.list_opt[:include]\r
576           r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true\r
577         end\r
578         it '素材はライセンスを含んでいる' do\r
579           r = Panel.list_opt[:include]\r
580           r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
581         end\r
582     it 'フキダシを含んでいる' do\r
583       r = Panel.show_include_opt\r
584       r.has_key?(:speech_balloons).should be_true\r
585     end\r
586       it 'フキダシはフキダシ枠を含んでいる' do\r
587         r = Panel.show_include_opt\r
588         r[:speech_balloons].has_key?(:balloons).should be_true\r
589       end\r
590       it 'フキダシはセリフを含んでいる' do\r
591         r = Panel.show_include_opt\r
592         r[:speech_balloons].has_key?(:speeches).should be_true\r
593       end\r
594     it '作家を含んでいる' do\r
595       r = Panel.list_opt[:include]\r
596       r.has_key?(:author).should be_true\r
597     end\r
598   end\r
599   describe 'json一覧出力オプションに於いて' do\r
600     it 'includeキーを含んでいる' do\r
601       r = Panel.list_json_opt\r
602       r.has_key?(:include).should be_true\r
603     end\r
604     it '4つの項目を含んでいる' do\r
605       r = Panel.list_json_opt[:include]\r
606       r.should have(4).items\r
607     end\r
608     it 'コミックを含んでいる' do\r
609       r = Panel.list_json_opt[:include]\r
610       r.has_key?(:comic).should be_true\r
611     end\r
612     it 'コマ絵を含んでいる' do\r
613       r = Panel.list_json_opt[:include]\r
614       r.has_key?(:panel_pictures).should be_true\r
615     end\r
616       it 'コマ絵は素材を含んでいる' do\r
617         r = Panel.list_json_opt[:include]\r
618         r[:panel_pictures].has_key?(:resource_picture).should be_true\r
619       end\r
620         it '素材は絵師を含んでいる' do\r
621           r = Panel.list_json_opt[:include]\r
622           r[:panel_pictures][:resource_picture].has_key?(:artist).should be_true\r
623         end\r
624         it '素材はライセンスを含んでいる' do\r
625           r = Panel.list_json_opt[:include]\r
626           r[:panel_pictures][:resource_picture].has_key?(:license).should be_true\r
627         end\r
628     it 'フキダシを含んでいる' do\r
629       r = Panel.show_include_opt\r
630       r.has_key?(:speech_balloons).should be_true\r
631     end\r
632       it 'フキダシはフキダシ枠を含んでいる' do\r
633         r = Panel.show_include_opt\r
634         r[:speech_balloons].has_key?(:balloons).should be_true\r
635       end\r
636       it 'フキダシはセリフを含んでいる' do\r
637         r = Panel.show_include_opt\r
638         r[:speech_balloons].has_key?(:speeches).should be_true\r
639       end\r
640     it '作家を含んでいる' do\r
641       r = Panel.list_json_opt[:include]\r
642       r.has_key?(:author).should be_true\r
643     end\r
644   end\r
645   \r
646   #異常データ検出\r
647     #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった\r
648     #コマ絵とフキダシの整合チェックをする\r
649   describe 'id収集に於いて' do\r
650     context 'つつがなく終わるとき' do\r
651       it '第一パラメータで指定された配列中から第二引数のidを収集している' do\r
652         a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], \r
653           [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]\r
654         r = Panel.collect_element_value a, :panel_id\r
655         r.should eq [1, 2, 3, 4]\r
656       end\r
657     end\r
658     context 'Nil除外指示があるとき' do\r
659       it '収集したpanel_idのうちnilは除外している' do\r
660         a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}], \r
661           [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]\r
662         r = Panel.collect_element_value a, :panel_id, true\r
663         r.should eq [1, 2, 3, 4]\r
664       end\r
665     end\r
666   end\r
667   describe 'id一致チェックに於いて' do\r
668     #parent.idがNilのときはすべてNil。数値のときは全一致\r
669     context '親が既存(idが数値)のとき' do\r
670       it 'すべてid一致するときTrueを返す' do\r
671         r = Panel.validate_id [1, 1, 1, 1], 1\r
672         r.should be_true\r
673       end\r
674       it 'idが一致する中にNilが混じってもTrueを返す' do\r
675         r = Panel.validate_id [1, 1, 1, 1, nil], 1\r
676         r.should be_true\r
677       end\r
678       it 'すべて数値でも一致しないときFalseを返す' do\r
679         r = Panel.validate_id [1, 1, 1, 1, 2], 1\r
680         r.should be_false\r
681       end\r
682       it '数値とNilが混ざってもIDが一致しないときFalseを返す' do\r
683         r = Panel.validate_id [1, 1, nil, 2], 1\r
684         r.should be_false\r
685       end\r
686     end\r
687     context '親が新規(idがNil)のとき' do\r
688       it 'すべてNilはTrueを返す' do\r
689         r = Panel.validate_id [ nil,nil,nil,nil], nil\r
690         r.should be_true\r
691       end\r
692       it 'すべてnilでなければFalseを返す' do\r
693         r = Panel.validate_id [nil,nil,nil,nil, 2], nil\r
694         r.should be_false\r
695       end\r
696     end\r
697   end\r
698   describe 'idチェック単体に於いて' do\r
699     before do\r
700 #      @pp = Factory :panel_picture, :panel_id => @panel.id, :t => 1\r
701     end\r
702     context 'つつがなく終わるとき' do\r
703       it 'idを収集依頼している' do\r
704         Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
705         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
706         Panel.stub(:validate_id).with(any_args).and_return(true)\r
707         r = Panel.validate_element_id [], :panel_id, nil\r
708       end\r
709       it '収集したidを一致チェック依頼している' do\r
710         Panel.should_receive(:validate_id).with(any_args).exactly(1)\r
711         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
712         Panel.stub(:validate_id).with(any_args).and_return(true)\r
713         r = Panel.validate_element_id [], :panel_id, nil\r
714       end\r
715     end\r
716     #実データでチェック\r
717     #依頼チェックだけでは不安なので最低限のチェックを\r
718     context 'コマ新規のとき' do\r
719       it 'コマ絵で正常通過している' do\r
720         @panel = Factory.build :panel, :author_id => @author.id\r
721         @panel.panel_pictures.build(\r
722           Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)\r
723         )\r
724         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
725         r.should be_true\r
726       end\r
727       it 'フキダシで正常通過している' do\r
728         @panel = Factory.build :panel, :author_id => @author.id\r
729         @panel.speech_balloons.build(\r
730           Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
731         )\r
732         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
733         r.should be_true\r
734       end\r
735     end\r
736     context 'コマ既存のとき' do\r
737       it 'コマ絵で正常通過している' do\r
738         @panel = Factory :panel, :author_id => @author.id\r
739         @panel.panel_pictures.build(\r
740           Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)\r
741         )\r
742         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
743         r.should be_true\r
744       end\r
745       it 'フキダシで正常通過している' do\r
746         @panel = Factory :panel, :author_id => @author.id\r
747         @panel.speech_balloons.build(\r
748           Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
749         )\r
750         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
751         r.should be_true\r
752       end\r
753     end\r
754     context 'フキダシ新規のとき' do\r
755       it 'バルーンで正常通過している' do\r
756         @panel = Factory.build :panel, :author_id => @author.id\r
757         @panel.speech_balloons.build(\r
758           Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
759         )\r
760         @panel.speech_balloons.first.balloons.build(\r
761           Factory.attributes_for(:balloon, :speech_balloon_id => nil)\r
762         )\r
763         r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id\r
764         r.should be_true\r
765       end\r
766       it 'セリフで正常通過している' do\r
767         @panel = Factory.build :panel, :author_id => @author.id\r
768         @panel.speech_balloons.build(\r
769           Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
770         )\r
771         @panel.speech_balloons.first.speeches.build(\r
772           Factory.attributes_for(:speech, :speech_balloon_id => nil)\r
773         )\r
774         r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id\r
775         r.should be_true\r
776       end\r
777     end\r
778   end\r
779   describe 'idチェックリスト生成に於いて' do\r
780     before do\r
781       @panel = Factory.build :panel, :author_id => @author.id\r
782     end\r
783     context 'つつがなく終わるとき' do\r
784       it 'コマ部品とフキダシ部品のトータル2を返す' do\r
785         @panel.panel_pictures.build(\r
786           Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)\r
787         )\r
788         @panel.speech_balloons.build(\r
789           Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
790         )\r
791         @panel.speech_balloons.first.balloons.build(\r
792           Factory.attributes_for(:balloon, :speech_balloon_id => nil)\r
793         )\r
794         @panel.speech_balloons.first.speeches.build(\r
795           Factory.attributes_for(:speech, :speech_balloon_id => nil)\r
796         )\r
797         r = @panel.validate_id_list\r
798         r.should have(2).items\r
799       end\r
800       it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do\r
801         @panel.panel_pictures.build(\r
802           Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)\r
803         )\r
804         sb1 = @panel.speech_balloons.build(\r
805           Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
806         )\r
807         sb1.balloons.build(\r
808           Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
809         )\r
810         sb1.speeches.build(\r
811           Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
812         )\r
813         sb2 = @panel.speech_balloons.build(\r
814           Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
815         )\r
816         sb2.balloons.build(\r
817           Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
818         )\r
819         sb2.speeches.build(\r
820           Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
821         )\r
822         r = @panel.validate_id_list\r
823         r.should have(3).items\r
824       end\r
825     end\r
826   end\r
827   describe 'idチェック複合に於いて' do\r
828     before do\r
829       @panel = Factory.build :panel, :author_id => @author.id\r
830     end\r
831     context 'つつがなく終わるとき' do\r
832       it 'コマ部品とフキダシ部品の二回チェック依頼している' do\r
833         Panel.should_receive(:validate_element_id).with(any_args).exactly(2)\r
834         Panel.stub(:validate_element_id).with(any_args).and_return(true)\r
835         @panel.panel_pictures.build(\r
836           Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => nil)\r
837         )\r
838         sb1 = @panel.speech_balloons.build(\r
839           Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
840         )\r
841         sb1.balloons.build(\r
842           Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
843         )\r
844         sb1.speeches.build(\r
845           Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
846         )\r
847         r = Panel.validate_elements_id(@panel.validate_id_list)\r
848       end\r
849     end\r
850   end\r
851   describe 'シリアライズチェックに於いて' do\r
852     context 'つつがなく終わるとき' do\r
853       it '0からシリアライズされているならTrueを返す' do\r
854         r = Panel.validate_t [0, 1, 2]\r
855         r.should be_true\r
856       end\r
857       it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
858         r = Panel.validate_t [0, 2, 1]\r
859         r.should be_true\r
860       end\r
861       it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
862         r = Panel.validate_t [ 2, 1, 4, 3, 0]\r
863         r.should be_true\r
864       end\r
865     end\r
866     context '異常なとき' do\r
867       it '0から始まらないならFalseを返す' do\r
868         r = Panel.validate_t [1, 2, 3]\r
869         r.should be_false\r
870       end\r
871       it '連続していないならFalseを返す' do\r
872         r = Panel.validate_t [0, 1, 2, 4]\r
873         r.should be_false\r
874       end\r
875       it '連続していないならFalseを返す' do\r
876         r = Panel.validate_t [0, 1, 2, 4, 5]\r
877         r.should be_false\r
878       end\r
879     end\r
880   end\r
881   describe 'tチェック単体に於いて' do\r
882     before do\r
883     end\r
884     context 'つつがなく終わるとき' do\r
885       it 'コマ絵とフキダシのtを収集依頼している' do\r
886         Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
887         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
888         Panel.stub(:validate_t).with(any_args).and_return(true)\r
889         r = Panel.validate_element_t [], :t\r
890       end\r
891       it '収集したtをシリアライズチェック依頼している' do\r
892         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
893         Panel.should_receive(:validate_t).with(any_args).exactly(1)\r
894         Panel.stub(:validate_t).with(any_args).and_return(true)\r
895         r = Panel.validate_element_t [], :t\r
896       end\r
897     end\r
898     #実データでチェック\r
899     #依頼チェックだけでは不安なので最低限のチェックを\r
900     context '新規のとき' do\r
901       it 'コマ絵で正常通過している' do\r
902         @panel = Factory.build :panel, :author_id => @author.id\r
903         @panel.panel_pictures.build(\r
904           Factory.attributes_for(:panel_picture, :panel_id => nil, :resource_picture_id => @rp.id, :t => nil)\r
905         )\r
906         r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
907         r.should be_true\r
908       end\r
909       it 'フキダシで正常通過している' do\r
910         @panel = Factory.build :panel, :author_id => @author.id\r
911         @panel.speech_balloons.build(\r
912           Factory.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)\r
913         )\r
914         r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
915         r.should be_true\r
916       end\r
917     end\r
918     context '既存のとき' do\r
919       it 'コマ絵で正常通過している' do\r
920         @panel = Factory :panel, :author_id => @author.id\r
921         @panel.panel_pictures.build(\r
922           Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)\r
923         )\r
924         r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
925         r.should be_true\r
926       end\r
927       it 'フキダシで正常通過している' do\r
928         @panel = Factory :panel, :author_id => @author.id\r
929         @panel.speech_balloons.build(\r
930           Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
931         )\r
932         r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
933         r.should be_true\r
934       end\r
935     end\r
936   end\r
937   describe '複合チェックに於いて' do\r
938     context 'つつがなく終わるとき' do\r
939       it 'している' do\r
940         @panel = Factory.build :panel, :author_id => @author.id\r
941         @panel.panel_pictures.build(\r
942           Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 0)\r
943         )\r
944         @panel.panel_pictures.build(\r
945           Factory.attributes_for(:panel_picture, :panel_id => @panel.id, :resource_picture_id => @rp.id, :t => 1)\r
946         )\r
947         sb1 = @panel.speech_balloons.build(\r
948           Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)\r
949         )\r
950         sb1.balloons.build(\r
951           Factory.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
952         )\r
953         sb1.speeches.build(\r
954           Factory.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
955         )\r
956         sb2 = @panel.speech_balloons.build(\r
957           Factory.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)\r
958         )\r
959         sb2.balloons.build(\r
960           Factory.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
961         )\r
962         sb2.speeches.build(\r
963           Factory.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
964         )\r
965         r = @panel.validate_child\r
966         r.should be_true\r
967       end\r
968     end\r
969   end\r
970 end\r