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
45 context 'panel_idを検証するとき' do
46 #ネストの保存はnilを許可しなければならないので数値チェックだけ
49 @gp.should_not be_valid
52 context 'picture_idを検証するとき' do
55 @gp.should_not be_valid
59 @gp.should_not be_valid
61 it '存在する実素材でなければ失敗する' do
63 @gp.should_not be_valid
66 context 'repeatを検証するとき' do
69 @gp.should_not be_valid
73 @gp.should_not be_valid
77 @gp.should_not be_valid
81 @gp.should_not be_valid
87 @gp.should_not be_valid
91 @gp.should_not be_valid
97 @gp.should_not be_valid
101 @gp.should_not be_valid
104 context 'zを検証するとき' do
107 @gp.should_not be_valid
111 @gp.should_not be_valid
115 @gp.should_not be_valid
119 @gp.should_not be_valid
124 describe 'デフォルト値補充に於いて' do
126 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
136 it '繰り返しに0を補充している' do
138 @gp.repeat.should eq 0
142 describe '上書き補充に於いて' do
144 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
149 describe '閲覧許可に於いて' do
151 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
153 context 'オープンモードのとき' do
155 MagicNumber['run_mode'] = 0
157 it '自身にゲスト用ロールチェックを問い合わせしている' do
158 GroundPicture.any_instance.stub(:guest_role_check).and_return(true)
159 GroundPicture.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
160 r = @gp.visible?([@author])
162 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
163 GroundPicture.any_instance.stub(:guest_role_check).and_return(false)
164 r = @gp.visible?([@author])
168 context 'クローズドモードのとき' do
170 MagicNumber['run_mode'] = 1
172 it '自身に読者用ロールチェックを問い合わせしている' do
173 GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
174 GroundPicture.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
175 r = @gp.visible?([@author])
177 it '読者用ロールチェックが失敗したとき、falseを返す' do
178 GroundPicture.any_instance.stub(:reader_role_check).and_return(false)
179 r = @gp.visible?([@author])
183 context '事前チェックする' do
185 MagicNumber['run_mode'] = 1
186 GroundPicture.any_instance.stub(:reader_role_check).and_return(true)
188 it '自身のコマに所持判定を問い合わせしている' do
189 Panel.any_instance.stub(:own?).and_return(true)
190 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
191 r = @gp.visible?([@author])
193 it '自身のコマに閲覧許可を問い合わせしている' do
194 Panel.any_instance.stub(:own?).and_return(false)
195 Panel.any_instance.stub(:visible?).and_return(true)
196 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
197 r = @gp.visible?([@author])
200 context 'つつがなく終わるとき' do
202 MagicNumber['run_mode'] = 1
203 Panel.any_instance.stub(:reader_role_check).and_return(true)
205 it '自分のコマの絵地なら許可する' do
206 Panel.any_instance.stub(:own?).and_return(true)
207 Panel.any_instance.stub(:visible?).and_return(false)
208 r = @gp.visible?([@author])
211 it '他人の非公開コマの絵地なら許可しない' do
212 Panel.any_instance.stub(:own?).and_return(false)
213 Panel.any_instance.stub(:visible?).and_return(false)
214 r = @gp.visible?([@author])
217 it '他人のコマの絵地でも公開なら許可する' do
218 Panel.any_instance.stub(:own?).and_return(false)
219 Panel.any_instance.stub(:visible?).and_return(true)
220 r = @gp.visible?([@author])
226 describe '一覧取得に於いて' do
228 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
230 context 'page補正について' do
231 it '文字列から数値に変換される' do
232 GroundPicture.page('8').should eq 8
235 GroundPicture.page().should eq 1
238 GroundPicture.page('0').should eq 1
241 context 'page_size補正について' do
242 it '文字列から数値に変換される' do
243 GroundPicture.page_size('7').should eq 7
245 it 'nilの場合はGroundPicture.default_page_sizeになる' do
246 GroundPicture.page_size().should eq GroundPicture.default_page_size
248 it '0以下の場合はGroundPicture.default_page_sizeになる' do
249 GroundPicture.page_size('0').should eq GroundPicture.default_page_size
251 it 'GroundPicture.max_page_sizeを超えた場合はGroundPicture.max_page_sizeになる' do
252 GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
255 context 'つつがなく終わるとき' do
256 it '一覧取得オプションを利用している' do
257 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
258 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
259 r = GroundPicture.list
263 pl = GroundPicture.list
267 #公開コマなら(他人のコマであっても)含んでいる
268 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
269 npl = FactoryGirl.create :ground_picture, :panel_id => opl.id, :picture_id => @p.id, :updated_at => Time.now + 100
270 pl = GroundPicture.list
271 pl.should eq [npl, @gp]
273 it '非公開のコマの絵地は含まない' do
274 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
275 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
276 pl = GroundPicture.list
279 context 'DBに5件あって1ページの件数を2件に変えたとして' do
281 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
282 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
283 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
284 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
285 GroundPicture.stub(:default_page_size).and_return(2)
288 pl = GroundPicture.list
289 pl.should have(2).items
291 it 'page=1なら末尾2件を返す' do
293 pl = GroundPicture.list(1)
294 pl.should eq [@gp5, @gp4]
296 it 'page=2なら中間2件を返す' do
297 pl = GroundPicture.list(2)
298 pl.should eq [@gp3, @gp2]
300 it 'page=3なら先頭1件を返す' do
301 pl = GroundPicture.list(3)
307 describe '自分のコマで使った絵地一覧取得に於いて' do
309 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
311 context 'つつがなく終わるとき' do
312 it '一覧取得オプションを利用している' do
313 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
314 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
315 r = GroundPicture.mylist @author
319 pl = GroundPicture.mylist @author
323 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
324 pl = GroundPicture.mylist @author
325 pl.should eq [npl, @gp]
327 it '他人のコマの絵地は公開でも含まない' do
328 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
329 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
330 pl = GroundPicture.mylist @author
333 it '自分のコマの絵地は非公開でも含んでいる' do
334 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
335 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
336 pl = GroundPicture.mylist @author
337 pl.should eq [npl, @gp]
339 context 'DBに5件あって1ページの件数を2件に変えたとして' do
341 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
342 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
343 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
344 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
347 c = GroundPicture.mylist @author, 1, 2
348 c.should have(2).items
350 it 'page=1なら末尾2件を返す' do
352 c = GroundPicture.mylist(@author, 1, 2)
353 c.should eq [@gp5, @gp4]
355 it 'page=2なら中間2件を返す' do
356 c = GroundPicture.mylist(@author, 2, 2)
357 c.should eq [@gp3, @gp2]
359 it 'page=3なら先頭1件を返す' do
360 c = GroundPicture.mylist(@author, 3, 2)
366 describe '他作家の絵地一覧取得に於いて' do
368 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
369 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
370 @other_gp = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id
373 r = GroundPicture.himlist @other_author
374 r.should eq [@other_gp]
377 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
378 new_gp = FactoryGirl.create :ground_picture, :panel_id => new_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
379 r = GroundPicture.himlist @other_author
380 r.should eq [new_gp, @other_gp]
383 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
384 hidden_gp = FactoryGirl.create :ground_picture, :panel_id => hidden_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
385 r = GroundPicture.himlist @other_author
386 r.should eq [@other_gp]
388 context 'DBに5件あって1ページの件数を2件に変えたとして' do
390 @other_gp2 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 100
391 @other_gp3 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 200
392 @other_gp4 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 300
393 @other_gp5 = FactoryGirl.create :ground_picture, :panel_id => @other_panel.id, :picture_id => @p.id, :updated_at => Time.now + 400
396 pl = GroundPicture.himlist @other_author, 1, 2
397 pl.should have(2).items
399 it 'page=1なら末尾2件を返す' do
401 pl = GroundPicture.himlist @other_author, 1, 2
402 pl.should eq [@other_gp5, @other_gp4]
404 it 'page=2なら中間2件を返す' do
405 pl = GroundPicture.himlist @other_author, 2, 2
406 pl.should eq [@other_gp3, @other_gp2]
408 it 'page=3なら先頭1件を返す' do
409 pl = GroundPicture.himlist @other_author, 3, 2
410 pl.should eq [@other_gp]
415 describe '絵地一覧ページ制御に於いて' do
417 GroundPicture.stub(:count).with(any_args).and_return(100)
420 r = GroundPicture.list_paginate
421 r.is_a?(Kaminari::PaginatableArray).should be_true
423 it '絵地一覧の取得条件を利用している' do
424 GroundPicture.stub(:list_where).with(any_args).and_return('')
425 GroundPicture.should_receive(:list_where).with(any_args).exactly(1)
426 r = GroundPicture.list_paginate
428 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
429 r = GroundPicture.list_paginate 3, 10
430 r.limit_value.should eq 10
431 r.offset_value.should eq 20
435 describe '自分の絵地一覧ページ制御に於いて' do
437 GroundPicture.stub(:count).with(any_args).and_return(100)
440 r = GroundPicture.mylist_paginate @author
441 r.is_a?(Kaminari::PaginatableArray).should be_true
443 it '自分の絵地一覧の取得条件を利用している' do
444 GroundPicture.stub(:mylist_where).with(any_args).and_return('')
445 GroundPicture.should_receive(:mylist_where).with(any_args).exactly(1)
446 r = GroundPicture.mylist_paginate @author
448 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
449 r = GroundPicture.mylist_paginate @author, 3, 10
450 r.limit_value.should eq 10
451 r.offset_value.should eq 20
455 describe '他作家の絵地一覧ページ制御に於いて' do
457 GroundPicture.stub(:count).with(any_args).and_return(100)
460 r = GroundPicture.himlist_paginate @other_author
461 r.is_a?(Kaminari::PaginatableArray).should be_true
463 it '他作家の絵地一覧の取得条件を利用している' do
464 GroundPicture.stub(:himlist_where).with(any_args).and_return('')
465 GroundPicture.should_receive(:himlist_where).with(any_args).exactly(1)
466 r = GroundPicture.himlist_paginate @other_author
468 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
469 r = GroundPicture.himlist_paginate @other_author, 3, 10
470 r.limit_value.should eq 10
471 r.offset_value.should eq 20
475 describe '一覧取得オプションに於いて' do
477 r = GroundPicture.list_opt
478 r.should have(2).items
481 r = GroundPicture.list_opt
482 r.has_key?(:panel).should be_true
485 r = GroundPicture.list_opt
486 r[:panel].has_key?(:author).should be_true
489 r = GroundPicture.list_opt
490 r.has_key?(:picture).should be_true
493 r = GroundPicture.list_opt
494 r[:picture].has_key?(:artist).should be_true
496 it '実素材はライセンスを含んでいる' do
497 r = GroundPicture.list_opt
498 r[:picture].has_key?(:license).should be_true
501 describe 'json一覧出力オプションに於いて' do
503 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
504 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
505 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
506 @sbt = FactoryGirl.create :speech_balloon_template
507 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
508 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
509 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
510 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
513 r = GroundPicture.list.to_json GroundPicture.list_json_opt
516 i.has_key?('panel').should be_true
519 r = GroundPicture.list.to_json GroundPicture.list_json_opt
523 s.has_key?('author').should be_true
526 r = GroundPicture.list.to_json GroundPicture.list_json_opt
529 i.has_key?('picture').should be_true
532 r = GroundPicture.list.to_json GroundPicture.list_json_opt
536 s.has_key?('artist').should be_true
538 it '実素材はライセンスを含んでいる' do
539 r = GroundPicture.list.to_json GroundPicture.list_json_opt
543 s.has_key?('license').should be_true
547 describe '単体取得に於いて' do
549 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
551 context 'つつがなく終わるとき' do
552 it '単体取得オプションを利用している' do
553 GroundPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
554 GroundPicture.should_receive(:show_opt).with(any_args).exactly(1)
555 r = GroundPicture.show @gp.id, @author
557 it '閲覧許可を問い合わせている' do
558 GroundPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
559 GroundPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
560 r = GroundPicture.show @gp.id, @author
564 GroundPicture.any_instance.stub(:visible?).and_return(true)
565 pl = GroundPicture.show @gp.id, @author
568 context '閲覧許可が出なかったとき' do
569 it '403Forbidden例外を返す' do
570 GroundPicture.any_instance.stub(:visible?).and_return(false)
572 GroundPicture.show @gp.id, @author
573 }.should raise_error(ActiveRecord::Forbidden)
576 context '存在しない絵地を開こうとしたとき' do
577 it '404RecordNotFound例外を返す' do
579 GroundPicture.show 110, @author
580 }.should raise_error(ActiveRecord::RecordNotFound)
584 describe '単体取得オプションに於いて' do
585 it 'includeキーを含んでいる' do
586 r = GroundPicture.show_opt
587 r.has_key?(:include).should be_true
590 r = GroundPicture.show_opt[:include]
591 r.should have(2).items
594 r = GroundPicture.show_opt[:include]
595 r.has_key?(:panel).should be_true
598 r = GroundPicture.show_opt[:include]
599 r[:panel].has_key?(:author).should be_true
602 r = GroundPicture.show_opt[:include]
603 r.has_key?(:picture).should be_true
606 r = GroundPicture.show_opt[:include]
607 r[:picture].has_key?(:artist).should be_true
609 it '実素材はライセンスを含んでいる' do
610 r = GroundPicture.show_opt[:include]
611 r[:picture].has_key?(:license).should be_true
614 describe 'json単体出力オプションに於いて' do
616 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
619 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
622 i.has_key?('panel').should be_true
625 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
629 s.has_key?('author').should be_true
632 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
635 i.has_key?('picture').should be_true
638 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
641 i.has_key?('artist').should be_true
643 it '実素材はライセンスを含んでいる' do
644 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
647 i.has_key?('license').should be_true