1 # -*- encoding: utf-8 -*-
5 describe GroundPicture do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @other_user = FactoryGirl.create( :user_yas)
12 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
13 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
14 @sp = FactoryGirl.create :system_picture
15 @lg = FactoryGirl.create :license_group
16 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
17 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
18 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
19 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
20 @panel = FactoryGirl.create :panel, :author_id => @author.id
25 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
28 context 'オーソドックスなデータのとき' do
47 context 'panel_idを検証するとき' do
48 #ネストの保存はnilを許可しなければならないので数値チェックだけ
51 @gp.should_not be_valid
54 context 'picture_idを検証するとき' do
57 @gp.should_not be_valid
61 @gp.should_not be_valid
63 it '存在する実素材でなければ失敗する' do
65 @gp.should_not be_valid
68 context 'repeatを検証するとき' do
71 @gp.should_not be_valid
75 @gp.should_not be_valid
79 @gp.should_not be_valid
83 @gp.should_not be_valid
89 @gp.should_not be_valid
93 @gp.should_not be_valid
99 @gp.should_not be_valid
103 @gp.should_not be_valid
106 context 'zを検証するとき' do
109 @gp.should_not be_valid
113 @gp.should_not be_valid
117 @gp.should_not be_valid
121 @gp.should_not be_valid
124 context 'tを検証するとき' do
127 @gp.should_not be_valid
131 @gp.should_not be_valid
135 @gp.should_not be_valid
140 describe '文字コード検証に於いて' do
142 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
145 context 'captionを検証するとき' do
146 it 'Shift JISなら失敗する' do
147 @gp.caption = "\x83G\x83r\x83]\x83D"
150 }.should raise_error(Pettanr::BadRequest)
155 describe 'デフォルト値補充に於いて' do
157 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
167 it '繰り返しに0を補充している' do
169 @gp.repeat.should eq 0
173 describe '上書き補充に於いて' do
174 it 'panel_idが設定されている' do
175 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
176 @gp.overwrite @panel.id
177 @gp.panel_id.should eq @panel.id
181 describe '閲覧許可に於いて' do
183 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
185 context 'オープンモードのとき' do
187 MagicNumber['run_mode'] = 0
189 it '自身にゲスト用ロールチェックを問い合わせしている' do
190 GroundPicture.any_instance.stub(:guest_role_check).and_return(true)
191 GroundPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
192 r = @gp.visible?([@author])
194 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
195 GroundPicture.any_instance.stub(:guest_role_check).and_return(false)
196 r = @gp.visible?([@author])
200 context 'クローズドモードのとき' do
202 MagicNumber['run_mode'] = 1
204 it '自身に読者用ロールチェックを問い合わせしている' do
205 GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
206 GroundPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
207 r = @gp.visible?([@author])
209 it '読者用ロールチェックが失敗したとき、falseを返す' do
210 GroundPicture.any_instance.stub(:reader_role_check).and_return(false)
211 r = @gp.visible?([@author])
215 context '事前チェックする' do
217 MagicNumber['run_mode'] = 1
218 GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
220 it '自身のコマに所持判定を問い合わせしている' do
221 Panel.any_instance.stub(:own?).and_return(true)
222 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
223 r = @gp.visible?([@author])
225 it '自身のコマに閲覧許可を問い合わせしている' do
226 Panel.any_instance.stub(:own?).and_return(false)
227 Panel.any_instance.stub(:visible?).and_return(true)
228 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
229 r = @gp.visible?([@author])
232 context 'つつがなく終わるとき' do
234 MagicNumber['run_mode'] = 1
235 Panel.any_instance.stub(:reader_role_check).and_return(true)
237 it '自分のコマの絵地なら許可する' do
238 Panel.any_instance.stub(:own?).and_return(true)
239 Panel.any_instance.stub(:visible?).and_return(false)
240 r = @gp.visible?([@author])
243 it '他人の非公開コマの絵地なら許可しない' do
244 Panel.any_instance.stub(:own?).and_return(false)
245 Panel.any_instance.stub(:visible?).and_return(false)
246 r = @gp.visible?([@author])
249 it '他人のコマの絵地でも公開なら許可する' do
250 Panel.any_instance.stub(:own?).and_return(false)
251 Panel.any_instance.stub(:visible?).and_return(true)
252 r = @gp.visible?([@author])
258 describe '一覧取得に於いて' do
260 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
262 context 'page補正について' do
263 it '文字列から数値に変換される' do
264 GroundPicture.page('8').should eq 8
267 GroundPicture.page().should eq 1
270 GroundPicture.page('0').should eq 1
273 context 'page_size補正について' do
274 it '文字列から数値に変換される' do
275 GroundPicture.page_size('7').should eq 7
277 it 'nilの場合はGroundPicture.default_page_sizeになる' do
278 GroundPicture.page_size().should eq GroundPicture.default_page_size
280 it '0以下の場合はGroundPicture.default_page_sizeになる' do
281 GroundPicture.page_size('0').should eq GroundPicture.default_page_size
283 it 'GroundPicture.max_page_sizeを超えた場合はGroundPicture.max_page_sizeになる' do
284 GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
287 context 'つつがなく終わるとき' do
288 it '一覧取得オプションを利用している' do
289 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
290 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
291 r = GroundPicture.list
295 pl = GroundPicture.list
299 #公開コマなら(他人のコマであっても)含んでいる
300 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
301 npl = FactoryGirl.create :ground_picture, :panel_id => opl.id, :picture_id => @p.id, :updated_at => Time.now + 100
302 pl = GroundPicture.list
303 pl.should eq [npl, @gp]
305 it '非公開のコマの絵地は含まない' do
306 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
307 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
308 pl = GroundPicture.list
311 context 'DBに5件あって1ページの件数を2件に変えたとして' do
313 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
314 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
315 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
316 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
317 GroundPicture.stub(:default_page_size).and_return(2)
320 pl = GroundPicture.list
321 pl.should have(2).items
323 it 'page=1なら末尾2件を返す' do
325 pl = GroundPicture.list(1)
326 pl.should eq [@gp5, @gp4]
328 it 'page=2なら中間2件を返す' do
329 pl = GroundPicture.list(2)
330 pl.should eq [@gp3, @gp2]
332 it 'page=3なら先頭1件を返す' do
333 pl = GroundPicture.list(3)
339 describe '自分のコマで使った絵地一覧取得に於いて' do
341 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
343 context 'つつがなく終わるとき' do
344 it '一覧取得オプションを利用している' do
345 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
346 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
347 r = GroundPicture.mylist @author
351 pl = GroundPicture.mylist @author
355 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
356 pl = GroundPicture.mylist @author
357 pl.should eq [npl, @gp]
359 it '他人のコマの絵地は公開でも含まない' do
360 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
361 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
362 pl = GroundPicture.mylist @author
365 it '自分のコマの絵地は非公開でも含んでいる' do
366 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
367 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
368 pl = GroundPicture.mylist @author
369 pl.should eq [npl, @gp]
371 context 'DBに5件あって1ページの件数を2件に変えたとして' do
373 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
374 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
375 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
376 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
379 c = GroundPicture.mylist @author, 1, 2
380 c.should have(2).items
382 it 'page=1なら末尾2件を返す' do
384 c = GroundPicture.mylist(@author, 1, 2)
385 c.should eq [@gp5, @gp4]
387 it 'page=2なら中間2件を返す' do
388 c = GroundPicture.mylist(@author, 2, 2)
389 c.should eq [@gp3, @gp2]
391 it 'page=3なら先頭1件を返す' do
392 c = GroundPicture.mylist(@author, 3, 2)
398 describe '他作家の絵地一覧取得に於いて' do
400 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
401 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
402 @other_gp = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id
405 r = GroundPicture.himlist @other_author
406 r.should eq [@other_gp]
409 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
410 new_gp = FactoryGirl.create :ground_picture, :panel_id => new_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
411 r = GroundPicture.himlist @other_author
412 r.should eq [new_gp, @other_gp]
415 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
416 hidden_gp = FactoryGirl.create :ground_picture, :panel_id => hidden_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
417 r = GroundPicture.himlist @other_author
418 r.should eq [@other_gp]
420 context 'DBに5件あって1ページの件数を2件に変えたとして' do
422 @other_gp2 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
423 @other_gp3 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 200
424 @other_gp4 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 300
425 @other_gp5 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 400
428 pl = GroundPicture.himlist @other_author, 1, 2
429 pl.should have(2).items
431 it 'page=1なら末尾2件を返す' do
433 pl = GroundPicture.himlist @other_author, 1, 2
434 pl.should eq [@other_gp5, @other_gp4]
436 it 'page=2なら中間2件を返す' do
437 pl = GroundPicture.himlist @other_author, 2, 2
438 pl.should eq [@other_gp3, @other_gp2]
440 it 'page=3なら先頭1件を返す' do
441 pl = GroundPicture.himlist @other_author, 3, 2
442 pl.should eq [@other_gp]
447 describe '絵地一覧ページ制御に於いて' do
449 GroundPicture.stub(:count).with(any_args).and_return(100)
452 r = GroundPicture.list_paginate
453 r.is_a?(Kaminari::PaginatableArray).should be_true
455 it '絵地一覧の取得条件を利用している' do
456 GroundPicture.stub(:list_where).with(any_args).and_return('')
457 GroundPicture.should_receive(:list_where).with(any_args).exactly(1)
458 r = GroundPicture.list_paginate
460 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
461 r = GroundPicture.list_paginate 3, 10
462 r.limit_value.should eq 10
463 r.offset_value.should eq 20
467 describe '自分の絵地一覧ページ制御に於いて' do
469 GroundPicture.stub(:count).with(any_args).and_return(100)
472 r = GroundPicture.mylist_paginate @author
473 r.is_a?(Kaminari::PaginatableArray).should be_true
475 it '自分の絵地一覧の取得条件を利用している' do
476 GroundPicture.stub(:mylist_where).with(any_args).and_return('')
477 GroundPicture.should_receive(:mylist_where).with(any_args).exactly(1)
478 r = GroundPicture.mylist_paginate @author
480 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
481 r = GroundPicture.mylist_paginate @author, 3, 10
482 r.limit_value.should eq 10
483 r.offset_value.should eq 20
487 describe '他作家の絵地一覧ページ制御に於いて' do
489 GroundPicture.stub(:count).with(any_args).and_return(100)
492 r = GroundPicture.himlist_paginate @other_author
493 r.is_a?(Kaminari::PaginatableArray).should be_true
495 it '他作家の絵地一覧の取得条件を利用している' do
496 GroundPicture.stub(:himlist_where).with(any_args).and_return('')
497 GroundPicture.should_receive(:himlist_where).with(any_args).exactly(1)
498 r = GroundPicture.himlist_paginate @other_author
500 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
501 r = GroundPicture.himlist_paginate @other_author, 3, 10
502 r.limit_value.should eq 10
503 r.offset_value.should eq 20
507 describe '一覧取得オプションに於いて' do
509 r = GroundPicture.list_opt
510 r.should have(2).items
513 r = GroundPicture.list_opt
514 r.has_key?(:panel).should be_true
517 r = GroundPicture.list_opt
518 r[:panel].has_key?(:author).should be_true
521 r = GroundPicture.list_opt
522 r.has_key?(:picture).should be_true
525 r = GroundPicture.list_opt
526 r[:picture].has_key?(:artist).should be_true
528 it '実素材はライセンスを含んでいる' do
529 r = GroundPicture.list_opt
530 r[:picture].has_key?(:license).should be_true
533 describe 'json一覧出力オプションに於いて' do
535 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
536 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
537 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
538 @sbt = FactoryGirl.create :speech_balloon_template
539 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
540 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
541 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
542 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
545 r = GroundPicture.list.to_json GroundPicture.list_json_opt
548 i.has_key?('panel').should be_true
551 r = GroundPicture.list.to_json GroundPicture.list_json_opt
555 s.has_key?('author').should be_true
558 r = GroundPicture.list.to_json GroundPicture.list_json_opt
561 i.has_key?('picture').should be_true
564 r = GroundPicture.list.to_json GroundPicture.list_json_opt
568 s.has_key?('artist').should be_true
570 it '実素材はライセンスを含んでいる' do
571 r = GroundPicture.list.to_json GroundPicture.list_json_opt
575 s.has_key?('license').should be_true
579 describe '単体取得に於いて' do
581 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
583 context 'つつがなく終わるとき' do
584 it '単体取得オプションを利用している' do
585 GroundPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
586 GroundPicture.should_receive(:show_opt).with(any_args).exactly(1)
587 r = GroundPicture.show @gp.id, @author
589 it '閲覧許可を問い合わせている' do
590 GroundPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
591 GroundPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
592 r = GroundPicture.show @gp.id, @author
596 GroundPicture.any_instance.stub(:visible?).and_return(true)
597 pl = GroundPicture.show @gp.id, @author
600 context '閲覧許可が出なかったとき' do
601 it '403Forbidden例外を返す' do
602 GroundPicture.any_instance.stub(:visible?).and_return(false)
604 GroundPicture.show @gp.id, @author
605 }.should raise_error(ActiveRecord::Forbidden)
608 context '存在しない絵地を開こうとしたとき' do
609 it '404RecordNotFound例外を返す' do
611 GroundPicture.show 110, @author
612 }.should raise_error(ActiveRecord::RecordNotFound)
616 describe '単体取得オプションに於いて' do
617 it 'includeキーを含んでいる' do
618 r = GroundPicture.show_opt
619 r.has_key?(:include).should be_true
622 r = GroundPicture.show_opt[:include]
623 r.should have(2).items
626 r = GroundPicture.show_opt[:include]
627 r.has_key?(:panel).should be_true
630 r = GroundPicture.show_opt[:include]
631 r[:panel].has_key?(:author).should be_true
634 r = GroundPicture.show_opt[:include]
635 r.has_key?(:picture).should be_true
638 r = GroundPicture.show_opt[:include]
639 r[:picture].has_key?(:artist).should be_true
641 it '実素材はライセンスを含んでいる' do
642 r = GroundPicture.show_opt[:include]
643 r[:picture].has_key?(:license).should be_true
646 describe 'json単体出力オプションに於いて' do
648 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
651 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
654 i.has_key?('panel').should be_true
657 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
661 s.has_key?('author').should be_true
664 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
667 i.has_key?('picture').should be_true
670 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
673 i.has_key?('artist').should be_true
675 it '実素材はライセンスを含んでいる' do
676 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
679 i.has_key?('license').should be_true