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 '検査対象がnil(ゲスト)のとき' do
154 context 'クローズドモードのとき' do
156 MagicNumber['run_mode'] = 1
159 r = @gp.visible?(nil)
163 context 'オープンモードのとき' do
165 MagicNumber['run_mode'] = 0
167 it '公開されたコマの絵地なら許可する' do
168 Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
169 r = @gp.visible?(nil)
173 Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
174 r = @gp.visible?(nil)
179 context '検査対象が作家のとき' do
180 it '公開されたコマの絵地なら許可する' do
181 Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
182 r = @gp.visible?(@author)
186 Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
187 r = @gp.visible?(@author)
191 context '検査対象が管理者のとき' do
193 Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
194 r = @gp.visible?(@admin)
198 context '検査対象がそれ以外のとき' do
205 describe '一覧取得に於いて' do
207 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
209 context 'page補正について' do
210 it '文字列から数値に変換される' do
211 GroundPicture.page('8').should eq 8
214 GroundPicture.page().should eq 1
217 GroundPicture.page('0').should eq 1
220 context 'page_size補正について' do
221 it '文字列から数値に変換される' do
222 GroundPicture.page_size('7').should eq 7
224 it 'nilの場合はGroundPicture.default_page_sizeになる' do
225 GroundPicture.page_size().should eq GroundPicture.default_page_size
227 it '0以下の場合はGroundPicture.default_page_sizeになる' do
228 GroundPicture.page_size('0').should eq GroundPicture.default_page_size
230 it 'GroundPicture.max_page_sizeを超えた場合はGroundPicture.max_page_sizeになる' do
231 GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
234 context 'つつがなく終わるとき' do
235 it '一覧取得オプションを利用している' do
236 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
237 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
238 r = GroundPicture.list
242 pl = GroundPicture.list
246 #公開コマなら(他人のコマであっても)含んでいる
247 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
248 npl = FactoryGirl.create :ground_picture, :panel_id => opl.id, :picture_id => @p.id, :updated_at => Time.now + 100
249 pl = GroundPicture.list
250 pl.should eq [npl, @gp]
252 it '非公開のコマの絵地は含まない' do
253 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
254 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
255 pl = GroundPicture.list
258 context 'DBに5件あって1ページの件数を2件に変えたとして' do
260 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
261 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
262 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
263 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
264 GroundPicture.stub(:default_page_size).and_return(2)
267 pl = GroundPicture.list
268 pl.should have(2).items
270 it 'page=1なら末尾2件を返す' do
272 pl = GroundPicture.list(1)
273 pl.should eq [@gp5, @gp4]
275 it 'page=2なら中間2件を返す' do
276 pl = GroundPicture.list(2)
277 pl.should eq [@gp3, @gp2]
279 it 'page=3なら先頭1件を返す' do
280 pl = GroundPicture.list(3)
284 context 'DBに5件あって1ページの件数を0件に変えたとして' do
286 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
287 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
288 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
289 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
290 GroundPicture.stub(:default_page_size).and_return(2)
293 r = GroundPicture.list 5, 0
294 r.should have(5).items
298 describe '一覧取得オプションに於いて' do
299 it 'includeキーを含んでいる' do
300 r = GroundPicture.list_opt
301 r.has_key?(:include).should be_true
304 r = GroundPicture.list_opt[:include]
305 r.should have(2).items
308 r = GroundPicture.list_opt[:include]
309 r.has_key?(:panel).should be_true
312 r = GroundPicture.list_opt[:include]
313 r[:panel].has_key?(:author).should be_true
316 r = GroundPicture.list_opt[:include]
317 r.has_key?(:picture).should be_true
320 r = GroundPicture.list_opt[:include]
321 r[:picture].has_key?(:artist).should be_true
323 it '実素材はライセンスを含んでいる' do
324 r = GroundPicture.list_opt[:include]
325 r[:picture].has_key?(:license).should be_true
328 describe 'json一覧出力オプションに於いて' do
330 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
331 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
332 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
333 @sbt = FactoryGirl.create :speech_balloon_template
334 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
335 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
336 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
337 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
340 r = GroundPicture.list.to_json GroundPicture.list_json_opt
343 i.has_key?('panel').should be_true
346 r = GroundPicture.list.to_json GroundPicture.list_json_opt
350 s.has_key?('author').should be_true
353 r = GroundPicture.list.to_json GroundPicture.list_json_opt
356 i.has_key?('picture').should be_true
359 r = GroundPicture.list.to_json GroundPicture.list_json_opt
363 s.has_key?('artist').should be_true
365 it '実素材はライセンスを含んでいる' do
366 r = GroundPicture.list.to_json GroundPicture.list_json_opt
370 s.has_key?('license').should be_true
374 describe '自分のコマで使った絵地一覧取得に於いて' do
376 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
378 context 'つつがなく終わるとき' do
379 it '一覧取得オプションを利用している' do
380 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
381 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
382 r = GroundPicture.mylist @author
386 pl = GroundPicture.mylist @author
390 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
391 pl = GroundPicture.mylist @author
392 pl.should eq [npl, @gp]
394 it '他人のコマの絵地は公開でも含まない' do
395 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
396 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
397 pl = GroundPicture.mylist @author
400 it '自分のコマの絵地は非公開でも含んでいる' do
401 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
402 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
403 pl = GroundPicture.mylist @author
404 pl.should eq [npl, @gp]
406 context 'DBに5件あって1ページの件数を2件に変えたとして' do
408 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
409 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
410 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
411 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
414 c = GroundPicture.mylist @author, 1, 2
415 c.should have(2).items
417 it 'page=1なら末尾2件を返す' do
419 c = GroundPicture.mylist(@author, 1, 2)
420 c.should eq [@gp5, @gp4]
422 it 'page=2なら中間2件を返す' do
423 c = GroundPicture.mylist(@author, 2, 2)
424 c.should eq [@gp3, @gp2]
426 it 'page=3なら先頭1件を返す' do
427 c = GroundPicture.mylist(@author, 3, 2)
431 context 'DBに5件あって1ページの件数を0件に変えたとして' do
433 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
434 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
435 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
436 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
437 Author.stub(:default_ground_picture_page_size).and_return(2)
440 r = GroundPicture.mylist @author, 5, 0
441 r.should have(5).items
446 describe '単体取得に於いて' do
448 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
450 context 'つつがなく終わるとき' do
451 it '単体取得オプションを利用している' do
452 GroundPicture.stub(:show_opt).with(any_args).and_return({:include => :panel})
453 GroundPicture.should_receive(:show_opt).with(any_args).exactly(1)
454 r = GroundPicture.show @gp.id, @author
456 it '閲覧許可を問い合わせている' do
457 GroundPicture.any_instance.stub(:visible?).with(any_args).and_return(true)
458 GroundPicture.any_instance.should_receive(:visible?).with(any_args).exactly(1)
459 r = GroundPicture.show @gp.id, @author
463 GroundPicture.any_instance.stub(:visible?).and_return(true)
464 pl = GroundPicture.show @gp.id, @author
467 context '閲覧許可が出なかったとき' do
468 it '403Forbidden例外を返す' do
469 GroundPicture.any_instance.stub(:visible?).and_return(false)
471 GroundPicture.show @gp.id, @author
472 }.should raise_error(ActiveRecord::Forbidden)
475 context '存在しない絵地を開こうとしたとき' do
476 it '404RecordNotFound例外を返す' do
478 GroundPicture.show 110, @author
479 }.should raise_error(ActiveRecord::RecordNotFound)
483 describe '単体取得オプションに於いて' do
484 it 'includeキーを含んでいる' do
485 r = GroundPicture.show_opt
486 r.has_key?(:include).should be_true
489 r = GroundPicture.show_opt[:include]
490 r.should have(2).items
493 r = GroundPicture.show_opt[:include]
494 r.has_key?(:panel).should be_true
497 r = GroundPicture.show_opt[:include]
498 r[:panel].has_key?(:author).should be_true
501 r = GroundPicture.show_opt[:include]
502 r.has_key?(:picture).should be_true
505 r = GroundPicture.show_opt[:include]
506 r[:picture].has_key?(:artist).should be_true
508 it '実素材はライセンスを含んでいる' do
509 r = GroundPicture.show_opt[:include]
510 r[:picture].has_key?(:license).should be_true
513 describe 'json単体出力オプションに於いて' do
515 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
518 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
521 i.has_key?('panel').should be_true
524 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
528 s.has_key?('author').should be_true
531 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
534 i.has_key?('picture').should be_true
537 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
540 i.has_key?('artist').should be_true
542 it '実素材はライセンスを含んでいる' do
543 r = GroundPicture.show(@gp.id, @author).to_json GroundPicture.show_json_opt
546 i.has_key?('license').should be_true