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 context '事前チェックする' do
145 it '自身にロールリストからの作家取得を依頼している' do
146 Story.should_receive(:get_author_from_roles).with(any_args).exactly(1)
147 r = @story.own?([@author])
150 context 'ロール内作家が取得できるとき' do
153 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
154 Story.stub(:get_author_from_roles).with(any_args).and_return(@author)
155 r = @story.own?([@author])
158 it 'ロール内作家のidが自身の作家idと一致しないならno' do
159 Story.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
160 @story.own?(@other_author).should be_false
163 context 'ロール内作家が取得できないとき' do
165 Story.stub(:get_author_from_roles).with(any_args).and_return(nil)
168 r = @story.own?([@author])
174 describe '閲覧許可に於いて' do
176 @comic = FactoryGirl.create :comic, :author_id => @author.id
177 @panel = FactoryGirl.create :panel, :author_id => @author.id
178 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
180 context 'オープンモードのとき' do
182 MagicNumber['run_mode'] = 0
184 it '自身にゲスト用ロールチェックを問い合わせしている' do
185 Story.any_instance.stub(:guest_role_check).and_return(true)
186 Story.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
187 r = @story.visible?([@author])
189 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
190 Story.any_instance.stub(:guest_role_check).and_return(false)
191 r = @story.visible?([@author])
195 context 'クローズドモードのとき' do
197 MagicNumber['run_mode'] = 1
199 it '自身に読者用ロールチェックを問い合わせしている' do
200 Story.any_instance.stub(:reader_role_check).and_return(true)
201 Story.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
202 r = @story.visible?([@author])
204 it '読者用ロールチェックが失敗したとき、falseを返す' do
205 Story.any_instance.stub(:reader_role_check).and_return(false)
206 r = @story.visible?([@author])
210 context '事前チェックする' do
212 MagicNumber['run_mode'] = 1
213 Story.any_instance.stub(:reader_role_check).and_return(true)
215 it '自身のコミックに所持判定を問い合わせしている' do
216 Comic.any_instance.stub(:own?).and_return(true)
217 Comic.any_instance.should_receive(:own?).with(any_args).exactly(1)
218 r = @story.visible?([@author])
220 it '自身のコミックに閲覧許可を問い合わせしている' do
221 Comic.any_instance.stub(:own?).and_return(false)
222 Comic.any_instance.stub(:visible?).and_return(true)
223 Comic.any_instance.should_receive(:visible?).with(any_args).exactly(1)
224 r = @story.visible?([@author])
227 context 'つつがなく終わるとき' do
229 MagicNumber['run_mode'] = 1
230 Story.any_instance.stub(:reader_role_check).and_return(true)
232 it '自分のコミックのストーリーなら許可する' do
233 Comic.any_instance.stub(:own?).and_return(true)
234 Comic.any_instance.stub(:visible).and_return(0)
235 r = @story.visible?([@author])
238 it '他人の非公開コミックのストーリーなら許可しない' do
239 Comic.any_instance.stub(:own?).and_return(false)
240 Comic.any_instance.stub(:visible).and_return(0)
241 r = @story.visible?([@author])
244 it '他人のコミックのストーリーでも公開なら許可する' do
245 Comic.any_instance.stub(:own?).and_return(false)
246 Comic.any_instance.stub(:visible).and_return(1)
247 r = @story.visible?([@author])
253 describe 'プレイリスト取得に於いて' do
255 @comic = FactoryGirl.create :comic, :author_id => @author.id
256 @panel = FactoryGirl.create :panel, :author_id => @author.id
257 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
258 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
259 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
260 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
262 context 'offset補正について' do
263 it '文字列から数値に変換される' do
264 Story.offset(100, '8').should eq 8
267 Story.offset(100).should eq 0
269 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
271 it '1件のときオフセット1なら0になる' do
272 Story.offset(1, '1').should eq 0
274 it '5件のときオフセット5なら4になる' do
275 Story.offset(5, '5').should eq 4
277 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
278 #-4のときは、最後から4つのコマを表示する。
279 it '2件のときオフセット-1なら1になる' do
280 Story.offset(2, '-1').should eq 1
282 it '5件のときオフセット-2なら3になる' do
283 Story.offset(5, '-2').should eq 3
285 # 最終的なが負になるなど、不正な値が入ったときは0となる。
286 it '2件のときオフセット-5なら0になる' do
287 Story.offset(2, '-5').should eq 0
290 context 'panel_count補正について' do
291 it '文字列から数値に変換される' do
292 Story.panel_count(100, '7').should eq 7
294 it 'nilの場合はStory.default_panel_sizeになる' do
295 Story.panel_count(100).should eq Story.default_panel_size
297 it '0以下の場合はStory.default_panel_sizeになる' do
298 Story.panel_count(100, '0').should eq Story.default_panel_size
300 it 'Story.max_panel_sizeを超えた場合はStory.max_panel_sizeになる' do
301 Story.panel_count(100, '1000').should eq Story.max_panel_size
305 c = Story.play_list @comic, @author
309 #公開コミックの公開コマは(他人のコミックであっても)含んでいる
310 v = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
311 c = Story.play_list @comic, @author
312 c.should eq [ @story, v]
315 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id, :t => 1
316 c = Story.play_list @comic, @author
317 c.should eq [ @story, h]
319 context 'DBに5件あって1ページの件数を2件に変えたとして' do
321 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
322 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2
323 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3
324 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4
326 it 'offset=0なら末尾2件を返す' do
328 c = Story.play_list( @comic, @author, 0, 2)
329 c.should eq [@story, @story2]
331 it 'offset=2なら中間2件を返す' do
332 c = Story.play_list(@comic, @author, 2, 2)
333 c.should eq [@story3, @story4]
335 it 'offset=4なら先頭1件を返す' do
336 c = Story.play_list(@comic, @author, 4, 2)
337 c.should eq [@story5]
341 describe 'list関連テーブルプションに於いて' do
342 it 'includeキーを含んでいる' do
344 r.has_key?(:include).should be_true
347 r = Story.list_opt[:include]
348 r.should have(3).items
351 r = Story.list_opt[:include]
352 r.has_key?(:comic).should be_true
354 it 'コミックは作家を含んでいる' do
355 r = Story.list_opt[:include]
356 r[:comic].has_key?(:author).should be_true
359 r = Story.list_opt[:include]
360 r.has_key?(:author).should be_true
363 r = Story.list_opt[:include]
364 r.has_key?(:panel).should be_true
367 r = Story.list_opt[:include]
368 r[:panel].has_key?(:author).should be_true
371 r = Story.list_opt[:include]
372 r[:panel].has_key?(:panel_pictures).should be_true
374 it 'コマ絵は実素材を含んでいる' do
375 r = Story.list_opt[:include]
376 r[:panel][:panel_pictures].has_key?(:picture).should be_true
379 r = Story.list_opt[:include]
380 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
382 it '実素材はライセンスを含んでいる' do
383 r = Story.list_opt[:include]
384 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
386 it 'コマはフキダシを含んでいる' do
387 r = Story.list_opt[:include]
388 r[:panel].has_key?(:speech_balloons).should be_true
390 it 'フキダシはフキダシ枠を含んでいる' do
391 r = Story.list_opt[:include]
392 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
394 it 'フキダシはセリフを含んでいる' do
395 r = Story.list_opt[:include]
396 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
399 describe 'json一覧出力オプションに於いて' do
402 describe '一覧取得に於いて' do
404 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
405 @panel = FactoryGirl.create :panel, :author_id => @author.id
406 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
407 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
408 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
409 @hidden_comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
411 context 'page補正について' do
412 it '文字列から数値に変換される' do
413 Story.page('8').should eq 8
416 Story.page().should eq 1
419 Story.page('0').should eq 1
422 context 'page_size補正について' do
423 it '文字列から数値に変換される' do
424 Story.page_size('7').should eq 7
426 it 'nilの場合はStory.default_page_sizeになる' do
427 Story.page_size().should eq Story.default_page_size
429 it '0以下の場合はStory.default_page_sizeになる' do
430 Story.page_size('0').should eq Story.default_page_size
432 it 'Story.max_page_sizeを超えた場合はStory.max_page_sizeになる' do
433 Story.page_size('1000').should eq Story.max_page_size
441 #公開コミックのStoryは(他人のStoryであっても)含んでいる
442 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
444 c.should eq [ v, @story]
446 it '非公開のストーリーは(自分のストーリーであっても)含まない' do
447 h = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hidden_comic.id, :panel_id => @panel.id, :t => 0
449 c.should eq [ @story]
451 context 'DBに5件あって1ページの件数を2件に変えたとして' do
453 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
454 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
455 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
456 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
460 l.should have(2).items
462 it 'page=1なら末尾2件を返す' do
465 l.should eq [@story5, @story4]
467 it 'page=2なら中間2件を返す' do
469 l.should eq [@story3, @story2]
471 it 'page=3なら先頭1件を返す' do
476 context 'DBに5件あって1ページの件数を2件に変えたとして' do
478 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
479 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
480 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
481 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
482 Story.stub(:default_page_size).and_return(2)
484 it '件数0は全件(5件)を返す' do
486 r.should have(5).items
490 describe '自分のストーリー一覧取得に於いて' do
492 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
493 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
494 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
495 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
496 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
497 @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
498 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
500 context 'つつがなく終わるとき' do
501 it '一覧取得オプションを利用している' do
502 Story.stub(:list_opt).with(any_args).and_return({})
503 Story.should_receive(:list_opt).with(any_args).exactly(1)
504 r = Story.mylist @author
508 s = Story.mylist @author
512 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
513 sl = Story.mylist @author
514 sl.should eq [ns, @story]
516 it '他人のストーリーはコマコミックともに公開でも含まない' do
517 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
518 sl = Story.mylist @author
519 sl.should eq [@story]
521 it '自分のストーリーはコマコミックともに非公開でも含んでいる' do
522 hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
523 sl = Story.mylist @author
524 sl.should eq [hs, @story]
526 context 'DBに5件あって1ページの件数を2件に変えたとして' do
528 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
529 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
530 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
531 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
532 Story.stub(:default_page_size).and_return(2)
535 l = Story.mylist @author, 1, 2
536 l.should have(2).items
538 it 'page=1なら末尾2件を返す' do
540 l = Story.mylist @author, 1, 2
541 l.should eq [@story5, @story4]
543 it 'page=2なら中間2件を返す' do
544 l = Story.mylist @author, 2, 2
545 l.should eq [@story3, @story2]
547 it 'page=3なら先頭1件を返す' do
548 l = Story.mylist @author, 3, 2
552 context 'DBに5件あって1ページの件数を2件に変えたとして' do
554 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
555 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
556 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
557 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
558 Author.stub(:default_story_page_size).and_return(2)
560 it '件数0は全件(5件)を返す' do
561 r = Story.mylist @author, 5, 0
562 r.should have(5).items
567 describe '単体取得に於いて' do
569 @comic = FactoryGirl.create :comic, :author_id => @author.id
570 @panel = FactoryGirl.create :panel, :author_id => @author.id
571 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
573 context 'つつがなく終わるとき' do
574 it '単体取得オプションを利用している' do
575 Story.stub(:show_opt).with(any_args).and_return({})
576 Story.should_receive(:show_opt).with(any_args).exactly(1)
577 r = Story.show @story.id, @author
579 it '閲覧許可を問い合わせている' do
580 Story.any_instance.stub(:visible?).with(@author).and_return(true)
581 Story.any_instance.should_receive(:visible?).with(@author).exactly(1)
582 r = Story.show @story.id, @author
586 l = Story.show @story.id, @author
589 context '他人のストーリーを開こうとしたとき' do
590 it '403Forbidden例外を返す' do
591 Story.any_instance.stub(:visible?).with(@other_author).and_return(false)
593 Story.show @story.id, @other_author
594 }.should raise_error(ActiveRecord::Forbidden)
597 context '存在しないストーリーを開こうとしたとき' do
598 it '404RecordNotFound例外を返す' do
600 Story.show 110, @author
601 }.should raise_error(ActiveRecord::RecordNotFound)
606 describe '編集取得に於いて' do
608 @comic = FactoryGirl.create :comic, :author_id => @author.id
609 @panel = FactoryGirl.create :panel, :author_id => @author.id
610 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
612 context 'つつがなく終わるとき' do
613 it '単体取得オプションを利用している' do
614 Story.stub(:show_opt).with(any_args).and_return({})
615 Story.should_receive(:show_opt).with(any_args).exactly(1)
616 r = Story.edit @story.id, @author
618 it '所持判定を問い合わせている' do
619 Story.any_instance.stub(:own?).with(any_args).and_return(true)
620 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
621 r = Story.edit @story.id, @author
625 l = Story.edit @story.id, @author
628 context '他人のストーリーを開こうとしたとき' do
629 it '403Forbidden例外を返す' do
630 Story.any_instance.stub(:own?).and_return(false)
632 Story.edit @story.id, @author
633 }.should raise_error(ActiveRecord::Forbidden)
636 context '存在しないストーリーを開こうとしたとき' do
637 it '404RecordNotFound例外を返す' do
639 Story.edit 110, @author
640 }.should raise_error(ActiveRecord::RecordNotFound)
645 describe '単体取得オプションに於いて' do
646 it 'includeキーを含んでいる' do
648 r.has_key?(:include).should be_true
651 r = Story.show_opt[:include]
652 r.should have(3).items
655 r = Story.show_opt[:include]
656 r.has_key?(:comic).should be_true
658 it 'コミックは作家を含んでいる' do
659 r = Story.show_opt[:include]
660 r[:comic].has_key?(:author).should be_true
663 r = Story.show_opt[:include]
664 r.has_key?(:author).should be_true
667 r = Story.show_opt[:include]
668 r.has_key?(:panel).should be_true
671 r = Story.show_opt[:include]
672 r[:panel].has_key?(:author).should be_true
675 r = Story.show_opt[:include]
676 r[:panel].has_key?(:panel_pictures).should be_true
678 it 'コマ絵は実素材を含んでいる' do
679 r = Story.show_opt[:include]
680 r[:panel][:panel_pictures].has_key?(:picture).should be_true
683 r = Story.show_opt[:include]
684 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
686 it '実素材はライセンスを含んでいる' do
687 r = Story.show_opt[:include]
688 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
690 it 'コマはフキダシを含んでいる' do
691 r = Story.show_opt[:include]
692 r[:panel].has_key?(:speech_balloons).should be_true
694 it 'フキダシはフキダシ枠を含んでいる' do
695 r = Story.show_opt[:include]
696 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
698 it 'フキダシはセリフを含んでいる' do
699 r = Story.show_opt[:include]
700 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
703 describe 'json単体取得オプションに於いて' do
706 describe 'ストーリーのjson出力に於いて' do
709 @panel = FactoryGirl.create :panel, :author_id => @author.id
710 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
711 @sb = @panel.speech_balloons.create(
712 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
714 @gc = @panel.ground_colors.create(
715 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
717 @gp = @panel.ground_pictures.create(
718 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
720 @pc = @panel.panel_colors.create(
721 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
724 @comic = FactoryGirl.create :comic, :author_id => @author.id
725 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
727 context '事前チェックする' do
729 Panel.any_instance.stub(:elements).and_return('{}')
731 it 'コマ要素のjson出力を依頼している' do
732 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
733 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
734 r = @story.story_as_json @author
737 it 'json textを返している' do
738 r = JSON.parse @story.story_as_json(@author)
739 r.is_a?(Hash).should be_true
741 it 'comic,author,panel,コマ要素を含んでいる' do
742 r = JSON.parse @story.story_as_json(@author)
743 r.has_key?('comic').should be_true
744 r['comic'].has_key?('author').should be_true
745 r.has_key?('author').should be_true
746 r.has_key?('panel').should be_true
747 r['panel'].has_key?('author').should be_true
749 context 'コマ閲覧許可のとき' do
751 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
753 it 'コマ要素にコマ要素を追加している' do
754 r = JSON.parse @story.story_as_json(@author)
755 r['panel'].has_key?('elements').should be_true
756 r['panel']['elements'].should_not be_empty
759 context 'コマ閲覧不許可のとき' do
761 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
763 it 'コマ要素にデータを含ませない' do
764 r = JSON.parse @story.story_as_json(@author)
765 r['panel'].has_key?('elements').should be_false
770 describe 'ストーリーリストのjson出力に於いて' do
772 @panel = FactoryGirl.create :panel, :author_id => @author.id
773 @comic = FactoryGirl.create :comic, :author_id => @author.id
774 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
775 Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
777 context 'つつがなく終わるとき' do
778 it 'ストーリーのjson出力を依頼している' do
779 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
780 r = Story.list_as_json_text [@story], @author
783 it 'json textを返している' do
784 r = Story.list_as_json_text [@story], @author
786 j.is_a?(Array).should be_true
789 r = Story.list_as_json_text [@story], @author
791 j.first.has_key?('s').should be_true
795 describe 'ライセンス素材に於いて' do
798 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
799 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
800 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
801 @panel = FactoryGirl.create :panel, :author_id => @author.id
802 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id
804 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
805 @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id
808 @comic = FactoryGirl.create :comic, :author_id => @author.id
809 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
810 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id
814 context 'つつがなく終わるとき' do
816 it '連想配列(値は実素材、キーは実素材id)を返している' do
817 r = Story.licensed_pictures [@story, @story2]
818 r.is_a?(Hash).should be_true
819 r.should have(2).items
820 r[@pp.picture_id].should eq @p
821 r[@pp2.picture_id].should eq @p2
823 context 'コマが削除されているときき' do
827 it '削除されているコマは無視する' do
828 r = Story.licensed_pictures [@story, @story2]
829 r.is_a?(Hash).should be_true
830 r.should have(1).items
831 r[@pp.picture_id].should eq @p
832 r[@pp2.picture_id].should be_nil
837 describe 't補充値に於いて' do
839 @comic = FactoryGirl.create :comic, :author_id => @author.id
840 @panel = FactoryGirl.create :panel, :author_id => @author.id
843 context 'コミック初のコマなら' do
845 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
847 r = Story.new_t @story.comic_id
851 context 'コミックに一個コマがあるとき' do
853 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
854 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
856 r = Story.new_t @story.comic_id
860 context 'コミックに2個コマがあるとき' do
862 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
863 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
864 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
866 r = Story.new_t @story.comic_id
871 describe 'シリアライズチェックに於いて' do
872 context 'つつがなく終わるとき' do
873 it '0からシリアライズされているならTrueを返す' do
874 r = Story.serial? [0, 1, 2]
877 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
878 r = Story.serial? [0, 2, 1]
881 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
882 r = Story.serial? [ 2, 1, 4, 3, 0]
887 it '0から始まらないならFalseを返す' do
888 r = Story.serial? [1, 2, 3]
891 it '連続していないならFalseを返す' do
892 r = Story.serial? [0, 1, 2, 4]
895 it '連続していないならFalseを返す' do
896 r = Story.serial? [0, 1, 2, 4, 5]
901 describe 't収集に於いて' do
903 @comic = FactoryGirl.create :comic, :author_id => @author.id
904 @panel = FactoryGirl.create :panel, :author_id => @author.id
905 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
906 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
907 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
909 context 'つつがなく終わるとき' do
910 it 'ストーリーから同一コミックのtだけを収集している' do
911 r = Story.collect_t @story
916 it 'ストーリーから同一コミックのtだけを収集している' do
917 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
918 r = Story.collect_t @story
919 r.sort.should eq [0, 1]
922 context '複数コマでヨソのコミックも混じっているとき' do
923 it 'ストーリーから同一コミックのtだけを収集している' do
924 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
925 r = Story.collect_t @story
926 r.sort.should eq [0, 1]
930 describe 'tチェックに於いて' do
932 @comic = FactoryGirl.create :comic, :author_id => @author.id
933 @panel = FactoryGirl.create :panel, :author_id => @author.id
934 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
936 context 'つつがなく終わるとき' do
938 Story.should_receive(:collect_t).with(any_args).exactly(1)
939 Story.stub(:collect_t).with(any_args).and_return([])
940 Story.stub(:serial?).with(any_args).and_return(true)
941 r = Story.validate_t @story
943 it '収集したtをシリアライズチェック依頼している' do
944 Story.stub(:collect_t).with(any_args).and_return([])
945 Story.should_receive(:serial?).with(any_args).exactly(1)
946 Story.stub(:serial?).with(any_args).and_return(true)
947 r = Story.validate_t @story
951 #依頼チェックだけでは不安なので最低限のチェックを
953 it '一件だけで正常通過している' do
954 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
955 r = Story.validate_t @story
960 it '2件目を作っても正常通過している' do
961 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
962 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
963 r = Story.validate_t @story2
968 describe '挿入シフトに於いて' do
970 @comic = FactoryGirl.create :comic, :author_id => @author.id
971 @panel = FactoryGirl.create :panel, :author_id => @author.id
975 it 'Updateを依頼している' do
976 Story.stub(:update_all).with(any_args)
977 Story.should_receive(:update_all).with(any_args).exactly(1)
978 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
982 context 'テーブルに1件(t:0)で0に挿入したとき' do
984 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
985 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
987 it '既存の行を1にシフトしている' do
990 l.first.t.should eq 1
992 it 'これから挿入するt(0)が欠番になっている' do
994 l = Story.find(:all).map {|s| s.t }
995 l.include?(0).should_not be_true
998 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
1000 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1001 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1002 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1004 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1005 @story3.insert_shift
1006 l = Story.find(:all).map {|s| s.t }
1007 l.sort.should eq [0, 2]
1010 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
1012 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1013 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1014 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1015 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1016 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1017 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1019 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1020 @story6.insert_shift
1021 l = Story.find(:all).map {|s| s.t }
1022 l.sort.should eq [0, 1, 3, 4, 5]
1025 context '先ほどのケース+他のコミック1件で挿入したとき' do
1027 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1028 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
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
1031 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1032 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1033 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1034 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1036 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1037 @story6.insert_shift
1038 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
1039 l.sort.should eq [0, 1, 3, 4, 5]
1041 it '他のコミックに影響がない' do
1043 @story6.insert_shift
1045 @storyc2.t.should eq ot
1049 describe '少ない方に移動に於いて' do
1051 @comic = FactoryGirl.create :comic, :author_id => @author.id
1052 @panel = FactoryGirl.create :panel, :author_id => @author.id
1055 it 'Updateを依頼している' do
1056 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1057 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1058 Story.stub(:update_all).with(any_args)
1059 Story.should_receive(:update_all).with(any_args).exactly(1)
1062 @story2.lesser_shift ot
1065 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
1067 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1068 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1072 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1074 @story2.lesser_shift @ot
1075 l = Story.find(:all).map {|s| s.t }
1076 l.sort.should eq [1, 1]
1078 it '既存のt0を1にシフトしている' do
1079 @story2.lesser_shift @ot
1081 @story.t.should eq 1
1084 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
1086 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1087 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1088 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1092 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1094 @story3.lesser_shift @ot
1095 l = Story.find(:all).map {|s| s.t }
1096 l.sort.should eq [0, 2, 2]
1098 it '既存のt1を2にシフトしている' do
1099 @story3.lesser_shift @ot
1101 @story2.t.should eq 2
1104 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
1106 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1107 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1108 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1109 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1110 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1114 it 'これから挿入するt(1)が欠番になっている' do
1116 @story4.lesser_shift @ot
1117 l = Story.find(:all).map {|s| s.t }
1118 l.sort.should eq [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
1141 context '先ほどのケース+他のコミック1件で挿入したとき' do
1143 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1144 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1145 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1146 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1147 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1148 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1149 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1153 it 'これから挿入するt(1)が欠番になっている' do
1154 @story4.lesser_shift @ot
1155 l = Story.find(:all).map {|s| s.t }
1156 l.sort.should eq [0, 0, 2, 3, 3, 4]
1158 it '既存のt0には変化がない' do
1159 @story4.lesser_shift @ot
1161 @story.t.should eq 0
1163 it '既存のt4には変化がない' do
1164 @story4.lesser_shift @ot
1166 @story5.t.should eq 4
1168 it '既存のt1を2にシフトしている' do
1169 @story4.lesser_shift @ot
1171 @story2.t.should eq 2
1173 it '既存のt2を3にシフトしている' do
1174 @story4.lesser_shift @ot
1176 @story3.t.should eq 3
1178 it '他のコミックに影響がない' do
1179 @story4.lesser_shift @ot
1181 @storyc2.t.should eq 0
1186 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
1188 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1189 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1193 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1195 @story2.lesser_shift @ot
1196 l = Story.find(:all).map {|s| s.t }
1197 l.sort.should eq [1, 1]
1199 it '既存のt0を1にシフトしている' do
1200 @story2.lesser_shift @ot
1202 @story.t.should eq 1
1204 it '既存のt1は0に補正されている' do
1205 @story2.lesser_shift @ot
1206 @story2.t.should eq 0
1210 describe '大きい方に移動に於いて' do
1212 @comic = FactoryGirl.create :comic, :author_id => @author.id
1213 @panel = FactoryGirl.create :panel, :author_id => @author.id
1216 it 'Updateを依頼している' do
1217 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1218 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1219 Story.stub(:update_all).with(any_args)
1220 Story.should_receive(:update_all).with(any_args).exactly(1)
1223 @story.higher_shift ot
1226 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1228 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1229 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1233 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1235 @story.higher_shift @ot
1236 l = Story.find(:all).map {|s| s.t }
1237 l.sort.should eq [0, 0]
1239 it '既存のt1を0にシフトしている' do
1240 @story.higher_shift @ot
1242 @story2.t.should eq 0
1245 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1247 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1248 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1249 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1253 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1255 @story.higher_shift @ot
1256 l = Story.find(:all).map {|s| s.t }
1257 l.sort.should eq [0, 0, 2]
1259 it '既存のt1を0にシフトしている' do
1260 @story.higher_shift @ot
1262 @story2.t.should eq 0
1265 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1267 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1268 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1269 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1270 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1271 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1275 it 'これから挿入するt(3)が欠番になっている' do
1277 @story2.higher_shift @ot
1278 l = Story.find(:all).map {|s| s.t }
1279 l.sort.should eq [0, 1, 1, 2, 4]
1281 it '既存のt0には変化がない' do
1282 @story2.higher_shift @ot
1284 @story.t.should eq 0
1286 it '既存のt4には変化がない' do
1287 @story2.higher_shift @ot
1289 @story5.t.should eq 4
1291 it '既存のt2を1にシフトしている' do
1292 @story2.higher_shift @ot
1294 @story3.t.should eq 1
1296 it '既存のt3を2にシフトしている' do
1297 @story2.higher_shift @ot
1299 @story4.t.should eq 2
1302 context '先ほどのケース+他のコミック1件で挿入したとき' do
1304 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1305 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1306 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1307 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1308 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1309 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1310 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1314 it 'これから挿入するt(3)が欠番になっている' do
1316 @story2.higher_shift @ot
1317 l = Story.find(:all).map {|s| s.t }
1318 l.sort.should eq [0, 0, 1, 1, 2, 4]
1320 it '既存のt0には変化がない' do
1321 @story2.higher_shift @ot
1323 @story.t.should eq 0
1325 it '既存のt4には変化がない' do
1326 @story2.higher_shift @ot
1328 @story5.t.should eq 4
1330 it '既存のt2を1にシフトしている' do
1331 @story2.higher_shift @ot
1333 @story3.t.should eq 1
1335 it '既存のt3を2にシフトしている' do
1336 @story2.higher_shift @ot
1338 @story4.t.should eq 2
1340 it '他のコミックに影響がない' do
1341 @story2.higher_shift @ot
1343 @storyc2.t.should eq 0
1347 #max超えたときはmaxとして正常扱い
1348 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1350 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1351 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1355 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1357 @story.higher_shift @ot
1358 l = Story.find(:all).map {|s| s.t }
1359 l.sort.should eq [0, 0]
1361 it '既存のt1を0にシフトしている' do
1362 @story.higher_shift @ot
1364 @story2.t.should eq 0
1366 it '既存のt0は1に補正されている' do
1367 @story.higher_shift @ot
1368 @story.t.should eq 1
1372 describe '入れ替えに於いて' do
1374 @comic = FactoryGirl.create :comic, :author_id => @author.id
1375 @panel = FactoryGirl.create :panel, :author_id => @author.id
1376 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1377 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1379 context '新tが旧tより小さいとき' do
1380 it '少ない方に移動を依頼している' do
1381 Story.any_instance.stub(:lesser_shift).with(any_args)
1382 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1385 @story2.update_shift ot
1388 context '新tが旧tより大きいとき' do
1389 it '大きい方に移動を依頼している' do
1390 Story.any_instance.stub(:higher_shift).with(any_args)
1391 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1394 @story.update_shift ot
1398 describe '順序入れ替えに於いて' do
1400 @comic = FactoryGirl.create :comic, :author_id => @author.id
1401 @panel = FactoryGirl.create :panel, :author_id => @author.id
1403 context 'オブジェクトが新規でtが空のとき' do
1404 it '末尾追加としてtを補充依頼している' do
1405 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1406 Story.stub(:new_t).with(any_args).and_return(0)
1407 Story.should_receive(:new_t).with(any_args).exactly(1)
1412 context 'オブジェクトが新規でtが設定されているとき' do
1413 it '挿入追加として挿入シフトを依頼している' do
1414 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1415 Story.any_instance.stub(:insert_shift).with(any_args)
1416 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1421 context 'オブジェクトが新規でなくtが設定されているとき' do
1422 it 'コマ移動として入れ替えを依頼している' do
1423 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1424 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1425 Story.any_instance.stub(:update_shift).with(any_args)
1426 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1431 context 'オブジェクトが新規でなくtが空のとき' do
1432 it '入れ替えもシフトもせず、tを空のままにしている' do
1433 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1437 describe '編集許可に於いて' do
1439 @comic = FactoryGirl.create :comic, :author_id => @author.id
1440 @panel = FactoryGirl.create :panel, :author_id => @author.id
1441 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1443 context 'つつがなく終わるとき' do
1449 context 'コミックで引っかかるとき' do
1451 @story.comic_id = nil
1456 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1461 context 'コマで引っかかるとき' do
1463 @story.panel_id = nil
1468 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1474 describe '保存に於いて' do
1476 @comic = FactoryGirl.create :comic, :author_id => @author.id
1477 @panel = FactoryGirl.create :panel, :author_id => @author.id
1478 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1480 context 'つつがなく終わるとき' do
1481 it '編集許可チェックを依頼している' do
1482 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1483 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1486 it '順序入れ替えを依頼している' do
1487 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1488 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1489 Story.any_instance.stub(:save).with(any_args).and_return(true)
1490 Story.stub(:validate_t).with(any_args).and_return(true)
1494 Story.stub(:new_t).with(any_args).and_return(0)
1495 Story.any_instance.stub(:save).with(any_args).and_return(true)
1496 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1497 Story.stub(:validate_t).with(any_args).and_return(true)
1500 it 'tのシリアライズチェックを依頼している' do
1501 Story.stub(:new_t).with(any_args).and_return(0)
1502 Story.any_instance.stub(:save).with(any_args).and_return(true)
1503 Story.stub(:validate_t).with(any_args).and_return(true)
1504 Story.should_receive(:validate_t).with(any_args).exactly(1)
1508 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1509 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1511 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1512 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1513 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1514 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1515 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1516 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1517 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1518 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1520 it '既存のt0には変化がない' do
1523 @story.t.should eq 0
1525 it '既存のt1には変化がない' do
1528 @story2.t.should eq 1
1530 it '既存のt2を3にシフトしている' do
1533 @story3.t.should eq 3
1535 it '既存のt3を4にシフトしている' do
1538 @story4.t.should eq 4
1540 it '既存のt5を5にシフトしている' do
1543 @story5.t.should eq 5
1545 it '新規のt2が作成されている' do
1548 @story6.t.should eq 2
1550 it '他のコミックに影響がない' do
1554 @storyc2.t.should eq @ot
1557 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1559 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1560 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1561 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1562 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1563 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1564 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1565 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1569 it '既存のt0には変化がない' do
1572 @story.t.should eq 0
1574 it '既存のt4には変化がない' do
1577 @story5.t.should eq 4
1579 it '既存のt1を2にシフトしている' do
1582 @story2.t.should eq 2
1584 it '既存のt2を3にシフトしている' do
1587 @story3.t.should eq 3
1589 it '既存のt3を1にシフトしている' do
1592 @story4.t.should eq 1
1594 it '他のコミックに影響がない' do
1597 @storyc2.t.should eq 0
1600 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1602 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1603 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1604 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1605 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1606 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1607 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1608 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1612 it '既存のt0には変化がない' do
1615 @story.t.should eq 0
1617 it '既存のt4には変化がない' do
1620 @story5.t.should eq 4
1622 it '既存のt1を3にシフトしている' do
1625 @story2.t.should eq 3
1627 it '既存のt2を1にシフトしている' do
1630 @story3.t.should eq 1
1632 it '既存のt3を2にシフトしている' do
1635 @story4.t.should eq 2
1637 it '他のコミックに影響がない' do
1640 @storyc2.t.should eq 0
1643 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1644 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1646 Story.any_instance.stub(:save).with(any_args).and_return(false)
1647 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1648 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1649 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1650 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1651 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1652 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1653 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1654 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1659 @story.t.should eq 0
1661 @story2.t.should eq 1
1663 @story3.t.should eq 2
1665 @story4.t.should eq 3
1667 @story5.t.should eq 4
1669 @storyc2.t.should eq 0
1676 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1678 Story.stub(:validate_t).with(any_args).and_return(false)
1679 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1680 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1681 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1682 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1683 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1684 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1685 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1692 @story.t.should eq 0
1694 @story2.t.should eq 1
1696 @story3.t.should eq 2
1698 @story4.t.should eq 3
1700 @story5.t.should eq 4
1702 @storyc2.t.should eq 0
1705 r = @story4.store @ot
1708 it 'tにエラーメッセージが入っている' do
1710 @story4.errors[:t].should_not be_empty
1711 @story4.valid?.should be_true
1714 context '編集不可だったとき' do
1716 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1717 Story.any_instance.stub(:allow?).and_return(false)
1719 it '403Forbidden例外を返す' do
1722 }.should raise_error(ActiveRecord::Forbidden)
1726 describe '切り詰め処理つき削除に於いて' do
1728 @comic = FactoryGirl.create :comic, :author_id => @author.id
1729 @panel = FactoryGirl.create :panel, :author_id => @author.id
1730 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1732 context 'つつがなく終わるとき' do
1735 @story.destroy_and_shorten
1736 }.should change(Story, :count ).by(-1)
1739 r = @story.destroy_and_shorten
1743 context '削除に失敗したとき' do
1745 Story.any_instance.stub(:destroy).and_return(false)
1749 @story.destroy_and_shorten
1750 }.should_not change(Story, :count )
1753 r = @story.destroy_and_shorten
1757 #連携テスト。切り詰めが直接DBをいじる
1758 context '2件で先頭を削除したとき' do
1760 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1764 @story.destroy_and_shorten
1765 }.should change(Story, :count ).by(-1)
1768 @story.destroy_and_shorten
1770 Story.find @story.id
1771 }.should raise_error(ActiveRecord::RecordNotFound)
1774 @story.destroy_and_shorten
1776 @story2.t.should eq 0
1779 context '3件で先頭を削除したとき' do
1781 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1782 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1786 @story.destroy_and_shorten
1787 }.should change(Story, :count ).by(-1)
1790 @story.destroy_and_shorten
1792 Story.find @story.id
1793 }.should raise_error(ActiveRecord::RecordNotFound)
1796 @story.destroy_and_shorten
1798 @story2.t.should eq 0
1801 @story.destroy_and_shorten
1803 @story3.t.should eq 1
1806 context '5件で3件目を削除したとき' do
1808 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1809 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1810 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1811 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1815 @story3.destroy_and_shorten
1816 }.should change(Story, :count ).by(-1)
1819 @story3.destroy_and_shorten
1821 @story.t.should eq 0
1824 @story3.destroy_and_shorten
1826 @story2.t.should eq 1
1829 @story3.destroy_and_shorten
1831 Story.find @story3.id
1832 }.should raise_error(ActiveRecord::RecordNotFound)
1835 @story3.destroy_and_shorten
1837 @story4.t.should eq 2
1840 @story3.destroy_and_shorten
1842 @story5.t.should eq 3
1845 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する