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
50 context 'panel_idを検証するとき' do
51 #ネストの保存はnilを許可しなければならないので数値チェックだけ
54 @gc.should_not be_valid
57 context 'codeを検証するとき' do
64 @gc.should_not be_valid
68 @gc.should_not be_valid
72 @gc.should_not be_valid
74 it '24bit colorでなければ失敗する' do
76 @gc.should_not be_valid
79 context 'orientationを検証するとき' do
82 @gc.should_not be_valid
86 @gc.should_not be_valid
90 @gc.should_not be_valid
94 @gc.should_not be_valid
97 context 'xyを検証するとき' do
104 @gc.should_not be_valid
108 @gc.should_not be_valid
111 context 'whを検証するとき' do
118 @gc.should_not be_valid
122 @gc.should_not be_valid
125 context 'zを検証するとき' do
128 @gc.should_not be_valid
132 @gc.should_not be_valid
136 @gc.should_not be_valid
140 @gc.should_not be_valid
143 context 'tを検証するとき' do
146 @gc.should_not be_valid
150 @gc.should_not be_valid
154 @gc.should_not be_valid
159 describe '文字コード検証に於いて' do
161 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
164 context 'captionを検証するとき' do
165 it 'Shift JISなら失敗する' do
166 @gc.caption = "\x83G\x83r\x83]\x83D"
169 }.should raise_error(Pettanr::BadRequest)
174 describe 'デフォルト値補充に於いて' do
176 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
181 describe '上書き補充に於いて' do
182 it 'panel_idが設定されている' do
183 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
184 @gc.overwrite @panel.id
185 @gc.panel_id.should eq @panel.id
189 describe '閲覧許可に於いて' do
191 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
193 context 'オープンモードのとき' do
195 MagicNumber['run_mode'] = 0
197 it '自身にゲスト用ロールチェックを問い合わせしている' do
198 GroundColor.any_instance.stub(:guest_role_check).and_return(true)
199 GroundColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
200 r = @gc.visible?([@author])
202 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
203 GroundColor.any_instance.stub(:guest_role_check).and_return(false)
204 r = @gc.visible?([@author])
208 context 'クローズドモードのとき' do
210 MagicNumber['run_mode'] = 1
212 it '自身に読者用ロールチェックを問い合わせしている' do
213 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
214 GroundColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
215 r = @gc.visible?([@author])
217 it '読者用ロールチェックが失敗したとき、falseを返す' do
218 GroundColor.any_instance.stub(:reader_role_check).and_return(false)
219 r = @gc.visible?([@author])
223 context '事前チェックする' do
225 MagicNumber['run_mode'] = 1
226 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
228 it '自身のコマに所持判定を問い合わせしている' do
229 Panel.any_instance.stub(:own?).and_return(true)
230 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
231 r = @gc.visible?([@author])
233 it '自身のコマに閲覧許可を問い合わせしている' do
234 Panel.any_instance.stub(:own?).and_return(false)
235 Panel.any_instance.stub(:visible?).and_return(true)
236 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
237 r = @gc.visible?([@author])
240 context 'つつがなく終わるとき' do
242 MagicNumber['run_mode'] = 1
243 Panel.any_instance.stub(:reader_role_check).and_return(true)
245 it '自分のコマの色地なら許可する' do
246 Panel.any_instance.stub(:own?).and_return(true)
247 Panel.any_instance.stub(:visible?).and_return(false)
248 r = @gc.visible?([@author])
251 it '他人の非公開コマの色地なら許可しない' do
252 Panel.any_instance.stub(:own?).and_return(false)
253 Panel.any_instance.stub(:visible?).and_return(false)
254 r = @gc.visible?([@author])
257 it '他人のコマの色地でも公開なら許可する' do
258 Panel.any_instance.stub(:own?).and_return(false)
259 Panel.any_instance.stub(:visible?).and_return(true)
260 r = @gc.visible?([@author])
266 describe '一覧取得に於いて' do
268 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
270 context 'page補正について' do
271 it '文字列から数値に変換される' do
272 GroundColor.page('8').should eq 8
275 GroundColor.page().should eq 1
278 GroundColor.page('0').should eq 1
281 context 'page_size補正について' do
282 it '文字列から数値に変換される' do
283 GroundColor.page_size('7').should eq 7
285 it 'nilの場合はGroundColor.default_page_sizeになる' do
286 GroundColor.page_size().should eq GroundColor.default_page_size
288 it '0以下の場合はGroundColor.default_page_sizeになる' do
289 GroundColor.page_size('0').should eq GroundColor.default_page_size
291 it 'GroundColor.max_page_sizeを超えた場合はGroundColor.max_page_sizeになる' do
292 GroundColor.page_size('1000').should eq GroundColor.max_page_size
295 context 'つつがなく終わるとき' do
296 it '一覧取得オプションを利用している' do
297 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
298 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
303 pl = GroundColor.list
307 #公開コマなら(他人のコマであっても)含んでいる
308 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
309 npl = FactoryGirl.create :ground_color, :panel_id => opl.id, :updated_at => Time.now + 100
310 pl = GroundColor.list
311 pl.should eq [npl, @gc]
313 it '非公開のコマの色地は含まない' do
314 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
315 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :updated_at => Time.now + 100
316 pl = GroundColor.list
319 context 'DBに5件あって1ページの件数を2件に変えたとして' do
321 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
322 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
323 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
324 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
325 GroundColor.stub(:default_page_size).and_return(2)
328 pl = GroundColor.list
329 pl.should have(2).items
331 it 'page=1なら末尾2件を返す' do
333 pl = GroundColor.list(1)
334 pl.should eq [@gc5, @gc4]
336 it 'page=2なら中間2件を返す' do
337 pl = GroundColor.list(2)
338 pl.should eq [@gc3, @gc2]
340 it 'page=3なら先頭1件を返す' do
341 pl = GroundColor.list(3)
347 describe '自分のコマで使った色地一覧取得に於いて' do
349 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
351 context 'つつがなく終わるとき' do
352 it '一覧取得オプションを利用している' do
353 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
354 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
355 r = GroundColor.mylist @author
359 pl = GroundColor.mylist @author
363 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 100
364 pl = GroundColor.mylist @author
365 pl.should eq [npl, @gc]
367 it '他人のコマの色地は公開でも含まない' do
368 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
369 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id
370 pl = GroundColor.mylist @author
373 it '自分のコマの色地は非公開でも含んでいる' do
374 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
375 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :z => 2, :updated_at => Time.now + 100
376 pl = GroundColor.mylist @author
377 pl.should eq [npl, @gc]
379 context 'DBに5件あって1ページの件数を2件に変えたとして' do
381 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
382 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
383 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
384 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
387 c = GroundColor.mylist @author, 1, 2
388 c.should have(2).items
390 it 'page=1なら末尾2件を返す' do
392 c = GroundColor.mylist(@author, 1, 2)
393 c.should eq [@gc5, @gc4]
395 it 'page=2なら中間2件を返す' do
396 c = GroundColor.mylist(@author, 2, 2)
397 c.should eq [@gc3, @gc2]
399 it 'page=3なら先頭1件を返す' do
400 c = GroundColor.mylist(@author, 3, 2)
406 describe '他作家の色地一覧取得に於いて' do
408 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
409 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
410 @other_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id
413 r = GroundColor.himlist @other_author
414 r.should eq [@other_gc]
417 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
418 new_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
419 r = GroundColor.himlist @other_author
420 r.should eq [new_gc, @other_gc]
423 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
424 hidden_gc = FactoryGirl.create :ground_color, :panel_id => hidden_panel.id
425 r = GroundColor.himlist @other_author
426 r.should eq [@other_gc]
428 context 'DBに5件あって1ページの件数を2件に変えたとして' do
430 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
431 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
432 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
433 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
436 pl = GroundColor.himlist @other_author, 1, 2
437 pl.should have(2).items
439 it 'page=1なら末尾2件を返す' do
441 pl = GroundColor.himlist @other_author, 1, 2
442 pl.should eq [@other_gc5, @other_gc4]
444 it 'page=2なら中間2件を返す' do
445 pl = GroundColor.himlist @other_author, 2, 2
446 pl.should eq [@other_gc3, @other_gc2]
448 it 'page=3なら先頭1件を返す' do
449 pl = GroundColor.himlist @other_author, 3, 2
450 pl.should eq [@other_gc]
455 describe '色地一覧ページ制御に於いて' do
457 GroundColor.stub(:count).with(any_args).and_return(100)
460 r = GroundColor.list_paginate
461 r.is_a?(Kaminari::PaginatableArray).should be_true
463 it '色地一覧の取得条件を利用している' do
464 GroundColor.stub(:list_where).with(any_args).and_return('')
465 GroundColor.should_receive(:list_where).with(any_args).exactly(1)
466 r = GroundColor.list_paginate
468 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
469 r = GroundColor.list_paginate 3, 10
470 r.limit_value.should eq 10
471 r.offset_value.should eq 20
475 describe '自分の色地一覧ページ制御に於いて' do
477 GroundColor.stub(:count).with(any_args).and_return(100)
480 r = GroundColor.mylist_paginate @author
481 r.is_a?(Kaminari::PaginatableArray).should be_true
483 it '自分の色地一覧の取得条件を利用している' do
484 GroundColor.stub(:mylist_where).with(any_args).and_return('')
485 GroundColor.should_receive(:mylist_where).with(any_args).exactly(1)
486 r = GroundColor.mylist_paginate @author
488 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
489 r = GroundColor.mylist_paginate @author, 3, 10
490 r.limit_value.should eq 10
491 r.offset_value.should eq 20
495 describe '他作家の色地一覧ページ制御に於いて' do
497 GroundColor.stub(:count).with(any_args).and_return(100)
500 r = GroundColor.himlist_paginate @other_author
501 r.is_a?(Kaminari::PaginatableArray).should be_true
503 it '他作家の色地一覧の取得条件を利用している' do
504 GroundColor.stub(:himlist_where).with(any_args).and_return('')
505 GroundColor.should_receive(:himlist_where).with(any_args).exactly(1)
506 r = GroundColor.himlist_paginate @other_author
508 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
509 r = GroundColor.himlist_paginate @other_author, 3, 10
510 r.limit_value.should eq 10
511 r.offset_value.should eq 20
515 describe '一覧取得オプションに於いて' do
517 r = GroundColor.list_opt
518 r.should have(1).items
521 r = GroundColor.list_opt
522 r.has_key?(:panel).should be_true
525 r = GroundColor.list_opt
526 r[:panel].has_key?(:author).should be_true
529 describe 'json一覧出力オプションに於いて' do
531 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
532 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
533 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
534 @sbt = FactoryGirl.create :speech_balloon_template
535 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
536 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
537 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
538 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
541 r = GroundColor.list.to_json GroundColor.list_json_opt
544 i.has_key?('panel').should be_true
547 r = GroundColor.list.to_json GroundColor.list_json_opt
551 s.has_key?('author').should be_true
555 describe '単体取得に於いて' do
557 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
559 context 'つつがなく終わるとき' do
560 it '単体取得オプションを利用している' do
561 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
562 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
563 r = GroundColor.show @gc.id, @author
565 it '閲覧許可を問い合わせている' do
566 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
567 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
568 r = GroundColor.show @gc.id, @author
572 GroundColor.any_instance.stub(:visible?).and_return(true)
573 pl = GroundColor.show @gc.id, @author
576 context '閲覧許可が出なかったとき' do
577 it '403Forbidden例外を返す' do
578 GroundColor.any_instance.stub(:visible?).and_return(false)
580 GroundColor.show @gc.id, @author
581 }.should raise_error(ActiveRecord::Forbidden)
584 context '存在しない色地を開こうとしたとき' do
585 it '404RecordNotFound例外を返す' do
587 GroundColor.show 110, @author
588 }.should raise_error(ActiveRecord::RecordNotFound)
592 describe '単体取得オプションに於いて' do
593 it 'includeキーを含んでいる' do
594 r = GroundColor.show_opt
595 r.has_key?(:include).should be_true
598 r = GroundColor.show_opt[:include]
599 r.should have(1).items
602 r = GroundColor.show_opt[:include]
603 r.has_key?(:panel).should be_true
606 r = GroundColor.show_opt[:include]
607 r[:panel].has_key?(:author).should be_true
610 describe 'json単体出力オプションに於いて' do
612 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
615 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
618 i.has_key?('panel').should be_true
621 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
625 s.has_key?('author').should be_true