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 = 'a'
51 @sheet_panel.should_not be_valid
55 context 'panel_idを検証するとき' do
57 @sheet_panel.panel_id = 'a'
58 @sheet_panel.should_not be_valid
65 @sheet_panel.should_not be_valid
69 @sheet_panel.should_not be_valid
73 @sheet_panel.should be_valid
77 @sheet_panel.should be_valid
83 @sheet_panel.should_not be_valid
87 @sheet_panel.should_not be_valid
91 @sheet_panel.should be_valid
95 @sheet_panel.should be_valid
101 @sheet_panel.should_not be_valid
105 @sheet_panel.should_not be_valid
109 @sheet_panel.should_not be_valid
113 @sheet_panel.should_not be_valid
116 context 'tを検証するとき' do
119 @sheet_panel.should_not be_valid
123 @sheet_panel.should_not be_valid
127 @sheet_panel.should_not be_valid
131 context 'author_idを検証するとき' do
133 @sheet_panel.author_id = nil
134 @sheet_panel.should_not be_valid
137 @sheet_panel.author_id = 'a'
138 @sheet_panel.should_not be_valid
140 it '存在する作家でなければ失敗する' do
141 @sheet_panel.author_id = 0
142 @sheet_panel.should_not be_valid
145 context '全体を検証するとき' do
149 describe 'デフォルト値補充に於いて' do
151 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
152 @panel = FactoryGirl.create :panel, :author_id => @author.id
155 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
157 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id
158 @sheet_panel.supply_default
159 @sheet_panel.t.should be_nil
164 describe '上書き補充に於いて' do
166 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
167 @panel = FactoryGirl.create :panel, :author_id => @author.id
170 context 'author_idを補充' do
171 it '問答無用でauthor_idを補充する' do
172 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id
173 @sheet_panel.author_id = nil
174 @sheet_panel.overwrite @author
175 @sheet_panel.author_id.should eq @author.id
181 describe '所持判定に於いて' do
183 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
184 @panel = FactoryGirl.create :panel, :author_id => @author.id
185 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
186 @sheeto = FactoryGirl.create :sheet, :author_id => @other_author.id
187 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
188 @sheet_panelo = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @sheeto.id, :panel_id => @panelo.id
190 context '事前チェックする' do
191 it '自身にロールリストからの作家取得を依頼している' do
192 SheetPanel.should_receive(:get_author_from_roles).with(any_args).exactly(1)
193 r = @sheet_panel.own?([@author])
196 context 'ロール内作家が取得できるとき' do
199 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
200 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(@author)
201 r = @sheet_panel.own?([@author])
204 it 'ロール内作家のidが自身の作家idと一致しないならno' do
205 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
206 @sheet_panel.own?(@other_author).should be_false
209 context 'ロール内作家が取得できないとき' do
211 SheetPanel.stub(:get_author_from_roles).with(any_args).and_return(nil)
214 r = @sheet_panel.own?([@author])
220 describe '閲覧許可に於いて' do
222 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
223 @panel = FactoryGirl.create :panel, :author_id => @author.id
224 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
226 context 'オープンモードのとき' do
228 MagicNumber['run_mode'] = 0
230 it '自身にゲスト用ロールチェックを問い合わせしている' do
231 SheetPanel.any_instance.stub(:guest_role_check).and_return(true)
232 SheetPanel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
233 r = @sheet_panel.visible?([@author])
235 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
236 SheetPanel.any_instance.stub(:guest_role_check).and_return(false)
237 r = @sheet_panel.visible?([@author])
241 context 'クローズドモードのとき' do
243 MagicNumber['run_mode'] = 1
245 it '自身に読者用ロールチェックを問い合わせしている' do
246 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
247 SheetPanel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
248 r = @sheet_panel.visible?([@author])
250 it '読者用ロールチェックが失敗したとき、falseを返す' do
251 SheetPanel.any_instance.stub(:reader_role_check).and_return(false)
252 r = @sheet_panel.visible?([@author])
256 context '事前チェックする' do
258 MagicNumber['run_mode'] = 1
259 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
261 it '自身の用紙に所持判定を問い合わせしている' do
262 Sheet.any_instance.stub(:own?).and_return(true)
263 Sheet.any_instance.should_receive(:own?).with(any_args).exactly(1)
264 r = @sheet_panel.visible?([@author])
266 it '自身の用紙に閲覧許可を問い合わせしている' do
267 Sheet.any_instance.stub(:own?).and_return(false)
268 Sheet.any_instance.stub(:visible?).and_return(true)
269 Sheet.any_instance.should_receive(:visible?).with(any_args).exactly(1)
270 r = @sheet_panel.visible?([@author])
273 context 'つつがなく終わるとき' do
275 MagicNumber['run_mode'] = 1
276 SheetPanel.any_instance.stub(:reader_role_check).and_return(true)
278 it '自分の用紙の紙コマなら許可する' do
279 Sheet.any_instance.stub(:own?).and_return(true)
280 Sheet.any_instance.stub(:visible).and_return(0)
281 r = @sheet_panel.visible?([@author])
284 it '他人の非公開用紙の紙コマなら許可しない' do
285 Sheet.any_instance.stub(:own?).and_return(false)
286 Sheet.any_instance.stub(:visible).and_return(0)
287 r = @sheet_panel.visible?([@author])
290 it '他人の用紙の紙コマでも公開なら許可する' do
291 Sheet.any_instance.stub(:own?).and_return(false)
292 Sheet.any_instance.stub(:visible).and_return(1)
293 r = @sheet_panel.visible?([@author])
299 describe 'プレイリスト取得に於いて' do
301 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
302 @panel = FactoryGirl.create :panel, :author_id => @author.id
303 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
304 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
305 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
306 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
309 c = SheetPanel.play_list @sheet, @author
310 c.should eq [@sheet_panel]
313 #公開用紙の公開コマは(他人の用紙であっても)含んでいる
314 v = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
315 c = SheetPanel.play_list @sheet, @author
316 c.should eq [ @sheet_panel, v]
319 h = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel2.id, :t => 1
320 c = SheetPanel.play_list @sheet, @author
321 c.should eq [ @sheet_panel, h]
325 describe '一覧取得に於いて' do
327 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
328 @panel = FactoryGirl.create :panel, :author_id => @author.id
329 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
330 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
331 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
332 @hidden_sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
334 context 'page補正について' do
335 it '文字列から数値に変換される' do
336 SheetPanel.page('8').should eq 8
339 SheetPanel.page().should eq 1
342 SheetPanel.page('0').should eq 1
345 context 'page_size補正について' do
346 it '文字列から数値に変換される' do
347 SheetPanel.page_size('7').should eq 7
349 it 'nilの場合はSheetPanel.default_page_sizeになる' do
350 SheetPanel.page_size().should eq SheetPanel.default_page_size
352 it '0以下の場合はSheetPanel.default_page_sizeになる' do
353 SheetPanel.page_size('0').should eq SheetPanel.default_page_size
355 it 'SheetPanel.max_page_sizeを超えた場合はSheetPanel.max_page_sizeになる' do
356 SheetPanel.page_size('1000').should eq SheetPanel.max_page_size
361 c.should eq [@sheet_panel]
364 #公開用紙のSheetPanelは(他人のSheetPanelであっても)含んでいる
365 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
367 c.should eq [ v, @sheet_panel]
369 it '非公開の紙コマは(自分の紙コマであっても)含まない' do
370 h = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @hidden_sheet.id, :panel_id => @panel.id, :t => 0
372 c.should eq [ @sheet_panel]
374 context 'DBに5件あって1ページの件数を2件に変えたとして' do
376 @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
377 @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
378 @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
379 @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
382 l = SheetPanel.list 1, 2
383 l.should have(2).items
385 it 'page=1なら末尾2件を返す' do
387 l = SheetPanel.list 1, 2
388 l.should eq [@sheet_panel5, @sheet_panel4]
390 it 'page=2なら中間2件を返す' do
391 l = SheetPanel.list 2, 2
392 l.should eq [@sheet_panel3, @sheet_panel2]
394 it 'page=3なら先頭1件を返す' do
395 l = SheetPanel.list 3, 2
396 l.should eq [@sheet_panel]
401 describe '自分の紙コマ一覧取得に於いて' do
403 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
404 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
405 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
406 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
407 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
408 @hsheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 0
409 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
411 context 'つつがなく終わるとき' do
412 it '一覧取得オプションを利用している' do
413 SheetPanel.stub(:list_opt).with(any_args).and_return({})
414 SheetPanel.should_receive(:list_opt).with(any_args).exactly(1)
415 r = SheetPanel.mylist @author
419 s = SheetPanel.mylist @author
420 s.should eq [@sheet_panel]
423 ns = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
424 sl = SheetPanel.mylist @author
425 sl.should eq [ns, @sheet_panel]
427 it '他人の紙コマはコマ用紙ともに公開でも含まない' do
428 so = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id
429 sl = SheetPanel.mylist @author
430 sl.should eq [@sheet_panel]
432 it '自分の紙コマはコマ用紙ともに非公開でも含んでいる' do
433 hs = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @hsheet.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
434 sl = SheetPanel.mylist @author
435 sl.should eq [hs, @sheet_panel]
437 context 'DBに5件あって1ページの件数を2件に変えたとして' do
439 @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
440 @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
441 @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
442 @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
443 SheetPanel.stub(:default_page_size).and_return(2)
446 l = SheetPanel.mylist @author, 1, 2
447 l.should have(2).items
449 it 'page=1なら末尾2件を返す' do
451 l = SheetPanel.mylist @author, 1, 2
452 l.should eq [@sheet_panel5, @sheet_panel4]
454 it 'page=2なら中間2件を返す' do
455 l = SheetPanel.mylist @author, 2, 2
456 l.should eq [@sheet_panel3, @sheet_panel2]
458 it 'page=3なら先頭1件を返す' do
459 l = SheetPanel.mylist @author, 3, 2
460 l.should eq [@sheet_panel]
465 describe '他作家の紙コマ一覧取得に於いて' do
467 @sheet = FactoryGirl.create :sheet, :author_id => @author.id, :visible => 1
468 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
469 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
470 @other_sheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 1
471 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
472 @other_sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @other_author.id, :sheet_id => @other_sheet.id, :panel_id => @other_panel.id
475 r = SheetPanel.himlist @other_author
476 r.should eq [@other_sheet_panel]
479 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
480 r = SheetPanel.himlist @other_author
481 r.should eq [ns, @other_sheet_panel]
484 @hsheet = FactoryGirl.create :sheet, :author_id => @other_author.id, :visible => 0
485 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
486 r = SheetPanel.himlist @other_author
487 r.should eq [@other_sheet_panel]
489 context 'DBに5件あって1ページの件数を2件に変えたとして' do
491 @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
492 @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
493 @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
494 @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
495 SheetPanel.stub(:default_page_size).and_return(2)
498 l = SheetPanel.himlist @other_author, 1, 2
499 l.should have(2).items
501 it 'page=1なら末尾2件を返す' do
503 l = SheetPanel.himlist @other_author, 1, 2
504 l.should eq [@other_sheet_panel5, @other_sheet_panel4]
506 it 'page=2なら中間2件を返す' do
507 l = SheetPanel.himlist @other_author, 2, 2
508 l.should eq [@other_sheet_panel3, @other_sheet_panel2]
510 it 'page=3なら先頭1件を返す' do
511 l = SheetPanel.himlist @other_author, 3, 2
512 l.should eq [@other_sheet_panel]
517 describe '紙コマ一覧ページ制御に於いて' do
519 SheetPanel.stub(:count).with(any_args).and_return(100)
522 r = SheetPanel.list_paginate
523 r.is_a?(Kaminari::PaginatableArray).should be_true
525 it '紙コマ一覧の取得条件を利用している' do
526 SheetPanel.stub(:list_where).with(any_args).and_return('')
527 SheetPanel.should_receive(:list_where).with(any_args).exactly(1)
528 r = SheetPanel.list_paginate
530 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
531 r = SheetPanel.list_paginate 3, 10
532 r.limit_value.should eq 10
533 r.offset_value.should eq 20
537 describe '自分の紙コマ一覧ページ制御に於いて' do
539 SheetPanel.stub(:count).with(any_args).and_return(100)
542 r = SheetPanel.mylist_paginate @author
543 r.is_a?(Kaminari::PaginatableArray).should be_true
545 it '自分の紙コマ一覧の取得条件を利用している' do
546 SheetPanel.stub(:mylist_where).with(any_args).and_return('')
547 SheetPanel.should_receive(:mylist_where).with(any_args).exactly(1)
548 r = SheetPanel.mylist_paginate @author
550 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
551 r = SheetPanel.mylist_paginate @author, 3, 10
552 r.limit_value.should eq 10
553 r.offset_value.should eq 20
557 describe '他作家の紙コマ一覧ページ制御に於いて' do
559 SheetPanel.stub(:count).with(any_args).and_return(100)
562 r = SheetPanel.himlist_paginate @other_author
563 r.is_a?(Kaminari::PaginatableArray).should be_true
565 it '他作家の紙コマ一覧の取得条件を利用している' do
566 SheetPanel.stub(:himlist_where).with(any_args).and_return('')
567 SheetPanel.should_receive(:himlist_where).with(any_args).exactly(1)
568 r = SheetPanel.himlist_paginate @other_author
570 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
571 r = SheetPanel.himlist_paginate @other_author, 3, 10
572 r.limit_value.should eq 10
573 r.offset_value.should eq 20
577 describe 'list関連テーブルプションに於いて' do
579 r = SheetPanel.list_opt
580 r.should have(3).items
583 r = SheetPanel.list_opt
584 r.has_key?(:sheet).should be_true
587 r = SheetPanel.list_opt
588 r[:sheet].has_key?(:author).should be_true
591 r = SheetPanel.list_opt
592 r.has_key?(:author).should be_true
595 r = SheetPanel.list_opt
596 r.has_key?(:panel).should be_true
599 r = SheetPanel.list_opt
600 r[:panel].has_key?(:author).should be_true
603 r = SheetPanel.list_opt
604 r[:panel].has_key?(:panel_pictures).should be_true
606 it 'コマ絵は実素材を含んでいる' do
607 r = SheetPanel.list_opt
608 r[:panel][:panel_pictures].has_key?(:picture).should be_true
611 r = SheetPanel.list_opt
612 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
614 it '実素材はライセンスを含んでいる' do
615 r = SheetPanel.list_opt
616 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
618 it 'コマはフキダシを含んでいる' do
619 r = SheetPanel.list_opt
620 r[:panel].has_key?(:speech_balloons).should be_true
622 it 'フキダシはフキダシ枠を含んでいる' do
623 r = SheetPanel.list_opt
624 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
626 it 'フキダシはセリフを含んでいる' do
627 r = SheetPanel.list_opt
628 r[:panel][:speech_balloons].has_key?(:speech).should be_true
631 describe 'json一覧出力オプションに於いて' do
634 describe '単体取得に於いて' do
636 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
637 @panel = FactoryGirl.create :panel, :author_id => @author.id
638 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
640 context 'つつがなく終わるとき' do
641 it '単体取得オプションを利用している' do
642 SheetPanel.stub(:show_opt).with(any_args).and_return({})
643 SheetPanel.should_receive(:show_opt).with(any_args).exactly(1)
644 r = SheetPanel.show @sheet_panel.id, @author
646 it '閲覧許可を問い合わせている' do
647 SheetPanel.any_instance.stub(:visible?).with(@author).and_return(true)
648 SheetPanel.any_instance.should_receive(:visible?).with(@author).exactly(1)
649 r = SheetPanel.show @sheet_panel.id, @author
653 l = SheetPanel.show @sheet_panel.id, @author
654 l.should eq @sheet_panel
656 context '他人の紙コマを開こうとしたとき' do
657 it '403Forbidden例外を返す' do
658 SheetPanel.any_instance.stub(:visible?).with(@other_author).and_return(false)
660 SheetPanel.show @sheet_panel.id, @other_author
661 }.should raise_error(ActiveRecord::Forbidden)
664 context '存在しない紙コマを開こうとしたとき' do
665 it '404RecordNotFound例外を返す' do
667 SheetPanel.show 110, @author
668 }.should raise_error(ActiveRecord::RecordNotFound)
673 describe '編集取得に於いて' do
675 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
676 @panel = FactoryGirl.create :panel, :author_id => @author.id
677 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
679 context 'つつがなく終わるとき' do
680 it '単体取得オプションを利用している' do
681 SheetPanel.stub(:show_opt).with(any_args).and_return({})
682 SheetPanel.should_receive(:show_opt).with(any_args).exactly(1)
683 r = SheetPanel.edit @sheet_panel.id, @author
685 it '所持判定を問い合わせている' do
686 SheetPanel.any_instance.stub(:own?).with(any_args).and_return(true)
687 SheetPanel.any_instance.should_receive(:own?).with(any_args).exactly(1)
688 r = SheetPanel.edit @sheet_panel.id, @author
692 l = SheetPanel.edit @sheet_panel.id, @author
693 l.should eq @sheet_panel
695 context '他人の紙コマを開こうとしたとき' do
696 it '403Forbidden例外を返す' do
697 SheetPanel.any_instance.stub(:own?).and_return(false)
699 SheetPanel.edit @sheet_panel.id, @author
700 }.should raise_error(ActiveRecord::Forbidden)
703 context '存在しない紙コマを開こうとしたとき' do
704 it '404RecordNotFound例外を返す' do
706 SheetPanel.edit 110, @author
707 }.should raise_error(ActiveRecord::RecordNotFound)
712 describe '単体取得オプションに於いて' do
713 it 'includeキーを含んでいる' do
714 r = SheetPanel.show_opt
715 r.has_key?(:include).should be_true
718 r = SheetPanel.show_opt[:include]
719 r.should have(3).items
722 r = SheetPanel.show_opt[:include]
723 r.has_key?(:sheet).should be_true
726 r = SheetPanel.show_opt[:include]
727 r[:sheet].has_key?(:author).should be_true
730 r = SheetPanel.show_opt[:include]
731 r.has_key?(:author).should be_true
734 r = SheetPanel.show_opt[:include]
735 r.has_key?(:panel).should be_true
738 r = SheetPanel.show_opt[:include]
739 r[:panel].has_key?(:author).should be_true
742 r = SheetPanel.show_opt[:include]
743 r[:panel].has_key?(:panel_pictures).should be_true
745 it 'コマ絵は実素材を含んでいる' do
746 r = SheetPanel.show_opt[:include]
747 r[:panel][:panel_pictures].has_key?(:picture).should be_true
750 r = SheetPanel.show_opt[:include]
751 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
753 it '実素材はライセンスを含んでいる' do
754 r = SheetPanel.show_opt[:include]
755 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
757 it 'コマはフキダシを含んでいる' do
758 r = SheetPanel.show_opt[:include]
759 r[:panel].has_key?(:speech_balloons).should be_true
761 it 'フキダシはフキダシ枠を含んでいる' do
762 r = SheetPanel.show_opt[:include]
763 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
765 it 'フキダシはセリフを含んでいる' do
766 r = SheetPanel.show_opt[:include]
767 r[:panel][:speech_balloons].has_key?(:speech).should be_true
770 describe 'json単体取得オプションに於いて' do
773 describe '紙コマのjson出力に於いて' do
776 @panel = FactoryGirl.create :panel, :author_id => @author.id
777 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
778 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
779 @speech = @sb.build_speech(
780 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
782 @balloon = @sb.build_balloon(
783 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
787 @gc = @panel.ground_colors.create(
788 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
790 @gp = @panel.ground_pictures.create(
791 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
794 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
795 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
797 context '事前チェックする' do
799 Panel.any_instance.stub(:elements).and_return('{}')
801 it 'コマ要素のjson出力を依頼している' do
802 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
803 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
804 r = @sheet_panel.sheet_panel_as_json @author
807 it 'json textを返している' do
808 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
809 r.is_a?(Hash).should be_true
811 it 'sheet,author,panel,コマ要素を含んでいる' do
812 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
813 r.has_key?('sheet').should be_true
814 r['sheet'].has_key?('author').should be_true
815 r.has_key?('author').should be_true
816 r.has_key?('panel').should be_true
817 r['panel'].has_key?('author').should be_true
819 context 'コマ閲覧許可のとき' do
821 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
823 it 'コマ要素にコマ要素を追加している' do
824 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
825 r['panel'].has_key?('elements').should be_true
826 r['panel']['elements'].should_not be_empty
829 context 'コマ閲覧不許可のとき' do
831 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
833 it 'コマ要素にデータを含ませない' do
834 r = JSON.parse @sheet_panel.sheet_panel_as_json(@author)
835 r['panel'].has_key?('elements').should be_false
840 describe '紙コマリストのjson出力に於いて' do
842 @panel = FactoryGirl.create :panel, :author_id => @author.id
843 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
844 @sheet_panel = FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
845 SheetPanel.any_instance.stub(:sheet_panel_as_json).with(@author).and_return('{"s": 5}')
847 context 'つつがなく終わるとき' do
848 it '紙コマのjson出力を依頼している' do
849 SheetPanel.any_instance.should_receive(:sheet_panel_as_json).with(@author).exactly(1)
850 r = SheetPanel.list_as_json_text [@sheet_panel], @author
853 it 'json textを返している' do
854 r = SheetPanel.list_as_json_text [@sheet_panel], @author
856 j.is_a?(Array).should be_true
859 r = SheetPanel.list_as_json_text [@sheet_panel], @author
861 j.first.has_key?('s').should be_true
865 describe 't補充値に於いて' do
867 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
868 @panel = FactoryGirl.create :panel, :author_id => @author.id
871 context '用紙初のコマなら' do
873 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
875 r = SheetPanel.new_t @sheet_panel.sheet_id
879 context '用紙に一個コマがあるとき' do
881 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0
882 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
884 r = SheetPanel.new_t @sheet_panel.sheet_id
888 context '用紙に2個コマがあるとき' do
890 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 0
891 FactoryGirl.create :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id, :t => 1
892 @sheet_panel = FactoryGirl.build :sheet_panel, :author_id => @author.id, :sheet_id => @sheet.id, :panel_id => @panel.id
894 r = SheetPanel.new_t @sheet_panel.sheet_id
899 describe 'シリアライズチェックに於いて' do
900 context 'つつがなく終わるとき' do
901 it '0からシリアライズされているならTrueを返す' do
902 r = SheetPanel.serial? [0, 1, 2]
905 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
906 r = SheetPanel.serial? [0, 2, 1]
909 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
910 r = SheetPanel.serial? [ 2, 1, 4, 3, 0]
915 it '0から始まらないならFalseを返す' do
916 r = SheetPanel.serial? [1, 2, 3]
919 it '連続していないならFalseを返す' do
920 r = SheetPanel.serial? [0, 1, 2, 4]
923 it '連続していないならFalseを返す' do
924 r = SheetPanel.serial? [0, 1, 2, 4, 5]
929 describe 't収集に於いて' do
931 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
932 @panel = FactoryGirl.create :panel, :author_id => @author.id
933 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
934 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
935 @c2sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
937 context 'つつがなく終わるとき' do
938 it '紙コマから同一用紙のtだけを収集している' do
939 r = SheetPanel.collect_t @sheet_panel
944 it '紙コマから同一用紙のtだけを収集している' do
945 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
946 r = SheetPanel.collect_t @sheet_panel
947 r.sort.should eq [0, 1]
950 context '複数コマでヨソの用紙も混じっているとき' do
951 it '紙コマから同一用紙のtだけを収集している' do
952 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
953 r = SheetPanel.collect_t @sheet_panel
954 r.sort.should eq [0, 1]
958 describe 'tチェックに於いて' do
960 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
961 @panel = FactoryGirl.create :panel, :author_id => @author.id
962 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
964 context 'つつがなく終わるとき' do
966 SheetPanel.should_receive(:collect_t).with(any_args).exactly(1)
967 SheetPanel.stub(:collect_t).with(any_args).and_return([])
968 SheetPanel.stub(:serial?).with(any_args).and_return(true)
969 r = SheetPanel.validate_t @sheet_panel
971 it '収集したtをシリアライズチェック依頼している' do
972 SheetPanel.stub(:collect_t).with(any_args).and_return([])
973 SheetPanel.should_receive(:serial?).with(any_args).exactly(1)
974 SheetPanel.stub(:serial?).with(any_args).and_return(true)
975 r = SheetPanel.validate_t @sheet_panel
979 #依頼チェックだけでは不安なので最低限のチェックを
981 it '一件だけで正常通過している' do
982 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
983 r = SheetPanel.validate_t @sheet_panel
988 it '2件目を作っても正常通過している' do
989 @sheet_panel = FactoryGirl.create :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
990 @sheet_panel2 = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
991 r = SheetPanel.validate_t @sheet_panel2
996 describe '挿入シフトに於いて' do
998 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
999 @panel = FactoryGirl.create :panel, :author_id => @author.id
1003 it 'Updateを依頼している' do
1004 SheetPanel.stub(:update_all).with(any_args)
1005 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1006 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1007 @sheet_panel.insert_shift
1010 context 'テーブルに1件(t:0)で0に挿入したとき' do
1012 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1013 @sheet_panel2 = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1015 it '既存の行を1にシフトしている' do
1016 @sheet_panel2.insert_shift
1017 l = SheetPanel.find :all
1018 l.first.t.should eq 1
1020 it 'これから挿入するt(0)が欠番になっている' do
1021 @sheet_panel2.insert_shift
1022 l = SheetPanel.find(:all).map {|s| s.t }
1023 l.include?(0).should_not be_true
1026 context 'テーブルに2件(t:0,1)で1に挿入したとき' 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.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1030 @sheet_panel3 = FactoryGirl.build :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1032 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1033 @sheet_panel3.insert_shift
1034 l = SheetPanel.find(:all).map {|s| s.t }
1035 l.sort.should eq [0, 2]
1038 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
1040 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1041 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1042 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1043 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1044 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1045 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1047 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1048 @sheet_panel6.insert_shift
1049 l = SheetPanel.find(:all).map {|s| s.t }
1050 l.sort.should eq [0, 1, 3, 4, 5]
1053 context '先ほどのケース+他の用紙1件で挿入したとき' do
1055 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1056 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1057 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1058 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1059 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1060 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1061 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1062 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1064 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1065 @sheet_panel6.insert_shift
1066 l = SheetPanel.find(:all, :conditions => ['sheet_id = ?', @sheet.id]).map {|s| s.t }
1067 l.sort.should eq [0, 1, 3, 4, 5]
1070 ot = @sheet_panelc2.t
1071 @sheet_panel6.insert_shift
1072 @sheet_panelc2.reload
1073 @sheet_panelc2.t.should eq ot
1077 describe '少ない方に移動に於いて' do
1079 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1080 @panel = FactoryGirl.create :panel, :author_id => @author.id
1083 it 'Updateを依頼している' do
1084 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1085 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1086 SheetPanel.stub(:update_all).with(any_args)
1087 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1088 ot = @sheet_panel2.t
1090 @sheet_panel2.lesser_shift ot
1093 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
1095 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1096 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1097 @ot = @sheet_panel2.t
1100 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1102 @sheet_panel2.lesser_shift @ot
1103 l = SheetPanel.find(:all).map {|s| s.t }
1104 l.sort.should eq [1, 1]
1106 it '既存のt0を1にシフトしている' do
1107 @sheet_panel2.lesser_shift @ot
1109 @sheet_panel.t.should eq 1
1112 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
1114 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1115 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1116 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1117 @ot = @sheet_panel3.t
1120 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1122 @sheet_panel3.lesser_shift @ot
1123 l = SheetPanel.find(:all).map {|s| s.t }
1124 l.sort.should eq [0, 2, 2]
1126 it '既存のt1を2にシフトしている' do
1127 @sheet_panel3.lesser_shift @ot
1128 @sheet_panel2.reload
1129 @sheet_panel2.t.should eq 2
1132 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
1134 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1135 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1136 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1137 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1138 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1139 @ot = @sheet_panel4.t
1142 it 'これから挿入するt(1)が欠番になっている' do
1144 @sheet_panel4.lesser_shift @ot
1145 l = SheetPanel.find(:all).map {|s| s.t }
1146 l.sort.should eq [0, 2, 3, 3, 4]
1148 it '既存のt0には変化がない' do
1149 @sheet_panel4.lesser_shift @ot
1151 @sheet_panel.t.should eq 0
1153 it '既存のt4には変化がない' do
1154 @sheet_panel4.lesser_shift @ot
1155 @sheet_panel5.reload
1156 @sheet_panel5.t.should eq 4
1158 it '既存のt1を2にシフトしている' do
1159 @sheet_panel4.lesser_shift @ot
1160 @sheet_panel2.reload
1161 @sheet_panel2.t.should eq 2
1163 it '既存のt2を3にシフトしている' do
1164 @sheet_panel4.lesser_shift @ot
1165 @sheet_panel3.reload
1166 @sheet_panel3.t.should eq 3
1169 context '先ほどのケース+他の用紙1件で挿入したとき' do
1171 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1172 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1173 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1174 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1175 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1176 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1177 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1178 @ot = @sheet_panel4.t
1181 it 'これから挿入するt(1)が欠番になっている' do
1182 @sheet_panel4.lesser_shift @ot
1183 l = SheetPanel.find(:all).map {|s| s.t }
1184 l.sort.should eq [0, 0, 2, 3, 3, 4]
1186 it '既存のt0には変化がない' do
1187 @sheet_panel4.lesser_shift @ot
1189 @sheet_panel.t.should eq 0
1191 it '既存のt4には変化がない' do
1192 @sheet_panel4.lesser_shift @ot
1193 @sheet_panel5.reload
1194 @sheet_panel5.t.should eq 4
1196 it '既存のt1を2にシフトしている' do
1197 @sheet_panel4.lesser_shift @ot
1198 @sheet_panel2.reload
1199 @sheet_panel2.t.should eq 2
1201 it '既存のt2を3にシフトしている' do
1202 @sheet_panel4.lesser_shift @ot
1203 @sheet_panel3.reload
1204 @sheet_panel3.t.should eq 3
1207 @sheet_panel4.lesser_shift @ot
1208 @sheet_panelc2.reload
1209 @sheet_panelc2.t.should eq 0
1214 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
1216 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1217 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1218 @ot = @sheet_panel2.t
1219 @sheet_panel2.t = -1
1221 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1223 @sheet_panel2.lesser_shift @ot
1224 l = SheetPanel.find(:all).map {|s| s.t }
1225 l.sort.should eq [1, 1]
1227 it '既存のt0を1にシフトしている' do
1228 @sheet_panel2.lesser_shift @ot
1230 @sheet_panel.t.should eq 1
1232 it '既存のt1は0に補正されている' do
1233 @sheet_panel2.lesser_shift @ot
1234 @sheet_panel2.t.should eq 0
1238 describe '大きい方に移動に於いて' do
1240 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1241 @panel = FactoryGirl.create :panel, :author_id => @author.id
1244 it 'Updateを依頼している' do
1245 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1246 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1247 SheetPanel.stub(:update_all).with(any_args)
1248 SheetPanel.should_receive(:update_all).with(any_args).exactly(1)
1251 @sheet_panel.higher_shift ot
1254 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1256 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1257 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1258 @ot = @sheet_panel.t
1261 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1263 @sheet_panel.higher_shift @ot
1264 l = SheetPanel.find(:all).map {|s| s.t }
1265 l.sort.should eq [0, 0]
1267 it '既存のt1を0にシフトしている' do
1268 @sheet_panel.higher_shift @ot
1269 @sheet_panel2.reload
1270 @sheet_panel2.t.should eq 0
1273 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1275 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1276 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1277 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1278 @ot = @sheet_panel.t
1281 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1283 @sheet_panel.higher_shift @ot
1284 l = SheetPanel.find(:all).map {|s| s.t }
1285 l.sort.should eq [0, 0, 2]
1287 it '既存のt1を0にシフトしている' do
1288 @sheet_panel.higher_shift @ot
1289 @sheet_panel2.reload
1290 @sheet_panel2.t.should eq 0
1293 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1295 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1296 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1297 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1298 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1299 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1300 @ot = @sheet_panel2.t
1303 it 'これから挿入するt(3)が欠番になっている' do
1305 @sheet_panel2.higher_shift @ot
1306 l = SheetPanel.find(:all).map {|s| s.t }
1307 l.sort.should eq [0, 1, 1, 2, 4]
1309 it '既存のt0には変化がない' do
1310 @sheet_panel2.higher_shift @ot
1312 @sheet_panel.t.should eq 0
1314 it '既存のt4には変化がない' do
1315 @sheet_panel2.higher_shift @ot
1316 @sheet_panel5.reload
1317 @sheet_panel5.t.should eq 4
1319 it '既存のt2を1にシフトしている' do
1320 @sheet_panel2.higher_shift @ot
1321 @sheet_panel3.reload
1322 @sheet_panel3.t.should eq 1
1324 it '既存のt3を2にシフトしている' do
1325 @sheet_panel2.higher_shift @ot
1326 @sheet_panel4.reload
1327 @sheet_panel4.t.should eq 2
1330 context '先ほどのケース+他の用紙1件で挿入したとき' do
1332 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1333 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1334 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1335 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1336 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1337 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1338 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1339 @ot = @sheet_panel2.t
1342 it 'これから挿入するt(3)が欠番になっている' do
1344 @sheet_panel2.higher_shift @ot
1345 l = SheetPanel.find(:all).map {|s| s.t }
1346 l.sort.should eq [0, 0, 1, 1, 2, 4]
1348 it '既存のt0には変化がない' do
1349 @sheet_panel2.higher_shift @ot
1351 @sheet_panel.t.should eq 0
1353 it '既存のt4には変化がない' do
1354 @sheet_panel2.higher_shift @ot
1355 @sheet_panel5.reload
1356 @sheet_panel5.t.should eq 4
1358 it '既存のt2を1にシフトしている' do
1359 @sheet_panel2.higher_shift @ot
1360 @sheet_panel3.reload
1361 @sheet_panel3.t.should eq 1
1363 it '既存のt3を2にシフトしている' do
1364 @sheet_panel2.higher_shift @ot
1365 @sheet_panel4.reload
1366 @sheet_panel4.t.should eq 2
1369 @sheet_panel2.higher_shift @ot
1370 @sheet_panelc2.reload
1371 @sheet_panelc2.t.should eq 0
1375 #max超えたときはmaxとして正常扱い
1376 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1378 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1379 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1380 @ot = @sheet_panel.t
1383 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1385 @sheet_panel.higher_shift @ot
1386 l = SheetPanel.find(:all).map {|s| s.t }
1387 l.sort.should eq [0, 0]
1389 it '既存のt1を0にシフトしている' do
1390 @sheet_panel.higher_shift @ot
1391 @sheet_panel2.reload
1392 @sheet_panel2.t.should eq 0
1394 it '既存のt0は1に補正されている' do
1395 @sheet_panel.higher_shift @ot
1396 @sheet_panel.t.should eq 1
1400 describe '入れ替えに於いて' do
1402 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1403 @panel = FactoryGirl.create :panel, :author_id => @author.id
1404 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1405 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1407 context '新tが旧tより小さいとき' do
1408 it '少ない方に移動を依頼している' do
1409 SheetPanel.any_instance.stub(:lesser_shift).with(any_args)
1410 SheetPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1411 ot = @sheet_panel2.t
1413 @sheet_panel2.update_shift ot
1416 context '新tが旧tより大きいとき' do
1417 it '大きい方に移動を依頼している' do
1418 SheetPanel.any_instance.stub(:higher_shift).with(any_args)
1419 SheetPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1422 @sheet_panel.update_shift ot
1426 describe '順序入れ替えに於いて' do
1428 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1429 @panel = FactoryGirl.create :panel, :author_id => @author.id
1431 context 'オブジェクトが新規でtが空のとき' do
1432 it '末尾追加としてtを補充依頼している' do
1433 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1434 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1435 SheetPanel.should_receive(:new_t).with(any_args).exactly(1)
1436 @sheet_panel.t = nil
1437 r = @sheet_panel.rotate
1440 context 'オブジェクトが新規でtが設定されているとき' do
1441 it '挿入追加として挿入シフトを依頼している' do
1442 @sheet_panel = FactoryGirl.build :sheet_panel, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1443 SheetPanel.any_instance.stub(:insert_shift).with(any_args)
1444 SheetPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1446 r = @sheet_panel.rotate
1449 context 'オブジェクトが新規でなくtが設定されているとき' do
1450 it 'コマ移動として入れ替えを依頼している' do
1451 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1452 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1453 SheetPanel.any_instance.stub(:update_shift).with(any_args)
1454 SheetPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
1456 r = @sheet_panel.rotate 1
1459 context 'オブジェクトが新規でなくtが空のとき' do
1460 it '入れ替えもシフトもせず、tを空のままにしている' do
1461 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1465 describe '編集許可に於いて' do
1467 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1468 @panel = FactoryGirl.create :panel, :author_id => @author.id
1469 @sheet_panel = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1471 context 'つつがなく終わるとき' do
1473 r = @sheet_panel.allow?
1477 context '用紙で引っかかるとき' do
1479 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1480 Sheet.any_instance.stub(:own?).with(any_args).and_return(false)
1481 r = @sheet_panel.allow?
1485 context 'コマで引っかかるとき' do
1487 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
1488 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1489 r = @sheet_panel.allow?
1493 context '用紙またはコマが指定されていなかったとき' do
1495 Sheet.any_instance.stub(:own?).with(any_args).and_return(true)
1496 @sheet_panel.panel_id = nil
1497 r = @sheet_panel.allow?
1501 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1502 @sheet_panel.sheet_id = nil
1503 r = @sheet_panel.allow?
1508 describe '保存に於いて' do
1510 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1511 @panel = FactoryGirl.create :panel, :author_id => @author.id
1512 @sheet_panel = FactoryGirl.build :sheet_panel, :t => nil, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1514 context 'つつがなく終わるとき' do
1515 it '編集許可チェックを依頼している' do
1516 SheetPanel.any_instance.stub(:allow?).with(any_args).and_return(true)
1517 SheetPanel.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1518 r = @sheet_panel.store
1520 it '順序入れ替えを依頼している' do
1521 SheetPanel.any_instance.stub(:rotate).with(any_args).and_return(0)
1522 SheetPanel.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1523 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1524 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1525 r = @sheet_panel.store
1528 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1529 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1530 SheetPanel.any_instance.should_receive(:save).with(any_args).exactly(1)
1531 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1532 r = @sheet_panel.store
1534 it 'tのシリアライズチェックを依頼している' do
1535 SheetPanel.stub(:new_t).with(any_args).and_return(0)
1536 SheetPanel.any_instance.stub(:save).with(any_args).and_return(true)
1537 SheetPanel.stub(:validate_t).with(any_args).and_return(true)
1538 SheetPanel.should_receive(:validate_t).with(any_args).exactly(1)
1539 r = @sheet_panel.store
1542 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1543 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したとき' do
1545 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1546 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1547 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1548 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1549 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1550 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1551 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1552 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1554 it '既存のt0には変化がない' do
1557 @sheet_panel.t.should eq 0
1559 it '既存のt1には変化がない' do
1561 @sheet_panel2.reload
1562 @sheet_panel2.t.should eq 1
1564 it '既存のt2を3にシフトしている' do
1566 @sheet_panel3.reload
1567 @sheet_panel3.t.should eq 3
1569 it '既存のt3を4にシフトしている' do
1571 @sheet_panel4.reload
1572 @sheet_panel4.t.should eq 4
1574 it '既存のt5を5にシフトしている' do
1576 @sheet_panel5.reload
1577 @sheet_panel5.t.should eq 5
1579 it '新規のt2が作成されている' do
1581 @sheet_panel6.reload
1582 @sheet_panel6.t.should eq 2
1585 @ot = @sheet_panelc2.t
1587 @sheet_panelc2.reload
1588 @sheet_panelc2.t.should eq @ot
1591 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したとき' do
1593 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1594 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1595 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1596 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1597 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1598 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1599 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1600 @ot = @sheet_panel4.t
1603 it '既存のt0には変化がない' do
1604 @sheet_panel4.store @ot
1606 @sheet_panel.t.should eq 0
1608 it '既存のt4には変化がない' do
1609 @sheet_panel4.store @ot
1610 @sheet_panel5.reload
1611 @sheet_panel5.t.should eq 4
1613 it '既存のt1を2にシフトしている' do
1614 @sheet_panel4.store @ot
1615 @sheet_panel2.reload
1616 @sheet_panel2.t.should eq 2
1618 it '既存のt2を3にシフトしている' do
1619 @sheet_panel4.store @ot
1620 @sheet_panel3.reload
1621 @sheet_panel3.t.should eq 3
1623 it '既存のt3を1にシフトしている' do
1624 @sheet_panel4.store @ot
1625 @sheet_panel4.reload
1626 @sheet_panel4.t.should eq 1
1629 @sheet_panel4.store @ot
1630 @sheet_panelc2.reload
1631 @sheet_panelc2.t.should eq 0
1634 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で1を3に移動したとき' do
1636 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1637 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1638 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1639 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1640 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1641 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1642 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1643 @ot = @sheet_panel2.t
1646 it '既存のt0には変化がない' do
1647 @sheet_panel2.store @ot
1649 @sheet_panel.t.should eq 0
1651 it '既存のt4には変化がない' do
1652 @sheet_panel2.store @ot
1653 @sheet_panel5.reload
1654 @sheet_panel5.t.should eq 4
1656 it '既存のt1を3にシフトしている' do
1657 @sheet_panel2.store @ot
1658 @sheet_panel2.reload
1659 @sheet_panel2.t.should eq 3
1661 it '既存のt2を1にシフトしている' do
1662 @sheet_panel2.store @ot
1663 @sheet_panel3.reload
1664 @sheet_panel3.t.should eq 1
1666 it '既存のt3を2にシフトしている' do
1667 @sheet_panel2.store @ot
1668 @sheet_panel4.reload
1669 @sheet_panel4.t.should eq 2
1672 @sheet_panel2.store @ot
1673 @sheet_panelc2.reload
1674 @sheet_panelc2.t.should eq 0
1677 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1678 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で2に挿入したが保存に失敗したとき' do
1680 SheetPanel.any_instance.stub(:save).with(any_args).and_return(false)
1681 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1682 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1683 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1684 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1685 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1686 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1687 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1688 @sheet_panel6 = FactoryGirl.build :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1693 @sheet_panel.t.should eq 0
1694 @sheet_panel2.reload
1695 @sheet_panel2.t.should eq 1
1696 @sheet_panel3.reload
1697 @sheet_panel3.t.should eq 2
1698 @sheet_panel4.reload
1699 @sheet_panel4.t.should eq 3
1700 @sheet_panel5.reload
1701 @sheet_panel5.t.should eq 4
1702 @sheet_panelc2.reload
1703 @sheet_panelc2.t.should eq 0
1706 r = @sheet_panel6.store
1710 context 'テーブルに5件(t:0,1,2,3,4)+他の用紙1件で3を1に移動したがシリアルチェックに失敗したとき' do
1712 SheetPanel.stub(:validate_t).with(any_args).and_return(false)
1713 @sheet2 = FactoryGirl.create :sheet, :author_id => @author.id
1714 @sheet_panelc2 = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet2.id, :panel_id => @panel.id, :author_id => @author.id
1715 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1716 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1717 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1718 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1719 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1720 @ot = @sheet_panel4.t
1724 @sheet_panel4.store @ot
1726 @sheet_panel.t.should eq 0
1727 @sheet_panel2.reload
1728 @sheet_panel2.t.should eq 1
1729 @sheet_panel3.reload
1730 @sheet_panel3.t.should eq 2
1731 @sheet_panel4.reload
1732 @sheet_panel4.t.should eq 3
1733 @sheet_panel5.reload
1734 @sheet_panel5.t.should eq 4
1735 @sheet_panelc2.reload
1736 @sheet_panelc2.t.should eq 0
1739 r = @sheet_panel4.store @ot
1742 it 'tにエラーメッセージが入っている' do
1743 @sheet_panel4.store @ot
1744 @sheet_panel4.errors[:t].should_not be_empty
1745 @sheet_panel4.valid?.should be_true
1748 context '編集不可だったとき' do
1750 @sheet_panel = FactoryGirl.build :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1751 SheetPanel.any_instance.stub(:allow?).and_return(false)
1753 it '403Forbidden例外を返す' do
1756 }.should raise_error(ActiveRecord::Forbidden)
1760 describe '切り詰め処理つき削除に於いて' do
1762 @sheet = FactoryGirl.create :sheet, :author_id => @author.id
1763 @panel = FactoryGirl.create :panel, :author_id => @author.id
1764 @sheet_panel = FactoryGirl.create :sheet_panel, :t => 0, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1766 context 'つつがなく終わるとき' do
1769 @sheet_panel.destroy_and_shorten
1770 }.should change(SheetPanel, :count ).by(-1)
1773 r = @sheet_panel.destroy_and_shorten
1777 context '削除に失敗したとき' do
1779 SheetPanel.any_instance.stub(:destroy).and_return(false)
1783 @sheet_panel.destroy_and_shorten
1784 }.should_not change(SheetPanel, :count )
1787 r = @sheet_panel.destroy_and_shorten
1791 #連携テスト。切り詰めが直接DBをいじる
1792 context '2件で先頭を削除したとき' do
1794 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1798 @sheet_panel.destroy_and_shorten
1799 }.should change(SheetPanel, :count ).by(-1)
1802 @sheet_panel.destroy_and_shorten
1804 SheetPanel.find @sheet_panel.id
1805 }.should raise_error(ActiveRecord::RecordNotFound)
1808 @sheet_panel.destroy_and_shorten
1809 @sheet_panel2.reload
1810 @sheet_panel2.t.should eq 0
1813 context '3件で先頭を削除したとき' do
1815 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1816 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1820 @sheet_panel.destroy_and_shorten
1821 }.should change(SheetPanel, :count ).by(-1)
1824 @sheet_panel.destroy_and_shorten
1826 SheetPanel.find @sheet_panel.id
1827 }.should raise_error(ActiveRecord::RecordNotFound)
1830 @sheet_panel.destroy_and_shorten
1831 @sheet_panel2.reload
1832 @sheet_panel2.t.should eq 0
1835 @sheet_panel.destroy_and_shorten
1836 @sheet_panel3.reload
1837 @sheet_panel3.t.should eq 1
1840 context '5件で3件目を削除したとき' do
1842 @sheet_panel2 = FactoryGirl.create :sheet_panel, :t => 1, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1843 @sheet_panel3 = FactoryGirl.create :sheet_panel, :t => 2, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1844 @sheet_panel4 = FactoryGirl.create :sheet_panel, :t => 3, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1845 @sheet_panel5 = FactoryGirl.create :sheet_panel, :t => 4, :sheet_id => @sheet.id, :panel_id => @panel.id, :author_id => @author.id
1849 @sheet_panel3.destroy_and_shorten
1850 }.should change(SheetPanel, :count ).by(-1)
1853 @sheet_panel3.destroy_and_shorten
1855 @sheet_panel.t.should eq 0
1858 @sheet_panel3.destroy_and_shorten
1859 @sheet_panel2.reload
1860 @sheet_panel2.t.should eq 1
1863 @sheet_panel3.destroy_and_shorten
1865 SheetPanel.find @sheet_panel3.id
1866 }.should raise_error(ActiveRecord::RecordNotFound)
1869 @sheet_panel3.destroy_and_shorten
1870 @sheet_panel4.reload
1871 @sheet_panel4.t.should eq 2
1874 @sheet_panel3.destroy_and_shorten
1875 @sheet_panel5.reload
1876 @sheet_panel5.t.should eq 3
1879 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する