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
151 describe '一覧取得に於いて' do
153 @comic = FactoryGirl.create :comic, :author_id => @author.id
154 @panel = FactoryGirl.create :panel, :author_id => @author.id
155 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
156 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
157 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
158 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
160 context 'offset補正について' do
161 it '文字列から数値に変換される' do
162 Story.offset(100, '8').should eq 8
165 Story.offset(100).should eq 0
167 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
169 it '1件のときオフセット1なら0になる' do
170 Story.offset(1, '1').should eq 0
172 it '5件のときオフセット5なら4になる' do
173 Story.offset(5, '5').should eq 4
175 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
176 #-4のときは、最後から4つのコマを表示する。
177 it '2件のときオフセット-1なら1になる' do
178 Story.offset(2, '-1').should eq 1
180 it '5件のときオフセット-2なら3になる' do
181 Story.offset(5, '-2').should eq 3
183 # 最終的なが負になるなど、不正な値が入ったときは0となる。
184 it '2件のときオフセット-5なら0になる' do
185 Story.offset(2, '-5').should eq 0
188 context 'panel_count補正について' do
189 it '文字列から数値に変換される' do
190 Story.panel_count(100, '7').should eq 7
192 it 'nilの場合はStory.default_panel_sizeになる' do
193 Story.panel_count(100).should eq Story.default_panel_size
195 it '0以下の場合はStory.default_panel_sizeになる' do
196 Story.panel_count(100, '0').should eq Story.default_panel_size
198 it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
199 Story.panel_count(100, '1000').should eq Story.max_panel_size
203 c = Story.play_list @comic, @author
207 #公開コミックの公開コマは(他人のコミックであっても)含んでいる
208 v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
209 c = Story.play_list @comic, @author
210 c.should eq [ @story, v]
213 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
214 c = Story.play_list @comic, @author
215 c.should eq [ @story, h]
217 context 'DBに5件あって1ページの件数を2件に変えたとして' do
219 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
220 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
221 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
222 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
224 it 'offset=0なら末尾2件を返す' do
226 c = Story.play_list( @comic, @author, 0, 2)
227 c.should eq [@story, @story2]
229 it 'offset=2なら中間2件を返す' do
230 c = Story.play_list(@comic, @author, 2, 2)
231 c.should eq [@story3, @story4]
233 it 'offset=4なら先頭1件を返す' do
234 c = Story.play_list(@comic, @author, 4, 2)
235 c.should eq [@story5]
239 describe 'list関連テーブルプションに於いて' do
240 it 'includeキーを含んでいる' do
242 r.has_key?(:include).should be_true
245 r = Story.list_opt[:include]
246 r.should have(3).items
249 r = Story.list_opt[:include]
250 r.has_key?(:comic).should be_true
252 it 'コミックは作家を含んでいる' do
253 r = Story.list_opt[:include]
254 r[:comic].has_key?(:author).should be_true
257 r = Story.list_opt[:include]
258 r.has_key?(:author).should be_true
261 r = Story.list_opt[:include]
262 r.has_key?(:panel).should be_true
265 r = Story.list_opt[:include]
266 r[:panel].has_key?(:author).should be_true
269 r = Story.list_opt[:include]
270 r[:panel].has_key?(:panel_pictures).should be_true
272 it 'コマ絵は実素材を含んでいる' do
273 r = Story.list_opt[:include]
274 r[:panel][:panel_pictures].has_key?(:picture).should be_true
277 r = Story.list_opt[:include]
278 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
280 it '実素材はライセンスを含んでいる' do
281 r = Story.list_opt[:include]
282 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
284 it 'コマはフキダシを含んでいる' do
285 r = Story.list_opt[:include]
286 r[:panel].has_key?(:speech_balloons).should be_true
288 it 'フキダシはフキダシ枠を含んでいる' do
289 r = Story.list_opt[:include]
290 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
292 it 'フキダシはセリフを含んでいる' do
293 r = Story.list_opt[:include]
294 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
297 describe 'json一覧出力オプションに於いて' do
300 describe '自分のストーリー一覧取得に於いて' do
302 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
303 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
304 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
305 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
306 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
307 @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
308 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
310 context 'つつがなく終わるとき' do
\r
311 it '一覧取得オプションを利用している' do
\r
312 Story.stub(:list_opt).with(any_args).and_return({})
\r
313 Story.should_receive(:list_opt).with(any_args).exactly(1)
\r
314 r = Story.mylist @author
318 s = Story.mylist @author
322 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
323 sl = Story.mylist @author
324 sl.should eq [ns, @story]
326 it '他人のストーリーはコマコミックともに公開でも含まない' do
327 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
328 sl = Story.mylist @author
329 sl.should eq [@story]
331 it '自分のストーリーはコマコミックともに非公開でも含んでいる' do
332 hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
333 sl = Story.mylist @author
334 sl.should eq [hs, @story]
336 context 'DBに5件あって1ページの件数を2件に変えたとして' do
338 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
339 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
340 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
341 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
344 c = Story.mylist @author, 1, 2
345 c.should have(2).items
347 it 'page=1なら末尾2件を返す' do
349 c = Story.mylist(@author, 1, 2)
350 c.should eq [@story5, @story4]
352 it 'page=2なら中間2件を返す' do
353 c = Story.mylist(@author, 2, 2)
354 c.should eq [@story3, @story2]
356 it 'page=3なら先頭1件を返す' do
357 c = Story.mylist(@author, 3, 2)
361 context 'DBに5件あって1ページの件数を0件に変えたとして' do
363 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
364 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
365 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
366 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
367 Author.stub(:default_story_size).and_return(2)
\r
370 r = Story.mylist @author, 5, 0
371 r.should have(5).items
376 describe '編集取得に於いて' do
378 @comic = FactoryGirl.create :comic, :author_id => @author.id
379 @panel = FactoryGirl.create :panel, :author_id => @author.id
380 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
382 context 'つつがなく終わるとき' do
\r
383 it '単体取得オプションを利用している' do
\r
384 Story.stub(:show_opt).with(any_args).and_return({})
\r
385 Story.should_receive(:show_opt).with(any_args).exactly(1)
\r
386 r = Story.edit @story.id, @author
388 it '所持判定を問い合わせている' do
\r
389 Story.any_instance.stub(:own?).with(any_args).and_return(true)
\r
390 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
391 r = Story.edit @story.id, @author
395 l = Story.edit @story.id, @author
398 context '他人のストーリーを開こうとしたとき' do
399 it '403Forbidden例外を返す' do
400 Story.any_instance.stub(:own?).and_return(false)
402 Story.edit @story.id, @author
403 }.should raise_error(ActiveRecord::Forbidden)
406 context '存在しないストーリーを開こうとしたとき' do
407 it '404RecordNotFound例外を返す' do
409 Story.edit 110, @author
410 }.should raise_error(ActiveRecord::RecordNotFound)
415 describe '単体取得オプションに於いて' do
416 it 'includeキーを含んでいる' do
418 r.has_key?(:include).should be_true
421 r = Story.show_opt[:include]
422 r.should have(3).items
425 r = Story.show_opt[:include]
426 r.has_key?(:comic).should be_true
428 it 'コミックは作家を含んでいる' do
429 r = Story.show_opt[:include]
430 r[:comic].has_key?(:author).should be_true
433 r = Story.show_opt[:include]
434 r.has_key?(:author).should be_true
437 r = Story.show_opt[:include]
438 r.has_key?(:panel).should be_true
441 r = Story.show_opt[:include]
442 r[:panel].has_key?(:author).should be_true
445 r = Story.show_opt[:include]
446 r[:panel].has_key?(:panel_pictures).should be_true
448 it 'コマ絵は実素材を含んでいる' do
449 r = Story.show_opt[:include]
450 r[:panel][:panel_pictures].has_key?(:picture).should be_true
453 r = Story.show_opt[:include]
454 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
456 it '実素材はライセンスを含んでいる' do
457 r = Story.show_opt[:include]
458 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
460 it 'コマはフキダシを含んでいる' do
461 r = Story.show_opt[:include]
462 r[:panel].has_key?(:speech_balloons).should be_true
464 it 'フキダシはフキダシ枠を含んでいる' do
465 r = Story.show_opt[:include]
466 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
468 it 'フキダシはセリフを含んでいる' do
469 r = Story.show_opt[:include]
470 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
473 describe 'json単体取得オプションに於いて' do
476 describe 'ストーリーのjson出力に於いて' do
479 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
480 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
481 @sb = @panel.speech_balloons.create(
\r
482 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
484 @gc = @panel.ground_colors.create(
\r
485 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
487 @gp = @panel.ground_pictures.create(
\r
488 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
490 @pc = @panel.panel_colors.create(
\r
491 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
494 @comic = FactoryGirl.create :comic, :author_id => @author.id
495 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
497 context '事前チェックする' do
499 Panel.any_instance.stub(:elements).and_return('{}')
501 it 'コマ要素のjson出力を依頼している' do
\r
502 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
503 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
\r
504 r = @story.story_as_json @author
507 it 'json textを返している' do
\r
508 r = JSON.parse @story.story_as_json(@author)
\r
509 r.is_a?(Hash).should be_true
\r
511 it 'comic,author,panel,コマ要素を含んでいる' do
\r
512 r = JSON.parse @story.story_as_json(@author)
\r
513 r.has_key?('comic').should be_true
\r
514 r['comic'].has_key?('author').should be_true
\r
515 r.has_key?('author').should be_true
\r
516 r.has_key?('panel').should be_true
\r
517 r['panel'].has_key?('author').should be_true
\r
519 context 'コマ閲覧許可のとき' do
521 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
523 it 'コマ要素にコマ要素を追加している' do
\r
524 r = JSON.parse @story.story_as_json(@author)
\r
525 r['panel'].has_key?('elements').should be_true
\r
526 r['panel']['elements'].should_not be_empty
\r
529 context 'コマ閲覧不許可のとき' do
531 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
533 it 'コマ要素にデータを含ませない' do
\r
534 r = JSON.parse @story.story_as_json(@author)
\r
535 r['panel'].has_key?('elements').should be_false
\r
540 describe 'ストーリーリストのjson出力に於いて' do
\r
542 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
543 @comic = FactoryGirl.create :comic, :author_id => @author.id
544 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
545 Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
\r
547 context 'つつがなく終わるとき' do
\r
548 it 'ストーリーのjson出力を依頼している' do
\r
549 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
\r
550 r = Story.list_as_json_text [@story], @author
\r
553 it 'json textを返している' do
\r
554 r = Story.list_as_json_text [@story], @author
\r
556 j.is_a?(Array).should be_true
\r
558 it 'ストーリーを含んでいる' do
\r
559 r = Story.list_as_json_text [@story], @author
\r
561 j.first.has_key?('s').should be_true
\r
565 describe 't補充値に於いて' do
567 @comic = FactoryGirl.create :comic, :author_id => @author.id
568 @panel = FactoryGirl.create :panel, :author_id => @author.id
571 context 'コミック初のコマなら' do
573 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
575 r = Story.new_t @story.comic_id
579 context 'コミックに一個コマがあるとき' do
581 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
582 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
584 r = Story.new_t @story.comic_id
588 context 'コミックに2個コマがあるとき' do
590 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
591 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
592 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
594 r = Story.new_t @story.comic_id
599 describe 'シリアライズチェックに於いて' do
600 context 'つつがなく終わるとき' do
601 it '0からシリアライズされているならTrueを返す' do
602 r = Story.serial? [0, 1, 2]
605 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
606 r = Story.serial? [0, 2, 1]
609 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
610 r = Story.serial? [ 2, 1, 4, 3, 0]
615 it '0から始まらないならFalseを返す' do
616 r = Story.serial? [1, 2, 3]
619 it '連続していないならFalseを返す' do
620 r = Story.serial? [0, 1, 2, 4]
623 it '連続していないならFalseを返す' do
624 r = Story.serial? [0, 1, 2, 4, 5]
629 describe 't収集に於いて' do
631 @comic = FactoryGirl.create :comic, :author_id => @author.id
632 @panel = FactoryGirl.create :panel, :author_id => @author.id
633 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
634 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
635 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
637 context 'つつがなく終わるとき' do
638 it 'ストーリーから同一コミックのtだけを収集している' do
639 r = Story.collect_t @story
644 it 'ストーリーから同一コミックのtだけを収集している' do
645 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
646 r = Story.collect_t @story
647 r.sort.should eq [0, 1]
650 context '複数コマでヨソのコミックも混じっているとき' do
651 it 'ストーリーから同一コミックのtだけを収集している' do
652 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
653 r = Story.collect_t @story
654 r.sort.should eq [0, 1]
658 describe 'tチェックに於いて' do
660 @comic = FactoryGirl.create :comic, :author_id => @author.id
661 @panel = FactoryGirl.create :panel, :author_id => @author.id
662 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
664 context 'つつがなく終わるとき' do
666 Story.should_receive(:collect_t).with(any_args).exactly(1)
667 Story.stub(:collect_t).with(any_args).and_return([])
668 Story.stub(:serial?).with(any_args).and_return(true)
669 r = Story.validate_t @story
671 it '収集したtをシリアライズチェック依頼している' do
672 Story.stub(:collect_t).with(any_args).and_return([])
673 Story.should_receive(:serial?).with(any_args).exactly(1)
674 Story.stub(:serial?).with(any_args).and_return(true)
675 r = Story.validate_t @story
679 #依頼チェックだけでは不安なので最低限のチェックを
681 it '一件だけで正常通過している' do
682 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
683 r = Story.validate_t @story
688 it '2件目を作っても正常通過している' do
689 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
690 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
691 r = Story.validate_t @story2
696 describe '挿入シフトに於いて' do
698 @comic = FactoryGirl.create :comic, :author_id => @author.id
699 @panel = FactoryGirl.create :panel, :author_id => @author.id
703 it 'Updateを依頼している' do
704 Story.stub(:update_all).with(any_args)
705 Story.should_receive(:update_all).with(any_args).exactly(1)
706 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
710 context 'テーブルに1件(t:0)で0に挿入したとき' do
712 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
713 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
715 it '既存の行を1にシフトしている' do
718 l.first.t.should eq 1
720 it 'これから挿入するt(0)が欠番になっている' do
722 l = Story.find(:all).map {|s| s.t }
723 l.include?(0).should_not be_true
726 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
728 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
729 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
730 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
732 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
734 l = Story.find(:all).map {|s| s.t }
735 l.sort.should eq [0, 2]
738 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
740 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
741 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
742 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
743 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
744 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
745 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
747 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
749 l = Story.find(:all).map {|s| s.t }
750 l.sort.should eq [0, 1, 3, 4, 5]
753 context '先ほどのケース+他のコミック1件で挿入したとき' do
755 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
756 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
757 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
758 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
759 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
760 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
761 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
762 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
764 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
766 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
767 l.sort.should eq [0, 1, 3, 4, 5]
773 @storyc2.t.should eq ot
777 describe '少ない方に移動に於いて' do
779 @comic = FactoryGirl.create :comic, :author_id => @author.id
780 @panel = FactoryGirl.create :panel, :author_id => @author.id
783 it 'Updateを依頼している' do
784 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
785 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
786 Story.stub(:update_all).with(any_args)
787 Story.should_receive(:update_all).with(any_args).exactly(1)
790 @story2.lesser_shift ot
793 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
795 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
796 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
800 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
802 @story2.lesser_shift @ot
803 l = Story.find(:all).map {|s| s.t }
804 l.sort.should eq [1, 1]
806 it '既存のt0を1にシフトしている' do
807 @story2.lesser_shift @ot
812 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
814 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
815 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
816 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
820 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
822 @story3.lesser_shift @ot
823 l = Story.find(:all).map {|s| s.t }
824 l.sort.should eq [0, 2, 2]
826 it '既存のt1を2にシフトしている' do
827 @story3.lesser_shift @ot
829 @story2.t.should eq 2
832 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
834 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
835 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
836 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
837 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
838 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
842 it 'これから挿入するt(1)が欠番になっている' do
844 @story4.lesser_shift @ot
845 l = Story.find(:all).map {|s| s.t }
846 l.sort.should eq [0, 2, 3, 3, 4]
849 @story4.lesser_shift @ot
854 @story4.lesser_shift @ot
856 @story5.t.should eq 4
858 it '既存のt1を2にシフトしている' do
859 @story4.lesser_shift @ot
861 @story2.t.should eq 2
863 it '既存のt2を3にシフトしている' do
864 @story4.lesser_shift @ot
866 @story3.t.should eq 3
869 context '先ほどのケース+他のコミック1件で挿入したとき' do
871 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
872 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
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
881 it 'これから挿入するt(1)が欠番になっている' do
882 @story4.lesser_shift @ot
883 l = Story.find(:all).map {|s| s.t }
884 l.sort.should eq [0, 0, 2, 3, 3, 4]
887 @story4.lesser_shift @ot
892 @story4.lesser_shift @ot
894 @story5.t.should eq 4
896 it '既存のt1を2にシフトしている' do
897 @story4.lesser_shift @ot
899 @story2.t.should eq 2
901 it '既存のt2を3にシフトしている' do
902 @story4.lesser_shift @ot
904 @story3.t.should eq 3
907 @story4.lesser_shift @ot
909 @storyc2.t.should eq 0
914 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
916 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
917 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
921 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
923 @story2.lesser_shift @ot
924 l = Story.find(:all).map {|s| s.t }
925 l.sort.should eq [1, 1]
927 it '既存のt0を1にシフトしている' do
928 @story2.lesser_shift @ot
932 it '既存のt1は0に補正されている' do
933 @story2.lesser_shift @ot
934 @story2.t.should eq 0
938 describe '大きい方に移動に於いて' do
940 @comic = FactoryGirl.create :comic, :author_id => @author.id
941 @panel = FactoryGirl.create :panel, :author_id => @author.id
944 it 'Updateを依頼している' do
945 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
946 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
947 Story.stub(:update_all).with(any_args)
948 Story.should_receive(:update_all).with(any_args).exactly(1)
951 @story.higher_shift ot
954 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
956 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
957 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
961 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
963 @story.higher_shift @ot
964 l = Story.find(:all).map {|s| s.t }
965 l.sort.should eq [0, 0]
967 it '既存のt1を0にシフトしている' do
968 @story.higher_shift @ot
970 @story2.t.should eq 0
973 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
975 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
976 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
977 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
981 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
983 @story.higher_shift @ot
984 l = Story.find(:all).map {|s| s.t }
985 l.sort.should eq [0, 0, 2]
987 it '既存のt1を0にシフトしている' do
988 @story.higher_shift @ot
990 @story2.t.should eq 0
993 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
995 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
996 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
997 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
998 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
999 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1003 it 'これから挿入するt(3)が欠番になっている' do
1005 @story2.higher_shift @ot
1006 l = Story.find(:all).map {|s| s.t }
1007 l.sort.should eq [0, 1, 1, 2, 4]
1009 it '既存のt0には変化がない' do
1010 @story2.higher_shift @ot
1012 @story.t.should eq 0
1014 it '既存のt4には変化がない' do
1015 @story2.higher_shift @ot
1017 @story5.t.should eq 4
1019 it '既存のt2を1にシフトしている' do
1020 @story2.higher_shift @ot
1022 @story3.t.should eq 1
1024 it '既存のt3を2にシフトしている' do
1025 @story2.higher_shift @ot
1027 @story4.t.should eq 2
1030 context '先ほどのケース+他のコミック1件で挿入したとき' do
1032 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1033 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1034 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1035 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1036 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1037 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1038 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1042 it 'これから挿入するt(3)が欠番になっている' do
1044 @story2.higher_shift @ot
1045 l = Story.find(:all).map {|s| s.t }
1046 l.sort.should eq [0, 0, 1, 1, 2, 4]
1048 it '既存のt0には変化がない' do
1049 @story2.higher_shift @ot
1051 @story.t.should eq 0
1053 it '既存のt4には変化がない' do
1054 @story2.higher_shift @ot
1056 @story5.t.should eq 4
1058 it '既存のt2を1にシフトしている' do
1059 @story2.higher_shift @ot
1061 @story3.t.should eq 1
1063 it '既存のt3を2にシフトしている' do
1064 @story2.higher_shift @ot
1066 @story4.t.should eq 2
1068 it '他のコミックに影響がない' do
1069 @story2.higher_shift @ot
1071 @storyc2.t.should eq 0
1075 #max超えたときはmaxとして正常扱い
1076 context 'テーブルに2件(t:0,1)で0を2に移動したとき' 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
1083 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1085 @story.higher_shift @ot
1086 l = Story.find(:all).map {|s| s.t }
1087 l.sort.should eq [0, 0]
1089 it '既存のt1を0にシフトしている' do
1090 @story.higher_shift @ot
1092 @story2.t.should eq 0
1094 it '既存のt0は1に補正されている' do
1095 @story.higher_shift @ot
1096 @story.t.should eq 1
1100 describe '入れ替えに於いて' do
1102 @comic = FactoryGirl.create :comic, :author_id => @author.id
1103 @panel = FactoryGirl.create :panel, :author_id => @author.id
1104 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1105 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1107 context '新tが旧tより小さいとき' do
1108 it '少ない方に移動を依頼している' do
1109 Story.any_instance.stub(:lesser_shift).with(any_args)
1110 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1113 @story2.update_shift ot
1116 context '新tが旧tより大きいとき' do
1117 it '大きい方に移動を依頼している' do
1118 Story.any_instance.stub(:higher_shift).with(any_args)
1119 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1122 @story.update_shift ot
1126 describe '順序入れ替えに於いて' do
1128 @comic = FactoryGirl.create :comic, :author_id => @author.id
1129 @panel = FactoryGirl.create :panel, :author_id => @author.id
1131 context 'オブジェクトが新規でtが空のとき' do
1132 it '末尾追加としてtを補充依頼している' do
1133 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1134 Story.stub(:new_t).with(any_args).and_return(0)
1135 Story.should_receive(:new_t).with(any_args).exactly(1)
1140 context 'オブジェクトが新規でtが設定されているとき' do
1141 it '挿入追加として挿入シフトを依頼している' do
1142 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1143 Story.any_instance.stub(:insert_shift).with(any_args)
1144 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1149 context 'オブジェクトが新規でなくtが設定されているとき' do
1150 it 'コマ移動として入れ替えを依頼している' do
1151 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1152 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1153 Story.any_instance.stub(:update_shift).with(any_args)
1154 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1159 context 'オブジェクトが新規でなくtが空のとき' do
1160 it '入れ替えもシフトもせず、tを空のままにしている' do
1161 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1165 describe '編集許可に於いて' do
1167 @comic = FactoryGirl.create :comic, :author_id => @author.id
1168 @panel = FactoryGirl.create :panel, :author_id => @author.id
1169 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1171 context 'つつがなく終わるとき' do
1177 context 'コミックで引っかかるとき' do
1179 @story.comic_id = nil
1184 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1189 context 'コマで引っかかるとき' do
1191 @story.panel_id = nil
1196 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1202 describe '保存に於いて' do
1204 @comic = FactoryGirl.create :comic, :author_id => @author.id
1205 @panel = FactoryGirl.create :panel, :author_id => @author.id
1206 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1208 context 'つつがなく終わるとき' do
1209 it '編集許可チェックを依頼している' do
1210 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1211 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1214 it '順序入れ替えを依頼している' do
1215 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1216 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1217 Story.any_instance.stub(:save).with(any_args).and_return(true)
1218 Story.stub(:validate_t).with(any_args).and_return(true)
1222 Story.stub(:new_t).with(any_args).and_return(0)
1223 Story.any_instance.stub(:save).with(any_args).and_return(true)
1224 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1225 Story.stub(:validate_t).with(any_args).and_return(true)
1228 it 'tのシリアライズチェックを依頼している' do
1229 Story.stub(:new_t).with(any_args).and_return(0)
1230 Story.any_instance.stub(:save).with(any_args).and_return(true)
1231 Story.stub(:validate_t).with(any_args).and_return(true)
1232 Story.should_receive(:validate_t).with(any_args).exactly(1)
1236 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1237 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1239 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1240 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1241 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1242 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1243 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1244 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1245 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1246 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1248 it '既存のt0には変化がない' do
1251 @story.t.should eq 0
1253 it '既存のt1には変化がない' do
1256 @story2.t.should eq 1
1258 it '既存のt2を3にシフトしている' do
1261 @story3.t.should eq 3
1263 it '既存のt3を4にシフトしている' do
1266 @story4.t.should eq 4
1268 it '既存のt5を5にシフトしている' do
1271 @story5.t.should eq 5
1273 it '新規のt2が作成されている' do
1276 @story6.t.should eq 2
1278 it '他のコミックに影響がない' do
1282 @storyc2.t.should eq @ot
1285 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1287 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1288 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1289 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1290 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1291 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1292 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1293 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1297 it '既存のt0には変化がない' do
1300 @story.t.should eq 0
1302 it '既存のt4には変化がない' do
1305 @story5.t.should eq 4
1307 it '既存のt1を2にシフトしている' do
1310 @story2.t.should eq 2
1312 it '既存のt2を3にシフトしている' do
1315 @story3.t.should eq 3
1317 it '既存のt3を1にシフトしている' do
1320 @story4.t.should eq 1
1322 it '他のコミックに影響がない' do
1325 @storyc2.t.should eq 0
1328 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1330 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1331 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1332 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1333 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1334 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1335 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1336 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1340 it '既存のt0には変化がない' do
1343 @story.t.should eq 0
1345 it '既存のt4には変化がない' do
1348 @story5.t.should eq 4
1350 it '既存のt1を3にシフトしている' do
1353 @story2.t.should eq 3
1355 it '既存のt2を1にシフトしている' do
1358 @story3.t.should eq 1
1360 it '既存のt3を2にシフトしている' do
1363 @story4.t.should eq 2
1365 it '他のコミックに影響がない' do
1368 @storyc2.t.should eq 0
1371 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1372 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1374 Story.any_instance.stub(:save).with(any_args).and_return(false)
1375 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1376 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1377 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1378 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1379 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1380 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1381 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1382 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1387 @story.t.should eq 0
1389 @story2.t.should eq 1
1391 @story3.t.should eq 2
1393 @story4.t.should eq 3
1395 @story5.t.should eq 4
1397 @storyc2.t.should eq 0
1404 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1406 Story.stub(:validate_t).with(any_args).and_return(false)
1407 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1408 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1409 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1410 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1411 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1412 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1413 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1420 @story.t.should eq 0
1422 @story2.t.should eq 1
1424 @story3.t.should eq 2
1426 @story4.t.should eq 3
1428 @story5.t.should eq 4
1430 @storyc2.t.should eq 0
1433 r = @story4.store @ot
1436 it 'tにエラーメッセージが入っている' do
1438 @story4.errors[:t].should_not be_empty
1439 @story4.valid?.should be_true
1442 context '編集不可だったとき' do
1444 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1445 Story.any_instance.stub(:allow?).and_return(false)
1447 it '403Forbidden例外を返す' do
1450 }.should raise_error(ActiveRecord::Forbidden)
1454 describe '切り詰め処理つき削除に於いて' do
1456 @comic = FactoryGirl.create :comic, :author_id => @author.id
1457 @panel = FactoryGirl.create :panel, :author_id => @author.id
1458 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1460 context 'つつがなく終わるとき' do
1463 @story.destroy_and_shorten
1464 }.should change(Story, :count ).by(-1)
1467 #連携テスト。切り詰めが直接DBをいじる
1468 context '2件で先頭を削除したとき' do
1470 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1474 @story.destroy_and_shorten
1475 }.should change(Story, :count ).by(-1)
1478 @story.destroy_and_shorten
1480 Story.find @story.id
1481 }.should raise_error(ActiveRecord::RecordNotFound)
1484 @story.destroy_and_shorten
1486 @story2.t.should eq 0
1489 context '3件で先頭を削除したとき' do
1491 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1492 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1496 @story.destroy_and_shorten
1497 }.should change(Story, :count ).by(-1)
1500 @story.destroy_and_shorten
1502 Story.find @story.id
1503 }.should raise_error(ActiveRecord::RecordNotFound)
1506 @story.destroy_and_shorten
1508 @story2.t.should eq 0
1511 @story.destroy_and_shorten
1513 @story3.t.should eq 1
1516 context '5件で3件目を削除したとき' do
1518 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1519 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1520 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1521 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1525 @story3.destroy_and_shorten
1526 }.should change(Story, :count ).by(-1)
1529 @story3.destroy_and_shorten
1531 @story.t.should eq 0
1534 @story3.destroy_and_shorten
1536 @story2.t.should eq 1
1539 @story3.destroy_and_shorten
1541 Story.find @story3.id
1542 }.should raise_error(ActiveRecord::RecordNotFound)
1545 @story3.destroy_and_shorten
1547 @story4.t.should eq 2
1550 @story3.destroy_and_shorten
1552 @story5.t.should eq 3
1555 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する