OSDN Git Service

#31540:try sort
[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     @admin = 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 = FactoryGirl.create :author, :user_id => @user.id\r
12     @artist = FactoryGirl.create :artist_yas, :author_id => @author.id\r
13     @other_user = FactoryGirl.create( :user_yas)\r
14     @other_author = FactoryGirl.create :author, :user_id => @other_user.id\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       @panel = FactoryGirl.build :panel, :author_id => @author.id\r
25     end\r
26     \r
27     context 'オーソドックスなデータのとき' do\r
28       it '下限データが通る' do\r
29         @panel.width = 1\r
30         @panel.height = 1\r
31         @panel.border = 0\r
32         @panel.x = -99999\r
33         @panel.y = -99999\r
34         @panel.z = 1\r
35         @panel.publish = 0\r
36         @panel.should be_valid\r
37       end\r
38       it '上限データが通る' do\r
39         @panel.width = 99999\r
40         @panel.height = 99999\r
41         @panel.border = 99999\r
42         @panel.x = 99999\r
43         @panel.y = 99999\r
44         @panel.z = 99999\r
45         @panel.publish = 99999\r
46         @panel.should be_valid\r
47       end\r
48     end\r
49     \r
50     context 'widthを検証するとき' do\r
51       it 'nullなら失敗する' do\r
52         @panel.width = nil\r
53         @panel.should_not be_valid\r
54       end\r
55       it '数値でなければ失敗する' do\r
56         @panel.width = 'a'\r
57         @panel.should_not be_valid\r
58       end\r
59       it '0なら失敗する' do\r
60         @panel.width = '0'\r
61         @panel.should_not be_valid\r
62       end\r
63       it '負でも失敗する' do\r
64         @panel.width = -1\r
65         @panel.should_not be_valid\r
66       end\r
67     end\r
68     context 'heightを検証するとき' do\r
69       it 'nullなら失敗する' do\r
70         @panel.height = nil\r
71         @panel.should_not be_valid\r
72       end\r
73       it '数値でなければ失敗する' do\r
74         @panel.height = 'a'\r
75         @panel.should_not be_valid\r
76       end\r
77       it '0なら失敗する' do\r
78         @panel.height = '0'\r
79         @panel.should_not be_valid\r
80       end\r
81       it '負でも失敗する' do\r
82         @panel.height = -1\r
83         @panel.should_not be_valid\r
84       end\r
85     end\r
86     context 'borderを検証するとき' do\r
87       it 'nullなら失敗する' do\r
88         @panel.border = nil\r
89         @panel.should_not be_valid\r
90       end\r
91       it '数値でなければ失敗する' do\r
92         @panel.border = 'a'\r
93         @panel.should_not be_valid\r
94       end\r
95       it '負なら失敗する' do\r
96         @panel.border = '-1'\r
97         @panel.should_not be_valid\r
98       end\r
99       it '0なら通る' do\r
100         @panel.border = 0\r
101         @panel.should be_valid\r
102       end\r
103     end\r
104     context 'xを検証するとき' do\r
105       it '数値でなければ失敗する' do\r
106         @panel.x = 'a'\r
107         @panel.should_not be_valid\r
108       end\r
109       it '0なら通る' do\r
110         @panel.x = '0'\r
111         @panel.should be_valid\r
112       end\r
113       it '負でも通る' do\r
114         @panel.x = -1\r
115         @panel.should be_valid\r
116       end\r
117     end\r
118     context 'yを検証するとき' do\r
119       it '数値でなければ失敗する' do\r
120         @panel.y = 'a'\r
121         @panel.should_not be_valid\r
122       end\r
123       it '0なら通る' do\r
124         @panel.y = '0'\r
125         @panel.should be_valid\r
126       end\r
127       it '負でも通る' do\r
128         @panel.y = -1\r
129         @panel.should be_valid\r
130       end\r
131     end\r
132     context 'zを検証するとき' do\r
133       it '数値でなければ失敗する' do\r
134         @panel.z = 'a'\r
135         @panel.should_not be_valid\r
136       end\r
137       it '0なら失敗する' do\r
138         @panel.z = '0'\r
139         @panel.should_not be_valid\r
140       end\r
141       it '負なら失敗する' do\r
142         @panel.z = -1\r
143         @panel.should_not be_valid\r
144       end\r
145     end\r
146     context 'author_idを検証するとき' do\r
147       it 'nullなら失敗する' do\r
148         @panel.author_id = nil\r
149         @panel.should_not be_valid\r
150       end\r
151       it '数値でなければ失敗する' do\r
152         @panel.author_id = 'a'\r
153         @panel.should_not be_valid\r
154       end\r
155       it '存在する作家でなければ失敗する' do\r
156         @panel.author_id = 0\r
157         @panel.should_not be_valid\r
158       end\r
159     end\r
160     context '公開フラグを検証するとき' do\r
161       it '数値でなければ失敗する' do\r
162         @panel.publish = 'a'\r
163         @panel.should_not be_valid\r
164       end\r
165     end\r
166     context '全体を検証するとき' do\r
167       before do\r
168         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
169       end\r
170     end\r
171   end\r
172   \r
173   describe '文字コード検証に於いて' do\r
174     before do\r
175       @panel = FactoryGirl.build :panel, :author_id => @author.id\r
176     end\r
177     \r
178     context 'captionを検証するとき' do\r
179       it 'Shift JISなら失敗する' do\r
180         @panel.caption = "\x83G\x83r\x83]\x83D"\r
181         lambda{\r
182           @panel.valid_encode\r
183         }.should raise_error(Pettanr::BadRequest)\r
184       end\r
185     end\r
186     \r
187   end\r
188   \r
189   describe 'デフォルト値補充に於いて' do\r
190     before do\r
191       @panel = FactoryGirl.build :panel, :author_id => @author.id\r
192     end\r
193     it 'borderは2を補充する' do\r
194       @panel.border = nil\r
195       @panel.supply_default\r
196       @panel.border.should eq 2\r
197     end\r
198     it 'publishは0を補充する' do\r
199       @panel.publish = nil\r
200       @panel.supply_default\r
201       @panel.publish.should eq 0\r
202     end\r
203   end\r
204   \r
205   describe '上書き補充に於いて' do\r
206     before do\r
207       @panel = FactoryGirl.build :panel, :author_id => @author.id\r
208     end\r
209     context 'author_idを補充' do\r
210       it 'ログイン中の作家idを補充する' do\r
211         @panel.author_id = nil\r
212         @panel.overwrite @author\r
213         @panel.author_id.should eq @author.id\r
214       end\r
215     end\r
216     \r
217   end\r
218   \r
219   describe '所持判定に於いて' do\r
220     before do\r
221       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
222     end\r
223     context '事前チェックする' do\r
224       it '自身にロールリストからの作家取得を依頼している' do\r
225         Panel.should_receive(:get_author_from_roles).with(any_args).exactly(1)\r
226         r = @panel.own?([@author])\r
227       end\r
228     end\r
229     context 'ロール内作家が取得できるとき' do\r
230       before do\r
231       end\r
232       it 'ロール内作家のidが自身の作家idと一致するなら許可する' do\r
233         Panel.stub(:get_author_from_roles).with(any_args).and_return(@author)\r
234         r = @panel.own?([@author])\r
235         r.should be_true\r
236       end\r
237       it 'ロール内作家のidが自身の作家idと一致しないならno' do\r
238         Panel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)\r
239         @panel.own?(@other_author).should be_false\r
240       end\r
241     end\r
242     context 'ロール内作家が取得できないとき' do\r
243       before do\r
244         Panel.stub(:get_author_from_roles).with(any_args).and_return(nil)\r
245       end\r
246       it 'Falseを返す' do\r
247         r = @panel.own?([@author])\r
248         r.should be_false\r
249       end\r
250     end\r
251   end\r
252   \r
253   describe '閲覧許可に於いて' do\r
254     before do\r
255       @comic = FactoryGirl.create :comic, :author_id => @author.id\r
256       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
257       @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id\r
258     end\r
259     context 'オープンモードのとき' do\r
260       before do\r
261         MagicNumber['run_mode'] = 0\r
262       end\r
263       it '自身にゲスト用ロールチェックを問い合わせしている' do\r
264         Panel.any_instance.stub(:guest_role_check).and_return(true)\r
265         Panel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)\r
266         r = @panel.visible?([@author])\r
267       end\r
268       it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do\r
269         Panel.any_instance.stub(:guest_role_check).and_return(false)\r
270         r = @panel.visible?([@author])\r
271         r.should be_false\r
272       end\r
273     end\r
274     context 'クローズドモードのとき' do\r
275       before do\r
276         MagicNumber['run_mode'] = 1\r
277       end\r
278       it '自身に読者用ロールチェックを問い合わせしている' do\r
279         Panel.any_instance.stub(:reader_role_check).and_return(true)\r
280         Panel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)\r
281         r = @panel.visible?([@author])\r
282       end\r
283       it '読者用ロールチェックが失敗したとき、falseを返す' do\r
284         Panel.any_instance.stub(:reader_role_check).and_return(false)\r
285         r = @panel.visible?([@author])\r
286         r.should be_false\r
287       end\r
288     end\r
289     context '事前チェックする' do\r
290       before do\r
291         MagicNumber['run_mode'] = 1\r
292         Panel.any_instance.stub(:reader_role_check).and_return(true)\r
293       end\r
294       it '自身に所持判定を問い合わせしている' do\r
295         Panel.any_instance.stub(:own?).and_return(true)\r
296         Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
297         r = @panel.visible?([@author])\r
298       end\r
299       it '自身に閲覧許可を問い合わせしている' do\r
300         Panel.any_instance.stub(:own?).and_return(false)\r
301         Panel.any_instance.stub(:publish?).and_return(true)\r
302         Panel.any_instance.should_receive(:publish?).with(any_args).exactly(1)\r
303         r = @panel.visible?([@author])\r
304       end\r
305     end\r
306     context 'つつがなく終わるとき' do\r
307       before do\r
308         MagicNumber['run_mode'] = 1\r
309         Panel.any_instance.stub(:reader_role_check).and_return(true)\r
310       end\r
311       it '自分のコマなら許可する' do\r
312         Panel.any_instance.stub(:own?).and_return(true)\r
313         Panel.any_instance.stub(:publish?).and_return(false)\r
314         r = @panel.visible?([@author])\r
315         r.should be_true\r
316       end\r
317       it '他人の非公開コマなら許可しない' do\r
318         Panel.any_instance.stub(:own?).and_return(false)\r
319         Panel.any_instance.stub(:publish?).and_return(false)\r
320         r = @panel.visible?([@author])\r
321         r.should be_false\r
322       end\r
323       it '他人のコマでも公開なら許可する' do\r
324         Panel.any_instance.stub(:own?).and_return(false)\r
325         Panel.any_instance.stub(:publish?).and_return(true)\r
326         r = @panel.visible?([@author])\r
327         r.should be_true\r
328       end\r
329     end\r
330   end\r
331   \r
332   describe '一覧取得に於いて' do\r
333     before do\r
334       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
335     end\r
336     context 'page補正について' do\r
337       it '文字列から数値に変換される' do\r
338         Panel.page('8').should eq 8\r
339       end\r
340       it 'nilの場合は1になる' do\r
341         Panel.page().should eq 1\r
342       end\r
343       it '0以下の場合は1になる' do\r
344         Panel.page('0').should eq 1\r
345       end\r
346     end\r
347     context 'page_size補正について' do\r
348       it '文字列から数値に変換される' do\r
349         Panel.page_size('7').should eq 7\r
350       end\r
351       it 'nilの場合はPanel.default_page_sizeになる' do\r
352         Panel.page_size().should eq Panel.default_page_size\r
353       end\r
354       it '0以下の場合はPanel.default_page_sizeになる' do\r
355         Panel.page_size('0').should eq Panel.default_page_size\r
356       end\r
357       it 'Panel.max_page_sizeを超えた場合はPanel.max_page_sizeになる' do\r
358         Panel.page_size('1000').should eq Panel.max_page_size\r
359       end\r
360     end\r
361     it 'リストを返す' do\r
362       r = Panel.list\r
363       r.should eq [@panel]\r
364     end\r
365     it '時系列で並んでいる' do\r
366       #公開コミックは(他人のコミックであっても)含んでいる\r
367       npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
368       r = Panel.list\r
369       r.should eq [npl, @panel]\r
370     end\r
371     it '非公開のコマ(自分のコマであっても)は含まない' do\r
372       npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0\r
373       r = Panel.list\r
374       r.should eq [@panel]\r
375     end\r
376     context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
377       before do\r
378         @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
379         @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
380         @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
381         @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
382         Panel.stub(:default_page_size).and_return(2)\r
383       end\r
384       it '通常は2件を返す' do\r
385         pl = Panel.list\r
386         pl.should have(2).items \r
387       end\r
388       it 'page=1なら末尾2件を返す' do\r
389         #時系列で並んでいる\r
390         pl = Panel.list 1\r
391         pl.should eq [@npl5, @npl4]\r
392       end\r
393       it 'page=2なら中間2件を返す' do\r
394         pl = Panel.list 2\r
395         pl.should eq [@npl3, @npl2]\r
396       end\r
397       it 'page=3なら先頭1件を返す' do\r
398         pl = Panel.list 3\r
399         pl.should eq [@panel]\r
400       end\r
401     end\r
402   end\r
403   \r
404   describe '自分のコマ一覧取得に於いて' do\r
405     before do\r
406       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
407     end\r
408     it 'リストを返す' do\r
409       pl = Panel.mylist @author\r
410       pl.should eq [@panel]\r
411     end\r
412     it '時系列で並んでいる' do\r
413       npl = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
414       pl = Panel.mylist @author\r
415       pl.should eq [npl, @panel]\r
416     end\r
417     it '他人のコマは公開でも含まない' do\r
418       npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1\r
419       pl = Panel.mylist @author\r
420       pl.should eq [@panel]\r
421     end\r
422     it '自分のコマは非公開でも含んでいる' do\r
423       npl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0, :updated_at => Time.now + 100\r
424       pl = Panel.mylist @author\r
425       pl.should eq [npl, @panel]\r
426     end\r
427     context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
428       before do\r
429         @npl2 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 100\r
430         @npl3 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 200\r
431         @npl4 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 300\r
432         @npl5 = FactoryGirl.create :panel, :author_id => @author.id, :updated_at => Time.now + 400\r
433       end\r
434       it '通常は2件を返す' do\r
435         pl = Panel.mylist @author, 1, 2\r
436         pl.should have(2).items \r
437       end\r
438       it 'page=1なら末尾2件を返す' do\r
439         #時系列で並んでいる\r
440         pl = Panel.mylist @author, 1, 2\r
441         pl.should eq [@npl5, @npl4]\r
442       end\r
443       it 'page=2なら中間2件を返す' do\r
444         pl = Panel.mylist @author, 2, 2\r
445         pl.should eq [@npl3, @npl2]\r
446       end\r
447       it 'page=3なら先頭1件を返す' do\r
448         pl = Panel.mylist @author, 3, 2\r
449         pl.should eq [@panel]\r
450       end\r
451     end\r
452   end\r
453   \r
454   describe '他作家のコマ一覧取得に於いて' do\r
455     before do\r
456       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
457       @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1\r
458     end\r
459     it 'リストを返す' do\r
460       r = Panel.himlist @other_author\r
461       r.should eq [@other_panel]\r
462     end\r
463     it '時系列で並んでいる' do\r
464       npl = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
465       r = Panel.himlist @other_author\r
466       r.should eq [npl, @other_panel]\r
467     end\r
468     it '公開コマに限る' do\r
469       npl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0\r
470       r = Panel.himlist @other_author\r
471       r.should eq [@other_panel]\r
472     end\r
473     context 'DBに5件あって1ページの件数を2件に変えたとして' do\r
474       before do\r
475         @other_panel2 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100\r
476         @other_panel3 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 200\r
477         @other_panel4 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 300\r
478         @other_panel5 = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 400\r
479       end\r
480       it '通常は2件を返す' do\r
481         pl = Panel.himlist @other_author, 1, 2\r
482         pl.should have(2).items \r
483       end\r
484       it 'page=1なら末尾2件を返す' do\r
485         #時系列で並んでいる\r
486         pl = Panel.himlist @other_author, 1, 2\r
487         pl.should eq [@other_panel5, @other_panel4]\r
488       end\r
489       it 'page=2なら中間2件を返す' do\r
490         pl = Panel.himlist @other_author, 2, 2\r
491         pl.should eq [@other_panel3, @other_panel2]\r
492       end\r
493       it 'page=3なら先頭1件を返す' do\r
494         pl = Panel.himlist @other_author, 3, 2\r
495         pl.should eq [@other_panel]\r
496       end\r
497     end\r
498   end\r
499   \r
500   describe 'コマ一覧ページ制御に於いて' do\r
501     before do\r
502       Panel.stub(:count).with(any_args).and_return(100)\r
503     end\r
504     it 'ページ制御を返す' do\r
505       r = Panel.list_paginate \r
506       r.is_a?(Kaminari::PaginatableArray).should be_true\r
507     end\r
508     it 'コマ一覧の取得条件を利用している' do\r
509       Panel.stub(:list_where).with(any_args).and_return('')\r
510       Panel.should_receive(:list_where).with(any_args).exactly(1)\r
511       r = Panel.list_paginate \r
512     end\r
513     it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
514       r = Panel.list_paginate 3, 10\r
515       r.limit_value.should eq 10\r
516       r.offset_value.should eq 20\r
517     end\r
518   end\r
519   \r
520   describe '自分のコマ一覧ページ制御に於いて' do\r
521     before do\r
522       Panel.stub(:count).with(any_args).and_return(100)\r
523     end\r
524     it 'ページ制御を返す' do\r
525       r = Panel.mylist_paginate @author\r
526       r.is_a?(Kaminari::PaginatableArray).should be_true\r
527     end\r
528     it '自分のコマ一覧の取得条件を利用している' do\r
529       Panel.stub(:mylist_where).with(any_args).and_return('')\r
530       Panel.should_receive(:mylist_where).with(any_args).exactly(1)\r
531       r = Panel.mylist_paginate @author\r
532     end\r
533     it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
534       r = Panel.mylist_paginate @author, 3, 10\r
535       r.limit_value.should eq 10\r
536       r.offset_value.should eq 20\r
537     end\r
538   end\r
539   \r
540   describe '他作家のコマ一覧ページ制御に於いて' do\r
541     before do\r
542       Panel.stub(:count).with(any_args).and_return(100)\r
543     end\r
544     it 'ページ制御を返す' do\r
545       r = Panel.himlist_paginate @other_author\r
546       r.is_a?(Kaminari::PaginatableArray).should be_true\r
547     end\r
548     it '他作家のコマ一覧の取得条件を利用している' do\r
549       Panel.stub(:himlist_where).with(any_args).and_return('')\r
550       Panel.should_receive(:himlist_where).with(any_args).exactly(1)\r
551       r = Panel.himlist_paginate @other_author\r
552     end\r
553     it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do\r
554       r = Panel.himlist_paginate @other_author, 3, 10\r
555       r.limit_value.should eq 10\r
556       r.offset_value.should eq 20\r
557     end\r
558   end\r
559   \r
560   describe '一覧取得オプションに於いて' do\r
561     it '5つの項目を含んでいる' do\r
562       r = Panel.list_opt\r
563       r.should have(5).items\r
564     end\r
565     it 'コマ絵を含んでいる' do\r
566       r = Panel.list_opt\r
567       r.has_key?(:panel_pictures).should be_true\r
568     end\r
569       it 'コマ絵は実素材を含んでいる' do\r
570         r = Panel.list_opt\r
571         r[:panel_pictures].has_key?(:picture).should be_true\r
572       end\r
573         it '実素材は絵師を含んでいる' do\r
574           r = Panel.list_opt\r
575           r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
576         end\r
577         it '実素材はライセンスを含んでいる' do\r
578           r = Panel.list_opt\r
579           r[:panel_pictures][:picture].has_key?(:license).should be_true\r
580         end\r
581     it 'フキダシを含んでいる' do\r
582       r = Panel.list_opt\r
583       r.has_key?(:speech_balloons).should be_true\r
584     end\r
585       it 'フキダシはフキダシ枠を含んでいる' do\r
586         r = Panel.list_opt\r
587         r[:speech_balloons].has_key?(:balloon).should be_true\r
588       end\r
589       it 'フキダシはセリフを含んでいる' do\r
590         r = Panel.list_opt\r
591         r[:speech_balloons].has_key?(:speech).should be_true\r
592       end\r
593     it '絵地を含んでいる' do\r
594       r = Panel.list_opt\r
595       r.has_key?(:ground_pictures).should be_true\r
596     end\r
597       it '絵地は実素材を含んでいる' do\r
598         r = Panel.list_opt\r
599         r[:ground_pictures].has_key?(:picture).should be_true\r
600       end\r
601         it '実素材は絵師を含んでいる' do\r
602           r = Panel.list_opt\r
603           r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
604         end\r
605         it '実素材はライセンスを含んでいる' do\r
606           r = Panel.list_opt\r
607           r[:ground_pictures][:picture].has_key?(:license).should be_true\r
608         end\r
609     it '色地を含んでいる' do\r
610       r = Panel.list_opt\r
611       r.has_key?(:ground_colors).should be_true\r
612     end\r
613     it '作家を含んでいる' do\r
614       r = Panel.list_opt\r
615       r.has_key?(:author).should be_true\r
616     end\r
617   end\r
618   describe 'json一覧出力オプションに於いて' do\r
619   end\r
620   \r
621   describe '単体取得に於いて' do\r
622     before do\r
623       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
624     end\r
625     context 'つつがなく終わるとき' do\r
626       it '単体取得オプションを利用している' do\r
627         Panel.stub(:show_opt).with(any_args).and_return({})\r
628         Panel.should_receive(:show_opt).with(any_args).exactly(1)\r
629         r = Panel.show @panel.id, @author\r
630       end\r
631       it '閲覧許可を問い合わせている' do\r
632         Panel.any_instance.stub(:visible?).with(any_args).and_return(true)\r
633         Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)\r
634         r = Panel.show @panel.id, @author\r
635       end\r
636     end\r
637     it '指定のコマを返す' do\r
638       Panel.any_instance.stub(:visible?).and_return(true)\r
639       pl = Panel.show @panel.id, @author\r
640       pl.should eq @panel\r
641     end\r
642     context '閲覧許可が出なかったとき' do\r
643       it '403Forbidden例外を返す' do\r
644         Panel.any_instance.stub(:visible?).and_return(false)\r
645         lambda{\r
646           Panel.show @panel.id, @author\r
647         }.should raise_error(ActiveRecord::Forbidden)\r
648       end\r
649     end\r
650     context '存在しないコマを開こうとしたとき' do\r
651       it '404RecordNotFound例外を返す' do\r
652         lambda{\r
653           Panel.show 110, @author\r
654         }.should raise_error(ActiveRecord::RecordNotFound)\r
655       end\r
656     end\r
657   end\r
658   describe '編集取得に於いて' do\r
659     before do\r
660       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
661     end\r
662     context 'つつがなく終わるとき' do\r
663       it '単体取得オプションを利用している' do\r
664         Panel.stub(:show_opt).with(any_args).and_return({})\r
665         Panel.should_receive(:show_opt).with(any_args).exactly(1)\r
666         r = Panel.edit @panel.id, @author\r
667       end\r
668       it '所持判定を問い合わせている' do\r
669         Panel.any_instance.stub(:own?).with(any_args).and_return(true)\r
670         Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)\r
671         r = Panel.edit @panel.id, @author\r
672       end\r
673     end\r
674     it '指定のコマを返す' do\r
675       Panel.any_instance.stub(:own?).and_return(true)\r
676       pl = Panel.edit @panel.id, @author\r
677       pl.should eq @panel\r
678     end\r
679     context '他人のコマを開こうとしたとき' do\r
680       it '403Forbidden例外を返す' do\r
681         Panel.any_instance.stub(:own?).and_return(false)\r
682         lambda{\r
683           Panel.edit @panel.id, @author\r
684         }.should raise_error(ActiveRecord::Forbidden)\r
685       end\r
686     end\r
687     context '存在しないコマを開こうとしたとき' do\r
688       it '404RecordNotFound例外を返す' do\r
689         lambda{\r
690           Panel.edit 110, @author\r
691         }.should raise_error(ActiveRecord::RecordNotFound)\r
692       end\r
693     end\r
694   end\r
695   describe '単体取得オプションに於いて' do\r
696     it 'includeキーを含んでいる' do\r
697       r = Panel.show_opt\r
698       r.has_key?(:include).should be_true\r
699     end\r
700     it '5つの項目を含んでいる' do\r
701       r = Panel.show_opt[:include]\r
702       r.should have(5).items\r
703     end\r
704     it 'コマ絵を含んでいる' do\r
705       r = Panel.show_opt[:include]\r
706       r.has_key?(:panel_pictures).should be_true\r
707     end\r
708       it 'コマ絵は実素材を含んでいる' do\r
709         r = Panel.show_opt[:include]\r
710         r[:panel_pictures].has_key?(:picture).should be_true\r
711       end\r
712         it '実素材は絵師を含んでいる' do\r
713           r = Panel.show_opt[:include]\r
714           r[:panel_pictures][:picture].has_key?(:artist).should be_true\r
715         end\r
716         it '実素材はライセンスを含んでいる' do\r
717           r = Panel.show_opt[:include]\r
718           r[:panel_pictures][:picture].has_key?(:license).should be_true\r
719         end\r
720     it 'フキダシを含んでいる' do\r
721       r = Panel.show_opt[:include]\r
722       r.has_key?(:speech_balloons).should be_true\r
723     end\r
724       it 'フキダシはフキダシ枠を含んでいる' do\r
725         r = Panel.show_opt[:include]\r
726         r[:speech_balloons].has_key?(:balloon).should be_true\r
727       end\r
728       it 'フキダシはセリフを含んでいる' do\r
729         r = Panel.show_opt[:include]\r
730         r[:speech_balloons].has_key?(:speech).should be_true\r
731       end\r
732     it '絵地を含んでいる' do\r
733       r = Panel.show_opt[:include]\r
734       r.has_key?(:ground_pictures).should be_true\r
735     end\r
736       it '絵地は実素材を含んでいる' do\r
737         r = Panel.show_opt[:include]\r
738         r[:ground_pictures].has_key?(:picture).should be_true\r
739       end\r
740         it '実素材は絵師を含んでいる' do\r
741           r = Panel.show_opt[:include]\r
742           r[:ground_pictures][:picture].has_key?(:artist).should be_true\r
743         end\r
744         it '実素材はライセンスを含んでいる' do\r
745           r = Panel.show_opt[:include]\r
746           r[:ground_pictures][:picture].has_key?(:license).should be_true\r
747         end\r
748     it '色地を含んでいる' do\r
749       r = Panel.show_opt[:include]\r
750       r.has_key?(:ground_colors).should be_true\r
751     end\r
752     it '作家を含んでいる' do\r
753       r = Panel.show_opt[:include]\r
754       r.has_key?(:author).should be_true\r
755     end\r
756   end\r
757   describe 'json単体出力オプションに於いて' do\r
758   end\r
759   describe 'コマ部品集合に於いて' do\r
760     before do\r
761       #コマを作成しておく。\r
762       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
763       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
764       @sb = @panel.speech_balloons.create(\r
765         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
766       )\r
767       @gc = @panel.ground_colors.create(\r
768         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
769       )\r
770       @gp = @panel.ground_pictures.create(\r
771         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
772       )\r
773       @panel.reload\r
774     end\r
775     it 'リストを返している' do\r
776       r = @panel.parts_element\r
777       r.is_a?(Array).should be_true\r
778     end\r
779     it 'コマ絵とフキダシと絵地と色地を合わせている' do\r
780       r = @panel.parts_element\r
781       r.include?(@pp).should be_true\r
782       r.include?(@sb).should be_true\r
783       r.include?(@gc).should be_true\r
784       r.include?(@gp).should be_true\r
785     end\r
786   end\r
787   describe 'コマ部品に於いて' do\r
788     before do\r
789       #コマを作成しておく。\r
790       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
791       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
792       @sb = @panel.speech_balloons.create(\r
793         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
794       )\r
795       @gc = @panel.ground_colors.create(\r
796         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
797       )\r
798       @gp = @panel.ground_pictures.create(\r
799         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
800       )\r
801       @panel.reload\r
802     end\r
803     context 'つつがなく終わるとき' do\r
804       it 'コマ部品集合を利用している' do\r
805         Panel.any_instance.stub(:parts_element).with(any_args).and_return([])\r
806         Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)\r
807         r = @panel.parts\r
808       end\r
809     end\r
810     it 'リストを返している' do\r
811       r = @panel.parts\r
812       r.is_a?(Array).should be_true\r
813       r.size.should eq 4\r
814     end\r
815     it 'tでソートしている' do\r
816       r = @panel.parts\r
817       r[0].should eq @sb\r
818       r[1].should eq @pp\r
819       r[2].should eq @gc\r
820       r[3].should eq @gp\r
821     end\r
822     context 'さらに末尾にフキダシを追加したとき' do\r
823       before do\r
824         @sb2 = @panel.speech_balloons.create(\r
825           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4)\r
826         )\r
827         @panel.reload\r
828       end\r
829       it 'tでソートしている' do\r
830         r = @panel.parts\r
831         r[0].should eq @sb\r
832         r[1].should eq @pp\r
833         r[2].should eq @gc\r
834         r[3].should eq @gp\r
835         r[4].should eq @sb2\r
836       end\r
837     end\r
838   end\r
839   \r
840   describe 'z順コマ部品に於いて' do\r
841     before do\r
842       #コマを作成しておく。\r
843       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
844       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :z => 2, :width => @p.width, :height => @p.height\r
845       @sb = @panel.speech_balloons.create(\r
846         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 1, :z => 1)\r
847       )\r
848       @gc = @panel.ground_colors.create(\r
849         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2, :z => 3)\r
850       )\r
851       @gp = @panel.ground_pictures.create(\r
852         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3, :z => 4)\r
853       )\r
854       @panel.reload\r
855     end\r
856     context 'つつがなく終わるとき' do\r
857       it 'コマ部品集合を利用している' do\r
858         Panel.any_instance.stub(:parts_element).with(any_args).and_return([])\r
859         Panel.any_instance.should_receive(:parts_element).with(any_args).exactly(1)\r
860         r = @panel.zorderd_elements\r
861       end\r
862     end\r
863     it 'リストを返している' do\r
864       r = @panel.zorderd_elements\r
865       r.is_a?(Array).should be_true\r
866       r.size.should eq 4\r
867     end\r
868     it 'zでオフセットを0でソートしている' do\r
869       r = @panel.zorderd_elements\r
870       r[0].should eq @sb\r
871       r[1].should eq @pp\r
872       r[2].should eq @gc\r
873       r[3].should eq @gp\r
874     end\r
875     context 'さらに末尾にフキダシを追加したとき' do\r
876       before do\r
877         @sb2 = @panel.speech_balloons.create(\r
878           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 5)\r
879         )\r
880         @panel.reload\r
881       end\r
882       it 'zでソートしている' do\r
883         r = @panel.zorderd_elements\r
884         r[0].should eq @sb\r
885         r[1].should eq @pp\r
886         r[2].should eq @gc\r
887         r[3].should eq @gp\r
888         r[4].should eq @sb2\r
889       end\r
890     end\r
891   end\r
892   describe 'コマ要素に於いて' do\r
893     before do\r
894       #コマを作成しておく。\r
895       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
896       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
897       @sb = @panel.speech_balloons.create(\r
898         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
899       )\r
900       @gc = @panel.ground_colors.create(\r
901         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
902       )\r
903       @gp = @panel.ground_pictures.create(\r
904         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
905       )\r
906       @panel.reload\r
907     end\r
908     context 'つつがなく終わるとき' do\r
909       it 'コマ部品を利用している' do\r
910         Panel.any_instance.stub(:parts).with(any_args).and_return([])\r
911         Panel.any_instance.should_receive(:parts).with(any_args).exactly(1)\r
912         r = @panel.panel_elements\r
913       end\r
914     end\r
915     it 'リストを返している' do\r
916       r = @panel.panel_elements\r
917       r.is_a?(Array).should be_true\r
918     end\r
919     it 'tでソートしている' do\r
920       r = @panel.panel_elements\r
921       r[0].should eq @sb\r
922       r[1].should eq @pp\r
923       r[2].should eq @gc\r
924       r[3].should eq @gp\r
925     end\r
926   end\r
927   describe 'コマ要素のjson出力に於いて' do\r
928     before do\r
929       #コマを作成しておく。\r
930       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
931       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
932       @sb = @panel.speech_balloons.create(\r
933         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
934       )\r
935       @gc = @panel.ground_colors.create(\r
936         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
937       )\r
938       @gp = @panel.ground_pictures.create(\r
939         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
940       )\r
941       @panel.reload\r
942     end\r
943     context 'つつがなく終わるとき' do\r
944       before do\r
945         Panel.stub(:elm_json_opt).with(@pp).and_return({})\r
946         Panel.stub(:elm_json_opt).with(@sb).and_return({})\r
947         Panel.stub(:elm_json_opt).with(@gp).and_return({})\r
948         Panel.stub(:elm_json_opt).with(@gc).and_return({})\r
949       end\r
950       it 'コマ要素のjson出力オプションにコマ絵json出力オプションを依頼している' do\r
951         Panel.should_receive(:elm_json_opt).with(@pp).exactly(1)\r
952         r = @panel.elements\r
953       end\r
954       it 'コマ要素のjson出力オプションにフキダシjson出力オプションを依頼している' do\r
955         Panel.should_receive(:elm_json_opt).with(@sb).exactly(1)\r
956         r = @panel.elements\r
957       end\r
958       it 'コマ要素のjson出力オプションに絵地json出力オプションを依頼している' do\r
959         Panel.should_receive(:elm_json_opt).with(@gp).exactly(1)\r
960         r = @panel.elements\r
961       end\r
962       it 'コマ要素のjson出力オプションに色地json出力オプションを依頼している' do\r
963         Panel.should_receive(:elm_json_opt).with(@gc).exactly(1)\r
964         r = @panel.elements\r
965       end\r
966     end\r
967     it 'リストを返している' do\r
968       r = @panel.elements\r
969       r.is_a?(Array).should be_true\r
970     end\r
971   end\r
972   describe 'コマのjson出力に於いて' do\r
973     before do\r
974       #コマを作成しておく。\r
975       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
976       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
977       @sb = @panel.speech_balloons.create(\r
978         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
979       )\r
980       @sb.create_balloon(\r
981         FactoryGirl.attributes_for(:balloon, :speech_balloon_id => @sb.id)\r
982       )\r
983       @sb.create_speech(\r
984         FactoryGirl.attributes_for(:speech, :speech_balloon_id => @sb.id)\r
985       )\r
986       @gc = @panel.ground_colors.create(\r
987         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
988       )\r
989       @gp = @panel.ground_pictures.create(\r
990         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 3)\r
991       )\r
992       @panel.reload\r
993     end\r
994     context 'つつがなく終わるとき' do\r
995       before do\r
996         Panel.any_instance.stub(:elements).with(any_args).and_return({})\r
997       end\r
998       it 'コマ要素のjson出力を依頼している' do\r
999         Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)\r
1000         r = @panel.panel_elements_as_json\r
1001       end\r
1002     end\r
1003     it 'json textを返している' do\r
1004       r = JSON.parse @panel.panel_elements_as_json\r
1005       r.is_a?(Hash).should be_true\r
1006     end\r
1007     it 'author,コマ要素を含んでいる' do\r
1008       r = JSON.parse @panel.panel_elements_as_json\r
1009       r.has_key?('author').should be_true\r
1010       r.has_key?('elements').should be_true\r
1011       #t:0\r
1012       sb = r['elements'].first\r
1013       sb.has_key?('classname').should be_true\r
1014       sb.has_key?('balloon').should be_true\r
1015       sb.has_key?('speech').should be_true\r
1016       #t:1\r
1017     end\r
1018   end\r
1019   describe 'コマリストのjson出力に於いて' do\r
1020     before do\r
1021       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1022       Panel.any_instance.stub(:panel_elements_as_json).with(any_args).and_return('{"p": 5}')\r
1023     end\r
1024     context 'つつがなく終わるとき' do\r
1025       it 'コマのjson出力を依頼している' do\r
1026         Panel.any_instance.should_receive(:panel_elements_as_json).with(any_args).exactly(1)\r
1027         r = Panel.list_as_json_text [@panel]\r
1028       end\r
1029     end\r
1030     it 'json textを返している' do\r
1031       r = Panel.list_as_json_text [@panel]\r
1032       j = JSON.parse r\r
1033       j.is_a?(Array).should be_true\r
1034     end\r
1035     it 'コマを含んでいる' do\r
1036       r = Panel.list_as_json_text [@panel]\r
1037       j = JSON.parse r\r
1038       j.first.has_key?('p').should be_true\r
1039     end\r
1040   end\r
1041   \r
1042   describe 'ライセンス素材に於いて' do\r
1043     before do\r
1044       #コマを作成しておく。\r
1045       @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id\r
1046       @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id\r
1047       @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id\r
1048       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1049       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height, :picture_id => @p.id\r
1050       @sb = @panel.speech_balloons.create(\r
1051         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
1052       )\r
1053       @gc = @panel.ground_colors.create(\r
1054         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 2)\r
1055       )\r
1056       @gp = @panel.ground_pictures.create(\r
1057         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p2.id, :t => 3)\r
1058       )\r
1059       @panel.reload\r
1060     end\r
1061     context '事前チェック' do\r
1062     end\r
1063     context 'つつがなく終わるとき' do\r
1064     end\r
1065     it '連想配列(値は実素材、キーは実素材id)を返している' do\r
1066       r = @panel.licensed_pictures\r
1067       r.is_a?(Hash).should be_true\r
1068       r.should have(2).items\r
1069       r[@pp.picture_id].should eq @p\r
1070       r[@gp.picture_id].should eq @p2\r
1071     end\r
1072   end\r
1073   \r
1074   describe '検証値収集に於いて' do\r
1075     context 'つつがなく終わるとき' do\r
1076       it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do\r
1077         elements = [[{:panel_id => 1, :a => 'a'}, {:panel_id => 2, :a => 'a'}], \r
1078           [{:panel_id => 3, :a => 'a'}, {:panel_id => 4, :a => 'a'}]]\r
1079         r = Panel.collect_element_value elements, :panel_id\r
1080         r.should eq [1, 2, 3, 4]\r
1081       end\r
1082       it '第一パラメータで指定された配列中から第二引数のカラム値を収集している' do\r
1083         elements = [[{:t => 1, :a => 'a'}, {:t => 2, :a => 'a'}], \r
1084           [{:t => 3, :a => 'a'}, {:t => 0, :a => 'a'}]]\r
1085         r = Panel.collect_element_value elements, :t\r
1086         r.should eq [1, 2, 3, 0]\r
1087       end\r
1088     end\r
1089   end\r
1090   describe 'シリアライズチェックに於いて' do\r
1091     context 'つつがなく終わるとき' do\r
1092       it '0からシリアライズされているならTrueを返す' do\r
1093         r = Panel.validate_serial [0, 1, 2]\r
1094         r.should be_true\r
1095       end\r
1096       it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
1097         r = Panel.validate_serial [0, 2, 1]\r
1098         r.should be_true\r
1099       end\r
1100       it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do\r
1101         r = Panel.validate_serial [ 2, 1, 4, 3, 0]\r
1102         r.should be_true\r
1103       end\r
1104     end\r
1105     context 'オフセットが1のとき' do\r
1106       it '0からシリアライズされているならFalseを返す' do\r
1107         r = Panel.validate_serial [0, 1, 2], 1\r
1108         r.should be_false\r
1109       end\r
1110       it '1からシリアライズされているならTrueを返す' do\r
1111         r = Panel.validate_serial [1, 2, 3], 1\r
1112         r.should be_true\r
1113       end\r
1114     end\r
1115     context '異常なとき' do\r
1116       it '0から始まらないならFalseを返す' do\r
1117         r = Panel.validate_serial [1, 2, 3]\r
1118         r.should be_false\r
1119       end\r
1120       it '連続していないならFalseを返す' do\r
1121         r = Panel.validate_serial [0, 1, 2, 4]\r
1122         r.should be_false\r
1123       end\r
1124       it '連続していないならFalseを返す' do\r
1125         r = Panel.validate_serial [0, 1, 2, 4, 5]\r
1126         r.should be_false\r
1127       end\r
1128     end\r
1129   end\r
1130   describe 'シリアライズチェック単体に於いて' do\r
1131     before do\r
1132     end\r
1133     context 'つつがなく終わるとき' do\r
1134       it '検証値収集を依頼している' do\r
1135         Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
1136         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
1137         Panel.stub(:validate_serial).with(any_args).and_return(true)\r
1138         r = Panel.validate_element_serial [], :t\r
1139       end\r
1140       it 'シリアライズチェック依頼している' do\r
1141         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
1142         Panel.should_receive(:validate_serial).with(any_args).exactly(1)\r
1143         Panel.stub(:validate_serial).with(any_args).and_return(true)\r
1144         r = Panel.validate_element_serial [], :t\r
1145       end\r
1146     end\r
1147   end\r
1148   describe '従属データの検証に於いて' do\r
1149     context 'つつがなく終わるとき' do\r
1150       it 'trueを返している' do\r
1151         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1152         @panel.panel_pictures.build(\r
1153           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
1154         )\r
1155         @panel.panel_pictures.build(\r
1156           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)\r
1157         )\r
1158         sb1 = @panel.speech_balloons.build(\r
1159           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
1160         )\r
1161         sb1.build_balloon(\r
1162           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
1163         )\r
1164         sb1.build_speech(\r
1165           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
1166         )\r
1167         sb2 = @panel.speech_balloons.build(\r
1168           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)\r
1169         )\r
1170         sb2.build_balloon(\r
1171           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
1172         )\r
1173         sb2.build_speech(\r
1174           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
1175         )\r
1176         @gc = @panel.ground_colors.build(\r
1177           FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
1178         )\r
1179         @gp = @panel.ground_pictures.build(\r
1180           FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
1181         )\r
1182         r = @panel.validate_child\r
1183         r.should be_true\r
1184       end\r
1185     end\r
1186     context 'tシリアライズされていないとき' do\r
1187       it 'falseを返している' do\r
1188         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1189         @panel.panel_pictures.build(\r
1190           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
1191         )\r
1192         @panel.panel_pictures.build(\r
1193           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 1+1)\r
1194         )\r
1195         sb1 = @panel.speech_balloons.build(\r
1196           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
1197         )\r
1198         sb1.build_balloon(\r
1199           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
1200         )\r
1201         sb1.build_speech(\r
1202           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
1203         )\r
1204         sb2 = @panel.speech_balloons.build(\r
1205           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 4, :z => 3+1)\r
1206         )\r
1207         sb2.build_balloon(\r
1208           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
1209         )\r
1210         sb2.build_speech(\r
1211           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
1212         )\r
1213         @gc = @panel.ground_colors.build(\r
1214           FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
1215         )\r
1216         @gp = @panel.ground_pictures.build(\r
1217           FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
1218         )\r
1219         r = @panel.validate_child\r
1220         r.should be_false\r
1221       end\r
1222     end\r
1223     context 'zシリアライズされていないとき' do\r
1224       it 'falseを返している' do\r
1225         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1226         @panel.panel_pictures.build(\r
1227           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 0, :z => 0+1)\r
1228         )\r
1229         @panel.panel_pictures.build(\r
1230           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 1, :z => 0+1)\r
1231         )\r
1232         sb1 = @panel.speech_balloons.build(\r
1233           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 2, :z => 2+1)\r
1234         )\r
1235         sb1.build_balloon(\r
1236           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
1237         )\r
1238         sb1.build_speech(\r
1239           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
1240         )\r
1241         sb2 = @panel.speech_balloons.build(\r
1242           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 3, :z => 3+1)\r
1243         )\r
1244         sb2.build_balloon(\r
1245           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
1246         )\r
1247         sb2.build_speech(\r
1248           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
1249         )\r
1250         @gc = @panel.ground_colors.build(\r
1251           FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :t => 4, :z => 4+1)\r
1252         )\r
1253         @gp = @panel.ground_pictures.build(\r
1254           FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => 5, :z => 5+1)\r
1255         )\r
1256         r = @panel.validate_child\r
1257         r.should be_false\r
1258       end\r
1259     end\r
1260   end\r
1261   describe '保存に於いて' do\r
1262     before do\r
1263       @attr = FactoryGirl.attributes_for :panel\r
1264       @panel = Panel.new\r
1265       @panel.supply_default\r
1266     end\r
1267     context 'つつがなく終わるとき' do\r
1268       before do\r
1269         Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)\r
1270         Panel.any_instance.stub(:save).with(any_args).and_return(true)\r
1271       end\r
1272       it 'コマモデルに上書き補充を依頼している' do\r
1273         Panel.any_instance.should_receive(:overwrite).exactly(1)\r
1274         r = @panel.store @attr, @author\r
1275       end\r
1276       it '保存を依頼している' do\r
1277         Panel.any_instance.should_receive(:save).with(any_args).exactly(1)\r
1278         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1279         r = @panel.store @attr, @author\r
1280       end\r
1281       it '従属データの検証を依頼している' do\r
1282         Panel.any_instance.should_receive(:validate_child).with(any_args).exactly(1)\r
1283         r = @panel.store @attr, @author\r
1284       end\r
1285     end\r
1286     context 'つつがなく終わるとき' do\r
1287       before do\r
1288         Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)\r
1289       end\r
1290       it 'Trueを返す' do\r
1291         r = @panel.store @attr, @author\r
1292         r.should be_true\r
1293       end\r
1294       it '行が追加されている' do\r
1295         Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)\r
1296         lambda {\r
1297           r = @panel.store @attr, @author\r
1298         }.should change(Panel, :count)\r
1299       end\r
1300     end\r
1301     context '不正なjsonデータのとき' do\r
1302       before do\r
1303       end\r
1304       it 'エラーメッセージがセットされている' do\r
1305         r = @panel.store false, @author\r
1306         @panel.errors[:base].should_not be_blank\r
1307       end\r
1308     end\r
1309     context '従属データの検証に失敗したとき' do\r
1310       before do\r
1311         Panel.any_instance.stub(:save).with(any_args).and_return(true)\r
1312         Panel.any_instance.stub(:validate_child).with(any_args).and_return(false)\r
1313       end\r
1314       it 'エラーメッセージがセットされている' do\r
1315         r = @panel.store @attr, @author\r
1316         @panel.errors[:base].should_not be_blank\r
1317       end\r
1318     end\r
1319     context 'カラム値がFalseしたとき' do\r
1320       before do\r
1321         Panel.any_instance.stub(:validate_child).with(any_args).and_return(true)\r
1322       end\r
1323       it 'エラーメッセージがセットされている' do\r
1324         r = @panel.store false, @author\r
1325         @panel.errors.should_not be_empty\r
1326       end\r
1327     end\r
1328   end\r
1329   \r
1330   describe '削除に於いて' do\r
1331     before do\r
1332       @comic = FactoryGirl.create :comic, :author_id => @author.id\r
1333       @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1\r
1334       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
1335       @sb = @panel.speech_balloons.create(\r
1336         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
1337       )\r
1338       @gc = @panel.ground_colors.create(\r
1339         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)\r
1340       )\r
1341       @gp = @panel.ground_pictures.create(\r
1342         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
1343       )\r
1344     end\r
1345     context 'つつがなく終わるとき' do\r
1346       it '自身を削除する' do\r
1347         lambda {\r
1348           r = @panel.destroy_with_elements\r
1349         }.should change(Panel, :count).by(-1)\r
1350         lambda {\r
1351           r = Panel.find @panel.id\r
1352         }.should raise_error\r
1353       end\r
1354       it '自身にリンクしているコマ要素をすべて削除する' do\r
1355         lambda {\r
1356           r = @panel.destroy_with_elements\r
1357         }.should change(PanelPicture, :count).by(-1)\r
1358         lambda {\r
1359           r = PanelPicture.find @pp.id\r
1360         }.should raise_error \r
1361       end\r
1362       it '自身にリンクしているコマ要素をすべて削除する' do\r
1363         lambda {\r
1364           r = @panel.destroy_with_elements\r
1365         }.should change(GroundPicture, :count).by(-1)\r
1366         lambda {\r
1367           r = GroundPicture.find @gp.id\r
1368         }.should raise_error \r
1369       end\r
1370       it 'Trueを返す' do\r
1371         r = @panel.destroy_with_elements\r
1372         r.should be_true\r
1373       end\r
1374     end\r
1375     context '削除に失敗したとき' do\r
1376       before do\r
1377         PanelPicture.any_instance.stub(:destroy).with(any_args).and_return(false)\r
1378       end\r
1379       it 'Falseを返す' do\r
1380         r = @panel.destroy_with_elements\r
1381         r.should be_false\r
1382       end\r
1383       it 'ロールバックしている' do\r
1384         lambda {\r
1385           r = @panel.destroy_with_elements\r
1386         }.should_not change(Panel, :count)\r
1387         lambda {\r
1388           r = @panel.destroy_with_elements\r
1389         }.should_not change(PanelPicture, :count)\r
1390       end\r
1391     end\r
1392   end\r
1393 =begin\r
1394   describe 'id挿げ替え防止確認に於いて' do\r
1395     before do\r
1396       #コマを作成しておく。\r
1397       @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1398       @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height\r
1399       @sb = @panel.speech_balloons.create(\r
1400         FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)\r
1401       )\r
1402       @gc = @panel.ground_colors.create(\r
1403         FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)\r
1404       )\r
1405       @gp = @panel.ground_pictures.create(\r
1406         FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)\r
1407       )\r
1408       @pc = @panel.panel_colors.create(\r
1409         FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)\r
1410       )\r
1411       @panel.reload\r
1412     end\r
1413     it 'author,コマ要素を含んでいる' do\r
1414       @panel2 = FactoryGirl.create :panel, :author_id => @author.id\r
1415       @panel2.panel_pictures.create(\r
1416         FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height)\r
1417       )\r
1418       @panel2.save!\r
1419     end\r
1420   end\r
1421   describe 'id一致チェックに於いて' do\r
1422     #parent.idがNilのときはすべてNil。数値のときは全一致\r
1423     context '親が既存(idが数値)のとき' do\r
1424       it 'すべてid一致するときTrueを返す' do\r
1425         r = Panel.validate_id [1, 1, 1, 1], 1\r
1426         r.should be_true\r
1427       end\r
1428       it 'idが一致する中にNilが混じってもTrueを返す' do\r
1429         r = Panel.validate_id [1, 1, 1, 1, nil], 1\r
1430         r.should be_true\r
1431       end\r
1432       it 'すべて数値でも一致しないときFalseを返す' do\r
1433         r = Panel.validate_id [1, 1, 1, 1, 2], 1\r
1434         r.should be_false\r
1435       end\r
1436       it '数値とNilが混ざってもIDが一致しないときFalseを返す' do\r
1437         r = Panel.validate_id [1, 1, nil, 2], 1\r
1438         r.should be_false\r
1439       end\r
1440     end\r
1441     context '親が新規(idがNil)のとき' do\r
1442       it 'すべてNilはTrueを返す' do\r
1443         r = Panel.validate_id [ nil,nil,nil,nil], nil\r
1444         r.should be_true\r
1445       end\r
1446       it 'すべてnilでなければFalseを返す' do\r
1447         r = Panel.validate_id [nil,nil,nil,nil, 2], nil\r
1448         r.should be_false\r
1449       end\r
1450     end\r
1451   end\r
1452   describe 'idチェック単体に於いて' do\r
1453     before do\r
1454 #      @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1\r
1455     end\r
1456     context 'つつがなく終わるとき' do\r
1457       it 'idを収集依頼している' do\r
1458         Panel.should_receive(:collect_element_value).with(any_args).exactly(1)\r
1459         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
1460         Panel.stub(:validate_id).with(any_args).and_return(true)\r
1461         r = Panel.validate_element_id [], :panel_id, nil\r
1462       end\r
1463       it '収集したidを一致チェック依頼している' do\r
1464         Panel.should_receive(:validate_id).with(any_args).exactly(1)\r
1465         Panel.stub(:collect_element_value).with(any_args).and_return([])\r
1466         Panel.stub(:validate_id).with(any_args).and_return(true)\r
1467         r = Panel.validate_element_id [], :panel_id, nil\r
1468       end\r
1469     end\r
1470     #実データでチェック\r
1471     #依頼チェックだけでは不安なので最低限のチェックを\r
1472     context 'コマ新規のとき' do\r
1473       it 'コマ絵で正常通過している' do\r
1474         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1475         @panel.panel_pictures.build(\r
1476           FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)\r
1477         )\r
1478         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
1479         r.should be_true\r
1480       end\r
1481       it 'フキダシで正常通過している' do\r
1482         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1483         @panel.speech_balloons.build(\r
1484           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
1485         )\r
1486         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
1487         r.should be_true\r
1488       end\r
1489     end\r
1490     context 'コマ既存のとき' do\r
1491       it 'コマ絵で正常通過している' do\r
1492         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1493         @panel.panel_pictures.build(\r
1494           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)\r
1495         )\r
1496         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
1497         r.should be_true\r
1498       end\r
1499       it 'フキダシで正常通過している' do\r
1500         @panel = FactoryGirl.create :panel, :author_id => @author.id\r
1501         @panel.speech_balloons.build(\r
1502           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
1503         )\r
1504         r = Panel.validate_element_id [@panel.panel_pictures, @panel.speech_balloons], :panel_id, @panel.id\r
1505         r.should be_true\r
1506       end\r
1507     end\r
1508     context 'フキダシ新規のとき' do\r
1509       it 'バルーンで正常通過している' do\r
1510         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1511         @panel.speech_balloons.build(\r
1512           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
1513         )\r
1514         @panel.speech_balloons.first.balloons.build(\r
1515           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)\r
1516         )\r
1517         r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id\r
1518         r.should be_true\r
1519       end\r
1520       it 'セリフで正常通過している' do\r
1521         @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1522         @panel.speech_balloons.build(\r
1523           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
1524         )\r
1525         @panel.speech_balloons.first.speeches.build(\r
1526           FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)\r
1527         )\r
1528         r = Panel.validate_element_id [@panel.speech_balloons.first.speeches, @panel.speech_balloons.first.balloons], :speech_balloon_id, @panel.speech_balloons.first.id\r
1529         r.should be_true\r
1530       end\r
1531     end\r
1532   end\r
1533   describe 'idチェックリスト生成に於いて' do\r
1534     before do\r
1535       @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1536     end\r
1537     context 'つつがなく終わるとき' do\r
1538       it 'コマ部品とフキダシ部品のトータル2を返す' do\r
1539         @panel.panel_pictures.build(\r
1540           FactoryGirl.attributes_for(:panel_picture, :panel_id => nil, :picture_id => @p.id, :t => nil)\r
1541         )\r
1542         @panel.speech_balloons.build(\r
1543           FactoryGirl.attributes_for(:speech_balloon, :panel_id => nil, :speech_balloon_template_id => @sbt.id)\r
1544         )\r
1545         @panel.speech_balloons.first.balloons.build(\r
1546           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => nil)\r
1547         )\r
1548         @panel.speech_balloons.first.speeches.build(\r
1549           FactoryGirl.attributes_for(:speech, :speech_balloon_id => nil)\r
1550         )\r
1551         r = @panel.validate_id_list\r
1552         r.should have(2).items\r
1553       end\r
1554       it 'コマ部品とフキダシ部品[複数:2]のケースでトータル3を返す' do\r
1555         @panel.panel_pictures.build(\r
1556           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)\r
1557         )\r
1558         sb1 = @panel.speech_balloons.build(\r
1559           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
1560         )\r
1561         sb1.balloons.build(\r
1562           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
1563         )\r
1564         sb1.speeches.build(\r
1565           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
1566         )\r
1567         sb2 = @panel.speech_balloons.build(\r
1568           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
1569         )\r
1570         sb2.balloons.build(\r
1571           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb2.id)\r
1572         )\r
1573         sb2.speeches.build(\r
1574           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb2.id)\r
1575         )\r
1576         r = @panel.validate_id_list\r
1577         r.should have(3).items\r
1578       end\r
1579     end\r
1580   end\r
1581   describe 'idチェック複合に於いて' do\r
1582     before do\r
1583       @panel = FactoryGirl.build :panel, :author_id => @author.id\r
1584     end\r
1585     context 'つつがなく終わるとき' do\r
1586       it 'コマ部品とフキダシ部品の二回チェック依頼している' do\r
1587         Panel.should_receive(:validate_element_id).with(any_args).exactly(2)\r
1588         Panel.stub(:validate_element_id).with(any_args).and_return(true)\r
1589         @panel.panel_pictures.build(\r
1590           FactoryGirl.attributes_for(:panel_picture, :panel_id => @panel.id, :picture_id => @p.id, :t => nil)\r
1591         )\r
1592         sb1 = @panel.speech_balloons.build(\r
1593           FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id)\r
1594         )\r
1595         sb1.balloons.build(\r
1596           FactoryGirl.attributes_for(:balloon, :speech_balloon_id => sb1.id)\r
1597         )\r
1598         sb1.speeches.build(\r
1599           FactoryGirl.attributes_for(:speech, :speech_balloon_id => sb1.id)\r
1600         )\r
1601         r = Panel.validate_elements_id(@panel.validate_id_list)\r
1602       end\r
1603     end\r
1604   end\r
1605 =end\r
1606 end\r