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)
260 context 'DBに5件あって1ページの件数を0件に変えたとして' do
262 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
263 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
264 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
265 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
266 GroundColor.stub(:default_page_size).and_return(2)
269 r = GroundColor.list 5, 0
270 r.should have(5).items
275 describe '自分のコマで使った色地一覧取得に於いて' do
277 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
279 context 'つつがなく終わるとき' do
280 it '一覧取得オプションを利用している' do
281 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
282 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
283 r = GroundColor.mylist @author
287 pl = GroundColor.mylist @author
291 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 100
292 pl = GroundColor.mylist @author
293 pl.should eq [npl, @gc]
295 it '他人のコマの色地は公開でも含まない' do
296 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
297 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id
298 pl = GroundColor.mylist @author
301 it '自分のコマの色地は非公開でも含んでいる' do
302 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
303 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :z => 2, :updated_at => Time.now + 100
304 pl = GroundColor.mylist @author
305 pl.should eq [npl, @gc]
307 context 'DBに5件あって1ページの件数を2件に変えたとして' do
309 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
310 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
311 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
312 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
315 c = GroundColor.mylist @author, 1, 2
316 c.should have(2).items
318 it 'page=1なら末尾2件を返す' do
320 c = GroundColor.mylist(@author, 1, 2)
321 c.should eq [@gc5, @gc4]
323 it 'page=2なら中間2件を返す' do
324 c = GroundColor.mylist(@author, 2, 2)
325 c.should eq [@gc3, @gc2]
327 it 'page=3なら先頭1件を返す' do
328 c = GroundColor.mylist(@author, 3, 2)
332 context 'DBに5件あって1ページの件数を0件に変えたとして' do
334 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :updated_at => Time.now + 100
335 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :updated_at => Time.now + 200
336 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :updated_at => Time.now + 300
337 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :updated_at => Time.now + 400
338 Author.stub(:default_ground_color_page_size).and_return(2)
341 r = GroundColor.mylist @author, 5, 0
342 r.should have(5).items
347 describe '他作家の色地一覧取得に於いて' do
349 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
350 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
351 @other_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id
354 r = GroundColor.himlist @other_author
355 r.should eq [@other_gc]
358 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
359 new_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
360 r = GroundColor.himlist @other_author
361 r.should eq [new_gc, @other_gc]
364 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
365 hidden_gc = FactoryGirl.create :ground_color, :panel_id => hidden_panel.id
366 r = GroundColor.himlist @other_author
367 r.should eq [@other_gc]
369 context 'DBに5件あって1ページの件数を2件に変えたとして' do
371 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
372 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
373 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
374 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
377 pl = GroundColor.himlist @other_author, 1, 2
378 pl.should have(2).items
380 it 'page=1なら末尾2件を返す' do
382 pl = GroundColor.himlist @other_author, 1, 2
383 pl.should eq [@other_gc5, @other_gc4]
385 it 'page=2なら中間2件を返す' do
386 pl = GroundColor.himlist @other_author, 2, 2
387 pl.should eq [@other_gc3, @other_gc2]
389 it 'page=3なら先頭1件を返す' do
390 pl = GroundColor.himlist @other_author, 3, 2
391 pl.should eq [@other_gc]
394 context 'DBに5件あって1ページの件数を0件に変えたとして' do
396 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 100
397 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 200
398 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 300
399 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :updated_at => Time.now + 400
400 Author.stub(:default_ground_color_page_size).and_return(2)
403 r = GroundColor.himlist @other_author, 5, 0
404 r.should have(5).items
409 describe '一覧取得オプションに於いて' do
410 it 'includeキーを含んでいる' do
411 r = GroundColor.list_opt
412 r.has_key?(:include).should be_true
415 r = GroundColor.list_opt[:include]
416 r.should have(1).items
419 r = GroundColor.list_opt[:include]
420 r.has_key?(:panel).should be_true
423 r = GroundColor.list_opt[:include]
424 r[:panel].has_key?(:author).should be_true
427 describe 'json一覧出力オプションに於いて' do
429 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
430 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
431 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
432 @sbt = FactoryGirl.create :speech_balloon_template
433 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
434 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
435 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
436 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
439 r = GroundColor.list.to_json GroundColor.list_json_opt
442 i.has_key?('panel').should be_true
445 r = GroundColor.list.to_json GroundColor.list_json_opt
449 s.has_key?('author').should be_true
453 describe '単体取得に於いて' do
455 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
457 context 'つつがなく終わるとき' do
458 it '単体取得オプションを利用している' do
459 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
460 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
461 r = GroundColor.show @gc.id, @author
463 it '閲覧許可を問い合わせている' do
464 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
465 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
466 r = GroundColor.show @gc.id, @author
470 GroundColor.any_instance.stub(:visible?).and_return(true)
471 pl = GroundColor.show @gc.id, @author
474 context '閲覧許可が出なかったとき' do
475 it '403Forbidden例外を返す' do
476 GroundColor.any_instance.stub(:visible?).and_return(false)
478 GroundColor.show @gc.id, @author
479 }.should raise_error(ActiveRecord::Forbidden)
482 context '存在しない色地を開こうとしたとき' do
483 it '404RecordNotFound例外を返す' do
485 GroundColor.show 110, @author
486 }.should raise_error(ActiveRecord::RecordNotFound)
490 describe '単体取得オプションに於いて' do
491 it 'includeキーを含んでいる' do
492 r = GroundColor.show_opt
493 r.has_key?(:include).should be_true
496 r = GroundColor.show_opt[:include]
497 r.should have(1).items
500 r = GroundColor.show_opt[:include]
501 r.has_key?(:panel).should be_true
504 r = GroundColor.show_opt[:include]
505 r[:panel].has_key?(:author).should be_true
508 describe 'json単体出力オプションに於いて' do
510 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id
513 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
516 i.has_key?('panel').should be_true
519 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
523 s.has_key?('author').should be_true