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
369 r = Story.mylist @author, 5, 0
370 r.should have(5).items
375 describe '編集取得に於いて' do
377 @comic = FactoryGirl.create :comic, :author_id => @author.id
378 @panel = FactoryGirl.create :panel, :author_id => @author.id
379 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
381 context 'つつがなく終わるとき' do
\r
382 it '単体取得オプションを利用している' do
\r
383 Story.stub(:show_opt).with(any_args).and_return({})
\r
384 Story.should_receive(:show_opt).with(any_args).exactly(1)
\r
385 r = Story.edit @story.id, @author
387 it '所持判定を問い合わせている' do
\r
388 Story.any_instance.stub(:own?).with(any_args).and_return(true)
\r
389 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
390 r = Story.edit @story.id, @author
394 l = Story.edit @story.id, @author
397 context '他人のストーリーを開こうとしたとき' do
398 it '403Forbidden例外を返す' do
399 Story.any_instance.stub(:own?).and_return(false)
401 Story.edit @story.id, @author
402 }.should raise_error(ActiveRecord::Forbidden)
405 context '存在しないストーリーを開こうとしたとき' do
406 it '404RecordNotFound例外を返す' do
408 Story.edit 110, @author
409 }.should raise_error(ActiveRecord::RecordNotFound)
414 describe '単体取得オプションに於いて' do
415 it 'includeキーを含んでいる' do
417 r.has_key?(:include).should be_true
420 r = Story.show_opt[:include]
421 r.should have(3).items
424 r = Story.show_opt[:include]
425 r.has_key?(:comic).should be_true
427 it 'コミックは作家を含んでいる' do
428 r = Story.show_opt[:include]
429 r[:comic].has_key?(:author).should be_true
432 r = Story.show_opt[:include]
433 r.has_key?(:author).should be_true
436 r = Story.show_opt[:include]
437 r.has_key?(:panel).should be_true
440 r = Story.show_opt[:include]
441 r[:panel].has_key?(:author).should be_true
444 r = Story.show_opt[:include]
445 r[:panel].has_key?(:panel_pictures).should be_true
447 it 'コマ絵は実素材を含んでいる' do
448 r = Story.show_opt[:include]
449 r[:panel][:panel_pictures].has_key?(:picture).should be_true
452 r = Story.show_opt[:include]
453 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
455 it '実素材はライセンスを含んでいる' do
456 r = Story.show_opt[:include]
457 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
459 it 'コマはフキダシを含んでいる' do
460 r = Story.show_opt[:include]
461 r[:panel].has_key?(:speech_balloons).should be_true
463 it 'フキダシはフキダシ枠を含んでいる' do
464 r = Story.show_opt[:include]
465 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
467 it 'フキダシはセリフを含んでいる' do
468 r = Story.show_opt[:include]
469 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
472 describe 'json単体取得オプションに於いて' do
475 describe 'ストーリーのjson出力に於いて' do
478 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
479 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
\r
480 @sb = @panel.speech_balloons.create(
\r
481 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
\r
483 @gc = @panel.ground_colors.create(
\r
484 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
\r
486 @gp = @panel.ground_pictures.create(
\r
487 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
\r
489 @pc = @panel.panel_colors.create(
\r
490 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
\r
493 @comic = FactoryGirl.create :comic, :author_id => @author.id
494 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
496 context '事前チェックする' do
498 Panel.any_instance.stub(:elements).and_return('{}')
500 it 'コマ要素のjson出力を依頼している' do
\r
501 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
502 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
\r
503 r = @story.story_as_json @author
506 it 'json textを返している' do
\r
507 r = JSON.parse @story.story_as_json(@author)
\r
508 r.is_a?(Hash).should be_true
\r
510 it 'comic,author,panel,コマ要素を含んでいる' do
\r
511 r = JSON.parse @story.story_as_json(@author)
\r
512 r.has_key?('comic').should be_true
\r
513 r['comic'].has_key?('author').should be_true
\r
514 r.has_key?('author').should be_true
\r
515 r.has_key?('panel').should be_true
\r
516 r['panel'].has_key?('author').should be_true
\r
518 context 'コマ閲覧許可のとき' do
520 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
522 it 'コマ要素にコマ要素を追加している' do
\r
523 r = JSON.parse @story.story_as_json(@author)
\r
524 r['panel'].has_key?('elements').should be_true
\r
525 r['panel']['elements'].should_not be_empty
\r
528 context 'コマ閲覧不許可のとき' do
530 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
532 it 'コマ要素にデータを含ませない' do
\r
533 r = JSON.parse @story.story_as_json(@author)
\r
534 r['panel'].has_key?('elements').should be_false
\r
539 describe 't補充値に於いて' do
541 @comic = FactoryGirl.create :comic, :author_id => @author.id
542 @panel = FactoryGirl.create :panel, :author_id => @author.id
545 context 'コミック初のコマなら' do
547 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
549 r = Story.new_t @story.comic_id
553 context 'コミックに一個コマがあるとき' do
555 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
556 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
558 r = Story.new_t @story.comic_id
562 context 'コミックに2個コマがあるとき' do
564 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
565 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
566 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
568 r = Story.new_t @story.comic_id
573 describe 'シリアライズチェックに於いて' do
574 context 'つつがなく終わるとき' do
575 it '0からシリアライズされているならTrueを返す' do
576 r = Story.serial? [0, 1, 2]
579 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
580 r = Story.serial? [0, 2, 1]
583 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
584 r = Story.serial? [ 2, 1, 4, 3, 0]
589 it '0から始まらないならFalseを返す' do
590 r = Story.serial? [1, 2, 3]
593 it '連続していないならFalseを返す' do
594 r = Story.serial? [0, 1, 2, 4]
597 it '連続していないならFalseを返す' do
598 r = Story.serial? [0, 1, 2, 4, 5]
603 describe 't収集に於いて' do
605 @comic = FactoryGirl.create :comic, :author_id => @author.id
606 @panel = FactoryGirl.create :panel, :author_id => @author.id
607 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
608 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
609 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
611 context 'つつがなく終わるとき' do
612 it 'ストーリーから同一コミックのtだけを収集している' do
613 r = Story.collect_t @story
618 it 'ストーリーから同一コミックのtだけを収集している' do
619 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
620 r = Story.collect_t @story
621 r.sort.should eq [0, 1]
624 context '複数コマでヨソのコミックも混じっているとき' do
625 it 'ストーリーから同一コミックのtだけを収集している' do
626 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
627 r = Story.collect_t @story
628 r.sort.should eq [0, 1]
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.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
638 context 'つつがなく終わるとき' do
640 Story.should_receive(:collect_t).with(any_args).exactly(1)
641 Story.stub(:collect_t).with(any_args).and_return([])
642 Story.stub(:serial?).with(any_args).and_return(true)
643 r = Story.validate_t @story
645 it '収集したtをシリアライズチェック依頼している' do
646 Story.stub(:collect_t).with(any_args).and_return([])
647 Story.should_receive(:serial?).with(any_args).exactly(1)
648 Story.stub(:serial?).with(any_args).and_return(true)
649 r = Story.validate_t @story
653 #依頼チェックだけでは不安なので最低限のチェックを
655 it '一件だけで正常通過している' do
656 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
657 r = Story.validate_t @story
662 it '2件目を作っても正常通過している' do
663 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
664 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
665 r = Story.validate_t @story2
670 describe '挿入シフトに於いて' do
672 @comic = FactoryGirl.create :comic, :author_id => @author.id
673 @panel = FactoryGirl.create :panel, :author_id => @author.id
677 it 'Updateを依頼している' do
678 Story.stub(:update_all).with(any_args)
679 Story.should_receive(:update_all).with(any_args).exactly(1)
680 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
684 context 'テーブルに1件(t:0)で0に挿入したとき' do
686 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
687 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
689 it '既存の行を1にシフトしている' do
692 l.first.t.should eq 1
694 it 'これから挿入するt(0)が欠番になっている' do
696 l = Story.find(:all).map {|s| s.t }
697 l.include?(0).should_not be_true
700 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
702 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
703 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
704 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
706 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
708 l = Story.find(:all).map {|s| s.t }
709 l.sort.should eq [0, 2]
712 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
714 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
715 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
716 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
717 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
718 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
719 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
721 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
723 l = Story.find(:all).map {|s| s.t }
724 l.sort.should eq [0, 1, 3, 4, 5]
727 context '先ほどのケース+他のコミック1件で挿入したとき' do
729 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
730 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
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.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
734 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
735 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
736 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
738 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
740 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
741 l.sort.should eq [0, 1, 3, 4, 5]
747 @storyc2.t.should eq ot
751 describe '少ない方に移動に於いて' do
753 @comic = FactoryGirl.create :comic, :author_id => @author.id
754 @panel = FactoryGirl.create :panel, :author_id => @author.id
757 it 'Updateを依頼している' do
758 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
759 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
760 Story.stub(:update_all).with(any_args)
761 Story.should_receive(:update_all).with(any_args).exactly(1)
764 @story2.lesser_shift ot
767 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
769 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
770 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
774 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
776 @story2.lesser_shift @ot
777 l = Story.find(:all).map {|s| s.t }
778 l.sort.should eq [1, 1]
780 it '既存のt0を1にシフトしている' do
781 @story2.lesser_shift @ot
786 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
788 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
789 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
790 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
794 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
796 @story3.lesser_shift @ot
797 l = Story.find(:all).map {|s| s.t }
798 l.sort.should eq [0, 2, 2]
800 it '既存のt1を2にシフトしている' do
801 @story3.lesser_shift @ot
803 @story2.t.should eq 2
806 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
808 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
809 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
810 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
811 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
812 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
816 it 'これから挿入するt(1)が欠番になっている' do
818 @story4.lesser_shift @ot
819 l = Story.find(:all).map {|s| s.t }
820 l.sort.should eq [0, 2, 3, 3, 4]
823 @story4.lesser_shift @ot
828 @story4.lesser_shift @ot
830 @story5.t.should eq 4
832 it '既存のt1を2にシフトしている' do
833 @story4.lesser_shift @ot
835 @story2.t.should eq 2
837 it '既存のt2を3にシフトしている' do
838 @story4.lesser_shift @ot
840 @story3.t.should eq 3
843 context '先ほどのケース+他のコミック1件で挿入したとき' do
845 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
846 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
847 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
848 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
849 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
850 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
851 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
855 it 'これから挿入するt(1)が欠番になっている' do
856 @story4.lesser_shift @ot
857 l = Story.find(:all).map {|s| s.t }
858 l.sort.should eq [0, 0, 2, 3, 3, 4]
861 @story4.lesser_shift @ot
866 @story4.lesser_shift @ot
868 @story5.t.should eq 4
870 it '既存のt1を2にシフトしている' do
871 @story4.lesser_shift @ot
873 @story2.t.should eq 2
875 it '既存のt2を3にシフトしている' do
876 @story4.lesser_shift @ot
878 @story3.t.should eq 3
881 @story4.lesser_shift @ot
883 @storyc2.t.should eq 0
888 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
890 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
891 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
895 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
897 @story2.lesser_shift @ot
898 l = Story.find(:all).map {|s| s.t }
899 l.sort.should eq [1, 1]
901 it '既存のt0を1にシフトしている' do
902 @story2.lesser_shift @ot
906 it '既存のt1は0に補正されている' do
907 @story2.lesser_shift @ot
908 @story2.t.should eq 0
912 describe '大きい方に移動に於いて' do
914 @comic = FactoryGirl.create :comic, :author_id => @author.id
915 @panel = FactoryGirl.create :panel, :author_id => @author.id
918 it 'Updateを依頼している' 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
921 Story.stub(:update_all).with(any_args)
922 Story.should_receive(:update_all).with(any_args).exactly(1)
925 @story.higher_shift ot
928 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
930 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
931 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
935 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
937 @story.higher_shift @ot
938 l = Story.find(:all).map {|s| s.t }
939 l.sort.should eq [0, 0]
941 it '既存のt1を0にシフトしている' do
942 @story.higher_shift @ot
944 @story2.t.should eq 0
947 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
949 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
950 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
951 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
955 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
957 @story.higher_shift @ot
958 l = Story.find(:all).map {|s| s.t }
959 l.sort.should eq [0, 0, 2]
961 it '既存のt1を0にシフトしている' do
962 @story.higher_shift @ot
964 @story2.t.should eq 0
967 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
969 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
970 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
971 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
972 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
973 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
977 it 'これから挿入するt(3)が欠番になっている' do
979 @story2.higher_shift @ot
980 l = Story.find(:all).map {|s| s.t }
981 l.sort.should eq [0, 1, 1, 2, 4]
984 @story2.higher_shift @ot
989 @story2.higher_shift @ot
991 @story5.t.should eq 4
993 it '既存のt2を1にシフトしている' do
994 @story2.higher_shift @ot
996 @story3.t.should eq 1
998 it '既存のt3を2にシフトしている' do
999 @story2.higher_shift @ot
1001 @story4.t.should eq 2
1004 context '先ほどのケース+他のコミック1件で挿入したとき' do
1006 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1007 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1008 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1009 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1010 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1011 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1012 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1016 it 'これから挿入するt(3)が欠番になっている' do
1018 @story2.higher_shift @ot
1019 l = Story.find(:all).map {|s| s.t }
1020 l.sort.should eq [0, 0, 1, 1, 2, 4]
1022 it '既存のt0には変化がない' do
1023 @story2.higher_shift @ot
1025 @story.t.should eq 0
1027 it '既存のt4には変化がない' do
1028 @story2.higher_shift @ot
1030 @story5.t.should eq 4
1032 it '既存のt2を1にシフトしている' do
1033 @story2.higher_shift @ot
1035 @story3.t.should eq 1
1037 it '既存のt3を2にシフトしている' do
1038 @story2.higher_shift @ot
1040 @story4.t.should eq 2
1042 it '他のコミックに影響がない' do
1043 @story2.higher_shift @ot
1045 @storyc2.t.should eq 0
1049 #max超えたときはmaxとして正常扱い
1050 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1052 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1053 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1057 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1059 @story.higher_shift @ot
1060 l = Story.find(:all).map {|s| s.t }
1061 l.sort.should eq [0, 0]
1063 it '既存のt1を0にシフトしている' do
1064 @story.higher_shift @ot
1066 @story2.t.should eq 0
1068 it '既存のt0は1に補正されている' do
1069 @story.higher_shift @ot
1070 @story.t.should eq 1
1074 describe '入れ替えに於いて' do
1076 @comic = FactoryGirl.create :comic, :author_id => @author.id
1077 @panel = FactoryGirl.create :panel, :author_id => @author.id
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
1081 context '新tが旧tより小さいとき' do
1082 it '少ない方に移動を依頼している' do
1083 Story.any_instance.stub(:lesser_shift).with(any_args)
1084 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1087 @story2.update_shift ot
1090 context '新tが旧tより大きいとき' do
1091 it '大きい方に移動を依頼している' do
1092 Story.any_instance.stub(:higher_shift).with(any_args)
1093 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1096 @story.update_shift ot
1100 describe '順序入れ替えに於いて' do
1102 @comic = FactoryGirl.create :comic, :author_id => @author.id
1103 @panel = FactoryGirl.create :panel, :author_id => @author.id
1105 context 'オブジェクトが新規でtが空のとき' do
1106 it '末尾追加としてtを補充依頼している' do
1107 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1108 Story.stub(:new_t).with(any_args).and_return(0)
1109 Story.should_receive(:new_t).with(any_args).exactly(1)
1114 context 'オブジェクトが新規でtが設定されているとき' do
1115 it '挿入追加として挿入シフトを依頼している' do
1116 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1117 Story.any_instance.stub(:insert_shift).with(any_args)
1118 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1123 context 'オブジェクトが新規でなくtが設定されているとき' do
1124 it 'コマ移動として入れ替えを依頼している' do
1125 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1126 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1127 Story.any_instance.stub(:update_shift).with(any_args)
1128 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1133 context 'オブジェクトが新規でなくtが空のとき' do
1134 it '入れ替えもシフトもせず、tを空のままにしている' do
1135 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1139 describe '編集許可に於いて' do
1141 @comic = FactoryGirl.create :comic, :author_id => @author.id
1142 @panel = FactoryGirl.create :panel, :author_id => @author.id
1143 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1145 context 'つつがなく終わるとき' do
1151 context 'コミックで引っかかるとき' do
1153 @story.comic_id = nil
1158 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1163 context 'コマで引っかかるとき' do
1165 @story.panel_id = nil
1170 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1176 describe '保存に於いて' do
1178 @comic = FactoryGirl.create :comic, :author_id => @author.id
1179 @panel = FactoryGirl.create :panel, :author_id => @author.id
1180 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1182 context 'つつがなく終わるとき' do
1183 it '編集許可チェックを依頼している' do
1184 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1185 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1188 it '順序入れ替えを依頼している' do
1189 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1190 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1191 Story.any_instance.stub(:save).with(any_args).and_return(true)
1192 Story.stub(:validate_t).with(any_args).and_return(true)
1196 Story.stub(:new_t).with(any_args).and_return(0)
1197 Story.any_instance.stub(:save).with(any_args).and_return(true)
1198 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1199 Story.stub(:validate_t).with(any_args).and_return(true)
1202 it 'tのシリアライズチェックを依頼している' do
1203 Story.stub(:new_t).with(any_args).and_return(0)
1204 Story.any_instance.stub(:save).with(any_args).and_return(true)
1205 Story.stub(:validate_t).with(any_args).and_return(true)
1206 Story.should_receive(:validate_t).with(any_args).exactly(1)
1210 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1211 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1213 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1214 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1215 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1216 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1217 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1218 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1219 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1220 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1222 it '既存のt0には変化がない' do
1225 @story.t.should eq 0
1227 it '既存のt1には変化がない' do
1230 @story2.t.should eq 1
1232 it '既存のt2を3にシフトしている' do
1235 @story3.t.should eq 3
1237 it '既存のt3を4にシフトしている' do
1240 @story4.t.should eq 4
1242 it '既存のt5を5にシフトしている' do
1245 @story5.t.should eq 5
1247 it '新規のt2が作成されている' do
1250 @story6.t.should eq 2
1252 it '他のコミックに影響がない' do
1256 @storyc2.t.should eq @ot
1259 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1261 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1262 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1263 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1264 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1265 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1266 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1267 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1271 it '既存のt0には変化がない' do
1274 @story.t.should eq 0
1276 it '既存のt4には変化がない' do
1279 @story5.t.should eq 4
1281 it '既存のt1を2にシフトしている' do
1284 @story2.t.should eq 2
1286 it '既存のt2を3にシフトしている' do
1289 @story3.t.should eq 3
1291 it '既存のt3を1にシフトしている' do
1294 @story4.t.should eq 1
1296 it '他のコミックに影響がない' do
1299 @storyc2.t.should eq 0
1302 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1304 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1305 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1306 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1307 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1308 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1309 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1310 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1314 it '既存のt0には変化がない' do
1317 @story.t.should eq 0
1319 it '既存のt4には変化がない' do
1322 @story5.t.should eq 4
1324 it '既存のt1を3にシフトしている' do
1327 @story2.t.should eq 3
1329 it '既存のt2を1にシフトしている' do
1332 @story3.t.should eq 1
1334 it '既存のt3を2にシフトしている' do
1337 @story4.t.should eq 2
1339 it '他のコミックに影響がない' do
1342 @storyc2.t.should eq 0
1345 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1346 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1348 Story.any_instance.stub(:save).with(any_args).and_return(false)
1349 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1350 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1351 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1352 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1353 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1354 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1355 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1356 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1361 @story.t.should eq 0
1363 @story2.t.should eq 1
1365 @story3.t.should eq 2
1367 @story4.t.should eq 3
1369 @story5.t.should eq 4
1371 @storyc2.t.should eq 0
1378 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1380 Story.stub(:validate_t).with(any_args).and_return(false)
1381 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1382 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1383 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1384 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1385 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1386 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1387 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1394 @story.t.should eq 0
1396 @story2.t.should eq 1
1398 @story3.t.should eq 2
1400 @story4.t.should eq 3
1402 @story5.t.should eq 4
1404 @storyc2.t.should eq 0
1407 r = @story4.store @ot
1410 it 'tにエラーメッセージが入っている' do
1412 @story4.errors[:t].should_not be_empty
1413 @story4.valid?.should be_true
1416 context '編集不可だったとき' do
1418 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1419 Story.any_instance.stub(:allow?).and_return(false)
1421 it '403Forbidden例外を返す' do
1424 }.should raise_error(ActiveRecord::Forbidden)
1428 describe '切り詰め処理つき削除に於いて' do
1430 @comic = FactoryGirl.create :comic, :author_id => @author.id
1431 @panel = FactoryGirl.create :panel, :author_id => @author.id
1432 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1434 context 'つつがなく終わるとき' do
1437 @story.destroy_and_shorten
1438 }.should change(Story, :count ).by(-1)
1441 #連携テスト。切り詰めが直接DBをいじる
1442 context '2件で先頭を削除したとき' do
1444 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1448 @story.destroy_and_shorten
1449 }.should change(Story, :count ).by(-1)
1452 @story.destroy_and_shorten
1454 Story.find @story.id
1455 }.should raise_error(ActiveRecord::RecordNotFound)
1458 @story.destroy_and_shorten
1460 @story2.t.should eq 0
1463 context '3件で先頭を削除したとき' do
1465 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1466 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1470 @story.destroy_and_shorten
1471 }.should change(Story, :count ).by(-1)
1474 @story.destroy_and_shorten
1476 Story.find @story.id
1477 }.should raise_error(ActiveRecord::RecordNotFound)
1480 @story.destroy_and_shorten
1482 @story2.t.should eq 0
1485 @story.destroy_and_shorten
1487 @story3.t.should eq 1
1490 context '5件で3件目を削除したとき' do
1492 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1493 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1494 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1495 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1499 @story3.destroy_and_shorten
1500 }.should change(Story, :count ).by(-1)
1503 @story3.destroy_and_shorten
1505 @story.t.should eq 0
1508 @story3.destroy_and_shorten
1510 @story2.t.should eq 1
1513 @story3.destroy_and_shorten
1515 Story.find @story3.id
1516 }.should raise_error(ActiveRecord::RecordNotFound)
1519 @story3.destroy_and_shorten
1521 @story4.t.should eq 2
1524 @story3.destroy_and_shorten
1526 @story5.t.should eq 3
1529 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する