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
491 describe '自分のストーリー一覧取得に於いて' do
493 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
494 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
495 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
496 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
497 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
498 @hcomic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
499 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
501 context 'つつがなく終わるとき' do
502 it '一覧取得オプションを利用している' do
503 Story.stub(:list_opt).with(any_args).and_return({})
504 Story.should_receive(:list_opt).with(any_args).exactly(1)
505 r = Story.mylist @author
509 s = Story.mylist @author
513 ns = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
514 sl = Story.mylist @author
515 sl.should eq [ns, @story]
517 it '他人のストーリーはコマコミックともに公開でも含まない' do
518 so = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
519 sl = Story.mylist @author
520 sl.should eq [@story]
522 it '自分のストーリーはコマコミックともに非公開でも含んでいる' do
523 hs = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @hcomic.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
524 sl = Story.mylist @author
525 sl.should eq [hs, @story]
527 context 'DBに5件あって1ページの件数を2件に変えたとして' do
529 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
530 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
531 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
532 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
533 Story.stub(:default_page_size).and_return(2)
536 l = Story.mylist @author, 1, 2
537 l.should have(2).items
539 it 'page=1なら末尾2件を返す' do
541 l = Story.mylist @author, 1, 2
542 l.should eq [@story5, @story4]
544 it 'page=2なら中間2件を返す' do
545 l = Story.mylist @author, 2, 2
546 l.should eq [@story3, @story2]
548 it 'page=3なら先頭1件を返す' do
549 l = Story.mylist @author, 3, 2
553 context 'DBに5件あって1ページの件数を2件に変えたとして' do
555 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
556 @story3 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
557 @story4 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
558 @story5 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
559 Author.stub(:default_story_page_size).and_return(2)
561 it '件数0は全件(5件)を返す' do
562 r = Story.mylist @author, 5, 0
563 r.should have(5).items
568 describe '他作家のストーリー一覧取得に於いて' do
570 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
571 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
572 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
573 @other_comic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
574 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
575 @other_story = FactoryGirl.create :story, :author_id => @other_author.id, :comic_id => @other_comic.id, :panel_id => @other_panel.id
578 r = Story.himlist @other_author
579 r.should eq [@other_story]
582 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
583 r = Story.himlist @other_author
584 r.should eq [ns, @other_story]
587 @hcomic = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 0
588 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
589 r = Story.himlist @other_author
590 r.should eq [@other_story]
592 context 'DBに5件あって1ページの件数を2件に変えたとして' do
594 @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
595 @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
596 @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
597 @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
598 Story.stub(:default_page_size).and_return(2)
601 l = Story.himlist @other_author, 1, 2
602 l.should have(2).items
604 it 'page=1なら末尾2件を返す' do
606 l = Story.himlist @other_author, 1, 2
607 l.should eq [@other_story5, @other_story4]
609 it 'page=2なら中間2件を返す' do
610 l = Story.himlist @other_author, 2, 2
611 l.should eq [@other_story3, @other_story2]
613 it 'page=3なら先頭1件を返す' do
614 l = Story.himlist @other_author, 3, 2
615 l.should eq [@other_story]
618 context 'DBに5件あって1ページの件数を2件に変えたとして' do
620 @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
621 @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
622 @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
623 @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
624 Author.stub(:default_story_page_size).and_return(2)
626 it '件数0は全件(5件)を返す' do
627 r = Story.himlist @other_author, 5, 0
628 r.should have(5).items
633 describe '単体取得に於いて' do
635 @comic = FactoryGirl.create :comic, :author_id => @author.id
636 @panel = FactoryGirl.create :panel, :author_id => @author.id
637 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
639 context 'つつがなく終わるとき' do
640 it '単体取得オプションを利用している' do
641 Story.stub(:show_opt).with(any_args).and_return({})
642 Story.should_receive(:show_opt).with(any_args).exactly(1)
643 r = Story.show @story.id, @author
645 it '閲覧許可を問い合わせている' do
646 Story.any_instance.stub(:visible?).with(@author).and_return(true)
647 Story.any_instance.should_receive(:visible?).with(@author).exactly(1)
648 r = Story.show @story.id, @author
652 l = Story.show @story.id, @author
655 context '他人のストーリーを開こうとしたとき' do
656 it '403Forbidden例外を返す' do
657 Story.any_instance.stub(:visible?).with(@other_author).and_return(false)
659 Story.show @story.id, @other_author
660 }.should raise_error(ActiveRecord::Forbidden)
663 context '存在しないストーリーを開こうとしたとき' do
664 it '404RecordNotFound例外を返す' do
666 Story.show 110, @author
667 }.should raise_error(ActiveRecord::RecordNotFound)
672 describe '編集取得に於いて' do
674 @comic = FactoryGirl.create :comic, :author_id => @author.id
675 @panel = FactoryGirl.create :panel, :author_id => @author.id
676 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
678 context 'つつがなく終わるとき' do
679 it '単体取得オプションを利用している' do
680 Story.stub(:show_opt).with(any_args).and_return({})
681 Story.should_receive(:show_opt).with(any_args).exactly(1)
682 r = Story.edit @story.id, @author
684 it '所持判定を問い合わせている' do
685 Story.any_instance.stub(:own?).with(any_args).and_return(true)
686 Story.any_instance.should_receive(:own?).with(any_args).exactly(1)
687 r = Story.edit @story.id, @author
691 l = Story.edit @story.id, @author
694 context '他人のストーリーを開こうとしたとき' do
695 it '403Forbidden例外を返す' do
696 Story.any_instance.stub(:own?).and_return(false)
698 Story.edit @story.id, @author
699 }.should raise_error(ActiveRecord::Forbidden)
702 context '存在しないストーリーを開こうとしたとき' do
703 it '404RecordNotFound例外を返す' do
705 Story.edit 110, @author
706 }.should raise_error(ActiveRecord::RecordNotFound)
711 describe '単体取得オプションに於いて' do
712 it 'includeキーを含んでいる' do
714 r.has_key?(:include).should be_true
717 r = Story.show_opt[:include]
718 r.should have(3).items
721 r = Story.show_opt[:include]
722 r.has_key?(:comic).should be_true
724 it 'コミックは作家を含んでいる' do
725 r = Story.show_opt[:include]
726 r[:comic].has_key?(:author).should be_true
729 r = Story.show_opt[:include]
730 r.has_key?(:author).should be_true
733 r = Story.show_opt[:include]
734 r.has_key?(:panel).should be_true
737 r = Story.show_opt[:include]
738 r[:panel].has_key?(:author).should be_true
741 r = Story.show_opt[:include]
742 r[:panel].has_key?(:panel_pictures).should be_true
744 it 'コマ絵は実素材を含んでいる' do
745 r = Story.show_opt[:include]
746 r[:panel][:panel_pictures].has_key?(:picture).should be_true
749 r = Story.show_opt[:include]
750 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
752 it '実素材はライセンスを含んでいる' do
753 r = Story.show_opt[:include]
754 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
756 it 'コマはフキダシを含んでいる' do
757 r = Story.show_opt[:include]
758 r[:panel].has_key?(:speech_balloons).should be_true
760 it 'フキダシはフキダシ枠を含んでいる' do
761 r = Story.show_opt[:include]
762 r[:panel][:speech_balloons].has_key?(:balloons).should be_true
764 it 'フキダシはセリフを含んでいる' do
765 r = Story.show_opt[:include]
766 r[:panel][:speech_balloons].has_key?(:speeches).should be_true
769 describe 'json単体取得オプションに於いて' do
772 describe 'ストーリーのjson出力に於いて' do
775 @panel = FactoryGirl.create :panel, :author_id => @author.id
776 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
777 @sb = @panel.speech_balloons.create(
778 FactoryGirl.attributes_for(:speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @sbt.id, :t => 0)
780 @gc = @panel.ground_colors.create(
781 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id, :color_id => @color.id)
783 @gp = @panel.ground_pictures.create(
784 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
786 @pc = @panel.panel_colors.create(
787 FactoryGirl.attributes_for(:panel_color, :panel_id => @panel.id, :code => 0xff0000)
790 @comic = FactoryGirl.create :comic, :author_id => @author.id
791 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
793 context '事前チェックする' do
795 Panel.any_instance.stub(:elements).and_return('{}')
797 it 'コマ要素のjson出力を依頼している' do
798 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
799 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
800 r = @story.story_as_json @author
803 it 'json textを返している' do
804 r = JSON.parse @story.story_as_json(@author)
805 r.is_a?(Hash).should be_true
807 it 'comic,author,panel,コマ要素を含んでいる' do
808 r = JSON.parse @story.story_as_json(@author)
809 r.has_key?('comic').should be_true
810 r['comic'].has_key?('author').should be_true
811 r.has_key?('author').should be_true
812 r.has_key?('panel').should be_true
813 r['panel'].has_key?('author').should be_true
815 context 'コマ閲覧許可のとき' do
817 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
819 it 'コマ要素にコマ要素を追加している' do
820 r = JSON.parse @story.story_as_json(@author)
821 r['panel'].has_key?('elements').should be_true
822 r['panel']['elements'].should_not be_empty
825 context 'コマ閲覧不許可のとき' do
827 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
829 it 'コマ要素にデータを含ませない' do
830 r = JSON.parse @story.story_as_json(@author)
831 r['panel'].has_key?('elements').should be_false
836 describe 'ストーリーリストのjson出力に於いて' do
838 @panel = FactoryGirl.create :panel, :author_id => @author.id
839 @comic = FactoryGirl.create :comic, :author_id => @author.id
840 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
841 Story.any_instance.stub(:story_as_json).with(@author).and_return('{"s": 5}')
843 context 'つつがなく終わるとき' do
844 it 'ストーリーのjson出力を依頼している' do
845 Story.any_instance.should_receive(:story_as_json).with(@author).exactly(1)
846 r = Story.list_as_json_text [@story], @author
849 it 'json textを返している' do
850 r = Story.list_as_json_text [@story], @author
852 j.is_a?(Array).should be_true
855 r = Story.list_as_json_text [@story], @author
857 j.first.has_key?('s').should be_true
861 describe 'ライセンス素材に於いて' do
864 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
865 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
866 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
867 @panel = FactoryGirl.create :panel, :author_id => @author.id
868 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id
870 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
871 @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id
874 @comic = FactoryGirl.create :comic, :author_id => @author.id
875 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
876 @story2 = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel2.id
880 context 'つつがなく終わるとき' do
882 it '連想配列(値は実素材、キーは実素材id)を返している' do
883 r = Story.licensed_pictures [@story, @story2]
884 r.is_a?(Hash).should be_true
885 r.should have(2).items
886 r[@pp.picture_id].should eq @p
887 r[@pp2.picture_id].should eq @p2
889 context 'コマが削除されているときき' do
893 it '削除されているコマは無視する' do
894 r = Story.licensed_pictures [@story, @story2]
895 r.is_a?(Hash).should be_true
896 r.should have(1).items
897 r[@pp.picture_id].should eq @p
898 r[@pp2.picture_id].should be_nil
903 describe 't補充値に於いて' do
905 @comic = FactoryGirl.create :comic, :author_id => @author.id
906 @panel = FactoryGirl.create :panel, :author_id => @author.id
909 context 'コミック初のコマなら' do
911 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
913 r = Story.new_t @story.comic_id
917 context 'コミックに一個コマがあるとき' do
919 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
920 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
922 r = Story.new_t @story.comic_id
926 context 'コミックに2個コマがあるとき' do
928 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 0
929 FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id, :t => 1
930 @story = FactoryGirl.build :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
932 r = Story.new_t @story.comic_id
937 describe 'シリアライズチェックに於いて' do
938 context 'つつがなく終わるとき' do
939 it '0からシリアライズされているならTrueを返す' do
940 r = Story.serial? [0, 1, 2]
943 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
944 r = Story.serial? [0, 2, 1]
947 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
948 r = Story.serial? [ 2, 1, 4, 3, 0]
953 it '0から始まらないならFalseを返す' do
954 r = Story.serial? [1, 2, 3]
957 it '連続していないならFalseを返す' do
958 r = Story.serial? [0, 1, 2, 4]
961 it '連続していないならFalseを返す' do
962 r = Story.serial? [0, 1, 2, 4, 5]
967 describe 't収集に於いて' do
969 @comic = FactoryGirl.create :comic, :author_id => @author.id
970 @panel = FactoryGirl.create :panel, :author_id => @author.id
971 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
972 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
973 @c2story = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
975 context 'つつがなく終わるとき' do
976 it 'ストーリーから同一コミックのtだけを収集している' do
977 r = Story.collect_t @story
982 it 'ストーリーから同一コミックのtだけを収集している' do
983 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
984 r = Story.collect_t @story
985 r.sort.should eq [0, 1]
988 context '複数コマでヨソのコミックも混じっているとき' do
989 it 'ストーリーから同一コミックのtだけを収集している' do
990 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
991 r = Story.collect_t @story
992 r.sort.should eq [0, 1]
996 describe 'tチェックに於いて' do
998 @comic = FactoryGirl.create :comic, :author_id => @author.id
999 @panel = FactoryGirl.create :panel, :author_id => @author.id
1000 @story = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1002 context 'つつがなく終わるとき' do
1004 Story.should_receive(:collect_t).with(any_args).exactly(1)
1005 Story.stub(:collect_t).with(any_args).and_return([])
1006 Story.stub(:serial?).with(any_args).and_return(true)
1007 r = Story.validate_t @story
1009 it '収集したtをシリアライズチェック依頼している' do
1010 Story.stub(:collect_t).with(any_args).and_return([])
1011 Story.should_receive(:serial?).with(any_args).exactly(1)
1012 Story.stub(:serial?).with(any_args).and_return(true)
1013 r = Story.validate_t @story
1017 #依頼チェックだけでは不安なので最低限のチェックを
1019 it '一件だけで正常通過している' do
1020 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1021 r = Story.validate_t @story
1026 it '2件目を作っても正常通過している' do
1027 @story = FactoryGirl.create :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1028 @story2 = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
1029 r = Story.validate_t @story2
1034 describe '挿入シフトに於いて' do
1036 @comic = FactoryGirl.create :comic, :author_id => @author.id
1037 @panel = FactoryGirl.create :panel, :author_id => @author.id
1041 it 'Updateを依頼している' do
1042 Story.stub(:update_all).with(any_args)
1043 Story.should_receive(:update_all).with(any_args).exactly(1)
1044 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1048 context 'テーブルに1件(t:0)で0に挿入したとき' do
1050 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1051 @story2 = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1053 it '既存の行を1にシフトしている' do
1054 @story2.insert_shift
1056 l.first.t.should eq 1
1058 it 'これから挿入するt(0)が欠番になっている' do
1059 @story2.insert_shift
1060 l = Story.find(:all).map {|s| s.t }
1061 l.include?(0).should_not be_true
1064 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
1066 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1067 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1068 @story3 = FactoryGirl.build :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1070 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1071 @story3.insert_shift
1072 l = Story.find(:all).map {|s| s.t }
1073 l.sort.should eq [0, 2]
1076 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
1078 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1079 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1080 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1081 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1082 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1083 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1085 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1086 @story6.insert_shift
1087 l = Story.find(:all).map {|s| s.t }
1088 l.sort.should eq [0, 1, 3, 4, 5]
1091 context '先ほどのケース+他のコミック1件で挿入したとき' do
1093 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1094 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1095 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1096 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1097 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1098 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1099 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1100 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1102 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1103 @story6.insert_shift
1104 l = Story.find(:all, :conditions => ['comic_id = ?', @comic.id]).map {|s| s.t }
1105 l.sort.should eq [0, 1, 3, 4, 5]
1107 it '他のコミックに影響がない' do
1109 @story6.insert_shift
1111 @storyc2.t.should eq ot
1115 describe '少ない方に移動に於いて' do
1117 @comic = FactoryGirl.create :comic, :author_id => @author.id
1118 @panel = FactoryGirl.create :panel, :author_id => @author.id
1121 it 'Updateを依頼している' do
1122 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1123 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1124 Story.stub(:update_all).with(any_args)
1125 Story.should_receive(:update_all).with(any_args).exactly(1)
1128 @story2.lesser_shift ot
1131 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
1133 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1134 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1138 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1140 @story2.lesser_shift @ot
1141 l = Story.find(:all).map {|s| s.t }
1142 l.sort.should eq [1, 1]
1144 it '既存のt0を1にシフトしている' do
1145 @story2.lesser_shift @ot
1147 @story.t.should eq 1
1150 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
1152 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1153 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1154 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1158 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1160 @story3.lesser_shift @ot
1161 l = Story.find(:all).map {|s| s.t }
1162 l.sort.should eq [0, 2, 2]
1164 it '既存のt1を2にシフトしている' do
1165 @story3.lesser_shift @ot
1167 @story2.t.should eq 2
1170 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
1172 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1173 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1174 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1175 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1176 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1180 it 'これから挿入するt(1)が欠番になっている' do
1182 @story4.lesser_shift @ot
1183 l = Story.find(:all).map {|s| s.t }
1184 l.sort.should eq [0, 2, 3, 3, 4]
1186 it '既存のt0には変化がない' do
1187 @story4.lesser_shift @ot
1189 @story.t.should eq 0
1191 it '既存のt4には変化がない' do
1192 @story4.lesser_shift @ot
1194 @story5.t.should eq 4
1196 it '既存のt1を2にシフトしている' do
1197 @story4.lesser_shift @ot
1199 @story2.t.should eq 2
1201 it '既存のt2を3にシフトしている' do
1202 @story4.lesser_shift @ot
1204 @story3.t.should eq 3
1207 context '先ほどのケース+他のコミック1件で挿入したとき' do
1209 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1210 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1211 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1212 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1213 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1214 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1215 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1219 it 'これから挿入するt(1)が欠番になっている' do
1220 @story4.lesser_shift @ot
1221 l = Story.find(:all).map {|s| s.t }
1222 l.sort.should eq [0, 0, 2, 3, 3, 4]
1224 it '既存のt0には変化がない' do
1225 @story4.lesser_shift @ot
1227 @story.t.should eq 0
1229 it '既存のt4には変化がない' do
1230 @story4.lesser_shift @ot
1232 @story5.t.should eq 4
1234 it '既存のt1を2にシフトしている' do
1235 @story4.lesser_shift @ot
1237 @story2.t.should eq 2
1239 it '既存のt2を3にシフトしている' do
1240 @story4.lesser_shift @ot
1242 @story3.t.should eq 3
1244 it '他のコミックに影響がない' do
1245 @story4.lesser_shift @ot
1247 @storyc2.t.should eq 0
1252 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
1254 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1255 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1259 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1261 @story2.lesser_shift @ot
1262 l = Story.find(:all).map {|s| s.t }
1263 l.sort.should eq [1, 1]
1265 it '既存のt0を1にシフトしている' do
1266 @story2.lesser_shift @ot
1268 @story.t.should eq 1
1270 it '既存のt1は0に補正されている' do
1271 @story2.lesser_shift @ot
1272 @story2.t.should eq 0
1276 describe '大きい方に移動に於いて' do
1278 @comic = FactoryGirl.create :comic, :author_id => @author.id
1279 @panel = FactoryGirl.create :panel, :author_id => @author.id
1282 it 'Updateを依頼している' do
1283 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1284 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1285 Story.stub(:update_all).with(any_args)
1286 Story.should_receive(:update_all).with(any_args).exactly(1)
1289 @story.higher_shift ot
1292 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1294 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1295 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1299 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1301 @story.higher_shift @ot
1302 l = Story.find(:all).map {|s| s.t }
1303 l.sort.should eq [0, 0]
1305 it '既存のt1を0にシフトしている' do
1306 @story.higher_shift @ot
1308 @story2.t.should eq 0
1311 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1313 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1314 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1315 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1319 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1321 @story.higher_shift @ot
1322 l = Story.find(:all).map {|s| s.t }
1323 l.sort.should eq [0, 0, 2]
1325 it '既存のt1を0にシフトしている' do
1326 @story.higher_shift @ot
1328 @story2.t.should eq 0
1331 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1333 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1334 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1335 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1336 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1337 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1341 it 'これから挿入するt(3)が欠番になっている' do
1343 @story2.higher_shift @ot
1344 l = Story.find(:all).map {|s| s.t }
1345 l.sort.should eq [0, 1, 1, 2, 4]
1347 it '既存のt0には変化がない' do
1348 @story2.higher_shift @ot
1350 @story.t.should eq 0
1352 it '既存のt4には変化がない' do
1353 @story2.higher_shift @ot
1355 @story5.t.should eq 4
1357 it '既存のt2を1にシフトしている' do
1358 @story2.higher_shift @ot
1360 @story3.t.should eq 1
1362 it '既存のt3を2にシフトしている' do
1363 @story2.higher_shift @ot
1365 @story4.t.should eq 2
1368 context '先ほどのケース+他のコミック1件で挿入したとき' do
1370 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1371 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1372 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1373 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1374 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1375 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1376 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1380 it 'これから挿入するt(3)が欠番になっている' do
1382 @story2.higher_shift @ot
1383 l = Story.find(:all).map {|s| s.t }
1384 l.sort.should eq [0, 0, 1, 1, 2, 4]
1386 it '既存のt0には変化がない' do
1387 @story2.higher_shift @ot
1389 @story.t.should eq 0
1391 it '既存のt4には変化がない' do
1392 @story2.higher_shift @ot
1394 @story5.t.should eq 4
1396 it '既存のt2を1にシフトしている' do
1397 @story2.higher_shift @ot
1399 @story3.t.should eq 1
1401 it '既存のt3を2にシフトしている' do
1402 @story2.higher_shift @ot
1404 @story4.t.should eq 2
1406 it '他のコミックに影響がない' do
1407 @story2.higher_shift @ot
1409 @storyc2.t.should eq 0
1413 #max超えたときはmaxとして正常扱い
1414 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1416 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1417 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1421 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1423 @story.higher_shift @ot
1424 l = Story.find(:all).map {|s| s.t }
1425 l.sort.should eq [0, 0]
1427 it '既存のt1を0にシフトしている' do
1428 @story.higher_shift @ot
1430 @story2.t.should eq 0
1432 it '既存のt0は1に補正されている' do
1433 @story.higher_shift @ot
1434 @story.t.should eq 1
1438 describe '入れ替えに於いて' do
1440 @comic = FactoryGirl.create :comic, :author_id => @author.id
1441 @panel = FactoryGirl.create :panel, :author_id => @author.id
1442 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1443 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1445 context '新tが旧tより小さいとき' do
1446 it '少ない方に移動を依頼している' do
1447 Story.any_instance.stub(:lesser_shift).with(any_args)
1448 Story.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1451 @story2.update_shift ot
1454 context '新tが旧tより大きいとき' do
1455 it '大きい方に移動を依頼している' do
1456 Story.any_instance.stub(:higher_shift).with(any_args)
1457 Story.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1460 @story.update_shift ot
1464 describe '順序入れ替えに於いて' do
1466 @comic = FactoryGirl.create :comic, :author_id => @author.id
1467 @panel = FactoryGirl.create :panel, :author_id => @author.id
1469 context 'オブジェクトが新規でtが空のとき' do
1470 it '末尾追加としてtを補充依頼している' do
1471 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1472 Story.stub(:new_t).with(any_args).and_return(0)
1473 Story.should_receive(:new_t).with(any_args).exactly(1)
1478 context 'オブジェクトが新規でtが設定されているとき' do
1479 it '挿入追加として挿入シフトを依頼している' do
1480 @story = FactoryGirl.build :story, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1481 Story.any_instance.stub(:insert_shift).with(any_args)
1482 Story.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1487 context 'オブジェクトが新規でなくtが設定されているとき' do
1488 it 'コマ移動として入れ替えを依頼している' do
1489 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1490 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1491 Story.any_instance.stub(:update_shift).with(any_args)
1492 Story.any_instance.should_receive(:update_shift).with(1).exactly(1)
1497 context 'オブジェクトが新規でなくtが空のとき' do
1498 it '入れ替えもシフトもせず、tを空のままにしている' do
1499 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1503 describe '編集許可に於いて' do
1505 @comic = FactoryGirl.create :comic, :author_id => @author.id
1506 @panel = FactoryGirl.create :panel, :author_id => @author.id
1507 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1509 context 'つつがなく終わるとき' do
1515 context 'コミックで引っかかるとき' do
1517 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1518 Comic.any_instance.stub(:own?).with(any_args).and_return(false)
1523 context 'コマで引っかかるとき' do
1525 Comic.any_instance.stub(:own?).with(any_args).and_return(true)
1526 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1531 context 'コミックまたはコマが指定されていなかったとき' do
1533 Comic.any_instance.stub(:own?).with(any_args).and_return(true)
1534 @story.panel_id = nil
1539 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1540 @story.comic_id = nil
1546 describe '保存に於いて' do
1548 @comic = FactoryGirl.create :comic, :author_id => @author.id
1549 @panel = FactoryGirl.create :panel, :author_id => @author.id
1550 @story = FactoryGirl.build :story, :t => nil, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1552 context 'つつがなく終わるとき' do
1553 it '編集許可チェックを依頼している' do
1554 Story.any_instance.stub(:allow?).with(any_args).and_return(true)
1555 Story.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1558 it '順序入れ替えを依頼している' do
1559 Story.any_instance.stub(:rotate).with(any_args).and_return(0)
1560 Story.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1561 Story.any_instance.stub(:save).with(any_args).and_return(true)
1562 Story.stub(:validate_t).with(any_args).and_return(true)
1566 Story.stub(:new_t).with(any_args).and_return(0)
1567 Story.any_instance.stub(:save).with(any_args).and_return(true)
1568 Story.any_instance.should_receive(:save).with(any_args).exactly(1)
1569 Story.stub(:validate_t).with(any_args).and_return(true)
1572 it 'tのシリアライズチェックを依頼している' do
1573 Story.stub(:new_t).with(any_args).and_return(0)
1574 Story.any_instance.stub(:save).with(any_args).and_return(true)
1575 Story.stub(:validate_t).with(any_args).and_return(true)
1576 Story.should_receive(:validate_t).with(any_args).exactly(1)
1580 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1581 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したとき' do
1583 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1584 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1585 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1586 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1587 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1588 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1589 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1590 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1592 it '既存のt0には変化がない' do
1595 @story.t.should eq 0
1597 it '既存のt1には変化がない' do
1600 @story2.t.should eq 1
1602 it '既存のt2を3にシフトしている' do
1605 @story3.t.should eq 3
1607 it '既存のt3を4にシフトしている' do
1610 @story4.t.should eq 4
1612 it '既存のt5を5にシフトしている' do
1615 @story5.t.should eq 5
1617 it '新規のt2が作成されている' do
1620 @story6.t.should eq 2
1622 it '他のコミックに影響がない' do
1626 @storyc2.t.should eq @ot
1629 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したとき' do
1631 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1632 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1633 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1634 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1635 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1636 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1637 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1641 it '既存のt0には変化がない' do
1644 @story.t.should eq 0
1646 it '既存のt4には変化がない' do
1649 @story5.t.should eq 4
1651 it '既存のt1を2にシフトしている' do
1654 @story2.t.should eq 2
1656 it '既存のt2を3にシフトしている' do
1659 @story3.t.should eq 3
1661 it '既存のt3を1にシフトしている' do
1664 @story4.t.should eq 1
1666 it '他のコミックに影響がない' do
1669 @storyc2.t.should eq 0
1672 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で1を3に移動したとき' do
1674 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1675 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1676 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1677 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1678 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1679 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1680 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1684 it '既存のt0には変化がない' do
1687 @story.t.should eq 0
1689 it '既存のt4には変化がない' do
1692 @story5.t.should eq 4
1694 it '既存のt1を3にシフトしている' do
1697 @story2.t.should eq 3
1699 it '既存のt2を1にシフトしている' do
1702 @story3.t.should eq 1
1704 it '既存のt3を2にシフトしている' do
1707 @story4.t.should eq 2
1709 it '他のコミックに影響がない' do
1712 @storyc2.t.should eq 0
1715 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1716 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で2に挿入したが保存に失敗したとき' do
1718 Story.any_instance.stub(:save).with(any_args).and_return(false)
1719 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1720 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1721 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1722 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1723 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1724 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1725 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1726 @story6 = FactoryGirl.build :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1731 @story.t.should eq 0
1733 @story2.t.should eq 1
1735 @story3.t.should eq 2
1737 @story4.t.should eq 3
1739 @story5.t.should eq 4
1741 @storyc2.t.should eq 0
1748 context 'テーブルに5件(t:0,1,2,3,4)+他のコミック1件で3を1に移動したがシリアルチェックに失敗したとき' do
1750 Story.stub(:validate_t).with(any_args).and_return(false)
1751 @comic2 = FactoryGirl.create :comic, :author_id => @author.id
1752 @storyc2 = FactoryGirl.create :story, :t => 0, :comic_id => @comic2.id, :panel_id => @panel.id, :author_id => @author.id
1753 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1754 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1755 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1756 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1757 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1764 @story.t.should eq 0
1766 @story2.t.should eq 1
1768 @story3.t.should eq 2
1770 @story4.t.should eq 3
1772 @story5.t.should eq 4
1774 @storyc2.t.should eq 0
1777 r = @story4.store @ot
1780 it 'tにエラーメッセージが入っている' do
1782 @story4.errors[:t].should_not be_empty
1783 @story4.valid?.should be_true
1786 context '編集不可だったとき' do
1788 @story = FactoryGirl.build :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1789 Story.any_instance.stub(:allow?).and_return(false)
1791 it '403Forbidden例外を返す' do
1794 }.should raise_error(ActiveRecord::Forbidden)
1798 describe '切り詰め処理つき削除に於いて' do
1800 @comic = FactoryGirl.create :comic, :author_id => @author.id
1801 @panel = FactoryGirl.create :panel, :author_id => @author.id
1802 @story = FactoryGirl.create :story, :t => 0, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1804 context 'つつがなく終わるとき' do
1807 @story.destroy_and_shorten
1808 }.should change(Story, :count ).by(-1)
1811 r = @story.destroy_and_shorten
1815 context '削除に失敗したとき' do
1817 Story.any_instance.stub(:destroy).and_return(false)
1821 @story.destroy_and_shorten
1822 }.should_not change(Story, :count )
1825 r = @story.destroy_and_shorten
1829 #連携テスト。切り詰めが直接DBをいじる
1830 context '2件で先頭を削除したとき' do
1832 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1836 @story.destroy_and_shorten
1837 }.should change(Story, :count ).by(-1)
1840 @story.destroy_and_shorten
1842 Story.find @story.id
1843 }.should raise_error(ActiveRecord::RecordNotFound)
1846 @story.destroy_and_shorten
1848 @story2.t.should eq 0
1851 context '3件で先頭を削除したとき' do
1853 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1854 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1858 @story.destroy_and_shorten
1859 }.should change(Story, :count ).by(-1)
1862 @story.destroy_and_shorten
1864 Story.find @story.id
1865 }.should raise_error(ActiveRecord::RecordNotFound)
1868 @story.destroy_and_shorten
1870 @story2.t.should eq 0
1873 @story.destroy_and_shorten
1875 @story3.t.should eq 1
1878 context '5件で3件目を削除したとき' do
1880 @story2 = FactoryGirl.create :story, :t => 1, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1881 @story3 = FactoryGirl.create :story, :t => 2, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1882 @story4 = FactoryGirl.create :story, :t => 3, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1883 @story5 = FactoryGirl.create :story, :t => 4, :comic_id => @comic.id, :panel_id => @panel.id, :author_id => @author.id
1887 @story3.destroy_and_shorten
1888 }.should change(Story, :count ).by(-1)
1891 @story3.destroy_and_shorten
1893 @story.t.should eq 0
1896 @story3.destroy_and_shorten
1898 @story2.t.should eq 1
1901 @story3.destroy_and_shorten
1903 Story.find @story3.id
1904 }.should raise_error(ActiveRecord::RecordNotFound)
1907 @story3.destroy_and_shorten
1909 @story4.t.should eq 2
1912 @story3.destroy_and_shorten
1914 @story5.t.should eq 3
1917 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する