1 # -*- encoding: utf-8 -*-
5 describe GroundColor do
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @user = FactoryGirl.create( :user_yas)
10 @author = FactoryGirl.create :author, :user_id => @user.id
11 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
12 @other_user = FactoryGirl.create( :user_yas)
13 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
14 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
15 @sp = FactoryGirl.create :system_picture
16 @lg = FactoryGirl.create :license_group
17 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.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
21 @panel = FactoryGirl.create :panel, :author_id => @author.id
26 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
29 context 'オーソドックスなデータのとき' do
44 context 'panel_idを検証するとき' do
45 #ネストの保存はnilを許可しなければならないので数値チェックだけ
48 @gc.should_not be_valid
51 context 'codeを検証するとき' do
58 @gc.should_not be_valid
62 @gc.should_not be_valid
66 @gc.should_not be_valid
68 it '24bit colorでなければ失敗する' do
70 @gc.should_not be_valid
76 @gc.should_not be_valid
80 @gc.should_not be_valid
84 @gc.should_not be_valid
88 @gc.should_not be_valid
94 @gc.should_not be_valid
98 @gc.should_not be_valid
102 @gc.should_not be_valid
107 describe '文字コード検証に於いて' do
109 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
112 context 'captionを検証するとき' do
113 it 'Shift JISなら失敗する' do
114 @gc.caption = "\x83G\x83r\x83]\x83D"
117 }.should raise_error(Pettanr::BadRequest)
122 describe 'デフォルト値補充に於いて' do
124 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
129 describe '上書き補充に於いて' do
130 it 'panel_idが設定されている' do
131 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
132 @gc.overwrite @panel.id
133 @gc.panel_id.should eq @panel.id
137 describe '閲覧許可に於いて' do
139 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
141 context 'オープンモードのとき' do
143 MagicNumber['run_mode'] = 0
145 it '自身にゲスト用ロールチェックを問い合わせしている' do
146 GroundColor.any_instance.stub(:guest_role_check).and_return(true)
147 GroundColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
148 r = @gc.visible?([@author])
150 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
151 GroundColor.any_instance.stub(:guest_role_check).and_return(false)
152 r = @gc.visible?([@author])
156 context 'クローズドモードのとき' do
158 MagicNumber['run_mode'] = 1
160 it '自身に読者用ロールチェックを問い合わせしている' do
161 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
162 GroundColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
163 r = @gc.visible?([@author])
165 it '読者用ロールチェックが失敗したとき、falseを返す' do
166 GroundColor.any_instance.stub(:reader_role_check).and_return(false)
167 r = @gc.visible?([@author])
171 context '事前チェックする' do
173 MagicNumber['run_mode'] = 1
174 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
176 it '自身のコマに所持判定を問い合わせしている' do
177 Panel.any_instance.stub(:own?).and_return(true)
178 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
179 r = @gc.visible?([@author])
181 it '自身のコマに閲覧許可を問い合わせしている' do
182 Panel.any_instance.stub(:own?).and_return(false)
183 Panel.any_instance.stub(:visible?).and_return(true)
184 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
185 r = @gc.visible?([@author])
188 context 'つつがなく終わるとき' do
190 MagicNumber['run_mode'] = 1
191 Panel.any_instance.stub(:reader_role_check).and_return(true)
193 it '自分のコマの色地なら許可する' do
194 Panel.any_instance.stub(:own?).and_return(true)
195 Panel.any_instance.stub(:visible?).and_return(false)
196 r = @gc.visible?([@author])
199 it '他人の非公開コマの色地なら許可しない' do
200 Panel.any_instance.stub(:own?).and_return(false)
201 Panel.any_instance.stub(:visible?).and_return(false)
202 r = @gc.visible?([@author])
205 it '他人のコマの色地でも公開なら許可する' do
206 Panel.any_instance.stub(:own?).and_return(false)
207 Panel.any_instance.stub(:visible?).and_return(true)
208 r = @gc.visible?([@author])
214 describe '一覧取得に於いて' do
216 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
218 context 'page補正について' do
219 it '文字列から数値に変換される' do
220 GroundColor.page('8').should eq 8
223 GroundColor.page().should eq 1
226 GroundColor.page('0').should eq 1
229 context 'page_size補正について' do
230 it '文字列から数値に変換される' do
231 GroundColor.page_size('7').should eq 7
233 it 'nilの場合はGroundColor.default_page_sizeになる' do
234 GroundColor.page_size().should eq GroundColor.default_page_size
236 it '0以下の場合はGroundColor.default_page_sizeになる' do
237 GroundColor.page_size('0').should eq GroundColor.default_page_size
239 it 'GroundColor.max_page_sizeを超えた場合はGroundColor.max_page_sizeになる' do
240 GroundColor.page_size('1000').should eq GroundColor.max_page_size
243 context 'つつがなく終わるとき' do
244 it '一覧取得オプションを利用している' do
245 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
246 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
251 pl = GroundColor.list
255 #公開コマなら(他人のコマであっても)含んでいる
256 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
257 npl = FactoryGirl.create :ground_color, :panel_id => opl.id, :updated_at => Time.now + 100
258 pl = GroundColor.list
259 pl.should eq [npl, @gc]
261 it '非公開のコマの色地は含まない' do
262 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
263 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :updated_at => Time.now + 100
264 pl = GroundColor.list
267 context 'DBに5件あって1ページの件数を2件に変えたとして' do
269 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
270 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
271 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
272 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
273 GroundColor.stub(:default_page_size).and_return(2)
276 pl = GroundColor.list
277 pl.should have(2).items
279 it 'page=1なら末尾2件を返す' do
281 pl = GroundColor.list(1)
282 pl.should eq [@gc5, @gc4]
284 it 'page=2なら中間2件を返す' do
285 pl = GroundColor.list(2)
286 pl.should eq [@gc3, @gc2]
288 it 'page=3なら先頭1件を返す' do
289 pl = GroundColor.list(3)
295 describe '自分のコマで使った色地一覧取得に於いて' do
297 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
299 context 'つつがなく終わるとき' do
300 it '一覧取得オプションを利用している' do
301 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
302 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
303 r = GroundColor.mylist @author
307 pl = GroundColor.mylist @author
311 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 100
312 pl = GroundColor.mylist @author
313 pl.should eq [npl, @gc]
315 it '他人のコマの色地は公開でも含まない' do
316 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
317 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id
318 pl = GroundColor.mylist @author
321 it '自分のコマの色地は非公開でも含んでいる' do
322 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
323 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :z => 2, :updated_at => Time.now + 100
324 pl = GroundColor.mylist @author
325 pl.should eq [npl, @gc]
327 context 'DBに5件あって1ページの件数を2件に変えたとして' do
329 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
330 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
331 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
332 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
335 c = GroundColor.mylist @author, 1, 2
336 c.should have(2).items
338 it 'page=1なら末尾2件を返す' do
340 c = GroundColor.mylist(@author, 1, 2)
341 c.should eq [@gc5, @gc4]
343 it 'page=2なら中間2件を返す' do
344 c = GroundColor.mylist(@author, 2, 2)
345 c.should eq [@gc3, @gc2]
347 it 'page=3なら先頭1件を返す' do
348 c = GroundColor.mylist(@author, 3, 2)
354 describe '他作家の色地一覧取得に於いて' do
356 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
357 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
358 @other_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id
361 r = GroundColor.himlist @other_author
362 r.should eq [@other_gc]
365 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
366 new_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
367 r = GroundColor.himlist @other_author
368 r.should eq [new_gc, @other_gc]
371 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
372 hidden_gc = FactoryGirl.create :ground_color, :panel_id => hidden_panel.id
373 r = GroundColor.himlist @other_author
374 r.should eq [@other_gc]
376 context 'DBに5件あって1ページの件数を2件に変えたとして' do
378 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
379 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
380 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
381 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
384 pl = GroundColor.himlist @other_author, 1, 2
385 pl.should have(2).items
387 it 'page=1なら末尾2件を返す' do
389 pl = GroundColor.himlist @other_author, 1, 2
390 pl.should eq [@other_gc5, @other_gc4]
392 it 'page=2なら中間2件を返す' do
393 pl = GroundColor.himlist @other_author, 2, 2
394 pl.should eq [@other_gc3, @other_gc2]
396 it 'page=3なら先頭1件を返す' do
397 pl = GroundColor.himlist @other_author, 3, 2
398 pl.should eq [@other_gc]
403 describe '色地一覧ページ制御に於いて' do
405 GroundColor.stub(:count).with(any_args).and_return(100)
408 r = GroundColor.list_paginate
409 r.is_a?(Kaminari::PaginatableArray).should be_true
411 it '色地一覧の取得条件を利用している' do
412 GroundColor.stub(:list_where).with(any_args).and_return('')
413 GroundColor.should_receive(:list_where).with(any_args).exactly(1)
414 r = GroundColor.list_paginate
416 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
417 r = GroundColor.list_paginate 3, 10
418 r.limit_value.should eq 10
419 r.offset_value.should eq 20
423 describe '自分の色地一覧ページ制御に於いて' do
425 GroundColor.stub(:count).with(any_args).and_return(100)
428 r = GroundColor.mylist_paginate @author
429 r.is_a?(Kaminari::PaginatableArray).should be_true
431 it '自分の色地一覧の取得条件を利用している' do
432 GroundColor.stub(:mylist_where).with(any_args).and_return('')
433 GroundColor.should_receive(:mylist_where).with(any_args).exactly(1)
434 r = GroundColor.mylist_paginate @author
436 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
437 r = GroundColor.mylist_paginate @author, 3, 10
438 r.limit_value.should eq 10
439 r.offset_value.should eq 20
443 describe '他作家の色地一覧ページ制御に於いて' do
445 GroundColor.stub(:count).with(any_args).and_return(100)
448 r = GroundColor.himlist_paginate @other_author
449 r.is_a?(Kaminari::PaginatableArray).should be_true
451 it '他作家の色地一覧の取得条件を利用している' do
452 GroundColor.stub(:himlist_where).with(any_args).and_return('')
453 GroundColor.should_receive(:himlist_where).with(any_args).exactly(1)
454 r = GroundColor.himlist_paginate @other_author
456 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
457 r = GroundColor.himlist_paginate @other_author, 3, 10
458 r.limit_value.should eq 10
459 r.offset_value.should eq 20
463 describe '一覧取得オプションに於いて' do
465 r = GroundColor.list_opt
466 r.should have(1).items
469 r = GroundColor.list_opt
470 r.has_key?(:panel).should be_true
473 r = GroundColor.list_opt
474 r[:panel].has_key?(:author).should be_true
477 describe 'json一覧出力オプションに於いて' do
479 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
480 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
481 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
482 @sbt = FactoryGirl.create :speech_balloon_template
483 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
484 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
485 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
486 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
489 r = GroundColor.list.to_json GroundColor.list_json_opt
492 i.has_key?('panel').should be_true
495 r = GroundColor.list.to_json GroundColor.list_json_opt
499 s.has_key?('author').should be_true
503 describe '単体取得に於いて' do
505 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
507 context 'つつがなく終わるとき' do
508 it '単体取得オプションを利用している' do
509 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
510 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
511 r = GroundColor.show @gc.id, @author
513 it '閲覧許可を問い合わせている' do
514 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
515 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
516 r = GroundColor.show @gc.id, @author
520 GroundColor.any_instance.stub(:visible?).and_return(true)
521 pl = GroundColor.show @gc.id, @author
524 context '閲覧許可が出なかったとき' do
525 it '403Forbidden例外を返す' do
526 GroundColor.any_instance.stub(:visible?).and_return(false)
528 GroundColor.show @gc.id, @author
529 }.should raise_error(ActiveRecord::Forbidden)
532 context '存在しない色地を開こうとしたとき' do
533 it '404RecordNotFound例外を返す' do
535 GroundColor.show 110, @author
536 }.should raise_error(ActiveRecord::RecordNotFound)
540 describe '単体取得オプションに於いて' do
541 it 'includeキーを含んでいる' do
542 r = GroundColor.show_opt
543 r.has_key?(:include).should be_true
546 r = GroundColor.show_opt[:include]
547 r.should have(1).items
550 r = GroundColor.show_opt[:include]
551 r.has_key?(:panel).should be_true
554 r = GroundColor.show_opt[:include]
555 r[:panel].has_key?(:author).should be_true
558 describe 'json単体出力オプションに於いて' do
560 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
563 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
566 i.has_key?('panel').should be_true
569 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
573 s.has_key?('author').should be_true