1 # -*- encoding: utf-8 -*-
8 @admin =FactoryGirl.create :admin
9 @user_yas = FactoryGirl.create :user_yas_with_owner
10 @user_rom = FactoryGirl.create :user_rom
11 @author_yas = @user_yas.author
14 describe '生成メソッドに於いて' do
16 @item = FactoryGirl.create :sheet_install_a_with_sheet_panels, author: @author_yas
21 describe 'copy_attributesに於いて' do
23 @item = FactoryGirl.create :sheet_install_a_with_sheet_panels, author: @author_yas
26 it 'ブーストメッセージをリーフに伝搬する' do
35 @admin =FactoryGirl.create :admin
36 @user_yas = FactoryGirl.create :user_yas_with_owner
37 @user_rom = FactoryGirl.create :user_rom
38 @author_yas = @user_yas.author
41 describe '生成メソッドに於いて' do
43 @item = FactoryGirl.create :panel_hello_with_scroll_panels, author: @author_yas
50 describe ScrollPanel do
53 @admin =FactoryGirl.create :admin
54 @user_yas = FactoryGirl.create :user_yas_with_owner
55 @user_rom = FactoryGirl.create :user_rom
56 @author_yas = @user_yas.author
61 describe 'new_tに於いて' do
63 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
66 context 'オーソドックスなデータのとき' do
68 expect(@model.new_t(@scroll.id)).to eq 0
73 context 'オーソドックスなデータのとき' do
75 @item = FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
76 expect(@model.new_t(@scroll.id)).to eq 1
80 @item = FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
81 @item = FactoryGirl.create :scroll_panel_plain, z: 2, t: 1, scroll: @scroll, panel: @panel
82 @item = FactoryGirl.create :scroll_panel_plain, z: 3, t: 2, scroll: @scroll, panel: @panel
83 expect(@model.new_t(@scroll.id)).to eq 3
90 describe 'collect_tに於いて' do
92 @dummy = FactoryGirl.create :scroll_great_with_scroll_panels, author: @author_yas
93 @scroll = FactoryGirl.create :scroll_hello, author: @author_yas
96 context 'オーソドックスなデータのとき' do
98 expect(@model.collect_t(@scroll.id)).to be_empty
103 context 'オーソドックスなデータのとき' do
105 @item = FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
106 expect(@model.collect_t(@scroll.id)).to eq [0]
110 @item = FactoryGirl.create :scroll_panel_plain, z: 1, t: 0, scroll: @scroll, panel: @panel
111 @item = FactoryGirl.create :scroll_panel_plain, z: 2, t: 1, scroll: @scroll, panel: @panel
112 @item = FactoryGirl.create :scroll_panel_plain, z: 3, t: 2, scroll: @scroll, panel: @panel
113 expect(@model.collect_t(@scroll.id)).to eq [0, 1, 2]
120 describe 'tチェックに於いて' do
122 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
123 @panel = FactoryGirl.create :panel, :author_id => @author.id
124 @item = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
126 context 'つつがなく終わるとき' do
128 SheetPanel.should_receive(:collect_t).with(any_args).exactly(1)
129 SheetPanel.stub(:collect_t).with(any_args).and_return([])
130 SheetPanel.stub(:serial?).with(any_args).and_return(true)
131 r = SheetPanel.validate_t @item
133 it '収集したtをシリアライズチェック依頼している' do
134 SheetPanel.stub(:collect_t).with(any_args).and_return([])
135 SheetPanel.should_receive(:serial?).with(any_args).exactly(1)
136 SheetPanel.stub(:serial?).with(any_args).and_return(true)
137 r = SheetPanel.validate_t @item
141 #依頼チェックだけでは不安なので最低限のチェックを
143 it '一件だけで正常通過している' do
144 @item = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
145 r = SheetPanel.validate_t @item
150 it '2件目を作っても正常通過している' do
151 @item = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
152 @item2 = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
153 r = SheetPanel.validate_t @item2
160 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
161 @panel = FactoryGirl.create :panel, :author_id => @author.id
162 @item = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
164 context 'つつがなく終わるとき' do
165 it '編集許可チェックを依頼している' do
166 SheetPanel.any_instance.stub(:allow?).with(any_args).and_return(true)
167 SheetPanel.any_instance.should_receive(:allow?).with(any_args).exactly(1)
170 it '順序入れ替えを依頼している' do
171 SheetPanel.any_instance.stub(:rotate).with(any_args).and_return(0)
172 SheetPanel.any_instance.should_receive(:rotate).with(any_args).exactly(1)
173 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
174 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
178 SheetPanel.stub(:new_t).with(any_args).and_return(0)
179 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
180 SheetPanel.any_instance.should_receive(:save).with(any_args).exactly(1)
181 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
184 it 'tのシリアライズチェックを依頼している' do
185 SheetPanel.stub(:new_t).with(any_args).and_return(0)
186 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
187 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
188 SheetPanel.should_receive(:validate_t).with(any_args).exactly(1)
192 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
193 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したとき' do
195 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
196 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
197 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
198 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
199 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
200 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
201 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
202 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
214 it '既存のt2を3にシフトしている' do
219 it '既存のt3を4にシフトしている' do
224 it '既存のt5を5にシフトしている' do
229 it '新規のt2が作成されている' do
238 @itemc2.t.should eq @ot
241 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したとき' do
243 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
244 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
245 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
246 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
247 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
248 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
249 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
263 it '既存のt1を2にシフトしている' do
268 it '既存のt2を3にシフトしている' do
273 it '既存のt3を1にシフトしている' do
281 @itemc2.t.should eq 0
284 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で1を3に移動したとき' do
286 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
287 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
288 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
289 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
290 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
291 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
292 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
306 it '既存のt1を3にシフトしている' do
311 it '既存のt2を1にシフトしている' do
316 it '既存のt3を2にシフトしている' do
324 @itemc2.t.should eq 0
327 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
328 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したが保存に失敗したとき' do
330 SheetPanel.any_instance.stub(:save).with(any_args).and_return(false)
331 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
332 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
333 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
334 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
335 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
336 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
337 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
338 @item6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
353 @itemc2.t.should eq 0
360 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したがシリアルチェックに失敗したとき' do
362 SheetPanel.stub(:validate_t).with(any_args).and_return(false)
363 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
364 @itemc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
365 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
366 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
367 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
368 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
369 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
386 @itemc2.t.should eq 0
392 it 'tにエラーメッセージが入っている' do
394 @item4.errors[:t].should_not be_empty
395 @item4.valid?.should be_true
398 context '編集不可だったとき' do
400 @item = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
401 SheetPanel.any_instance.stub(:allow?).and_return(false)
403 it '403Forbidden例外を返す' do
406 }.should raise_error(ActiveRecord::Forbidden)
410 describe '切り詰め処理つき削除に於いて' do
412 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
413 @panel = FactoryGirl.create :panel, :author_id => @author.id
414 @item = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
416 context 'つつがなく終わるとき' do
419 @item.destroy_and_shorten
420 }.should change(SheetPanel, :count ).by(-1)
423 r = @item.destroy_and_shorten
427 context '削除に失敗したとき' do
429 SheetPanel.any_instance.stub(:destroy).and_return(false)
433 @item.destroy_and_shorten
434 }.should_not change(SheetPanel, :count )
437 r = @item.destroy_and_shorten
442 context '2件で先頭を削除したとき' do
444 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
448 @item.destroy_and_shorten
449 }.should change(SheetPanel, :count ).by(-1)
452 @item.destroy_and_shorten
454 SheetPanel.find @item.id
455 }.should raise_error(ActiveRecord::RecordNotFound)
458 @item.destroy_and_shorten
463 context '3件で先頭を削除したとき' do
465 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
466 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
470 @item.destroy_and_shorten
471 }.should change(SheetPanel, :count ).by(-1)
474 @item.destroy_and_shorten
476 SheetPanel.find @item.id
477 }.should raise_error(ActiveRecord::RecordNotFound)
480 @item.destroy_and_shorten
485 @item.destroy_and_shorten
490 context '5件で3件目を削除したとき' do
492 @item2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
493 @item3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
494 @item4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
495 @item5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
499 @item3.destroy_and_shorten
500 }.should change(SheetPanel, :count ).by(-1)
503 @item3.destroy_and_shorten
508 @item3.destroy_and_shorten
513 @item3.destroy_and_shorten
515 SheetPanel.find @item3.id
516 }.should raise_error(ActiveRecord::RecordNotFound)
519 @item3.destroy_and_shorten
524 @item3.destroy_and_shorten
529 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する