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 @user = FactoryGirl.create( :user_yas)
11 @author = FactoryGirl.create :author, :user_id => @user.id
12 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
13 @other_user = FactoryGirl.create( :user_yas)
14 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
15 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
16 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
17 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
18 @sbt = FactoryGirl.create :speech_balloon_template
23 @comic = FactoryGirl.create :comic, :author_id => @author.id
24 @panel = FactoryGirl.create :panel, :author_id => @author.id
25 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
28 context 'オーソドックスなデータのとき' do
31 @story.should be_valid
35 @story.should be_valid
39 context 'comic_idを検証するとき' do
42 @story.should_not be_valid
46 @story.should_not be_valid
48 it '存在するコミックでなければ失敗する' do
50 @story.should_not be_valid
54 context 'panel_idを検証するとき' do
57 @story.should_not be_valid
61 @story.should_not be_valid
63 it '存在するコマでなければ失敗する' do
65 @story.should_not be_valid
72 @story.should_not be_valid
76 @story.should_not be_valid
80 @story.should_not be_valid
84 context 'author_idを検証するとき' do
86 @story.author_id = nil
87 @story.should_not be_valid
90 @story.author_id = 'a'
91 @story.should_not be_valid
93 it '存在する作家でなければ失敗する' do
95 @story.should_not be_valid
98 context '全体を検証するとき' do
102 describe 'デフォルト値補充に於いて' do
104 @comic = FactoryGirl.create :comic, :author_id => @author.id
105 @panel = FactoryGirl.create :panel, :author_id => @author.id
108 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
110 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
111 @story.supply_default
112 @story.t.should be_nil
117 describe '上書き補充に於いて' do
119 @comic = FactoryGirl.create :comic, :author_id => @author.id
120 @panel = FactoryGirl.create :panel, :author_id => @author.id
123 context 'author_idを補充' do
124 it '問答無用でauthor_idを補充する' do
125 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id
126 @story.author_id = nil
127 @story.overwrite @author
128 @story.author_id.should eq @author.id
134 describe '所持判定に於いて' do
136 @comic = FactoryGirl.create :comic, :author_id => @author.id
137 @panel = FactoryGirl.create :panel, :author_id => @author.id
138 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
139 @comico = FactoryGirl.create :comic, :author_id => @other_author.id
140 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
141 @storyo = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @comico.id, :panel_id => @panelo.id
143 context '事前チェックする' do
144 it '自身にロールリストからの作家取得を依頼している' do
145 Story.should_receive(:get_author_from_roles).with(any_args).exactly(1)
146 r = @story.own?([@author])
149 context 'ロール内作家が取得できるとき' do
152 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
153 Story.stub(:get_author_from_roles).with(any_args).and_return(@author)
154 r = @story.own?([@author])
157 it 'ロール内作家のidが自身の作家idと一致しないならno' do
158 Story.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
159 @story.own?(@other_author).should be_false
162 context 'ロール内作家が取得できないとき' do
164 Story.stub(:get_author_from_roles).with(any_args).and_return(nil)
167 r = @story.own?([@author])
173 describe '閲覧許可に於いて' do
175 @comic = FactoryGirl.create :comic, :author_id => @author.id
176 @panel = FactoryGirl.create :panel, :author_id => @author.id
177 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
179 context 'オープンモードのとき' do
181 MagicNumber['run_mode'] = 0
183 it '自身にゲスト用ロールチェックを問い合わせしている' do
184 Story.any_instance.stub(:guest_role_check).and_return(true)
185 Story.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
186 r = @story.visible?([@author])
188 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
189 Story.any_instance.stub(:guest_role_check).and_return(false)
190 r = @story.visible?([@author])
194 context 'クローズドモードのとき' do
196 MagicNumber['run_mode'] = 1
198 it '自身に読者用ロールチェックを問い合わせしている' do
199 Story.any_instance.stub(:reader_role_check).and_return(true)
200 Story.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
201 r = @story.visible?([@author])
203 it '読者用ロールチェックが失敗したとき、falseを返す' do
204 Story.any_instance.stub(:reader_role_check).and_return(false)
205 r = @story.visible?([@author])
209 context '事前チェックする' do
211 MagicNumber['run_mode'] = 1
212 Story.any_instance.stub(:reader_role_check).and_return(true)
214 it '自身のコミックに所持判定を問い合わせしている' do
215 Comic.any_instance.stub(:own?).and_return(true)
216 Comic.any_instance.should_receive(:own?).with(any_args).exactly(1)
217 r = @story.visible?([@author])
219 it '自身のコミックに閲覧許可を問い合わせしている' do
220 Comic.any_instance.stub(:own?).and_return(false)
221 Comic.any_instance.stub(:visible?).and_return(true)
222 Comic.any_instance.should_receive(:visible?).with(any_args).exactly(1)
223 r = @story.visible?([@author])
226 context 'つつがなく終わるとき' do
228 MagicNumber['run_mode'] = 1
229 Story.any_instance.stub(:reader_role_check).and_return(true)
231 it '自分のコミックのストーリーなら許可する' do
232 Comic.any_instance.stub(:own?).and_return(true)
233 Comic.any_instance.stub(:visible).and_return(0)
234 r = @story.visible?([@author])
237 it '他人の非公開コミックのストーリーなら許可しない' do
238 Comic.any_instance.stub(:own?).and_return(false)
239 Comic.any_instance.stub(:visible).and_return(0)
240 r = @story.visible?([@author])
243 it '他人のコミックのストーリーでも公開なら許可する' do
244 Comic.any_instance.stub(:own?).and_return(false)
245 Comic.any_instance.stub(:visible).and_return(1)
246 r = @story.visible?([@author])
252 describe 'プレイリスト取得に於いて' do
254 @comic = FactoryGirl.create :comic, :author_id => @author.id
255 @panel = FactoryGirl.create :panel, :author_id => @author.id
256 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
257 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
258 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
259 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
261 context 'offset補正について' do
262 it '文字列から数値に変換される' do
263 Story.offset(100, '8').should eq 8
266 Story.offset(100).should eq 0
268 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
270 it '1件のときオフセット1なら0になる' do
271 Story.offset(1, '1').should eq 0
273 it '5件のときオフセット5なら4になる' do
274 Story.offset(5, '5').should eq 4
276 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
277 #-4のときは、最後から4つのコマを表示する。
278 it '2件のときオフセット-1なら1になる' do
279 Story.offset(2, '-1').should eq 1
281 it '5件のときオフセット-2なら3になる' do
282 Story.offset(5, '-2').should eq 3
284 # 最終的なが負になるなど、不正な値が入ったときは0となる。
285 it '2件のときオフセット-5なら0になる' do
286 Story.offset(2, '-5').should eq 0
289 context 'panel_count補正について' do
290 it '文字列から数値に変換される' do
291 Story.panel_count(100, '7').should eq 7
293 it 'nilの場合はStory.default_panel_sizeになる' do
294 Story.panel_count(100).should eq Story.default_panel_size
296 it '0以下の場合はStory.default_panel_sizeになる' do
297 Story.panel_count(100, '0').should eq Story.default_panel_size
299 it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
300 Story.panel_count(100, '1000').should eq Story.max_panel_size
304 c = Story.play_list @comic, @author
308 #公開コミックの公開コマは(他人のコミックであっても)含んでいる
309 v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
310 c = Story.play_list @comic, @author
311 c.should eq [ @story, v]
314 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
315 c = Story.play_list @comic, @author
316 c.should eq [ @story, h]
318 context 'DBに5件あって1ページの件数を2件に変えたとして' do
320 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
321 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
322 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
323 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
325 it 'offset=0なら末尾2件を返す' do
327 c = Story.play_list( @comic, @author, 0, 2)
328 c.should eq [@story, @story2]
330 it 'offset=2なら中間2件を返す' do
331 c = Story.play_list(@comic, @author, 2, 2)
332 c.should eq [@story3, @story4]
334 it 'offset=4なら先頭1件を返す' do
335 c = Story.play_list(@comic, @author, 4, 2)
336 c.should eq [@story5]
341 describe '一覧取得に於いて' do
343 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
344 @panel = FactoryGirl.create :panel, :author_id => @author.id
345 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
346 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
347 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
348 @hidden_comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
350 context 'page補正について' do
351 it '文字列から数値に変換される' do
352 Story.page('8').should eq 8
355 Story.page().should eq 1
358 Story.page('0').should eq 1
361 context 'page_size補正について' do
362 it '文字列から数値に変換される' do
363 Story.page_size('7').should eq 7
365 it 'nilの場合はStory.default_page_sizeになる' do
366 Story.page_size().should eq Story.default_page_size
368 it '0以下の場合はStory.default_page_sizeになる' do
369 Story.page_size('0').should eq Story.default_page_size
371 it 'Story.max_page_sizeを超えた場合はStory.max_page_sizeになる' do
372 Story.page_size('1000').should eq Story.max_page_size
380 #公開コミックのStoryは(他人のStoryであっても)含んでいる
381 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
383 c.should eq [ v, @story]
385 it '非公開のストーリーは(自分のストーリーであっても)含まない' do
386 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hidden_comic.id, :panel_id => @panel.id, :t => 0
388 c.should eq [ @story]
390 context 'DBに5件あって1ページの件数を2件に変えたとして' do
392 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
393 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
394 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
395 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
399 l.should have(2).items
401 it 'page=1なら末尾2件を返す' do
404 l.should eq [@story5, @story4]
406 it 'page=2なら中間2件を返す' do
408 l.should eq [@story3, @story2]
410 it 'page=3なら先頭1件を返す' do
417 describe '自分のストーリー一覧取得に於いて' do
419 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
420 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
421 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
422 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
423 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
424 @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
425 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
427 context 'つつがなく終わるとき' do
428 it '一覧取得オプションを利用している' do
429 Story.stub(:list_opt).with(any_args).and_return({})
430 Story.should_receive(:list_opt).with(any_args).exactly(1)
431 r = Story.mylist @author
435 s = Story.mylist @author
439 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
440 sl = Story.mylist @author
441 sl.should eq [ns, @story]
443 it '他人のストーリーはコマコミックともに公開でも含まない' do
444 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
445 sl = Story.mylist @author
446 sl.should eq [@story]
448 it '自分のストーリーはコマコミックともに非公開でも含んでいる' do
449 hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
450 sl = Story.mylist @author
451 sl.should eq [hs, @story]
453 context 'DBに5件あって1ページの件数を2件に変えたとして' do
455 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
456 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
457 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
458 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
459 Story.stub(:default_page_size).and_return(2)
462 l = Story.mylist @author, 1, 2
463 l.should have(2).items
465 it 'page=1なら末尾2件を返す' do
467 l = Story.mylist @author, 1, 2
468 l.should eq [@story5, @story4]
470 it 'page=2なら中間2件を返す' do
471 l = Story.mylist @author, 2, 2
472 l.should eq [@story3, @story2]
474 it 'page=3なら先頭1件を返す' do
475 l = Story.mylist @author, 3, 2
481 describe '他作家のストーリー一覧取得に於いて' do
483 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
484 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
485 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
486 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
487 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
488 @other_story = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
491 r = Story.himlist @other_author
492 r.should eq [@other_story]
495 ns = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
496 r = Story.himlist @other_author
497 r.should eq [ns, @other_story]
500 @hcomic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 0
501 ns = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @hcomic.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
502 r = Story.himlist @other_author
503 r.should eq [@other_story]
505 context 'DBに5件あって1ページの件数を2件に変えたとして' do
507 @other_story2 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
508 @other_story3 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 2, :updated_at => Time.now + 200
509 @other_story4 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 3, :updated_at => Time.now + 300
510 @other_story5 = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id, :t => 4, :updated_at => Time.now + 400
511 Story.stub(:default_page_size).and_return(2)
514 l = Story.himlist @other_author, 1, 2
515 l.should have(2).items
517 it 'page=1なら末尾2件を返す' do
519 l = Story.himlist @other_author, 1, 2
520 l.should eq [@other_story5, @other_story4]
522 it 'page=2なら中間2件を返す' do
523 l = Story.himlist @other_author, 2, 2
524 l.should eq [@other_story3, @other_story2]
526 it 'page=3なら先頭1件を返す' do
527 l = Story.himlist @other_author, 3, 2
528 l.should eq [@other_story]
533 describe 'ストーリー一覧ページ制御に於いて' do
535 Story.stub(:count).with(any_args).and_return(100)
538 r = Story.list_paginate
539 r.is_a?(Kaminari::PaginatableArray).should be_true
541 it 'ストーリー一覧の取得条件を利用している' do
542 Story.stub(:list_where).with(any_args).and_return('')
543 Story.should_receive(:list_where).with(any_args).exactly(1)
544 r = Story.list_paginate
546 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
547 r = Story.list_paginate 3, 10
548 r.limit_value.should eq 10
549 r.offset_value.should eq 20
553 describe '自分のストーリー一覧ページ制御に於いて' do
555 Story.stub(:count).with(any_args).and_return(100)
558 r = Story.mylist_paginate @author
559 r.is_a?(Kaminari::PaginatableArray).should be_true
561 it '自分のストーリー一覧の取得条件を利用している' do
562 Story.stub(:mylist_where).with(any_args).and_return('')
563 Story.should_receive(:mylist_where).with(any_args).exactly(1)
564 r = Story.mylist_paginate @author
566 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
567 r = Story.mylist_paginate @author, 3, 10
568 r.limit_value.should eq 10
569 r.offset_value.should eq 20
573 describe '他作家のストーリー一覧ページ制御に於いて' do
575 Story.stub(:count).with(any_args).and_return(100)
578 r = Story.himlist_paginate @other_author
579 r.is_a?(Kaminari::PaginatableArray).should be_true
581 it '他作家のストーリー一覧の取得条件を利用している' do
582 Story.stub(:himlist_where).with(any_args).and_return('')
583 Story.should_receive(:himlist_where).with(any_args).exactly(1)
584 r = Story.himlist_paginate @other_author
586 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
587 r = Story.himlist_paginate @other_author, 3, 10
588 r.limit_value.should eq 10
589 r.offset_value.should eq 20
593 describe 'list関連テーブルプションに於いて' do
596 r.should have(3).items
600 r.has_key?(:comic).should be_true
602 it 'コミックは作家を含んでいる' do
604 r[:comic].has_key?(:author).should be_true
608 r.has_key?(:author).should be_true
612 r.has_key?(:panel).should be_true
616 r[:panel].has_key?(:author).should be_true
620 r[:panel].has_key?(:panel_pictures).should be_true
622 it 'コマ絵は実素材を含んでいる' do
624 r[:panel][:panel_pictures].has_key?(:picture).should be_true
628 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
630 it '実素材はライセンスを含んでいる' do
632 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
634 it 'コマはフキダシを含んでいる' do
636 r[:panel].has_key?(:speech_balloons).should be_true
638 it 'フキダシはフキダシ枠を含んでいる' do
640 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
642 it 'フキダシはセリフを含んでいる' do
644 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
647 describe 'json一覧出力オプションに於いて' do
650 describe '単体取得に於いて' do
652 @comic = FactoryGirl.create :comic, :author_id => @author.id
653 @panel = FactoryGirl.create :panel, :author_id => @author.id
654 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
656 context 'つつがなく終わるとき' do
657 it '単体取得オプションを利用している' do
658 Story.stub(:show_opt).with(any_args).and_return({})
659 Story.should_receive(:show_opt).with(any_args).exactly(1)
660 r = Story.show @story.id, @author
662 it '閲覧許可を問い合わせている' do
663 Story.any_instance.stub(:visible?).with(@author).and_return(true)
664 Story.any_instance.should_receive(:visible?).with(@author).exactly(1)
665 r = Story.show @story.id, @author
669 l = Story.show @story.id, @author
672 context '他人のストーリーを開こうとしたとき' do
673 it '403Forbidden例外を返す' do
674 Story.any_instance.stub(:visible?).with(@other_author).and_return(false)
676 Story.show @story.id, @other_author
677 }.should raise_error(ActiveRecord::Forbidden)
680 context '存在しないストーリーを開こうとしたとき' do
681 it '404RecordNotFound例外を返す' do
683 Story.show 110, @author
684 }.should raise_error(ActiveRecord::RecordNotFound)
689 describe '編集取得に於いて' do
691 @comic = FactoryGirl.create :comic, :author_id => @author.id
692 @panel = FactoryGirl.create :panel, :author_id => @author.id
693 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
695 context 'つつがなく終わるとき' do
696 it '単体取得オプションを利用している' do
697 Story.stub(:show_opt).with(any_args).and_return({})
698 Story.should_receive(:show_opt).with(any_args).exactly(1)
699 r = Story.edit @story.id, @author
701 it '所持判定を問い合わせている' do
702 Story.any_instance.stub(:own?).with(any_args).and_return(true)
703 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
704 r = Story.edit @story.id, @author
708 l = Story.edit @story.id, @author
711 context '他人のストーリーを開こうとしたとき' do
712 it '403Forbidden例外を返す' do
713 Story.any_instance.stub(:own?).and_return(false)
715 Story.edit @story.id, @author
716 }.should raise_error(ActiveRecord::Forbidden)
719 context '存在しないストーリーを開こうとしたとき' do
720 it '404RecordNotFound例外を返す' do
722 Story.edit 110, @author
723 }.should raise_error(ActiveRecord::RecordNotFound)
728 describe '単体取得オプションに於いて' do
729 it 'includeキーを含んでいる' do
731 r.has_key?(:include).should be_true
734 r = Story.show_opt[:include]
735 r.should have(3).items
738 r = Story.show_opt[:include]
739 r.has_key?(:comic).should be_true
741 it 'コミックは作家を含んでいる' do
742 r = Story.show_opt[:include]
743 r[:comic].has_key?(:author).should be_true
746 r = Story.show_opt[:include]
747 r.has_key?(:author).should be_true
750 r = Story.show_opt[:include]
751 r.has_key?(:panel).should be_true
754 r = Story.show_opt[:include]
755 r[:panel].has_key?(:author).should be_true
758 r = Story.show_opt[:include]
759 r[:panel].has_key?(:panel_pictures).should be_true
761 it 'コマ絵は実素材を含んでいる' do
762 r = Story.show_opt[:include]
763 r[:panel][:panel_pictures].has_key?(:picture).should be_true
766 r = Story.show_opt[:include]
767 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
769 it '実素材はライセンスを含んでいる' do
770 r = Story.show_opt[:include]
771 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
773 it 'コマはフキダシを含んでいる' do
774 r = Story.show_opt[:include]
775 r[:panel].has_key?(:speech_balloons).should be_true
777 it 'フキダシはフキダシ枠を含んでいる' do
778 r = Story.show_opt[:include]
779 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
781 it 'フキダシはセリフを含んでいる' do
782 r = Story.show_opt[:include]
783 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
786 describe 'json単体取得オプションに於いて' do
789 describe 'ストーリーのjson出力に於いて' do
792 @panel = FactoryGirl.create :panel, :author_id => @author.id
793 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
794 @sb = @panel.speech_balloons.create(
795 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
797 @gc = @panel.ground_colors.create(
798 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
800 @gp = @panel.ground_pictures.create(
801 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
804 @comic = FactoryGirl.create :comic, :author_id => @author.id
805 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
807 context '事前チェックする' do
809 Panel.any_instance.stub(:elements).and_return('{}')
811 it 'コマ要素のjson出力を依頼している' do
812 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
813 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
814 r = @story.story_as_json @author
817 it 'json textを返している' do
818 r = JSON.parse @story.story_as_json(@author)
819 r.is_a?(Hash).should be_true
821 it 'comic,author,panel,コマ要素を含んでいる' do
822 r = JSON.parse @story.story_as_json(@author)
823 r.has_key?('comic').should be_true
824 r['comic'].has_key?('author').should be_true
825 r.has_key?('author').should be_true
826 r.has_key?('panel').should be_true
827 r['panel'].has_key?('author').should be_true
829 context 'コマ閲覧許可のとき' do
831 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
833 it 'コマ要素にコマ要素を追加している' do
834 r = JSON.parse @story.story_as_json(@author)
835 r['panel'].has_key?('elements').should be_true
836 r['panel']['elements'].should_not be_empty
839 context 'コマ閲覧不許可のとき' do
841 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
843 it 'コマ要素にデータを含ませない' do
844 r = JSON.parse @story.story_as_json(@author)
845 r['panel'].has_key?('elements').should be_false
850 describe 'ストーリーリストのjson出力に於いて' do
852 @panel = FactoryGirl.create :panel, :author_id => @author.id
853 @comic = FactoryGirl.create :comic, :author_id => @author.id
854 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
855 Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
857 context 'つつがなく終わるとき' do
858 it 'ストーリーのjson出力を依頼している' do
859 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
860 r = Story.list_as_json_text [@story], @author
863 it 'json textを返している' do
864 r = Story.list_as_json_text [@story], @author
866 j.is_a?(Array).should be_true
869 r = Story.list_as_json_text [@story], @author
871 j.first.has_key?('s').should be_true
875 describe 'ライセンス素材に於いて' do
878 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
879 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
880 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
881 @panel = FactoryGirl.create :panel, :author_id => @author.id
882 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id
884 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
885 @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id
888 @comic = FactoryGirl.create :comic, :author_id => @author.id
889 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
890 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id
894 context 'つつがなく終わるとき' do
896 it '連想配列(値は実素材、キーは実素材id)を返している' do
897 r = Story.licensed_pictures [@story, @story2]
898 r.is_a?(Hash).should be_true
899 r.should have(2).items
900 r[@pp.picture_id].should eq @p
901 r[@pp2.picture_id].should eq @p2
903 context 'コマが削除されているときき' do
907 it '削除されているコマは無視する' do
908 r = Story.licensed_pictures [@story, @story2]
909 r.is_a?(Hash).should be_true
910 r.should have(1).items
911 r[@pp.picture_id].should eq @p
912 r[@pp2.picture_id].should be_nil
917 describe 't補充値に於いて' do
919 @comic = FactoryGirl.create :comic, :author_id => @author.id
920 @panel = FactoryGirl.create :panel, :author_id => @author.id
923 context 'コミック初のコマなら' do
925 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
927 r = Story.new_t @story.comic_id
931 context 'コミックに一個コマがあるとき' do
933 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
934 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
936 r = Story.new_t @story.comic_id
940 context 'コミックに2個コマがあるとき' do
942 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
943 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
944 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
946 r = Story.new_t @story.comic_id
951 describe 'シリアライズチェックに於いて' do
952 context 'つつがなく終わるとき' do
953 it '0からシリアライズされているならTrueを返す' do
954 r = Story.serial? [0, 1, 2]
957 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
958 r = Story.serial? [0, 2, 1]
961 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
962 r = Story.serial? [ 2, 1, 4, 3, 0]
967 it '0から始まらないならFalseを返す' do
968 r = Story.serial? [1, 2, 3]
971 it '連続していないならFalseを返す' do
972 r = Story.serial? [0, 1, 2, 4]
975 it '連続していないならFalseを返す' do
976 r = Story.serial? [0, 1, 2, 4, 5]
981 describe 't収集に於いて' do
983 @comic = FactoryGirl.create :comic, :author_id => @author.id
984 @panel = FactoryGirl.create :panel, :author_id => @author.id
985 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
986 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
987 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
989 context 'つつがなく終わるとき' do
990 it 'ストーリーから同一コミックのtだけを収集している' do
991 r = Story.collect_t @story
996 it 'ストーリーから同一コミックのtだけを収集している' do
997 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
998 r = Story.collect_t @story
999 r.sort.should eq [0, 1]
1002 context '複数コマでヨソのコミックも混じっているとき' do
1003 it 'ストーリーから同一コミックのtだけを収集している' do
1004 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1005 r = Story.collect_t @story
1006 r.sort.should eq [0, 1]
1010 describe 'tチェックに於いて' do
1012 @comic = FactoryGirl.create :comic, :author_id => @author.id
1013 @panel = FactoryGirl.create :panel, :author_id => @author.id
1014 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1016 context 'つつがなく終わるとき' do
1018 Story.should_receive(:collect_t).with(any_args).exactly(1)
1019 Story.stub(:collect_t).with(any_args).and_return([])
1020 Story.stub(:serial?).with(any_args).and_return(true)
1021 r = Story.validate_t @story
1023 it '収集したtをシリアライズチェック依頼している' do
1024 Story.stub(:collect_t).with(any_args).and_return([])
1025 Story.should_receive(:serial?).with(any_args).exactly(1)
1026 Story.stub(:serial?).with(any_args).and_return(true)
1027 r = Story.validate_t @story
1031 #依頼チェックだけでは不安なので最低限のチェックを
1033 it '一件だけで正常通過している' do
1034 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1035 r = Story.validate_t @story
1040 it '2件目を作っても正常通過している' do
1041 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1042 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
1043 r = Story.validate_t @story2
1048 describe '挿入シフトに於いて' do
1050 @comic = FactoryGirl.create :comic, :author_id => @author.id
1051 @panel = FactoryGirl.create :panel, :author_id => @author.id
1055 it 'Updateを依頼している' do
1056 Story.stub(:update_all).with(any_args)
1057 Story.should_receive(:update_all).with(any_args).exactly(1)
1058 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1062 context 'テーブルに1件(t:0)で0に挿入したとき' do
1064 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1065 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1067 it '既存の行を1にシフトしている' do
1068 @story2.insert_shift
1070 l.first.t.should eq 1
1072 it 'これから挿入するt(0)が欠番になっている' do
1073 @story2.insert_shift
1074 l = Story.find(:all).map {|s| s.t }
1075 l.include?(0).should_not be_true
1078 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
1080 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1081 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1082 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1084 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1085 @story3.insert_shift
1086 l = Story.find(:all).map {|s| s.t }
1087 l.sort.should eq [0, 2]
1090 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
1092 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1093 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1094 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1095 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1096 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1097 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1099 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1100 @story6.insert_shift
1101 l = Story.find(:all).map {|s| s.t }
1102 l.sort.should eq [0, 1, 3, 4, 5]
1105 context '先ほどのケース+他のコミック1件で挿入したとき' do
1107 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1108 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1109 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1110 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1111 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1112 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1113 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1114 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1116 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1117 @story6.insert_shift
1118 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
1119 l.sort.should eq [0, 1, 3, 4, 5]
1121 it '他のコミックに影響がない' do
1123 @story6.insert_shift
1125 @storyc2.t.should eq ot
1129 describe '少ない方に移動に於いて' do
1131 @comic = FactoryGirl.create :comic, :author_id => @author.id
1132 @panel = FactoryGirl.create :panel, :author_id => @author.id
1135 it 'Updateを依頼している' do
1136 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1137 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1138 Story.stub(:update_all).with(any_args)
1139 Story.should_receive(:update_all).with(any_args).exactly(1)
1142 @story2.lesser_shift ot
1145 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
1147 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1148 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1152 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1154 @story2.lesser_shift @ot
1155 l = Story.find(:all).map {|s| s.t }
1156 l.sort.should eq [1, 1]
1158 it '既存のt0を1にシフトしている' do
1159 @story2.lesser_shift @ot
1161 @story.t.should eq 1
1164 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
1166 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1167 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1168 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1172 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1174 @story3.lesser_shift @ot
1175 l = Story.find(:all).map {|s| s.t }
1176 l.sort.should eq [0, 2, 2]
1178 it '既存のt1を2にシフトしている' do
1179 @story3.lesser_shift @ot
1181 @story2.t.should eq 2
1184 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
1186 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1187 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1188 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1189 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1190 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1194 it 'これから挿入するt(1)が欠番になっている' do
1196 @story4.lesser_shift @ot
1197 l = Story.find(:all).map {|s| s.t }
1198 l.sort.should eq [0, 2, 3, 3, 4]
1200 it '既存のt0には変化がない' do
1201 @story4.lesser_shift @ot
1203 @story.t.should eq 0
1205 it '既存のt4には変化がない' do
1206 @story4.lesser_shift @ot
1208 @story5.t.should eq 4
1210 it '既存のt1を2にシフトしている' do
1211 @story4.lesser_shift @ot
1213 @story2.t.should eq 2
1215 it '既存のt2を3にシフトしている' do
1216 @story4.lesser_shift @ot
1218 @story3.t.should eq 3
1221 context '先ほどのケース+他のコミック1件で挿入したとき' do
1223 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1224 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1225 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1226 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1227 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1228 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1229 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1233 it 'これから挿入するt(1)が欠番になっている' do
1234 @story4.lesser_shift @ot
1235 l = Story.find(:all).map {|s| s.t }
1236 l.sort.should eq [0, 0, 2, 3, 3, 4]
1238 it '既存のt0には変化がない' do
1239 @story4.lesser_shift @ot
1241 @story.t.should eq 0
1243 it '既存のt4には変化がない' do
1244 @story4.lesser_shift @ot
1246 @story5.t.should eq 4
1248 it '既存のt1を2にシフトしている' do
1249 @story4.lesser_shift @ot
1251 @story2.t.should eq 2
1253 it '既存のt2を3にシフトしている' do
1254 @story4.lesser_shift @ot
1256 @story3.t.should eq 3
1258 it '他のコミックに影響がない' do
1259 @story4.lesser_shift @ot
1261 @storyc2.t.should eq 0
1266 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
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
1273 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1275 @story2.lesser_shift @ot
1276 l = Story.find(:all).map {|s| s.t }
1277 l.sort.should eq [1, 1]
1279 it '既存のt0を1にシフトしている' do
1280 @story2.lesser_shift @ot
1282 @story.t.should eq 1
1284 it '既存のt1は0に補正されている' do
1285 @story2.lesser_shift @ot
1286 @story2.t.should eq 0
1290 describe '大きい方に移動に於いて' do
1292 @comic = FactoryGirl.create :comic, :author_id => @author.id
1293 @panel = FactoryGirl.create :panel, :author_id => @author.id
1296 it 'Updateを依頼している' do
1297 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1298 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1299 Story.stub(:update_all).with(any_args)
1300 Story.should_receive(:update_all).with(any_args).exactly(1)
1303 @story.higher_shift ot
1306 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1308 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1309 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1313 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1315 @story.higher_shift @ot
1316 l = Story.find(:all).map {|s| s.t }
1317 l.sort.should eq [0, 0]
1319 it '既存のt1を0にシフトしている' do
1320 @story.higher_shift @ot
1322 @story2.t.should eq 0
1325 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1327 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1328 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1329 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1333 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1335 @story.higher_shift @ot
1336 l = Story.find(:all).map {|s| s.t }
1337 l.sort.should eq [0, 0, 2]
1339 it '既存のt1を0にシフトしている' do
1340 @story.higher_shift @ot
1342 @story2.t.should eq 0
1345 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1347 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1348 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1349 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1350 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1351 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1355 it 'これから挿入するt(3)が欠番になっている' do
1357 @story2.higher_shift @ot
1358 l = Story.find(:all).map {|s| s.t }
1359 l.sort.should eq [0, 1, 1, 2, 4]
1361 it '既存のt0には変化がない' do
1362 @story2.higher_shift @ot
1364 @story.t.should eq 0
1366 it '既存のt4には変化がない' do
1367 @story2.higher_shift @ot
1369 @story5.t.should eq 4
1371 it '既存のt2を1にシフトしている' do
1372 @story2.higher_shift @ot
1374 @story3.t.should eq 1
1376 it '既存のt3を2にシフトしている' do
1377 @story2.higher_shift @ot
1379 @story4.t.should eq 2
1382 context '先ほどのケース+他のコミック1件で挿入したとき' do
1384 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1385 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1386 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1387 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1388 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1389 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1390 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1394 it 'これから挿入するt(3)が欠番になっている' do
1396 @story2.higher_shift @ot
1397 l = Story.find(:all).map {|s| s.t }
1398 l.sort.should eq [0, 0, 1, 1, 2, 4]
1400 it '既存のt0には変化がない' do
1401 @story2.higher_shift @ot
1403 @story.t.should eq 0
1405 it '既存のt4には変化がない' do
1406 @story2.higher_shift @ot
1408 @story5.t.should eq 4
1410 it '既存のt2を1にシフトしている' do
1411 @story2.higher_shift @ot
1413 @story3.t.should eq 1
1415 it '既存のt3を2にシフトしている' do
1416 @story2.higher_shift @ot
1418 @story4.t.should eq 2
1420 it '他のコミックに影響がない' do
1421 @story2.higher_shift @ot
1423 @storyc2.t.should eq 0
1427 #max超えたときはmaxとして正常扱い
1428 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1430 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1431 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1435 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1437 @story.higher_shift @ot
1438 l = Story.find(:all).map {|s| s.t }
1439 l.sort.should eq [0, 0]
1441 it '既存のt1を0にシフトしている' do
1442 @story.higher_shift @ot
1444 @story2.t.should eq 0
1446 it '既存のt0は1に補正されている' do
1447 @story.higher_shift @ot
1448 @story.t.should eq 1
1452 describe '入れ替えに於いて' do
1454 @comic = FactoryGirl.create :comic, :author_id => @author.id
1455 @panel = FactoryGirl.create :panel, :author_id => @author.id
1456 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1457 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1459 context '新tが旧tより小さいとき' do
1460 it '少ない方に移動を依頼している' do
1461 Story.any_instance.stub(:lesser_shift).with(any_args)
1462 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1465 @story2.update_shift ot
1468 context '新tが旧tより大きいとき' do
1469 it '大きい方に移動を依頼している' do
1470 Story.any_instance.stub(:higher_shift).with(any_args)
1471 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1474 @story.update_shift ot
1478 describe '順序入れ替えに於いて' do
1480 @comic = FactoryGirl.create :comic, :author_id => @author.id
1481 @panel = FactoryGirl.create :panel, :author_id => @author.id
1483 context 'オブジェクトが新規でtが空のとき' do
1484 it '末尾追加としてtを補充依頼している' do
1485 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1486 Story.stub(:new_t).with(any_args).and_return(0)
1487 Story.should_receive(:new_t).with(any_args).exactly(1)
1492 context 'オブジェクトが新規でtが設定されているとき' do
1493 it '挿入追加として挿入シフトを依頼している' do
1494 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1495 Story.any_instance.stub(:insert_shift).with(any_args)
1496 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1501 context 'オブジェクトが新規でなくtが設定されているとき' do
1502 it 'コマ移動として入れ替えを依頼している' do
1503 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1504 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1505 Story.any_instance.stub(:update_shift).with(any_args)
1506 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1511 context 'オブジェクトが新規でなくtが空のとき' do
1512 it '入れ替えもシフトもせず、tを空のままにしている' do
1513 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1517 describe '編集許可に於いて' do
1519 @comic = FactoryGirl.create :comic, :author_id => @author.id
1520 @panel = FactoryGirl.create :panel, :author_id => @author.id
1521 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1523 context 'つつがなく終わるとき' do
1529 context 'コミックで引っかかるとき' do
1531 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1532 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1537 context 'コマで引っかかるとき' do
1539 Comic.any_instance.stub(:own?).with(any_args).and_return(true)
1540 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1545 context 'コミックまたはコマが指定されていなかったとき' do
1547 Comic.any_instance.stub(:own?).with(any_args).and_return(true)
1548 @story.panel_id = nil
1553 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1554 @story.comic_id = nil
1560 describe '保存に於いて' do
1562 @comic = FactoryGirl.create :comic, :author_id => @author.id
1563 @panel = FactoryGirl.create :panel, :author_id => @author.id
1564 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1566 context 'つつがなく終わるとき' do
1567 it '編集許可チェックを依頼している' do
1568 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1569 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1572 it '順序入れ替えを依頼している' do
1573 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1574 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1575 Story.any_instance.stub(:save).with(any_args).and_return(true)
1576 Story.stub(:validate_t).with(any_args).and_return(true)
1580 Story.stub(:new_t).with(any_args).and_return(0)
1581 Story.any_instance.stub(:save).with(any_args).and_return(true)
1582 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1583 Story.stub(:validate_t).with(any_args).and_return(true)
1586 it 'tのシリアライズチェックを依頼している' do
1587 Story.stub(:new_t).with(any_args).and_return(0)
1588 Story.any_instance.stub(:save).with(any_args).and_return(true)
1589 Story.stub(:validate_t).with(any_args).and_return(true)
1590 Story.should_receive(:validate_t).with(any_args).exactly(1)
1594 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1595 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1597 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1598 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1599 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1600 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1601 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1602 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1603 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1604 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1606 it '既存のt0には変化がない' do
1609 @story.t.should eq 0
1611 it '既存のt1には変化がない' do
1614 @story2.t.should eq 1
1616 it '既存のt2を3にシフトしている' do
1619 @story3.t.should eq 3
1621 it '既存のt3を4にシフトしている' do
1624 @story4.t.should eq 4
1626 it '既存のt5を5にシフトしている' do
1629 @story5.t.should eq 5
1631 it '新規のt2が作成されている' do
1634 @story6.t.should eq 2
1636 it '他のコミックに影響がない' do
1640 @storyc2.t.should eq @ot
1643 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1645 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1646 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1647 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1648 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1649 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1650 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1651 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1655 it '既存のt0には変化がない' do
1658 @story.t.should eq 0
1660 it '既存のt4には変化がない' do
1663 @story5.t.should eq 4
1665 it '既存のt1を2にシフトしている' do
1668 @story2.t.should eq 2
1670 it '既存のt2を3にシフトしている' do
1673 @story3.t.should eq 3
1675 it '既存のt3を1にシフトしている' do
1678 @story4.t.should eq 1
1680 it '他のコミックに影響がない' do
1683 @storyc2.t.should eq 0
1686 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1688 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1689 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1690 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1691 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1692 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1693 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1694 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1698 it '既存のt0には変化がない' do
1701 @story.t.should eq 0
1703 it '既存のt4には変化がない' do
1706 @story5.t.should eq 4
1708 it '既存のt1を3にシフトしている' do
1711 @story2.t.should eq 3
1713 it '既存のt2を1にシフトしている' do
1716 @story3.t.should eq 1
1718 it '既存のt3を2にシフトしている' do
1721 @story4.t.should eq 2
1723 it '他のコミックに影響がない' do
1726 @storyc2.t.should eq 0
1729 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1730 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1732 Story.any_instance.stub(:save).with(any_args).and_return(false)
1733 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1734 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1735 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1736 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1737 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1738 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1739 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1740 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1745 @story.t.should eq 0
1747 @story2.t.should eq 1
1749 @story3.t.should eq 2
1751 @story4.t.should eq 3
1753 @story5.t.should eq 4
1755 @storyc2.t.should eq 0
1762 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1764 Story.stub(:validate_t).with(any_args).and_return(false)
1765 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1766 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1767 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1768 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1769 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1770 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1771 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1778 @story.t.should eq 0
1780 @story2.t.should eq 1
1782 @story3.t.should eq 2
1784 @story4.t.should eq 3
1786 @story5.t.should eq 4
1788 @storyc2.t.should eq 0
1791 r = @story4.store @ot
1794 it 'tにエラーメッセージが入っている' do
1796 @story4.errors[:t].should_not be_empty
1797 @story4.valid?.should be_true
1800 context '編集不可だったとき' do
1802 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1803 Story.any_instance.stub(:allow?).and_return(false)
1805 it '403Forbidden例外を返す' do
1808 }.should raise_error(ActiveRecord::Forbidden)
1812 describe '切り詰め処理つき削除に於いて' do
1814 @comic = FactoryGirl.create :comic, :author_id => @author.id
1815 @panel = FactoryGirl.create :panel, :author_id => @author.id
1816 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1818 context 'つつがなく終わるとき' do
1821 @story.destroy_and_shorten
1822 }.should change(Story, :count ).by(-1)
1825 r = @story.destroy_and_shorten
1829 context '削除に失敗したとき' do
1831 Story.any_instance.stub(:destroy).and_return(false)
1835 @story.destroy_and_shorten
1836 }.should_not change(Story, :count )
1839 r = @story.destroy_and_shorten
1843 #連携テスト。切り詰めが直接DBをいじる
1844 context '2件で先頭を削除したとき' do
1846 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1850 @story.destroy_and_shorten
1851 }.should change(Story, :count ).by(-1)
1854 @story.destroy_and_shorten
1856 Story.find @story.id
1857 }.should raise_error(ActiveRecord::RecordNotFound)
1860 @story.destroy_and_shorten
1862 @story2.t.should eq 0
1865 context '3件で先頭を削除したとき' do
1867 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1868 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1872 @story.destroy_and_shorten
1873 }.should change(Story, :count ).by(-1)
1876 @story.destroy_and_shorten
1878 Story.find @story.id
1879 }.should raise_error(ActiveRecord::RecordNotFound)
1882 @story.destroy_and_shorten
1884 @story2.t.should eq 0
1887 @story.destroy_and_shorten
1889 @story3.t.should eq 1
1892 context '5件で3件目を削除したとき' do
1894 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1895 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1896 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1897 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1901 @story3.destroy_and_shorten
1902 }.should change(Story, :count ).by(-1)
1905 @story3.destroy_and_shorten
1907 @story.t.should eq 0
1910 @story3.destroy_and_shorten
1912 @story2.t.should eq 1
1915 @story3.destroy_and_shorten
1917 Story.find @story3.id
1918 }.should raise_error(ActiveRecord::RecordNotFound)
1921 @story3.destroy_and_shorten
1923 @story4.t.should eq 2
1926 @story3.destroy_and_shorten
1928 @story5.t.should eq 3
1931 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する