OSDN Git Service

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