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
97 describe '上書き補充に於いて' do
99 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id
104 describe '閲覧許可に於いて' do
106 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
108 context 'オープンモードのとき' do
110 MagicNumber['run_mode'] = 0
112 it '自身にゲスト用ロールチェックを問い合わせしている' do
113 GroundColor.any_instance.stub(:guest_role_check).and_return(true)
114 GroundColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
115 r = @gc.visible?([@author])
117 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
118 GroundColor.any_instance.stub(:guest_role_check).and_return(false)
119 r = @gc.visible?([@author])
123 context 'クローズドモードのとき' do
125 MagicNumber['run_mode'] = 1
127 it '自身に読者用ロールチェックを問い合わせしている' do
128 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
129 GroundColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
130 r = @gc.visible?([@author])
132 it '読者用ロールチェックが失敗したとき、falseを返す' do
133 GroundColor.any_instance.stub(:reader_role_check).and_return(false)
134 r = @gc.visible?([@author])
138 context '事前チェックする' do
140 MagicNumber['run_mode'] = 1
141 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
143 it '自身のコマに所持判定を問い合わせしている' do
144 Panel.any_instance.stub(:own?).and_return(true)
145 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
146 r = @gc.visible?([@author])
148 it '自身のコマに閲覧許可を問い合わせしている' do
149 Panel.any_instance.stub(:own?).and_return(false)
150 Panel.any_instance.stub(:visible?).and_return(true)
151 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
152 r = @gc.visible?([@author])
155 context 'つつがなく終わるとき' do
157 MagicNumber['run_mode'] = 1
158 Panel.any_instance.stub(:reader_role_check).and_return(true)
160 it '自分のコマの色地なら許可する' do
161 Panel.any_instance.stub(:own?).and_return(true)
162 Panel.any_instance.stub(:visible?).and_return(false)
163 r = @gc.visible?([@author])
166 it '他人の非公開コマの色地なら許可しない' do
167 Panel.any_instance.stub(:own?).and_return(false)
168 Panel.any_instance.stub(:visible?).and_return(false)
169 r = @gc.visible?([@author])
172 it '他人のコマの色地でも公開なら許可する' do
173 Panel.any_instance.stub(:own?).and_return(false)
174 Panel.any_instance.stub(:visible?).and_return(true)
175 r = @gc.visible?([@author])
181 describe '一覧取得に於いて' do
183 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
185 context 'page補正について' do
186 it '文字列から数値に変換される' do
187 GroundColor.page('8').should eq 8
190 GroundColor.page().should eq 1
193 GroundColor.page('0').should eq 1
196 context 'page_size補正について' do
197 it '文字列から数値に変換される' do
198 GroundColor.page_size('7').should eq 7
200 it 'nilの場合はGroundColor.default_page_sizeになる' do
201 GroundColor.page_size().should eq GroundColor.default_page_size
203 it '0以下の場合はGroundColor.default_page_sizeになる' do
204 GroundColor.page_size('0').should eq GroundColor.default_page_size
206 it 'GroundColor.max_page_sizeを超えた場合はGroundColor.max_page_sizeになる' do
207 GroundColor.page_size('1000').should eq GroundColor.max_page_size
210 context 'つつがなく終わるとき' do
211 it '一覧取得オプションを利用している' do
212 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
213 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
218 pl = GroundColor.list
222 #公開コマなら(他人のコマであっても)含んでいる
223 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
224 npl = FactoryGirl.create :ground_color, :panel_id => opl.id, :updated_at => Time.now + 100
225 pl = GroundColor.list
226 pl.should eq [npl, @gc]
228 it '非公開のコマの色地は含まない' do
229 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
230 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :updated_at => Time.now + 100
231 pl = GroundColor.list
234 context 'DBに5件あって1ページの件数を2件に変えたとして' do
236 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
237 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
238 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
239 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
240 GroundColor.stub(:default_page_size).and_return(2)
243 pl = GroundColor.list
244 pl.should have(2).items
246 it 'page=1なら末尾2件を返す' do
248 pl = GroundColor.list(1)
249 pl.should eq [@gc5, @gc4]
251 it 'page=2なら中間2件を返す' do
252 pl = GroundColor.list(2)
253 pl.should eq [@gc3, @gc2]
255 it 'page=3なら先頭1件を返す' do
256 pl = GroundColor.list(3)
262 describe '自分のコマで使った色地一覧取得に於いて' do
264 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
266 context 'つつがなく終わるとき' do
267 it '一覧取得オプションを利用している' do
268 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
269 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
270 r = GroundColor.mylist @author
274 pl = GroundColor.mylist @author
278 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 100
279 pl = GroundColor.mylist @author
280 pl.should eq [npl, @gc]
282 it '他人のコマの色地は公開でも含まない' do
283 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
284 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id
285 pl = GroundColor.mylist @author
288 it '自分のコマの色地は非公開でも含んでいる' do
289 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
290 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :z => 2, :updated_at => Time.now + 100
291 pl = GroundColor.mylist @author
292 pl.should eq [npl, @gc]
294 context 'DBに5件あって1ページの件数を2件に変えたとして' do
296 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
297 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
298 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
299 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
302 c = GroundColor.mylist @author, 1, 2
303 c.should have(2).items
305 it 'page=1なら末尾2件を返す' do
307 c = GroundColor.mylist(@author, 1, 2)
308 c.should eq [@gc5, @gc4]
310 it 'page=2なら中間2件を返す' do
311 c = GroundColor.mylist(@author, 2, 2)
312 c.should eq [@gc3, @gc2]
314 it 'page=3なら先頭1件を返す' do
315 c = GroundColor.mylist(@author, 3, 2)
321 describe '他作家の色地一覧取得に於いて' do
323 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
324 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
325 @other_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id
328 r = GroundColor.himlist @other_author
329 r.should eq [@other_gc]
332 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
333 new_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
334 r = GroundColor.himlist @other_author
335 r.should eq [new_gc, @other_gc]
338 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
339 hidden_gc = FactoryGirl.create :ground_color, :panel_id => hidden_panel.id
340 r = GroundColor.himlist @other_author
341 r.should eq [@other_gc]
343 context 'DBに5件あって1ページの件数を2件に変えたとして' do
345 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
346 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
347 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
348 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
351 pl = GroundColor.himlist @other_author, 1, 2
352 pl.should have(2).items
354 it 'page=1なら末尾2件を返す' do
356 pl = GroundColor.himlist @other_author, 1, 2
357 pl.should eq [@other_gc5, @other_gc4]
359 it 'page=2なら中間2件を返す' do
360 pl = GroundColor.himlist @other_author, 2, 2
361 pl.should eq [@other_gc3, @other_gc2]
363 it 'page=3なら先頭1件を返す' do
364 pl = GroundColor.himlist @other_author, 3, 2
365 pl.should eq [@other_gc]
370 describe '色地一覧ページ制御に於いて' do
372 GroundColor.stub(:count).with(any_args).and_return(100)
375 r = GroundColor.list_paginate
376 r.is_a?(Kaminari::PaginatableArray).should be_true
378 it '色地一覧の取得条件を利用している' do
379 GroundColor.stub(:list_where).with(any_args).and_return('')
380 GroundColor.should_receive(:list_where).with(any_args).exactly(1)
381 r = GroundColor.list_paginate
383 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
384 r = GroundColor.list_paginate 3, 10
385 r.limit_value.should eq 10
386 r.offset_value.should eq 20
390 describe '自分の色地一覧ページ制御に於いて' do
392 GroundColor.stub(:count).with(any_args).and_return(100)
395 r = GroundColor.mylist_paginate @author
396 r.is_a?(Kaminari::PaginatableArray).should be_true
398 it '自分の色地一覧の取得条件を利用している' do
399 GroundColor.stub(:mylist_where).with(any_args).and_return('')
400 GroundColor.should_receive(:mylist_where).with(any_args).exactly(1)
401 r = GroundColor.mylist_paginate @author
403 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
404 r = GroundColor.mylist_paginate @author, 3, 10
405 r.limit_value.should eq 10
406 r.offset_value.should eq 20
410 describe '他作家の色地一覧ページ制御に於いて' do
412 GroundColor.stub(:count).with(any_args).and_return(100)
415 r = GroundColor.himlist_paginate @other_author
416 r.is_a?(Kaminari::PaginatableArray).should be_true
418 it '他作家の色地一覧の取得条件を利用している' do
419 GroundColor.stub(:himlist_where).with(any_args).and_return('')
420 GroundColor.should_receive(:himlist_where).with(any_args).exactly(1)
421 r = GroundColor.himlist_paginate @other_author
423 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
424 r = GroundColor.himlist_paginate @other_author, 3, 10
425 r.limit_value.should eq 10
426 r.offset_value.should eq 20
430 describe '一覧取得オプションに於いて' do
432 r = GroundColor.list_opt
433 r.should have(1).items
436 r = GroundColor.list_opt
437 r.has_key?(:panel).should be_true
440 r = GroundColor.list_opt
441 r[:panel].has_key?(:author).should be_true
444 describe 'json一覧出力オプションに於いて' do
446 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
447 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
448 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
449 @sbt = FactoryGirl.create :speech_balloon_template
450 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
451 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
452 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
453 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
456 r = GroundColor.list.to_json GroundColor.list_json_opt
459 i.has_key?('panel').should be_true
462 r = GroundColor.list.to_json GroundColor.list_json_opt
466 s.has_key?('author').should be_true
470 describe '単体取得に於いて' do
472 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
474 context 'つつがなく終わるとき' do
475 it '単体取得オプションを利用している' do
476 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
477 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
478 r = GroundColor.show @gc.id, @author
480 it '閲覧許可を問い合わせている' do
481 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
482 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
483 r = GroundColor.show @gc.id, @author
487 GroundColor.any_instance.stub(:visible?).and_return(true)
488 pl = GroundColor.show @gc.id, @author
491 context '閲覧許可が出なかったとき' do
492 it '403Forbidden例外を返す' do
493 GroundColor.any_instance.stub(:visible?).and_return(false)
495 GroundColor.show @gc.id, @author
496 }.should raise_error(ActiveRecord::Forbidden)
499 context '存在しない色地を開こうとしたとき' do
500 it '404RecordNotFound例外を返す' do
502 GroundColor.show 110, @author
503 }.should raise_error(ActiveRecord::RecordNotFound)
507 describe '単体取得オプションに於いて' do
508 it 'includeキーを含んでいる' do
509 r = GroundColor.show_opt
510 r.has_key?(:include).should be_true
513 r = GroundColor.show_opt[:include]
514 r.should have(1).items
517 r = GroundColor.show_opt[:include]
518 r.has_key?(:panel).should be_true
521 r = GroundColor.show_opt[:include]
522 r[:panel].has_key?(:author).should be_true
525 describe 'json単体出力オプションに於いて' do
527 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
530 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
533 i.has_key?('panel').should be_true
536 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
540 s.has_key?('author').should be_true