OSDN Git Service

ecf150a4134baa8f922467525fd0cd73daf69333
[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     FactoryGirl.create :admin\r
7     @sp = FactoryGirl.create :system_picture\r
8     @lg = FactoryGirl.create :license_group\r
9     @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id\r
10     @user = FactoryGirl.create( :user_yas)\r
11     @author = @user.author\r
12     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id\r
13     @other_user = FactoryGirl.create( :user_yas)\r
14     @other_author = @other_user.author\r
15     @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id\r
16     @op = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
17     @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id\r
18     @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id\r
19     @sbt = FactoryGirl.create :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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.create :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 = FactoryGirl.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 = FactoryGirl.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 = FactoryGirl.create :panel, :author_id => @author.id\r
227       panel.own?(@author).should == true\r
228     end\r
229     it '他人のコマならno' do\r
230       panel = FactoryGirl.create :panel, :author_id => @author.id\r
231       panel.own?(@other_author).should == false\r
232     end\r
233     it '作家が不明ならno' do\r
234       panel = FactoryGirl.create :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 = FactoryGirl.create :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 = FactoryGirl.create :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 = FactoryGirl.create :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 = FactoryGirl.create :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 = FactoryGirl.create :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 = FactoryGirl.create :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     it '6つの項目を含んでいる' do\r
318       r = Panel.show_include_opt\r
319       r.should have(6).items\r
320     end\r
321     it 'コマ絵を含んでいる' do\r
322       r = Panel.show_include_opt\r
323       r.has_key?(:panel_pictures).should be_true\r
324     end\r
325       it 'コマ絵は実素材を含んでいる' do\r
326         r = Panel.show_include_opt\r
327         r[:panel_pictures].has_key?(:picture).should be_true\r
328       end\r
329         it '実素材は絵師を含んでいる' do\r
330           r = Panel.show_include_opt\r
331           r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
332         end\r
333         it '実素材はライセンスを含んでいる' do\r
334           r = Panel.show_include_opt\r
335           r[:panel_pictures][:picture].has_key?(:license).should be_true\r
336         end\r
337     it 'フキダシを含んでいる' do\r
338       r = Panel.show_include_opt\r
339       r.has_key?(:speech_balloons).should be_true\r
340     end\r
341       it 'フキダシはフキダシ枠を含んでいる' do\r
342         r = Panel.show_include_opt\r
343         r[:speech_balloons].has_key?(:balloons).should be_true\r
344       end\r
345       it 'フキダシはセリフを含んでいる' do\r
346         r = Panel.show_include_opt\r
347         r[:speech_balloons].has_key?(:speeches).should be_true\r
348       end\r
349     it '景色画像を含んでいる' do\r
350       r = Panel.show_include_opt\r
351       r.has_key?(:ground_pictures).should be_true\r
352     end\r
353       it '景色画像は実素材を含んでいる' do\r
354         r = Panel.show_include_opt\r
355         r[:ground_pictures].has_key?(:picture).should be_true\r
356       end\r
357         it '実素材は絵師を含んでいる' do\r
358           r = Panel.show_include_opt\r
359           r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
360         end\r
361         it '実素材はライセンスを含んでいる' do\r
362           r = Panel.show_include_opt\r
363           r[:ground_pictures][:picture].has_key?(:license).should be_true\r
364         end\r
365     it '間接色を含んでいる' do\r
366       r = Panel.show_include_opt\r
367       r.has_key?(:ground_colors).should be_true\r
368     end\r
369       it '間接色は色を含んでいる' do\r
370         r = Panel.show_include_opt\r
371         r[:ground_colors].has_key?(:color).should be_true\r
372       end\r
373     it '景色を含んでいる' do\r
374       r = Panel.show_include_opt\r
375       r.has_key?(:panel_colors).should be_true\r
376     end\r
377     it '作家を含んでいる' do\r
378       r = Panel.show_include_opt\r
379       r.has_key?(:author).should be_true\r
380     end\r
381   end\r
382   describe 'json単体出力オプションに於いて' do\r
383     it 'includeキーを含んでいる' do\r
384       r = Panel.show_json_include_opt\r
385       r.has_key?(:include).should be_true\r
386     end\r
387     it '6つの項目を含んでいる' do\r
388       r = Panel.show_json_include_opt[:include]\r
389       r.should have(6).items\r
390     end\r
391     it 'コマ絵を含んでいる' do\r
392       r = Panel.show_json_include_opt[:include]\r
393       r.has_key?(:panel_pictures).should be_true\r
394     end\r
395       it 'コマ絵は実素材を含んでいる' do\r
396         r = Panel.show_json_include_opt[:include]\r
397         r[:panel_pictures].has_key?(:picture).should be_true\r
398       end\r
399         it '実素材は絵師を含んでいる' do\r
400           r = Panel.show_json_include_opt[:include]\r
401           r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
402         end\r
403         it '実素材はライセンスを含んでいる' do\r
404           r = Panel.show_json_include_opt[:include]\r
405           r[:panel_pictures][:picture].has_key?(:license).should be_true\r
406         end\r
407     it 'フキダシを含んでいる' do\r
408       r = Panel.show_json_include_opt[:include]\r
409       r.has_key?(:speech_balloons).should be_true\r
410     end\r
411       it 'フキダシはフキダシ枠を含んでいる' do\r
412         r = Panel.show_json_include_opt[:include]\r
413         r[:speech_balloons].has_key?(:balloons).should be_true\r
414       end\r
415       it 'フキダシはセリフを含んでいる' do\r
416         r = Panel.show_json_include_opt[:include]\r
417         r[:speech_balloons].has_key?(:speeches).should be_true\r
418       end\r
419     it '景色画像を含んでいる' do\r
420       r = Panel.show_json_include_opt[:include]\r
421       r.has_key?(:ground_pictures).should be_true\r
422     end\r
423       it '景色画像は実素材を含んでいる' do\r
424         r = Panel.show_json_include_opt[:include]\r
425         r[:ground_pictures].has_key?(:picture).should be_true\r
426       end\r
427         it '実素材は絵師を含んでいる' do\r
428           r = Panel.show_json_include_opt[:include]\r
429           r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
430         end\r
431         it '実素材はライセンスを含んでいる' do\r
432           r = Panel.show_json_include_opt[:include]\r
433           r[:ground_pictures][:picture].has_key?(:license).should be_true\r
434         end\r
435     it '間接色を含んでいる' do\r
436       r = Panel.show_json_include_opt[:include]\r
437       r.has_key?(:ground_colors).should be_true\r
438     end\r
439       it '間接色は色を含んでいる' do\r
440         r = Panel.show_json_include_opt[:include]\r
441         r[:ground_colors].has_key?(:color).should be_true\r
442       end\r
443     it '景色を含んでいる' do\r
444       r = Panel.show_json_include_opt[:include]\r
445       r.has_key?(:panel_colors).should be_true\r
446     end\r
447     it '作家を含んでいる' do\r
448       r = Panel.show_json_include_opt[:include]\r
449       r.has_key?(:author).should be_true\r
450     end\r
451   end\r
452   describe '一覧取得に於いて' do\r
453     before do\r
454       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
455     end\r
456     context 'page補正について' do\r
457       it '文字列から数値に変換される' do\r
458         Panel.page('8').should eq 8\r
459       end\r
460       it 'nilの場合は1になる' do\r
461         Panel.page().should eq 1\r
462       end\r
463       it '0以下の場合は1になる' do\r
464         Panel.page('0').should eq 1\r
465       end\r
466     end\r
467     context 'page_size補正について' do\r
468       it '文字列から数値に変換される' do\r
469         Panel.page_size('7').should eq 7\r
470       end\r
471       it 'nilの場合はPanel.default_page_sizeになる' do\r
472         Panel.page_size().should eq Panel.default_page_size\r
473       end\r
474       it '0以下の場合はPanel.default_page_sizeになる' do\r
475         Panel.page_size('0').should eq Panel.default_page_size\r
476       end\r
477       it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do\r
478         Panel.page_size('1000').should eq Panel.max_page_size\r
479       end\r
480     end\r
481     it 'リストを返す' do\r
482       pl = Panel.list\r
483       pl.should eq [@panel]\r
484     end\r
485     it '時系列で並んでいる' do\r
486       npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
487       pl = Panel.list\r
488       pl.should eq [npl, @panel]\r
489     end\r
490     it '非公開のコマは含まない' do\r
491       npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0\r
492       pl = Panel.list\r
493       pl.should eq [@panel]\r
494     end\r
495     context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
496       before do\r
497         @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
498         @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
499         @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
500         @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
501         Panel.stub(:default_page_size).and_return(2)\r
502       end\r
503       it '通常は2件を返す' do\r
504         pl = Panel.list\r
505         pl.should have(2).items \r
506       end\r
507       it 'page=1なら末尾2件を返す' do\r
508         #時系列で並んでいる\r
509         pl = Panel.list( {}, 1)\r
510         pl.should eq [@npl5, @npl4]\r
511       end\r
512       it 'page=2なら中間2件を返す' do\r
513         pl = Panel.list({}, 2)\r
514         pl.should eq [@npl3, @npl2]\r
515       end\r
516       it 'page=3なら先頭1件を返す' do\r
517         pl = Panel.list({}, 3)\r
518         pl.should eq [@panel]\r
519       end\r
520     end\r
521   end\r
522   describe 'list関連テーブルプションに於いて' do\r
523     it 'includeキーを含んでいる' do\r
524       r = Panel.list_opt\r
525       r.has_key?(:include).should be_true\r
526     end\r
527     it '6つの項目を含んでいる' do\r
528       r = Panel.list_opt[:include]\r
529       r.should have(6).items\r
530     end\r
531     it 'コマ絵を含んでいる' do\r
532       r = Panel.list_opt[:include]\r
533       r.has_key?(:panel_pictures).should be_true\r
534     end\r
535       it 'コマ絵は実素材を含んでいる' do\r
536         r = Panel.list_opt[:include]\r
537         r[:panel_pictures].has_key?(:picture).should be_true\r
538       end\r
539         it '実素材は絵師を含んでいる' do\r
540           r = Panel.list_opt[:include]\r
541           r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
542         end\r
543         it '実素材はライセンスを含んでいる' do\r
544           r = Panel.list_opt[:include]\r
545           r[:panel_pictures][:picture].has_key?(:license).should be_true\r
546         end\r
547     it 'フキダシを含んでいる' do\r
548       r = Panel.list_opt[:include]\r
549       r.has_key?(:speech_balloons).should be_true\r
550     end\r
551       it 'フキダシはフキダシ枠を含んでいる' do\r
552         r = Panel.list_opt[:include]\r
553         r[:speech_balloons].has_key?(:balloons).should be_true\r
554       end\r
555       it 'フキダシはセリフを含んでいる' do\r
556         r = Panel.list_opt[:include]\r
557         r[:speech_balloons].has_key?(:speeches).should be_true\r
558       end\r
559     it '景色画像を含んでいる' do\r
560       r = Panel.list_opt[:include]\r
561       r.has_key?(:ground_pictures).should be_true\r
562     end\r
563       it '景色画像は実素材を含んでいる' do\r
564         r = Panel.list_opt[:include]\r
565         r[:ground_pictures].has_key?(:picture).should be_true\r
566       end\r
567         it '実素材は絵師を含んでいる' do\r
568           r = Panel.list_opt[:include]\r
569           r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
570         end\r
571         it '実素材はライセンスを含んでいる' do\r
572           r = Panel.list_opt[:include]\r
573           r[:ground_pictures][:picture].has_key?(:license).should be_true\r
574         end\r
575     it '間接色を含んでいる' do\r
576       r = Panel.list_opt[:include]\r
577       r.has_key?(:ground_colors).should be_true\r
578     end\r
579       it '間接色は色を含んでいる' do\r
580         r = Panel.list_opt[:include]\r
581         r[:ground_colors].has_key?(:color).should be_true\r
582       end\r
583     it '景色を含んでいる' do\r
584       r = Panel.list_opt[:include]\r
585       r.has_key?(:panel_colors).should be_true\r
586     end\r
587     it '作家を含んでいる' do\r
588       r = Panel.list_opt[:include]\r
589       r.has_key?(:author).should be_true\r
590     end\r
591   end\r
592   describe 'json一覧出力オプションに於いて' do\r
593     it 'includeキーを含んでいる' do\r
594       r = Panel.list_json_opt\r
595       r.has_key?(:include).should be_true\r
596     end\r
597     it '6つの項目を含んでいる' do\r
598       r = Panel.list_json_opt[:include]\r
599       r.should have(6).items\r
600     end\r
601     it 'コマ絵を含んでいる' do\r
602       r = Panel.list_json_opt[:include]\r
603       r.has_key?(:panel_pictures).should be_true\r
604     end\r
605       it 'コマ絵は実素材を含んでいる' do\r
606         r = Panel.list_json_opt[:include]\r
607         r[:panel_pictures].has_key?(:picture).should be_true\r
608       end\r
609         it '実素材は絵師を含んでいる' do\r
610           r = Panel.list_json_opt[:include]\r
611           r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
612         end\r
613         it '実素材はライセンスを含んでいる' do\r
614           r = Panel.list_json_opt[:include]\r
615           r[:panel_pictures][:picture].has_key?(:license).should be_true\r
616         end\r
617     it 'フキダシを含んでいる' do\r
618       r = Panel.list_json_opt[:include]\r
619       r.has_key?(:speech_balloons).should be_true\r
620     end\r
621       it 'フキダシはフキダシ枠を含んでいる' do\r
622         r = Panel.list_json_opt[:include]\r
623         r[:speech_balloons].has_key?(:balloons).should be_true\r
624       end\r
625       it 'フキダシはセリフを含んでいる' do\r
626         r = Panel.list_json_opt[:include]\r
627         r[:speech_balloons].has_key?(:speeches).should be_true\r
628       end\r
629     it '景色画像を含んでいる' do\r
630       r = Panel.list_json_opt[:include]\r
631       r.has_key?(:ground_pictures).should be_true\r
632     end\r
633       it '景色画像は実素材を含んでいる' do\r
634         r = Panel.list_json_opt[:include]\r
635         r[:ground_pictures].has_key?(:picture).should be_true\r
636       end\r
637         it '実素材は絵師を含んでいる' do\r
638           r = Panel.list_json_opt[:include]\r
639           r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
640         end\r
641         it '実素材はライセンスを含んでいる' do\r
642           r = Panel.list_json_opt[:include]\r
643           r[:ground_pictures][:picture].has_key?(:license).should be_true\r
644         end\r
645     it '間接色を含んでいる' do\r
646       r = Panel.list_json_opt[:include]\r
647       r.has_key?(:ground_colors).should be_true\r
648     end\r
649       it '間接色は色を含んでいる' do\r
650         r = Panel.list_json_opt[:include]\r
651         r[:ground_colors].has_key?(:color).should be_true\r
652       end\r
653     it '景色を含んでいる' do\r
654       r = Panel.list_json_opt[:include]\r
655       r.has_key?(:panel_colors).should be_true\r
656     end\r
657     it '作家を含んでいる' do\r
658       r = Panel.list_json_opt[:include]\r
659       r.has_key?(:author).should be_true\r
660     end\r
661   end\r
662   \r
663   describe '自分のコマ一覧取得に於いて' do\r
664     before do\r
665       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
666     end\r
667     it 'リストを返す' do\r
668       pl = Panel.mylist @author\r
669       pl.should eq [@panel]\r
670     end\r
671     it '時系列で並んでいる' do\r
672       npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
673       pl = Panel.mylist @author\r
674       pl.should eq [npl, @panel]\r
675     end\r
676     it '他人のコマは公開でも含まない' do\r
677       npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1\r
678       pl = Panel.mylist @author\r
679       pl.should eq [@panel]\r
680     end\r
681     it '自分のコマは非公開でも含んでいる' do\r
682       npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100\r
683       pl = Panel.mylist @author\r
684       pl.should eq [npl, @panel]\r
685     end\r
686   end\r
687   \r
688   #異常データ検出\r
689     #コマはコミックに従属しなくなったのでtで入れ替えるチェックは要らなくなった\r
690     #コマ絵とフキダシの整合チェックをする\r
691   describe 'id収集に於いて' do\r
692     context 'つつがなく終わるとき' do\r
693       it '第一パラメータで指定された配列中から第二引数のidを収集している' do\r
694         a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], \r
695           [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]\r
696         r = Panel.collect_element_value a, :panel_id\r
697         r.should eq [1, 2, 3, 4]\r
698       end\r
699     end\r
700     context 'Nil除外指示があるとき' do\r
701       it '収集したpanel_idのうちnilは除外している' do\r
702         a = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}, {:panel_id => nil, :a => 'a'}], \r
703           [{:panel_id => 3, :a => 'a'}, {:panel_id => nil, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]\r
704         r = Panel.collect_element_value a, :panel_id, true\r
705         r.should eq [1, 2, 3, 4]\r
706       end\r
707     end\r
708   end\r
709   describe 'id一致チェックに於いて' do\r
710     #parent.idがNilのときはすべてNil。数値のときは全一致\r
711     context '親が既存(idが数値)のとき' do\r
712       it 'すべてid一致するときTrueを返す' do\r
713         r = Panel.validate_id [1, 1, 1, 1], 1\r
714         r.should be_true\r
715       end\r
716       it 'idが一致する中にNilが混じってもTrueを返す' do\r
717         r = Panel.validate_id [1, 1, 1, 1, nil], 1\r
718         r.should be_true\r
719       end\r
720       it 'すべて数値でも一致しないときFalseを返す' do\r
721         r = Panel.validate_id [1, 1, 1, 1, 2], 1\r
722         r.should be_false\r
723       end\r
724       it '数値とNilが混ざってもIDが一致しないときFalseを返す' do\r
725         r = Panel.validate_id [1, 1, nil, 2], 1\r
726         r.should be_false\r
727       end\r
728     end\r
729     context '親が新規(idがNil)のとき' do\r
730       it 'すべてNilはTrueを返す' do\r
731         r = Panel.validate_id [ nil,nil,nil,nil], nil\r
732         r.should be_true\r
733       end\r
734       it 'すべてnilでなければFalseを返す' do\r
735         r = Panel.validate_id [nil,nil,nil,nil, 2], nil\r
736         r.should be_false\r
737       end\r
738     end\r
739   end\r
740   describe 'idチェック単体に於いて' do\r
741     before do\r
742 #      @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1\r
743     end\r
744     context 'つつがなく終わるとき' do\r
745       it 'idを収集依頼している' do\r
746         Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
747         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
748         Panel.stub(:validate_id).with(any_args).and_return(true)\r
749         r = Panel.validate_element_id [], :panel_id, nil\r
750       end\r
751       it '収集したidを一致チェック依頼している' do\r
752         Panel.should_receive(:validate_id).with(any_args).exactly(1)\r
753         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
754         Panel.stub(:validate_id).with(any_args).and_return(true)\r
755         r = Panel.validate_element_id [], :panel_id, nil\r
756       end\r
757     end\r
758     #実データでチェック\r
759     #依頼チェックだけでは不安なので最低限のチェックを\r
760     context 'コマ新規のとき' do\r
761       it 'コマ絵で正常通過している' do\r
762         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
763         @panel.panel_pictures.build(\r
764           FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)\r
765         )\r
766         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
767         r.should be_true\r
768       end\r
769       it 'フキダシで正常通過している' do\r
770         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
771         @panel.speech_balloons.build(\r
772           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
773         )\r
774         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
775         r.should be_true\r
776       end\r
777     end\r
778     context 'コマ既存のとき' do\r
779       it 'コマ絵で正常通過している' do\r
780         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
781         @panel.panel_pictures.build(\r
782           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)\r
783         )\r
784         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
785         r.should be_true\r
786       end\r
787       it 'フキダシで正常通過している' do\r
788         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
789         @panel.speech_balloons.build(\r
790           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
791         )\r
792         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
793         r.should be_true\r
794       end\r
795     end\r
796     context 'フキダシ新規のとき' do\r
797       it 'バルーンで正常通過している' do\r
798         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
799         @panel.speech_balloons.build(\r
800           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
801         )\r
802         @panel.speech_balloons.first.balloons.build(\r
803           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)\r
804         )\r
805         r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id\r
806         r.should be_true\r
807       end\r
808       it 'セリフで正常通過している' do\r
809         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
810         @panel.speech_balloons.build(\r
811           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
812         )\r
813         @panel.speech_balloons.first.speeches.build(\r
814           FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)\r
815         )\r
816         r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id\r
817         r.should be_true\r
818       end\r
819     end\r
820   end\r
821   describe 'idチェックリスト生成に於いて' do\r
822     before do\r
823       @panel = FactoryGirl.build :panel, :author_id => @author.id\r
824     end\r
825     context 'つつがなく終わるとき' do\r
826       it 'コマ部品とフキダシ部品のトータル2を返す' do\r
827         @panel.panel_pictures.build(\r
828           FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)\r
829         )\r
830         @panel.speech_balloons.build(\r
831           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
832         )\r
833         @panel.speech_balloons.first.balloons.build(\r
834           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)\r
835         )\r
836         @panel.speech_balloons.first.speeches.build(\r
837           FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)\r
838         )\r
839         r = @panel.validate_id_list\r
840         r.should have(2).items\r
841       end\r
842       it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do\r
843         @panel.panel_pictures.build(\r
844           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)\r
845         )\r
846         sb1 = @panel.speech_balloons.build(\r
847           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
848         )\r
849         sb1.balloons.build(\r
850           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
851         )\r
852         sb1.speeches.build(\r
853           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
854         )\r
855         sb2 = @panel.speech_balloons.build(\r
856           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
857         )\r
858         sb2.balloons.build(\r
859           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
860         )\r
861         sb2.speeches.build(\r
862           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
863         )\r
864         r = @panel.validate_id_list\r
865         r.should have(3).items\r
866       end\r
867     end\r
868   end\r
869   describe 'idチェック複合に於いて' do\r
870     before do\r
871       @panel = FactoryGirl.build :panel, :author_id => @author.id\r
872     end\r
873     context 'つつがなく終わるとき' do\r
874       it 'コマ部品とフキダシ部品の二回チェック依頼している' do\r
875         Panel.should_receive(:validate_element_id).with(any_args).exactly(2)\r
876         Panel.stub(:validate_element_id).with(any_args).and_return(true)\r
877         @panel.panel_pictures.build(\r
878           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)\r
879         )\r
880         sb1 = @panel.speech_balloons.build(\r
881           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
882         )\r
883         sb1.balloons.build(\r
884           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
885         )\r
886         sb1.speeches.build(\r
887           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
888         )\r
889         r = Panel.validate_elements_id(@panel.validate_id_list)\r
890       end\r
891     end\r
892   end\r
893   describe 'シリアライズチェックに於いて' do\r
894     context 'つつがなく終わるとき' do\r
895       it '0からシリアライズされているならTrueを返す' do\r
896         r = Panel.validate_t [0, 1, 2]\r
897         r.should be_true\r
898       end\r
899       it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
900         r = Panel.validate_t [0, 2, 1]\r
901         r.should be_true\r
902       end\r
903       it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
904         r = Panel.validate_t [ 2, 1, 4, 3, 0]\r
905         r.should be_true\r
906       end\r
907     end\r
908     context '異常なとき' do\r
909       it '0から始まらないならFalseを返す' do\r
910         r = Panel.validate_t [1, 2, 3]\r
911         r.should be_false\r
912       end\r
913       it '連続していないならFalseを返す' do\r
914         r = Panel.validate_t [0, 1, 2, 4]\r
915         r.should be_false\r
916       end\r
917       it '連続していないならFalseを返す' do\r
918         r = Panel.validate_t [0, 1, 2, 4, 5]\r
919         r.should be_false\r
920       end\r
921     end\r
922   end\r
923   describe 'tチェック単体に於いて' do\r
924     before do\r
925     end\r
926     context 'つつがなく終わるとき' do\r
927       it 'コマ絵とフキダシのtを収集依頼している' do\r
928         Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
929         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
930         Panel.stub(:validate_t).with(any_args).and_return(true)\r
931         r = Panel.validate_element_t [], :t\r
932       end\r
933       it '収集したtをシリアライズチェック依頼している' do\r
934         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
935         Panel.should_receive(:validate_t).with(any_args).exactly(1)\r
936         Panel.stub(:validate_t).with(any_args).and_return(true)\r
937         r = Panel.validate_element_t [], :t\r
938       end\r
939     end\r
940     #実データでチェック\r
941     #依頼チェックだけでは不安なので最低限のチェックを\r
942     context '新規のとき' do\r
943       it 'コマ絵で正常通過している' do\r
944         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
945         @panel.panel_pictures.build(\r
946           FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)\r
947         )\r
948         r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
949         r.should be_true\r
950       end\r
951       it 'フキダシで正常通過している' do\r
952         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
953         @panel.speech_balloons.build(\r
954           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id, :t => nil)\r
955         )\r
956         r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
957         r.should be_true\r
958       end\r
959     end\r
960     context '既存のとき' do\r
961       it 'コマ絵で正常通過している' do\r
962         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
963         @panel.panel_pictures.build(\r
964           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)\r
965         )\r
966         r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
967         r.should be_true\r
968       end\r
969       it 'フキダシで正常通過している' do\r
970         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
971         @panel.speech_balloons.build(\r
972           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
973         )\r
974         r = Panel.validate_element_t [@panel.panel_pictures, @panel.speech_balloons], :t\r
975         r.should be_true\r
976       end\r
977     end\r
978   end\r
979   describe '複合チェックに於いて' do\r
980     context 'つつがなく終わるとき' do\r
981       it 'している' do\r
982         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
983         @panel.panel_pictures.build(\r
984           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)\r
985         )\r
986         @panel.panel_pictures.build(\r
987           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)\r
988         )\r
989         sb1 = @panel.speech_balloons.build(\r
990           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)\r
991         )\r
992         sb1.balloons.build(\r
993           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
994         )\r
995         sb1.speeches.build(\r
996           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
997         )\r
998         sb2 = @panel.speech_balloons.build(\r
999           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)\r
1000         )\r
1001         sb2.balloons.build(\r
1002           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
1003         )\r
1004         sb2.speeches.build(\r
1005           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
1006         )\r
1007         r = @panel.validate_child\r
1008         r.should be_true\r
1009       end\r
1010     end\r
1011   end\r
1012   describe '複合チェックに於いて' do\r
1013     context 'つつがなく終わるとき' do\r
1014       it 'している' do\r
1015         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1016         @panel.panel_pictures.build(\r
1017           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0)\r
1018         )\r
1019         @panel.panel_pictures.build(\r
1020           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1)\r
1021         )\r
1022         sb1 = @panel.speech_balloons.build(\r
1023           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2)\r
1024         )\r
1025         sb1.balloons.build(\r
1026           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
1027         )\r
1028         sb1.speeches.build(\r
1029           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
1030         )\r
1031         sb2 = @panel.speech_balloons.build(\r
1032           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3)\r
1033         )\r
1034         sb2.balloons.build(\r
1035           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
1036         )\r
1037         sb2.speeches.build(\r
1038           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
1039         )\r
1040         r = @panel.validate_child\r
1041         r.should be_true\r
1042       end\r
1043     end\r
1044   end\r
1045   describe '保存に於いて' do\r
1046     context 'つつがなく終わるとき' do\r
1047       it 'idチェックを依頼している' do\r
1048         Panel.should_receive(:validate_elements_id).with(any_args).exactly(1)\r
1049         Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
1050         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1051         r = @panel.store\r
1052       end\r
1053       it '保存を依頼している' do\r
1054         Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
1055         Panel.any_instance.should_receive(:save).with(any_args).exactly(1)\r
1056         Panel.any_instance.stub(:save).with(any_args).and_return(true)\r
1057         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1058         r = @panel.store\r
1059       end\r
1060       it 'Trueを返す' do\r
1061         Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
1062         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1063         r = @panel.store\r
1064         r.should be_true\r
1065       end\r
1066       it 'エラーメッセージがセットされていない' do\r
1067         Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
1068         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1069         r = @panel.store\r
1070         @panel.errors.empty?.should be_true\r
1071       end\r
1072       context '新規のとき' do\r
1073         it 'Trueを返す' do\r
1074           Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
1075           @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1076           r = @panel.store\r
1077           r.should be_true\r
1078         end\r
1079         it '行が追加されている' do\r
1080           Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
1081           @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1082           lambda {\r
1083             r = @panel.store\r
1084           }.should change(Panel, :count)\r
1085         end\r
1086       end\r
1087       context '更新のとき' do\r
1088         it 'Trueを返す' do\r
1089           Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
1090           @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1091           r = @panel.store\r
1092           r.should be_true\r
1093         end\r
1094         it '行が追加されていない' do\r
1095           Panel.stub(:validate_elements_id).with(any_args).and_return(true)\r
1096           @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1097           lambda {\r
1098             r = @panel.store\r
1099           }.should_not change(Panel, :count)\r
1100         end\r
1101       end\r
1102     end\r
1103     context 'idチェックが失敗するとき' do\r
1104       it 'Falseを返す' do\r
1105         Panel.stub(:validate_elements_id).with(any_args).and_return(false)\r
1106         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1107         r = @panel.store\r
1108         r.should be_false\r
1109       end\r
1110       it 'エラーメッセージがセットされている' do\r
1111         Panel.stub(:validate_elements_id).with(any_args).and_return(false)\r
1112         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1113         r = @panel.store\r
1114         @panel.errors.empty?.should be_false\r
1115       end\r
1116       it '行が追加されていない' do\r
1117         Panel.stub(:validate_elements_id).with(any_args).and_return(false)\r
1118         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1119         lambda {\r
1120           r = @panel.store\r
1121         }.should_not change(Panel, :count)\r
1122       end\r
1123     end\r
1124   end\r
1125 end\r