OSDN Git Service

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