1 # -*- encoding: utf-8 -*-
5 describe GroundPicture 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 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
29 context 'オーソドックスなデータのとき' do
48 context 'panel_idを検証するとき' do
49 #ネストの保存はnilを許可しなければならないので数値チェックだけ
52 @gp.should_not be_valid
55 context 'picture_idを検証するとき' do
58 @gp.should_not be_valid
62 @gp.should_not be_valid
64 it '存在する実素材でなければ失敗する' do
66 @gp.should_not be_valid
69 context 'repeatを検証するとき' do
72 @gp.should_not be_valid
76 @gp.should_not be_valid
80 @gp.should_not be_valid
84 @gp.should_not be_valid
90 @gp.should_not be_valid
94 @gp.should_not be_valid
100 @gp.should_not be_valid
104 @gp.should_not be_valid
107 context 'zを検証するとき' do
110 @gp.should_not be_valid
114 @gp.should_not be_valid
118 @gp.should_not be_valid
122 @gp.should_not be_valid
125 context 'tを検証するとき' do
128 @gp.should_not be_valid
132 @gp.should_not be_valid
136 @gp.should_not be_valid
141 describe '文字コード検証に於いて' do
143 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
146 context 'captionを検証するとき' do
147 it 'Shift JISなら失敗する' do
148 @gp.caption = "\x83G\x83r\x83]\x83D"
151 }.should raise_error(Pettanr::BadRequest)
156 describe 'デフォルト値補充に於いて' do
158 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
168 it '繰り返しに0を補充している' do
170 @gp.repeat.should eq 0
174 describe '上書き補充に於いて' do
175 it 'panel_idが設定されている' do
176 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
177 @gp.overwrite @panel.id
178 @gp.panel_id.should eq @panel.id
182 describe '閲覧許可に於いて' do
184 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
186 context 'オープンモードのとき' do
188 MagicNumber['run_mode'] = 0
190 it '自身にゲスト用ロールチェックを問い合わせしている' do
191 GroundPicture.any_instance.stub(:guest_role_check).and_return(true)
192 GroundPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
193 r = @gp.visible?([@author])
195 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
196 GroundPicture.any_instance.stub(:guest_role_check).and_return(false)
197 r = @gp.visible?([@author])
201 context 'クローズドモードのとき' do
203 MagicNumber['run_mode'] = 1
205 it '自身に読者用ロールチェックを問い合わせしている' do
206 GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
207 GroundPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
208 r = @gp.visible?([@author])
210 it '読者用ロールチェックが失敗したとき、falseを返す' do
211 GroundPicture.any_instance.stub(:reader_role_check).and_return(false)
212 r = @gp.visible?([@author])
216 context '事前チェックする' do
218 MagicNumber['run_mode'] = 1
219 GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
221 it '自身のコマに所持判定を問い合わせしている' do
222 Panel.any_instance.stub(:own?).and_return(true)
223 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
224 r = @gp.visible?([@author])
226 it '自身のコマに閲覧許可を問い合わせしている' do
227 Panel.any_instance.stub(:own?).and_return(false)
228 Panel.any_instance.stub(:visible?).and_return(true)
229 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
230 r = @gp.visible?([@author])
233 context 'つつがなく終わるとき' do
235 MagicNumber['run_mode'] = 1
236 Panel.any_instance.stub(:reader_role_check).and_return(true)
238 it '自分のコマの絵地なら許可する' do
239 Panel.any_instance.stub(:own?).and_return(true)
240 Panel.any_instance.stub(:visible?).and_return(false)
241 r = @gp.visible?([@author])
244 it '他人の非公開コマの絵地なら許可しない' do
245 Panel.any_instance.stub(:own?).and_return(false)
246 Panel.any_instance.stub(:visible?).and_return(false)
247 r = @gp.visible?([@author])
250 it '他人のコマの絵地でも公開なら許可する' do
251 Panel.any_instance.stub(:own?).and_return(false)
252 Panel.any_instance.stub(:visible?).and_return(true)
253 r = @gp.visible?([@author])
259 describe '一覧取得に於いて' do
261 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
263 context 'page補正について' do
264 it '文字列から数値に変換される' do
265 GroundPicture.page('8').should eq 8
268 GroundPicture.page().should eq 1
271 GroundPicture.page('0').should eq 1
274 context 'page_size補正について' do
275 it '文字列から数値に変換される' do
276 GroundPicture.page_size('7').should eq 7
278 it 'nilの場合はGroundPicture.default_page_sizeになる' do
279 GroundPicture.page_size().should eq GroundPicture.default_page_size
281 it '0以下の場合はGroundPicture.default_page_sizeになる' do
282 GroundPicture.page_size('0').should eq GroundPicture.default_page_size
284 it 'GroundPicture.max_page_sizeを超えた場合はGroundPicture.max_page_sizeになる' do
285 GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
288 context 'つつがなく終わるとき' do
289 it '一覧取得オプションを利用している' do
290 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
291 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
292 r = GroundPicture.list
296 pl = GroundPicture.list
300 #公開コマなら(他人のコマであっても)含んでいる
301 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
302 npl = FactoryGirl.create :ground_picture, :panel_id => opl.id, :picture_id => @p.id, :updated_at => Time.now + 100
303 pl = GroundPicture.list
304 pl.should eq [npl, @gp]
306 it '非公開のコマの絵地は含まない' do
307 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
308 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
309 pl = GroundPicture.list
312 context 'DBに5件あって1ページの件数を2件に変えたとして' do
314 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
315 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
316 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
317 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
318 GroundPicture.stub(:default_page_size).and_return(2)
321 pl = GroundPicture.list
322 pl.should have(2).items
324 it 'page=1なら末尾2件を返す' do
326 pl = GroundPicture.list(1)
327 pl.should eq [@gp5, @gp4]
329 it 'page=2なら中間2件を返す' do
330 pl = GroundPicture.list(2)
331 pl.should eq [@gp3, @gp2]
333 it 'page=3なら先頭1件を返す' do
334 pl = GroundPicture.list(3)
340 describe '自分のコマで使った絵地一覧取得に於いて' do
342 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
344 context 'つつがなく終わるとき' do
345 it '一覧取得オプションを利用している' do
346 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
347 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
348 r = GroundPicture.mylist @author
352 pl = GroundPicture.mylist @author
356 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
357 pl = GroundPicture.mylist @author
358 pl.should eq [npl, @gp]
360 it '他人のコマの絵地は公開でも含まない' do
361 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
362 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
363 pl = GroundPicture.mylist @author
366 it '自分のコマの絵地は非公開でも含んでいる' do
367 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
368 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
369 pl = GroundPicture.mylist @author
370 pl.should eq [npl, @gp]
372 context 'DBに5件あって1ページの件数を2件に変えたとして' do
374 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
375 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
376 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
377 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
380 c = GroundPicture.mylist @author, 1, 2
381 c.should have(2).items
383 it 'page=1なら末尾2件を返す' do
385 c = GroundPicture.mylist(@author, 1, 2)
386 c.should eq [@gp5, @gp4]
388 it 'page=2なら中間2件を返す' do
389 c = GroundPicture.mylist(@author, 2, 2)
390 c.should eq [@gp3, @gp2]
392 it 'page=3なら先頭1件を返す' do
393 c = GroundPicture.mylist(@author, 3, 2)
399 describe '他作家の絵地一覧取得に於いて' do
401 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
402 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
403 @other_gp = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id
406 r = GroundPicture.himlist @other_author
407 r.should eq [@other_gp]
410 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
411 new_gp = FactoryGirl.create :ground_picture, :panel_id => new_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
412 r = GroundPicture.himlist @other_author
413 r.should eq [new_gp, @other_gp]
416 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
417 hidden_gp = FactoryGirl.create :ground_picture, :panel_id => hidden_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
418 r = GroundPicture.himlist @other_author
419 r.should eq [@other_gp]
421 context 'DBに5件あって1ページの件数を2件に変えたとして' do
423 @other_gp2 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
424 @other_gp3 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 200
425 @other_gp4 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 300
426 @other_gp5 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 400
429 pl = GroundPicture.himlist @other_author, 1, 2
430 pl.should have(2).items
432 it 'page=1なら末尾2件を返す' do
434 pl = GroundPicture.himlist @other_author, 1, 2
435 pl.should eq [@other_gp5, @other_gp4]
437 it 'page=2なら中間2件を返す' do
438 pl = GroundPicture.himlist @other_author, 2, 2
439 pl.should eq [@other_gp3, @other_gp2]
441 it 'page=3なら先頭1件を返す' do
442 pl = GroundPicture.himlist @other_author, 3, 2
443 pl.should eq [@other_gp]
448 describe '絵地一覧ページ制御に於いて' do
450 GroundPicture.stub(:count).with(any_args).and_return(100)
453 r = GroundPicture.list_paginate
454 r.is_a?(Kaminari::PaginatableArray).should be_true
456 it '絵地一覧の取得条件を利用している' do
457 GroundPicture.stub(:list_where).with(any_args).and_return('')
458 GroundPicture.should_receive(:list_where).with(any_args).exactly(1)
459 r = GroundPicture.list_paginate
461 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
462 r = GroundPicture.list_paginate 3, 10
463 r.limit_value.should eq 10
464 r.offset_value.should eq 20
468 describe '自分の絵地一覧ページ制御に於いて' do
470 GroundPicture.stub(:count).with(any_args).and_return(100)
473 r = GroundPicture.mylist_paginate @author
474 r.is_a?(Kaminari::PaginatableArray).should be_true
476 it '自分の絵地一覧の取得条件を利用している' do
477 GroundPicture.stub(:mylist_where).with(any_args).and_return('')
478 GroundPicture.should_receive(:mylist_where).with(any_args).exactly(1)
479 r = GroundPicture.mylist_paginate @author
481 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
482 r = GroundPicture.mylist_paginate @author, 3, 10
483 r.limit_value.should eq 10
484 r.offset_value.should eq 20
488 describe '他作家の絵地一覧ページ制御に於いて' do
490 GroundPicture.stub(:count).with(any_args).and_return(100)
493 r = GroundPicture.himlist_paginate @other_author
494 r.is_a?(Kaminari::PaginatableArray).should be_true
496 it '他作家の絵地一覧の取得条件を利用している' do
497 GroundPicture.stub(:himlist_where).with(any_args).and_return('')
498 GroundPicture.should_receive(:himlist_where).with(any_args).exactly(1)
499 r = GroundPicture.himlist_paginate @other_author
501 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
502 r = GroundPicture.himlist_paginate @other_author, 3, 10
503 r.limit_value.should eq 10
504 r.offset_value.should eq 20
508 describe '一覧取得オプションに於いて' do
510 r = GroundPicture.list_opt
511 r.should have(2).items
514 r = GroundPicture.list_opt
515 r.has_key?(:panel).should be_true
518 r = GroundPicture.list_opt
519 r[:panel].has_key?(:author).should be_true
522 r = GroundPicture.list_opt
523 r.has_key?(:picture).should be_true
526 r = GroundPicture.list_opt
527 r[:picture].has_key?(:artist).should be_true
529 it '実素材はライセンスを含んでいる' do
530 r = GroundPicture.list_opt
531 r[:picture].has_key?(:license).should be_true
534 describe 'json一覧出力オプションに於いて' do
536 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
537 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
538 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
539 @sbt = FactoryGirl.create :speech_balloon_template
540 @scroll = FactoryGirl.create :scroll, :author_id => @author.id, :visible => 1
541 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
542 @scroll_panel = FactoryGirl.create :scroll_panel, :author_id => @author.id, :scroll_id => @scroll.id, :panel_id => @panel.id
543 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
546 r = GroundPicture.list.to_json GroundPicture.list_json_opt
549 i.has_key?('panel').should be_true
552 r = GroundPicture.list.to_json GroundPicture.list_json_opt
556 s.has_key?('author').should be_true
559 r = GroundPicture.list.to_json GroundPicture.list_json_opt
562 i.has_key?('picture').should be_true
565 r = GroundPicture.list.to_json GroundPicture.list_json_opt
569 s.has_key?('artist').should be_true
571 it '実素材はライセンスを含んでいる' do
572 r = GroundPicture.list.to_json GroundPicture.list_json_opt
576 s.has_key?('license').should be_true
580 describe '単体取得に於いて' do
582 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
584 context 'つつがなく終わるとき' do
585 it '単体取得オプションを利用している' do
586 GroundPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
587 GroundPicture.should_receive(:show_opt).with(any_args).exactly(1)
588 r = GroundPicture.show @gp.id, @author
590 it '閲覧許可を問い合わせている' do
591 GroundPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
592 GroundPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
593 r = GroundPicture.show @gp.id, @author
597 GroundPicture.any_instance.stub(:visible?).and_return(true)
598 pl = GroundPicture.show @gp.id, @author
601 context '閲覧許可が出なかったとき' do
602 it '403Forbidden例外を返す' do
603 GroundPicture.any_instance.stub(:visible?).and_return(false)
605 GroundPicture.show @gp.id, @author
606 }.should raise_error(ActiveRecord::Forbidden)
609 context '存在しない絵地を開こうとしたとき' do
610 it '404RecordNotFound例外を返す' do
612 GroundPicture.show 110, @author
613 }.should raise_error(ActiveRecord::RecordNotFound)
617 describe '単体取得オプションに於いて' do
618 it 'includeキーを含んでいる' do
619 r = GroundPicture.show_opt
620 r.has_key?(:include).should be_true
623 r = GroundPicture.show_opt[:include]
624 r.should have(2).items
627 r = GroundPicture.show_opt[:include]
628 r.has_key?(:panel).should be_true
631 r = GroundPicture.show_opt[:include]
632 r[:panel].has_key?(:author).should be_true
635 r = GroundPicture.show_opt[:include]
636 r.has_key?(:picture).should be_true
639 r = GroundPicture.show_opt[:include]
640 r[:picture].has_key?(:artist).should be_true
642 it '実素材はライセンスを含んでいる' do
643 r = GroundPicture.show_opt[:include]
644 r[:picture].has_key?(:license).should be_true
647 describe 'json単体出力オプションに於いて' do
649 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
652 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
655 i.has_key?('panel').should be_true
658 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
662 s.has_key?('author').should be_true
665 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
668 i.has_key?('picture').should be_true
671 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
674 i.has_key?('artist').should be_true
676 it '実素材はライセンスを含んでいる' do
677 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
680 i.has_key?('license').should be_true