1 # -*- encoding: utf-8 -*-
4 describe ScrollPanel do
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 SpeechBalloonTemplate.delete_all
11 @speech_balloon_template = FactoryGirl.create :speech_balloon_template, "name" => "circle@pettan.com", "classname" => "CircleSpeechBalloon", "caption" => "cc", "system_picture_id" => @sp.id, "settings" => '{}'
12 @writing_format = FactoryGirl.create :writing_format
13 @user = FactoryGirl.create( :user_yas)
14 @author = FactoryGirl.create :author, :user_id => @user.id
15 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
16 @other_user = FactoryGirl.create( :user_yas)
17 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
18 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
19 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
20 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
25 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
26 @panel = FactoryGirl.create :panel, :author_id => @author.id
27 @scroll_panel = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
30 context 'オーソドックスなデータのとき' do
33 @scroll_panel.should be_valid
36 @scroll_panel.t = 99999
37 @scroll_panel.should be_valid
41 context 'scroll_idを検証するとき' do
43 @scroll_panel.scroll_id = nil
44 @scroll_panel.should_not be_valid
47 @scroll_panel.scroll_id = 'a'
48 @scroll_panel.should_not be_valid
50 it '存在するスクロールでなければ失敗する' do
51 @scroll_panel.scroll_id = 0
52 @scroll_panel.should_not be_valid
56 context 'panel_idを検証するとき' do
58 @scroll_panel.panel_id = nil
59 @scroll_panel.should_not be_valid
62 @scroll_panel.panel_id = 'a'
63 @scroll_panel.should_not be_valid
65 it '存在するコマでなければ失敗する' do
66 @scroll_panel.panel_id = 0
67 @scroll_panel.should_not be_valid
74 @scroll_panel.should_not be_valid
78 @scroll_panel.should_not be_valid
82 @scroll_panel.should_not be_valid
86 context 'author_idを検証するとき' do
88 @scroll_panel.author_id = nil
89 @scroll_panel.should_not be_valid
92 @scroll_panel.author_id = 'a'
93 @scroll_panel.should_not be_valid
95 it '存在する作家でなければ失敗する' do
96 @scroll_panel.author_id = 0
97 @scroll_panel.should_not be_valid
100 context '全体を検証するとき' do
104 describe 'デフォルト値補充に於いて' do
106 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
107 @panel = FactoryGirl.create :panel, :author_id => @author.id
110 #dbのデフォルト値が0だから明示的にnilにしないと追加ができない
112 @scroll_panel = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id
113 @scroll_panel.supply_default
114 @scroll_panel.t.should be_nil
119 describe '上書き補充に於いて' do
121 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
122 @panel = FactoryGirl.create :panel, :author_id => @author.id
125 context 'author_idを補充' do
126 it '問答無用でauthor_idを補充する' do
127 @scroll_panel = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id
128 @scroll_panel.author_id = nil
129 @scroll_panel.overwrite @author
130 @scroll_panel.author_id.should eq @author.id
136 describe '所持判定に於いて' do
138 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
139 @panel = FactoryGirl.create :panel, :author_id => @author.id
140 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
141 @scrollo = FactoryGirl.create :scroll, :author_id => @other_author.id
142 @panelo = FactoryGirl.create :panel, :author_id => @other_author.id
143 @scroll_panelo = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @scrollo.id, :panel_id => @panelo.id
145 context '事前チェックする' do
146 it '自身にロールリストからの作家取得を依頼している' do
147 ScrollPanel.should_receive(:get_author_from_roles).with(any_args).exactly(1)
148 r = @scroll_panel.own?([@author])
151 context 'ロール内作家が取得できるとき' do
154 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
155 ScrollPanel.stub(:get_author_from_roles).with(any_args).and_return(@author)
156 r = @scroll_panel.own?([@author])
159 it 'ロール内作家のidが自身の作家idと一致しないならno' do
160 ScrollPanel.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
161 @scroll_panel.own?(@other_author).should be_false
164 context 'ロール内作家が取得できないとき' do
166 ScrollPanel.stub(:get_author_from_roles).with(any_args).and_return(nil)
169 r = @scroll_panel.own?([@author])
175 describe '閲覧許可に於いて' do
177 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
178 @panel = FactoryGirl.create :panel, :author_id => @author.id
179 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
181 context 'オープンモードのとき' do
183 MagicNumber['run_mode'] = 0
185 it '自身にゲスト用ロールチェックを問い合わせしている' do
186 ScrollPanel.any_instance.stub(:guest_role_check).and_return(true)
187 ScrollPanel.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
188 r = @scroll_panel.visible?([@author])
190 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
191 ScrollPanel.any_instance.stub(:guest_role_check).and_return(false)
192 r = @scroll_panel.visible?([@author])
196 context 'クローズドモードのとき' do
198 MagicNumber['run_mode'] = 1
200 it '自身に読者用ロールチェックを問い合わせしている' do
201 ScrollPanel.any_instance.stub(:reader_role_check).and_return(true)
202 ScrollPanel.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
203 r = @scroll_panel.visible?([@author])
205 it '読者用ロールチェックが失敗したとき、falseを返す' do
206 ScrollPanel.any_instance.stub(:reader_role_check).and_return(false)
207 r = @scroll_panel.visible?([@author])
211 context '事前チェックする' do
213 MagicNumber['run_mode'] = 1
214 ScrollPanel.any_instance.stub(:reader_role_check).and_return(true)
216 it '自身のスクロールに所持判定を問い合わせしている' do
217 Scroll.any_instance.stub(:own?).and_return(true)
218 Scroll.any_instance.should_receive(:own?).with(any_args).exactly(1)
219 r = @scroll_panel.visible?([@author])
221 it '自身のスクロールに閲覧許可を問い合わせしている' do
222 Scroll.any_instance.stub(:own?).and_return(false)
223 Scroll.any_instance.stub(:visible?).and_return(true)
224 Scroll.any_instance.should_receive(:visible?).with(any_args).exactly(1)
225 r = @scroll_panel.visible?([@author])
228 context 'つつがなく終わるとき' do
230 MagicNumber['run_mode'] = 1
231 ScrollPanel.any_instance.stub(:reader_role_check).and_return(true)
233 it '自分のスクロールのスクコマなら許可する' do
234 Scroll.any_instance.stub(:own?).and_return(true)
235 Scroll.any_instance.stub(:visible).and_return(0)
236 r = @scroll_panel.visible?([@author])
239 it '他人の非公開スクロールのスクコマなら許可しない' do
240 Scroll.any_instance.stub(:own?).and_return(false)
241 Scroll.any_instance.stub(:visible).and_return(0)
242 r = @scroll_panel.visible?([@author])
245 it '他人のスクロールのスクコマでも公開なら許可する' do
246 Scroll.any_instance.stub(:own?).and_return(false)
247 Scroll.any_instance.stub(:visible).and_return(1)
248 r = @scroll_panel.visible?([@author])
254 describe 'プレイリスト取得に於いて' do
256 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
257 @panel = FactoryGirl.create :panel, :author_id => @author.id
258 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
259 @panel2 = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
260 @other_scroll = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 1
261 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
263 context 'offset補正について' do
264 it '文字列から数値に変換される' do
265 ScrollPanel.offset(100, '8').should eq 8
268 ScrollPanel.offset(100).should eq 0
270 #投稿されたコマ数以上の値が指定されたときは、最後のコマだけになる
272 it '1件のときオフセット1なら0になる' do
273 ScrollPanel.offset(1, '1').should eq 0
275 it '5件のときオフセット5なら4になる' do
276 ScrollPanel.offset(5, '5').should eq 4
278 # 負の値が指定されたときは、最後のコマから数えてコマを飛ばして表示する。
279 #-4のときは、最後から4つのコマを表示する。
280 it '2件のときオフセット-1なら1になる' do
281 ScrollPanel.offset(2, '-1').should eq 1
283 it '5件のときオフセット-2なら3になる' do
284 ScrollPanel.offset(5, '-2').should eq 3
286 # 最終的なが負になるなど、不正な値が入ったときは0となる。
287 it '2件のときオフセット-5なら0になる' do
288 ScrollPanel.offset(2, '-5').should eq 0
291 context 'panel_count補正について' do
292 it '文字列から数値に変換される' do
293 ScrollPanel.panel_count(100, '7').should eq 7
295 it 'nilの場合はScrollPanel.default_panel_sizeになる' do
296 ScrollPanel.panel_count(100).should eq ScrollPanel.default_panel_size
298 it '0以下の場合はScrollPanel.default_panel_sizeになる' do
299 ScrollPanel.panel_count(100, '0').should eq ScrollPanel.default_panel_size
301 it 'ScrollPanel.max_panel_sizeを超えた場合はScrollPanel.max_panel_sizeになる' do
302 ScrollPanel.panel_count(100, '1000').should eq ScrollPanel.max_panel_size
306 c = ScrollPanel.play_list @scroll, @author
307 c.should eq [@scroll_panel]
310 #公開スクロールの公開コマは(他人のスクロールであっても)含んでいる
311 v = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 1
312 c = ScrollPanel.play_list @scroll, @author
313 c.should eq [ @scroll_panel, v]
316 h = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel2.id, :t => 1
317 c = ScrollPanel.play_list @scroll, @author
318 c.should eq [ @scroll_panel, h]
320 context 'DBに5件あって1ページの件数を2件に変えたとして' do
322 @scroll_panel2 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 1
323 @scroll_panel3 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 2
324 @scroll_panel4 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 3
325 @scroll_panel5 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 4
327 it 'offset=0なら末尾2件を返す' do
329 c = ScrollPanel.play_list( @scroll, @author, 0, 2)
330 c.should eq [@scroll_panel, @scroll_panel2]
332 it 'offset=2なら中間2件を返す' do
333 c = ScrollPanel.play_list(@scroll, @author, 2, 2)
334 c.should eq [@scroll_panel3, @scroll_panel4]
336 it 'offset=4なら先頭1件を返す' do
337 c = ScrollPanel.play_list(@scroll, @author, 4, 2)
338 c.should eq [@scroll_panel5]
343 describe '一覧取得に於いて' do
345 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
346 @panel = FactoryGirl.create :panel, :author_id => @author.id
347 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
348 @other_scroll = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 1
349 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
350 @hidden_scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 0
352 context 'page補正について' do
353 it '文字列から数値に変換される' do
354 ScrollPanel.page('8').should eq 8
357 ScrollPanel.page().should eq 1
360 ScrollPanel.page('0').should eq 1
363 context 'page_size補正について' do
364 it '文字列から数値に変換される' do
365 ScrollPanel.page_size('7').should eq 7
367 it 'nilの場合はScrollPanel.default_page_sizeになる' do
368 ScrollPanel.page_size().should eq ScrollPanel.default_page_size
370 it '0以下の場合はScrollPanel.default_page_sizeになる' do
371 ScrollPanel.page_size('0').should eq ScrollPanel.default_page_size
373 it 'ScrollPanel.max_page_sizeを超えた場合はScrollPanel.max_page_sizeになる' do
374 ScrollPanel.page_size('1000').should eq ScrollPanel.max_page_size
379 c.should eq [@scroll_panel]
382 #公開スクロールのScrollPanelは(他人のScrollPanelであっても)含んでいる
383 v = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @other_scroll.id, :panel_id => @other_panel.id, :t => 0, :updated_at => Time.now + 100
385 c.should eq [ v, @scroll_panel]
387 it '非公開のスクコマは(自分のスクコマであっても)含まない' do
388 h = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @hidden_scroll.id, :panel_id => @panel.id, :t => 0
390 c.should eq [ @scroll_panel]
392 context 'DBに5件あって1ページの件数を2件に変えたとして' do
394 @scroll_panel2 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
395 @scroll_panel3 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
396 @scroll_panel4 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
397 @scroll_panel5 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
400 l = ScrollPanel.list 1, 2
401 l.should have(2).items
403 it 'page=1なら末尾2件を返す' do
405 l = ScrollPanel.list 1, 2
406 l.should eq [@scroll_panel5, @scroll_panel4]
408 it 'page=2なら中間2件を返す' do
409 l = ScrollPanel.list 2, 2
410 l.should eq [@scroll_panel3, @scroll_panel2]
412 it 'page=3なら先頭1件を返す' do
413 l = ScrollPanel.list 3, 2
414 l.should eq [@scroll_panel]
419 describe '自分のスクコマ一覧取得に於いて' do
421 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
422 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
423 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
424 @other_scroll = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 1
425 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
426 @hscroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 0
427 @hpanel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
429 context 'つつがなく終わるとき' do
430 it '一覧取得オプションを利用している' do
431 ScrollPanel.stub(:list_opt).with(any_args).and_return({})
432 ScrollPanel.should_receive(:list_opt).with(any_args).exactly(1)
433 r = ScrollPanel.mylist @author
437 s = ScrollPanel.mylist @author
438 s.should eq [@scroll_panel]
441 ns = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
442 sl = ScrollPanel.mylist @author
443 sl.should eq [ns, @scroll_panel]
445 it '他人のスクコマはコマスクロールともに公開でも含まない' do
446 so = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @other_scroll.id, :panel_id => @other_panel.id
447 sl = ScrollPanel.mylist @author
448 sl.should eq [@scroll_panel]
450 it '自分のスクコマはコマスクロールともに非公開でも含んでいる' do
451 hs = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @hscroll.id, :panel_id => @hpanel.id, :updated_at => Time.now + 100
452 sl = ScrollPanel.mylist @author
453 sl.should eq [hs, @scroll_panel]
455 context 'DBに5件あって1ページの件数を2件に変えたとして' do
457 @scroll_panel2 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 1, :updated_at => Time.now + 100
458 @scroll_panel3 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 2, :updated_at => Time.now + 200
459 @scroll_panel4 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 3, :updated_at => Time.now + 300
460 @scroll_panel5 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 4, :updated_at => Time.now + 400
461 ScrollPanel.stub(:default_page_size).and_return(2)
464 l = ScrollPanel.mylist @author, 1, 2
465 l.should have(2).items
467 it 'page=1なら末尾2件を返す' do
469 l = ScrollPanel.mylist @author, 1, 2
470 l.should eq [@scroll_panel5, @scroll_panel4]
472 it 'page=2なら中間2件を返す' do
473 l = ScrollPanel.mylist @author, 2, 2
474 l.should eq [@scroll_panel3, @scroll_panel2]
476 it 'page=3なら先頭1件を返す' do
477 l = ScrollPanel.mylist @author, 3, 2
478 l.should eq [@scroll_panel]
483 describe '他作家のスクコマ一覧取得に於いて' do
485 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
486 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
487 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
488 @other_scroll = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 1
489 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
490 @other_scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @other_scroll.id, :panel_id => @other_panel.id
493 r = ScrollPanel.himlist @other_author
494 r.should eq [@other_scroll_panel]
497 ns = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @other_scroll.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
498 r = ScrollPanel.himlist @other_author
499 r.should eq [ns, @other_scroll_panel]
502 @hscroll = FactoryGirl.create :scroll, :author_id => @other_author.id, :visible => 0
503 ns = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @hscroll.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
504 r = ScrollPanel.himlist @other_author
505 r.should eq [@other_scroll_panel]
507 context 'DBに5件あって1ページの件数を2件に変えたとして' do
509 @other_scroll_panel2 = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @other_scroll.id, :panel_id => @other_panel.id, :t => 1, :updated_at => Time.now + 100
510 @other_scroll_panel3 = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @other_scroll.id, :panel_id => @other_panel.id, :t => 2, :updated_at => Time.now + 200
511 @other_scroll_panel4 = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @other_scroll.id, :panel_id => @other_panel.id, :t => 3, :updated_at => Time.now + 300
512 @other_scroll_panel5 = FactoryGirl.create :scroll_panel, :author_id => @other_author.id, :scroll_id => @other_scroll.id, :panel_id => @other_panel.id, :t => 4, :updated_at => Time.now + 400
513 ScrollPanel.stub(:default_page_size).and_return(2)
516 l = ScrollPanel.himlist @other_author, 1, 2
517 l.should have(2).items
519 it 'page=1なら末尾2件を返す' do
521 l = ScrollPanel.himlist @other_author, 1, 2
522 l.should eq [@other_scroll_panel5, @other_scroll_panel4]
524 it 'page=2なら中間2件を返す' do
525 l = ScrollPanel.himlist @other_author, 2, 2
526 l.should eq [@other_scroll_panel3, @other_scroll_panel2]
528 it 'page=3なら先頭1件を返す' do
529 l = ScrollPanel.himlist @other_author, 3, 2
530 l.should eq [@other_scroll_panel]
535 describe 'スクコマ一覧ページ制御に於いて' do
537 ScrollPanel.stub(:count).with(any_args).and_return(100)
540 r = ScrollPanel.list_paginate
541 r.is_a?(Kaminari::PaginatableArray).should be_true
543 it 'スクコマ一覧の取得条件を利用している' do
544 ScrollPanel.stub(:list_where).with(any_args).and_return('')
545 ScrollPanel.should_receive(:list_where).with(any_args).exactly(1)
546 r = ScrollPanel.list_paginate
548 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
549 r = ScrollPanel.list_paginate 3, 10
550 r.limit_value.should eq 10
551 r.offset_value.should eq 20
555 describe '自分のスクコマ一覧ページ制御に於いて' do
557 ScrollPanel.stub(:count).with(any_args).and_return(100)
560 r = ScrollPanel.mylist_paginate @author
561 r.is_a?(Kaminari::PaginatableArray).should be_true
563 it '自分のスクコマ一覧の取得条件を利用している' do
564 ScrollPanel.stub(:mylist_where).with(any_args).and_return('')
565 ScrollPanel.should_receive(:mylist_where).with(any_args).exactly(1)
566 r = ScrollPanel.mylist_paginate @author
568 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
569 r = ScrollPanel.mylist_paginate @author, 3, 10
570 r.limit_value.should eq 10
571 r.offset_value.should eq 20
575 describe '他作家のスクコマ一覧ページ制御に於いて' do
577 ScrollPanel.stub(:count).with(any_args).and_return(100)
580 r = ScrollPanel.himlist_paginate @other_author
581 r.is_a?(Kaminari::PaginatableArray).should be_true
583 it '他作家のスクコマ一覧の取得条件を利用している' do
584 ScrollPanel.stub(:himlist_where).with(any_args).and_return('')
585 ScrollPanel.should_receive(:himlist_where).with(any_args).exactly(1)
586 r = ScrollPanel.himlist_paginate @other_author
588 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
589 r = ScrollPanel.himlist_paginate @other_author, 3, 10
590 r.limit_value.should eq 10
591 r.offset_value.should eq 20
595 describe 'list関連テーブルプションに於いて' do
597 r = ScrollPanel.list_opt
598 r.should have(3).items
601 r = ScrollPanel.list_opt
602 r.has_key?(:scroll).should be_true
604 it 'スクロールは作家を含んでいる' do
605 r = ScrollPanel.list_opt
606 r[:scroll].has_key?(:author).should be_true
609 r = ScrollPanel.list_opt
610 r.has_key?(:author).should be_true
613 r = ScrollPanel.list_opt
614 r.has_key?(:panel).should be_true
617 r = ScrollPanel.list_opt
618 r[:panel].has_key?(:author).should be_true
621 r = ScrollPanel.list_opt
622 r[:panel].has_key?(:panel_pictures).should be_true
624 it 'コマ絵は実素材を含んでいる' do
625 r = ScrollPanel.list_opt
626 r[:panel][:panel_pictures].has_key?(:picture).should be_true
629 r = ScrollPanel.list_opt
630 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
632 it '実素材はライセンスを含んでいる' do
633 r = ScrollPanel.list_opt
634 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
636 it 'コマはフキダシを含んでいる' do
637 r = ScrollPanel.list_opt
638 r[:panel].has_key?(:speech_balloons).should be_true
640 it 'フキダシはフキダシ枠を含んでいる' do
641 r = ScrollPanel.list_opt
642 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
644 it 'フキダシはセリフを含んでいる' do
645 r = ScrollPanel.list_opt
646 r[:panel][:speech_balloons].has_key?(:speech).should be_true
649 describe 'json一覧出力オプションに於いて' do
652 describe '単体取得に於いて' do
654 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
655 @panel = FactoryGirl.create :panel, :author_id => @author.id
656 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
658 context 'つつがなく終わるとき' do
659 it '単体取得オプションを利用している' do
660 ScrollPanel.stub(:show_opt).with(any_args).and_return({})
661 ScrollPanel.should_receive(:show_opt).with(any_args).exactly(1)
662 r = ScrollPanel.show @scroll_panel.id, @author
664 it '閲覧許可を問い合わせている' do
665 ScrollPanel.any_instance.stub(:visible?).with(@author).and_return(true)
666 ScrollPanel.any_instance.should_receive(:visible?).with(@author).exactly(1)
667 r = ScrollPanel.show @scroll_panel.id, @author
671 l = ScrollPanel.show @scroll_panel.id, @author
672 l.should eq @scroll_panel
674 context '他人のスクコマを開こうとしたとき' do
675 it '403Forbidden例外を返す' do
676 ScrollPanel.any_instance.stub(:visible?).with(@other_author).and_return(false)
678 ScrollPanel.show @scroll_panel.id, @other_author
679 }.should raise_error(ActiveRecord::Forbidden)
682 context '存在しないスクコマを開こうとしたとき' do
683 it '404RecordNotFound例外を返す' do
685 ScrollPanel.show 110, @author
686 }.should raise_error(ActiveRecord::RecordNotFound)
691 describe '編集取得に於いて' do
693 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
694 @panel = FactoryGirl.create :panel, :author_id => @author.id
695 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
697 context 'つつがなく終わるとき' do
698 it '単体取得オプションを利用している' do
699 ScrollPanel.stub(:show_opt).with(any_args).and_return({})
700 ScrollPanel.should_receive(:show_opt).with(any_args).exactly(1)
701 r = ScrollPanel.edit @scroll_panel.id, @author
703 it '所持判定を問い合わせている' do
704 ScrollPanel.any_instance.stub(:own?).with(any_args).and_return(true)
705 ScrollPanel.any_instance.should_receive(:own?).with(any_args).exactly(1)
706 r = ScrollPanel.edit @scroll_panel.id, @author
710 l = ScrollPanel.edit @scroll_panel.id, @author
711 l.should eq @scroll_panel
713 context '他人のスクコマを開こうとしたとき' do
714 it '403Forbidden例外を返す' do
715 ScrollPanel.any_instance.stub(:own?).and_return(false)
717 ScrollPanel.edit @scroll_panel.id, @author
718 }.should raise_error(ActiveRecord::Forbidden)
721 context '存在しないスクコマを開こうとしたとき' do
722 it '404RecordNotFound例外を返す' do
724 ScrollPanel.edit 110, @author
725 }.should raise_error(ActiveRecord::RecordNotFound)
730 describe '単体取得オプションに於いて' do
731 it 'includeキーを含んでいる' do
732 r = ScrollPanel.show_opt
733 r.has_key?(:include).should be_true
736 r = ScrollPanel.show_opt[:include]
737 r.should have(3).items
740 r = ScrollPanel.show_opt[:include]
741 r.has_key?(:scroll).should be_true
743 it 'スクロールは作家を含んでいる' do
744 r = ScrollPanel.show_opt[:include]
745 r[:scroll].has_key?(:author).should be_true
748 r = ScrollPanel.show_opt[:include]
749 r.has_key?(:author).should be_true
752 r = ScrollPanel.show_opt[:include]
753 r.has_key?(:panel).should be_true
756 r = ScrollPanel.show_opt[:include]
757 r[:panel].has_key?(:author).should be_true
760 r = ScrollPanel.show_opt[:include]
761 r[:panel].has_key?(:panel_pictures).should be_true
763 it 'コマ絵は実素材を含んでいる' do
764 r = ScrollPanel.show_opt[:include]
765 r[:panel][:panel_pictures].has_key?(:picture).should be_true
768 r = ScrollPanel.show_opt[:include]
769 r[:panel][:panel_pictures][:picture].has_key?(:artist).should be_true
771 it '実素材はライセンスを含んでいる' do
772 r = ScrollPanel.show_opt[:include]
773 r[:panel][:panel_pictures][:picture].has_key?(:license).should be_true
775 it 'コマはフキダシを含んでいる' do
776 r = ScrollPanel.show_opt[:include]
777 r[:panel].has_key?(:speech_balloons).should be_true
779 it 'フキダシはフキダシ枠を含んでいる' do
780 r = ScrollPanel.show_opt[:include]
781 r[:panel][:speech_balloons].has_key?(:balloon).should be_true
783 it 'フキダシはセリフを含んでいる' do
784 r = ScrollPanel.show_opt[:include]
785 r[:panel][:speech_balloons].has_key?(:speech).should be_true
788 describe 'json単体取得オプションに於いて' do
791 describe 'スクコマのjson出力に於いて' do
794 @panel = FactoryGirl.create :panel, :author_id => @author.id
795 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :width => @p.width, :height => @p.height
796 @sb = FactoryGirl.build :speech_balloon, :panel_id => @panel.id, :speech_balloon_template_id => @speech_balloon_template.id
797 @speech = @sb.build_speech(
798 FactoryGirl.attributes_for(:speech, :writing_format_id => @writing_format.id)
800 @balloon = @sb.build_balloon(
801 FactoryGirl.attributes_for(:balloon, :system_picture_id => @sp.id)
805 @gc = @panel.ground_colors.create(
806 FactoryGirl.attributes_for(:ground_color, :panel_id => @panel.id)
808 @gp = @panel.ground_pictures.create(
809 FactoryGirl.attributes_for(:ground_picture, :panel_id => @panel.id, :picture_id => @p.id)
812 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
813 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
815 context '事前チェックする' do
817 Panel.any_instance.stub(:elements).and_return('{}')
819 it 'コマ要素のjson出力を依頼している' do
820 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
821 Panel.any_instance.should_receive(:elements).with(any_args).exactly(1)
822 r = @scroll_panel.scroll_panel_as_json @author
825 it 'json textを返している' do
826 r = JSON.parse @scroll_panel.scroll_panel_as_json(@author)
827 r.is_a?(Hash).should be_true
829 it 'scroll,author,panel,コマ要素を含んでいる' do
830 r = JSON.parse @scroll_panel.scroll_panel_as_json(@author)
831 r.has_key?('scroll').should be_true
832 r['scroll'].has_key?('author').should be_true
833 r.has_key?('author').should be_true
834 r.has_key?('panel').should be_true
835 r['panel'].has_key?('author').should be_true
837 context 'コマ閲覧許可のとき' do
839 Panel.any_instance.stub(:visible?).with(any_args).and_return(true)
841 it 'コマ要素にコマ要素を追加している' do
842 r = JSON.parse @scroll_panel.scroll_panel_as_json(@author)
843 r['panel'].has_key?('elements').should be_true
844 r['panel']['elements'].should_not be_empty
847 context 'コマ閲覧不許可のとき' do
849 Panel.any_instance.stub(:visible?).with(any_args).and_return(false)
851 it 'コマ要素にデータを含ませない' do
852 r = JSON.parse @scroll_panel.scroll_panel_as_json(@author)
853 r['panel'].has_key?('elements').should be_false
858 describe 'スクコマリストのjson出力に於いて' do
860 @panel = FactoryGirl.create :panel, :author_id => @author.id
861 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
862 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
863 ScrollPanel.any_instance.stub(:scroll_panel_as_json).with(@author).and_return('{"s": 5}')
865 context 'つつがなく終わるとき' do
866 it 'スクコマのjson出力を依頼している' do
867 ScrollPanel.any_instance.should_receive(:scroll_panel_as_json).with(@author).exactly(1)
868 r = ScrollPanel.list_as_json_text [@scroll_panel], @author
871 it 'json textを返している' do
872 r = ScrollPanel.list_as_json_text [@scroll_panel], @author
874 j.is_a?(Array).should be_true
877 r = ScrollPanel.list_as_json_text [@scroll_panel], @author
879 j.first.has_key?('s').should be_true
883 describe 'ライセンス素材に於いて' do
886 @op2 = FactoryGirl.create :original_picture, :artist_id => @artist.id
887 @p2 = FactoryGirl.create :picture, :original_picture_id => @op2.id, :license_id => @license.id, :artist_id => @artist.id
888 @rp2 = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op2.id, :picture_id => @p2.id
889 @panel = FactoryGirl.create :panel, :author_id => @author.id
890 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 0, :width => @p.width, :height => @p.height, :picture_id => @p.id
892 @panel2 = FactoryGirl.create :panel, :author_id => @author.id
893 @pp2= FactoryGirl.create :panel_picture, :panel_id => @panel2.id, :t => 0, :width => @p2.width, :height => @p2.height, :picture_id => @p2.id
896 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
897 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
898 @scroll_panel2 = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel2.id
902 context 'つつがなく終わるとき' do
904 it '連想配列(値は実素材、キーは実素材id)を返している' do
905 r = ScrollPanel.licensed_pictures [@scroll_panel, @scroll_panel2]
906 r.is_a?(Hash).should be_true
907 r.should have(2).items
908 r[@pp.picture_id].should eq @p
909 r[@pp2.picture_id].should eq @p2
911 context 'コマが削除されているときき' do
915 it '削除されているコマは無視する' do
916 r = ScrollPanel.licensed_pictures [@scroll_panel, @scroll_panel2]
917 r.is_a?(Hash).should be_true
918 r.should have(1).items
919 r[@pp.picture_id].should eq @p
920 r[@pp2.picture_id].should be_nil
925 describe 't補充値に於いて' do
927 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
928 @panel = FactoryGirl.create :panel, :author_id => @author.id
931 context 'スクロール初のコマなら' do
933 @scroll_panel = FactoryGirl.build :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
934 @scroll_panel.t = nil
935 r = ScrollPanel.new_t @scroll_panel.scroll_id
939 context 'スクロールに一個コマがあるとき' do
941 FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 0
942 @scroll_panel = FactoryGirl.build :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
943 @scroll_panel.t = nil
944 r = ScrollPanel.new_t @scroll_panel.scroll_id
948 context 'スクロールに2個コマがあるとき' do
950 FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 0
951 FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id, :t => 1
952 @scroll_panel = FactoryGirl.build :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
953 @scroll_panel.t = nil
954 r = ScrollPanel.new_t @scroll_panel.scroll_id
959 describe 'シリアライズチェックに於いて' do
960 context 'つつがなく終わるとき' do
961 it '0からシリアライズされているならTrueを返す' do
962 r = ScrollPanel.serial? [0, 1, 2]
965 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
966 r = ScrollPanel.serial? [0, 2, 1]
969 it '見た目はシリアライズされてなくてもソート結果が無事ならtrueを返す' do
970 r = ScrollPanel.serial? [ 2, 1, 4, 3, 0]
975 it '0から始まらないならFalseを返す' do
976 r = ScrollPanel.serial? [1, 2, 3]
979 it '連続していないならFalseを返す' do
980 r = ScrollPanel.serial? [0, 1, 2, 4]
983 it '連続していないならFalseを返す' do
984 r = ScrollPanel.serial? [0, 1, 2, 4, 5]
989 describe 't収集に於いて' do
991 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
992 @panel = FactoryGirl.create :panel, :author_id => @author.id
993 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
994 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
995 @c2scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
997 context 'つつがなく終わるとき' do
998 it 'スクコマから同一スクロールのtだけを収集している' do
999 r = ScrollPanel.collect_t @scroll_panel
1003 context '複数コマのとき' do
1004 it 'スクコマから同一スクロールのtだけを収集している' do
1005 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1006 r = ScrollPanel.collect_t @scroll_panel
1007 r.sort.should eq [0, 1]
1010 context '複数コマでヨソのスクロールも混じっているとき' do
1011 it 'スクコマから同一スクロールのtだけを収集している' do
1012 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1013 r = ScrollPanel.collect_t @scroll_panel
1014 r.sort.should eq [0, 1]
1018 describe 'tチェックに於いて' do
1020 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1021 @panel = FactoryGirl.create :panel, :author_id => @author.id
1022 @scroll_panel = FactoryGirl.build :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1024 context 'つつがなく終わるとき' do
1026 ScrollPanel.should_receive(:collect_t).with(any_args).exactly(1)
1027 ScrollPanel.stub(:collect_t).with(any_args).and_return([])
1028 ScrollPanel.stub(:serial?).with(any_args).and_return(true)
1029 r = ScrollPanel.validate_t @scroll_panel
1031 it '収集したtをシリアライズチェック依頼している' do
1032 ScrollPanel.stub(:collect_t).with(any_args).and_return([])
1033 ScrollPanel.should_receive(:serial?).with(any_args).exactly(1)
1034 ScrollPanel.stub(:serial?).with(any_args).and_return(true)
1035 r = ScrollPanel.validate_t @scroll_panel
1039 #依頼チェックだけでは不安なので最低限のチェックを
1041 it '一件だけで正常通過している' do
1042 @scroll_panel = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1043 r = ScrollPanel.validate_t @scroll_panel
1048 it '2件目を作っても正常通過している' do
1049 @scroll_panel = FactoryGirl.create :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id, :t => 0
1050 @scroll_panel2 = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id, :t => 1
1051 r = ScrollPanel.validate_t @scroll_panel2
1056 describe '挿入シフトに於いて' do
1058 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1059 @panel = FactoryGirl.create :panel, :author_id => @author.id
1063 it 'Updateを依頼している' do
1064 ScrollPanel.stub(:update_all).with(any_args)
1065 ScrollPanel.should_receive(:update_all).with(any_args).exactly(1)
1066 @scroll_panel = FactoryGirl.build :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1067 @scroll_panel.insert_shift
1070 context 'テーブルに1件(t:0)で0に挿入したとき' do
1072 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1073 @scroll_panel2 = FactoryGirl.build :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1075 it '既存の行を1にシフトしている' do
1076 @scroll_panel2.insert_shift
1077 l = ScrollPanel.find :all
1078 l.first.t.should eq 1
1080 it 'これから挿入するt(0)が欠番になっている' do
1081 @scroll_panel2.insert_shift
1082 l = ScrollPanel.find(:all).map {|s| s.t }
1083 l.include?(0).should_not be_true
1086 context 'テーブルに2件(t:0,1)で1に挿入したとき' do
1088 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1089 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1090 @scroll_panel3 = FactoryGirl.build :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1092 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1093 @scroll_panel3.insert_shift
1094 l = ScrollPanel.find(:all).map {|s| s.t }
1095 l.sort.should eq [0, 2]
1098 context 'テーブルに5件(t:0,1,2,3,4)で2に挿入したとき' do
1100 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1101 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1102 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1103 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1104 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1105 @scroll_panel6 = FactoryGirl.build :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1107 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1108 @scroll_panel6.insert_shift
1109 l = ScrollPanel.find(:all).map {|s| s.t }
1110 l.sort.should eq [0, 1, 3, 4, 5]
1113 context '先ほどのケース+他のスクロール1件で挿入したとき' do
1115 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
1116 @scroll_panelc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
1117 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1118 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1119 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1120 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1121 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1122 @scroll_panel6 = FactoryGirl.build :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1124 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1125 @scroll_panel6.insert_shift
1126 l = ScrollPanel.find(:all, :conditions => ['scroll_id = ?', @scroll.id]).map {|s| s.t }
1127 l.sort.should eq [0, 1, 3, 4, 5]
1129 it '他のスクロールに影響がない' do
1130 ot = @scroll_panelc2.t
1131 @scroll_panel6.insert_shift
1132 @scroll_panelc2.reload
1133 @scroll_panelc2.t.should eq ot
1137 describe '少ない方に移動に於いて' do
1139 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1140 @panel = FactoryGirl.create :panel, :author_id => @author.id
1143 it 'Updateを依頼している' do
1144 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1145 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1146 ScrollPanel.stub(:update_all).with(any_args)
1147 ScrollPanel.should_receive(:update_all).with(any_args).exactly(1)
1148 ot = @scroll_panel2.t
1149 @scroll_panel2.t = 0
1150 @scroll_panel2.lesser_shift ot
1153 context 'テーブルに2件(t:0,1)で1を0に移動したとき' do
1155 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1156 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1157 @ot = @scroll_panel2.t
1158 @scroll_panel2.t = 0
1160 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1162 @scroll_panel2.lesser_shift @ot
1163 l = ScrollPanel.find(:all).map {|s| s.t }
1164 l.sort.should eq [1, 1]
1166 it '既存のt0を1にシフトしている' do
1167 @scroll_panel2.lesser_shift @ot
1168 @scroll_panel.reload
1169 @scroll_panel.t.should eq 1
1172 context 'テーブルに3件(t:0,1,2)で2を1に移動したとき' do
1174 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1175 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1176 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1177 @ot = @scroll_panel3.t
1178 @scroll_panel3.t = 1
1180 it '既存のt1を2にシフトしてこれから挿入するt(1)が欠番になっている' do
1182 @scroll_panel3.lesser_shift @ot
1183 l = ScrollPanel.find(:all).map {|s| s.t }
1184 l.sort.should eq [0, 2, 2]
1186 it '既存のt1を2にシフトしている' do
1187 @scroll_panel3.lesser_shift @ot
1188 @scroll_panel2.reload
1189 @scroll_panel2.t.should eq 2
1192 context 'テーブルに5件(t:0,1,2,3,4)で3を1に移動したとき' do
1194 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1195 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1196 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1197 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1198 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1199 @ot = @scroll_panel4.t
1200 @scroll_panel4.t = 1
1202 it 'これから挿入するt(1)が欠番になっている' do
1204 @scroll_panel4.lesser_shift @ot
1205 l = ScrollPanel.find(:all).map {|s| s.t }
1206 l.sort.should eq [0, 2, 3, 3, 4]
1208 it '既存のt0には変化がない' do
1209 @scroll_panel4.lesser_shift @ot
1210 @scroll_panel.reload
1211 @scroll_panel.t.should eq 0
1213 it '既存のt4には変化がない' do
1214 @scroll_panel4.lesser_shift @ot
1215 @scroll_panel5.reload
1216 @scroll_panel5.t.should eq 4
1218 it '既存のt1を2にシフトしている' do
1219 @scroll_panel4.lesser_shift @ot
1220 @scroll_panel2.reload
1221 @scroll_panel2.t.should eq 2
1223 it '既存のt2を3にシフトしている' do
1224 @scroll_panel4.lesser_shift @ot
1225 @scroll_panel3.reload
1226 @scroll_panel3.t.should eq 3
1229 context '先ほどのケース+他のスクロール1件で挿入したとき' do
1231 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
1232 @scroll_panelc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
1233 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1234 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1235 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1236 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1237 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1238 @ot = @scroll_panel4.t
1239 @scroll_panel4.t = 1
1241 it 'これから挿入するt(1)が欠番になっている' do
1242 @scroll_panel4.lesser_shift @ot
1243 l = ScrollPanel.find(:all).map {|s| s.t }
1244 l.sort.should eq [0, 0, 2, 3, 3, 4]
1246 it '既存のt0には変化がない' do
1247 @scroll_panel4.lesser_shift @ot
1248 @scroll_panel.reload
1249 @scroll_panel.t.should eq 0
1251 it '既存のt4には変化がない' do
1252 @scroll_panel4.lesser_shift @ot
1253 @scroll_panel5.reload
1254 @scroll_panel5.t.should eq 4
1256 it '既存のt1を2にシフトしている' do
1257 @scroll_panel4.lesser_shift @ot
1258 @scroll_panel2.reload
1259 @scroll_panel2.t.should eq 2
1261 it '既存のt2を3にシフトしている' do
1262 @scroll_panel4.lesser_shift @ot
1263 @scroll_panel3.reload
1264 @scroll_panel3.t.should eq 3
1266 it '他のスクロールに影響がない' do
1267 @scroll_panel4.lesser_shift @ot
1268 @scroll_panelc2.reload
1269 @scroll_panelc2.t.should eq 0
1274 context 'テーブルに2件(t:0,1)で1を-1に移動したとき' do
1276 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1277 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1278 @ot = @scroll_panel2.t
1279 @scroll_panel2.t = -1
1281 it '既存のt0を1にシフトしてこれから挿入するt(0)が欠番になっている' do
1283 @scroll_panel2.lesser_shift @ot
1284 l = ScrollPanel.find(:all).map {|s| s.t }
1285 l.sort.should eq [1, 1]
1287 it '既存のt0を1にシフトしている' do
1288 @scroll_panel2.lesser_shift @ot
1289 @scroll_panel.reload
1290 @scroll_panel.t.should eq 1
1292 it '既存のt1は0に補正されている' do
1293 @scroll_panel2.lesser_shift @ot
1294 @scroll_panel2.t.should eq 0
1298 describe '大きい方に移動に於いて' do
1300 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1301 @panel = FactoryGirl.create :panel, :author_id => @author.id
1304 it 'Updateを依頼している' do
1305 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1306 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1307 ScrollPanel.stub(:update_all).with(any_args)
1308 ScrollPanel.should_receive(:update_all).with(any_args).exactly(1)
1309 ot = @scroll_panel.t
1311 @scroll_panel.higher_shift ot
1314 context 'テーブルに2件(t:0,1)で0を1に移動したとき' do
1316 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1317 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1318 @ot = @scroll_panel.t
1321 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1323 @scroll_panel.higher_shift @ot
1324 l = ScrollPanel.find(:all).map {|s| s.t }
1325 l.sort.should eq [0, 0]
1327 it '既存のt1を0にシフトしている' do
1328 @scroll_panel.higher_shift @ot
1329 @scroll_panel2.reload
1330 @scroll_panel2.t.should eq 0
1333 context 'テーブルに3件(t:0,1,2)で0を1に移動したとき' do
1335 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1336 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1337 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1338 @ot = @scroll_panel.t
1341 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1343 @scroll_panel.higher_shift @ot
1344 l = ScrollPanel.find(:all).map {|s| s.t }
1345 l.sort.should eq [0, 0, 2]
1347 it '既存のt1を0にシフトしている' do
1348 @scroll_panel.higher_shift @ot
1349 @scroll_panel2.reload
1350 @scroll_panel2.t.should eq 0
1353 context 'テーブルに5件(t:0,1,2,3,4)で1を3に移動したとき' do
1355 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1356 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1357 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1358 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1359 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1360 @ot = @scroll_panel2.t
1361 @scroll_panel2.t = 3
1363 it 'これから挿入するt(3)が欠番になっている' do
1365 @scroll_panel2.higher_shift @ot
1366 l = ScrollPanel.find(:all).map {|s| s.t }
1367 l.sort.should eq [0, 1, 1, 2, 4]
1369 it '既存のt0には変化がない' do
1370 @scroll_panel2.higher_shift @ot
1371 @scroll_panel.reload
1372 @scroll_panel.t.should eq 0
1374 it '既存のt4には変化がない' do
1375 @scroll_panel2.higher_shift @ot
1376 @scroll_panel5.reload
1377 @scroll_panel5.t.should eq 4
1379 it '既存のt2を1にシフトしている' do
1380 @scroll_panel2.higher_shift @ot
1381 @scroll_panel3.reload
1382 @scroll_panel3.t.should eq 1
1384 it '既存のt3を2にシフトしている' do
1385 @scroll_panel2.higher_shift @ot
1386 @scroll_panel4.reload
1387 @scroll_panel4.t.should eq 2
1390 context '先ほどのケース+他のスクロール1件で挿入したとき' do
1392 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
1393 @scroll_panelc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
1394 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1395 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1396 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1397 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1398 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1399 @ot = @scroll_panel2.t
1400 @scroll_panel2.t = 3
1402 it 'これから挿入するt(3)が欠番になっている' do
1404 @scroll_panel2.higher_shift @ot
1405 l = ScrollPanel.find(:all).map {|s| s.t }
1406 l.sort.should eq [0, 0, 1, 1, 2, 4]
1408 it '既存のt0には変化がない' do
1409 @scroll_panel2.higher_shift @ot
1410 @scroll_panel.reload
1411 @scroll_panel.t.should eq 0
1413 it '既存のt4には変化がない' do
1414 @scroll_panel2.higher_shift @ot
1415 @scroll_panel5.reload
1416 @scroll_panel5.t.should eq 4
1418 it '既存のt2を1にシフトしている' do
1419 @scroll_panel2.higher_shift @ot
1420 @scroll_panel3.reload
1421 @scroll_panel3.t.should eq 1
1423 it '既存のt3を2にシフトしている' do
1424 @scroll_panel2.higher_shift @ot
1425 @scroll_panel4.reload
1426 @scroll_panel4.t.should eq 2
1428 it '他のスクロールに影響がない' do
1429 @scroll_panel2.higher_shift @ot
1430 @scroll_panelc2.reload
1431 @scroll_panelc2.t.should eq 0
1435 #max超えたときはmaxとして正常扱い
1436 context 'テーブルに2件(t:0,1)で0を2に移動したとき' do
1438 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1439 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1440 @ot = @scroll_panel.t
1443 it '既存のt1を0にシフトしてこれから挿入するt(1)が欠番になっている' do
1445 @scroll_panel.higher_shift @ot
1446 l = ScrollPanel.find(:all).map {|s| s.t }
1447 l.sort.should eq [0, 0]
1449 it '既存のt1を0にシフトしている' do
1450 @scroll_panel.higher_shift @ot
1451 @scroll_panel2.reload
1452 @scroll_panel2.t.should eq 0
1454 it '既存のt0は1に補正されている' do
1455 @scroll_panel.higher_shift @ot
1456 @scroll_panel.t.should eq 1
1460 describe '入れ替えに於いて' do
1462 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1463 @panel = FactoryGirl.create :panel, :author_id => @author.id
1464 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1465 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1467 context '新tが旧tより小さいとき' do
1468 it '少ない方に移動を依頼している' do
1469 ScrollPanel.any_instance.stub(:lesser_shift).with(any_args)
1470 ScrollPanel.any_instance.should_receive(:lesser_shift).with(any_args).exactly(1)
1471 ot = @scroll_panel2.t
1472 @scroll_panel2.t = 0
1473 @scroll_panel2.update_shift ot
1476 context '新tが旧tより大きいとき' do
1477 it '大きい方に移動を依頼している' do
1478 ScrollPanel.any_instance.stub(:higher_shift).with(any_args)
1479 ScrollPanel.any_instance.should_receive(:higher_shift).with(any_args).exactly(1)
1480 ot = @scroll_panel.t
1482 @scroll_panel.update_shift ot
1486 describe '順序入れ替えに於いて' do
1488 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1489 @panel = FactoryGirl.create :panel, :author_id => @author.id
1491 context 'オブジェクトが新規でtが空のとき' do
1492 it '末尾追加としてtを補充依頼している' do
1493 @scroll_panel = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1494 ScrollPanel.stub(:new_t).with(any_args).and_return(0)
1495 ScrollPanel.should_receive(:new_t).with(any_args).exactly(1)
1496 @scroll_panel.t = nil
1497 r = @scroll_panel.rotate
1500 context 'オブジェクトが新規でtが設定されているとき' do
1501 it '挿入追加として挿入シフトを依頼している' do
1502 @scroll_panel = FactoryGirl.build :scroll_panel, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1503 ScrollPanel.any_instance.stub(:insert_shift).with(any_args)
1504 ScrollPanel.any_instance.should_receive(:insert_shift).with(any_args).exactly(1)
1506 r = @scroll_panel.rotate
1509 context 'オブジェクトが新規でなくtが設定されているとき' do
1510 it 'コマ移動として入れ替えを依頼している' do
1511 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1512 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1513 ScrollPanel.any_instance.stub(:update_shift).with(any_args)
1514 ScrollPanel.any_instance.should_receive(:update_shift).with(1).exactly(1)
1515 @scroll_panel2.t = 0
1516 r = @scroll_panel.rotate 1
1519 context 'オブジェクトが新規でなくtが空のとき' do
1520 it '入れ替えもシフトもせず、tを空のままにしている' do
1521 #結果、tに欠番が生じてシリアライズチェックでひっかかる
1525 describe '編集許可に於いて' do
1527 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1528 @panel = FactoryGirl.create :panel, :author_id => @author.id
1529 @scroll_panel = FactoryGirl.build :scroll_panel, :t => nil, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1531 context 'つつがなく終わるとき' do
1533 r = @scroll_panel.allow?
1537 context 'スクロールで引っかかるとき' do
1539 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1540 Scroll.any_instance.stub(:own?).with(any_args).and_return(false)
1541 r = @scroll_panel.allow?
1545 context 'コマで引っかかるとき' do
1547 Scroll.any_instance.stub(:own?).with(any_args).and_return(true)
1548 Panel.any_instance.stub(:usable?).with(any_args).and_return(false)
1549 r = @scroll_panel.allow?
1553 context 'スクロールまたはコマが指定されていなかったとき' do
1555 Scroll.any_instance.stub(:own?).with(any_args).and_return(true)
1556 @scroll_panel.panel_id = nil
1557 r = @scroll_panel.allow?
1561 Panel.any_instance.stub(:usable?).with(any_args).and_return(true)
1562 @scroll_panel.scroll_id = nil
1563 r = @scroll_panel.allow?
1568 describe '保存に於いて' do
1570 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1571 @panel = FactoryGirl.create :panel, :author_id => @author.id
1572 @scroll_panel = FactoryGirl.build :scroll_panel, :t => nil, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1574 context 'つつがなく終わるとき' do
1575 it '編集許可チェックを依頼している' do
1576 ScrollPanel.any_instance.stub(:allow?).with(any_args).and_return(true)
1577 ScrollPanel.any_instance.should_receive(:allow?).with(any_args).exactly(1)
1578 r = @scroll_panel.store
1580 it '順序入れ替えを依頼している' do
1581 ScrollPanel.any_instance.stub(:rotate).with(any_args).and_return(0)
1582 ScrollPanel.any_instance.should_receive(:rotate).with(any_args).exactly(1)
1583 ScrollPanel.any_instance.stub(:save).with(any_args).and_return(true)
1584 ScrollPanel.stub(:validate_t).with(any_args).and_return(true)
1585 r = @scroll_panel.store
1588 ScrollPanel.stub(:new_t).with(any_args).and_return(0)
1589 ScrollPanel.any_instance.stub(:save).with(any_args).and_return(true)
1590 ScrollPanel.any_instance.should_receive(:save).with(any_args).exactly(1)
1591 ScrollPanel.stub(:validate_t).with(any_args).and_return(true)
1592 r = @scroll_panel.store
1594 it 'tのシリアライズチェックを依頼している' do
1595 ScrollPanel.stub(:new_t).with(any_args).and_return(0)
1596 ScrollPanel.any_instance.stub(:save).with(any_args).and_return(true)
1597 ScrollPanel.stub(:validate_t).with(any_args).and_return(true)
1598 ScrollPanel.should_receive(:validate_t).with(any_args).exactly(1)
1599 r = @scroll_panel.store
1602 #入れ替えテストと同じテストを実施。こちらはシフトだけでなく本尊も更新されている
1603 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で2に挿入したとき' do
1605 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
1606 @scroll_panelc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
1607 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1608 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1609 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1610 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1611 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1612 @scroll_panel6 = FactoryGirl.build :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1614 it '既存のt0には変化がない' do
1615 @scroll_panel6.store
1616 @scroll_panel.reload
1617 @scroll_panel.t.should eq 0
1619 it '既存のt1には変化がない' do
1620 @scroll_panel6.store
1621 @scroll_panel2.reload
1622 @scroll_panel2.t.should eq 1
1624 it '既存のt2を3にシフトしている' do
1625 @scroll_panel6.store
1626 @scroll_panel3.reload
1627 @scroll_panel3.t.should eq 3
1629 it '既存のt3を4にシフトしている' do
1630 @scroll_panel6.store
1631 @scroll_panel4.reload
1632 @scroll_panel4.t.should eq 4
1634 it '既存のt5を5にシフトしている' do
1635 @scroll_panel6.store
1636 @scroll_panel5.reload
1637 @scroll_panel5.t.should eq 5
1639 it '新規のt2が作成されている' do
1640 @scroll_panel6.store
1641 @scroll_panel6.reload
1642 @scroll_panel6.t.should eq 2
1644 it '他のスクロールに影響がない' do
1645 @ot = @scroll_panelc2.t
1646 @scroll_panel6.store
1647 @scroll_panelc2.reload
1648 @scroll_panelc2.t.should eq @ot
1651 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で3を1に移動したとき' do
1653 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
1654 @scroll_panelc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
1655 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1656 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1657 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1658 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1659 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1660 @ot = @scroll_panel4.t
1661 @scroll_panel4.t = 1
1663 it '既存のt0には変化がない' do
1664 @scroll_panel4.store @ot
1665 @scroll_panel.reload
1666 @scroll_panel.t.should eq 0
1668 it '既存のt4には変化がない' do
1669 @scroll_panel4.store @ot
1670 @scroll_panel5.reload
1671 @scroll_panel5.t.should eq 4
1673 it '既存のt1を2にシフトしている' do
1674 @scroll_panel4.store @ot
1675 @scroll_panel2.reload
1676 @scroll_panel2.t.should eq 2
1678 it '既存のt2を3にシフトしている' do
1679 @scroll_panel4.store @ot
1680 @scroll_panel3.reload
1681 @scroll_panel3.t.should eq 3
1683 it '既存のt3を1にシフトしている' do
1684 @scroll_panel4.store @ot
1685 @scroll_panel4.reload
1686 @scroll_panel4.t.should eq 1
1688 it '他のスクロールに影響がない' do
1689 @scroll_panel4.store @ot
1690 @scroll_panelc2.reload
1691 @scroll_panelc2.t.should eq 0
1694 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で1を3に移動したとき' do
1696 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
1697 @scroll_panelc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
1698 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1699 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1700 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1701 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1702 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1703 @ot = @scroll_panel2.t
1704 @scroll_panel2.t = 3
1706 it '既存のt0には変化がない' do
1707 @scroll_panel2.store @ot
1708 @scroll_panel.reload
1709 @scroll_panel.t.should eq 0
1711 it '既存のt4には変化がない' do
1712 @scroll_panel2.store @ot
1713 @scroll_panel5.reload
1714 @scroll_panel5.t.should eq 4
1716 it '既存のt1を3にシフトしている' do
1717 @scroll_panel2.store @ot
1718 @scroll_panel2.reload
1719 @scroll_panel2.t.should eq 3
1721 it '既存のt2を1にシフトしている' do
1722 @scroll_panel2.store @ot
1723 @scroll_panel3.reload
1724 @scroll_panel3.t.should eq 1
1726 it '既存のt3を2にシフトしている' do
1727 @scroll_panel2.store @ot
1728 @scroll_panel4.reload
1729 @scroll_panel4.t.should eq 2
1731 it '他のスクロールに影響がない' do
1732 @scroll_panel2.store @ot
1733 @scroll_panelc2.reload
1734 @scroll_panelc2.t.should eq 0
1737 #ロールバックテスト。入れ替えが直接DBをいじるので、すべてのケースで確実にロールバックを確認する
1738 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で2に挿入したが保存に失敗したとき' do
1740 ScrollPanel.any_instance.stub(:save).with(any_args).and_return(false)
1741 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
1742 @scroll_panelc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
1743 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1744 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1745 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1746 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1747 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1748 @scroll_panel6 = FactoryGirl.build :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1751 @scroll_panel6.store
1752 @scroll_panel.reload
1753 @scroll_panel.t.should eq 0
1754 @scroll_panel2.reload
1755 @scroll_panel2.t.should eq 1
1756 @scroll_panel3.reload
1757 @scroll_panel3.t.should eq 2
1758 @scroll_panel4.reload
1759 @scroll_panel4.t.should eq 3
1760 @scroll_panel5.reload
1761 @scroll_panel5.t.should eq 4
1762 @scroll_panelc2.reload
1763 @scroll_panelc2.t.should eq 0
1766 r = @scroll_panel6.store
1770 context 'テーブルに5件(t:0,1,2,3,4)+他のスクロール1件で3を1に移動したがシリアルチェックに失敗したとき' do
1772 ScrollPanel.stub(:validate_t).with(any_args).and_return(false)
1773 @scroll2 = FactoryGirl.create :scroll, :author_id => @author.id
1774 @scroll_panelc2 = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll2.id, :panel_id => @panel.id, :author_id => @author.id
1775 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1776 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1777 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1778 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1779 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1780 @ot = @scroll_panel4.t
1781 @scroll_panel4.t = 1
1784 @scroll_panel4.store @ot
1785 @scroll_panel.reload
1786 @scroll_panel.t.should eq 0
1787 @scroll_panel2.reload
1788 @scroll_panel2.t.should eq 1
1789 @scroll_panel3.reload
1790 @scroll_panel3.t.should eq 2
1791 @scroll_panel4.reload
1792 @scroll_panel4.t.should eq 3
1793 @scroll_panel5.reload
1794 @scroll_panel5.t.should eq 4
1795 @scroll_panelc2.reload
1796 @scroll_panelc2.t.should eq 0
1799 r = @scroll_panel4.store @ot
1802 it 'tにエラーメッセージが入っている' do
1803 @scroll_panel4.store @ot
1804 @scroll_panel4.errors[:t].should_not be_empty
1805 @scroll_panel4.valid?.should be_true
1808 context '編集不可だったとき' do
1810 @scroll_panel = FactoryGirl.build :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1811 ScrollPanel.any_instance.stub(:allow?).and_return(false)
1813 it '403Forbidden例外を返す' do
1816 }.should raise_error(ActiveRecord::Forbidden)
1820 describe '切り詰め処理つき削除に於いて' do
1822 @scroll = FactoryGirl.create :scroll, :author_id => @author.id
1823 @panel = FactoryGirl.create :panel, :author_id => @author.id
1824 @scroll_panel = FactoryGirl.create :scroll_panel, :t => 0, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1826 context 'つつがなく終わるとき' do
1829 @scroll_panel.destroy_and_shorten
1830 }.should change(ScrollPanel, :count ).by(-1)
1833 r = @scroll_panel.destroy_and_shorten
1837 context '削除に失敗したとき' do
1839 ScrollPanel.any_instance.stub(:destroy).and_return(false)
1843 @scroll_panel.destroy_and_shorten
1844 }.should_not change(ScrollPanel, :count )
1847 r = @scroll_panel.destroy_and_shorten
1851 #連携テスト。切り詰めが直接DBをいじる
1852 context '2件で先頭を削除したとき' do
1854 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1858 @scroll_panel.destroy_and_shorten
1859 }.should change(ScrollPanel, :count ).by(-1)
1862 @scroll_panel.destroy_and_shorten
1864 ScrollPanel.find @scroll_panel.id
1865 }.should raise_error(ActiveRecord::RecordNotFound)
1868 @scroll_panel.destroy_and_shorten
1869 @scroll_panel2.reload
1870 @scroll_panel2.t.should eq 0
1873 context '3件で先頭を削除したとき' do
1875 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1876 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1880 @scroll_panel.destroy_and_shorten
1881 }.should change(ScrollPanel, :count ).by(-1)
1884 @scroll_panel.destroy_and_shorten
1886 ScrollPanel.find @scroll_panel.id
1887 }.should raise_error(ActiveRecord::RecordNotFound)
1890 @scroll_panel.destroy_and_shorten
1891 @scroll_panel2.reload
1892 @scroll_panel2.t.should eq 0
1895 @scroll_panel.destroy_and_shorten
1896 @scroll_panel3.reload
1897 @scroll_panel3.t.should eq 1
1900 context '5件で3件目を削除したとき' do
1902 @scroll_panel2 = FactoryGirl.create :scroll_panel, :t => 1, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1903 @scroll_panel3 = FactoryGirl.create :scroll_panel, :t => 2, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1904 @scroll_panel4 = FactoryGirl.create :scroll_panel, :t => 3, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1905 @scroll_panel5 = FactoryGirl.create :scroll_panel, :t => 4, :scroll_id => @scroll.id, :panel_id => @panel.id, :author_id => @author.id
1909 @scroll_panel3.destroy_and_shorten
1910 }.should change(ScrollPanel, :count ).by(-1)
1913 @scroll_panel3.destroy_and_shorten
1914 @scroll_panel.reload
1915 @scroll_panel.t.should eq 0
1918 @scroll_panel3.destroy_and_shorten
1919 @scroll_panel2.reload
1920 @scroll_panel2.t.should eq 1
1923 @scroll_panel3.destroy_and_shorten
1925 ScrollPanel.find @scroll_panel3.id
1926 }.should raise_error(ActiveRecord::RecordNotFound)
1929 @scroll_panel3.destroy_and_shorten
1930 @scroll_panel4.reload
1931 @scroll_panel4.t.should eq 2
1934 @scroll_panel3.destroy_and_shorten
1935 @scroll_panel5.reload
1936 @scroll_panel5.t.should eq 3
1939 #ロールバックテスト。切り詰めが直接DBをいじるので、すべてのケースで確実にロールバックを確認する