1 # -*- encoding: utf-8 -*-
6 FactoryGirl.create :admin
7 @sp = FactoryGirl.create :system_picture
8 @lg = FactoryGirl.create :license_group
9 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10 @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
154 describe '一覧取得に於いて' do
156 @comic = FactoryGirl.create :comic, :author_id => @author.id
157 @panel = FactoryGirl.create :panel, :author_id => @author.id
158 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
159 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
160 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
161 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
163 context 'offset補正について' do
164 it '文字列から数値に変換される' do
165 Story.offset(100, '8').should eq 8
168 Story.offset(100).should eq 0
170 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
172 it '1件のときオフセット1なら0になる' do
173 Story.offset(1, '1').should eq 0
175 it '5件のときオフセット5なら4になる' do
176 Story.offset(5, '5').should eq 4
178 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
179 #-4のときは、最後から4つのコマを表示する。
180 it '2件のときオフセット-1なら1になる' do
181 Story.offset(2, '-1').should eq 1
183 it '5件のときオフセット-2なら3になる' do
184 Story.offset(5, '-2').should eq 3
186 # 最終的なが負になるなど、不正な値が入ったときは0となる。
187 it '2件のときオフセット-5なら0になる' do
188 Story.offset(2, '-5').should eq 0
191 context 'panel_count補正について' do
192 it '文字列から数値に変換される' do
193 Story.panel_count(100, '7').should eq 7
195 it 'nilの場合はStory.default_panel_sizeになる' do
196 Story.panel_count(100).should eq Story.default_panel_size
198 it '0以下の場合はStory.default_panel_sizeになる' do
199 Story.panel_count(100, '0').should eq Story.default_panel_size
201 it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
202 Story.panel_count(100, '1000').should eq Story.max_panel_size
206 c = Story.play_list @comic, @author
210 #公開コミックの公開コマは(他人のコミックであっても)含んでいる
211 v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
212 c = Story.play_list @comic, @author
213 c.should eq [ @story, v]
216 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
217 c = Story.play_list @comic, @author
218 c.should eq [ @story, h]
220 context 'DBに5件あって1ページの件数を2件に変えたとして' do
222 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
223 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
224 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
225 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
227 it 'offset=0なら末尾2件を返す' do
229 c = Story.play_list( @comic, @author, 0, 2)
230 c.should eq [@story, @story2]
232 it 'offset=2なら中間2件を返す' do
233 c = Story.play_list(@comic, @author, 2, 2)
234 c.should eq [@story3, @story4]
236 it 'offset=4なら先頭1件を返す' do
237 c = Story.play_list(@comic, @author, 4, 2)
238 c.should eq [@story5]
242 describe 'list関連テーブルプションに於いて' do
243 it 'includeキーを含んでいる' do
245 r.has_key?(:include).should be_true
248 r = Story.list_opt[:include]
249 r.should have(3).items
252 r = Story.list_opt[:include]
253 r.has_key?(:comic).should be_true
255 it 'コミックは作家を含んでいる' do
256 r = Story.list_opt[:include]
257 r[:comic].has_key?(:author).should be_true
260 r = Story.list_opt[:include]
261 r.has_key?(:author).should be_true
264 r = Story.list_opt[:include]
265 r.has_key?(:panel).should be_true
268 r = Story.list_opt[:include]
269 r[:panel].has_key?(:author).should be_true
272 r = Story.list_opt[:include]
273 r[:panel].has_key?(:panel_pictures).should be_true
275 it 'コマ絵は実素材を含んでいる' do
276 r = Story.list_opt[:include]
277 r[:panel][:panel_pictures].has_key?(:picture).should be_true
280 r = Story.list_opt[:include]
281 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
283 it '実素材はライセンスを含んでいる' do
284 r = Story.list_opt[:include]
285 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
287 it 'コマはフキダシを含んでいる' do
288 r = Story.list_opt[:include]
289 r[:panel].has_key?(:speech_balloons).should be_true
291 it 'フキダシはフキダシ枠を含んでいる' do
292 r = Story.list_opt[:include]
293 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
295 it 'フキダシはセリフを含んでいる' do
296 r = Story.list_opt[:include]
297 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
300 describe 'json一覧出力オプションに於いて' do
303 describe '自分のストーリー一覧取得に於いて' do
305 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
306 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
307 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
308 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
309 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
310 @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
311 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
313 context 'つつがなく終わるとき' do
\r
314 it '一覧取得オプションを利用している' do
\r
315 Story.stub(:list_opt).with(any_args).and_return({})
\r
316 Story.should_receive(:list_opt).with(any_args).exactly(1)
\r
317 r = Story.mylist @author
321 s = Story.mylist @author
325 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
326 sl = Story.mylist @author
327 sl.should eq [ns, @story]
329 it '他人のストーリーはコマコミックともに公開でも含まない' do
330 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
331 sl = Story.mylist @author
332 sl.should eq [@story]
334 it '自分のストーリーはコマコミックともに非公開でも含んでいる' do
335 hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
336 sl = Story.mylist @author
337 sl.should eq [hs, @story]
339 context 'DBに5件あって1ページの件数を2件に変えたとして' do
341 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
342 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
343 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
344 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
347 c = Story.mylist @author, 1, 2
348 c.should have(2).items
350 it 'page=1なら末尾2件を返す' do
352 c = Story.mylist(@author, 1, 2)
353 c.should eq [@story5, @story4]
355 it 'page=2なら中間2件を返す' do
356 c = Story.mylist(@author, 2, 2)
357 c.should eq [@story3, @story2]
359 it 'page=3なら先頭1件を返す' do
360 c = Story.mylist(@author, 3, 2)
364 context 'DBに5件あって1ページの件数を0件に変えたとして' do
366 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
367 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
368 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
369 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
370 Author.stub(:default_story_size).and_return(2)
\r
373 r = Story.mylist @author, 5, 0
374 r.should have(5).items
379 describe '編集取得に於いて' do
381 @comic = FactoryGirl.create :comic, :author_id => @author.id
382 @panel = FactoryGirl.create :panel, :author_id => @author.id
383 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
385 context 'つつがなく終わるとき' do
\r
386 it '単体取得オプションを利用している' do
\r
387 Story.stub(:show_opt).with(any_args).and_return({})
\r
388 Story.should_receive(:show_opt).with(any_args).exactly(1)
\r
389 r = Story.edit @story.id, @author
391 it '所持判定を問い合わせている' do
\r
392 Story.any_instance.stub(:own?).with(any_args).and_return(true)
\r
393 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
394 r = Story.edit @story.id, @author
398 l = Story.edit @story.id, @author
401 context '他人のストーリーを開こうとしたとき' do
402 it '403Forbidden例外を返す' do
403 Story.any_instance.stub(:own?).and_return(false)
405 Story.edit @story.id, @author
406 }.should raise_error(ActiveRecord::Forbidden)
409 context '存在しないストーリーを開こうとしたとき' do
410 it '404RecordNotFound例外を返す' do
412 Story.edit 110, @author
413 }.should raise_error(ActiveRecord::RecordNotFound)
418 describe '単体取得オプションに於いて' do
419 it 'includeキーを含んでいる' do
421 r.has_key?(:include).should be_true
424 r = Story.show_opt[:include]
425 r.should have(3).items
428 r = Story.show_opt[:include]
429 r.has_key?(:comic).should be_true
431 it 'コミックは作家を含んでいる' do
432 r = Story.show_opt[:include]
433 r[:comic].has_key?(:author).should be_true
436 r = Story.show_opt[:include]
437 r.has_key?(:author).should be_true
440 r = Story.show_opt[:include]
441 r.has_key?(:panel).should be_true
444 r = Story.show_opt[:include]
445 r[:panel].has_key?(:author).should be_true
448 r = Story.show_opt[:include]
449 r[:panel].has_key?(:panel_pictures).should be_true
451 it 'コマ絵は実素材を含んでいる' do
452 r = Story.show_opt[:include]
453 r[:panel][:panel_pictures].has_key?(:picture).should be_true
456 r = Story.show_opt[:include]
457 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
459 it '実素材はライセンスを含んでいる' do
460 r = Story.show_opt[:include]
461 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
463 it 'コマはフキダシを含んでいる' do
464 r = Story.show_opt[:include]
465 r[:panel].has_key?(:speech_balloons).should be_true
467 it 'フキダシはフキダシ枠を含んでいる' do
468 r = Story.show_opt[:include]
469 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
471 it 'フキダシはセリフを含んでいる' do
472 r = Story.show_opt[:include]
473 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
476 describe 'json単体取得オプションに於いて' do
479 describe 'ストーリーのjson出力に於いて' do
482 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
483 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
484 @sb = @panel.speech_balloons.create(
\r
485 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
487 @gc = @panel.ground_colors.create(
\r
488 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
490 @gp = @panel.ground_pictures.create(
\r
491 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
493 @pc = @panel.panel_colors.create(
\r
494 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
497 @comic = FactoryGirl.create :comic, :author_id => @author.id
498 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
500 context '事前チェックする' do
502 Panel.any_instance.stub(:elements).and_return('{}')
504 it 'コマ要素のjson出力を依頼している' do
\r
505 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
506 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
\r
507 r = @story.story_as_json @author
510 it 'json textを返している' do
\r
511 r = JSON.parse @story.story_as_json(@author)
\r
512 r.is_a?(Hash).should be_true
\r
514 it 'comic,author,panel,コマ要素を含んでいる' do
\r
515 r = JSON.parse @story.story_as_json(@author)
\r
516 r.has_key?('comic').should be_true
\r
517 r['comic'].has_key?('author').should be_true
\r
518 r.has_key?('author').should be_true
\r
519 r.has_key?('panel').should be_true
\r
520 r['panel'].has_key?('author').should be_true
\r
522 context 'コマ閲覧許可のとき' do
524 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
526 it 'コマ要素にコマ要素を追加している' do
\r
527 r = JSON.parse @story.story_as_json(@author)
\r
528 r['panel'].has_key?('elements').should be_true
\r
529 r['panel']['elements'].should_not be_empty
\r
532 context 'コマ閲覧不許可のとき' do
534 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
536 it 'コマ要素にデータを含ませない' do
\r
537 r = JSON.parse @story.story_as_json(@author)
\r
538 r['panel'].has_key?('elements').should be_false
\r
543 describe 'ストーリーリストのjson出力に於いて' do
\r
545 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
546 @comic = FactoryGirl.create :comic, :author_id => @author.id
547 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
548 Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
\r
550 context 'つつがなく終わるとき' do
\r
551 it 'ストーリーのjson出力を依頼している' do
\r
552 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
\r
553 r = Story.list_as_json_text [@story], @author
\r
556 it 'json textを返している' do
\r
557 r = Story.list_as_json_text [@story], @author
\r
559 j.is_a?(Array).should be_true
\r
561 it 'ストーリーを含んでいる' do
\r
562 r = Story.list_as_json_text [@story], @author
\r
564 j.first.has_key?('s').should be_true
\r
568 describe 't補充値に於いて' do
570 @comic = FactoryGirl.create :comic, :author_id => @author.id
571 @panel = FactoryGirl.create :panel, :author_id => @author.id
574 context 'コミック初のコマなら' do
576 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
578 r = Story.new_t @story.comic_id
582 context 'コミックに一個コマがあるとき' do
584 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
585 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
587 r = Story.new_t @story.comic_id
591 context 'コミックに2個コマがあるとき' do
593 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
594 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
595 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
597 r = Story.new_t @story.comic_id
602 describe 'シリアライズチェックに於いて' do
603 context 'つつがなく終わるとき' do
604 it '0からシリアライズされているならTrueを返す' do
605 r = Story.serial? [0, 1, 2]
608 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
609 r = Story.serial? [0, 2, 1]
612 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
613 r = Story.serial? [ 2, 1, 4, 3, 0]
618 it '0から始まらないならFalseを返す' do
619 r = Story.serial? [1, 2, 3]
622 it '連続していないならFalseを返す' do
623 r = Story.serial? [0, 1, 2, 4]
626 it '連続していないならFalseを返す' do
627 r = Story.serial? [0, 1, 2, 4, 5]
632 describe 't収集に於いて' do
634 @comic = FactoryGirl.create :comic, :author_id => @author.id
635 @panel = FactoryGirl.create :panel, :author_id => @author.id
636 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
637 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
638 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
640 context 'つつがなく終わるとき' do
641 it 'ストーリーから同一コミックのtだけを収集している' do
642 r = Story.collect_t @story
647 it 'ストーリーから同一コミックのtだけを収集している' do
648 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
649 r = Story.collect_t @story
650 r.sort.should eq [0, 1]
653 context '複数コマでヨソのコミックも混じっているとき' do
654 it 'ストーリーから同一コミックのtだけを収集している' do
655 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
656 r = Story.collect_t @story
657 r.sort.should eq [0, 1]
661 describe 'tチェックに於いて' do
663 @comic = FactoryGirl.create :comic, :author_id => @author.id
664 @panel = FactoryGirl.create :panel, :author_id => @author.id
665 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
667 context 'つつがなく終わるとき' do
669 Story.should_receive(:collect_t).with(any_args).exactly(1)
670 Story.stub(:collect_t).with(any_args).and_return([])
671 Story.stub(:serial?).with(any_args).and_return(true)
672 r = Story.validate_t @story
674 it '収集したtをシリアライズチェック依頼している' do
675 Story.stub(:collect_t).with(any_args).and_return([])
676 Story.should_receive(:serial?).with(any_args).exactly(1)
677 Story.stub(:serial?).with(any_args).and_return(true)
678 r = Story.validate_t @story
682 #依頼チェックだけでは不安なので最低限のチェックを
684 it '一件だけで正常通過している' do
685 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
686 r = Story.validate_t @story
691 it '2件目を作っても正常通過している' do
692 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
693 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
694 r = Story.validate_t @story2
699 describe '挿入シフトに於いて' do
701 @comic = FactoryGirl.create :comic, :author_id => @author.id
702 @panel = FactoryGirl.create :panel, :author_id => @author.id
706 it 'Updateを依頼している' do
707 Story.stub(:update_all).with(any_args)
708 Story.should_receive(:update_all).with(any_args).exactly(1)
709 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
713 context 'テーブルに1件(t:0)で0に挿入したとき' do
715 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
716 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
718 it '既存の行を1にシフトしている' do
721 l.first.t.should eq 1
723 it 'これから挿入するt(0)が欠番になっている' do
725 l = Story.find(:all).map {|s| s.t }
726 l.include?(0).should_not be_true
729 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
731 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
732 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
733 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
735 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
737 l = Story.find(:all).map {|s| s.t }
738 l.sort.should eq [0, 2]
741 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
743 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
744 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
745 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
746 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
747 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
748 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
750 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
752 l = Story.find(:all).map {|s| s.t }
753 l.sort.should eq [0, 1, 3, 4, 5]
756 context '先ほどのケース+他のコミック1件で挿入したとき' do
758 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
759 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
760 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
761 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
762 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
763 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
764 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
765 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
767 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
769 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
770 l.sort.should eq [0, 1, 3, 4, 5]
776 @storyc2.t.should eq ot
780 describe '少ない方に移動に於いて' do
782 @comic = FactoryGirl.create :comic, :author_id => @author.id
783 @panel = FactoryGirl.create :panel, :author_id => @author.id
786 it 'Updateを依頼している' do
787 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
788 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
789 Story.stub(:update_all).with(any_args)
790 Story.should_receive(:update_all).with(any_args).exactly(1)
793 @story2.lesser_shift ot
796 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
798 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
799 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
803 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
805 @story2.lesser_shift @ot
806 l = Story.find(:all).map {|s| s.t }
807 l.sort.should eq [1, 1]
809 it '既存のt0を1にシフトしている' do
810 @story2.lesser_shift @ot
815 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
817 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
818 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
819 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
823 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
825 @story3.lesser_shift @ot
826 l = Story.find(:all).map {|s| s.t }
827 l.sort.should eq [0, 2, 2]
829 it '既存のt1を2にシフトしている' do
830 @story3.lesser_shift @ot
832 @story2.t.should eq 2
835 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
837 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
838 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
839 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
840 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
841 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
845 it 'これから挿入するt(1)が欠番になっている' do
847 @story4.lesser_shift @ot
848 l = Story.find(:all).map {|s| s.t }
849 l.sort.should eq [0, 2, 3, 3, 4]
852 @story4.lesser_shift @ot
857 @story4.lesser_shift @ot
859 @story5.t.should eq 4
861 it '既存のt1を2にシフトしている' do
862 @story4.lesser_shift @ot
864 @story2.t.should eq 2
866 it '既存のt2を3にシフトしている' do
867 @story4.lesser_shift @ot
869 @story3.t.should eq 3
872 context '先ほどのケース+他のコミック1件で挿入したとき' do
874 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
875 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
876 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
877 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
878 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
879 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
880 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
884 it 'これから挿入するt(1)が欠番になっている' do
885 @story4.lesser_shift @ot
886 l = Story.find(:all).map {|s| s.t }
887 l.sort.should eq [0, 0, 2, 3, 3, 4]
890 @story4.lesser_shift @ot
895 @story4.lesser_shift @ot
897 @story5.t.should eq 4
899 it '既存のt1を2にシフトしている' do
900 @story4.lesser_shift @ot
902 @story2.t.should eq 2
904 it '既存のt2を3にシフトしている' do
905 @story4.lesser_shift @ot
907 @story3.t.should eq 3
910 @story4.lesser_shift @ot
912 @storyc2.t.should eq 0
917 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
919 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
920 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
924 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
926 @story2.lesser_shift @ot
927 l = Story.find(:all).map {|s| s.t }
928 l.sort.should eq [1, 1]
930 it '既存のt0を1にシフトしている' do
931 @story2.lesser_shift @ot
935 it '既存のt1は0に補正されている' do
936 @story2.lesser_shift @ot
937 @story2.t.should eq 0
941 describe '大きい方に移動に於いて' do
943 @comic = FactoryGirl.create :comic, :author_id => @author.id
944 @panel = FactoryGirl.create :panel, :author_id => @author.id
947 it 'Updateを依頼している' do
948 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
949 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
950 Story.stub(:update_all).with(any_args)
951 Story.should_receive(:update_all).with(any_args).exactly(1)
954 @story.higher_shift ot
957 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
959 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
960 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
964 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
966 @story.higher_shift @ot
967 l = Story.find(:all).map {|s| s.t }
968 l.sort.should eq [0, 0]
970 it '既存のt1を0にシフトしている' do
971 @story.higher_shift @ot
973 @story2.t.should eq 0
976 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
978 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
979 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
980 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
984 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
986 @story.higher_shift @ot
987 l = Story.find(:all).map {|s| s.t }
988 l.sort.should eq [0, 0, 2]
990 it '既存のt1を0にシフトしている' do
991 @story.higher_shift @ot
993 @story2.t.should eq 0
996 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
998 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
999 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1000 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1001 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1002 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1006 it 'これから挿入するt(3)が欠番になっている' do
1008 @story2.higher_shift @ot
1009 l = Story.find(:all).map {|s| s.t }
1010 l.sort.should eq [0, 1, 1, 2, 4]
1012 it '既存のt0には変化がない' do
1013 @story2.higher_shift @ot
1015 @story.t.should eq 0
1017 it '既存のt4には変化がない' do
1018 @story2.higher_shift @ot
1020 @story5.t.should eq 4
1022 it '既存のt2を1にシフトしている' do
1023 @story2.higher_shift @ot
1025 @story3.t.should eq 1
1027 it '既存のt3を2にシフトしている' do
1028 @story2.higher_shift @ot
1030 @story4.t.should eq 2
1033 context '先ほどのケース+他のコミック1件で挿入したとき' do
1035 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1036 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1037 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1038 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1039 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1040 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1041 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1045 it 'これから挿入するt(3)が欠番になっている' do
1047 @story2.higher_shift @ot
1048 l = Story.find(:all).map {|s| s.t }
1049 l.sort.should eq [0, 0, 1, 1, 2, 4]
1051 it '既存のt0には変化がない' do
1052 @story2.higher_shift @ot
1054 @story.t.should eq 0
1056 it '既存のt4には変化がない' do
1057 @story2.higher_shift @ot
1059 @story5.t.should eq 4
1061 it '既存のt2を1にシフトしている' do
1062 @story2.higher_shift @ot
1064 @story3.t.should eq 1
1066 it '既存のt3を2にシフトしている' do
1067 @story2.higher_shift @ot
1069 @story4.t.should eq 2
1071 it '他のコミックに影響がない' do
1072 @story2.higher_shift @ot
1074 @storyc2.t.should eq 0
1078 #max超えたときはmaxとして正常扱い
1079 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1081 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1082 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1086 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1088 @story.higher_shift @ot
1089 l = Story.find(:all).map {|s| s.t }
1090 l.sort.should eq [0, 0]
1092 it '既存のt1を0にシフトしている' do
1093 @story.higher_shift @ot
1095 @story2.t.should eq 0
1097 it '既存のt0は1に補正されている' do
1098 @story.higher_shift @ot
1099 @story.t.should eq 1
1103 describe '入れ替えに於いて' do
1105 @comic = FactoryGirl.create :comic, :author_id => @author.id
1106 @panel = FactoryGirl.create :panel, :author_id => @author.id
1107 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1108 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1110 context '新tが旧tより小さいとき' do
1111 it '少ない方に移動を依頼している' do
1112 Story.any_instance.stub(:lesser_shift).with(any_args)
1113 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1116 @story2.update_shift ot
1119 context '新tが旧tより大きいとき' do
1120 it '大きい方に移動を依頼している' do
1121 Story.any_instance.stub(:higher_shift).with(any_args)
1122 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1125 @story.update_shift ot
1129 describe '順序入れ替えに於いて' do
1131 @comic = FactoryGirl.create :comic, :author_id => @author.id
1132 @panel = FactoryGirl.create :panel, :author_id => @author.id
1134 context 'オブジェクトが新規でtが空のとき' do
1135 it '末尾追加としてtを補充依頼している' do
1136 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1137 Story.stub(:new_t).with(any_args).and_return(0)
1138 Story.should_receive(:new_t).with(any_args).exactly(1)
1143 context 'オブジェクトが新規でtが設定されているとき' do
1144 it '挿入追加として挿入シフトを依頼している' do
1145 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1146 Story.any_instance.stub(:insert_shift).with(any_args)
1147 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1152 context 'オブジェクトが新規でなくtが設定されているとき' do
1153 it 'コマ移動として入れ替えを依頼している' do
1154 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1155 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1156 Story.any_instance.stub(:update_shift).with(any_args)
1157 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1162 context 'オブジェクトが新規でなくtが空のとき' do
1163 it '入れ替えもシフトもせず、tを空のままにしている' do
1164 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1168 describe '編集許可に於いて' do
1170 @comic = FactoryGirl.create :comic, :author_id => @author.id
1171 @panel = FactoryGirl.create :panel, :author_id => @author.id
1172 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1174 context 'つつがなく終わるとき' do
1180 context 'コミックで引っかかるとき' do
1182 @story.comic_id = nil
1187 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1192 context 'コマで引っかかるとき' do
1194 @story.panel_id = nil
1199 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1205 describe '保存に於いて' do
1207 @comic = FactoryGirl.create :comic, :author_id => @author.id
1208 @panel = FactoryGirl.create :panel, :author_id => @author.id
1209 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1211 context 'つつがなく終わるとき' do
1212 it '編集許可チェックを依頼している' do
1213 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1214 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1217 it '順序入れ替えを依頼している' do
1218 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1219 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1220 Story.any_instance.stub(:save).with(any_args).and_return(true)
1221 Story.stub(:validate_t).with(any_args).and_return(true)
1225 Story.stub(:new_t).with(any_args).and_return(0)
1226 Story.any_instance.stub(:save).with(any_args).and_return(true)
1227 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1228 Story.stub(:validate_t).with(any_args).and_return(true)
1231 it 'tのシリアライズチェックを依頼している' do
1232 Story.stub(:new_t).with(any_args).and_return(0)
1233 Story.any_instance.stub(:save).with(any_args).and_return(true)
1234 Story.stub(:validate_t).with(any_args).and_return(true)
1235 Story.should_receive(:validate_t).with(any_args).exactly(1)
1239 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1240 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1242 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1243 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1244 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1245 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1246 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1247 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1248 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1249 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1251 it '既存のt0には変化がない' do
1254 @story.t.should eq 0
1256 it '既存のt1には変化がない' do
1259 @story2.t.should eq 1
1261 it '既存のt2を3にシフトしている' do
1264 @story3.t.should eq 3
1266 it '既存のt3を4にシフトしている' do
1269 @story4.t.should eq 4
1271 it '既存のt5を5にシフトしている' do
1274 @story5.t.should eq 5
1276 it '新規のt2が作成されている' do
1279 @story6.t.should eq 2
1281 it '他のコミックに影響がない' do
1285 @storyc2.t.should eq @ot
1288 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1290 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1291 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1292 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1293 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1294 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1295 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1296 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1300 it '既存のt0には変化がない' do
1303 @story.t.should eq 0
1305 it '既存のt4には変化がない' do
1308 @story5.t.should eq 4
1310 it '既存のt1を2にシフトしている' do
1313 @story2.t.should eq 2
1315 it '既存のt2を3にシフトしている' do
1318 @story3.t.should eq 3
1320 it '既存のt3を1にシフトしている' do
1323 @story4.t.should eq 1
1325 it '他のコミックに影響がない' do
1328 @storyc2.t.should eq 0
1331 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1333 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1334 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1335 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1336 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1337 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1338 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1339 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1343 it '既存のt0には変化がない' do
1346 @story.t.should eq 0
1348 it '既存のt4には変化がない' do
1351 @story5.t.should eq 4
1353 it '既存のt1を3にシフトしている' do
1356 @story2.t.should eq 3
1358 it '既存のt2を1にシフトしている' do
1361 @story3.t.should eq 1
1363 it '既存のt3を2にシフトしている' do
1366 @story4.t.should eq 2
1368 it '他のコミックに影響がない' do
1371 @storyc2.t.should eq 0
1374 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1375 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1377 Story.any_instance.stub(:save).with(any_args).and_return(false)
1378 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1379 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1380 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1381 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1382 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1383 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1384 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1385 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1390 @story.t.should eq 0
1392 @story2.t.should eq 1
1394 @story3.t.should eq 2
1396 @story4.t.should eq 3
1398 @story5.t.should eq 4
1400 @storyc2.t.should eq 0
1407 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1409 Story.stub(:validate_t).with(any_args).and_return(false)
1410 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1411 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1412 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1413 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1414 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1415 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1416 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1423 @story.t.should eq 0
1425 @story2.t.should eq 1
1427 @story3.t.should eq 2
1429 @story4.t.should eq 3
1431 @story5.t.should eq 4
1433 @storyc2.t.should eq 0
1436 r = @story4.store @ot
1439 it 'tにエラーメッセージが入っている' do
1441 @story4.errors[:t].should_not be_empty
1442 @story4.valid?.should be_true
1445 context '編集不可だったとき' do
1447 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1448 Story.any_instance.stub(:allow?).and_return(false)
1450 it '403Forbidden例外を返す' do
1453 }.should raise_error(ActiveRecord::Forbidden)
1457 describe '切り詰め処理つき削除に於いて' do
1459 @comic = FactoryGirl.create :comic, :author_id => @author.id
1460 @panel = FactoryGirl.create :panel, :author_id => @author.id
1461 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1463 context 'つつがなく終わるとき' do
1466 @story.destroy_and_shorten
1467 }.should change(Story, :count ).by(-1)
1470 #連携テスト。切り詰めが直接DBをいじる
1471 context '2件で先頭を削除したとき' do
1473 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1477 @story.destroy_and_shorten
1478 }.should change(Story, :count ).by(-1)
1481 @story.destroy_and_shorten
1483 Story.find @story.id
1484 }.should raise_error(ActiveRecord::RecordNotFound)
1487 @story.destroy_and_shorten
1489 @story2.t.should eq 0
1492 context '3件で先頭を削除したとき' do
1494 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1495 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1499 @story.destroy_and_shorten
1500 }.should change(Story, :count ).by(-1)
1503 @story.destroy_and_shorten
1505 Story.find @story.id
1506 }.should raise_error(ActiveRecord::RecordNotFound)
1509 @story.destroy_and_shorten
1511 @story2.t.should eq 0
1514 @story.destroy_and_shorten
1516 @story3.t.should eq 1
1519 context '5件で3件目を削除したとき' do
1521 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1522 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1523 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1524 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1528 @story3.destroy_and_shorten
1529 }.should change(Story, :count ).by(-1)
1532 @story3.destroy_and_shorten
1534 @story.t.should eq 0
1537 @story3.destroy_and_shorten
1539 @story2.t.should eq 1
1542 @story3.destroy_and_shorten
1544 Story.find @story3.id
1545 }.should raise_error(ActiveRecord::RecordNotFound)
1548 @story3.destroy_and_shorten
1550 @story4.t.should eq 2
1553 @story3.destroy_and_shorten
1555 @story5.t.should eq 3
1558 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する