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 'ストーリーリストのjson出力に於いて' do
\r
541 @panel = FactoryGirl.create :panel, :author_id => @author.id
\r
542 @comic = FactoryGirl.create :comic, :author_id => @author.id
543 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
544 Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
\r
546 context 'つつがなく終わるとき' do
\r
547 it 'ストーリーのjson出力を依頼している' do
\r
548 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
\r
549 r = Story.list_as_json_text [@story], @author
\r
552 it 'json textを返している' do
\r
553 r = Story.list_as_json_text [@story], @author
\r
555 j.is_a?(Array).should be_true
\r
557 it 'ストーリーを含んでいる' do
\r
558 r = Story.list_as_json_text [@story], @author
\r
560 j.first.has_key?('s').should be_true
\r
564 describe 't補充値に於いて' do
566 @comic = FactoryGirl.create :comic, :author_id => @author.id
567 @panel = FactoryGirl.create :panel, :author_id => @author.id
570 context 'コミック初のコマなら' do
572 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
574 r = Story.new_t @story.comic_id
578 context 'コミックに一個コマがあるとき' do
580 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
581 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
583 r = Story.new_t @story.comic_id
587 context 'コミックに2個コマがあるとき' do
589 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
590 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
591 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
593 r = Story.new_t @story.comic_id
598 describe 'シリアライズチェックに於いて' do
599 context 'つつがなく終わるとき' do
600 it '0からシリアライズされているならTrueを返す' do
601 r = Story.serial? [0, 1, 2]
604 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
605 r = Story.serial? [0, 2, 1]
608 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
609 r = Story.serial? [ 2, 1, 4, 3, 0]
614 it '0から始まらないならFalseを返す' do
615 r = Story.serial? [1, 2, 3]
618 it '連続していないならFalseを返す' do
619 r = Story.serial? [0, 1, 2, 4]
622 it '連続していないならFalseを返す' do
623 r = Story.serial? [0, 1, 2, 4, 5]
628 describe 't収集に於いて' do
630 @comic = FactoryGirl.create :comic, :author_id => @author.id
631 @panel = FactoryGirl.create :panel, :author_id => @author.id
632 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
633 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
634 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
636 context 'つつがなく終わるとき' do
637 it 'ストーリーから同一コミックのtだけを収集している' do
638 r = Story.collect_t @story
643 it 'ストーリーから同一コミックのtだけを収集している' do
644 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
645 r = Story.collect_t @story
646 r.sort.should eq [0, 1]
649 context '複数コマでヨソのコミックも混じっているとき' do
650 it 'ストーリーから同一コミックのtだけを収集している' do
651 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
652 r = Story.collect_t @story
653 r.sort.should eq [0, 1]
657 describe 'tチェックに於いて' do
659 @comic = FactoryGirl.create :comic, :author_id => @author.id
660 @panel = FactoryGirl.create :panel, :author_id => @author.id
661 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
663 context 'つつがなく終わるとき' do
665 Story.should_receive(:collect_t).with(any_args).exactly(1)
666 Story.stub(:collect_t).with(any_args).and_return([])
667 Story.stub(:serial?).with(any_args).and_return(true)
668 r = Story.validate_t @story
670 it '収集したtをシリアライズチェック依頼している' do
671 Story.stub(:collect_t).with(any_args).and_return([])
672 Story.should_receive(:serial?).with(any_args).exactly(1)
673 Story.stub(:serial?).with(any_args).and_return(true)
674 r = Story.validate_t @story
678 #依頼チェックだけでは不安なので最低限のチェックを
680 it '一件だけで正常通過している' do
681 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
682 r = Story.validate_t @story
687 it '2件目を作っても正常通過している' do
688 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
689 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
690 r = Story.validate_t @story2
695 describe '挿入シフトに於いて' do
697 @comic = FactoryGirl.create :comic, :author_id => @author.id
698 @panel = FactoryGirl.create :panel, :author_id => @author.id
702 it 'Updateを依頼している' do
703 Story.stub(:update_all).with(any_args)
704 Story.should_receive(:update_all).with(any_args).exactly(1)
705 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
709 context 'テーブルに1件(t:0)で0に挿入したとき' do
711 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
712 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
714 it '既存の行を1にシフトしている' do
717 l.first.t.should eq 1
719 it 'これから挿入するt(0)が欠番になっている' do
721 l = Story.find(:all).map {|s| s.t }
722 l.include?(0).should_not be_true
725 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
727 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
728 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
729 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
731 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
733 l = Story.find(:all).map {|s| s.t }
734 l.sort.should eq [0, 2]
737 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
739 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
740 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
741 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
742 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
743 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
744 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
746 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
748 l = Story.find(:all).map {|s| s.t }
749 l.sort.should eq [0, 1, 3, 4, 5]
752 context '先ほどのケース+他のコミック1件で挿入したとき' do
754 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
755 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
756 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
757 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
758 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
759 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
760 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
761 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
763 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
765 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
766 l.sort.should eq [0, 1, 3, 4, 5]
772 @storyc2.t.should eq ot
776 describe '少ない方に移動に於いて' do
778 @comic = FactoryGirl.create :comic, :author_id => @author.id
779 @panel = FactoryGirl.create :panel, :author_id => @author.id
782 it 'Updateを依頼している' do
783 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
784 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
785 Story.stub(:update_all).with(any_args)
786 Story.should_receive(:update_all).with(any_args).exactly(1)
789 @story2.lesser_shift ot
792 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
794 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
795 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
799 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
801 @story2.lesser_shift @ot
802 l = Story.find(:all).map {|s| s.t }
803 l.sort.should eq [1, 1]
805 it '既存のt0を1にシフトしている' do
806 @story2.lesser_shift @ot
811 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
813 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
814 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
815 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
819 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
821 @story3.lesser_shift @ot
822 l = Story.find(:all).map {|s| s.t }
823 l.sort.should eq [0, 2, 2]
825 it '既存のt1を2にシフトしている' do
826 @story3.lesser_shift @ot
828 @story2.t.should eq 2
831 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
833 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
834 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
835 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
836 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
837 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
841 it 'これから挿入するt(1)が欠番になっている' do
843 @story4.lesser_shift @ot
844 l = Story.find(:all).map {|s| s.t }
845 l.sort.should eq [0, 2, 3, 3, 4]
848 @story4.lesser_shift @ot
853 @story4.lesser_shift @ot
855 @story5.t.should eq 4
857 it '既存のt1を2にシフトしている' do
858 @story4.lesser_shift @ot
860 @story2.t.should eq 2
862 it '既存のt2を3にシフトしている' do
863 @story4.lesser_shift @ot
865 @story3.t.should eq 3
868 context '先ほどのケース+他のコミック1件で挿入したとき' do
870 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
871 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
872 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
873 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
874 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
875 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
876 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
880 it 'これから挿入するt(1)が欠番になっている' do
881 @story4.lesser_shift @ot
882 l = Story.find(:all).map {|s| s.t }
883 l.sort.should eq [0, 0, 2, 3, 3, 4]
886 @story4.lesser_shift @ot
891 @story4.lesser_shift @ot
893 @story5.t.should eq 4
895 it '既存のt1を2にシフトしている' do
896 @story4.lesser_shift @ot
898 @story2.t.should eq 2
900 it '既存のt2を3にシフトしている' do
901 @story4.lesser_shift @ot
903 @story3.t.should eq 3
906 @story4.lesser_shift @ot
908 @storyc2.t.should eq 0
913 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
915 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
916 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
920 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
922 @story2.lesser_shift @ot
923 l = Story.find(:all).map {|s| s.t }
924 l.sort.should eq [1, 1]
926 it '既存のt0を1にシフトしている' do
927 @story2.lesser_shift @ot
931 it '既存のt1は0に補正されている' do
932 @story2.lesser_shift @ot
933 @story2.t.should eq 0
937 describe '大きい方に移動に於いて' do
939 @comic = FactoryGirl.create :comic, :author_id => @author.id
940 @panel = FactoryGirl.create :panel, :author_id => @author.id
943 it 'Updateを依頼している' do
944 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
945 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
946 Story.stub(:update_all).with(any_args)
947 Story.should_receive(:update_all).with(any_args).exactly(1)
950 @story.higher_shift ot
953 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
955 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
956 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
960 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
962 @story.higher_shift @ot
963 l = Story.find(:all).map {|s| s.t }
964 l.sort.should eq [0, 0]
966 it '既存のt1を0にシフトしている' do
967 @story.higher_shift @ot
969 @story2.t.should eq 0
972 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
974 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
975 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
976 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
980 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
982 @story.higher_shift @ot
983 l = Story.find(:all).map {|s| s.t }
984 l.sort.should eq [0, 0, 2]
986 it '既存のt1を0にシフトしている' do
987 @story.higher_shift @ot
989 @story2.t.should eq 0
992 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
994 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
995 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
996 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
997 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
998 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1002 it 'これから挿入するt(3)が欠番になっている' do
1004 @story2.higher_shift @ot
1005 l = Story.find(:all).map {|s| s.t }
1006 l.sort.should eq [0, 1, 1, 2, 4]
1008 it '既存のt0には変化がない' do
1009 @story2.higher_shift @ot
1011 @story.t.should eq 0
1013 it '既存のt4には変化がない' do
1014 @story2.higher_shift @ot
1016 @story5.t.should eq 4
1018 it '既存のt2を1にシフトしている' do
1019 @story2.higher_shift @ot
1021 @story3.t.should eq 1
1023 it '既存のt3を2にシフトしている' do
1024 @story2.higher_shift @ot
1026 @story4.t.should eq 2
1029 context '先ほどのケース+他のコミック1件で挿入したとき' do
1031 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1032 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1033 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1034 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1035 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1036 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1037 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1041 it 'これから挿入するt(3)が欠番になっている' do
1043 @story2.higher_shift @ot
1044 l = Story.find(:all).map {|s| s.t }
1045 l.sort.should eq [0, 0, 1, 1, 2, 4]
1047 it '既存のt0には変化がない' do
1048 @story2.higher_shift @ot
1050 @story.t.should eq 0
1052 it '既存のt4には変化がない' do
1053 @story2.higher_shift @ot
1055 @story5.t.should eq 4
1057 it '既存のt2を1にシフトしている' do
1058 @story2.higher_shift @ot
1060 @story3.t.should eq 1
1062 it '既存のt3を2にシフトしている' do
1063 @story2.higher_shift @ot
1065 @story4.t.should eq 2
1067 it '他のコミックに影響がない' do
1068 @story2.higher_shift @ot
1070 @storyc2.t.should eq 0
1074 #max超えたときはmaxとして正常扱い
1075 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1077 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1078 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1082 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1084 @story.higher_shift @ot
1085 l = Story.find(:all).map {|s| s.t }
1086 l.sort.should eq [0, 0]
1088 it '既存のt1を0にシフトしている' do
1089 @story.higher_shift @ot
1091 @story2.t.should eq 0
1093 it '既存のt0は1に補正されている' do
1094 @story.higher_shift @ot
1095 @story.t.should eq 1
1099 describe '入れ替えに於いて' do
1101 @comic = FactoryGirl.create :comic, :author_id => @author.id
1102 @panel = FactoryGirl.create :panel, :author_id => @author.id
1103 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1104 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1106 context '新tが旧tより小さいとき' do
1107 it '少ない方に移動を依頼している' do
1108 Story.any_instance.stub(:lesser_shift).with(any_args)
1109 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1112 @story2.update_shift ot
1115 context '新tが旧tより大きいとき' do
1116 it '大きい方に移動を依頼している' do
1117 Story.any_instance.stub(:higher_shift).with(any_args)
1118 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1121 @story.update_shift ot
1125 describe '順序入れ替えに於いて' do
1127 @comic = FactoryGirl.create :comic, :author_id => @author.id
1128 @panel = FactoryGirl.create :panel, :author_id => @author.id
1130 context 'オブジェクトが新規でtが空のとき' do
1131 it '末尾追加としてtを補充依頼している' do
1132 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1133 Story.stub(:new_t).with(any_args).and_return(0)
1134 Story.should_receive(:new_t).with(any_args).exactly(1)
1139 context 'オブジェクトが新規でtが設定されているとき' do
1140 it '挿入追加として挿入シフトを依頼している' do
1141 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1142 Story.any_instance.stub(:insert_shift).with(any_args)
1143 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1148 context 'オブジェクトが新規でなくtが設定されているとき' do
1149 it 'コマ移動として入れ替えを依頼している' do
1150 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1151 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1152 Story.any_instance.stub(:update_shift).with(any_args)
1153 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1158 context 'オブジェクトが新規でなくtが空のとき' do
1159 it '入れ替えもシフトもせず、tを空のままにしている' do
1160 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1164 describe '編集許可に於いて' do
1166 @comic = FactoryGirl.create :comic, :author_id => @author.id
1167 @panel = FactoryGirl.create :panel, :author_id => @author.id
1168 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1170 context 'つつがなく終わるとき' do
1176 context 'コミックで引っかかるとき' do
1178 @story.comic_id = nil
1183 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1188 context 'コマで引っかかるとき' do
1190 @story.panel_id = nil
1195 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1201 describe '保存に於いて' do
1203 @comic = FactoryGirl.create :comic, :author_id => @author.id
1204 @panel = FactoryGirl.create :panel, :author_id => @author.id
1205 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1207 context 'つつがなく終わるとき' do
1208 it '編集許可チェックを依頼している' do
1209 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1210 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1213 it '順序入れ替えを依頼している' do
1214 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1215 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1216 Story.any_instance.stub(:save).with(any_args).and_return(true)
1217 Story.stub(:validate_t).with(any_args).and_return(true)
1221 Story.stub(:new_t).with(any_args).and_return(0)
1222 Story.any_instance.stub(:save).with(any_args).and_return(true)
1223 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1224 Story.stub(:validate_t).with(any_args).and_return(true)
1227 it 'tのシリアライズチェックを依頼している' do
1228 Story.stub(:new_t).with(any_args).and_return(0)
1229 Story.any_instance.stub(:save).with(any_args).and_return(true)
1230 Story.stub(:validate_t).with(any_args).and_return(true)
1231 Story.should_receive(:validate_t).with(any_args).exactly(1)
1235 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1236 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1238 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1239 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1240 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1241 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1242 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1243 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1244 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1245 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1247 it '既存のt0には変化がない' do
1250 @story.t.should eq 0
1252 it '既存のt1には変化がない' do
1255 @story2.t.should eq 1
1257 it '既存のt2を3にシフトしている' do
1260 @story3.t.should eq 3
1262 it '既存のt3を4にシフトしている' do
1265 @story4.t.should eq 4
1267 it '既存のt5を5にシフトしている' do
1270 @story5.t.should eq 5
1272 it '新規のt2が作成されている' do
1275 @story6.t.should eq 2
1277 it '他のコミックに影響がない' do
1281 @storyc2.t.should eq @ot
1284 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1286 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1287 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1288 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1289 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1290 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1291 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1292 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1296 it '既存のt0には変化がない' do
1299 @story.t.should eq 0
1301 it '既存のt4には変化がない' do
1304 @story5.t.should eq 4
1306 it '既存のt1を2にシフトしている' do
1309 @story2.t.should eq 2
1311 it '既存のt2を3にシフトしている' do
1314 @story3.t.should eq 3
1316 it '既存のt3を1にシフトしている' do
1319 @story4.t.should eq 1
1321 it '他のコミックに影響がない' do
1324 @storyc2.t.should eq 0
1327 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1329 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1330 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1331 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1332 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1333 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1334 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1335 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1339 it '既存のt0には変化がない' do
1342 @story.t.should eq 0
1344 it '既存のt4には変化がない' do
1347 @story5.t.should eq 4
1349 it '既存のt1を3にシフトしている' do
1352 @story2.t.should eq 3
1354 it '既存のt2を1にシフトしている' do
1357 @story3.t.should eq 1
1359 it '既存のt3を2にシフトしている' do
1362 @story4.t.should eq 2
1364 it '他のコミックに影響がない' do
1367 @storyc2.t.should eq 0
1370 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1371 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1373 Story.any_instance.stub(:save).with(any_args).and_return(false)
1374 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1375 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1376 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1377 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1378 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1379 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1380 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1381 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1386 @story.t.should eq 0
1388 @story2.t.should eq 1
1390 @story3.t.should eq 2
1392 @story4.t.should eq 3
1394 @story5.t.should eq 4
1396 @storyc2.t.should eq 0
1403 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1405 Story.stub(:validate_t).with(any_args).and_return(false)
1406 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1407 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1408 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1409 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1410 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1411 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1412 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1419 @story.t.should eq 0
1421 @story2.t.should eq 1
1423 @story3.t.should eq 2
1425 @story4.t.should eq 3
1427 @story5.t.should eq 4
1429 @storyc2.t.should eq 0
1432 r = @story4.store @ot
1435 it 'tにエラーメッセージが入っている' do
1437 @story4.errors[:t].should_not be_empty
1438 @story4.valid?.should be_true
1441 context '編集不可だったとき' do
1443 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1444 Story.any_instance.stub(:allow?).and_return(false)
1446 it '403Forbidden例外を返す' do
1449 }.should raise_error(ActiveRecord::Forbidden)
1453 describe '切り詰め処理つき削除に於いて' do
1455 @comic = FactoryGirl.create :comic, :author_id => @author.id
1456 @panel = FactoryGirl.create :panel, :author_id => @author.id
1457 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1459 context 'つつがなく終わるとき' do
1462 @story.destroy_and_shorten
1463 }.should change(Story, :count ).by(-1)
1466 #連携テスト。切り詰めが直接DBをいじる
1467 context '2件で先頭を削除したとき' do
1469 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1473 @story.destroy_and_shorten
1474 }.should change(Story, :count ).by(-1)
1477 @story.destroy_and_shorten
1479 Story.find @story.id
1480 }.should raise_error(ActiveRecord::RecordNotFound)
1483 @story.destroy_and_shorten
1485 @story2.t.should eq 0
1488 context '3件で先頭を削除したとき' do
1490 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1491 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1495 @story.destroy_and_shorten
1496 }.should change(Story, :count ).by(-1)
1499 @story.destroy_and_shorten
1501 Story.find @story.id
1502 }.should raise_error(ActiveRecord::RecordNotFound)
1505 @story.destroy_and_shorten
1507 @story2.t.should eq 0
1510 @story.destroy_and_shorten
1512 @story3.t.should eq 1
1515 context '5件で3件目を削除したとき' do
1517 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1518 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1519 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1520 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1524 @story3.destroy_and_shorten
1525 }.should change(Story, :count ).by(-1)
1528 @story3.destroy_and_shorten
1530 @story.t.should eq 0
1533 @story3.destroy_and_shorten
1535 @story2.t.should eq 1
1538 @story3.destroy_and_shorten
1540 Story.find @story3.id
1541 }.should raise_error(ActiveRecord::RecordNotFound)
1544 @story3.destroy_and_shorten
1546 @story4.t.should eq 2
1549 @story3.destroy_and_shorten
1551 @story5.t.should eq 3
1554 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する