OSDN Git Service

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