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
43 context 'panel_idを検証するとき' do
44 #ネストの保存はnilを許可しなければならないので数値チェックだけ
47 @gc.should_not be_valid
50 context 'codeを検証するとき' do
57 @gc.should_not be_valid
61 @gc.should_not be_valid
65 @gc.should_not be_valid
67 it '24bit colorでなければ失敗する' do
69 @gc.should_not be_valid
75 @gc.should_not be_valid
79 @gc.should_not be_valid
83 @gc.should_not be_valid
87 @gc.should_not be_valid
93 @gc.should_not be_valid
97 @gc.should_not be_valid
101 @gc.should_not be_valid
106 describe '文字コード検証に於いて' do
108 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
111 context 'captionを検証するとき' do
112 it 'Shift JISなら失敗する' do
113 @gc.caption = "\x83G\x83r\x83]\x83D"
116 }.should raise_error(Pettanr::BadRequest)
121 describe 'デフォルト値補充に於いて' do
123 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
128 describe '上書き補充に於いて' do
129 it 'panel_idが設定されている' do
130 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
131 @gc.overwrite @panel.id
132 @gc.panel_id.should eq @panel.id
136 describe '閲覧許可に於いて' do
138 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
140 context 'オープンモードのとき' do
142 MagicNumber['run_mode'] = 0
144 it '自身にゲスト用ロールチェックを問い合わせしている' do
145 GroundColor.any_instance.stub(:guest_role_check).and_return(true)
146 GroundColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
147 r = @gc.visible?([@author])
149 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
150 GroundColor.any_instance.stub(:guest_role_check).and_return(false)
151 r = @gc.visible?([@author])
155 context 'クローズドモードのとき' do
157 MagicNumber['run_mode'] = 1
159 it '自身に読者用ロールチェックを問い合わせしている' do
160 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
161 GroundColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
162 r = @gc.visible?([@author])
164 it '読者用ロールチェックが失敗したとき、falseを返す' do
165 GroundColor.any_instance.stub(:reader_role_check).and_return(false)
166 r = @gc.visible?([@author])
170 context '事前チェックする' do
172 MagicNumber['run_mode'] = 1
173 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
175 it '自身のコマに所持判定を問い合わせしている' do
176 Panel.any_instance.stub(:own?).and_return(true)
177 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
178 r = @gc.visible?([@author])
180 it '自身のコマに閲覧許可を問い合わせしている' do
181 Panel.any_instance.stub(:own?).and_return(false)
182 Panel.any_instance.stub(:visible?).and_return(true)
183 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
184 r = @gc.visible?([@author])
187 context 'つつがなく終わるとき' do
189 MagicNumber['run_mode'] = 1
190 Panel.any_instance.stub(:reader_role_check).and_return(true)
192 it '自分のコマの色地なら許可する' do
193 Panel.any_instance.stub(:own?).and_return(true)
194 Panel.any_instance.stub(:visible?).and_return(false)
195 r = @gc.visible?([@author])
198 it '他人の非公開コマの色地なら許可しない' do
199 Panel.any_instance.stub(:own?).and_return(false)
200 Panel.any_instance.stub(:visible?).and_return(false)
201 r = @gc.visible?([@author])
204 it '他人のコマの色地でも公開なら許可する' do
205 Panel.any_instance.stub(:own?).and_return(false)
206 Panel.any_instance.stub(:visible?).and_return(true)
207 r = @gc.visible?([@author])
213 describe '一覧取得に於いて' do
215 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
217 context 'page補正について' do
218 it '文字列から数値に変換される' do
219 GroundColor.page('8').should eq 8
222 GroundColor.page().should eq 1
225 GroundColor.page('0').should eq 1
228 context 'page_size補正について' do
229 it '文字列から数値に変換される' do
230 GroundColor.page_size('7').should eq 7
232 it 'nilの場合はGroundColor.default_page_sizeになる' do
233 GroundColor.page_size().should eq GroundColor.default_page_size
235 it '0以下の場合はGroundColor.default_page_sizeになる' do
236 GroundColor.page_size('0').should eq GroundColor.default_page_size
238 it 'GroundColor.max_page_sizeを超えた場合はGroundColor.max_page_sizeになる' do
239 GroundColor.page_size('1000').should eq GroundColor.max_page_size
242 context 'つつがなく終わるとき' do
243 it '一覧取得オプションを利用している' do
244 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
245 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
250 pl = GroundColor.list
254 #公開コマなら(他人のコマであっても)含んでいる
255 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
256 npl = FactoryGirl.create :ground_color, :panel_id => opl.id, :updated_at => Time.now + 100
257 pl = GroundColor.list
258 pl.should eq [npl, @gc]
260 it '非公開のコマの色地は含まない' do
261 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
262 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :updated_at => Time.now + 100
263 pl = GroundColor.list
266 context 'DBに5件あって1ページの件数を2件に変えたとして' do
268 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
269 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
270 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
271 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
272 GroundColor.stub(:default_page_size).and_return(2)
275 pl = GroundColor.list
276 pl.should have(2).items
278 it 'page=1なら末尾2件を返す' do
280 pl = GroundColor.list(1)
281 pl.should eq [@gc5, @gc4]
283 it 'page=2なら中間2件を返す' do
284 pl = GroundColor.list(2)
285 pl.should eq [@gc3, @gc2]
287 it 'page=3なら先頭1件を返す' do
288 pl = GroundColor.list(3)
294 describe '自分のコマで使った色地一覧取得に於いて' do
296 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
298 context 'つつがなく終わるとき' do
299 it '一覧取得オプションを利用している' do
300 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
301 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
302 r = GroundColor.mylist @author
306 pl = GroundColor.mylist @author
310 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 100
311 pl = GroundColor.mylist @author
312 pl.should eq [npl, @gc]
314 it '他人のコマの色地は公開でも含まない' do
315 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
316 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id
317 pl = GroundColor.mylist @author
320 it '自分のコマの色地は非公開でも含んでいる' do
321 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
322 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :z => 2, :updated_at => Time.now + 100
323 pl = GroundColor.mylist @author
324 pl.should eq [npl, @gc]
326 context 'DBに5件あって1ページの件数を2件に変えたとして' do
328 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
329 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
330 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
331 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
334 c = GroundColor.mylist @author, 1, 2
335 c.should have(2).items
337 it 'page=1なら末尾2件を返す' do
339 c = GroundColor.mylist(@author, 1, 2)
340 c.should eq [@gc5, @gc4]
342 it 'page=2なら中間2件を返す' do
343 c = GroundColor.mylist(@author, 2, 2)
344 c.should eq [@gc3, @gc2]
346 it 'page=3なら先頭1件を返す' do
347 c = GroundColor.mylist(@author, 3, 2)
353 describe '他作家の色地一覧取得に於いて' do
355 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
356 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
357 @other_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id
360 r = GroundColor.himlist @other_author
361 r.should eq [@other_gc]
364 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
365 new_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
366 r = GroundColor.himlist @other_author
367 r.should eq [new_gc, @other_gc]
370 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
371 hidden_gc = FactoryGirl.create :ground_color, :panel_id => hidden_panel.id
372 r = GroundColor.himlist @other_author
373 r.should eq [@other_gc]
375 context 'DBに5件あって1ページの件数を2件に変えたとして' do
377 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
378 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
379 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
380 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
383 pl = GroundColor.himlist @other_author, 1, 2
384 pl.should have(2).items
386 it 'page=1なら末尾2件を返す' do
388 pl = GroundColor.himlist @other_author, 1, 2
389 pl.should eq [@other_gc5, @other_gc4]
391 it 'page=2なら中間2件を返す' do
392 pl = GroundColor.himlist @other_author, 2, 2
393 pl.should eq [@other_gc3, @other_gc2]
395 it 'page=3なら先頭1件を返す' do
396 pl = GroundColor.himlist @other_author, 3, 2
397 pl.should eq [@other_gc]
402 describe '色地一覧ページ制御に於いて' do
404 GroundColor.stub(:count).with(any_args).and_return(100)
407 r = GroundColor.list_paginate
408 r.is_a?(Kaminari::PaginatableArray).should be_true
410 it '色地一覧の取得条件を利用している' do
411 GroundColor.stub(:list_where).with(any_args).and_return('')
412 GroundColor.should_receive(:list_where).with(any_args).exactly(1)
413 r = GroundColor.list_paginate
415 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
416 r = GroundColor.list_paginate 3, 10
417 r.limit_value.should eq 10
418 r.offset_value.should eq 20
422 describe '自分の色地一覧ページ制御に於いて' do
424 GroundColor.stub(:count).with(any_args).and_return(100)
427 r = GroundColor.mylist_paginate @author
428 r.is_a?(Kaminari::PaginatableArray).should be_true
430 it '自分の色地一覧の取得条件を利用している' do
431 GroundColor.stub(:mylist_where).with(any_args).and_return('')
432 GroundColor.should_receive(:mylist_where).with(any_args).exactly(1)
433 r = GroundColor.mylist_paginate @author
435 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
436 r = GroundColor.mylist_paginate @author, 3, 10
437 r.limit_value.should eq 10
438 r.offset_value.should eq 20
442 describe '他作家の色地一覧ページ制御に於いて' do
444 GroundColor.stub(:count).with(any_args).and_return(100)
447 r = GroundColor.himlist_paginate @other_author
448 r.is_a?(Kaminari::PaginatableArray).should be_true
450 it '他作家の色地一覧の取得条件を利用している' do
451 GroundColor.stub(:himlist_where).with(any_args).and_return('')
452 GroundColor.should_receive(:himlist_where).with(any_args).exactly(1)
453 r = GroundColor.himlist_paginate @other_author
455 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
456 r = GroundColor.himlist_paginate @other_author, 3, 10
457 r.limit_value.should eq 10
458 r.offset_value.should eq 20
462 describe '一覧取得オプションに於いて' do
464 r = GroundColor.list_opt
465 r.should have(1).items
468 r = GroundColor.list_opt
469 r.has_key?(:panel).should be_true
472 r = GroundColor.list_opt
473 r[:panel].has_key?(:author).should be_true
476 describe 'json一覧出力オプションに於いて' do
478 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
479 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
480 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
481 @sbt = FactoryGirl.create :speech_balloon_template
482 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
483 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
484 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
485 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
488 r = GroundColor.list.to_json GroundColor.list_json_opt
491 i.has_key?('panel').should be_true
494 r = GroundColor.list.to_json GroundColor.list_json_opt
498 s.has_key?('author').should be_true
502 describe '単体取得に於いて' do
504 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
506 context 'つつがなく終わるとき' do
507 it '単体取得オプションを利用している' do
508 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
509 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
510 r = GroundColor.show @gc.id, @author
512 it '閲覧許可を問い合わせている' do
513 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
514 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
515 r = GroundColor.show @gc.id, @author
519 GroundColor.any_instance.stub(:visible?).and_return(true)
520 pl = GroundColor.show @gc.id, @author
523 context '閲覧許可が出なかったとき' do
524 it '403Forbidden例外を返す' do
525 GroundColor.any_instance.stub(:visible?).and_return(false)
527 GroundColor.show @gc.id, @author
528 }.should raise_error(ActiveRecord::Forbidden)
531 context '存在しない色地を開こうとしたとき' do
532 it '404RecordNotFound例外を返す' do
534 GroundColor.show 110, @author
535 }.should raise_error(ActiveRecord::RecordNotFound)
539 describe '単体取得オプションに於いて' do
540 it 'includeキーを含んでいる' do
541 r = GroundColor.show_opt
542 r.has_key?(:include).should be_true
545 r = GroundColor.show_opt[:include]
546 r.should have(1).items
549 r = GroundColor.show_opt[:include]
550 r.has_key?(:panel).should be_true
553 r = GroundColor.show_opt[:include]
554 r[:panel].has_key?(:author).should be_true
557 describe 'json単体出力オプションに於いて' do
559 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
562 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
565 i.has_key?('panel').should be_true
568 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
572 s.has_key?('author').should be_true