1 # -*- encoding: utf-8 -*-
6 SpeechBalloonTemplate.delete_all
7 @admin = FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 SpeechBalloonTemplate.delete_all
12 @speech_balloon_template = FactoryGirl.create(:speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}')
13 @writing_format = FactoryGirl.create :writing_format
14 @user = FactoryGirl.create( :user_yas)
15 @author = FactoryGirl.create :author, :user_id => @user.id
16 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
17 @other_user = FactoryGirl.create( :user_yas)
18 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
19 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
20 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
21 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
26 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
27 @panel = FactoryGirl.create :panel, :author_id => @author.id
28 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
31 context 'オーソドックスなデータのとき' do
33 @sheet_panel.x = -99999
34 @sheet_panel.y = -99999
37 @sheet_panel.should be_valid
40 @sheet_panel.x = 99999
41 @sheet_panel.y = 99999
42 @sheet_panel.z = 99999
43 @sheet_panel.t = 99999
44 @sheet_panel.should be_valid
48 context 'sheet_idを検証するとき' do
50 @sheet_panel.sheet_id = nil
51 @sheet_panel.should_not be_valid
54 @sheet_panel.sheet_id = 'a'
55 @sheet_panel.should_not be_valid
57 it '存在する用紙でなければ失敗する' do
58 @sheet_panel.sheet_id = 0
59 @sheet_panel.should_not be_valid
63 context 'panel_idを検証するとき' do
65 @sheet_panel.panel_id = nil
66 @sheet_panel.should_not be_valid
69 @sheet_panel.panel_id = 'a'
70 @sheet_panel.should_not be_valid
72 it '存在するコマでなければ失敗する' do
73 @sheet_panel.panel_id = 0
74 @sheet_panel.should_not be_valid
81 @sheet_panel.should_not be_valid
85 @sheet_panel.should_not be_valid
89 @sheet_panel.should be_valid
93 @sheet_panel.should be_valid
99 @sheet_panel.should_not be_valid
103 @sheet_panel.should_not be_valid
107 @sheet_panel.should be_valid
111 @sheet_panel.should be_valid
114 context 'zを検証するとき' do
117 @sheet_panel.should_not be_valid
121 @sheet_panel.should_not be_valid
125 @sheet_panel.should_not be_valid
129 @sheet_panel.should_not be_valid
132 context 'tを検証するとき' do
135 @sheet_panel.should_not be_valid
139 @sheet_panel.should_not be_valid
143 @sheet_panel.should_not be_valid
147 context 'author_idを検証するとき' do
149 @sheet_panel.author_id = nil
150 @sheet_panel.should_not be_valid
153 @sheet_panel.author_id = 'a'
154 @sheet_panel.should_not be_valid
156 it '存在する作家でなければ失敗する' do
157 @sheet_panel.author_id = 0
158 @sheet_panel.should_not be_valid
161 context '全体を検証するとき' do
165 describe 'デフォルト値補充に於いて' do
167 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
168 @panel = FactoryGirl.create :panel, :author_id => @author.id
171 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
173 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id
174 @sheet_panel.supply_default
175 @sheet_panel.t.should be_nil
180 describe '上書き補充に於いて' do
182 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
183 @panel = FactoryGirl.create :panel, :author_id => @author.id
186 context 'author_idを補充' do
187 it '問答無用でauthor_idを補充する' do
188 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id
189 @sheet_panel.author_id = nil
190 @sheet_panel.overwrite @author
191 @sheet_panel.author_id.should eq @author.id
197 describe '所持判定に於いて' do
199 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
200 @panel = FactoryGirl.create :panel, :author_id => @author.id
201 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
202 @sheeto = FactoryGirl.create :sheet, :author_id => @other_author.id
203 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
204 @sheet_panelo = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @sheeto.id, :panel_id => @panelo.id
206 context '事前チェックする' do
207 it '自身にロールリストからの作家取得を依頼している' do
208 SheetPanel.should_receive(:get_author_from_roles).with(any_args).exactly(1)
209 r = @sheet_panel.own?([@author])
212 context 'ロール内作家が取得できるとき' do
215 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
216 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(@author)
217 r = @sheet_panel.own?([@author])
220 it 'ロール内作家のidが自身の作家idと一致しないならno' do
221 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
222 @sheet_panel.own?(@other_author).should be_false
225 context 'ロール内作家が取得できないとき' do
227 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(nil)
230 r = @sheet_panel.own?([@author])
236 describe '閲覧許可に於いて' do
238 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
239 @panel = FactoryGirl.create :panel, :author_id => @author.id
240 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
242 context 'オープンモードのとき' do
244 MagicNumber['run_mode'] = 0
246 it '自身にゲスト用ロールチェックを問い合わせしている' do
247 SheetPanel.any_instance.stub(:guest_role_check).and_return(true)
248 SheetPanel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
249 r = @sheet_panel.visible?([@author])
251 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
252 SheetPanel.any_instance.stub(:guest_role_check).and_return(false)
253 r = @sheet_panel.visible?([@author])
257 context 'クローズドモードのとき' do
259 MagicNumber['run_mode'] = 1
261 it '自身に読者用ロールチェックを問い合わせしている' do
262 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
263 SheetPanel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
264 r = @sheet_panel.visible?([@author])
266 it '読者用ロールチェックが失敗したとき、falseを返す' do
267 SheetPanel.any_instance.stub(:reader_role_check).and_return(false)
268 r = @sheet_panel.visible?([@author])
272 context '事前チェックする' do
274 MagicNumber['run_mode'] = 1
275 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
277 it '自身の用紙に所持判定を問い合わせしている' do
278 Sheet.any_instance.stub(:own?).and_return(true)
279 Sheet.any_instance.should_receive(:own?).with(any_args).exactly(1)
280 r = @sheet_panel.visible?([@author])
282 it '自身の用紙に閲覧許可を問い合わせしている' do
283 Sheet.any_instance.stub(:own?).and_return(false)
284 Sheet.any_instance.stub(:visible?).and_return(true)
285 Sheet.any_instance.should_receive(:visible?).with(any_args).exactly(1)
286 r = @sheet_panel.visible?([@author])
289 context 'つつがなく終わるとき' do
291 MagicNumber['run_mode'] = 1
292 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
294 it '自分の用紙の紙コマなら許可する' do
295 Sheet.any_instance.stub(:own?).and_return(true)
296 Sheet.any_instance.stub(:visible).and_return(0)
297 r = @sheet_panel.visible?([@author])
300 it '他人の非公開用紙の紙コマなら許可しない' do
301 Sheet.any_instance.stub(:own?).and_return(false)
302 Sheet.any_instance.stub(:visible).and_return(0)
303 r = @sheet_panel.visible?([@author])
306 it '他人の用紙の紙コマでも公開なら許可する' do
307 Sheet.any_instance.stub(:own?).and_return(false)
308 Sheet.any_instance.stub(:visible).and_return(1)
309 r = @sheet_panel.visible?([@author])
315 describe 'プレイリスト取得に於いて' do
317 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
318 @panel = FactoryGirl.create :panel, :author_id => @author.id
319 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
320 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
321 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
322 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
324 context 'offset補正について' do
325 it '文字列から数値に変換される' do
326 SheetPanel.offset(100, '8').should eq 8
329 SheetPanel.offset(100).should eq 0
331 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
333 it '1件のときオフセット1なら0になる' do
334 SheetPanel.offset(1, '1').should eq 0
336 it '5件のときオフセット5なら4になる' do
337 SheetPanel.offset(5, '5').should eq 4
339 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
340 #-4のときは、最後から4つのコマを表示する。
341 it '2件のときオフセット-1なら1になる' do
342 SheetPanel.offset(2, '-1').should eq 1
344 it '5件のときオフセット-2なら3になる' do
345 SheetPanel.offset(5, '-2').should eq 3
347 # 最終的なが負になるなど、不正な値が入ったときは0となる。
348 it '2件のときオフセット-5なら0になる' do
349 SheetPanel.offset(2, '-5').should eq 0
352 context 'panel_count補正について' do
353 it '文字列から数値に変換される' do
354 SheetPanel.panel_count(100, '7').should eq 7
356 it 'nilの場合はSheetPanel.default_panel_sizeになる' do
357 SheetPanel.panel_count(100).should eq SheetPanel.default_panel_size
359 it '0以下の場合はSheetPanel.default_panel_sizeになる' do
360 SheetPanel.panel_count(100, '0').should eq SheetPanel.default_panel_size
362 it 'SheetPanel.max_panel_sizeを超えた場合はSheetPanel.max_panel_sizeになる' do
363 SheetPanel.panel_count(100, '1000').should eq SheetPanel.max_panel_size
367 c = SheetPanel.play_list @sheet, @author
368 c.should eq [@sheet_panel]
371 #公開用紙の公開コマは(他人の用紙であっても)含んでいる
372 v = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
373 c = SheetPanel.play_list @sheet, @author
374 c.should eq [ @sheet_panel, v]
377 h = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel2.id, :t => 1
378 c = SheetPanel.play_list @sheet, @author
379 c.should eq [ @sheet_panel, h]
381 context 'DBに5件あって1ページの件数を2件に変えたとして' do
383 @sheet_panel2 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
384 @sheet_panel3 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 2
385 @sheet_panel4 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 3
386 @sheet_panel5 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 4
388 it 'offset=0なら末尾2件を返す' do
390 c = SheetPanel.play_list( @sheet, @author, 0, 2)
391 c.should eq [@sheet_panel, @sheet_panel2]
393 it 'offset=2なら中間2件を返す' do
394 c = SheetPanel.play_list(@sheet, @author, 2, 2)
395 c.should eq [@sheet_panel3, @sheet_panel4]
397 it 'offset=4なら先頭1件を返す' do
398 c = SheetPanel.play_list(@sheet, @author, 4, 2)
399 c.should eq [@sheet_panel5]
404 describe '一覧取得に於いて' do
406 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
407 @panel = FactoryGirl.create :panel, :author_id => @author.id
408 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
409 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
410 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
411 @hidden_sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
413 context 'page補正について' do
414 it '文字列から数値に変換される' do
415 SheetPanel.page('8').should eq 8
418 SheetPanel.page().should eq 1
421 SheetPanel.page('0').should eq 1
424 context 'page_size補正について' do
425 it '文字列から数値に変換される' do
426 SheetPanel.page_size('7').should eq 7
428 it 'nilの場合はSheetPanel.default_page_sizeになる' do
429 SheetPanel.page_size().should eq SheetPanel.default_page_size
431 it '0以下の場合はSheetPanel.default_page_sizeになる' do
432 SheetPanel.page_size('0').should eq SheetPanel.default_page_size
434 it 'SheetPanel.max_page_sizeを超えた場合はSheetPanel.max_page_sizeになる' do
435 SheetPanel.page_size('1000').should eq SheetPanel.max_page_size
440 c.should eq [@sheet_panel]
443 #公開用紙のSheetPanelは(他人のSheetPanelであっても)含んでいる
444 v = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id, :t => 0, :updated_at => Time.now + 100
446 c.should eq [ v, @sheet_panel]
448 it '非公開の紙コマは(自分の紙コマであっても)含まない' do
449 h = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @hidden_sheet.id, :panel_id => @panel.id, :t => 0
451 c.should eq [ @sheet_panel]
453 context 'DBに5件あって1ページの件数を2件に変えたとして' do
455 @sheet_panel2 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
456 @sheet_panel3 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
457 @sheet_panel4 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
458 @sheet_panel5 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
461 l = SheetPanel.list 1, 2
462 l.should have(2).items
464 it 'page=1なら末尾2件を返す' do
466 l = SheetPanel.list 1, 2
467 l.should eq [@sheet_panel5, @sheet_panel4]
469 it 'page=2なら中間2件を返す' do
470 l = SheetPanel.list 2, 2
471 l.should eq [@sheet_panel3, @sheet_panel2]
473 it 'page=3なら先頭1件を返す' do
474 l = SheetPanel.list 3, 2
475 l.should eq [@sheet_panel]
480 describe '自分の紙コマ一覧取得に於いて' do
482 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
483 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
484 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
485 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
486 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
487 @hsheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
488 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
490 context 'つつがなく終わるとき' do
491 it '一覧取得オプションを利用している' do
492 SheetPanel.stub(:list_opt).with(any_args).and_return({})
493 SheetPanel.should_receive(:list_opt).with(any_args).exactly(1)
494 r = SheetPanel.mylist @author
498 s = SheetPanel.mylist @author
499 s.should eq [@sheet_panel]
502 ns = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
503 sl = SheetPanel.mylist @author
504 sl.should eq [ns, @sheet_panel]
506 it '他人の紙コマはコマ用紙ともに公開でも含まない' do
507 so = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id
508 sl = SheetPanel.mylist @author
509 sl.should eq [@sheet_panel]
511 it '自分の紙コマはコマ用紙ともに非公開でも含んでいる' do
512 hs = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @hsheet.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
513 sl = SheetPanel.mylist @author
514 sl.should eq [hs, @sheet_panel]
516 context 'DBに5件あって1ページの件数を2件に変えたとして' do
518 @sheet_panel2 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
519 @sheet_panel3 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
520 @sheet_panel4 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
521 @sheet_panel5 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
522 SheetPanel.stub(:default_page_size).and_return(2)
525 l = SheetPanel.mylist @author, 1, 2
526 l.should have(2).items
528 it 'page=1なら末尾2件を返す' do
530 l = SheetPanel.mylist @author, 1, 2
531 l.should eq [@sheet_panel5, @sheet_panel4]
533 it 'page=2なら中間2件を返す' do
534 l = SheetPanel.mylist @author, 2, 2
535 l.should eq [@sheet_panel3, @sheet_panel2]
537 it 'page=3なら先頭1件を返す' do
538 l = SheetPanel.mylist @author, 3, 2
539 l.should eq [@sheet_panel]
544 describe '他作家の紙コマ一覧取得に於いて' do
546 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
547 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
548 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
549 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
550 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
551 @other_sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id
554 r = SheetPanel.himlist @other_author
555 r.should eq [@other_sheet_panel]
558 ns = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
559 r = SheetPanel.himlist @other_author
560 r.should eq [ns, @other_sheet_panel]
563 @hsheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 0
564 ns = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @hsheet.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
565 r = SheetPanel.himlist @other_author
566 r.should eq [@other_sheet_panel]
568 context 'DBに5件あって1ページの件数を2件に変えたとして' do
570 @other_sheet_panel2 = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
571 @other_sheet_panel3 = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id, :t => 2, :updated_at => Time.now + 200
572 @other_sheet_panel4 = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id, :t => 3, :updated_at => Time.now + 300
573 @other_sheet_panel5 = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id, :t => 4, :updated_at => Time.now + 400
574 SheetPanel.stub(:default_page_size).and_return(2)
577 l = SheetPanel.himlist @other_author, 1, 2
578 l.should have(2).items
580 it 'page=1なら末尾2件を返す' do
582 l = SheetPanel.himlist @other_author, 1, 2
583 l.should eq [@other_sheet_panel5, @other_sheet_panel4]
585 it 'page=2なら中間2件を返す' do
586 l = SheetPanel.himlist @other_author, 2, 2
587 l.should eq [@other_sheet_panel3, @other_sheet_panel2]
589 it 'page=3なら先頭1件を返す' do
590 l = SheetPanel.himlist @other_author, 3, 2
591 l.should eq [@other_sheet_panel]
596 describe '紙コマ一覧ページ制御に於いて' do
598 SheetPanel.stub(:count).with(any_args).and_return(100)
601 r = SheetPanel.list_paginate
602 r.is_a?(Kaminari::PaginatableArray).should be_true
604 it '紙コマ一覧の取得条件を利用している' do
605 SheetPanel.stub(:list_where).with(any_args).and_return('')
606 SheetPanel.should_receive(:list_where).with(any_args).exactly(1)
607 r = SheetPanel.list_paginate
609 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
610 r = SheetPanel.list_paginate 3, 10
611 r.limit_value.should eq 10
612 r.offset_value.should eq 20
616 describe '自分の紙コマ一覧ページ制御に於いて' do
618 SheetPanel.stub(:count).with(any_args).and_return(100)
621 r = SheetPanel.mylist_paginate @author
622 r.is_a?(Kaminari::PaginatableArray).should be_true
624 it '自分の紙コマ一覧の取得条件を利用している' do
625 SheetPanel.stub(:mylist_where).with(any_args).and_return('')
626 SheetPanel.should_receive(:mylist_where).with(any_args).exactly(1)
627 r = SheetPanel.mylist_paginate @author
629 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
630 r = SheetPanel.mylist_paginate @author, 3, 10
631 r.limit_value.should eq 10
632 r.offset_value.should eq 20
636 describe '他作家の紙コマ一覧ページ制御に於いて' do
638 SheetPanel.stub(:count).with(any_args).and_return(100)
641 r = SheetPanel.himlist_paginate @other_author
642 r.is_a?(Kaminari::PaginatableArray).should be_true
644 it '他作家の紙コマ一覧の取得条件を利用している' do
645 SheetPanel.stub(:himlist_where).with(any_args).and_return('')
646 SheetPanel.should_receive(:himlist_where).with(any_args).exactly(1)
647 r = SheetPanel.himlist_paginate @other_author
649 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
650 r = SheetPanel.himlist_paginate @other_author, 3, 10
651 r.limit_value.should eq 10
652 r.offset_value.should eq 20
656 describe 'list関連テーブルプションに於いて' do
658 r = SheetPanel.list_opt
659 r.should have(3).items
662 r = SheetPanel.list_opt
663 r.has_key?(:sheet).should be_true
666 r = SheetPanel.list_opt
667 r[:sheet].has_key?(:author).should be_true
670 r = SheetPanel.list_opt
671 r.has_key?(:author).should be_true
674 r = SheetPanel.list_opt
675 r.has_key?(:panel).should be_true
678 r = SheetPanel.list_opt
679 r[:panel].has_key?(:author).should be_true
682 r = SheetPanel.list_opt
683 r[:panel].has_key?(:panel_pictures).should be_true
685 it 'コマ絵は実素材を含んでいる' do
686 r = SheetPanel.list_opt
687 r[:panel][:panel_pictures].has_key?(:picture).should be_true
690 r = SheetPanel.list_opt
691 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
693 it '実素材はライセンスを含んでいる' do
694 r = SheetPanel.list_opt
695 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
697 it 'コマはフキダシを含んでいる' do
698 r = SheetPanel.list_opt
699 r[:panel].has_key?(:speech_balloons).should be_true
701 it 'フキダシはフキダシ枠を含んでいる' do
702 r = SheetPanel.list_opt
703 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
705 it 'フキダシはセリフを含んでいる' do
706 r = SheetPanel.list_opt
707 r[:panel][:speech_balloons].has_key?(:speech).should be_true
710 describe 'json一覧出力オプションに於いて' do
713 describe '単体取得に於いて' do
715 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
716 @panel = FactoryGirl.create :panel, :author_id => @author.id
717 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
719 context 'つつがなく終わるとき' do
720 it '単体取得オプションを利用している' do
721 SheetPanel.stub(:show_opt).with(any_args).and_return({})
722 SheetPanel.should_receive(:show_opt).with(any_args).exactly(1)
723 r = SheetPanel.show @sheet_panel.id, @author
725 it '閲覧許可を問い合わせている' do
726 SheetPanel.any_instance.stub(:visible?).with(@author).and_return(true)
727 SheetPanel.any_instance.should_receive(:visible?).with(@author).exactly(1)
728 r = SheetPanel.show @sheet_panel.id, @author
732 l = SheetPanel.show @sheet_panel.id, @author
733 l.should eq @sheet_panel
735 context '他人の紙コマを開こうとしたとき' do
736 it '403Forbidden例外を返す' do
737 SheetPanel.any_instance.stub(:visible?).with(@other_author).and_return(false)
739 SheetPanel.show @sheet_panel.id, @other_author
740 }.should raise_error(ActiveRecord::Forbidden)
743 context '存在しない紙コマを開こうとしたとき' do
744 it '404RecordNotFound例外を返す' do
746 SheetPanel.show 110, @author
747 }.should raise_error(ActiveRecord::RecordNotFound)
752 describe '編集取得に於いて' do
754 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
755 @panel = FactoryGirl.create :panel, :author_id => @author.id
756 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
758 context 'つつがなく終わるとき' do
759 it '単体取得オプションを利用している' do
760 SheetPanel.stub(:show_opt).with(any_args).and_return({})
761 SheetPanel.should_receive(:show_opt).with(any_args).exactly(1)
762 r = SheetPanel.edit @sheet_panel.id, @author
764 it '所持判定を問い合わせている' do
765 SheetPanel.any_instance.stub(:own?).with(any_args).and_return(true)
766 SheetPanel.any_instance.should_receive(:own?).with(any_args).exactly(1)
767 r = SheetPanel.edit @sheet_panel.id, @author
771 l = SheetPanel.edit @sheet_panel.id, @author
772 l.should eq @sheet_panel
774 context '他人の紙コマを開こうとしたとき' do
775 it '403Forbidden例外を返す' do
776 SheetPanel.any_instance.stub(:own?).and_return(false)
778 SheetPanel.edit @sheet_panel.id, @author
779 }.should raise_error(ActiveRecord::Forbidden)
782 context '存在しない紙コマを開こうとしたとき' do
783 it '404RecordNotFound例外を返す' do
785 SheetPanel.edit 110, @author
786 }.should raise_error(ActiveRecord::RecordNotFound)
791 describe '単体取得オプションに於いて' do
792 it 'includeキーを含んでいる' do
793 r = SheetPanel.show_opt
794 r.has_key?(:include).should be_true
797 r = SheetPanel.show_opt[:include]
798 r.should have(3).items
801 r = SheetPanel.show_opt[:include]
802 r.has_key?(:sheet).should be_true
805 r = SheetPanel.show_opt[:include]
806 r[:sheet].has_key?(:author).should be_true
809 r = SheetPanel.show_opt[:include]
810 r.has_key?(:author).should be_true
813 r = SheetPanel.show_opt[:include]
814 r.has_key?(:panel).should be_true
817 r = SheetPanel.show_opt[:include]
818 r[:panel].has_key?(:author).should be_true
821 r = SheetPanel.show_opt[:include]
822 r[:panel].has_key?(:panel_pictures).should be_true
824 it 'コマ絵は実素材を含んでいる' do
825 r = SheetPanel.show_opt[:include]
826 r[:panel][:panel_pictures].has_key?(:picture).should be_true
829 r = SheetPanel.show_opt[:include]
830 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
832 it '実素材はライセンスを含んでいる' do
833 r = SheetPanel.show_opt[:include]
834 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
836 it 'コマはフキダシを含んでいる' do
837 r = SheetPanel.show_opt[:include]
838 r[:panel].has_key?(:speech_balloons).should be_true
840 it 'フキダシはフキダシ枠を含んでいる' do
841 r = SheetPanel.show_opt[:include]
842 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
844 it 'フキダシはセリフを含んでいる' do
845 r = SheetPanel.show_opt[:include]
846 r[:panel][:speech_balloons].has_key?(:speech).should be_true
849 describe 'json単体取得オプションに於いて' do
852 describe '紙コマのjson出力に於いて' do
855 @panel = FactoryGirl.create :panel, :author_id => @author.id
856 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
857 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
858 @speech = @sb.build_speech(
859 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
861 @balloon = @sb.build_balloon(
862 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
866 @gc = @panel.ground_colors.create(
867 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
869 @gp = @panel.ground_pictures.create(
870 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
873 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
874 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
876 context '事前チェックする' do
878 Panel.any_instance.stub(:elements).and_return('{}')
880 it 'コマ要素のjson出力を依頼している' do
881 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
882 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
883 r = @sheet_panel.sheet_panel_as_json @author
886 it 'json textを返している' do
887 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
888 r.is_a?(Hash).should be_true
890 it 'sheet,author,panel,コマ要素を含んでいる' do
891 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
892 r.has_key?('sheet').should be_true
893 r['sheet'].has_key?('author').should be_true
894 r.has_key?('author').should be_true
895 r.has_key?('panel').should be_true
896 r['panel'].has_key?('author').should be_true
898 context 'コマ閲覧許可のとき' do
900 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
902 it 'コマ要素にコマ要素を追加している' do
903 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
904 r['panel'].has_key?('elements').should be_true
905 r['panel']['elements'].should_not be_empty
908 context 'コマ閲覧不許可のとき' do
910 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
912 it 'コマ要素にデータを含ませない' do
913 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
914 r['panel'].has_key?('elements').should be_false
919 describe '紙コマリストのjson出力に於いて' do
921 @panel = FactoryGirl.create :panel, :author_id => @author.id
922 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
923 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
924 SheetPanel.any_instance.stub(:sheet_panel_as_json).with(@author).and_return('{"s": 5}')
926 context 'つつがなく終わるとき' do
927 it '紙コマのjson出力を依頼している' do
928 SheetPanel.any_instance.should_receive(:sheet_panel_as_json).with(@author).exactly(1)
929 r = SheetPanel.list_as_json_text [@sheet_panel], @author
932 it 'json textを返している' do
933 r = SheetPanel.list_as_json_text [@sheet_panel], @author
935 j.is_a?(Array).should be_true
938 r = SheetPanel.list_as_json_text [@sheet_panel], @author
940 j.first.has_key?('s').should be_true
944 describe 'ライセンス素材に於いて' do
947 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
948 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
949 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
950 @panel = FactoryGirl.create :panel, :author_id => @author.id
951 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id
953 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
954 @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id
957 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
958 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
959 @sheet_panel2 = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel2.id
963 context 'つつがなく終わるとき' do
965 it '連想配列(値は実素材、キーは実素材id)を返している' do
966 r = SheetPanel.licensed_pictures [@sheet_panel, @sheet_panel2]
967 r.is_a?(Hash).should be_true
968 r.should have(2).items
969 r[@pp.picture_id].should eq @p
970 r[@pp2.picture_id].should eq @p2
972 context 'コマが削除されているときき' do
976 it '削除されているコマは無視する' do
977 r = SheetPanel.licensed_pictures [@sheet_panel, @sheet_panel2]
978 r.is_a?(Hash).should be_true
979 r.should have(1).items
980 r[@pp.picture_id].should eq @p
981 r[@pp2.picture_id].should be_nil
986 describe 't補充値に於いて' do
988 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
989 @panel = FactoryGirl.create :panel, :author_id => @author.id
992 context '用紙初のコマなら' do
994 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
996 r = SheetPanel.new_t @sheet_panel.sheet_id
1000 context '用紙に一個コマがあるとき' do
1002 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0
1003 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
1004 @sheet_panel.t = nil
1005 r = SheetPanel.new_t @sheet_panel.sheet_id
1009 context '用紙に2個コマがあるとき' do
1011 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0
1012 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
1013 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
1014 @sheet_panel.t = nil
1015 r = SheetPanel.new_t @sheet_panel.sheet_id
1020 describe 'シリアライズチェックに於いて' do
1021 context 'つつがなく終わるとき' do
1022 it '0からシリアライズされているならTrueを返す' do
1023 r = SheetPanel.serial? [0, 1, 2]
1026 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
1027 r = SheetPanel.serial? [0, 2, 1]
1030 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
1031 r = SheetPanel.serial? [ 2, 1, 4, 3, 0]
1036 it '0から始まらないならFalseを返す' do
1037 r = SheetPanel.serial? [1, 2, 3]
1040 it '連続していないならFalseを返す' do
1041 r = SheetPanel.serial? [0, 1, 2, 4]
1044 it '連続していないならFalseを返す' do
1045 r = SheetPanel.serial? [0, 1, 2, 4, 5]
1050 describe 't収集に於いて' do
1052 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1053 @panel = FactoryGirl.create :panel, :author_id => @author.id
1054 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1055 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1056 @c2sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1058 context 'つつがなく終わるとき' do
1059 it '紙コマから同一用紙のtだけを収集している' do
1060 r = SheetPanel.collect_t @sheet_panel
1064 context '複数コマのとき' do
1065 it '紙コマから同一用紙のtだけを収集している' do
1066 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1067 r = SheetPanel.collect_t @sheet_panel
1068 r.sort.should eq [0, 1]
1071 context '複数コマでヨソの用紙も混じっているとき' do
1072 it '紙コマから同一用紙のtだけを収集している' do
1073 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1074 r = SheetPanel.collect_t @sheet_panel
1075 r.sort.should eq [0, 1]
1079 describe 'tチェックに於いて' do
1081 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1082 @panel = FactoryGirl.create :panel, :author_id => @author.id
1083 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1085 context 'つつがなく終わるとき' do
1087 SheetPanel.should_receive(:collect_t).with(any_args).exactly(1)
1088 SheetPanel.stub(:collect_t).with(any_args).and_return([])
1089 SheetPanel.stub(:serial?).with(any_args).and_return(true)
1090 r = SheetPanel.validate_t @sheet_panel
1092 it '収集したtをシリアライズチェック依頼している' do
1093 SheetPanel.stub(:collect_t).with(any_args).and_return([])
1094 SheetPanel.should_receive(:serial?).with(any_args).exactly(1)
1095 SheetPanel.stub(:serial?).with(any_args).and_return(true)
1096 r = SheetPanel.validate_t @sheet_panel
1100 #依頼チェックだけでは不安なので最低限のチェックを
1102 it '一件だけで正常通過している' do
1103 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1104 r = SheetPanel.validate_t @sheet_panel
1109 it '2件目を作っても正常通過している' do
1110 @sheet_panel = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1111 @sheet_panel2 = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
1112 r = SheetPanel.validate_t @sheet_panel2
1117 describe '挿入シフトに於いて' do
1119 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1120 @panel = FactoryGirl.create :panel, :author_id => @author.id
1124 it 'Updateを依頼している' do
1125 SheetPanel.stub(:update_all).with(any_args)
1126 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1127 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1128 @sheet_panel.insert_shift
1131 context 'テーブルに1件(t:0)で0に挿入したとき' do
1133 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1134 @sheet_panel2 = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1136 it '既存の行を1にシフトしている' do
1137 @sheet_panel2.insert_shift
1138 l = SheetPanel.find :all
1139 l.first.t.should eq 1
1141 it 'これから挿入するt(0)が欠番になっている' do
1142 @sheet_panel2.insert_shift
1143 l = SheetPanel.find(:all).map {|s| s.t }
1144 l.include?(0).should_not be_true
1147 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
1149 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1150 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1151 @sheet_panel3 = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1153 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1154 @sheet_panel3.insert_shift
1155 l = SheetPanel.find(:all).map {|s| s.t }
1156 l.sort.should eq [0, 2]
1159 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
1161 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1162 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1163 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1164 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1165 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1166 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1168 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1169 @sheet_panel6.insert_shift
1170 l = SheetPanel.find(:all).map {|s| s.t }
1171 l.sort.should eq [0, 1, 3, 4, 5]
1174 context '先ほどのケース+他の用紙1件で挿入したとき' do
1176 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1177 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1178 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1179 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1180 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1181 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1182 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1183 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1185 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1186 @sheet_panel6.insert_shift
1187 l = SheetPanel.find(:all, :conditions => ['sheet_id = ?', @sheet.id]).map {|s| s.t }
1188 l.sort.should eq [0, 1, 3, 4, 5]
1191 ot = @sheet_panelc2.t
1192 @sheet_panel6.insert_shift
1193 @sheet_panelc2.reload
1194 @sheet_panelc2.t.should eq ot
1198 describe '少ない方に移動に於いて' do
1200 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1201 @panel = FactoryGirl.create :panel, :author_id => @author.id
1204 it 'Updateを依頼している' do
1205 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1206 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1207 SheetPanel.stub(:update_all).with(any_args)
1208 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1209 ot = @sheet_panel2.t
1211 @sheet_panel2.lesser_shift ot
1214 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
1216 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1217 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1218 @ot = @sheet_panel2.t
1221 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1223 @sheet_panel2.lesser_shift @ot
1224 l = SheetPanel.find(:all).map {|s| s.t }
1225 l.sort.should eq [1, 1]
1227 it '既存のt0を1にシフトしている' do
1228 @sheet_panel2.lesser_shift @ot
1230 @sheet_panel.t.should eq 1
1233 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
1235 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1236 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1237 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1238 @ot = @sheet_panel3.t
1241 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1243 @sheet_panel3.lesser_shift @ot
1244 l = SheetPanel.find(:all).map {|s| s.t }
1245 l.sort.should eq [0, 2, 2]
1247 it '既存のt1を2にシフトしている' do
1248 @sheet_panel3.lesser_shift @ot
1249 @sheet_panel2.reload
1250 @sheet_panel2.t.should eq 2
1253 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
1255 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1256 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1257 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1258 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1259 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1260 @ot = @sheet_panel4.t
1263 it 'これから挿入するt(1)が欠番になっている' do
1265 @sheet_panel4.lesser_shift @ot
1266 l = SheetPanel.find(:all).map {|s| s.t }
1267 l.sort.should eq [0, 2, 3, 3, 4]
1269 it '既存のt0には変化がない' do
1270 @sheet_panel4.lesser_shift @ot
1272 @sheet_panel.t.should eq 0
1274 it '既存のt4には変化がない' do
1275 @sheet_panel4.lesser_shift @ot
1276 @sheet_panel5.reload
1277 @sheet_panel5.t.should eq 4
1279 it '既存のt1を2にシフトしている' do
1280 @sheet_panel4.lesser_shift @ot
1281 @sheet_panel2.reload
1282 @sheet_panel2.t.should eq 2
1284 it '既存のt2を3にシフトしている' do
1285 @sheet_panel4.lesser_shift @ot
1286 @sheet_panel3.reload
1287 @sheet_panel3.t.should eq 3
1290 context '先ほどのケース+他の用紙1件で挿入したとき' do
1292 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1293 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1294 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1295 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1296 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1297 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1298 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1299 @ot = @sheet_panel4.t
1302 it 'これから挿入するt(1)が欠番になっている' do
1303 @sheet_panel4.lesser_shift @ot
1304 l = SheetPanel.find(:all).map {|s| s.t }
1305 l.sort.should eq [0, 0, 2, 3, 3, 4]
1307 it '既存のt0には変化がない' do
1308 @sheet_panel4.lesser_shift @ot
1310 @sheet_panel.t.should eq 0
1312 it '既存のt4には変化がない' do
1313 @sheet_panel4.lesser_shift @ot
1314 @sheet_panel5.reload
1315 @sheet_panel5.t.should eq 4
1317 it '既存のt1を2にシフトしている' do
1318 @sheet_panel4.lesser_shift @ot
1319 @sheet_panel2.reload
1320 @sheet_panel2.t.should eq 2
1322 it '既存のt2を3にシフトしている' do
1323 @sheet_panel4.lesser_shift @ot
1324 @sheet_panel3.reload
1325 @sheet_panel3.t.should eq 3
1328 @sheet_panel4.lesser_shift @ot
1329 @sheet_panelc2.reload
1330 @sheet_panelc2.t.should eq 0
1335 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
1337 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1338 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1339 @ot = @sheet_panel2.t
1340 @sheet_panel2.t = -1
1342 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1344 @sheet_panel2.lesser_shift @ot
1345 l = SheetPanel.find(:all).map {|s| s.t }
1346 l.sort.should eq [1, 1]
1348 it '既存のt0を1にシフトしている' do
1349 @sheet_panel2.lesser_shift @ot
1351 @sheet_panel.t.should eq 1
1353 it '既存のt1は0に補正されている' do
1354 @sheet_panel2.lesser_shift @ot
1355 @sheet_panel2.t.should eq 0
1359 describe '大きい方に移動に於いて' do
1361 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1362 @panel = FactoryGirl.create :panel, :author_id => @author.id
1365 it 'Updateを依頼している' do
1366 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1367 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1368 SheetPanel.stub(:update_all).with(any_args)
1369 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1372 @sheet_panel.higher_shift ot
1375 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1377 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1378 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1379 @ot = @sheet_panel.t
1382 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1384 @sheet_panel.higher_shift @ot
1385 l = SheetPanel.find(:all).map {|s| s.t }
1386 l.sort.should eq [0, 0]
1388 it '既存のt1を0にシフトしている' do
1389 @sheet_panel.higher_shift @ot
1390 @sheet_panel2.reload
1391 @sheet_panel2.t.should eq 0
1394 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1396 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1397 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1398 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1399 @ot = @sheet_panel.t
1402 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1404 @sheet_panel.higher_shift @ot
1405 l = SheetPanel.find(:all).map {|s| s.t }
1406 l.sort.should eq [0, 0, 2]
1408 it '既存のt1を0にシフトしている' do
1409 @sheet_panel.higher_shift @ot
1410 @sheet_panel2.reload
1411 @sheet_panel2.t.should eq 0
1414 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1416 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1417 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1418 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1419 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1420 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1421 @ot = @sheet_panel2.t
1424 it 'これから挿入するt(3)が欠番になっている' do
1426 @sheet_panel2.higher_shift @ot
1427 l = SheetPanel.find(:all).map {|s| s.t }
1428 l.sort.should eq [0, 1, 1, 2, 4]
1430 it '既存のt0には変化がない' do
1431 @sheet_panel2.higher_shift @ot
1433 @sheet_panel.t.should eq 0
1435 it '既存のt4には変化がない' do
1436 @sheet_panel2.higher_shift @ot
1437 @sheet_panel5.reload
1438 @sheet_panel5.t.should eq 4
1440 it '既存のt2を1にシフトしている' do
1441 @sheet_panel2.higher_shift @ot
1442 @sheet_panel3.reload
1443 @sheet_panel3.t.should eq 1
1445 it '既存のt3を2にシフトしている' do
1446 @sheet_panel2.higher_shift @ot
1447 @sheet_panel4.reload
1448 @sheet_panel4.t.should eq 2
1451 context '先ほどのケース+他の用紙1件で挿入したとき' do
1453 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1454 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1455 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1456 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1457 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1458 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1459 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1460 @ot = @sheet_panel2.t
1463 it 'これから挿入するt(3)が欠番になっている' do
1465 @sheet_panel2.higher_shift @ot
1466 l = SheetPanel.find(:all).map {|s| s.t }
1467 l.sort.should eq [0, 0, 1, 1, 2, 4]
1469 it '既存のt0には変化がない' do
1470 @sheet_panel2.higher_shift @ot
1472 @sheet_panel.t.should eq 0
1474 it '既存のt4には変化がない' do
1475 @sheet_panel2.higher_shift @ot
1476 @sheet_panel5.reload
1477 @sheet_panel5.t.should eq 4
1479 it '既存のt2を1にシフトしている' do
1480 @sheet_panel2.higher_shift @ot
1481 @sheet_panel3.reload
1482 @sheet_panel3.t.should eq 1
1484 it '既存のt3を2にシフトしている' do
1485 @sheet_panel2.higher_shift @ot
1486 @sheet_panel4.reload
1487 @sheet_panel4.t.should eq 2
1490 @sheet_panel2.higher_shift @ot
1491 @sheet_panelc2.reload
1492 @sheet_panelc2.t.should eq 0
1496 #max超えたときはmaxとして正常扱い
1497 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1499 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1500 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1501 @ot = @sheet_panel.t
1504 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1506 @sheet_panel.higher_shift @ot
1507 l = SheetPanel.find(:all).map {|s| s.t }
1508 l.sort.should eq [0, 0]
1510 it '既存のt1を0にシフトしている' do
1511 @sheet_panel.higher_shift @ot
1512 @sheet_panel2.reload
1513 @sheet_panel2.t.should eq 0
1515 it '既存のt0は1に補正されている' do
1516 @sheet_panel.higher_shift @ot
1517 @sheet_panel.t.should eq 1
1521 describe '入れ替えに於いて' do
1523 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1524 @panel = FactoryGirl.create :panel, :author_id => @author.id
1525 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1526 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1528 context '新tが旧tより小さいとき' do
1529 it '少ない方に移動を依頼している' do
1530 SheetPanel.any_instance.stub(:lesser_shift).with(any_args)
1531 SheetPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1532 ot = @sheet_panel2.t
1534 @sheet_panel2.update_shift ot
1537 context '新tが旧tより大きいとき' do
1538 it '大きい方に移動を依頼している' do
1539 SheetPanel.any_instance.stub(:higher_shift).with(any_args)
1540 SheetPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1543 @sheet_panel.update_shift ot
1547 describe '順序入れ替えに於いて' do
1549 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1550 @panel = FactoryGirl.create :panel, :author_id => @author.id
1552 context 'オブジェクトが新規でtが空のとき' do
1553 it '末尾追加としてtを補充依頼している' do
1554 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1555 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1556 SheetPanel.should_receive(:new_t).with(any_args).exactly(1)
1557 @sheet_panel.t = nil
1558 r = @sheet_panel.rotate
1561 context 'オブジェクトが新規でtが設定されているとき' do
1562 it '挿入追加として挿入シフトを依頼している' do
1563 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1564 SheetPanel.any_instance.stub(:insert_shift).with(any_args)
1565 SheetPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1567 r = @sheet_panel.rotate
1570 context 'オブジェクトが新規でなくtが設定されているとき' do
1571 it 'コマ移動として入れ替えを依頼している' do
1572 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1573 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1574 SheetPanel.any_instance.stub(:update_shift).with(any_args)
1575 SheetPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
1577 r = @sheet_panel.rotate 1
1580 context 'オブジェクトが新規でなくtが空のとき' do
1581 it '入れ替えもシフトもせず、tを空のままにしている' do
1582 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1586 describe '編集許可に於いて' do
1588 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1589 @panel = FactoryGirl.create :panel, :author_id => @author.id
1590 @sheet_panel = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1592 context 'つつがなく終わるとき' do
1594 r = @sheet_panel.allow?
1598 context '用紙で引っかかるとき' do
1600 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1601 Sheet.any_instance.stub(:own?).with(any_args).and_return(false)
1602 r = @sheet_panel.allow?
1606 context 'コマで引っかかるとき' do
1608 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
1609 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1610 r = @sheet_panel.allow?
1614 context '用紙またはコマが指定されていなかったとき' do
1616 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
1617 @sheet_panel.panel_id = nil
1618 r = @sheet_panel.allow?
1622 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1623 @sheet_panel.sheet_id = nil
1624 r = @sheet_panel.allow?
1629 describe '保存に於いて' do
1631 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1632 @panel = FactoryGirl.create :panel, :author_id => @author.id
1633 @sheet_panel = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1635 context 'つつがなく終わるとき' do
1636 it '編集許可チェックを依頼している' do
1637 SheetPanel.any_instance.stub(:allow?).with(any_args).and_return(true)
1638 SheetPanel.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1639 r = @sheet_panel.store
1641 it '順序入れ替えを依頼している' do
1642 SheetPanel.any_instance.stub(:rotate).with(any_args).and_return(0)
1643 SheetPanel.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1644 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1645 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1646 r = @sheet_panel.store
1649 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1650 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1651 SheetPanel.any_instance.should_receive(:save).with(any_args).exactly(1)
1652 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1653 r = @sheet_panel.store
1655 it 'tのシリアライズチェックを依頼している' do
1656 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1657 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1658 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1659 SheetPanel.should_receive(:validate_t).with(any_args).exactly(1)
1660 r = @sheet_panel.store
1663 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1664 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したとき' do
1666 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1667 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1668 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1669 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1670 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1671 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1672 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1673 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1675 it '既存のt0には変化がない' do
1678 @sheet_panel.t.should eq 0
1680 it '既存のt1には変化がない' do
1682 @sheet_panel2.reload
1683 @sheet_panel2.t.should eq 1
1685 it '既存のt2を3にシフトしている' do
1687 @sheet_panel3.reload
1688 @sheet_panel3.t.should eq 3
1690 it '既存のt3を4にシフトしている' do
1692 @sheet_panel4.reload
1693 @sheet_panel4.t.should eq 4
1695 it '既存のt5を5にシフトしている' do
1697 @sheet_panel5.reload
1698 @sheet_panel5.t.should eq 5
1700 it '新規のt2が作成されている' do
1702 @sheet_panel6.reload
1703 @sheet_panel6.t.should eq 2
1706 @ot = @sheet_panelc2.t
1708 @sheet_panelc2.reload
1709 @sheet_panelc2.t.should eq @ot
1712 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したとき' do
1714 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1715 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1716 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1717 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1718 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1719 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1720 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1721 @ot = @sheet_panel4.t
1724 it '既存のt0には変化がない' do
1725 @sheet_panel4.store @ot
1727 @sheet_panel.t.should eq 0
1729 it '既存のt4には変化がない' do
1730 @sheet_panel4.store @ot
1731 @sheet_panel5.reload
1732 @sheet_panel5.t.should eq 4
1734 it '既存のt1を2にシフトしている' do
1735 @sheet_panel4.store @ot
1736 @sheet_panel2.reload
1737 @sheet_panel2.t.should eq 2
1739 it '既存のt2を3にシフトしている' do
1740 @sheet_panel4.store @ot
1741 @sheet_panel3.reload
1742 @sheet_panel3.t.should eq 3
1744 it '既存のt3を1にシフトしている' do
1745 @sheet_panel4.store @ot
1746 @sheet_panel4.reload
1747 @sheet_panel4.t.should eq 1
1750 @sheet_panel4.store @ot
1751 @sheet_panelc2.reload
1752 @sheet_panelc2.t.should eq 0
1755 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で1を3に移動したとき' do
1757 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1758 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1759 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1760 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1761 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1762 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1763 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1764 @ot = @sheet_panel2.t
1767 it '既存のt0には変化がない' do
1768 @sheet_panel2.store @ot
1770 @sheet_panel.t.should eq 0
1772 it '既存のt4には変化がない' do
1773 @sheet_panel2.store @ot
1774 @sheet_panel5.reload
1775 @sheet_panel5.t.should eq 4
1777 it '既存のt1を3にシフトしている' do
1778 @sheet_panel2.store @ot
1779 @sheet_panel2.reload
1780 @sheet_panel2.t.should eq 3
1782 it '既存のt2を1にシフトしている' do
1783 @sheet_panel2.store @ot
1784 @sheet_panel3.reload
1785 @sheet_panel3.t.should eq 1
1787 it '既存のt3を2にシフトしている' do
1788 @sheet_panel2.store @ot
1789 @sheet_panel4.reload
1790 @sheet_panel4.t.should eq 2
1793 @sheet_panel2.store @ot
1794 @sheet_panelc2.reload
1795 @sheet_panelc2.t.should eq 0
1798 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1799 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したが保存に失敗したとき' do
1801 SheetPanel.any_instance.stub(:save).with(any_args).and_return(false)
1802 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1803 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1804 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1805 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1806 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1807 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1808 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1809 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1814 @sheet_panel.t.should eq 0
1815 @sheet_panel2.reload
1816 @sheet_panel2.t.should eq 1
1817 @sheet_panel3.reload
1818 @sheet_panel3.t.should eq 2
1819 @sheet_panel4.reload
1820 @sheet_panel4.t.should eq 3
1821 @sheet_panel5.reload
1822 @sheet_panel5.t.should eq 4
1823 @sheet_panelc2.reload
1824 @sheet_panelc2.t.should eq 0
1827 r = @sheet_panel6.store
1831 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したがシリアルチェックに失敗したとき' do
1833 SheetPanel.stub(:validate_t).with(any_args).and_return(false)
1834 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1835 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1836 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1837 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1838 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1839 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1840 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1841 @ot = @sheet_panel4.t
1845 @sheet_panel4.store @ot
1847 @sheet_panel.t.should eq 0
1848 @sheet_panel2.reload
1849 @sheet_panel2.t.should eq 1
1850 @sheet_panel3.reload
1851 @sheet_panel3.t.should eq 2
1852 @sheet_panel4.reload
1853 @sheet_panel4.t.should eq 3
1854 @sheet_panel5.reload
1855 @sheet_panel5.t.should eq 4
1856 @sheet_panelc2.reload
1857 @sheet_panelc2.t.should eq 0
1860 r = @sheet_panel4.store @ot
1863 it 'tにエラーメッセージが入っている' do
1864 @sheet_panel4.store @ot
1865 @sheet_panel4.errors[:t].should_not be_empty
1866 @sheet_panel4.valid?.should be_true
1869 context '編集不可だったとき' do
1871 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1872 SheetPanel.any_instance.stub(:allow?).and_return(false)
1874 it '403Forbidden例外を返す' do
1877 }.should raise_error(ActiveRecord::Forbidden)
1881 describe '切り詰め処理つき削除に於いて' do
1883 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1884 @panel = FactoryGirl.create :panel, :author_id => @author.id
1885 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1887 context 'つつがなく終わるとき' do
1890 @sheet_panel.destroy_and_shorten
1891 }.should change(SheetPanel, :count ).by(-1)
1894 r = @sheet_panel.destroy_and_shorten
1898 context '削除に失敗したとき' do
1900 SheetPanel.any_instance.stub(:destroy).and_return(false)
1904 @sheet_panel.destroy_and_shorten
1905 }.should_not change(SheetPanel, :count )
1908 r = @sheet_panel.destroy_and_shorten
1912 #連携テスト。切り詰めが直接DBをいじる
1913 context '2件で先頭を削除したとき' do
1915 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1919 @sheet_panel.destroy_and_shorten
1920 }.should change(SheetPanel, :count ).by(-1)
1923 @sheet_panel.destroy_and_shorten
1925 SheetPanel.find @sheet_panel.id
1926 }.should raise_error(ActiveRecord::RecordNotFound)
1929 @sheet_panel.destroy_and_shorten
1930 @sheet_panel2.reload
1931 @sheet_panel2.t.should eq 0
1934 context '3件で先頭を削除したとき' do
1936 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1937 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1941 @sheet_panel.destroy_and_shorten
1942 }.should change(SheetPanel, :count ).by(-1)
1945 @sheet_panel.destroy_and_shorten
1947 SheetPanel.find @sheet_panel.id
1948 }.should raise_error(ActiveRecord::RecordNotFound)
1951 @sheet_panel.destroy_and_shorten
1952 @sheet_panel2.reload
1953 @sheet_panel2.t.should eq 0
1956 @sheet_panel.destroy_and_shorten
1957 @sheet_panel3.reload
1958 @sheet_panel3.t.should eq 1
1961 context '5件で3件目を削除したとき' do
1963 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1964 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1965 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1966 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1970 @sheet_panel3.destroy_and_shorten
1971 }.should change(SheetPanel, :count ).by(-1)
1974 @sheet_panel3.destroy_and_shorten
1976 @sheet_panel.t.should eq 0
1979 @sheet_panel3.destroy_and_shorten
1980 @sheet_panel2.reload
1981 @sheet_panel2.t.should eq 1
1984 @sheet_panel3.destroy_and_shorten
1986 SheetPanel.find @sheet_panel3.id
1987 }.should raise_error(ActiveRecord::RecordNotFound)
1990 @sheet_panel3.destroy_and_shorten
1991 @sheet_panel4.reload
1992 @sheet_panel4.t.should eq 2
1995 @sheet_panel3.destroy_and_shorten
1996 @sheet_panel5.reload
1997 @sheet_panel5.t.should eq 3
2000 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する