1 # -*- encoding: utf-8 -*-
6 @admin =FactoryGirl.create :admin
7 @user_yas = FactoryGirl.create :user_yas_with_owner
8 @user_rom = FactoryGirl.create :user_rom
9 @author_yas = @user_yas.author
14 @sheet = FactoryGirl.create :sheet, author_id: @author_yas.id
15 @panel = FactoryGirl.create :panel, author_id: @author_yas.id
16 @item = FactoryGirl.build :sheet_panel_plain, sheet: @sheet, panel: @panel
19 context 'オーソドックスなデータのとき' do
25 expect(@item).to be_valid
32 expect(@item).to be_valid
36 context 'sheet_idを検証するとき' do
37 it '他人のコマや用紙を引用しているケースで、オーナーが削除することもあるので、空白でも通る' do
39 expect(@item).to be_valid
43 context 'panel_idを検証するとき' do
44 it '他人のコマや用紙を引用しているケースで、オーナーが削除することもあるので、空白でも通る' do
46 expect(@item).to be_valid
53 expect(@item).to_not be_valid
57 expect(@item).to be_valid
61 expect(@item).to be_valid
67 expect(@item).to_not be_valid
71 expect(@item).to be_valid
75 expect(@item).to be_valid
81 expect(@item).to_not be_valid
85 expect(@item).to_not be_valid
89 expect(@item).to_not be_valid
93 expect(@item).to be_valid
99 expect(@item).to_not be_valid
103 expect(@item).to_not be_valid
107 expect(@item).to be_valid
111 context '全体を検証するとき' do
115 describe 'デフォルト値補充に於いて' do
117 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
118 @panel = FactoryGirl.create :panel, :author_id => @author.id
121 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
123 @item = FactoryGirl.build :sheet_panel, :sheet_id => nil, :panel_id => @panel.id
125 @item.t.should be_nil
128 it '自身の用紙に最大t取得を依頼している' do
129 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id
130 Sheet.any_instance.should_receive(:new_t).with(any_args).exactly(1)
134 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id
135 Sheet.any_instance.stub(:new_t).with(any_args).and_return(4)
142 describe '上書き補充に於いて' do
144 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
145 @panel = FactoryGirl.create :panel, :author_id => @author.id
148 context 'author_idを補充' do
149 it '問答無用でauthor_idを補充する' do
150 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id
151 @item.author_id = nil
152 @item.overwrite @author
153 @item.author_id.should eq @author.id
159 describe '所持判定に於いて' do
161 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
162 @panel = FactoryGirl.create :panel, :author_id => @author.id
163 @item = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
164 @sheeto = FactoryGirl.create :sheet, :author_id => @other_author.id
165 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
166 @itemo = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @sheeto.id, :panel_id => @panelo.id
168 context '事前チェックする' do
169 it '自身にロールリストからの作家取得を依頼している' do
170 SheetPanel.should_receive(:get_author_from_roles).with(any_args).exactly(1)
171 r = @item.own?([@author])
174 context 'ロール内作家が取得できるとき' do
177 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
178 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(@author)
179 r = @item.own?([@author])
182 it 'ロール内作家のidが自身の作家idと一致しないならno' do
183 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
184 @item.own?(@other_author).should be_false
187 context 'ロール内作家が取得できないとき' do
189 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(nil)
192 r = @item.own?([@author])
198 describe '閲覧許可に於いて' do
200 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
201 @panel = FactoryGirl.create :panel, :author_id => @author.id
202 @item = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
204 context 'オープンモードのとき' do
206 MagicNumber['run_mode'] = 0
208 it '自身にゲスト用ロールチェックを問い合わせしている' do
209 SheetPanel.any_instance.stub(:guest_role_check).and_return(true)
210 SheetPanel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
211 r = @item.visible?([@author])
213 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
214 SheetPanel.any_instance.stub(:guest_role_check).and_return(false)
215 r = @item.visible?([@author])
219 context 'クローズドモードのとき' do
221 MagicNumber['run_mode'] = 1
223 it '自身に読者用ロールチェックを問い合わせしている' do
224 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
225 SheetPanel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
226 r = @item.visible?([@author])
228 it '読者用ロールチェックが失敗したとき、falseを返す' do
229 SheetPanel.any_instance.stub(:reader_role_check).and_return(false)
230 r = @item.visible?([@author])
234 context '事前チェックする' do
236 MagicNumber['run_mode'] = 1
237 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
239 it '自身の用紙に所持判定を問い合わせしている' do
240 Sheet.any_instance.stub(:own?).and_return(true)
241 Sheet.any_instance.should_receive(:own?).with(any_args).exactly(1)
242 r = @item.visible?([@author])
244 it '自身の用紙に閲覧許可を問い合わせしている' do
245 Sheet.any_instance.stub(:own?).and_return(false)
246 Sheet.any_instance.stub(:visible?).and_return(true)
247 Sheet.any_instance.should_receive(:visible?).with(any_args).exactly(1)
248 r = @item.visible?([@author])
251 context 'つつがなく終わるとき' do
253 MagicNumber['run_mode'] = 1
254 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
256 it '自分の用紙の紙コマなら許可する' do
257 Sheet.any_instance.stub(:own?).and_return(true)
258 Sheet.any_instance.stub(:visible).and_return(0)
259 r = @item.visible?([@author])
262 it '他人の非公開用紙の紙コマなら許可しない' do
263 Sheet.any_instance.stub(:own?).and_return(false)
264 Sheet.any_instance.stub(:visible).and_return(0)
265 r = @item.visible?([@author])
268 it '他人の用紙の紙コマでも公開なら許可する' do
269 Sheet.any_instance.stub(:own?).and_return(false)
270 Sheet.any_instance.stub(:visible).and_return(1)
271 r = @item.visible?([@author])
278 describe '単体取得に於いて' do
280 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
281 @panel = FactoryGirl.create :panel, :author_id => @author.id
282 @item = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
284 context 'つつがなく終わるとき' do
285 it '単体取得オプションを利用している' do
286 SheetPanel.stub(:show_opt).with(any_args).and_return({})
287 SheetPanel.should_receive(:show_opt).with(any_args).exactly(1)
288 r = SheetPanel.show @item.id, @author
290 it '閲覧許可を問い合わせている' do
291 SheetPanel.any_instance.stub(:visible?).with(@author).and_return(true)
292 SheetPanel.any_instance.should_receive(:visible?).with(@author).exactly(1)
293 r = SheetPanel.show @item.id, @author
297 l = SheetPanel.show @item.id, @author
300 context '他人の紙コマを開こうとしたとき' do
301 it '403Forbidden例外を返す' do
302 SheetPanel.any_instance.stub(:visible?).with(@other_author).and_return(false)
304 SheetPanel.show @item.id, @other_author
305 }.should raise_error(ActiveRecord::Forbidden)
308 context '存在しない紙コマを開こうとしたとき' do
309 it '404RecordNotFound例外を返す' do
311 SheetPanel.show 110, @author
312 }.should raise_error(ActiveRecord::RecordNotFound)
317 describe '編集取得に於いて' do
319 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
320 @panel = FactoryGirl.create :panel, :author_id => @author.id
321 @item = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
323 context 'つつがなく終わるとき' do
324 it '単体取得オプションを利用している' do
325 SheetPanel.stub(:show_opt).with(any_args).and_return({})
326 SheetPanel.should_receive(:show_opt).with(any_args).exactly(1)
327 r = SheetPanel.edit @item.id, @author
329 it '所持判定を問い合わせている' do
330 SheetPanel.any_instance.stub(:own?).with(any_args).and_return(true)
331 SheetPanel.any_instance.should_receive(:own?).with(any_args).exactly(1)
332 r = SheetPanel.edit @item.id, @author
336 l = SheetPanel.edit @item.id, @author
339 context '他人の紙コマを開こうとしたとき' do
340 it '403Forbidden例外を返す' do
341 SheetPanel.any_instance.stub(:own?).and_return(false)
343 SheetPanel.edit @item.id, @author
344 }.should raise_error(ActiveRecord::Forbidden)
347 context '存在しない紙コマを開こうとしたとき' do
348 it '404RecordNotFound例外を返す' do
350 SheetPanel.edit 110, @author
351 }.should raise_error(ActiveRecord::RecordNotFound)
356 describe '単体取得オプションに於いて' do
357 it 'includeキーを含んでいる' do
358 r = SheetPanel.show_opt
359 r.has_key?(:include).should be_true
362 r = SheetPanel.show_opt[:include]
363 r.should have(3).items
366 r = SheetPanel.show_opt[:include]
367 r.has_key?(:sheet).should be_true
370 r = SheetPanel.show_opt[:include]
371 r[:sheet].has_key?(:author).should be_true
374 r = SheetPanel.show_opt[:include]
375 r.has_key?(:author).should be_true
378 r = SheetPanel.show_opt[:include]
379 r.has_key?(:panel).should be_true
382 r = SheetPanel.show_opt[:include]
383 r[:panel].has_key?(:author).should be_true
386 r = SheetPanel.show_opt[:include]
387 r[:panel].has_key?(:panel_pictures).should be_true
389 it 'コマ絵は実素材を含んでいる' do
390 r = SheetPanel.show_opt[:include]
391 r[:panel][:panel_pictures].has_key?(:picture).should be_true
394 r = SheetPanel.show_opt[:include]
395 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
397 it '実素材はライセンスを含んでいる' do
398 r = SheetPanel.show_opt[:include]
399 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
401 it 'コマはフキダシを含んでいる' do
402 r = SheetPanel.show_opt[:include]
403 r[:panel].has_key?(:speech_balloons).should be_true
405 it 'フキダシはフキダシ枠を含んでいる' do
406 r = SheetPanel.show_opt[:include]
407 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
409 it 'フキダシはセリフを含んでいる' do
410 r = SheetPanel.show_opt[:include]
411 r[:panel][:speech_balloons].has_key?(:speech).should be_true
414 describe 'json単体取得オプションに於いて' do
417 describe '紙コマのjson出力に於いて' do
420 @panel = FactoryGirl.create :panel, :author_id => @author.id
421 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
422 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
423 @speech = @sb.build_speech(
424 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
426 @balloon = @sb.build_balloon(
427 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
431 @gc = @panel.ground_colors.create(
432 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
434 @gp = @panel.ground_pictures.create(
435 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
438 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
439 @item = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
441 context '事前チェックする' do
443 Panel.any_instance.stub(:elements).and_return('{}')
445 it 'コマ要素のjson出力を依頼している' do
446 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
447 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
448 r = @item.sheet_panel_as_json @author
451 it 'json textを返している' do
452 r = JSON.parse @item.sheet_panel_as_json(@author)
453 r.is_a?(Hash).should be_true
455 it 'sheet,author,panel,コマ要素を含んでいる' do
456 r = JSON.parse @item.sheet_panel_as_json(@author)
457 r.has_key?('sheet').should be_true
458 r['sheet'].has_key?('author').should be_true
459 r.has_key?('author').should be_true
460 r.has_key?('panel').should be_true
461 r['panel'].has_key?('author').should be_true
463 context 'コマ閲覧許可のとき' do
465 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
467 it 'コマ要素にコマ要素を追加している' do
468 r = JSON.parse @item.sheet_panel_as_json(@author)
469 r['panel'].has_key?('elements').should be_true
470 r['panel']['elements'].should_not be_empty
473 context 'コマ閲覧不許可のとき' do
475 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
477 it 'コマ要素にデータを含ませない' do
478 r = JSON.parse @item.sheet_panel_as_json(@author)
479 r['panel'].has_key?('elements').should be_false
484 describe '紙コマリストのjson出力に於いて' do
486 @panel = FactoryGirl.create :panel, :author_id => @author.id
487 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
488 @item = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
489 SheetPanel.any_instance.stub(:sheet_panel_as_json).with(@author).and_return('{"s": 5}')
491 context 'つつがなく終わるとき' do
492 it '紙コマのjson出力を依頼している' do
493 SheetPanel.any_instance.should_receive(:sheet_panel_as_json).with(@author).exactly(1)
494 r = SheetPanel.list_as_json_text [@item], @author
497 it 'json textを返している' do
498 r = SheetPanel.list_as_json_text [@item], @author
500 j.is_a?(Array).should be_true
503 r = SheetPanel.list_as_json_text [@item], @author
505 j.first.has_key?('s').should be_true
509 describe 't補充値に於いて' do
511 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
512 @panel = FactoryGirl.create :panel, :author_id => @author.id
515 context '用紙初のコマなら' do
517 @item = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
519 r = SheetPanel.new_t @item.sheet_id
523 context '用紙に一個コマがあるとき' do
525 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0
526 @item = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
528 r = SheetPanel.new_t @item.sheet_id
532 context '用紙に2個コマがあるとき' do
534 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0
535 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
536 @item = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
538 r = SheetPanel.new_t @item.sheet_id
543 describe 'シリアライズチェックに於いて' do
544 context 'つつがなく終わるとき' do
545 it '0からシリアライズされているならTrueを返す' do
546 r = SheetPanel.serial? [0, 1, 2]
549 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
550 r = SheetPanel.serial? [0, 2, 1]
553 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
554 r = SheetPanel.serial? [ 2, 1, 4, 3, 0]
559 it '0から始まらないならFalseを返す' do
560 r = SheetPanel.serial? [1, 2, 3]
563 it '連続していないならFalseを返す' do
564 r = SheetPanel.serial? [0, 1, 2, 4]
567 it '連続していないならFalseを返す' do
568 r = SheetPanel.serial? [0, 1, 2, 4, 5]
573 describe 't収集に於いて' do
575 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
576 @panel = FactoryGirl.create :panel, :author_id => @author.id
577 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
578 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
579 @c2sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
581 context 'つつがなく終わるとき' do
582 it '紙コマから同一用紙のtだけを収集している' do
583 r = SheetPanel.collect_t @item
588 it '紙コマから同一用紙のtだけを収集している' do
589 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
590 r = SheetPanel.collect_t @item
591 r.sort.should eq [0, 1]
594 context '複数コマでヨソの用紙も混じっているとき' do
595 it '紙コマから同一用紙のtだけを収集している' do
596 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
597 r = SheetPanel.collect_t @item
598 r.sort.should eq [0, 1]
602 describe 'tチェックに於いて' do
604 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
605 @panel = FactoryGirl.create :panel, :author_id => @author.id
606 @item = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
608 context 'つつがなく終わるとき' do
610 SheetPanel.should_receive(:collect_t).with(any_args).exactly(1)
611 SheetPanel.stub(:collect_t).with(any_args).and_return([])
612 SheetPanel.stub(:serial?).with(any_args).and_return(true)
613 r = SheetPanel.validate_t @item
615 it '収集したtをシリアライズチェック依頼している' do
616 SheetPanel.stub(:collect_t).with(any_args).and_return([])
617 SheetPanel.should_receive(:serial?).with(any_args).exactly(1)
618 SheetPanel.stub(:serial?).with(any_args).and_return(true)
619 r = SheetPanel.validate_t @item
623 #依頼チェックだけでは不安なので最低限のチェックを
625 it '一件だけで正常通過している' do
626 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
627 r = SheetPanel.validate_t @item
632 it '2件目を作っても正常通過している' do
633 @item = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
634 @item2 = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
635 r = SheetPanel.validate_t @item2
640 describe '挿入シフトに於いて' do
642 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
643 @panel = FactoryGirl.create :panel, :author_id => @author.id
647 it 'Updateを依頼している' do
648 SheetPanel.stub(:update_all).with(any_args)
649 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
650 @item = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
654 context 'テーブルに1件(t:0)で0に挿入したとき' do
656 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
657 @item2 = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
659 it '既存の行を1にシフトしている' do
661 l = SheetPanel.find :all
662 l.first.t.should eq 1
664 it 'これから挿入するt(0)が欠番になっている' do
666 l = SheetPanel.find(:all).map {|s| s.t }
667 l.include?(0).should_not be_true
670 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
672 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
673 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
674 @item3 = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
676 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
678 l = SheetPanel.find(:all).map {|s| s.t }
679 l.sort.should eq [0, 2]
682 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
684 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
685 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
686 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
687 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
688 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
689 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
691 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
693 l = SheetPanel.find(:all).map {|s| s.t }
694 l.sort.should eq [0, 1, 3, 4, 5]
697 context '先ほどのケース+他の用紙1件で挿入したとき' do
699 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
700 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
701 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
702 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
703 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
704 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
705 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
706 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
708 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
710 l = SheetPanel.find(:all, :conditions => ['sheet_id = ?', @sheet.id]).map {|s| s.t }
711 l.sort.should eq [0, 1, 3, 4, 5]
717 @itemc2.t.should eq ot
721 describe '少ない方に移動に於いて' do
723 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
724 @panel = FactoryGirl.create :panel, :author_id => @author.id
727 it 'Updateを依頼している' do
728 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
729 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
730 SheetPanel.stub(:update_all).with(any_args)
731 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
734 @item2.lesser_shift ot
737 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
739 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
740 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
744 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
746 @item2.lesser_shift @ot
747 l = SheetPanel.find(:all).map {|s| s.t }
748 l.sort.should eq [1, 1]
750 it '既存のt0を1にシフトしている' do
751 @item2.lesser_shift @ot
756 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
758 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
759 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
760 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
764 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
766 @item3.lesser_shift @ot
767 l = SheetPanel.find(:all).map {|s| s.t }
768 l.sort.should eq [0, 2, 2]
770 it '既存のt1を2にシフトしている' do
771 @item3.lesser_shift @ot
776 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
778 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
779 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
780 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
781 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
782 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
786 it 'これから挿入するt(1)が欠番になっている' do
788 @item4.lesser_shift @ot
789 l = SheetPanel.find(:all).map {|s| s.t }
790 l.sort.should eq [0, 2, 3, 3, 4]
793 @item4.lesser_shift @ot
798 @item4.lesser_shift @ot
802 it '既存のt1を2にシフトしている' do
803 @item4.lesser_shift @ot
807 it '既存のt2を3にシフトしている' do
808 @item4.lesser_shift @ot
813 context '先ほどのケース+他の用紙1件で挿入したとき' do
815 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
816 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
817 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
818 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
819 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
820 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
821 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
825 it 'これから挿入するt(1)が欠番になっている' do
826 @item4.lesser_shift @ot
827 l = SheetPanel.find(:all).map {|s| s.t }
828 l.sort.should eq [0, 0, 2, 3, 3, 4]
831 @item4.lesser_shift @ot
836 @item4.lesser_shift @ot
840 it '既存のt1を2にシフトしている' do
841 @item4.lesser_shift @ot
845 it '既存のt2を3にシフトしている' do
846 @item4.lesser_shift @ot
851 @item4.lesser_shift @ot
853 @itemc2.t.should eq 0
858 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
860 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
861 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
865 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
867 @item2.lesser_shift @ot
868 l = SheetPanel.find(:all).map {|s| s.t }
869 l.sort.should eq [1, 1]
871 it '既存のt0を1にシフトしている' do
872 @item2.lesser_shift @ot
876 it '既存のt1は0に補正されている' do
877 @item2.lesser_shift @ot
882 describe '大きい方に移動に於いて' do
884 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
885 @panel = FactoryGirl.create :panel, :author_id => @author.id
888 it 'Updateを依頼している' do
889 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
890 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
891 SheetPanel.stub(:update_all).with(any_args)
892 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
895 @item.higher_shift ot
898 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
900 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
901 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
905 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
907 @item.higher_shift @ot
908 l = SheetPanel.find(:all).map {|s| s.t }
909 l.sort.should eq [0, 0]
911 it '既存のt1を0にシフトしている' do
912 @item.higher_shift @ot
917 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
919 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
920 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
921 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
925 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
927 @item.higher_shift @ot
928 l = SheetPanel.find(:all).map {|s| s.t }
929 l.sort.should eq [0, 0, 2]
931 it '既存のt1を0にシフトしている' do
932 @item.higher_shift @ot
937 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
939 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
940 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
941 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
942 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
943 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
947 it 'これから挿入するt(3)が欠番になっている' do
949 @item2.higher_shift @ot
950 l = SheetPanel.find(:all).map {|s| s.t }
951 l.sort.should eq [0, 1, 1, 2, 4]
954 @item2.higher_shift @ot
959 @item2.higher_shift @ot
963 it '既存のt2を1にシフトしている' do
964 @item2.higher_shift @ot
968 it '既存のt3を2にシフトしている' do
969 @item2.higher_shift @ot
974 context '先ほどのケース+他の用紙1件で挿入したとき' do
976 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
977 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
978 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
979 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
980 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
981 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
982 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
986 it 'これから挿入するt(3)が欠番になっている' do
988 @item2.higher_shift @ot
989 l = SheetPanel.find(:all).map {|s| s.t }
990 l.sort.should eq [0, 0, 1, 1, 2, 4]
993 @item2.higher_shift @ot
998 @item2.higher_shift @ot
1000 @item5.t.should eq 4
1002 it '既存のt2を1にシフトしている' do
1003 @item2.higher_shift @ot
1005 @item3.t.should eq 1
1007 it '既存のt3を2にシフトしている' do
1008 @item2.higher_shift @ot
1010 @item4.t.should eq 2
1013 @item2.higher_shift @ot
1015 @itemc2.t.should eq 0
1019 #max超えたときはmaxとして正常扱い
1020 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1022 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1023 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1027 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1029 @item.higher_shift @ot
1030 l = SheetPanel.find(:all).map {|s| s.t }
1031 l.sort.should eq [0, 0]
1033 it '既存のt1を0にシフトしている' do
1034 @item.higher_shift @ot
1036 @item2.t.should eq 0
1038 it '既存のt0は1に補正されている' do
1039 @item.higher_shift @ot
1044 describe '入れ替えに於いて' do
1046 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1047 @panel = FactoryGirl.create :panel, :author_id => @author.id
1048 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1049 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1051 context '新tが旧tより小さいとき' do
1052 it '少ない方に移動を依頼している' do
1053 SheetPanel.any_instance.stub(:lesser_shift).with(any_args)
1054 SheetPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1057 @item2.update_shift ot
1060 context '新tが旧tより大きいとき' do
1061 it '大きい方に移動を依頼している' do
1062 SheetPanel.any_instance.stub(:higher_shift).with(any_args)
1063 SheetPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1066 @item.update_shift ot
1070 describe '順序入れ替えに於いて' do
1072 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1073 @panel = FactoryGirl.create :panel, :author_id => @author.id
1075 context 'オブジェクトが新規でtが空のとき' do
1076 it '末尾追加としてtを補充依頼している' do
1077 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1078 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1079 SheetPanel.should_receive(:new_t).with(any_args).exactly(1)
1084 context 'オブジェクトが新規でtが設定されているとき' do
1085 it '挿入追加として挿入シフトを依頼している' do
1086 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1087 SheetPanel.any_instance.stub(:insert_shift).with(any_args)
1088 SheetPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1093 context 'オブジェクトが新規でなくtが設定されているとき' do
1094 it 'コマ移動として入れ替えを依頼している' do
1095 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1096 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1097 SheetPanel.any_instance.stub(:update_shift).with(any_args)
1098 SheetPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
1103 context 'オブジェクトが新規でなくtが空のとき' do
1104 it '入れ替えもシフトもせず、tを空のままにしている' do
1105 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1109 describe '編集許可に於いて' do
1111 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1112 @panel = FactoryGirl.create :panel, :author_id => @author.id
1113 @item = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1115 context 'つつがなく終わるとき' do
1121 context '用紙で引っかかるとき' do
1123 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1124 Sheet.any_instance.stub(:own?).with(any_args).and_return(false)
1129 context 'コマで引っかかるとき' do
1131 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
1132 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1137 context '用紙またはコマが指定されていなかったとき' do
1139 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
1140 @item.panel_id = nil
1145 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1146 @item.sheet_id = nil
1152 describe '保存に於いて' do
1154 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1155 @panel = FactoryGirl.create :panel, :author_id => @author.id
1156 @item = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1158 context 'つつがなく終わるとき' do
1159 it '編集許可チェックを依頼している' do
1160 SheetPanel.any_instance.stub(:allow?).with(any_args).and_return(true)
1161 SheetPanel.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1164 it '順序入れ替えを依頼している' do
1165 SheetPanel.any_instance.stub(:rotate).with(any_args).and_return(0)
1166 SheetPanel.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1167 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1168 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1172 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1173 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1174 SheetPanel.any_instance.should_receive(:save).with(any_args).exactly(1)
1175 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1178 it 'tのシリアライズチェックを依頼している' do
1179 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1180 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1181 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1182 SheetPanel.should_receive(:validate_t).with(any_args).exactly(1)
1186 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1187 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したとき' do
1189 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1190 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1191 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1192 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1193 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1194 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1195 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1196 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1198 it '既存のt0には変化がない' do
1203 it '既存のt1には変化がない' do
1206 @item2.t.should eq 1
1208 it '既存のt2を3にシフトしている' do
1211 @item3.t.should eq 3
1213 it '既存のt3を4にシフトしている' do
1216 @item4.t.should eq 4
1218 it '既存のt5を5にシフトしている' do
1221 @item5.t.should eq 5
1223 it '新規のt2が作成されている' do
1226 @item6.t.should eq 2
1232 @itemc2.t.should eq @ot
1235 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したとき' do
1237 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1238 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1239 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1240 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1241 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1242 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1243 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1247 it '既存のt0には変化がない' do
1252 it '既存のt4には変化がない' do
1255 @item5.t.should eq 4
1257 it '既存のt1を2にシフトしている' do
1260 @item2.t.should eq 2
1262 it '既存のt2を3にシフトしている' do
1265 @item3.t.should eq 3
1267 it '既存のt3を1にシフトしている' do
1270 @item4.t.should eq 1
1275 @itemc2.t.should eq 0
1278 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で1を3に移動したとき' do
1280 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1281 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1282 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1283 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1284 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1285 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1286 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1290 it '既存のt0には変化がない' do
1295 it '既存のt4には変化がない' do
1298 @item5.t.should eq 4
1300 it '既存のt1を3にシフトしている' do
1303 @item2.t.should eq 3
1305 it '既存のt2を1にシフトしている' do
1308 @item3.t.should eq 1
1310 it '既存のt3を2にシフトしている' do
1313 @item4.t.should eq 2
1318 @itemc2.t.should eq 0
1321 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1322 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したが保存に失敗したとき' do
1324 SheetPanel.any_instance.stub(:save).with(any_args).and_return(false)
1325 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1326 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1327 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1328 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1329 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1330 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1331 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1332 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1339 @item2.t.should eq 1
1341 @item3.t.should eq 2
1343 @item4.t.should eq 3
1345 @item5.t.should eq 4
1347 @itemc2.t.should eq 0
1354 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したがシリアルチェックに失敗したとき' do
1356 SheetPanel.stub(:validate_t).with(any_args).and_return(false)
1357 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1358 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1359 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1360 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1361 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1362 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1363 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1372 @item2.t.should eq 1
1374 @item3.t.should eq 2
1376 @item4.t.should eq 3
1378 @item5.t.should eq 4
1380 @itemc2.t.should eq 0
1383 r = @item4.store @ot
1386 it 'tにエラーメッセージが入っている' do
1388 @item4.errors[:t].should_not be_empty
1389 @item4.valid?.should be_true
1392 context '編集不可だったとき' do
1394 @item = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1395 SheetPanel.any_instance.stub(:allow?).and_return(false)
1397 it '403Forbidden例外を返す' do
1400 }.should raise_error(ActiveRecord::Forbidden)
1404 describe '切り詰め処理つき削除に於いて' do
1406 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1407 @panel = FactoryGirl.create :panel, :author_id => @author.id
1408 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1410 context 'つつがなく終わるとき' do
1413 @item.destroy_and_shorten
1414 }.should change(SheetPanel, :count ).by(-1)
1417 r = @item.destroy_and_shorten
1421 context '削除に失敗したとき' do
1423 SheetPanel.any_instance.stub(:destroy).and_return(false)
1427 @item.destroy_and_shorten
1428 }.should_not change(SheetPanel, :count )
1431 r = @item.destroy_and_shorten
1435 #連携テスト。切り詰めが直接DBをいじる
1436 context '2件で先頭を削除したとき' do
1438 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1442 @item.destroy_and_shorten
1443 }.should change(SheetPanel, :count ).by(-1)
1446 @item.destroy_and_shorten
1448 SheetPanel.find @item.id
1449 }.should raise_error(ActiveRecord::RecordNotFound)
1452 @item.destroy_and_shorten
1454 @item2.t.should eq 0
1457 context '3件で先頭を削除したとき' do
1459 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1460 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1464 @item.destroy_and_shorten
1465 }.should change(SheetPanel, :count ).by(-1)
1468 @item.destroy_and_shorten
1470 SheetPanel.find @item.id
1471 }.should raise_error(ActiveRecord::RecordNotFound)
1474 @item.destroy_and_shorten
1476 @item2.t.should eq 0
1479 @item.destroy_and_shorten
1481 @item3.t.should eq 1
1484 context '5件で3件目を削除したとき' do
1486 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1487 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1488 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1489 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1493 @item3.destroy_and_shorten
1494 }.should change(SheetPanel, :count ).by(-1)
1497 @item3.destroy_and_shorten
1502 @item3.destroy_and_shorten
1504 @item2.t.should eq 1
1507 @item3.destroy_and_shorten
1509 SheetPanel.find @item3.id
1510 }.should raise_error(ActiveRecord::RecordNotFound)
1513 @item3.destroy_and_shorten
1515 @item4.t.should eq 2
1518 @item3.destroy_and_shorten
1520 @item5.t.should eq 3
1523 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する