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 = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14 @other_user = FactoryGirl.create( :user_yas)
15 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
16 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
17 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
18 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
19 @sbt = FactoryGirl.create :speech_balloon_template
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
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
176 Comic.any_instance.stub(:visible?).with(nil).and_return(true)
177 r = @story.visible?(nil)
180 it '非公開コミックのストーリーなら許可しない' do
181 Comic.any_instance.stub(:visible?).with(nil).and_return(false)
182 r = @story.visible?(nil)
187 context '検査対象が作家のとき' do
188 it '自分のコミックのストーリーなら許可する' do
189 Comic.any_instance.stub(:own?).with(@author).and_return(true)
190 Comic.any_instance.stub(:visible?).with(@author).and_return(true)
191 r = @story.visible?(@author)
194 it '他人の非公開コミックのストーリーなら許可しない' do
195 Comic.any_instance.stub(:own?).with(@other_author).and_return(false)
196 Comic.any_instance.stub(:visible?).with(@other_author).and_return(false)
197 r = @story.visible?(@other_author)
200 it '他人のコミックのストーリーでも公開なら許可する' do
201 Comic.any_instance.stub(:own?).with(@other_author).and_return(false)
202 Comic.any_instance.stub(:visible?).with(@other_author).and_return(true)
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
375 it '一覧取得オプションを利用している' do
376 Story.stub(:list_opt).with(any_args).and_return({})
377 Story.should_receive(:list_opt).with(any_args).exactly(1)
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)
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
447 it '単体取得オプションを利用している' do
448 Story.stub(:show_opt).with(any_args).and_return({})
449 Story.should_receive(:show_opt).with(any_args).exactly(1)
450 r = Story.show @story.id, @author
452 it '閲覧許可を問い合わせている' do
453 Story.any_instance.stub(:visible?).with(@author).and_return(true)
454 Story.any_instance.should_receive(:visible?).with(@author).exactly(1)
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
486 it '単体取得オプションを利用している' do
487 Story.stub(:show_opt).with(any_args).and_return({})
488 Story.should_receive(:show_opt).with(any_args).exactly(1)
489 r = Story.edit @story.id, @author
491 it '所持判定を問い合わせている' do
492 Story.any_instance.stub(:own?).with(any_args).and_return(true)
493 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
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
583 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
584 @sb = @panel.speech_balloons.create(
585 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
587 @gc = @panel.ground_colors.create(
588 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
590 @gp = @panel.ground_pictures.create(
591 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
593 @pc = @panel.panel_colors.create(
594 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
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
605 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
606 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
607 r = @story.story_as_json @author
610 it 'json textを返している' do
611 r = JSON.parse @story.story_as_json(@author)
612 r.is_a?(Hash).should be_true
614 it 'comic,author,panel,コマ要素を含んでいる' do
615 r = JSON.parse @story.story_as_json(@author)
616 r.has_key?('comic').should be_true
617 r['comic'].has_key?('author').should be_true
618 r.has_key?('author').should be_true
619 r.has_key?('panel').should be_true
620 r['panel'].has_key?('author').should be_true
622 context 'コマ閲覧許可のとき' do
624 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
626 it 'コマ要素にコマ要素を追加している' do
627 r = JSON.parse @story.story_as_json(@author)
628 r['panel'].has_key?('elements').should be_true
629 r['panel']['elements'].should_not be_empty
632 context 'コマ閲覧不許可のとき' do
634 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
636 it 'コマ要素にデータを含ませない' do
637 r = JSON.parse @story.story_as_json(@author)
638 r['panel'].has_key?('elements').should be_false
643 describe 'ストーリーリストのjson出力に於いて' do
645 @panel = FactoryGirl.create :panel, :author_id => @author.id
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}')
650 context 'つつがなく終わるとき' do
651 it 'ストーリーのjson出力を依頼している' do
652 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
653 r = Story.list_as_json_text [@story], @author
656 it 'json textを返している' do
657 r = Story.list_as_json_text [@story], @author
659 j.is_a?(Array).should be_true
662 r = Story.list_as_json_text [@story], @author
664 j.first.has_key?('s').should be_true
668 describe 'ライセンス素材に於いて' do
671 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
672 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
673 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
674 @panel = FactoryGirl.create :panel, :author_id => @author.id
675 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id
677 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
678 @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id
681 @comic = FactoryGirl.create :comic, :author_id => @author.id
682 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
683 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id
687 context 'つつがなく終わるとき' do
689 it '連想配列(値は実素材、キーは実素材id)を返している' do
690 r = Story.licensed_pictures [@story, @story2]
691 r.is_a?(Hash).should be_true
692 r.should have(2).items
693 r[@pp.picture_id].should eq @p
694 r[@pp2.picture_id].should eq @p2
698 describe 't補充値に於いて' do
700 @comic = FactoryGirl.create :comic, :author_id => @author.id
701 @panel = FactoryGirl.create :panel, :author_id => @author.id
704 context 'コミック初のコマなら' do
706 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
708 r = Story.new_t @story.comic_id
712 context 'コミックに一個コマがあるとき' do
714 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
715 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
717 r = Story.new_t @story.comic_id
721 context 'コミックに2個コマがあるとき' do
723 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
724 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
725 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
727 r = Story.new_t @story.comic_id
732 describe 'シリアライズチェックに於いて' do
733 context 'つつがなく終わるとき' do
734 it '0からシリアライズされているならTrueを返す' do
735 r = Story.serial? [0, 1, 2]
738 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
739 r = Story.serial? [0, 2, 1]
742 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
743 r = Story.serial? [ 2, 1, 4, 3, 0]
748 it '0から始まらないならFalseを返す' do
749 r = Story.serial? [1, 2, 3]
752 it '連続していないならFalseを返す' do
753 r = Story.serial? [0, 1, 2, 4]
756 it '連続していないならFalseを返す' do
757 r = Story.serial? [0, 1, 2, 4, 5]
762 describe 't収集に於いて' do
764 @comic = FactoryGirl.create :comic, :author_id => @author.id
765 @panel = FactoryGirl.create :panel, :author_id => @author.id
766 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
767 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
768 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
770 context 'つつがなく終わるとき' do
771 it 'ストーリーから同一コミックのtだけを収集している' do
772 r = Story.collect_t @story
777 it 'ストーリーから同一コミックのtだけを収集している' do
778 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
779 r = Story.collect_t @story
780 r.sort.should eq [0, 1]
783 context '複数コマでヨソのコミックも混じっているとき' do
784 it 'ストーリーから同一コミックのtだけを収集している' do
785 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
786 r = Story.collect_t @story
787 r.sort.should eq [0, 1]
791 describe 'tチェックに於いて' do
793 @comic = FactoryGirl.create :comic, :author_id => @author.id
794 @panel = FactoryGirl.create :panel, :author_id => @author.id
795 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
797 context 'つつがなく終わるとき' do
799 Story.should_receive(:collect_t).with(any_args).exactly(1)
800 Story.stub(:collect_t).with(any_args).and_return([])
801 Story.stub(:serial?).with(any_args).and_return(true)
802 r = Story.validate_t @story
804 it '収集したtをシリアライズチェック依頼している' do
805 Story.stub(:collect_t).with(any_args).and_return([])
806 Story.should_receive(:serial?).with(any_args).exactly(1)
807 Story.stub(:serial?).with(any_args).and_return(true)
808 r = Story.validate_t @story
812 #依頼チェックだけでは不安なので最低限のチェックを
814 it '一件だけで正常通過している' do
815 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
816 r = Story.validate_t @story
821 it '2件目を作っても正常通過している' do
822 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
823 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
824 r = Story.validate_t @story2
829 describe '挿入シフトに於いて' do
831 @comic = FactoryGirl.create :comic, :author_id => @author.id
832 @panel = FactoryGirl.create :panel, :author_id => @author.id
836 it 'Updateを依頼している' do
837 Story.stub(:update_all).with(any_args)
838 Story.should_receive(:update_all).with(any_args).exactly(1)
839 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
843 context 'テーブルに1件(t:0)で0に挿入したとき' do
845 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
846 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
848 it '既存の行を1にシフトしている' do
851 l.first.t.should eq 1
853 it 'これから挿入するt(0)が欠番になっている' do
855 l = Story.find(:all).map {|s| s.t }
856 l.include?(0).should_not be_true
859 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
861 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
862 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
863 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
865 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
867 l = Story.find(:all).map {|s| s.t }
868 l.sort.should eq [0, 2]
871 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
873 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
874 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
875 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
876 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
877 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
878 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
880 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
882 l = Story.find(:all).map {|s| s.t }
883 l.sort.should eq [0, 1, 3, 4, 5]
886 context '先ほどのケース+他のコミック1件で挿入したとき' do
888 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
889 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
890 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
891 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
892 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
893 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
894 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
895 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
897 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
899 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
900 l.sort.should eq [0, 1, 3, 4, 5]
906 @storyc2.t.should eq ot
910 describe '少ない方に移動に於いて' do
912 @comic = FactoryGirl.create :comic, :author_id => @author.id
913 @panel = FactoryGirl.create :panel, :author_id => @author.id
916 it 'Updateを依頼している' 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 Story.stub(:update_all).with(any_args)
920 Story.should_receive(:update_all).with(any_args).exactly(1)
923 @story2.lesser_shift ot
926 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
928 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
929 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
933 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
935 @story2.lesser_shift @ot
936 l = Story.find(:all).map {|s| s.t }
937 l.sort.should eq [1, 1]
939 it '既存のt0を1にシフトしている' do
940 @story2.lesser_shift @ot
945 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
947 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
948 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
949 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
953 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
955 @story3.lesser_shift @ot
956 l = Story.find(:all).map {|s| s.t }
957 l.sort.should eq [0, 2, 2]
959 it '既存のt1を2にシフトしている' do
960 @story3.lesser_shift @ot
962 @story2.t.should eq 2
965 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
967 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
968 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
969 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
970 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
971 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
975 it 'これから挿入するt(1)が欠番になっている' do
977 @story4.lesser_shift @ot
978 l = Story.find(:all).map {|s| s.t }
979 l.sort.should eq [0, 2, 3, 3, 4]
982 @story4.lesser_shift @ot
987 @story4.lesser_shift @ot
989 @story5.t.should eq 4
991 it '既存のt1を2にシフトしている' do
992 @story4.lesser_shift @ot
994 @story2.t.should eq 2
996 it '既存のt2を3にシフトしている' do
997 @story4.lesser_shift @ot
999 @story3.t.should eq 3
1002 context '先ほどのケース+他のコミック1件で挿入したとき' do
1004 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1005 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1006 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1007 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1008 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1009 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1010 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1014 it 'これから挿入するt(1)が欠番になっている' do
1015 @story4.lesser_shift @ot
1016 l = Story.find(:all).map {|s| s.t }
1017 l.sort.should eq [0, 0, 2, 3, 3, 4]
1019 it '既存のt0には変化がない' do
1020 @story4.lesser_shift @ot
1022 @story.t.should eq 0
1024 it '既存のt4には変化がない' do
1025 @story4.lesser_shift @ot
1027 @story5.t.should eq 4
1029 it '既存のt1を2にシフトしている' do
1030 @story4.lesser_shift @ot
1032 @story2.t.should eq 2
1034 it '既存のt2を3にシフトしている' do
1035 @story4.lesser_shift @ot
1037 @story3.t.should eq 3
1039 it '他のコミックに影響がない' do
1040 @story4.lesser_shift @ot
1042 @storyc2.t.should eq 0
1047 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
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
1054 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1056 @story2.lesser_shift @ot
1057 l = Story.find(:all).map {|s| s.t }
1058 l.sort.should eq [1, 1]
1060 it '既存のt0を1にシフトしている' do
1061 @story2.lesser_shift @ot
1063 @story.t.should eq 1
1065 it '既存のt1は0に補正されている' do
1066 @story2.lesser_shift @ot
1067 @story2.t.should eq 0
1071 describe '大きい方に移動に於いて' do
1073 @comic = FactoryGirl.create :comic, :author_id => @author.id
1074 @panel = FactoryGirl.create :panel, :author_id => @author.id
1077 it 'Updateを依頼している' 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 Story.stub(:update_all).with(any_args)
1081 Story.should_receive(:update_all).with(any_args).exactly(1)
1084 @story.higher_shift ot
1087 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1089 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1090 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1094 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1096 @story.higher_shift @ot
1097 l = Story.find(:all).map {|s| s.t }
1098 l.sort.should eq [0, 0]
1100 it '既存のt1を0にシフトしている' do
1101 @story.higher_shift @ot
1103 @story2.t.should eq 0
1106 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1108 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1109 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1110 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1114 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1116 @story.higher_shift @ot
1117 l = Story.find(:all).map {|s| s.t }
1118 l.sort.should eq [0, 0, 2]
1120 it '既存のt1を0にシフトしている' do
1121 @story.higher_shift @ot
1123 @story2.t.should eq 0
1126 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1128 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1129 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1130 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1131 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1132 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1136 it 'これから挿入するt(3)が欠番になっている' do
1138 @story2.higher_shift @ot
1139 l = Story.find(:all).map {|s| s.t }
1140 l.sort.should eq [0, 1, 1, 2, 4]
1142 it '既存のt0には変化がない' do
1143 @story2.higher_shift @ot
1145 @story.t.should eq 0
1147 it '既存のt4には変化がない' do
1148 @story2.higher_shift @ot
1150 @story5.t.should eq 4
1152 it '既存のt2を1にシフトしている' do
1153 @story2.higher_shift @ot
1155 @story3.t.should eq 1
1157 it '既存のt3を2にシフトしている' do
1158 @story2.higher_shift @ot
1160 @story4.t.should eq 2
1163 context '先ほどのケース+他のコミック1件で挿入したとき' do
1165 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1166 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1167 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1168 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1169 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1170 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1171 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1175 it 'これから挿入するt(3)が欠番になっている' do
1177 @story2.higher_shift @ot
1178 l = Story.find(:all).map {|s| s.t }
1179 l.sort.should eq [0, 0, 1, 1, 2, 4]
1181 it '既存のt0には変化がない' do
1182 @story2.higher_shift @ot
1184 @story.t.should eq 0
1186 it '既存のt4には変化がない' do
1187 @story2.higher_shift @ot
1189 @story5.t.should eq 4
1191 it '既存のt2を1にシフトしている' do
1192 @story2.higher_shift @ot
1194 @story3.t.should eq 1
1196 it '既存のt3を2にシフトしている' do
1197 @story2.higher_shift @ot
1199 @story4.t.should eq 2
1201 it '他のコミックに影響がない' do
1202 @story2.higher_shift @ot
1204 @storyc2.t.should eq 0
1208 #max超えたときはmaxとして正常扱い
1209 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1211 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1212 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1216 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1218 @story.higher_shift @ot
1219 l = Story.find(:all).map {|s| s.t }
1220 l.sort.should eq [0, 0]
1222 it '既存のt1を0にシフトしている' do
1223 @story.higher_shift @ot
1225 @story2.t.should eq 0
1227 it '既存のt0は1に補正されている' do
1228 @story.higher_shift @ot
1229 @story.t.should eq 1
1233 describe '入れ替えに於いて' do
1235 @comic = FactoryGirl.create :comic, :author_id => @author.id
1236 @panel = FactoryGirl.create :panel, :author_id => @author.id
1237 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1238 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1240 context '新tが旧tより小さいとき' do
1241 it '少ない方に移動を依頼している' do
1242 Story.any_instance.stub(:lesser_shift).with(any_args)
1243 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1246 @story2.update_shift ot
1249 context '新tが旧tより大きいとき' do
1250 it '大きい方に移動を依頼している' do
1251 Story.any_instance.stub(:higher_shift).with(any_args)
1252 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1255 @story.update_shift ot
1259 describe '順序入れ替えに於いて' do
1261 @comic = FactoryGirl.create :comic, :author_id => @author.id
1262 @panel = FactoryGirl.create :panel, :author_id => @author.id
1264 context 'オブジェクトが新規でtが空のとき' do
1265 it '末尾追加としてtを補充依頼している' do
1266 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1267 Story.stub(:new_t).with(any_args).and_return(0)
1268 Story.should_receive(:new_t).with(any_args).exactly(1)
1273 context 'オブジェクトが新規でtが設定されているとき' do
1274 it '挿入追加として挿入シフトを依頼している' do
1275 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1276 Story.any_instance.stub(:insert_shift).with(any_args)
1277 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1282 context 'オブジェクトが新規でなくtが設定されているとき' do
1283 it 'コマ移動として入れ替えを依頼している' do
1284 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1285 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1286 Story.any_instance.stub(:update_shift).with(any_args)
1287 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1292 context 'オブジェクトが新規でなくtが空のとき' do
1293 it '入れ替えもシフトもせず、tを空のままにしている' do
1294 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1298 describe '編集許可に於いて' do
1300 @comic = FactoryGirl.create :comic, :author_id => @author.id
1301 @panel = FactoryGirl.create :panel, :author_id => @author.id
1302 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1304 context 'つつがなく終わるとき' do
1310 context 'コミックで引っかかるとき' do
1312 @story.comic_id = nil
1317 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1322 context 'コマで引っかかるとき' do
1324 @story.panel_id = nil
1329 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1335 describe '保存に於いて' do
1337 @comic = FactoryGirl.create :comic, :author_id => @author.id
1338 @panel = FactoryGirl.create :panel, :author_id => @author.id
1339 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1341 context 'つつがなく終わるとき' do
1342 it '編集許可チェックを依頼している' do
1343 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1344 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1347 it '順序入れ替えを依頼している' do
1348 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1349 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1350 Story.any_instance.stub(:save).with(any_args).and_return(true)
1351 Story.stub(:validate_t).with(any_args).and_return(true)
1355 Story.stub(:new_t).with(any_args).and_return(0)
1356 Story.any_instance.stub(:save).with(any_args).and_return(true)
1357 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1358 Story.stub(:validate_t).with(any_args).and_return(true)
1361 it 'tのシリアライズチェックを依頼している' do
1362 Story.stub(:new_t).with(any_args).and_return(0)
1363 Story.any_instance.stub(:save).with(any_args).and_return(true)
1364 Story.stub(:validate_t).with(any_args).and_return(true)
1365 Story.should_receive(:validate_t).with(any_args).exactly(1)
1369 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1370 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1372 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1373 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1374 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1375 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1376 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1377 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1378 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1379 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1381 it '既存のt0には変化がない' do
1384 @story.t.should eq 0
1386 it '既存のt1には変化がない' do
1389 @story2.t.should eq 1
1391 it '既存のt2を3にシフトしている' do
1394 @story3.t.should eq 3
1396 it '既存のt3を4にシフトしている' do
1399 @story4.t.should eq 4
1401 it '既存のt5を5にシフトしている' do
1404 @story5.t.should eq 5
1406 it '新規のt2が作成されている' do
1409 @story6.t.should eq 2
1411 it '他のコミックに影響がない' do
1415 @storyc2.t.should eq @ot
1418 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1420 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1421 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1422 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1423 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1424 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1425 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1426 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1430 it '既存のt0には変化がない' do
1433 @story.t.should eq 0
1435 it '既存のt4には変化がない' do
1438 @story5.t.should eq 4
1440 it '既存のt1を2にシフトしている' do
1443 @story2.t.should eq 2
1445 it '既存のt2を3にシフトしている' do
1448 @story3.t.should eq 3
1450 it '既存のt3を1にシフトしている' do
1453 @story4.t.should eq 1
1455 it '他のコミックに影響がない' do
1458 @storyc2.t.should eq 0
1461 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1463 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1464 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1465 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1466 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1467 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1468 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1469 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1473 it '既存のt0には変化がない' do
1476 @story.t.should eq 0
1478 it '既存のt4には変化がない' do
1481 @story5.t.should eq 4
1483 it '既存のt1を3にシフトしている' do
1486 @story2.t.should eq 3
1488 it '既存のt2を1にシフトしている' do
1491 @story3.t.should eq 1
1493 it '既存のt3を2にシフトしている' do
1496 @story4.t.should eq 2
1498 it '他のコミックに影響がない' do
1501 @storyc2.t.should eq 0
1504 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1505 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1507 Story.any_instance.stub(:save).with(any_args).and_return(false)
1508 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1509 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1510 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1511 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1512 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1513 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1514 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1515 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1520 @story.t.should eq 0
1522 @story2.t.should eq 1
1524 @story3.t.should eq 2
1526 @story4.t.should eq 3
1528 @story5.t.should eq 4
1530 @storyc2.t.should eq 0
1537 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1539 Story.stub(:validate_t).with(any_args).and_return(false)
1540 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1541 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1542 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1543 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1544 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1545 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1546 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1553 @story.t.should eq 0
1555 @story2.t.should eq 1
1557 @story3.t.should eq 2
1559 @story4.t.should eq 3
1561 @story5.t.should eq 4
1563 @storyc2.t.should eq 0
1566 r = @story4.store @ot
1569 it 'tにエラーメッセージが入っている' do
1571 @story4.errors[:t].should_not be_empty
1572 @story4.valid?.should be_true
1575 context '編集不可だったとき' do
1577 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1578 Story.any_instance.stub(:allow?).and_return(false)
1580 it '403Forbidden例外を返す' do
1583 }.should raise_error(ActiveRecord::Forbidden)
1587 describe '切り詰め処理つき削除に於いて' do
1589 @comic = FactoryGirl.create :comic, :author_id => @author.id
1590 @panel = FactoryGirl.create :panel, :author_id => @author.id
1591 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1593 context 'つつがなく終わるとき' do
1596 @story.destroy_and_shorten
1597 }.should change(Story, :count ).by(-1)
1600 #連携テスト。切り詰めが直接DBをいじる
1601 context '2件で先頭を削除したとき' do
1603 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1607 @story.destroy_and_shorten
1608 }.should change(Story, :count ).by(-1)
1611 @story.destroy_and_shorten
1613 Story.find @story.id
1614 }.should raise_error(ActiveRecord::RecordNotFound)
1617 @story.destroy_and_shorten
1619 @story2.t.should eq 0
1622 context '3件で先頭を削除したとき' do
1624 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1625 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1629 @story.destroy_and_shorten
1630 }.should change(Story, :count ).by(-1)
1633 @story.destroy_and_shorten
1635 Story.find @story.id
1636 }.should raise_error(ActiveRecord::RecordNotFound)
1639 @story.destroy_and_shorten
1641 @story2.t.should eq 0
1644 @story.destroy_and_shorten
1646 @story3.t.should eq 1
1649 context '5件で3件目を削除したとき' do
1651 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1652 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1653 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1654 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1658 @story3.destroy_and_shorten
1659 }.should change(Story, :count ).by(-1)
1662 @story3.destroy_and_shorten
1664 @story.t.should eq 0
1667 @story3.destroy_and_shorten
1669 @story2.t.should eq 1
1672 @story3.destroy_and_shorten
1674 Story.find @story3.id
1675 }.should raise_error(ActiveRecord::RecordNotFound)
1678 @story3.destroy_and_shorten
1680 @story4.t.should eq 2
1683 @story3.destroy_and_shorten
1685 @story5.t.should eq 3
1688 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する