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
325 c = SheetPanel.play_list @sheet, @author
326 c.should eq [@sheet_panel]
329 #公開用紙の公開コマは(他人の用紙であっても)含んでいる
330 v = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
331 c = SheetPanel.play_list @sheet, @author
332 c.should eq [ @sheet_panel, v]
335 h = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel2.id, :t => 1
336 c = SheetPanel.play_list @sheet, @author
337 c.should eq [ @sheet_panel, h]
341 describe '一覧取得に於いて' do
343 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
344 @panel = FactoryGirl.create :panel, :author_id => @author.id
345 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
346 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
347 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
348 @hidden_sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
350 context 'page補正について' do
351 it '文字列から数値に変換される' do
352 SheetPanel.page('8').should eq 8
355 SheetPanel.page().should eq 1
358 SheetPanel.page('0').should eq 1
361 context 'page_size補正について' do
362 it '文字列から数値に変換される' do
363 SheetPanel.page_size('7').should eq 7
365 it 'nilの場合はSheetPanel.default_page_sizeになる' do
366 SheetPanel.page_size().should eq SheetPanel.default_page_size
368 it '0以下の場合はSheetPanel.default_page_sizeになる' do
369 SheetPanel.page_size('0').should eq SheetPanel.default_page_size
371 it 'SheetPanel.max_page_sizeを超えた場合はSheetPanel.max_page_sizeになる' do
372 SheetPanel.page_size('1000').should eq SheetPanel.max_page_size
377 c.should eq [@sheet_panel]
380 #公開用紙のSheetPanelは(他人のSheetPanelであっても)含んでいる
381 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
383 c.should eq [ v, @sheet_panel]
385 it '非公開の紙コマは(自分の紙コマであっても)含まない' do
386 h = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @hidden_sheet.id, :panel_id => @panel.id, :t => 0
388 c.should eq [ @sheet_panel]
390 context 'DBに5件あって1ページの件数を2件に変えたとして' do
392 @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
393 @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
394 @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
395 @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
398 l = SheetPanel.list 1, 2
399 l.should have(2).items
401 it 'page=1なら末尾2件を返す' do
403 l = SheetPanel.list 1, 2
404 l.should eq [@sheet_panel5, @sheet_panel4]
406 it 'page=2なら中間2件を返す' do
407 l = SheetPanel.list 2, 2
408 l.should eq [@sheet_panel3, @sheet_panel2]
410 it 'page=3なら先頭1件を返す' do
411 l = SheetPanel.list 3, 2
412 l.should eq [@sheet_panel]
417 describe '自分の紙コマ一覧取得に於いて' do
419 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
420 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
421 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
422 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
423 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
424 @hsheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
425 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
427 context 'つつがなく終わるとき' do
428 it '一覧取得オプションを利用している' do
429 SheetPanel.stub(:list_opt).with(any_args).and_return({})
430 SheetPanel.should_receive(:list_opt).with(any_args).exactly(1)
431 r = SheetPanel.mylist @author
435 s = SheetPanel.mylist @author
436 s.should eq [@sheet_panel]
439 ns = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
440 sl = SheetPanel.mylist @author
441 sl.should eq [ns, @sheet_panel]
443 it '他人の紙コマはコマ用紙ともに公開でも含まない' do
444 so = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id
445 sl = SheetPanel.mylist @author
446 sl.should eq [@sheet_panel]
448 it '自分の紙コマはコマ用紙ともに非公開でも含んでいる' do
449 hs = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @hsheet.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
450 sl = SheetPanel.mylist @author
451 sl.should eq [hs, @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
459 SheetPanel.stub(:default_page_size).and_return(2)
462 l = SheetPanel.mylist @author, 1, 2
463 l.should have(2).items
465 it 'page=1なら末尾2件を返す' do
467 l = SheetPanel.mylist @author, 1, 2
468 l.should eq [@sheet_panel5, @sheet_panel4]
470 it 'page=2なら中間2件を返す' do
471 l = SheetPanel.mylist @author, 2, 2
472 l.should eq [@sheet_panel3, @sheet_panel2]
474 it 'page=3なら先頭1件を返す' do
475 l = SheetPanel.mylist @author, 3, 2
476 l.should eq [@sheet_panel]
481 describe '他作家の紙コマ一覧取得に於いて' do
483 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
484 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
485 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
486 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
487 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
488 @other_sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id
491 r = SheetPanel.himlist @other_author
492 r.should eq [@other_sheet_panel]
495 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
496 r = SheetPanel.himlist @other_author
497 r.should eq [ns, @other_sheet_panel]
500 @hsheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 0
501 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
502 r = SheetPanel.himlist @other_author
503 r.should eq [@other_sheet_panel]
505 context 'DBに5件あって1ページの件数を2件に変えたとして' do
507 @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
508 @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
509 @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
510 @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
511 SheetPanel.stub(:default_page_size).and_return(2)
514 l = SheetPanel.himlist @other_author, 1, 2
515 l.should have(2).items
517 it 'page=1なら末尾2件を返す' do
519 l = SheetPanel.himlist @other_author, 1, 2
520 l.should eq [@other_sheet_panel5, @other_sheet_panel4]
522 it 'page=2なら中間2件を返す' do
523 l = SheetPanel.himlist @other_author, 2, 2
524 l.should eq [@other_sheet_panel3, @other_sheet_panel2]
526 it 'page=3なら先頭1件を返す' do
527 l = SheetPanel.himlist @other_author, 3, 2
528 l.should eq [@other_sheet_panel]
533 describe '紙コマ一覧ページ制御に於いて' do
535 SheetPanel.stub(:count).with(any_args).and_return(100)
538 r = SheetPanel.list_paginate
539 r.is_a?(Kaminari::PaginatableArray).should be_true
541 it '紙コマ一覧の取得条件を利用している' do
542 SheetPanel.stub(:list_where).with(any_args).and_return('')
543 SheetPanel.should_receive(:list_where).with(any_args).exactly(1)
544 r = SheetPanel.list_paginate
546 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
547 r = SheetPanel.list_paginate 3, 10
548 r.limit_value.should eq 10
549 r.offset_value.should eq 20
553 describe '自分の紙コマ一覧ページ制御に於いて' do
555 SheetPanel.stub(:count).with(any_args).and_return(100)
558 r = SheetPanel.mylist_paginate @author
559 r.is_a?(Kaminari::PaginatableArray).should be_true
561 it '自分の紙コマ一覧の取得条件を利用している' do
562 SheetPanel.stub(:mylist_where).with(any_args).and_return('')
563 SheetPanel.should_receive(:mylist_where).with(any_args).exactly(1)
564 r = SheetPanel.mylist_paginate @author
566 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
567 r = SheetPanel.mylist_paginate @author, 3, 10
568 r.limit_value.should eq 10
569 r.offset_value.should eq 20
573 describe '他作家の紙コマ一覧ページ制御に於いて' do
575 SheetPanel.stub(:count).with(any_args).and_return(100)
578 r = SheetPanel.himlist_paginate @other_author
579 r.is_a?(Kaminari::PaginatableArray).should be_true
581 it '他作家の紙コマ一覧の取得条件を利用している' do
582 SheetPanel.stub(:himlist_where).with(any_args).and_return('')
583 SheetPanel.should_receive(:himlist_where).with(any_args).exactly(1)
584 r = SheetPanel.himlist_paginate @other_author
586 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
587 r = SheetPanel.himlist_paginate @other_author, 3, 10
588 r.limit_value.should eq 10
589 r.offset_value.should eq 20
593 describe 'list関連テーブルプションに於いて' do
595 r = SheetPanel.list_opt
596 r.should have(3).items
599 r = SheetPanel.list_opt
600 r.has_key?(:sheet).should be_true
603 r = SheetPanel.list_opt
604 r[:sheet].has_key?(:author).should be_true
607 r = SheetPanel.list_opt
608 r.has_key?(:author).should be_true
611 r = SheetPanel.list_opt
612 r.has_key?(:panel).should be_true
615 r = SheetPanel.list_opt
616 r[:panel].has_key?(:author).should be_true
619 r = SheetPanel.list_opt
620 r[:panel].has_key?(:panel_pictures).should be_true
622 it 'コマ絵は実素材を含んでいる' do
623 r = SheetPanel.list_opt
624 r[:panel][:panel_pictures].has_key?(:picture).should be_true
627 r = SheetPanel.list_opt
628 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
630 it '実素材はライセンスを含んでいる' do
631 r = SheetPanel.list_opt
632 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
634 it 'コマはフキダシを含んでいる' do
635 r = SheetPanel.list_opt
636 r[:panel].has_key?(:speech_balloons).should be_true
638 it 'フキダシはフキダシ枠を含んでいる' do
639 r = SheetPanel.list_opt
640 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
642 it 'フキダシはセリフを含んでいる' do
643 r = SheetPanel.list_opt
644 r[:panel][:speech_balloons].has_key?(:speech).should be_true
647 describe 'json一覧出力オプションに於いて' do
650 describe '単体取得に於いて' do
652 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
653 @panel = FactoryGirl.create :panel, :author_id => @author.id
654 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
656 context 'つつがなく終わるとき' do
657 it '単体取得オプションを利用している' do
658 SheetPanel.stub(:show_opt).with(any_args).and_return({})
659 SheetPanel.should_receive(:show_opt).with(any_args).exactly(1)
660 r = SheetPanel.show @sheet_panel.id, @author
662 it '閲覧許可を問い合わせている' do
663 SheetPanel.any_instance.stub(:visible?).with(@author).and_return(true)
664 SheetPanel.any_instance.should_receive(:visible?).with(@author).exactly(1)
665 r = SheetPanel.show @sheet_panel.id, @author
669 l = SheetPanel.show @sheet_panel.id, @author
670 l.should eq @sheet_panel
672 context '他人の紙コマを開こうとしたとき' do
673 it '403Forbidden例外を返す' do
674 SheetPanel.any_instance.stub(:visible?).with(@other_author).and_return(false)
676 SheetPanel.show @sheet_panel.id, @other_author
677 }.should raise_error(ActiveRecord::Forbidden)
680 context '存在しない紙コマを開こうとしたとき' do
681 it '404RecordNotFound例外を返す' do
683 SheetPanel.show 110, @author
684 }.should raise_error(ActiveRecord::RecordNotFound)
689 describe '編集取得に於いて' do
691 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
692 @panel = FactoryGirl.create :panel, :author_id => @author.id
693 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
695 context 'つつがなく終わるとき' do
696 it '単体取得オプションを利用している' do
697 SheetPanel.stub(:show_opt).with(any_args).and_return({})
698 SheetPanel.should_receive(:show_opt).with(any_args).exactly(1)
699 r = SheetPanel.edit @sheet_panel.id, @author
701 it '所持判定を問い合わせている' do
702 SheetPanel.any_instance.stub(:own?).with(any_args).and_return(true)
703 SheetPanel.any_instance.should_receive(:own?).with(any_args).exactly(1)
704 r = SheetPanel.edit @sheet_panel.id, @author
708 l = SheetPanel.edit @sheet_panel.id, @author
709 l.should eq @sheet_panel
711 context '他人の紙コマを開こうとしたとき' do
712 it '403Forbidden例外を返す' do
713 SheetPanel.any_instance.stub(:own?).and_return(false)
715 SheetPanel.edit @sheet_panel.id, @author
716 }.should raise_error(ActiveRecord::Forbidden)
719 context '存在しない紙コマを開こうとしたとき' do
720 it '404RecordNotFound例外を返す' do
722 SheetPanel.edit 110, @author
723 }.should raise_error(ActiveRecord::RecordNotFound)
728 describe '単体取得オプションに於いて' do
729 it 'includeキーを含んでいる' do
730 r = SheetPanel.show_opt
731 r.has_key?(:include).should be_true
734 r = SheetPanel.show_opt[:include]
735 r.should have(3).items
738 r = SheetPanel.show_opt[:include]
739 r.has_key?(:sheet).should be_true
742 r = SheetPanel.show_opt[:include]
743 r[:sheet].has_key?(:author).should be_true
746 r = SheetPanel.show_opt[:include]
747 r.has_key?(:author).should be_true
750 r = SheetPanel.show_opt[:include]
751 r.has_key?(:panel).should be_true
754 r = SheetPanel.show_opt[:include]
755 r[:panel].has_key?(:author).should be_true
758 r = SheetPanel.show_opt[:include]
759 r[:panel].has_key?(:panel_pictures).should be_true
761 it 'コマ絵は実素材を含んでいる' do
762 r = SheetPanel.show_opt[:include]
763 r[:panel][:panel_pictures].has_key?(:picture).should be_true
766 r = SheetPanel.show_opt[:include]
767 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
769 it '実素材はライセンスを含んでいる' do
770 r = SheetPanel.show_opt[:include]
771 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
773 it 'コマはフキダシを含んでいる' do
774 r = SheetPanel.show_opt[:include]
775 r[:panel].has_key?(:speech_balloons).should be_true
777 it 'フキダシはフキダシ枠を含んでいる' do
778 r = SheetPanel.show_opt[:include]
779 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
781 it 'フキダシはセリフを含んでいる' do
782 r = SheetPanel.show_opt[:include]
783 r[:panel][:speech_balloons].has_key?(:speech).should be_true
786 describe 'json単体取得オプションに於いて' do
789 describe '紙コマのjson出力に於いて' do
792 @panel = FactoryGirl.create :panel, :author_id => @author.id
793 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
794 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
795 @speech = @sb.build_speech(
796 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
798 @balloon = @sb.build_balloon(
799 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
803 @gc = @panel.ground_colors.create(
804 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
806 @gp = @panel.ground_pictures.create(
807 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
810 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
811 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
813 context '事前チェックする' do
815 Panel.any_instance.stub(:elements).and_return('{}')
817 it 'コマ要素のjson出力を依頼している' do
818 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
819 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
820 r = @sheet_panel.sheet_panel_as_json @author
823 it 'json textを返している' do
824 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
825 r.is_a?(Hash).should be_true
827 it 'sheet,author,panel,コマ要素を含んでいる' do
828 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
829 r.has_key?('sheet').should be_true
830 r['sheet'].has_key?('author').should be_true
831 r.has_key?('author').should be_true
832 r.has_key?('panel').should be_true
833 r['panel'].has_key?('author').should be_true
835 context 'コマ閲覧許可のとき' do
837 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
839 it 'コマ要素にコマ要素を追加している' do
840 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
841 r['panel'].has_key?('elements').should be_true
842 r['panel']['elements'].should_not be_empty
845 context 'コマ閲覧不許可のとき' do
847 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
849 it 'コマ要素にデータを含ませない' do
850 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
851 r['panel'].has_key?('elements').should be_false
856 describe '紙コマリストのjson出力に於いて' do
858 @panel = FactoryGirl.create :panel, :author_id => @author.id
859 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
860 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
861 SheetPanel.any_instance.stub(:sheet_panel_as_json).with(@author).and_return('{"s": 5}')
863 context 'つつがなく終わるとき' do
864 it '紙コマのjson出力を依頼している' do
865 SheetPanel.any_instance.should_receive(:sheet_panel_as_json).with(@author).exactly(1)
866 r = SheetPanel.list_as_json_text [@sheet_panel], @author
869 it 'json textを返している' do
870 r = SheetPanel.list_as_json_text [@sheet_panel], @author
872 j.is_a?(Array).should be_true
875 r = SheetPanel.list_as_json_text [@sheet_panel], @author
877 j.first.has_key?('s').should be_true
881 describe 't補充値に於いて' do
883 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
884 @panel = FactoryGirl.create :panel, :author_id => @author.id
887 context '用紙初のコマなら' do
889 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
891 r = SheetPanel.new_t @sheet_panel.sheet_id
895 context '用紙に一個コマがあるとき' do
897 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0
898 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
900 r = SheetPanel.new_t @sheet_panel.sheet_id
904 context '用紙に2個コマがあるとき' do
906 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0
907 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
908 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
910 r = SheetPanel.new_t @sheet_panel.sheet_id
915 describe 'シリアライズチェックに於いて' do
916 context 'つつがなく終わるとき' do
917 it '0からシリアライズされているならTrueを返す' do
918 r = SheetPanel.serial? [0, 1, 2]
921 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
922 r = SheetPanel.serial? [0, 2, 1]
925 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
926 r = SheetPanel.serial? [ 2, 1, 4, 3, 0]
931 it '0から始まらないならFalseを返す' do
932 r = SheetPanel.serial? [1, 2, 3]
935 it '連続していないならFalseを返す' do
936 r = SheetPanel.serial? [0, 1, 2, 4]
939 it '連続していないならFalseを返す' do
940 r = SheetPanel.serial? [0, 1, 2, 4, 5]
945 describe 't収集に於いて' do
947 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
948 @panel = FactoryGirl.create :panel, :author_id => @author.id
949 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
950 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
951 @c2sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
953 context 'つつがなく終わるとき' do
954 it '紙コマから同一用紙のtだけを収集している' do
955 r = SheetPanel.collect_t @sheet_panel
960 it '紙コマから同一用紙のtだけを収集している' do
961 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
962 r = SheetPanel.collect_t @sheet_panel
963 r.sort.should eq [0, 1]
966 context '複数コマでヨソの用紙も混じっているとき' do
967 it '紙コマから同一用紙のtだけを収集している' do
968 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
969 r = SheetPanel.collect_t @sheet_panel
970 r.sort.should eq [0, 1]
974 describe 'tチェックに於いて' do
976 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
977 @panel = FactoryGirl.create :panel, :author_id => @author.id
978 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
980 context 'つつがなく終わるとき' do
982 SheetPanel.should_receive(:collect_t).with(any_args).exactly(1)
983 SheetPanel.stub(:collect_t).with(any_args).and_return([])
984 SheetPanel.stub(:serial?).with(any_args).and_return(true)
985 r = SheetPanel.validate_t @sheet_panel
987 it '収集したtをシリアライズチェック依頼している' do
988 SheetPanel.stub(:collect_t).with(any_args).and_return([])
989 SheetPanel.should_receive(:serial?).with(any_args).exactly(1)
990 SheetPanel.stub(:serial?).with(any_args).and_return(true)
991 r = SheetPanel.validate_t @sheet_panel
995 #依頼チェックだけでは不安なので最低限のチェックを
997 it '一件だけで正常通過している' do
998 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
999 r = SheetPanel.validate_t @sheet_panel
1004 it '2件目を作っても正常通過している' do
1005 @sheet_panel = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1006 @sheet_panel2 = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
1007 r = SheetPanel.validate_t @sheet_panel2
1012 describe '挿入シフトに於いて' do
1014 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1015 @panel = FactoryGirl.create :panel, :author_id => @author.id
1019 it 'Updateを依頼している' do
1020 SheetPanel.stub(:update_all).with(any_args)
1021 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1022 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1023 @sheet_panel.insert_shift
1026 context 'テーブルに1件(t:0)で0に挿入したとき' do
1028 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1029 @sheet_panel2 = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1031 it '既存の行を1にシフトしている' do
1032 @sheet_panel2.insert_shift
1033 l = SheetPanel.find :all
1034 l.first.t.should eq 1
1036 it 'これから挿入するt(0)が欠番になっている' do
1037 @sheet_panel2.insert_shift
1038 l = SheetPanel.find(:all).map {|s| s.t }
1039 l.include?(0).should_not be_true
1042 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
1044 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1045 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1046 @sheet_panel3 = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1048 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1049 @sheet_panel3.insert_shift
1050 l = SheetPanel.find(:all).map {|s| s.t }
1051 l.sort.should eq [0, 2]
1054 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
1056 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1057 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1058 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1059 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1060 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1061 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1063 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1064 @sheet_panel6.insert_shift
1065 l = SheetPanel.find(:all).map {|s| s.t }
1066 l.sort.should eq [0, 1, 3, 4, 5]
1069 context '先ほどのケース+他の用紙1件で挿入したとき' do
1071 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1072 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1073 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1074 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1075 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1076 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1077 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1078 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1080 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1081 @sheet_panel6.insert_shift
1082 l = SheetPanel.find(:all, :conditions => ['sheet_id = ?', @sheet.id]).map {|s| s.t }
1083 l.sort.should eq [0, 1, 3, 4, 5]
1086 ot = @sheet_panelc2.t
1087 @sheet_panel6.insert_shift
1088 @sheet_panelc2.reload
1089 @sheet_panelc2.t.should eq ot
1093 describe '少ない方に移動に於いて' do
1095 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1096 @panel = FactoryGirl.create :panel, :author_id => @author.id
1099 it 'Updateを依頼している' do
1100 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1101 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1102 SheetPanel.stub(:update_all).with(any_args)
1103 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1104 ot = @sheet_panel2.t
1106 @sheet_panel2.lesser_shift ot
1109 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
1111 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1112 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1113 @ot = @sheet_panel2.t
1116 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1118 @sheet_panel2.lesser_shift @ot
1119 l = SheetPanel.find(:all).map {|s| s.t }
1120 l.sort.should eq [1, 1]
1122 it '既存のt0を1にシフトしている' do
1123 @sheet_panel2.lesser_shift @ot
1125 @sheet_panel.t.should eq 1
1128 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
1130 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1131 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1132 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1133 @ot = @sheet_panel3.t
1136 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1138 @sheet_panel3.lesser_shift @ot
1139 l = SheetPanel.find(:all).map {|s| s.t }
1140 l.sort.should eq [0, 2, 2]
1142 it '既存のt1を2にシフトしている' do
1143 @sheet_panel3.lesser_shift @ot
1144 @sheet_panel2.reload
1145 @sheet_panel2.t.should eq 2
1148 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
1150 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1151 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1152 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1153 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1154 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1155 @ot = @sheet_panel4.t
1158 it 'これから挿入するt(1)が欠番になっている' do
1160 @sheet_panel4.lesser_shift @ot
1161 l = SheetPanel.find(:all).map {|s| s.t }
1162 l.sort.should eq [0, 2, 3, 3, 4]
1164 it '既存のt0には変化がない' do
1165 @sheet_panel4.lesser_shift @ot
1167 @sheet_panel.t.should eq 0
1169 it '既存のt4には変化がない' do
1170 @sheet_panel4.lesser_shift @ot
1171 @sheet_panel5.reload
1172 @sheet_panel5.t.should eq 4
1174 it '既存のt1を2にシフトしている' do
1175 @sheet_panel4.lesser_shift @ot
1176 @sheet_panel2.reload
1177 @sheet_panel2.t.should eq 2
1179 it '既存のt2を3にシフトしている' do
1180 @sheet_panel4.lesser_shift @ot
1181 @sheet_panel3.reload
1182 @sheet_panel3.t.should eq 3
1185 context '先ほどのケース+他の用紙1件で挿入したとき' do
1187 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1188 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1189 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1190 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1191 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1192 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1193 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1194 @ot = @sheet_panel4.t
1197 it 'これから挿入するt(1)が欠番になっている' do
1198 @sheet_panel4.lesser_shift @ot
1199 l = SheetPanel.find(:all).map {|s| s.t }
1200 l.sort.should eq [0, 0, 2, 3, 3, 4]
1202 it '既存のt0には変化がない' do
1203 @sheet_panel4.lesser_shift @ot
1205 @sheet_panel.t.should eq 0
1207 it '既存のt4には変化がない' do
1208 @sheet_panel4.lesser_shift @ot
1209 @sheet_panel5.reload
1210 @sheet_panel5.t.should eq 4
1212 it '既存のt1を2にシフトしている' do
1213 @sheet_panel4.lesser_shift @ot
1214 @sheet_panel2.reload
1215 @sheet_panel2.t.should eq 2
1217 it '既存のt2を3にシフトしている' do
1218 @sheet_panel4.lesser_shift @ot
1219 @sheet_panel3.reload
1220 @sheet_panel3.t.should eq 3
1223 @sheet_panel4.lesser_shift @ot
1224 @sheet_panelc2.reload
1225 @sheet_panelc2.t.should eq 0
1230 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
1232 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1233 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1234 @ot = @sheet_panel2.t
1235 @sheet_panel2.t = -1
1237 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1239 @sheet_panel2.lesser_shift @ot
1240 l = SheetPanel.find(:all).map {|s| s.t }
1241 l.sort.should eq [1, 1]
1243 it '既存のt0を1にシフトしている' do
1244 @sheet_panel2.lesser_shift @ot
1246 @sheet_panel.t.should eq 1
1248 it '既存のt1は0に補正されている' do
1249 @sheet_panel2.lesser_shift @ot
1250 @sheet_panel2.t.should eq 0
1254 describe '大きい方に移動に於いて' do
1256 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1257 @panel = FactoryGirl.create :panel, :author_id => @author.id
1260 it 'Updateを依頼している' do
1261 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1262 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1263 SheetPanel.stub(:update_all).with(any_args)
1264 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1267 @sheet_panel.higher_shift ot
1270 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1272 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1273 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1274 @ot = @sheet_panel.t
1277 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1279 @sheet_panel.higher_shift @ot
1280 l = SheetPanel.find(:all).map {|s| s.t }
1281 l.sort.should eq [0, 0]
1283 it '既存のt1を0にシフトしている' do
1284 @sheet_panel.higher_shift @ot
1285 @sheet_panel2.reload
1286 @sheet_panel2.t.should eq 0
1289 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1291 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1292 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1293 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1294 @ot = @sheet_panel.t
1297 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1299 @sheet_panel.higher_shift @ot
1300 l = SheetPanel.find(:all).map {|s| s.t }
1301 l.sort.should eq [0, 0, 2]
1303 it '既存のt1を0にシフトしている' do
1304 @sheet_panel.higher_shift @ot
1305 @sheet_panel2.reload
1306 @sheet_panel2.t.should eq 0
1309 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1311 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1312 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1313 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1314 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1315 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1316 @ot = @sheet_panel2.t
1319 it 'これから挿入するt(3)が欠番になっている' do
1321 @sheet_panel2.higher_shift @ot
1322 l = SheetPanel.find(:all).map {|s| s.t }
1323 l.sort.should eq [0, 1, 1, 2, 4]
1325 it '既存のt0には変化がない' do
1326 @sheet_panel2.higher_shift @ot
1328 @sheet_panel.t.should eq 0
1330 it '既存のt4には変化がない' do
1331 @sheet_panel2.higher_shift @ot
1332 @sheet_panel5.reload
1333 @sheet_panel5.t.should eq 4
1335 it '既存のt2を1にシフトしている' do
1336 @sheet_panel2.higher_shift @ot
1337 @sheet_panel3.reload
1338 @sheet_panel3.t.should eq 1
1340 it '既存のt3を2にシフトしている' do
1341 @sheet_panel2.higher_shift @ot
1342 @sheet_panel4.reload
1343 @sheet_panel4.t.should eq 2
1346 context '先ほどのケース+他の用紙1件で挿入したとき' do
1348 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1349 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1350 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1351 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1352 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1353 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1354 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1355 @ot = @sheet_panel2.t
1358 it 'これから挿入するt(3)が欠番になっている' do
1360 @sheet_panel2.higher_shift @ot
1361 l = SheetPanel.find(:all).map {|s| s.t }
1362 l.sort.should eq [0, 0, 1, 1, 2, 4]
1364 it '既存のt0には変化がない' do
1365 @sheet_panel2.higher_shift @ot
1367 @sheet_panel.t.should eq 0
1369 it '既存のt4には変化がない' do
1370 @sheet_panel2.higher_shift @ot
1371 @sheet_panel5.reload
1372 @sheet_panel5.t.should eq 4
1374 it '既存のt2を1にシフトしている' do
1375 @sheet_panel2.higher_shift @ot
1376 @sheet_panel3.reload
1377 @sheet_panel3.t.should eq 1
1379 it '既存のt3を2にシフトしている' do
1380 @sheet_panel2.higher_shift @ot
1381 @sheet_panel4.reload
1382 @sheet_panel4.t.should eq 2
1385 @sheet_panel2.higher_shift @ot
1386 @sheet_panelc2.reload
1387 @sheet_panelc2.t.should eq 0
1391 #max超えたときはmaxとして正常扱い
1392 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1394 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1395 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1396 @ot = @sheet_panel.t
1399 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1401 @sheet_panel.higher_shift @ot
1402 l = SheetPanel.find(:all).map {|s| s.t }
1403 l.sort.should eq [0, 0]
1405 it '既存のt1を0にシフトしている' do
1406 @sheet_panel.higher_shift @ot
1407 @sheet_panel2.reload
1408 @sheet_panel2.t.should eq 0
1410 it '既存のt0は1に補正されている' do
1411 @sheet_panel.higher_shift @ot
1412 @sheet_panel.t.should eq 1
1416 describe '入れ替えに於いて' do
1418 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1419 @panel = FactoryGirl.create :panel, :author_id => @author.id
1420 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1421 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1423 context '新tが旧tより小さいとき' do
1424 it '少ない方に移動を依頼している' do
1425 SheetPanel.any_instance.stub(:lesser_shift).with(any_args)
1426 SheetPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1427 ot = @sheet_panel2.t
1429 @sheet_panel2.update_shift ot
1432 context '新tが旧tより大きいとき' do
1433 it '大きい方に移動を依頼している' do
1434 SheetPanel.any_instance.stub(:higher_shift).with(any_args)
1435 SheetPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1438 @sheet_panel.update_shift ot
1442 describe '順序入れ替えに於いて' do
1444 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1445 @panel = FactoryGirl.create :panel, :author_id => @author.id
1447 context 'オブジェクトが新規でtが空のとき' do
1448 it '末尾追加としてtを補充依頼している' do
1449 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1450 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1451 SheetPanel.should_receive(:new_t).with(any_args).exactly(1)
1452 @sheet_panel.t = nil
1453 r = @sheet_panel.rotate
1456 context 'オブジェクトが新規でtが設定されているとき' do
1457 it '挿入追加として挿入シフトを依頼している' do
1458 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1459 SheetPanel.any_instance.stub(:insert_shift).with(any_args)
1460 SheetPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1462 r = @sheet_panel.rotate
1465 context 'オブジェクトが新規でなくtが設定されているとき' do
1466 it 'コマ移動として入れ替えを依頼している' do
1467 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1468 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1469 SheetPanel.any_instance.stub(:update_shift).with(any_args)
1470 SheetPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
1472 r = @sheet_panel.rotate 1
1475 context 'オブジェクトが新規でなくtが空のとき' do
1476 it '入れ替えもシフトもせず、tを空のままにしている' do
1477 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1481 describe '編集許可に於いて' do
1483 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1484 @panel = FactoryGirl.create :panel, :author_id => @author.id
1485 @sheet_panel = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1487 context 'つつがなく終わるとき' do
1489 r = @sheet_panel.allow?
1493 context '用紙で引っかかるとき' do
1495 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1496 Sheet.any_instance.stub(:own?).with(any_args).and_return(false)
1497 r = @sheet_panel.allow?
1501 context 'コマで引っかかるとき' do
1503 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
1504 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1505 r = @sheet_panel.allow?
1509 context '用紙またはコマが指定されていなかったとき' do
1511 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
1512 @sheet_panel.panel_id = nil
1513 r = @sheet_panel.allow?
1517 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1518 @sheet_panel.sheet_id = nil
1519 r = @sheet_panel.allow?
1524 describe '保存に於いて' do
1526 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1527 @panel = FactoryGirl.create :panel, :author_id => @author.id
1528 @sheet_panel = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1530 context 'つつがなく終わるとき' do
1531 it '編集許可チェックを依頼している' do
1532 SheetPanel.any_instance.stub(:allow?).with(any_args).and_return(true)
1533 SheetPanel.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1534 r = @sheet_panel.store
1536 it '順序入れ替えを依頼している' do
1537 SheetPanel.any_instance.stub(:rotate).with(any_args).and_return(0)
1538 SheetPanel.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1539 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1540 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1541 r = @sheet_panel.store
1544 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1545 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1546 SheetPanel.any_instance.should_receive(:save).with(any_args).exactly(1)
1547 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1548 r = @sheet_panel.store
1550 it 'tのシリアライズチェックを依頼している' do
1551 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1552 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1553 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1554 SheetPanel.should_receive(:validate_t).with(any_args).exactly(1)
1555 r = @sheet_panel.store
1558 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1559 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したとき' do
1561 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1562 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1563 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1564 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1565 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1566 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1567 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1568 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1570 it '既存のt0には変化がない' do
1573 @sheet_panel.t.should eq 0
1575 it '既存のt1には変化がない' do
1577 @sheet_panel2.reload
1578 @sheet_panel2.t.should eq 1
1580 it '既存のt2を3にシフトしている' do
1582 @sheet_panel3.reload
1583 @sheet_panel3.t.should eq 3
1585 it '既存のt3を4にシフトしている' do
1587 @sheet_panel4.reload
1588 @sheet_panel4.t.should eq 4
1590 it '既存のt5を5にシフトしている' do
1592 @sheet_panel5.reload
1593 @sheet_panel5.t.should eq 5
1595 it '新規のt2が作成されている' do
1597 @sheet_panel6.reload
1598 @sheet_panel6.t.should eq 2
1601 @ot = @sheet_panelc2.t
1603 @sheet_panelc2.reload
1604 @sheet_panelc2.t.should eq @ot
1607 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したとき' do
1609 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1610 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1611 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1612 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1613 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1614 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1615 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1616 @ot = @sheet_panel4.t
1619 it '既存のt0には変化がない' do
1620 @sheet_panel4.store @ot
1622 @sheet_panel.t.should eq 0
1624 it '既存のt4には変化がない' do
1625 @sheet_panel4.store @ot
1626 @sheet_panel5.reload
1627 @sheet_panel5.t.should eq 4
1629 it '既存のt1を2にシフトしている' do
1630 @sheet_panel4.store @ot
1631 @sheet_panel2.reload
1632 @sheet_panel2.t.should eq 2
1634 it '既存のt2を3にシフトしている' do
1635 @sheet_panel4.store @ot
1636 @sheet_panel3.reload
1637 @sheet_panel3.t.should eq 3
1639 it '既存のt3を1にシフトしている' do
1640 @sheet_panel4.store @ot
1641 @sheet_panel4.reload
1642 @sheet_panel4.t.should eq 1
1645 @sheet_panel4.store @ot
1646 @sheet_panelc2.reload
1647 @sheet_panelc2.t.should eq 0
1650 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で1を3に移動したとき' do
1652 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1653 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1654 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1655 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1656 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1657 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1658 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1659 @ot = @sheet_panel2.t
1662 it '既存のt0には変化がない' do
1663 @sheet_panel2.store @ot
1665 @sheet_panel.t.should eq 0
1667 it '既存のt4には変化がない' do
1668 @sheet_panel2.store @ot
1669 @sheet_panel5.reload
1670 @sheet_panel5.t.should eq 4
1672 it '既存のt1を3にシフトしている' do
1673 @sheet_panel2.store @ot
1674 @sheet_panel2.reload
1675 @sheet_panel2.t.should eq 3
1677 it '既存のt2を1にシフトしている' do
1678 @sheet_panel2.store @ot
1679 @sheet_panel3.reload
1680 @sheet_panel3.t.should eq 1
1682 it '既存のt3を2にシフトしている' do
1683 @sheet_panel2.store @ot
1684 @sheet_panel4.reload
1685 @sheet_panel4.t.should eq 2
1688 @sheet_panel2.store @ot
1689 @sheet_panelc2.reload
1690 @sheet_panelc2.t.should eq 0
1693 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1694 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したが保存に失敗したとき' do
1696 SheetPanel.any_instance.stub(:save).with(any_args).and_return(false)
1697 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1698 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1699 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1700 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1701 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1702 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1703 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1704 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1709 @sheet_panel.t.should eq 0
1710 @sheet_panel2.reload
1711 @sheet_panel2.t.should eq 1
1712 @sheet_panel3.reload
1713 @sheet_panel3.t.should eq 2
1714 @sheet_panel4.reload
1715 @sheet_panel4.t.should eq 3
1716 @sheet_panel5.reload
1717 @sheet_panel5.t.should eq 4
1718 @sheet_panelc2.reload
1719 @sheet_panelc2.t.should eq 0
1722 r = @sheet_panel6.store
1726 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したがシリアルチェックに失敗したとき' do
1728 SheetPanel.stub(:validate_t).with(any_args).and_return(false)
1729 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1730 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1731 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1732 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1733 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1734 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1735 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1736 @ot = @sheet_panel4.t
1740 @sheet_panel4.store @ot
1742 @sheet_panel.t.should eq 0
1743 @sheet_panel2.reload
1744 @sheet_panel2.t.should eq 1
1745 @sheet_panel3.reload
1746 @sheet_panel3.t.should eq 2
1747 @sheet_panel4.reload
1748 @sheet_panel4.t.should eq 3
1749 @sheet_panel5.reload
1750 @sheet_panel5.t.should eq 4
1751 @sheet_panelc2.reload
1752 @sheet_panelc2.t.should eq 0
1755 r = @sheet_panel4.store @ot
1758 it 'tにエラーメッセージが入っている' do
1759 @sheet_panel4.store @ot
1760 @sheet_panel4.errors[:t].should_not be_empty
1761 @sheet_panel4.valid?.should be_true
1764 context '編集不可だったとき' do
1766 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1767 SheetPanel.any_instance.stub(:allow?).and_return(false)
1769 it '403Forbidden例外を返す' do
1772 }.should raise_error(ActiveRecord::Forbidden)
1776 describe '切り詰め処理つき削除に於いて' do
1778 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1779 @panel = FactoryGirl.create :panel, :author_id => @author.id
1780 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1782 context 'つつがなく終わるとき' do
1785 @sheet_panel.destroy_and_shorten
1786 }.should change(SheetPanel, :count ).by(-1)
1789 r = @sheet_panel.destroy_and_shorten
1793 context '削除に失敗したとき' do
1795 SheetPanel.any_instance.stub(:destroy).and_return(false)
1799 @sheet_panel.destroy_and_shorten
1800 }.should_not change(SheetPanel, :count )
1803 r = @sheet_panel.destroy_and_shorten
1807 #連携テスト。切り詰めが直接DBをいじる
1808 context '2件で先頭を削除したとき' do
1810 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1814 @sheet_panel.destroy_and_shorten
1815 }.should change(SheetPanel, :count ).by(-1)
1818 @sheet_panel.destroy_and_shorten
1820 SheetPanel.find @sheet_panel.id
1821 }.should raise_error(ActiveRecord::RecordNotFound)
1824 @sheet_panel.destroy_and_shorten
1825 @sheet_panel2.reload
1826 @sheet_panel2.t.should eq 0
1829 context '3件で先頭を削除したとき' do
1831 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1832 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1836 @sheet_panel.destroy_and_shorten
1837 }.should change(SheetPanel, :count ).by(-1)
1840 @sheet_panel.destroy_and_shorten
1842 SheetPanel.find @sheet_panel.id
1843 }.should raise_error(ActiveRecord::RecordNotFound)
1846 @sheet_panel.destroy_and_shorten
1847 @sheet_panel2.reload
1848 @sheet_panel2.t.should eq 0
1851 @sheet_panel.destroy_and_shorten
1852 @sheet_panel3.reload
1853 @sheet_panel3.t.should eq 1
1856 context '5件で3件目を削除したとき' do
1858 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1859 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1860 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1861 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1865 @sheet_panel3.destroy_and_shorten
1866 }.should change(SheetPanel, :count ).by(-1)
1869 @sheet_panel3.destroy_and_shorten
1871 @sheet_panel.t.should eq 0
1874 @sheet_panel3.destroy_and_shorten
1875 @sheet_panel2.reload
1876 @sheet_panel2.t.should eq 1
1879 @sheet_panel3.destroy_and_shorten
1881 SheetPanel.find @sheet_panel3.id
1882 }.should raise_error(ActiveRecord::RecordNotFound)
1885 @sheet_panel3.destroy_and_shorten
1886 @sheet_panel4.reload
1887 @sheet_panel4.t.should eq 2
1890 @sheet_panel3.destroy_and_shorten
1891 @sheet_panel5.reload
1892 @sheet_panel5.t.should eq 3
1895 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する