1 # -*- encoding: utf-8 -*-
5 describe GroundColor 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 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
28 context 'オーソドックスなデータのとき' do
41 context 'panel_idを検証するとき' do
42 #ネストの保存はnilを許可しなければならないので数値チェックだけ
45 @gc.should_not be_valid
48 context 'codeを検証するとき' do
55 @gc.should_not be_valid
59 @gc.should_not be_valid
63 @gc.should_not be_valid
65 it '24bit colorでなければ失敗する' do
67 @gc.should_not be_valid
73 @gc.should_not be_valid
77 @gc.should_not be_valid
81 @gc.should_not be_valid
85 @gc.should_not be_valid
90 describe '文字コード検証に於いて' do
92 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
95 context 'captionを検証するとき' do
96 it 'Shift JISなら失敗する' do
97 @gc.caption = "\x83G\x83r\x83]\x83D"
100 }.should raise_error(Pettanr::BadRequest)
105 describe 'デフォルト値補充に於いて' do
107 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
112 describe '上書き補充に於いて' do
113 it 'panel_idが設定されている' do
114 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
115 @gc.overwrite @panel.id
116 @gc.panel_id.should eq @panel.id
120 describe '閲覧許可に於いて' do
122 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
124 context 'オープンモードのとき' do
126 MagicNumber['run_mode'] = 0
128 it '自身にゲスト用ロールチェックを問い合わせしている' do
129 GroundColor.any_instance.stub(:guest_role_check).and_return(true)
130 GroundColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
131 r = @gc.visible?([@author])
133 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
134 GroundColor.any_instance.stub(:guest_role_check).and_return(false)
135 r = @gc.visible?([@author])
139 context 'クローズドモードのとき' do
141 MagicNumber['run_mode'] = 1
143 it '自身に読者用ロールチェックを問い合わせしている' do
144 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
145 GroundColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
146 r = @gc.visible?([@author])
148 it '読者用ロールチェックが失敗したとき、falseを返す' do
149 GroundColor.any_instance.stub(:reader_role_check).and_return(false)
150 r = @gc.visible?([@author])
154 context '事前チェックする' do
156 MagicNumber['run_mode'] = 1
157 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
159 it '自身のコマに所持判定を問い合わせしている' do
160 Panel.any_instance.stub(:own?).and_return(true)
161 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
162 r = @gc.visible?([@author])
164 it '自身のコマに閲覧許可を問い合わせしている' do
165 Panel.any_instance.stub(:own?).and_return(false)
166 Panel.any_instance.stub(:visible?).and_return(true)
167 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
168 r = @gc.visible?([@author])
171 context 'つつがなく終わるとき' do
173 MagicNumber['run_mode'] = 1
174 Panel.any_instance.stub(:reader_role_check).and_return(true)
176 it '自分のコマの色地なら許可する' do
177 Panel.any_instance.stub(:own?).and_return(true)
178 Panel.any_instance.stub(:visible?).and_return(false)
179 r = @gc.visible?([@author])
182 it '他人の非公開コマの色地なら許可しない' do
183 Panel.any_instance.stub(:own?).and_return(false)
184 Panel.any_instance.stub(:visible?).and_return(false)
185 r = @gc.visible?([@author])
188 it '他人のコマの色地でも公開なら許可する' do
189 Panel.any_instance.stub(:own?).and_return(false)
190 Panel.any_instance.stub(:visible?).and_return(true)
191 r = @gc.visible?([@author])
197 describe '一覧取得に於いて' do
199 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
201 context 'page補正について' do
202 it '文字列から数値に変換される' do
203 GroundColor.page('8').should eq 8
206 GroundColor.page().should eq 1
209 GroundColor.page('0').should eq 1
212 context 'page_size補正について' do
213 it '文字列から数値に変換される' do
214 GroundColor.page_size('7').should eq 7
216 it 'nilの場合はGroundColor.default_page_sizeになる' do
217 GroundColor.page_size().should eq GroundColor.default_page_size
219 it '0以下の場合はGroundColor.default_page_sizeになる' do
220 GroundColor.page_size('0').should eq GroundColor.default_page_size
222 it 'GroundColor.max_page_sizeを超えた場合はGroundColor.max_page_sizeになる' do
223 GroundColor.page_size('1000').should eq GroundColor.max_page_size
226 context 'つつがなく終わるとき' do
227 it '一覧取得オプションを利用している' do
228 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
229 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
234 pl = GroundColor.list
238 #公開コマなら(他人のコマであっても)含んでいる
239 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
240 npl = FactoryGirl.create :ground_color, :panel_id => opl.id, :updated_at => Time.now + 100
241 pl = GroundColor.list
242 pl.should eq [npl, @gc]
244 it '非公開のコマの色地は含まない' do
245 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
246 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :updated_at => Time.now + 100
247 pl = GroundColor.list
250 context 'DBに5件あって1ページの件数を2件に変えたとして' do
252 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
253 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
254 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
255 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
256 GroundColor.stub(:default_page_size).and_return(2)
259 pl = GroundColor.list
260 pl.should have(2).items
262 it 'page=1なら末尾2件を返す' do
264 pl = GroundColor.list(1)
265 pl.should eq [@gc5, @gc4]
267 it 'page=2なら中間2件を返す' do
268 pl = GroundColor.list(2)
269 pl.should eq [@gc3, @gc2]
271 it 'page=3なら先頭1件を返す' do
272 pl = GroundColor.list(3)
278 describe '自分のコマで使った色地一覧取得に於いて' do
280 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
282 context 'つつがなく終わるとき' do
283 it '一覧取得オプションを利用している' do
284 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
285 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
286 r = GroundColor.mylist @author
290 pl = GroundColor.mylist @author
294 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 100
295 pl = GroundColor.mylist @author
296 pl.should eq [npl, @gc]
298 it '他人のコマの色地は公開でも含まない' do
299 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
300 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id
301 pl = GroundColor.mylist @author
304 it '自分のコマの色地は非公開でも含んでいる' do
305 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
306 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :z => 2, :updated_at => Time.now + 100
307 pl = GroundColor.mylist @author
308 pl.should eq [npl, @gc]
310 context 'DBに5件あって1ページの件数を2件に変えたとして' do
312 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
313 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
314 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
315 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
318 c = GroundColor.mylist @author, 1, 2
319 c.should have(2).items
321 it 'page=1なら末尾2件を返す' do
323 c = GroundColor.mylist(@author, 1, 2)
324 c.should eq [@gc5, @gc4]
326 it 'page=2なら中間2件を返す' do
327 c = GroundColor.mylist(@author, 2, 2)
328 c.should eq [@gc3, @gc2]
330 it 'page=3なら先頭1件を返す' do
331 c = GroundColor.mylist(@author, 3, 2)
337 describe '他作家の色地一覧取得に於いて' do
339 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
340 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
341 @other_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id
344 r = GroundColor.himlist @other_author
345 r.should eq [@other_gc]
348 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
349 new_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
350 r = GroundColor.himlist @other_author
351 r.should eq [new_gc, @other_gc]
354 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
355 hidden_gc = FactoryGirl.create :ground_color, :panel_id => hidden_panel.id
356 r = GroundColor.himlist @other_author
357 r.should eq [@other_gc]
359 context 'DBに5件あって1ページの件数を2件に変えたとして' do
361 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
362 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
363 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
364 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
367 pl = GroundColor.himlist @other_author, 1, 2
368 pl.should have(2).items
370 it 'page=1なら末尾2件を返す' do
372 pl = GroundColor.himlist @other_author, 1, 2
373 pl.should eq [@other_gc5, @other_gc4]
375 it 'page=2なら中間2件を返す' do
376 pl = GroundColor.himlist @other_author, 2, 2
377 pl.should eq [@other_gc3, @other_gc2]
379 it 'page=3なら先頭1件を返す' do
380 pl = GroundColor.himlist @other_author, 3, 2
381 pl.should eq [@other_gc]
386 describe '色地一覧ページ制御に於いて' do
388 GroundColor.stub(:count).with(any_args).and_return(100)
391 r = GroundColor.list_paginate
392 r.is_a?(Kaminari::PaginatableArray).should be_true
394 it '色地一覧の取得条件を利用している' do
395 GroundColor.stub(:list_where).with(any_args).and_return('')
396 GroundColor.should_receive(:list_where).with(any_args).exactly(1)
397 r = GroundColor.list_paginate
399 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
400 r = GroundColor.list_paginate 3, 10
401 r.limit_value.should eq 10
402 r.offset_value.should eq 20
406 describe '自分の色地一覧ページ制御に於いて' do
408 GroundColor.stub(:count).with(any_args).and_return(100)
411 r = GroundColor.mylist_paginate @author
412 r.is_a?(Kaminari::PaginatableArray).should be_true
414 it '自分の色地一覧の取得条件を利用している' do
415 GroundColor.stub(:mylist_where).with(any_args).and_return('')
416 GroundColor.should_receive(:mylist_where).with(any_args).exactly(1)
417 r = GroundColor.mylist_paginate @author
419 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
420 r = GroundColor.mylist_paginate @author, 3, 10
421 r.limit_value.should eq 10
422 r.offset_value.should eq 20
426 describe '他作家の色地一覧ページ制御に於いて' do
428 GroundColor.stub(:count).with(any_args).and_return(100)
431 r = GroundColor.himlist_paginate @other_author
432 r.is_a?(Kaminari::PaginatableArray).should be_true
434 it '他作家の色地一覧の取得条件を利用している' do
435 GroundColor.stub(:himlist_where).with(any_args).and_return('')
436 GroundColor.should_receive(:himlist_where).with(any_args).exactly(1)
437 r = GroundColor.himlist_paginate @other_author
439 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
440 r = GroundColor.himlist_paginate @other_author, 3, 10
441 r.limit_value.should eq 10
442 r.offset_value.should eq 20
446 describe '一覧取得オプションに於いて' do
448 r = GroundColor.list_opt
449 r.should have(1).items
452 r = GroundColor.list_opt
453 r.has_key?(:panel).should be_true
456 r = GroundColor.list_opt
457 r[:panel].has_key?(:author).should be_true
460 describe 'json一覧出力オプションに於いて' do
462 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
463 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
464 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
465 @sbt = FactoryGirl.create :speech_balloon_template
466 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
467 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
468 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
469 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
472 r = GroundColor.list.to_json GroundColor.list_json_opt
475 i.has_key?('panel').should be_true
478 r = GroundColor.list.to_json GroundColor.list_json_opt
482 s.has_key?('author').should be_true
486 describe '単体取得に於いて' do
488 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
490 context 'つつがなく終わるとき' do
491 it '単体取得オプションを利用している' do
492 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
493 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
494 r = GroundColor.show @gc.id, @author
496 it '閲覧許可を問い合わせている' do
497 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
498 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
499 r = GroundColor.show @gc.id, @author
503 GroundColor.any_instance.stub(:visible?).and_return(true)
504 pl = GroundColor.show @gc.id, @author
507 context '閲覧許可が出なかったとき' do
508 it '403Forbidden例外を返す' do
509 GroundColor.any_instance.stub(:visible?).and_return(false)
511 GroundColor.show @gc.id, @author
512 }.should raise_error(ActiveRecord::Forbidden)
515 context '存在しない色地を開こうとしたとき' do
516 it '404RecordNotFound例外を返す' do
518 GroundColor.show 110, @author
519 }.should raise_error(ActiveRecord::RecordNotFound)
523 describe '単体取得オプションに於いて' do
524 it 'includeキーを含んでいる' do
525 r = GroundColor.show_opt
526 r.has_key?(:include).should be_true
529 r = GroundColor.show_opt[:include]
530 r.should have(1).items
533 r = GroundColor.show_opt[:include]
534 r.has_key?(:panel).should be_true
537 r = GroundColor.show_opt[:include]
538 r[:panel].has_key?(:author).should be_true
541 describe 'json単体出力オプションに於いて' do
543 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
546 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
549 i.has_key?('panel').should be_true
552 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
556 s.has_key?('author').should be_true