1 # -*- encoding: utf-8 -*-
6 @admin = FactoryGirl.create :admin
7 @sp = FactoryGirl.create :system_picture
8 @lg = FactoryGirl.create :license_group
9 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10 @color = FactoryGirl.create :color
11 @user = FactoryGirl.create( :user_yas)
12 @author = FactoryGirl.create :author, :user_id => @user.id
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14 @other_user = FactoryGirl.create( :user_yas)
15 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
16 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
17 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
18 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
19 @sbt = FactoryGirl.create :speech_balloon_template
24 @comic = FactoryGirl.create :comic, :author_id => @author.id
25 @panel = FactoryGirl.create :panel, :author_id => @author.id
26 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
29 context 'オーソドックスなデータのとき' do
32 @story.should be_valid
36 @story.should be_valid
40 context 'comic_idを検証するとき' do
43 @story.should_not be_valid
47 @story.should_not be_valid
49 it '存在するコミックでなければ失敗する' do
51 @story.should_not be_valid
55 context 'panel_idを検証するとき' do
58 @story.should_not be_valid
62 @story.should_not be_valid
64 it '存在するコマでなければ失敗する' do
66 @story.should_not be_valid
73 @story.should_not be_valid
77 @story.should_not be_valid
81 @story.should_not be_valid
85 context 'author_idを検証するとき' do
87 @story.author_id = nil
88 @story.should_not be_valid
91 @story.author_id = 'a'
92 @story.should_not be_valid
94 it '存在する作家でなければ失敗する' do
96 @story.should_not be_valid
99 context '全体を検証するとき' do
103 describe 'デフォルト値補充に於いて' do
105 @comic = FactoryGirl.create :comic, :author_id => @author.id
106 @panel = FactoryGirl.create :panel, :author_id => @author.id
109 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
111 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
112 @story.supply_default
113 @story.t.should be_nil
118 describe '上書き補充に於いて' do
120 @comic = FactoryGirl.create :comic, :author_id => @author.id
121 @panel = FactoryGirl.create :panel, :author_id => @author.id
124 context 'author_idを補充' do
125 it '問答無用でauthor_idを補充する' do
126 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
127 @story.author_id = nil
128 @story.overwrite @author
129 @story.author_id.should eq @author.id
135 describe '所持判定に於いて' do
137 @comic = FactoryGirl.create :comic, :author_id => @author.id
138 @panel = FactoryGirl.create :panel, :author_id => @author.id
139 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
140 @comico = FactoryGirl.create :comic, :author_id => @other_author.id
141 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
142 @storyo = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @comico.id, :panel_id => @panelo.id
144 it '自分のストーリーならyes' do
145 @story.own?(@author).should == true
148 @storyo.own?(@author).should == false
150 it 'パラメータが作家でないならno' do
151 @story.own?(nil).should == false
155 describe '閲覧許可に於いて' do
157 @comic = FactoryGirl.create :comic, :author_id => @author.id
158 @panel = FactoryGirl.create :panel, :author_id => @author.id
159 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
161 context '検査対象がnil(ゲスト)のとき' do
162 context 'クローズドモードのとき' do
164 MagicNumber['run_mode'] = 1
167 r = @story.visible?(nil)
171 context 'オープンモードのとき' do
173 MagicNumber['run_mode'] = 0
175 it '公開コミックのストーリーなら許可する' do
176 Comic.any_instance.stub(:visible?).with(nil).and_return(true)
177 r = @story.visible?(nil)
180 it '非公開コミックのストーリーなら許可しない' do
181 Comic.any_instance.stub(:visible?).with(nil).and_return(false)
182 r = @story.visible?(nil)
187 context '検査対象が作家のとき' do
188 it '自分のコミックのストーリーなら許可する' do
189 Comic.any_instance.stub(:own?).with(@author).and_return(true)
190 Comic.any_instance.stub(:visible?).with(@author).and_return(true)
191 r = @story.visible?(@author)
194 it '他人の非公開コミックのストーリーなら許可しない' do
195 Comic.any_instance.stub(:own?).with(@other_author).and_return(false)
196 Comic.any_instance.stub(:visible?).with(@other_author).and_return(false)
197 r = @story.visible?(@other_author)
200 it '他人のコミックのストーリーでも公開なら許可する' do
201 Comic.any_instance.stub(:own?).with(@other_author).and_return(false)
202 Comic.any_instance.stub(:visible?).with(@other_author).and_return(true)
203 r = @story.visible?(@other_author)
207 context '検査対象がそれ以外のとき' do
209 r = @story.visible?(@admin)
215 describe 'プレイリスト取得に於いて' do
217 @comic = FactoryGirl.create :comic, :author_id => @author.id
218 @panel = FactoryGirl.create :panel, :author_id => @author.id
219 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
220 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
221 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
222 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
224 context 'offset補正について' do
225 it '文字列から数値に変換される' do
226 Story.offset(100, '8').should eq 8
229 Story.offset(100).should eq 0
231 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
233 it '1件のときオフセット1なら0になる' do
234 Story.offset(1, '1').should eq 0
236 it '5件のときオフセット5なら4になる' do
237 Story.offset(5, '5').should eq 4
239 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
240 #-4のときは、最後から4つのコマを表示する。
241 it '2件のときオフセット-1なら1になる' do
242 Story.offset(2, '-1').should eq 1
244 it '5件のときオフセット-2なら3になる' do
245 Story.offset(5, '-2').should eq 3
247 # 最終的なが負になるなど、不正な値が入ったときは0となる。
248 it '2件のときオフセット-5なら0になる' do
249 Story.offset(2, '-5').should eq 0
252 context 'panel_count補正について' do
253 it '文字列から数値に変換される' do
254 Story.panel_count(100, '7').should eq 7
256 it 'nilの場合はStory.default_panel_sizeになる' do
257 Story.panel_count(100).should eq Story.default_panel_size
259 it '0以下の場合はStory.default_panel_sizeになる' do
260 Story.panel_count(100, '0').should eq Story.default_panel_size
262 it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
263 Story.panel_count(100, '1000').should eq Story.max_panel_size
267 c = Story.play_list @comic, @author
271 #公開コミックの公開コマは(他人のコミックであっても)含んでいる
272 v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
273 c = Story.play_list @comic, @author
274 c.should eq [ @story, v]
277 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
278 c = Story.play_list @comic, @author
279 c.should eq [ @story, h]
281 context 'DBに5件あって1ページの件数を2件に変えたとして' do
283 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
284 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
285 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
286 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
288 it 'offset=0なら末尾2件を返す' do
290 c = Story.play_list( @comic, @author, 0, 2)
291 c.should eq [@story, @story2]
293 it 'offset=2なら中間2件を返す' do
294 c = Story.play_list(@comic, @author, 2, 2)
295 c.should eq [@story3, @story4]
297 it 'offset=4なら先頭1件を返す' do
298 c = Story.play_list(@comic, @author, 4, 2)
299 c.should eq [@story5]
303 describe 'list関連テーブルプションに於いて' do
304 it 'includeキーを含んでいる' do
306 r.has_key?(:include).should be_true
309 r = Story.list_opt[:include]
310 r.should have(3).items
313 r = Story.list_opt[:include]
314 r.has_key?(:comic).should be_true
316 it 'コミックは作家を含んでいる' do
317 r = Story.list_opt[:include]
318 r[:comic].has_key?(:author).should be_true
321 r = Story.list_opt[:include]
322 r.has_key?(:author).should be_true
325 r = Story.list_opt[:include]
326 r.has_key?(:panel).should be_true
329 r = Story.list_opt[:include]
330 r[:panel].has_key?(:author).should be_true
333 r = Story.list_opt[:include]
334 r[:panel].has_key?(:panel_pictures).should be_true
336 it 'コマ絵は実素材を含んでいる' do
337 r = Story.list_opt[:include]
338 r[:panel][:panel_pictures].has_key?(:picture).should be_true
341 r = Story.list_opt[:include]
342 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
344 it '実素材はライセンスを含んでいる' do
345 r = Story.list_opt[:include]
346 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
348 it 'コマはフキダシを含んでいる' do
349 r = Story.list_opt[:include]
350 r[:panel].has_key?(:speech_balloons).should be_true
352 it 'フキダシはフキダシ枠を含んでいる' do
353 r = Story.list_opt[:include]
354 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
356 it 'フキダシはセリフを含んでいる' do
357 r = Story.list_opt[:include]
358 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
361 describe 'json一覧出力オプションに於いて' do
364 describe '一覧取得に於いて' do
366 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
367 @panel = FactoryGirl.create :panel, :author_id => @author.id
368 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
369 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
370 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
371 @hidden_comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
373 context 'page補正について' do
374 it '文字列から数値に変換される' do
375 Story.page('8').should eq 8
378 Story.page().should eq 1
381 Story.page('0').should eq 1
384 context 'page_size補正について' do
385 it '文字列から数値に変換される' do
386 Story.page_size('7').should eq 7
388 it 'nilの場合はStory.default_page_sizeになる' do
389 Story.page_size().should eq Story.default_page_size
391 it '0以下の場合はStory.default_page_sizeになる' do
392 Story.page_size('0').should eq Story.default_page_size
394 it 'Story.max_page_sizeを超えた場合はStory.max_page_sizeになる' do
395 Story.page_size('1000').should eq Story.max_page_size
403 #公開コミックのStoryは(他人のStoryであっても)含んでいる
404 v = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 0, :updated_at => Time.now + 100
406 c.should eq [ v, @story]
408 it '非公開のストーリーは(自分のストーリーであっても)含まない' do
409 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hidden_comic.id, :panel_id => @panel.id, :t => 0
411 c.should eq [ @story]
413 context 'DBに5件あって1ページの件数を2件に変えたとして' do
415 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
416 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
417 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
418 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
422 l.should have(2).items
424 it 'page=1なら末尾2件を返す' do
427 l.should eq [@story5, @story4]
429 it 'page=2なら中間2件を返す' do
431 l.should eq [@story3, @story2]
433 it 'page=3なら先頭1件を返す' do
438 context 'DBに5件あって1ページの件数を2件に変えたとして' do
440 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
441 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
442 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
443 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
444 Story.stub(:default_page_size).and_return(2)
446 it '件数0は全件(5件)を返す' do
448 r.should have(5).items
452 describe '自分のストーリー一覧取得に於いて' do
454 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
455 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
456 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
457 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
458 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
459 @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
460 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
462 context 'つつがなく終わるとき' do
463 it '一覧取得オプションを利用している' do
464 Story.stub(:list_opt).with(any_args).and_return({})
465 Story.should_receive(:list_opt).with(any_args).exactly(1)
466 r = Story.mylist @author
470 s = Story.mylist @author
474 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
475 sl = Story.mylist @author
476 sl.should eq [ns, @story]
478 it '他人のストーリーはコマコミックともに公開でも含まない' do
479 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
480 sl = Story.mylist @author
481 sl.should eq [@story]
483 it '自分のストーリーはコマコミックともに非公開でも含んでいる' do
484 hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
485 sl = Story.mylist @author
486 sl.should eq [hs, @story]
488 context 'DBに5件あって1ページの件数を2件に変えたとして' do
490 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
491 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
492 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
493 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
494 Story.stub(:default_page_size).and_return(2)
497 l = Story.mylist @author, 1, 2
498 l.should have(2).items
500 it 'page=1なら末尾2件を返す' do
502 l = Story.mylist @author, 1, 2
503 l.should eq [@story5, @story4]
505 it 'page=2なら中間2件を返す' do
506 l = Story.mylist @author, 2, 2
507 l.should eq [@story3, @story2]
509 it 'page=3なら先頭1件を返す' do
510 l = Story.mylist @author, 3, 2
514 context 'DBに5件あって1ページの件数を2件に変えたとして' do
516 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
517 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
518 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
519 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
520 Author.stub(:default_story_page_size).and_return(2)
522 it '件数0は全件(5件)を返す' do
523 r = Story.mylist @author, 5, 0
524 r.should have(5).items
529 describe '単体取得に於いて' do
531 @comic = FactoryGirl.create :comic, :author_id => @author.id
532 @panel = FactoryGirl.create :panel, :author_id => @author.id
533 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
535 context 'つつがなく終わるとき' do
536 it '単体取得オプションを利用している' do
537 Story.stub(:show_opt).with(any_args).and_return({})
538 Story.should_receive(:show_opt).with(any_args).exactly(1)
539 r = Story.show @story.id, @author
541 it '閲覧許可を問い合わせている' do
542 Story.any_instance.stub(:visible?).with(@author).and_return(true)
543 Story.any_instance.should_receive(:visible?).with(@author).exactly(1)
544 r = Story.show @story.id, @author
548 l = Story.show @story.id, @author
551 context '他人のストーリーを開こうとしたとき' do
552 it '403Forbidden例外を返す' do
553 Story.any_instance.stub(:visible?).with(@other_author).and_return(false)
555 Story.show @story.id, @other_author
556 }.should raise_error(ActiveRecord::Forbidden)
559 context '存在しないストーリーを開こうとしたとき' do
560 it '404RecordNotFound例外を返す' do
562 Story.show 110, @author
563 }.should raise_error(ActiveRecord::RecordNotFound)
568 describe '編集取得に於いて' do
570 @comic = FactoryGirl.create :comic, :author_id => @author.id
571 @panel = FactoryGirl.create :panel, :author_id => @author.id
572 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
574 context 'つつがなく終わるとき' do
575 it '単体取得オプションを利用している' do
576 Story.stub(:show_opt).with(any_args).and_return({})
577 Story.should_receive(:show_opt).with(any_args).exactly(1)
578 r = Story.edit @story.id, @author
580 it '所持判定を問い合わせている' do
581 Story.any_instance.stub(:own?).with(any_args).and_return(true)
582 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
583 r = Story.edit @story.id, @author
587 l = Story.edit @story.id, @author
590 context '他人のストーリーを開こうとしたとき' do
591 it '403Forbidden例外を返す' do
592 Story.any_instance.stub(:own?).and_return(false)
594 Story.edit @story.id, @author
595 }.should raise_error(ActiveRecord::Forbidden)
598 context '存在しないストーリーを開こうとしたとき' do
599 it '404RecordNotFound例外を返す' do
601 Story.edit 110, @author
602 }.should raise_error(ActiveRecord::RecordNotFound)
607 describe '単体取得オプションに於いて' do
608 it 'includeキーを含んでいる' do
610 r.has_key?(:include).should be_true
613 r = Story.show_opt[:include]
614 r.should have(3).items
617 r = Story.show_opt[:include]
618 r.has_key?(:comic).should be_true
620 it 'コミックは作家を含んでいる' do
621 r = Story.show_opt[:include]
622 r[:comic].has_key?(:author).should be_true
625 r = Story.show_opt[:include]
626 r.has_key?(:author).should be_true
629 r = Story.show_opt[:include]
630 r.has_key?(:panel).should be_true
633 r = Story.show_opt[:include]
634 r[:panel].has_key?(:author).should be_true
637 r = Story.show_opt[:include]
638 r[:panel].has_key?(:panel_pictures).should be_true
640 it 'コマ絵は実素材を含んでいる' do
641 r = Story.show_opt[:include]
642 r[:panel][:panel_pictures].has_key?(:picture).should be_true
645 r = Story.show_opt[:include]
646 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
648 it '実素材はライセンスを含んでいる' do
649 r = Story.show_opt[:include]
650 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
652 it 'コマはフキダシを含んでいる' do
653 r = Story.show_opt[:include]
654 r[:panel].has_key?(:speech_balloons).should be_true
656 it 'フキダシはフキダシ枠を含んでいる' do
657 r = Story.show_opt[:include]
658 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
660 it 'フキダシはセリフを含んでいる' do
661 r = Story.show_opt[:include]
662 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
665 describe 'json単体取得オプションに於いて' do
668 describe 'ストーリーのjson出力に於いて' do
671 @panel = FactoryGirl.create :panel, :author_id => @author.id
672 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
673 @sb = @panel.speech_balloons.create(
674 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
676 @gc = @panel.ground_colors.create(
677 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
679 @gp = @panel.ground_pictures.create(
680 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
682 @pc = @panel.panel_colors.create(
683 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
686 @comic = FactoryGirl.create :comic, :author_id => @author.id
687 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
689 context '事前チェックする' do
691 Panel.any_instance.stub(:elements).and_return('{}')
693 it 'コマ要素のjson出力を依頼している' do
694 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
695 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
696 r = @story.story_as_json @author
699 it 'json textを返している' do
700 r = JSON.parse @story.story_as_json(@author)
701 r.is_a?(Hash).should be_true
703 it 'comic,author,panel,コマ要素を含んでいる' do
704 r = JSON.parse @story.story_as_json(@author)
705 r.has_key?('comic').should be_true
706 r['comic'].has_key?('author').should be_true
707 r.has_key?('author').should be_true
708 r.has_key?('panel').should be_true
709 r['panel'].has_key?('author').should be_true
711 context 'コマ閲覧許可のとき' do
713 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
715 it 'コマ要素にコマ要素を追加している' do
716 r = JSON.parse @story.story_as_json(@author)
717 r['panel'].has_key?('elements').should be_true
718 r['panel']['elements'].should_not be_empty
721 context 'コマ閲覧不許可のとき' do
723 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
725 it 'コマ要素にデータを含ませない' do
726 r = JSON.parse @story.story_as_json(@author)
727 r['panel'].has_key?('elements').should be_false
732 describe 'ストーリーリストのjson出力に於いて' do
734 @panel = FactoryGirl.create :panel, :author_id => @author.id
735 @comic = FactoryGirl.create :comic, :author_id => @author.id
736 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
737 Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
739 context 'つつがなく終わるとき' do
740 it 'ストーリーのjson出力を依頼している' do
741 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
742 r = Story.list_as_json_text [@story], @author
745 it 'json textを返している' do
746 r = Story.list_as_json_text [@story], @author
748 j.is_a?(Array).should be_true
751 r = Story.list_as_json_text [@story], @author
753 j.first.has_key?('s').should be_true
757 describe 'ライセンス素材に於いて' do
760 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
761 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
762 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
763 @panel = FactoryGirl.create :panel, :author_id => @author.id
764 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id
766 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
767 @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id
770 @comic = FactoryGirl.create :comic, :author_id => @author.id
771 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
772 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id
776 context 'つつがなく終わるとき' do
778 it '連想配列(値は実素材、キーは実素材id)を返している' do
779 r = Story.licensed_pictures [@story, @story2]
780 r.is_a?(Hash).should be_true
781 r.should have(2).items
782 r[@pp.picture_id].should eq @p
783 r[@pp2.picture_id].should eq @p2
785 context 'コマが削除されているときき' do
789 it '削除されているコマは無視する' do
790 r = Story.licensed_pictures [@story, @story2]
791 r.is_a?(Hash).should be_true
792 r.should have(1).items
793 r[@pp.picture_id].should eq @p
794 r[@pp2.picture_id].should be_nil
799 describe 't補充値に於いて' do
801 @comic = FactoryGirl.create :comic, :author_id => @author.id
802 @panel = FactoryGirl.create :panel, :author_id => @author.id
805 context 'コミック初のコマなら' do
807 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
809 r = Story.new_t @story.comic_id
813 context 'コミックに一個コマがあるとき' do
815 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
816 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
818 r = Story.new_t @story.comic_id
822 context 'コミックに2個コマがあるとき' do
824 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
825 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
826 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
828 r = Story.new_t @story.comic_id
833 describe 'シリアライズチェックに於いて' do
834 context 'つつがなく終わるとき' do
835 it '0からシリアライズされているならTrueを返す' do
836 r = Story.serial? [0, 1, 2]
839 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
840 r = Story.serial? [0, 2, 1]
843 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
844 r = Story.serial? [ 2, 1, 4, 3, 0]
849 it '0から始まらないならFalseを返す' do
850 r = Story.serial? [1, 2, 3]
853 it '連続していないならFalseを返す' do
854 r = Story.serial? [0, 1, 2, 4]
857 it '連続していないならFalseを返す' do
858 r = Story.serial? [0, 1, 2, 4, 5]
863 describe 't収集に於いて' do
865 @comic = FactoryGirl.create :comic, :author_id => @author.id
866 @panel = FactoryGirl.create :panel, :author_id => @author.id
867 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
868 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
869 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
871 context 'つつがなく終わるとき' do
872 it 'ストーリーから同一コミックのtだけを収集している' do
873 r = Story.collect_t @story
878 it 'ストーリーから同一コミックのtだけを収集している' do
879 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
880 r = Story.collect_t @story
881 r.sort.should eq [0, 1]
884 context '複数コマでヨソのコミックも混じっているとき' do
885 it 'ストーリーから同一コミックのtだけを収集している' do
886 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
887 r = Story.collect_t @story
888 r.sort.should eq [0, 1]
892 describe 'tチェックに於いて' do
894 @comic = FactoryGirl.create :comic, :author_id => @author.id
895 @panel = FactoryGirl.create :panel, :author_id => @author.id
896 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
898 context 'つつがなく終わるとき' do
900 Story.should_receive(:collect_t).with(any_args).exactly(1)
901 Story.stub(:collect_t).with(any_args).and_return([])
902 Story.stub(:serial?).with(any_args).and_return(true)
903 r = Story.validate_t @story
905 it '収集したtをシリアライズチェック依頼している' do
906 Story.stub(:collect_t).with(any_args).and_return([])
907 Story.should_receive(:serial?).with(any_args).exactly(1)
908 Story.stub(:serial?).with(any_args).and_return(true)
909 r = Story.validate_t @story
913 #依頼チェックだけでは不安なので最低限のチェックを
915 it '一件だけで正常通過している' do
916 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
917 r = Story.validate_t @story
922 it '2件目を作っても正常通過している' do
923 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
924 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
925 r = Story.validate_t @story2
930 describe '挿入シフトに於いて' do
932 @comic = FactoryGirl.create :comic, :author_id => @author.id
933 @panel = FactoryGirl.create :panel, :author_id => @author.id
937 it 'Updateを依頼している' do
938 Story.stub(:update_all).with(any_args)
939 Story.should_receive(:update_all).with(any_args).exactly(1)
940 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
944 context 'テーブルに1件(t:0)で0に挿入したとき' do
946 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
947 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
949 it '既存の行を1にシフトしている' do
952 l.first.t.should eq 1
954 it 'これから挿入するt(0)が欠番になっている' do
956 l = Story.find(:all).map {|s| s.t }
957 l.include?(0).should_not be_true
960 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
962 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
963 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
964 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
966 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
968 l = Story.find(:all).map {|s| s.t }
969 l.sort.should eq [0, 2]
972 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' 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
977 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
978 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
979 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
981 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
983 l = Story.find(:all).map {|s| s.t }
984 l.sort.should eq [0, 1, 3, 4, 5]
987 context '先ほどのケース+他のコミック1件で挿入したとき' do
989 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
990 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
991 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
992 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
993 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
994 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
995 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
996 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
998 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1000 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
1001 l.sort.should eq [0, 1, 3, 4, 5]
1003 it '他のコミックに影響がない' do
1005 @story6.insert_shift
1007 @storyc2.t.should eq ot
1011 describe '少ない方に移動に於いて' do
1013 @comic = FactoryGirl.create :comic, :author_id => @author.id
1014 @panel = FactoryGirl.create :panel, :author_id => @author.id
1017 it 'Updateを依頼している' do
1018 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1019 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1020 Story.stub(:update_all).with(any_args)
1021 Story.should_receive(:update_all).with(any_args).exactly(1)
1024 @story2.lesser_shift ot
1027 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
1029 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1030 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1034 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1036 @story2.lesser_shift @ot
1037 l = Story.find(:all).map {|s| s.t }
1038 l.sort.should eq [1, 1]
1040 it '既存のt0を1にシフトしている' do
1041 @story2.lesser_shift @ot
1043 @story.t.should eq 1
1046 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
1048 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1049 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1050 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1054 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1056 @story3.lesser_shift @ot
1057 l = Story.find(:all).map {|s| s.t }
1058 l.sort.should eq [0, 2, 2]
1060 it '既存のt1を2にシフトしている' do
1061 @story3.lesser_shift @ot
1063 @story2.t.should eq 2
1066 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
1068 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1069 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1070 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1071 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1072 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1076 it 'これから挿入するt(1)が欠番になっている' do
1078 @story4.lesser_shift @ot
1079 l = Story.find(:all).map {|s| s.t }
1080 l.sort.should eq [0, 2, 3, 3, 4]
1082 it '既存のt0には変化がない' do
1083 @story4.lesser_shift @ot
1085 @story.t.should eq 0
1087 it '既存のt4には変化がない' do
1088 @story4.lesser_shift @ot
1090 @story5.t.should eq 4
1092 it '既存のt1を2にシフトしている' do
1093 @story4.lesser_shift @ot
1095 @story2.t.should eq 2
1097 it '既存のt2を3にシフトしている' do
1098 @story4.lesser_shift @ot
1100 @story3.t.should eq 3
1103 context '先ほどのケース+他のコミック1件で挿入したとき' do
1105 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1106 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1107 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1108 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1109 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1110 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1111 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1115 it 'これから挿入するt(1)が欠番になっている' do
1116 @story4.lesser_shift @ot
1117 l = Story.find(:all).map {|s| s.t }
1118 l.sort.should eq [0, 0, 2, 3, 3, 4]
1120 it '既存のt0には変化がない' do
1121 @story4.lesser_shift @ot
1123 @story.t.should eq 0
1125 it '既存のt4には変化がない' do
1126 @story4.lesser_shift @ot
1128 @story5.t.should eq 4
1130 it '既存のt1を2にシフトしている' do
1131 @story4.lesser_shift @ot
1133 @story2.t.should eq 2
1135 it '既存のt2を3にシフトしている' do
1136 @story4.lesser_shift @ot
1138 @story3.t.should eq 3
1140 it '他のコミックに影響がない' do
1141 @story4.lesser_shift @ot
1143 @storyc2.t.should eq 0
1148 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' 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
1155 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1157 @story2.lesser_shift @ot
1158 l = Story.find(:all).map {|s| s.t }
1159 l.sort.should eq [1, 1]
1161 it '既存のt0を1にシフトしている' do
1162 @story2.lesser_shift @ot
1164 @story.t.should eq 1
1166 it '既存のt1は0に補正されている' do
1167 @story2.lesser_shift @ot
1168 @story2.t.should eq 0
1172 describe '大きい方に移動に於いて' do
1174 @comic = FactoryGirl.create :comic, :author_id => @author.id
1175 @panel = FactoryGirl.create :panel, :author_id => @author.id
1178 it 'Updateを依頼している' do
1179 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1180 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1181 Story.stub(:update_all).with(any_args)
1182 Story.should_receive(:update_all).with(any_args).exactly(1)
1185 @story.higher_shift ot
1188 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1190 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1191 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1195 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1197 @story.higher_shift @ot
1198 l = Story.find(:all).map {|s| s.t }
1199 l.sort.should eq [0, 0]
1201 it '既存のt1を0にシフトしている' do
1202 @story.higher_shift @ot
1204 @story2.t.should eq 0
1207 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1209 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1210 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1211 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1215 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1217 @story.higher_shift @ot
1218 l = Story.find(:all).map {|s| s.t }
1219 l.sort.should eq [0, 0, 2]
1221 it '既存のt1を0にシフトしている' do
1222 @story.higher_shift @ot
1224 @story2.t.should eq 0
1227 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1229 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1230 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1231 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1232 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1233 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1237 it 'これから挿入するt(3)が欠番になっている' do
1239 @story2.higher_shift @ot
1240 l = Story.find(:all).map {|s| s.t }
1241 l.sort.should eq [0, 1, 1, 2, 4]
1243 it '既存のt0には変化がない' do
1244 @story2.higher_shift @ot
1246 @story.t.should eq 0
1248 it '既存のt4には変化がない' do
1249 @story2.higher_shift @ot
1251 @story5.t.should eq 4
1253 it '既存のt2を1にシフトしている' do
1254 @story2.higher_shift @ot
1256 @story3.t.should eq 1
1258 it '既存のt3を2にシフトしている' do
1259 @story2.higher_shift @ot
1261 @story4.t.should eq 2
1264 context '先ほどのケース+他のコミック1件で挿入したとき' do
1266 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1267 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1268 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1269 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1270 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1271 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1272 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1276 it 'これから挿入するt(3)が欠番になっている' do
1278 @story2.higher_shift @ot
1279 l = Story.find(:all).map {|s| s.t }
1280 l.sort.should eq [0, 0, 1, 1, 2, 4]
1282 it '既存のt0には変化がない' do
1283 @story2.higher_shift @ot
1285 @story.t.should eq 0
1287 it '既存のt4には変化がない' do
1288 @story2.higher_shift @ot
1290 @story5.t.should eq 4
1292 it '既存のt2を1にシフトしている' do
1293 @story2.higher_shift @ot
1295 @story3.t.should eq 1
1297 it '既存のt3を2にシフトしている' do
1298 @story2.higher_shift @ot
1300 @story4.t.should eq 2
1302 it '他のコミックに影響がない' do
1303 @story2.higher_shift @ot
1305 @storyc2.t.should eq 0
1309 #max超えたときはmaxとして正常扱い
1310 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1312 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1313 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1317 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1319 @story.higher_shift @ot
1320 l = Story.find(:all).map {|s| s.t }
1321 l.sort.should eq [0, 0]
1323 it '既存のt1を0にシフトしている' do
1324 @story.higher_shift @ot
1326 @story2.t.should eq 0
1328 it '既存のt0は1に補正されている' do
1329 @story.higher_shift @ot
1330 @story.t.should eq 1
1334 describe '入れ替えに於いて' do
1336 @comic = FactoryGirl.create :comic, :author_id => @author.id
1337 @panel = FactoryGirl.create :panel, :author_id => @author.id
1338 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1339 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1341 context '新tが旧tより小さいとき' do
1342 it '少ない方に移動を依頼している' do
1343 Story.any_instance.stub(:lesser_shift).with(any_args)
1344 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1347 @story2.update_shift ot
1350 context '新tが旧tより大きいとき' do
1351 it '大きい方に移動を依頼している' do
1352 Story.any_instance.stub(:higher_shift).with(any_args)
1353 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1356 @story.update_shift ot
1360 describe '順序入れ替えに於いて' do
1362 @comic = FactoryGirl.create :comic, :author_id => @author.id
1363 @panel = FactoryGirl.create :panel, :author_id => @author.id
1365 context 'オブジェクトが新規でtが空のとき' do
1366 it '末尾追加としてtを補充依頼している' do
1367 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1368 Story.stub(:new_t).with(any_args).and_return(0)
1369 Story.should_receive(:new_t).with(any_args).exactly(1)
1374 context 'オブジェクトが新規でtが設定されているとき' do
1375 it '挿入追加として挿入シフトを依頼している' do
1376 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1377 Story.any_instance.stub(:insert_shift).with(any_args)
1378 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1383 context 'オブジェクトが新規でなくtが設定されているとき' do
1384 it 'コマ移動として入れ替えを依頼している' do
1385 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1386 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1387 Story.any_instance.stub(:update_shift).with(any_args)
1388 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1393 context 'オブジェクトが新規でなくtが空のとき' do
1394 it '入れ替えもシフトもせず、tを空のままにしている' do
1395 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1399 describe '編集許可に於いて' do
1401 @comic = FactoryGirl.create :comic, :author_id => @author.id
1402 @panel = FactoryGirl.create :panel, :author_id => @author.id
1403 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1405 context 'つつがなく終わるとき' do
1411 context 'コミックで引っかかるとき' do
1413 @story.comic_id = nil
1418 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1423 context 'コマで引っかかるとき' do
1425 @story.panel_id = nil
1430 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1436 describe '保存に於いて' do
1438 @comic = FactoryGirl.create :comic, :author_id => @author.id
1439 @panel = FactoryGirl.create :panel, :author_id => @author.id
1440 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1442 context 'つつがなく終わるとき' do
1443 it '編集許可チェックを依頼している' do
1444 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1445 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1448 it '順序入れ替えを依頼している' do
1449 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1450 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1451 Story.any_instance.stub(:save).with(any_args).and_return(true)
1452 Story.stub(:validate_t).with(any_args).and_return(true)
1456 Story.stub(:new_t).with(any_args).and_return(0)
1457 Story.any_instance.stub(:save).with(any_args).and_return(true)
1458 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1459 Story.stub(:validate_t).with(any_args).and_return(true)
1462 it 'tのシリアライズチェックを依頼している' do
1463 Story.stub(:new_t).with(any_args).and_return(0)
1464 Story.any_instance.stub(:save).with(any_args).and_return(true)
1465 Story.stub(:validate_t).with(any_args).and_return(true)
1466 Story.should_receive(:validate_t).with(any_args).exactly(1)
1470 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1471 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1473 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1474 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1475 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1476 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1477 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1478 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1479 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1480 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1482 it '既存のt0には変化がない' do
1485 @story.t.should eq 0
1487 it '既存のt1には変化がない' do
1490 @story2.t.should eq 1
1492 it '既存のt2を3にシフトしている' do
1495 @story3.t.should eq 3
1497 it '既存のt3を4にシフトしている' do
1500 @story4.t.should eq 4
1502 it '既存のt5を5にシフトしている' do
1505 @story5.t.should eq 5
1507 it '新規のt2が作成されている' do
1510 @story6.t.should eq 2
1512 it '他のコミックに影響がない' do
1516 @storyc2.t.should eq @ot
1519 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1521 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1522 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1523 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1524 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1525 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1526 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1527 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1531 it '既存のt0には変化がない' do
1534 @story.t.should eq 0
1536 it '既存のt4には変化がない' do
1539 @story5.t.should eq 4
1541 it '既存のt1を2にシフトしている' do
1544 @story2.t.should eq 2
1546 it '既存のt2を3にシフトしている' do
1549 @story3.t.should eq 3
1551 it '既存のt3を1にシフトしている' do
1554 @story4.t.should eq 1
1556 it '他のコミックに影響がない' do
1559 @storyc2.t.should eq 0
1562 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1564 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1565 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1566 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1567 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1568 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1569 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1570 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1574 it '既存のt0には変化がない' do
1577 @story.t.should eq 0
1579 it '既存のt4には変化がない' do
1582 @story5.t.should eq 4
1584 it '既存のt1を3にシフトしている' do
1587 @story2.t.should eq 3
1589 it '既存のt2を1にシフトしている' do
1592 @story3.t.should eq 1
1594 it '既存のt3を2にシフトしている' do
1597 @story4.t.should eq 2
1599 it '他のコミックに影響がない' do
1602 @storyc2.t.should eq 0
1605 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1606 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1608 Story.any_instance.stub(:save).with(any_args).and_return(false)
1609 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1610 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1611 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1612 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1613 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1614 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1615 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1616 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1621 @story.t.should eq 0
1623 @story2.t.should eq 1
1625 @story3.t.should eq 2
1627 @story4.t.should eq 3
1629 @story5.t.should eq 4
1631 @storyc2.t.should eq 0
1638 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1640 Story.stub(:validate_t).with(any_args).and_return(false)
1641 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1642 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1643 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1644 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1645 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1646 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1647 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1654 @story.t.should eq 0
1656 @story2.t.should eq 1
1658 @story3.t.should eq 2
1660 @story4.t.should eq 3
1662 @story5.t.should eq 4
1664 @storyc2.t.should eq 0
1667 r = @story4.store @ot
1670 it 'tにエラーメッセージが入っている' do
1672 @story4.errors[:t].should_not be_empty
1673 @story4.valid?.should be_true
1676 context '編集不可だったとき' do
1678 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1679 Story.any_instance.stub(:allow?).and_return(false)
1681 it '403Forbidden例外を返す' do
1684 }.should raise_error(ActiveRecord::Forbidden)
1688 describe '切り詰め処理つき削除に於いて' do
1690 @comic = FactoryGirl.create :comic, :author_id => @author.id
1691 @panel = FactoryGirl.create :panel, :author_id => @author.id
1692 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1694 context 'つつがなく終わるとき' do
1697 @story.destroy_and_shorten
1698 }.should change(Story, :count ).by(-1)
1701 r = @story.destroy_and_shorten
1705 context '削除に失敗したとき' do
1707 Story.any_instance.stub(:destroy).and_return(false)
1711 @story.destroy_and_shorten
1712 }.should_not change(Story, :count )
1715 r = @story.destroy_and_shorten
1719 #連携テスト。切り詰めが直接DBをいじる
1720 context '2件で先頭を削除したとき' do
1722 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1726 @story.destroy_and_shorten
1727 }.should change(Story, :count ).by(-1)
1730 @story.destroy_and_shorten
1732 Story.find @story.id
1733 }.should raise_error(ActiveRecord::RecordNotFound)
1736 @story.destroy_and_shorten
1738 @story2.t.should eq 0
1741 context '3件で先頭を削除したとき' do
1743 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1744 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1748 @story.destroy_and_shorten
1749 }.should change(Story, :count ).by(-1)
1752 @story.destroy_and_shorten
1754 Story.find @story.id
1755 }.should raise_error(ActiveRecord::RecordNotFound)
1758 @story.destroy_and_shorten
1760 @story2.t.should eq 0
1763 @story.destroy_and_shorten
1765 @story3.t.should eq 1
1768 context '5件で3件目を削除したとき' do
1770 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1771 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1772 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1773 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1777 @story3.destroy_and_shorten
1778 }.should change(Story, :count ).by(-1)
1781 @story3.destroy_and_shorten
1783 @story.t.should eq 0
1786 @story3.destroy_and_shorten
1788 @story2.t.should eq 1
1791 @story3.destroy_and_shorten
1793 Story.find @story3.id
1794 }.should raise_error(ActiveRecord::RecordNotFound)
1797 @story3.destroy_and_shorten
1799 @story4.t.should eq 2
1802 @story3.destroy_and_shorten
1804 @story5.t.should eq 3
1807 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する