1 # -*- encoding: utf-8 -*-
6 @admin = 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 @color = FactoryGirl.create :color
11 @user = FactoryGirl.create( :user_yas)
12 @author = @user.author
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14 @other_user = FactoryGirl.create( :user_yas)
15 @other_author = @other_user.author
16 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
17 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
18 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
19 @sbt = FactoryGirl.create :speech_balloon_template
\r
24 @comic = FactoryGirl.create :comic, :author_id => @author.id
25 @panel = FactoryGirl.create :panel, :author_id => @author.id
26 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
29 context 'オーソドックスなデータのとき' do
32 @story.should be_valid
36 @story.should be_valid
40 context 'comic_idを検証するとき' do
43 @story.should_not be_valid
47 @story.should_not be_valid
49 it '存在するコミックでなければ失敗する' do
51 @story.should_not be_valid
55 context 'panel_idを検証するとき' do
58 @story.should_not be_valid
62 @story.should_not be_valid
64 it '存在するコマでなければ失敗する' do
66 @story.should_not be_valid
73 @story.should_not be_valid
77 @story.should_not be_valid
81 @story.should_not be_valid
85 context 'author_idを検証するとき' do
87 @story.author_id = nil
88 @story.should_not be_valid
91 @story.author_id = 'a'
92 @story.should_not be_valid
94 it '存在する作家でなければ失敗する' do
96 @story.should_not be_valid
99 context '全体を検証するとき' do
103 describe 'デフォルト値補充に於いて' do
105 @comic = FactoryGirl.create :comic, :author_id => @author.id
106 @panel = FactoryGirl.create :panel, :author_id => @author.id
109 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
111 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
112 @story.supply_default
113 @story.t.should be_nil
118 describe '上書き補充に於いて' do
120 @comic = FactoryGirl.create :comic, :author_id => @author.id
121 @panel = FactoryGirl.create :panel, :author_id => @author.id
124 context 'author_idを補充' do
125 it '問答無用でauthor_idを補充する' do
126 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
127 @story.author_id = nil
128 @story.overwrite @author
129 @story.author_id.should eq @author.id
135 describe '所持判定に於いて' do
137 @comic = FactoryGirl.create :comic, :author_id => @author.id
138 @panel = FactoryGirl.create :panel, :author_id => @author.id
139 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
140 @comico = FactoryGirl.create :comic, :author_id => @other_author.id
141 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
142 @storyo = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @comico.id, :panel_id => @panelo.id
144 it '自分のストーリーならyes' do
145 @story.own?(@author).should == true
148 @storyo.own?(@author).should == false
150 it 'パラメータが作家でないならno' do
151 @story.own?(nil).should == false
155 describe '閲覧許可に於いて' do
\r
157 @comic = FactoryGirl.create :comic, :author_id => @author.id
158 @panel = FactoryGirl.create :panel, :author_id => @author.id
159 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
161 context '検査対象がnil(ゲスト)のとき' do
162 context 'クローズドモードのとき' do
164 MagicNumber['run_mode'] = 1
167 r = @story.visible?(nil)
171 context 'オープンモードのとき' do
173 MagicNumber['run_mode'] = 0
175 it '公開コミックのストーリーなら許可する' do
\r
176 Comic.any_instance.stub(:visible?).with(nil).and_return(true)
\r
177 r = @story.visible?(nil)
180 it '非公開コミックのストーリーなら許可しない' do
\r
181 Comic.any_instance.stub(:visible?).with(nil).and_return(false)
\r
182 r = @story.visible?(nil)
187 context '検査対象が作家のとき' do
188 it '自分のコミックのストーリーなら許可する' do
\r
189 Comic.any_instance.stub(:own?).with(@author).and_return(true)
\r
190 Comic.any_instance.stub(:visible?).with(@author).and_return(true)
\r
191 r = @story.visible?(@author)
194 it '他人の非公開コミックのストーリーなら許可しない' do
\r
195 Comic.any_instance.stub(:own?).with(@other_author).and_return(false)
\r
196 Comic.any_instance.stub(:visible?).with(@other_author).and_return(false)
\r
197 r = @story.visible?(@other_author)
200 it '他人のコミックのストーリーでも公開なら許可する' do
\r
201 Comic.any_instance.stub(:own?).with(@other_author).and_return(false)
\r
202 Comic.any_instance.stub(:visible?).with(@other_author).and_return(true)
\r
203 r = @story.visible?(@other_author)
207 context '検査対象がそれ以外のとき' do
209 r = @story.visible?(@admin)
215 describe '一覧取得に於いて' do
217 @comic = FactoryGirl.create :comic, :author_id => @author.id
218 @panel = FactoryGirl.create :panel, :author_id => @author.id
219 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
220 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
221 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
222 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
224 context 'offset補正について' do
225 it '文字列から数値に変換される' do
226 Story.offset(100, '8').should eq 8
229 Story.offset(100).should eq 0
231 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
233 it '1件のときオフセット1なら0になる' do
234 Story.offset(1, '1').should eq 0
236 it '5件のときオフセット5なら4になる' do
237 Story.offset(5, '5').should eq 4
239 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
240 #-4のときは、最後から4つのコマを表示する。
241 it '2件のときオフセット-1なら1になる' do
242 Story.offset(2, '-1').should eq 1
244 it '5件のときオフセット-2なら3になる' do
245 Story.offset(5, '-2').should eq 3
247 # 最終的なが負になるなど、不正な値が入ったときは0となる。
248 it '2件のときオフセット-5なら0になる' do
249 Story.offset(2, '-5').should eq 0
252 context 'panel_count補正について' do
253 it '文字列から数値に変換される' do
254 Story.panel_count(100, '7').should eq 7
256 it 'nilの場合はStory.default_panel_sizeになる' do
257 Story.panel_count(100).should eq Story.default_panel_size
259 it '0以下の場合はStory.default_panel_sizeになる' do
260 Story.panel_count(100, '0').should eq Story.default_panel_size
262 it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
263 Story.panel_count(100, '1000').should eq Story.max_panel_size
267 c = Story.play_list @comic, @author
271 #公開コミックの公開コマは(他人のコミックであっても)含んでいる
272 v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
273 c = Story.play_list @comic, @author
274 c.should eq [ @story, v]
277 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
278 c = Story.play_list @comic, @author
279 c.should eq [ @story, h]
281 context 'DBに5件あって1ページの件数を2件に変えたとして' do
283 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
284 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
285 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
286 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
288 it 'offset=0なら末尾2件を返す' do
290 c = Story.play_list( @comic, @author, 0, 2)
291 c.should eq [@story, @story2]
293 it 'offset=2なら中間2件を返す' do
294 c = Story.play_list(@comic, @author, 2, 2)
295 c.should eq [@story3, @story4]
297 it 'offset=4なら先頭1件を返す' do
298 c = Story.play_list(@comic, @author, 4, 2)
299 c.should eq [@story5]
303 describe 'list関連テーブルプションに於いて' do
304 it 'includeキーを含んでいる' do
306 r.has_key?(:include).should be_true
309 r = Story.list_opt[:include]
310 r.should have(3).items
313 r = Story.list_opt[:include]
314 r.has_key?(:comic).should be_true
316 it 'コミックは作家を含んでいる' do
317 r = Story.list_opt[:include]
318 r[:comic].has_key?(:author).should be_true
321 r = Story.list_opt[:include]
322 r.has_key?(:author).should be_true
325 r = Story.list_opt[:include]
326 r.has_key?(:panel).should be_true
329 r = Story.list_opt[:include]
330 r[:panel].has_key?(:author).should be_true
333 r = Story.list_opt[:include]
334 r[:panel].has_key?(:panel_pictures).should be_true
336 it 'コマ絵は実素材を含んでいる' do
337 r = Story.list_opt[:include]
338 r[:panel][:panel_pictures].has_key?(:picture).should be_true
341 r = Story.list_opt[:include]
342 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
344 it '実素材はライセンスを含んでいる' do
345 r = Story.list_opt[:include]
346 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
348 it 'コマはフキダシを含んでいる' do
349 r = Story.list_opt[:include]
350 r[:panel].has_key?(:speech_balloons).should be_true
352 it 'フキダシはフキダシ枠を含んでいる' do
353 r = Story.list_opt[:include]
354 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
356 it 'フキダシはセリフを含んでいる' do
357 r = Story.list_opt[:include]
358 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
361 describe 'json一覧出力オプションに於いて' do
364 describe '自分のストーリー一覧取得に於いて' do
366 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
367 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
368 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
369 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
370 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
371 @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
372 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
374 context 'つつがなく終わるとき' do
\r
375 it '一覧取得オプションを利用している' do
\r
376 Story.stub(:list_opt).with(any_args).and_return({})
\r
377 Story.should_receive(:list_opt).with(any_args).exactly(1)
\r
378 r = Story.mylist @author
382 s = Story.mylist @author
386 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
387 sl = Story.mylist @author
388 sl.should eq [ns, @story]
390 it '他人のストーリーはコマコミックともに公開でも含まない' do
391 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
392 sl = Story.mylist @author
393 sl.should eq [@story]
395 it '自分のストーリーはコマコミックともに非公開でも含んでいる' do
396 hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
397 sl = Story.mylist @author
398 sl.should eq [hs, @story]
400 context 'DBに5件あって1ページの件数を2件に変えたとして' do
402 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
403 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
404 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
405 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
408 c = Story.mylist @author, 1, 2
409 c.should have(2).items
411 it 'page=1なら末尾2件を返す' do
413 c = Story.mylist(@author, 1, 2)
414 c.should eq [@story5, @story4]
416 it 'page=2なら中間2件を返す' do
417 c = Story.mylist(@author, 2, 2)
418 c.should eq [@story3, @story2]
420 it 'page=3なら先頭1件を返す' do
421 c = Story.mylist(@author, 3, 2)
425 context 'DBに5件あって1ページの件数を0件に変えたとして' do
427 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
428 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
429 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
430 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
431 Author.stub(:default_story_size).and_return(2)
\r
434 r = Story.mylist @author, 5, 0
435 r.should have(5).items
440 describe '単体取得に於いて' do
442 @comic = FactoryGirl.create :comic, :author_id => @author.id
443 @panel = FactoryGirl.create :panel, :author_id => @author.id
444 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
446 context 'つつがなく終わるとき' do
\r
447 it '単体取得オプションを利用している' do
\r
448 Story.stub(:show_opt).with(any_args).and_return({})
\r
449 Story.should_receive(:show_opt).with(any_args).exactly(1)
\r
450 r = Story.show @story.id, @author
452 it '閲覧許可を問い合わせている' do
\r
453 Story.any_instance.stub(:visible?).with(@author).and_return(true)
\r
454 Story.any_instance.should_receive(:visible?).with(@author).exactly(1)
\r
455 r = Story.show @story.id, @author
459 l = Story.show @story.id, @author
462 context '他人のストーリーを開こうとしたとき' do
463 it '403Forbidden例外を返す' do
464 Story.any_instance.stub(:visible?).with(@other_author).and_return(false)
466 Story.show @story.id, @other_author
467 }.should raise_error(ActiveRecord::Forbidden)
470 context '存在しないストーリーを開こうとしたとき' do
471 it '404RecordNotFound例外を返す' do
473 Story.show 110, @author
474 }.should raise_error(ActiveRecord::RecordNotFound)
479 describe '編集取得に於いて' do
481 @comic = FactoryGirl.create :comic, :author_id => @author.id
482 @panel = FactoryGirl.create :panel, :author_id => @author.id
483 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
485 context 'つつがなく終わるとき' do
\r
486 it '単体取得オプションを利用している' do
\r
487 Story.stub(:show_opt).with(any_args).and_return({})
\r
488 Story.should_receive(:show_opt).with(any_args).exactly(1)
\r
489 r = Story.edit @story.id, @author
491 it '所持判定を問い合わせている' do
\r
492 Story.any_instance.stub(:own?).with(any_args).and_return(true)
\r
493 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
494 r = Story.edit @story.id, @author
498 l = Story.edit @story.id, @author
501 context '他人のストーリーを開こうとしたとき' do
502 it '403Forbidden例外を返す' do
503 Story.any_instance.stub(:own?).and_return(false)
505 Story.edit @story.id, @author
506 }.should raise_error(ActiveRecord::Forbidden)
509 context '存在しないストーリーを開こうとしたとき' do
510 it '404RecordNotFound例外を返す' do
512 Story.edit 110, @author
513 }.should raise_error(ActiveRecord::RecordNotFound)
518 describe '単体取得オプションに於いて' do
519 it 'includeキーを含んでいる' do
521 r.has_key?(:include).should be_true
524 r = Story.show_opt[:include]
525 r.should have(3).items
528 r = Story.show_opt[:include]
529 r.has_key?(:comic).should be_true
531 it 'コミックは作家を含んでいる' do
532 r = Story.show_opt[:include]
533 r[:comic].has_key?(:author).should be_true
536 r = Story.show_opt[:include]
537 r.has_key?(:author).should be_true
540 r = Story.show_opt[:include]
541 r.has_key?(:panel).should be_true
544 r = Story.show_opt[:include]
545 r[:panel].has_key?(:author).should be_true
548 r = Story.show_opt[:include]
549 r[:panel].has_key?(:panel_pictures).should be_true
551 it 'コマ絵は実素材を含んでいる' do
552 r = Story.show_opt[:include]
553 r[:panel][:panel_pictures].has_key?(:picture).should be_true
556 r = Story.show_opt[:include]
557 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
559 it '実素材はライセンスを含んでいる' do
560 r = Story.show_opt[:include]
561 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
563 it 'コマはフキダシを含んでいる' do
564 r = Story.show_opt[:include]
565 r[:panel].has_key?(:speech_balloons).should be_true
567 it 'フキダシはフキダシ枠を含んでいる' do
568 r = Story.show_opt[:include]
569 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
571 it 'フキダシはセリフを含んでいる' do
572 r = Story.show_opt[:include]
573 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
576 describe 'json単体取得オプションに於いて' do
579 describe 'ストーリーのjson出力に於いて' do
582 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
583 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
584 @sb = @panel.speech_balloons.create(
\r
585 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
587 @gc = @panel.ground_colors.create(
\r
588 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
590 @gp = @panel.ground_pictures.create(
\r
591 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
593 @pc = @panel.panel_colors.create(
\r
594 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
597 @comic = FactoryGirl.create :comic, :author_id => @author.id
598 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
600 context '事前チェックする' do
602 Panel.any_instance.stub(:elements).and_return('{}')
604 it 'コマ要素のjson出力を依頼している' do
\r
605 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
606 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
\r
607 r = @story.story_as_json @author
610 it 'json textを返している' do
\r
611 r = JSON.parse @story.story_as_json(@author)
\r
612 r.is_a?(Hash).should be_true
\r
614 it 'comic,author,panel,コマ要素を含んでいる' do
\r
615 r = JSON.parse @story.story_as_json(@author)
\r
616 r.has_key?('comic').should be_true
\r
617 r['comic'].has_key?('author').should be_true
\r
618 r.has_key?('author').should be_true
\r
619 r.has_key?('panel').should be_true
\r
620 r['panel'].has_key?('author').should be_true
\r
622 context 'コマ閲覧許可のとき' do
624 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
626 it 'コマ要素にコマ要素を追加している' do
\r
627 r = JSON.parse @story.story_as_json(@author)
\r
628 r['panel'].has_key?('elements').should be_true
\r
629 r['panel']['elements'].should_not be_empty
\r
632 context 'コマ閲覧不許可のとき' do
634 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
636 it 'コマ要素にデータを含ませない' do
\r
637 r = JSON.parse @story.story_as_json(@author)
\r
638 r['panel'].has_key?('elements').should be_false
\r
643 describe 'ストーリーリストのjson出力に於いて' do
\r
645 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
646 @comic = FactoryGirl.create :comic, :author_id => @author.id
647 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
648 Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
\r
650 context 'つつがなく終わるとき' do
\r
651 it 'ストーリーのjson出力を依頼している' do
\r
652 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
\r
653 r = Story.list_as_json_text [@story], @author
\r
656 it 'json textを返している' do
\r
657 r = Story.list_as_json_text [@story], @author
\r
659 j.is_a?(Array).should be_true
\r
661 it 'ストーリーを含んでいる' do
\r
662 r = Story.list_as_json_text [@story], @author
\r
664 j.first.has_key?('s').should be_true
\r
668 describe 't補充値に於いて' do
670 @comic = FactoryGirl.create :comic, :author_id => @author.id
671 @panel = FactoryGirl.create :panel, :author_id => @author.id
674 context 'コミック初のコマなら' do
676 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
678 r = Story.new_t @story.comic_id
682 context 'コミックに一個コマがあるとき' do
684 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
685 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
687 r = Story.new_t @story.comic_id
691 context 'コミックに2個コマがあるとき' do
693 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
694 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
695 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
697 r = Story.new_t @story.comic_id
702 describe 'シリアライズチェックに於いて' do
703 context 'つつがなく終わるとき' do
704 it '0からシリアライズされているならTrueを返す' do
705 r = Story.serial? [0, 1, 2]
708 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
709 r = Story.serial? [0, 2, 1]
712 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
713 r = Story.serial? [ 2, 1, 4, 3, 0]
718 it '0から始まらないならFalseを返す' do
719 r = Story.serial? [1, 2, 3]
722 it '連続していないならFalseを返す' do
723 r = Story.serial? [0, 1, 2, 4]
726 it '連続していないならFalseを返す' do
727 r = Story.serial? [0, 1, 2, 4, 5]
732 describe 't収集に於いて' do
734 @comic = FactoryGirl.create :comic, :author_id => @author.id
735 @panel = FactoryGirl.create :panel, :author_id => @author.id
736 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
737 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
738 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
740 context 'つつがなく終わるとき' do
741 it 'ストーリーから同一コミックのtだけを収集している' do
742 r = Story.collect_t @story
747 it 'ストーリーから同一コミックのtだけを収集している' do
748 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
749 r = Story.collect_t @story
750 r.sort.should eq [0, 1]
753 context '複数コマでヨソのコミックも混じっているとき' do
754 it 'ストーリーから同一コミックのtだけを収集している' do
755 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
756 r = Story.collect_t @story
757 r.sort.should eq [0, 1]
761 describe 'tチェックに於いて' do
763 @comic = FactoryGirl.create :comic, :author_id => @author.id
764 @panel = FactoryGirl.create :panel, :author_id => @author.id
765 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
767 context 'つつがなく終わるとき' do
769 Story.should_receive(:collect_t).with(any_args).exactly(1)
770 Story.stub(:collect_t).with(any_args).and_return([])
771 Story.stub(:serial?).with(any_args).and_return(true)
772 r = Story.validate_t @story
774 it '収集したtをシリアライズチェック依頼している' do
775 Story.stub(:collect_t).with(any_args).and_return([])
776 Story.should_receive(:serial?).with(any_args).exactly(1)
777 Story.stub(:serial?).with(any_args).and_return(true)
778 r = Story.validate_t @story
782 #依頼チェックだけでは不安なので最低限のチェックを
784 it '一件だけで正常通過している' do
785 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
786 r = Story.validate_t @story
791 it '2件目を作っても正常通過している' do
792 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
793 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
794 r = Story.validate_t @story2
799 describe '挿入シフトに於いて' do
801 @comic = FactoryGirl.create :comic, :author_id => @author.id
802 @panel = FactoryGirl.create :panel, :author_id => @author.id
806 it 'Updateを依頼している' do
807 Story.stub(:update_all).with(any_args)
808 Story.should_receive(:update_all).with(any_args).exactly(1)
809 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
813 context 'テーブルに1件(t:0)で0に挿入したとき' do
815 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
816 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
818 it '既存の行を1にシフトしている' do
821 l.first.t.should eq 1
823 it 'これから挿入するt(0)が欠番になっている' do
825 l = Story.find(:all).map {|s| s.t }
826 l.include?(0).should_not be_true
829 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
831 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
832 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
833 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
835 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
837 l = Story.find(:all).map {|s| s.t }
838 l.sort.should eq [0, 2]
841 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
843 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
844 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
845 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
846 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
847 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
848 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
850 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
852 l = Story.find(:all).map {|s| s.t }
853 l.sort.should eq [0, 1, 3, 4, 5]
856 context '先ほどのケース+他のコミック1件で挿入したとき' do
858 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
859 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
860 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
861 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
862 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
863 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
864 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
865 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
867 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
869 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
870 l.sort.should eq [0, 1, 3, 4, 5]
876 @storyc2.t.should eq ot
880 describe '少ない方に移動に於いて' do
882 @comic = FactoryGirl.create :comic, :author_id => @author.id
883 @panel = FactoryGirl.create :panel, :author_id => @author.id
886 it 'Updateを依頼している' do
887 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
888 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
889 Story.stub(:update_all).with(any_args)
890 Story.should_receive(:update_all).with(any_args).exactly(1)
893 @story2.lesser_shift ot
896 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
898 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
899 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
903 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
905 @story2.lesser_shift @ot
906 l = Story.find(:all).map {|s| s.t }
907 l.sort.should eq [1, 1]
909 it '既存のt0を1にシフトしている' do
910 @story2.lesser_shift @ot
915 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
917 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
918 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
919 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
923 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
925 @story3.lesser_shift @ot
926 l = Story.find(:all).map {|s| s.t }
927 l.sort.should eq [0, 2, 2]
929 it '既存のt1を2にシフトしている' do
930 @story3.lesser_shift @ot
932 @story2.t.should eq 2
935 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
937 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
938 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
939 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
940 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
941 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
945 it 'これから挿入するt(1)が欠番になっている' do
947 @story4.lesser_shift @ot
948 l = Story.find(:all).map {|s| s.t }
949 l.sort.should eq [0, 2, 3, 3, 4]
952 @story4.lesser_shift @ot
957 @story4.lesser_shift @ot
959 @story5.t.should eq 4
961 it '既存のt1を2にシフトしている' do
962 @story4.lesser_shift @ot
964 @story2.t.should eq 2
966 it '既存のt2を3にシフトしている' do
967 @story4.lesser_shift @ot
969 @story3.t.should eq 3
972 context '先ほどのケース+他のコミック1件で挿入したとき' do
974 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
975 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
976 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
977 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
978 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
979 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
980 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
984 it 'これから挿入するt(1)が欠番になっている' do
985 @story4.lesser_shift @ot
986 l = Story.find(:all).map {|s| s.t }
987 l.sort.should eq [0, 0, 2, 3, 3, 4]
990 @story4.lesser_shift @ot
995 @story4.lesser_shift @ot
997 @story5.t.should eq 4
999 it '既存のt1を2にシフトしている' do
1000 @story4.lesser_shift @ot
1002 @story2.t.should eq 2
1004 it '既存のt2を3にシフトしている' do
1005 @story4.lesser_shift @ot
1007 @story3.t.should eq 3
1009 it '他のコミックに影響がない' do
1010 @story4.lesser_shift @ot
1012 @storyc2.t.should eq 0
1017 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
1019 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1020 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1024 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1026 @story2.lesser_shift @ot
1027 l = Story.find(:all).map {|s| s.t }
1028 l.sort.should eq [1, 1]
1030 it '既存のt0を1にシフトしている' do
1031 @story2.lesser_shift @ot
1033 @story.t.should eq 1
1035 it '既存のt1は0に補正されている' do
1036 @story2.lesser_shift @ot
1037 @story2.t.should eq 0
1041 describe '大きい方に移動に於いて' do
1043 @comic = FactoryGirl.create :comic, :author_id => @author.id
1044 @panel = FactoryGirl.create :panel, :author_id => @author.id
1047 it 'Updateを依頼している' do
1048 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1049 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1050 Story.stub(:update_all).with(any_args)
1051 Story.should_receive(:update_all).with(any_args).exactly(1)
1054 @story.higher_shift ot
1057 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1059 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1060 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1064 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1066 @story.higher_shift @ot
1067 l = Story.find(:all).map {|s| s.t }
1068 l.sort.should eq [0, 0]
1070 it '既存のt1を0にシフトしている' do
1071 @story.higher_shift @ot
1073 @story2.t.should eq 0
1076 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1078 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1079 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1080 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1084 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1086 @story.higher_shift @ot
1087 l = Story.find(:all).map {|s| s.t }
1088 l.sort.should eq [0, 0, 2]
1090 it '既存のt1を0にシフトしている' do
1091 @story.higher_shift @ot
1093 @story2.t.should eq 0
1096 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1098 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1099 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1100 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1101 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1102 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1106 it 'これから挿入するt(3)が欠番になっている' do
1108 @story2.higher_shift @ot
1109 l = Story.find(:all).map {|s| s.t }
1110 l.sort.should eq [0, 1, 1, 2, 4]
1112 it '既存のt0には変化がない' do
1113 @story2.higher_shift @ot
1115 @story.t.should eq 0
1117 it '既存のt4には変化がない' do
1118 @story2.higher_shift @ot
1120 @story5.t.should eq 4
1122 it '既存のt2を1にシフトしている' do
1123 @story2.higher_shift @ot
1125 @story3.t.should eq 1
1127 it '既存のt3を2にシフトしている' do
1128 @story2.higher_shift @ot
1130 @story4.t.should eq 2
1133 context '先ほどのケース+他のコミック1件で挿入したとき' do
1135 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1136 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1137 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1138 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1139 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1140 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1141 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1145 it 'これから挿入するt(3)が欠番になっている' do
1147 @story2.higher_shift @ot
1148 l = Story.find(:all).map {|s| s.t }
1149 l.sort.should eq [0, 0, 1, 1, 2, 4]
1151 it '既存のt0には変化がない' do
1152 @story2.higher_shift @ot
1154 @story.t.should eq 0
1156 it '既存のt4には変化がない' do
1157 @story2.higher_shift @ot
1159 @story5.t.should eq 4
1161 it '既存のt2を1にシフトしている' do
1162 @story2.higher_shift @ot
1164 @story3.t.should eq 1
1166 it '既存のt3を2にシフトしている' do
1167 @story2.higher_shift @ot
1169 @story4.t.should eq 2
1171 it '他のコミックに影響がない' do
1172 @story2.higher_shift @ot
1174 @storyc2.t.should eq 0
1178 #max超えたときはmaxとして正常扱い
1179 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1181 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1182 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1186 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1188 @story.higher_shift @ot
1189 l = Story.find(:all).map {|s| s.t }
1190 l.sort.should eq [0, 0]
1192 it '既存のt1を0にシフトしている' do
1193 @story.higher_shift @ot
1195 @story2.t.should eq 0
1197 it '既存のt0は1に補正されている' do
1198 @story.higher_shift @ot
1199 @story.t.should eq 1
1203 describe '入れ替えに於いて' do
1205 @comic = FactoryGirl.create :comic, :author_id => @author.id
1206 @panel = FactoryGirl.create :panel, :author_id => @author.id
1207 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1208 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1210 context '新tが旧tより小さいとき' do
1211 it '少ない方に移動を依頼している' do
1212 Story.any_instance.stub(:lesser_shift).with(any_args)
1213 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1216 @story2.update_shift ot
1219 context '新tが旧tより大きいとき' do
1220 it '大きい方に移動を依頼している' do
1221 Story.any_instance.stub(:higher_shift).with(any_args)
1222 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1225 @story.update_shift ot
1229 describe '順序入れ替えに於いて' do
1231 @comic = FactoryGirl.create :comic, :author_id => @author.id
1232 @panel = FactoryGirl.create :panel, :author_id => @author.id
1234 context 'オブジェクトが新規でtが空のとき' do
1235 it '末尾追加としてtを補充依頼している' do
1236 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1237 Story.stub(:new_t).with(any_args).and_return(0)
1238 Story.should_receive(:new_t).with(any_args).exactly(1)
1243 context 'オブジェクトが新規でtが設定されているとき' do
1244 it '挿入追加として挿入シフトを依頼している' do
1245 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1246 Story.any_instance.stub(:insert_shift).with(any_args)
1247 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1252 context 'オブジェクトが新規でなくtが設定されているとき' do
1253 it 'コマ移動として入れ替えを依頼している' do
1254 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1255 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1256 Story.any_instance.stub(:update_shift).with(any_args)
1257 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1262 context 'オブジェクトが新規でなくtが空のとき' do
1263 it '入れ替えもシフトもせず、tを空のままにしている' do
1264 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1268 describe '編集許可に於いて' do
1270 @comic = FactoryGirl.create :comic, :author_id => @author.id
1271 @panel = FactoryGirl.create :panel, :author_id => @author.id
1272 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1274 context 'つつがなく終わるとき' do
1280 context 'コミックで引っかかるとき' do
1282 @story.comic_id = nil
1287 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1292 context 'コマで引っかかるとき' do
1294 @story.panel_id = nil
1299 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1305 describe '保存に於いて' do
1307 @comic = FactoryGirl.create :comic, :author_id => @author.id
1308 @panel = FactoryGirl.create :panel, :author_id => @author.id
1309 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1311 context 'つつがなく終わるとき' do
1312 it '編集許可チェックを依頼している' do
1313 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1314 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1317 it '順序入れ替えを依頼している' do
1318 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1319 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1320 Story.any_instance.stub(:save).with(any_args).and_return(true)
1321 Story.stub(:validate_t).with(any_args).and_return(true)
1325 Story.stub(:new_t).with(any_args).and_return(0)
1326 Story.any_instance.stub(:save).with(any_args).and_return(true)
1327 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1328 Story.stub(:validate_t).with(any_args).and_return(true)
1331 it 'tのシリアライズチェックを依頼している' do
1332 Story.stub(:new_t).with(any_args).and_return(0)
1333 Story.any_instance.stub(:save).with(any_args).and_return(true)
1334 Story.stub(:validate_t).with(any_args).and_return(true)
1335 Story.should_receive(:validate_t).with(any_args).exactly(1)
1339 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1340 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1342 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1343 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1344 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1345 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1346 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1347 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1348 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1349 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1351 it '既存のt0には変化がない' do
1354 @story.t.should eq 0
1356 it '既存のt1には変化がない' do
1359 @story2.t.should eq 1
1361 it '既存のt2を3にシフトしている' do
1364 @story3.t.should eq 3
1366 it '既存のt3を4にシフトしている' do
1369 @story4.t.should eq 4
1371 it '既存のt5を5にシフトしている' do
1374 @story5.t.should eq 5
1376 it '新規のt2が作成されている' do
1379 @story6.t.should eq 2
1381 it '他のコミックに影響がない' do
1385 @storyc2.t.should eq @ot
1388 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
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
1400 it '既存のt0には変化がない' do
1403 @story.t.should eq 0
1405 it '既存のt4には変化がない' do
1408 @story5.t.should eq 4
1410 it '既存のt1を2にシフトしている' do
1413 @story2.t.should eq 2
1415 it '既存のt2を3にシフトしている' do
1418 @story3.t.should eq 3
1420 it '既存のt3を1にシフトしている' do
1423 @story4.t.should eq 1
1425 it '他のコミックに影響がない' do
1428 @storyc2.t.should eq 0
1431 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1433 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1434 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1435 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1436 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1437 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1438 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1439 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1443 it '既存のt0には変化がない' do
1446 @story.t.should eq 0
1448 it '既存のt4には変化がない' do
1451 @story5.t.should eq 4
1453 it '既存のt1を3にシフトしている' do
1456 @story2.t.should eq 3
1458 it '既存のt2を1にシフトしている' do
1461 @story3.t.should eq 1
1463 it '既存のt3を2にシフトしている' do
1466 @story4.t.should eq 2
1468 it '他のコミックに影響がない' do
1471 @storyc2.t.should eq 0
1474 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1475 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1477 Story.any_instance.stub(:save).with(any_args).and_return(false)
1478 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1479 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1480 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1481 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1482 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1483 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1484 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1485 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1490 @story.t.should eq 0
1492 @story2.t.should eq 1
1494 @story3.t.should eq 2
1496 @story4.t.should eq 3
1498 @story5.t.should eq 4
1500 @storyc2.t.should eq 0
1507 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1509 Story.stub(:validate_t).with(any_args).and_return(false)
1510 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1511 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1512 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1513 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1514 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1515 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1516 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1523 @story.t.should eq 0
1525 @story2.t.should eq 1
1527 @story3.t.should eq 2
1529 @story4.t.should eq 3
1531 @story5.t.should eq 4
1533 @storyc2.t.should eq 0
1536 r = @story4.store @ot
1539 it 'tにエラーメッセージが入っている' do
1541 @story4.errors[:t].should_not be_empty
1542 @story4.valid?.should be_true
1545 context '編集不可だったとき' do
1547 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1548 Story.any_instance.stub(:allow?).and_return(false)
1550 it '403Forbidden例外を返す' do
1553 }.should raise_error(ActiveRecord::Forbidden)
1557 describe '切り詰め処理つき削除に於いて' do
1559 @comic = FactoryGirl.create :comic, :author_id => @author.id
1560 @panel = FactoryGirl.create :panel, :author_id => @author.id
1561 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1563 context 'つつがなく終わるとき' do
1566 @story.destroy_and_shorten
1567 }.should change(Story, :count ).by(-1)
1570 #連携テスト。切り詰めが直接DBをいじる
1571 context '2件で先頭を削除したとき' do
1573 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1577 @story.destroy_and_shorten
1578 }.should change(Story, :count ).by(-1)
1581 @story.destroy_and_shorten
1583 Story.find @story.id
1584 }.should raise_error(ActiveRecord::RecordNotFound)
1587 @story.destroy_and_shorten
1589 @story2.t.should eq 0
1592 context '3件で先頭を削除したとき' do
1594 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1595 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1599 @story.destroy_and_shorten
1600 }.should change(Story, :count ).by(-1)
1603 @story.destroy_and_shorten
1605 Story.find @story.id
1606 }.should raise_error(ActiveRecord::RecordNotFound)
1609 @story.destroy_and_shorten
1611 @story2.t.should eq 0
1614 @story.destroy_and_shorten
1616 @story3.t.should eq 1
1619 context '5件で3件目を削除したとき' do
1621 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1622 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1623 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1624 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1628 @story3.destroy_and_shorten
1629 }.should change(Story, :count ).by(-1)
1632 @story3.destroy_and_shorten
1634 @story.t.should eq 0
1637 @story3.destroy_and_shorten
1639 @story2.t.should eq 1
1642 @story3.destroy_and_shorten
1644 Story.find @story3.id
1645 }.should raise_error(ActiveRecord::RecordNotFound)
1648 @story3.destroy_and_shorten
1650 @story4.t.should eq 2
1653 @story3.destroy_and_shorten
1655 @story5.t.should eq 3
1658 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する