1 # -*- encoding: utf-8 -*-
6 FactoryGirl.create :admin
7 @sp = FactoryGirl.create :system_picture
8 @lg = FactoryGirl.create :license_group
9 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10 @user = FactoryGirl.create( :user_yas)
11 @author = @user.author
12 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
13 @other_user = FactoryGirl.create( :user_yas)
14 @other_author = @other_user.author
19 @comic = FactoryGirl.create :comic, :author_id => @author.id
20 @panel = FactoryGirl.create :panel, :author_id => @author.id
21 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
24 context 'オーソドックスなデータのとき' do
27 @story.should be_valid
31 @story.should be_valid
35 context 'comic_idを検証するとき' do
38 @story.should_not be_valid
42 @story.should_not be_valid
44 it '存在するコミックでなければ失敗する' do
46 @story.should_not be_valid
50 context 'panel_idを検証するとき' do
53 @story.should_not be_valid
57 @story.should_not be_valid
59 it '存在するコマでなければ失敗する' do
61 @story.should_not be_valid
68 @story.should_not be_valid
72 @story.should_not be_valid
76 @story.should_not be_valid
80 context 'author_idを検証するとき' do
82 @story.author_id = nil
83 @story.should_not be_valid
86 @story.author_id = 'a'
87 @story.should_not be_valid
89 it '存在する作家でなければ失敗する' do
91 @story.should_not be_valid
94 context '全体を検証するとき' do
98 describe 'デフォルト値補充に於いて' do
100 @comic = FactoryGirl.create :comic, :author_id => @author.id
101 @panel = FactoryGirl.create :panel, :author_id => @author.id
104 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
106 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
107 @story.supply_default
108 @story.t.should be_nil
113 describe '上書き補充に於いて' do
115 @comic = FactoryGirl.create :comic, :author_id => @author.id
116 @panel = FactoryGirl.create :panel, :author_id => @author.id
119 context 'author_idを補充' do
120 it '問答無用でauthor_idを補充する' do
121 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
122 @story.author_id = nil
123 @story.overwrite @author
124 @story.author_id.should eq @author.id
130 describe '所持判定に於いて' do
132 @comic = FactoryGirl.create :comic, :author_id => @author.id
133 @panel = FactoryGirl.create :panel, :author_id => @author.id
134 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
135 @comico = FactoryGirl.create :comic, :author_id => @other_author.id
136 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
137 @storyo = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @comico.id, :panel_id => @panelo.id
139 it '自分のストーリーならyes' do
140 @story.own?(@author).should == true
143 @storyo.own?(@author).should == false
146 describe '一覧取得に於いて' do
148 @comic = FactoryGirl.create :comic, :author_id => @author.id
149 @panel = FactoryGirl.create :panel, :author_id => @author.id
150 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
151 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
152 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
153 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
155 context 'offset補正について' do
156 it '文字列から数値に変換される' do
157 Story.offset(100, '8').should eq 8
160 Story.offset(100).should eq 0
162 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
164 it '1件のときオフセット1なら0になる' do
165 Story.offset(1, '1').should eq 0
167 it '5件のときオフセット5なら4になる' do
168 Story.offset(5, '5').should eq 4
170 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
171 #-4のときは、最後から4つのコマを表示する。
172 it '2件のときオフセット-1なら1になる' do
173 Story.offset(2, '-1').should eq 1
175 it '5件のときオフセット-2なら3になる' do
176 Story.offset(5, '-2').should eq 3
178 # 最終的なが負になるなど、不正な値が入ったときは0となる。
179 it '2件のときオフセット-5なら0になる' do
180 Story.offset(2, '-5').should eq 0
183 context 'panel_count補正について' do
184 it '文字列から数値に変換される' do
185 Story.panel_count(100, '7').should eq 7
187 it 'nilの場合はStory.default_panel_sizeになる' do
188 Story.panel_count(100).should eq Story.default_panel_size
190 it '0以下の場合はStory.default_panel_sizeになる' do
191 Story.panel_count(100, '0').should eq Story.default_panel_size
193 it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
194 Story.panel_count(100, '1000').should eq Story.max_panel_size
198 c = Story.list @comic, @author
202 #公開コミックの公開コマは(他人のコミックであっても)含んでいる
203 v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
204 c = Story.list @comic, @author
205 c.should eq [ @story, v]
208 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
209 c = Story.list @comic, @author
210 c.should eq [ @story]
212 context 'DBに5件あって1ページの件数を2件に変えたとして' do
214 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
215 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
216 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
217 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
219 it 'offset=0なら末尾2件を返す' do
221 c = Story.list( @comic, @author, 0, 2)
222 c.should eq [@story, @story2]
224 it 'offset=2なら中間2件を返す' do
225 c = Story.list(@comic, @author, 2, 2)
226 c.should eq [@story3, @story4]
228 it 'offset=4なら先頭1件を返す' do
229 c = Story.list(@comic, @author, 4, 2)
230 c.should eq [@story5]
234 describe 'list関連テーブルプションに於いて' do
235 it 'includeキーを含んでいる' do
237 r.has_key?(:include).should be_true
240 r = Story.list_opt[:include]
241 r.should have(3).items
244 r = Story.list_opt[:include]
245 r.has_key?(:comic).should be_true
247 it 'コミックは作家を含んでいる' do
248 r = Story.list_opt[:include]
249 r[:comic].has_key?(:author).should be_true
252 r = Story.list_opt[:include]
253 r.has_key?(:author).should be_true
256 r = Story.list_opt[:include]
257 r.has_key?(:panel).should be_true
260 r = Story.list_opt[:include]
261 r[:panel].has_key?(:author).should be_true
264 r = Story.list_opt[:include]
265 r[:panel].has_key?(:panel_pictures).should be_true
267 it 'コマ絵は実素材を含んでいる' do
268 r = Story.list_opt[:include]
269 r[:panel][:panel_pictures].has_key?(:picture).should be_true
272 r = Story.list_opt[:include]
273 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
275 it '実素材はライセンスを含んでいる' do
276 r = Story.list_opt[:include]
277 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
279 it 'コマはフキダシを含んでいる' do
280 r = Story.list_opt[:include]
281 r[:panel].has_key?(:speech_balloons).should be_true
283 it 'フキダシはフキダシ枠を含んでいる' do
284 r = Story.list_opt[:include]
285 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
287 it 'フキダシはセリフを含んでいる' do
288 r = Story.list_opt[:include]
289 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
292 describe 'json一覧出力オプションに於いて' do
293 it 'includeキーを含んでいる' do
294 r = Story.list_json_opt
295 r.has_key?(:include).should be_true
298 r = Story.list_json_opt[:include]
299 r.should have(3).items
302 r = Story.list_json_opt[:include]
303 r.has_key?(:comic).should be_true
305 it 'コミックは作家を含んでいる' do
306 r = Story.list_json_opt[:include]
307 r[:comic].has_key?(:author).should be_true
310 r = Story.list_json_opt[:include]
311 r.has_key?(:author).should be_true
314 r = Story.list_json_opt[:include]
315 r.has_key?(:panel).should be_true
318 r = Story.list_json_opt[:include]
319 r[:panel].has_key?(:author).should be_true
322 r = Story.list_json_opt[:include]
323 r[:panel].has_key?(:panel_pictures).should be_true
325 it 'コマ絵は実素材を含んでいる' do
326 r = Story.list_json_opt[:include]
327 r[:panel][:panel_pictures].has_key?(:picture).should be_true
330 r = Story.list_json_opt[:include]
331 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
333 it '実素材はライセンスを含んでいる' do
334 r = Story.list_json_opt[:include]
335 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
337 it 'コマはフキダシを含んでいる' do
338 r = Story.list_json_opt[:include]
339 r[:panel].has_key?(:speech_balloons).should be_true
341 it 'フキダシはフキダシ枠を含んでいる' do
342 r = Story.list_json_opt[:include]
343 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
345 it 'フキダシはセリフを含んでいる' do
346 r = Story.list_json_opt[:include]
347 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
351 describe '自分のストーリー一覧取得に於いて' do
353 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
354 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
355 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
356 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
357 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
359 context 'つつがなく終わるとき' do
\r
360 it '一覧取得オプションを利用している' do
\r
361 Story.stub(:list_opt).with(any_args).and_return({})
\r
362 Story.should_receive(:list_opt).with(any_args).exactly(1)
\r
363 r = Story.mylist @author
367 s = Story.mylist @author
371 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
372 sl = Story.mylist @author
373 sl.should eq [ns, @story]
375 it '他人のストーリーはコマコミックともに公開でも含まない' do
376 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
377 sl = Story.mylist @author
378 sl.should eq [@story]
380 it '自分のストーリーはコマコミックともには非公開でも含んでいる' do
381 nc = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
382 cl = Comic.mylist @author
383 cl.should eq [nc, @story]
385 context 'DBに5件あって1ページの件数を2件に変えたとして' do
387 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
388 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
389 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
390 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
393 c = Story.mylist @author, 1, 2
394 c.should have(2).items
396 it 'page=1なら末尾2件を返す' do
398 c = Story.mylist(@author, 1, 2)
399 c.should eq [@story5, @story4]
401 it 'page=2なら中間2件を返す' do
402 c = Story.mylist(@author, 2, 2)
403 c.should eq [@story3, @story2]
405 it 'page=3なら先頭1件を返す' do
406 c = Story.mylist(@author, 3, 2)
410 context 'DBに5件あって1ページの件数を0件に変えたとして' do
412 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
413 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
414 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
415 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
418 r = Story.mylist @author, 5, 0
419 r.should have(5).items
424 describe '編集取得に於いて' do
426 @comic = FactoryGirl.create :comic, :author_id => @author.id
427 @panel = FactoryGirl.create :panel, :author_id => @author.id
428 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
430 context 'つつがなく終わるとき' do
\r
431 it '単体取得オプションを利用している' do
\r
432 Story.stub(:show_opt).with(any_args).and_return({})
\r
433 Story.should_receive(:show_opt).with(any_args).exactly(1)
\r
434 r = Story.edit @story.id, @author
436 it '所持判定を問い合わせている' do
\r
437 Story.any_instance.stub(:own?).with(any_args).and_return(true)
\r
438 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
439 r = Story.edit @story.id, @author
443 l = Story.edit @story.id, @author
446 context '他人のストーリーを開こうとしたとき' do
447 it '403Forbidden例外を返す' do
448 Story.any_instance.stub(:own?).and_return(false)
450 Story.edit @story.id, @author
451 }.should raise_error(ActiveRecord::Forbidden)
454 context '存在しないストーリーを開こうとしたとき' do
455 it '404RecordNotFound例外を返す' do
457 Story.edit 110, @author
458 }.should raise_error(ActiveRecord::RecordNotFound)
463 describe '単体取得オプションに於いて' do
464 it 'includeキーを含んでいる' do
466 r.has_key?(:include).should be_true
469 r = Story.show_opt[:include]
470 r.should have(3).items
473 r = Story.show_opt[:include]
474 r.has_key?(:comic).should be_true
476 it 'コミックは作家を含んでいる' do
477 r = Story.show_opt[:include]
478 r[:comic].has_key?(:author).should be_true
481 r = Story.show_opt[:include]
482 r.has_key?(:author).should be_true
485 r = Story.show_opt[:include]
486 r.has_key?(:panel).should be_true
489 r = Story.show_opt[:include]
490 r[:panel].has_key?(:author).should be_true
493 r = Story.show_opt[:include]
494 r[:panel].has_key?(:panel_pictures).should be_true
496 it 'コマ絵は実素材を含んでいる' do
497 r = Story.show_opt[:include]
498 r[:panel][:panel_pictures].has_key?(:picture).should be_true
501 r = Story.show_opt[:include]
502 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
504 it '実素材はライセンスを含んでいる' do
505 r = Story.show_opt[:include]
506 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
508 it 'コマはフキダシを含んでいる' do
509 r = Story.show_opt[:include]
510 r[:panel].has_key?(:speech_balloons).should be_true
512 it 'フキダシはフキダシ枠を含んでいる' do
513 r = Story.show_opt[:include]
514 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
516 it 'フキダシはセリフを含んでいる' do
517 r = Story.show_opt[:include]
518 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
521 describe 'json単体取得オプションに於いて' do
522 it 'includeキーを含んでいる' do
523 r = Story.show_json_opt
524 r.has_key?(:include).should be_true
527 r = Story.show_json_opt[:include]
528 r.should have(3).items
531 r = Story.show_json_opt[:include]
532 r.has_key?(:comic).should be_true
534 it 'コミックは作家を含んでいる' do
535 r = Story.show_json_opt[:include]
536 r[:comic].has_key?(:author).should be_true
539 r = Story.show_json_opt[:include]
540 r.has_key?(:author).should be_true
543 r = Story.show_json_opt[:include]
544 r.has_key?(:panel).should be_true
547 r = Story.show_json_opt[:include]
548 r[:panel].has_key?(:author).should be_true
551 r = Story.show_json_opt[:include]
552 r[:panel].has_key?(:panel_pictures).should be_true
554 it 'コマ絵は実素材を含んでいる' do
555 r = Story.show_json_opt[:include]
556 r[:panel][:panel_pictures].has_key?(:picture).should be_true
559 r = Story.show_json_opt[:include]
560 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
562 it '実素材はライセンスを含んでいる' do
563 r = Story.show_json_opt[:include]
564 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
566 it 'コマはフキダシを含んでいる' do
567 r = Story.show_json_opt[:include]
568 r[:panel].has_key?(:speech_balloons).should be_true
570 it 'フキダシはフキダシ枠を含んでいる' do
571 r = Story.show_json_opt[:include]
572 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
574 it 'フキダシはセリフを含んでいる' do
575 r = Story.show_json_opt[:include]
576 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
580 describe 't補充値に於いて' do
582 @comic = FactoryGirl.create :comic, :author_id => @author.id
583 @panel = FactoryGirl.create :panel, :author_id => @author.id
586 context 'コミック初のコマなら' do
588 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
590 r = Story.new_t @story.comic_id
594 context 'コミックに一個コマがあるとき' do
596 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
597 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
599 r = Story.new_t @story.comic_id
603 context 'コミックに2個コマがあるとき' do
605 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
606 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
607 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
609 r = Story.new_t @story.comic_id
614 describe 'シリアライズチェックに於いて' do
615 context 'つつがなく終わるとき' do
616 it '0からシリアライズされているならTrueを返す' do
617 r = Story.serial? [0, 1, 2]
620 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
621 r = Story.serial? [0, 2, 1]
624 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
625 r = Story.serial? [ 2, 1, 4, 3, 0]
630 it '0から始まらないならFalseを返す' do
631 r = Story.serial? [1, 2, 3]
634 it '連続していないならFalseを返す' do
635 r = Story.serial? [0, 1, 2, 4]
638 it '連続していないならFalseを返す' do
639 r = Story.serial? [0, 1, 2, 4, 5]
644 describe 't収集に於いて' do
646 @comic = FactoryGirl.create :comic, :author_id => @author.id
647 @panel = FactoryGirl.create :panel, :author_id => @author.id
648 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
649 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
650 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
652 context 'つつがなく終わるとき' do
653 it 'ストーリーから同一コミックのtだけを収集している' do
654 r = Story.collect_t @story
659 it 'ストーリーから同一コミックのtだけを収集している' do
660 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
661 r = Story.collect_t @story
662 r.sort.should eq [0, 1]
665 context '複数コマでヨソのコミックも混じっているとき' do
666 it 'ストーリーから同一コミックのtだけを収集している' do
667 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
668 r = Story.collect_t @story
669 r.sort.should eq [0, 1]
673 describe 'tチェックに於いて' do
675 @comic = FactoryGirl.create :comic, :author_id => @author.id
676 @panel = FactoryGirl.create :panel, :author_id => @author.id
677 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
679 context 'つつがなく終わるとき' do
681 Story.should_receive(:collect_t).with(any_args).exactly(1)
682 Story.stub(:collect_t).with(any_args).and_return([])
683 Story.stub(:serial?).with(any_args).and_return(true)
684 r = Story.validate_t @story
686 it '収集したtをシリアライズチェック依頼している' do
687 Story.stub(:collect_t).with(any_args).and_return([])
688 Story.should_receive(:serial?).with(any_args).exactly(1)
689 Story.stub(:serial?).with(any_args).and_return(true)
690 r = Story.validate_t @story
694 #依頼チェックだけでは不安なので最低限のチェックを
696 it '一件だけで正常通過している' do
697 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
698 r = Story.validate_t @story
703 it '2件目を作っても正常通過している' do
704 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
705 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
706 r = Story.validate_t @story2
711 describe '挿入シフトに於いて' do
713 @comic = FactoryGirl.create :comic, :author_id => @author.id
714 @panel = FactoryGirl.create :panel, :author_id => @author.id
718 it 'Updateを依頼している' do
719 Story.stub(:update_all).with(any_args)
720 Story.should_receive(:update_all).with(any_args).exactly(1)
721 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
725 context 'テーブルに1件(t:0)で0に挿入したとき' do
727 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
728 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
730 it '既存の行を1にシフトしている' do
733 l.first.t.should eq 1
735 it 'これから挿入するt(0)が欠番になっている' do
737 l = Story.find(:all).map {|s| s.t }
738 l.include?(0).should_not be_true
741 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
743 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
744 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
745 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
747 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
749 l = Story.find(:all).map {|s| s.t }
750 l.sort.should eq [0, 2]
753 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
755 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
756 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
757 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
758 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
759 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
760 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
762 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
764 l = Story.find(:all).map {|s| s.t }
765 l.sort.should eq [0, 1, 3, 4, 5]
768 context '先ほどのケース+他のコミック1件で挿入したとき' do
770 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
771 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
772 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
773 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
774 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
775 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
776 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
777 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
779 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
781 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
782 l.sort.should eq [0, 1, 3, 4, 5]
788 @storyc2.t.should eq ot
792 describe '少ない方に移動に於いて' do
794 @comic = FactoryGirl.create :comic, :author_id => @author.id
795 @panel = FactoryGirl.create :panel, :author_id => @author.id
798 it 'Updateを依頼している' do
799 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
800 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
801 Story.stub(:update_all).with(any_args)
802 Story.should_receive(:update_all).with(any_args).exactly(1)
805 @story2.lesser_shift ot
808 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
810 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
811 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
815 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
817 @story2.lesser_shift @ot
818 l = Story.find(:all).map {|s| s.t }
819 l.sort.should eq [1, 1]
821 it '既存のt0を1にシフトしている' do
822 @story2.lesser_shift @ot
827 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
829 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
830 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
831 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
835 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
837 @story3.lesser_shift @ot
838 l = Story.find(:all).map {|s| s.t }
839 l.sort.should eq [0, 2, 2]
841 it '既存のt1を2にシフトしている' do
842 @story3.lesser_shift @ot
844 @story2.t.should eq 2
847 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
849 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
850 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
851 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
852 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
853 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
857 it 'これから挿入するt(1)が欠番になっている' do
859 @story4.lesser_shift @ot
860 l = Story.find(:all).map {|s| s.t }
861 l.sort.should eq [0, 2, 3, 3, 4]
864 @story4.lesser_shift @ot
869 @story4.lesser_shift @ot
871 @story5.t.should eq 4
873 it '既存のt1を2にシフトしている' do
874 @story4.lesser_shift @ot
876 @story2.t.should eq 2
878 it '既存のt2を3にシフトしている' do
879 @story4.lesser_shift @ot
881 @story3.t.should eq 3
884 context '先ほどのケース+他のコミック1件で挿入したとき' do
886 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
887 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
888 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
889 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
890 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
891 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
892 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
896 it 'これから挿入するt(1)が欠番になっている' do
897 @story4.lesser_shift @ot
898 l = Story.find(:all).map {|s| s.t }
899 l.sort.should eq [0, 0, 2, 3, 3, 4]
902 @story4.lesser_shift @ot
907 @story4.lesser_shift @ot
909 @story5.t.should eq 4
911 it '既存のt1を2にシフトしている' do
912 @story4.lesser_shift @ot
914 @story2.t.should eq 2
916 it '既存のt2を3にシフトしている' do
917 @story4.lesser_shift @ot
919 @story3.t.should eq 3
922 @story4.lesser_shift @ot
924 @storyc2.t.should eq 0
929 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
931 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
932 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
936 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
938 @story2.lesser_shift @ot
939 l = Story.find(:all).map {|s| s.t }
940 l.sort.should eq [1, 1]
942 it '既存のt0を1にシフトしている' do
943 @story2.lesser_shift @ot
947 it '既存のt1は0に補正されている' do
948 @story2.lesser_shift @ot
949 @story2.t.should eq 0
953 describe '大きい方に移動に於いて' do
955 @comic = FactoryGirl.create :comic, :author_id => @author.id
956 @panel = FactoryGirl.create :panel, :author_id => @author.id
959 it 'Updateを依頼している' do
960 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
961 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
962 Story.stub(:update_all).with(any_args)
963 Story.should_receive(:update_all).with(any_args).exactly(1)
966 @story.higher_shift ot
969 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
971 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
972 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
976 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
978 @story.higher_shift @ot
979 l = Story.find(:all).map {|s| s.t }
980 l.sort.should eq [0, 0]
982 it '既存のt1を0にシフトしている' do
983 @story.higher_shift @ot
985 @story2.t.should eq 0
988 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
990 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
991 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
992 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
996 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
998 @story.higher_shift @ot
999 l = Story.find(:all).map {|s| s.t }
1000 l.sort.should eq [0, 0, 2]
1002 it '既存のt1を0にシフトしている' do
1003 @story.higher_shift @ot
1005 @story2.t.should eq 0
1008 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1010 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1011 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1012 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1013 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1014 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1018 it 'これから挿入するt(3)が欠番になっている' do
1020 @story2.higher_shift @ot
1021 l = Story.find(:all).map {|s| s.t }
1022 l.sort.should eq [0, 1, 1, 2, 4]
1024 it '既存のt0には変化がない' do
1025 @story2.higher_shift @ot
1027 @story.t.should eq 0
1029 it '既存のt4には変化がない' do
1030 @story2.higher_shift @ot
1032 @story5.t.should eq 4
1034 it '既存のt2を1にシフトしている' do
1035 @story2.higher_shift @ot
1037 @story3.t.should eq 1
1039 it '既存のt3を2にシフトしている' do
1040 @story2.higher_shift @ot
1042 @story4.t.should eq 2
1045 context '先ほどのケース+他のコミック1件で挿入したとき' do
1047 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1048 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1049 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1050 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1051 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1052 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1053 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1057 it 'これから挿入するt(3)が欠番になっている' do
1059 @story2.higher_shift @ot
1060 l = Story.find(:all).map {|s| s.t }
1061 l.sort.should eq [0, 0, 1, 1, 2, 4]
1063 it '既存のt0には変化がない' do
1064 @story2.higher_shift @ot
1066 @story.t.should eq 0
1068 it '既存のt4には変化がない' do
1069 @story2.higher_shift @ot
1071 @story5.t.should eq 4
1073 it '既存のt2を1にシフトしている' do
1074 @story2.higher_shift @ot
1076 @story3.t.should eq 1
1078 it '既存のt3を2にシフトしている' do
1079 @story2.higher_shift @ot
1081 @story4.t.should eq 2
1083 it '他のコミックに影響がない' do
1084 @story2.higher_shift @ot
1086 @storyc2.t.should eq 0
1090 #max超えたときはmaxとして正常扱い
1091 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1093 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1094 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1098 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1100 @story.higher_shift @ot
1101 l = Story.find(:all).map {|s| s.t }
1102 l.sort.should eq [0, 0]
1104 it '既存のt1を0にシフトしている' do
1105 @story.higher_shift @ot
1107 @story2.t.should eq 0
1109 it '既存のt0は1に補正されている' do
1110 @story.higher_shift @ot
1111 @story.t.should eq 1
1115 describe '入れ替えに於いて' do
1117 @comic = FactoryGirl.create :comic, :author_id => @author.id
1118 @panel = FactoryGirl.create :panel, :author_id => @author.id
1119 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1120 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1122 context '新tが旧tより小さいとき' do
1123 it '少ない方に移動を依頼している' do
1124 Story.any_instance.stub(:lesser_shift).with(any_args)
1125 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1128 @story2.update_shift ot
1131 context '新tが旧tより大きいとき' do
1132 it '大きい方に移動を依頼している' do
1133 Story.any_instance.stub(:higher_shift).with(any_args)
1134 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1137 @story.update_shift ot
1141 describe '順序入れ替えに於いて' do
1143 @comic = FactoryGirl.create :comic, :author_id => @author.id
1144 @panel = FactoryGirl.create :panel, :author_id => @author.id
1146 context 'オブジェクトが新規でtが空のとき' do
1147 it '末尾追加としてtを補充依頼している' do
1148 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1149 Story.stub(:new_t).with(any_args).and_return(0)
1150 Story.should_receive(:new_t).with(any_args).exactly(1)
1155 context 'オブジェクトが新規でtが設定されているとき' do
1156 it '挿入追加として挿入シフトを依頼している' do
1157 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1158 Story.any_instance.stub(:insert_shift).with(any_args)
1159 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1164 context 'オブジェクトが新規でなくtが設定されているとき' do
1165 it 'コマ移動として入れ替えを依頼している' do
1166 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1167 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1168 Story.any_instance.stub(:update_shift).with(any_args)
1169 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1174 context 'オブジェクトが新規でなくtが空のとき' do
1175 it '入れ替えもシフトもせず、tを空のままにしている' do
1176 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1180 describe '編集許可に於いて' do
1182 @comic = FactoryGirl.create :comic, :author_id => @author.id
1183 @panel = FactoryGirl.create :panel, :author_id => @author.id
1184 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1186 context 'つつがなく終わるとき' do
1192 context 'コミックで引っかかるとき' do
1194 @story.comic_id = nil
1199 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1204 context 'コマで引っかかるとき' do
1206 @story.panel_id = nil
1211 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1217 describe '保存に於いて' do
1219 @comic = FactoryGirl.create :comic, :author_id => @author.id
1220 @panel = FactoryGirl.create :panel, :author_id => @author.id
1221 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1223 context 'つつがなく終わるとき' do
1224 it '編集許可チェックを依頼している' do
1225 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1226 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1229 it '順序入れ替えを依頼している' do
1230 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1231 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1232 Story.any_instance.stub(:save).with(any_args).and_return(true)
1233 Story.stub(:validate_t).with(any_args).and_return(true)
1237 Story.stub(:new_t).with(any_args).and_return(0)
1238 Story.any_instance.stub(:save).with(any_args).and_return(true)
1239 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1240 Story.stub(:validate_t).with(any_args).and_return(true)
1243 it 'tのシリアライズチェックを依頼している' do
1244 Story.stub(:new_t).with(any_args).and_return(0)
1245 Story.any_instance.stub(:save).with(any_args).and_return(true)
1246 Story.stub(:validate_t).with(any_args).and_return(true)
1247 Story.should_receive(:validate_t).with(any_args).exactly(1)
1251 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1252 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1254 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1255 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1256 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1257 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1258 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1259 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1260 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1261 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1263 it '既存のt0には変化がない' do
1266 @story.t.should eq 0
1268 it '既存のt1には変化がない' do
1271 @story2.t.should eq 1
1273 it '既存のt2を3にシフトしている' do
1276 @story3.t.should eq 3
1278 it '既存のt3を4にシフトしている' do
1281 @story4.t.should eq 4
1283 it '既存のt5を5にシフトしている' do
1286 @story5.t.should eq 5
1288 it '新規のt2が作成されている' do
1291 @story6.t.should eq 2
1293 it '他のコミックに影響がない' do
1297 @storyc2.t.should eq @ot
1300 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1302 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1303 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1304 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1305 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1306 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1307 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1308 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1312 it '既存のt0には変化がない' do
1315 @story.t.should eq 0
1317 it '既存のt4には変化がない' do
1320 @story5.t.should eq 4
1322 it '既存のt1を2にシフトしている' do
1325 @story2.t.should eq 2
1327 it '既存のt2を3にシフトしている' do
1330 @story3.t.should eq 3
1332 it '既存のt3を1にシフトしている' do
1335 @story4.t.should eq 1
1337 it '他のコミックに影響がない' do
1340 @storyc2.t.should eq 0
1343 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1345 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1346 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1347 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1348 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1349 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1350 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1351 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1355 it '既存のt0には変化がない' do
1358 @story.t.should eq 0
1360 it '既存のt4には変化がない' do
1363 @story5.t.should eq 4
1365 it '既存のt1を3にシフトしている' do
1368 @story2.t.should eq 3
1370 it '既存のt2を1にシフトしている' do
1373 @story3.t.should eq 1
1375 it '既存のt3を2にシフトしている' do
1378 @story4.t.should eq 2
1380 it '他のコミックに影響がない' do
1383 @storyc2.t.should eq 0
1386 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1387 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1389 Story.any_instance.stub(:save).with(any_args).and_return(false)
1390 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1391 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1392 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1393 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1394 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1395 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1396 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1397 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1402 @story.t.should eq 0
1404 @story2.t.should eq 1
1406 @story3.t.should eq 2
1408 @story4.t.should eq 3
1410 @story5.t.should eq 4
1412 @storyc2.t.should eq 0
1419 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1421 Story.stub(:validate_t).with(any_args).and_return(false)
1422 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1423 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1424 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1425 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1426 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1427 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1428 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1435 @story.t.should eq 0
1437 @story2.t.should eq 1
1439 @story3.t.should eq 2
1441 @story4.t.should eq 3
1443 @story5.t.should eq 4
1445 @storyc2.t.should eq 0
1448 r = @story4.store @ot
1451 it 'tにエラーメッセージが入っている' do
1453 @story4.errors[:t].should_not be_empty
1454 @story4.valid?.should be_true
1457 context '編集不可だったとき' do
1459 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1460 Story.any_instance.stub(:allow?).and_return(false)
1462 it '403Forbidden例外を返す' do
1465 }.should raise_error(ActiveRecord::Forbidden)
1469 describe '切り詰め処理つき削除に於いて' do
1471 @comic = FactoryGirl.create :comic, :author_id => @author.id
1472 @panel = FactoryGirl.create :panel, :author_id => @author.id
1473 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1475 context 'つつがなく終わるとき' do
1478 @story.destroy_and_shorten
1479 }.should change(Story, :count ).by(-1)
1482 #連携テスト。切り詰めが直接DBをいじる
1483 context '2件で先頭を削除したとき' do
1485 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1489 @story.destroy_and_shorten
1490 }.should change(Story, :count ).by(-1)
1493 @story.destroy_and_shorten
1495 Story.find @story.id
1496 }.should raise_error(ActiveRecord::RecordNotFound)
1499 @story.destroy_and_shorten
1501 @story2.t.should eq 0
1504 context '3件で先頭を削除したとき' do
1506 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1507 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1511 @story.destroy_and_shorten
1512 }.should change(Story, :count ).by(-1)
1515 @story.destroy_and_shorten
1517 Story.find @story.id
1518 }.should raise_error(ActiveRecord::RecordNotFound)
1521 @story.destroy_and_shorten
1523 @story2.t.should eq 0
1526 @story.destroy_and_shorten
1528 @story3.t.should eq 1
1531 context '5件で3件目を削除したとき' do
1533 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1534 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1535 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1536 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1540 @story3.destroy_and_shorten
1541 }.should change(Story, :count ).by(-1)
1544 @story3.destroy_and_shorten
1546 @story.t.should eq 0
1549 @story3.destroy_and_shorten
1551 @story2.t.should eq 1
1554 @story3.destroy_and_shorten
1556 Story.find @story3.id
1557 }.should raise_error(ActiveRecord::RecordNotFound)
1560 @story3.destroy_and_shorten
1562 @story4.t.should eq 2
1565 @story3.destroy_and_shorten
1567 @story5.t.should eq 3
1570 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する