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
21 @color = FactoryGirl.create :color
26 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id, :color_id => @color.id
29 context 'オーソドックスなデータのとき' do
40 context 'panel_idを検証するとき' do
41 #ネストの保存はnilを許可しなければならないので数値チェックだけ
44 @gc.should_not be_valid
47 context 'color_idを検証するとき' do
50 @gc.should_not be_valid
54 @gc.should_not be_valid
56 it '存在する色でなければ失敗する' do
58 @gc.should_not be_valid
64 @gc.should_not be_valid
68 @gc.should_not be_valid
72 @gc.should_not be_valid
76 @gc.should_not be_valid
81 describe 'デフォルト値補充に於いて' do
83 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id, :color_id => @color.id
88 describe '上書き補充に於いて' do
90 @gc = FactoryGirl.build :ground_color, :panel_id => @panel.id, :color_id => @color.id
95 describe '閲覧許可に於いて' do
97 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
99 context 'オープンモードのとき' do
101 MagicNumber['run_mode'] = 0
103 it '自身にゲスト用ロールチェックを問い合わせしている' do
104 GroundColor.any_instance.stub(:guest_role_check).and_return(true)
105 GroundColor.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
106 r = @gc.visible?([@author])
108 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
109 GroundColor.any_instance.stub(:guest_role_check).and_return(false)
110 r = @gc.visible?([@author])
114 context 'クローズドモードのとき' do
116 MagicNumber['run_mode'] = 1
118 it '自身に読者用ロールチェックを問い合わせしている' do
119 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
120 GroundColor.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
121 r = @gc.visible?([@author])
123 it '読者用ロールチェックが失敗したとき、falseを返す' do
124 GroundColor.any_instance.stub(:reader_role_check).and_return(false)
125 r = @gc.visible?([@author])
129 context '事前チェックする' do
131 MagicNumber['run_mode'] = 1
132 GroundColor.any_instance.stub(:reader_role_check).and_return(true)
134 it '自身のコマに所持判定を問い合わせしている' do
135 Panel.any_instance.stub(:own?).and_return(true)
136 Panel.any_instance.should_receive(:own?).with(any_args).exactly(1)
137 r = @gc.visible?([@author])
139 it '自身のコマに閲覧許可を問い合わせしている' do
140 Panel.any_instance.stub(:own?).and_return(false)
141 Panel.any_instance.stub(:visible?).and_return(true)
142 Panel.any_instance.should_receive(:visible?).with(any_args).exactly(1)
143 r = @gc.visible?([@author])
146 context 'つつがなく終わるとき' do
148 MagicNumber['run_mode'] = 1
149 Panel.any_instance.stub(:reader_role_check).and_return(true)
151 it '自分のコマの選択色地なら許可する' do
152 Panel.any_instance.stub(:own?).and_return(true)
153 Panel.any_instance.stub(:visible?).and_return(false)
154 r = @gc.visible?([@author])
157 it '他人の非公開コマの選択色地なら許可しない' do
158 Panel.any_instance.stub(:own?).and_return(false)
159 Panel.any_instance.stub(:visible?).and_return(false)
160 r = @gc.visible?([@author])
163 it '他人のコマの選択色地でも公開なら許可する' do
164 Panel.any_instance.stub(:own?).and_return(false)
165 Panel.any_instance.stub(:visible?).and_return(true)
166 r = @gc.visible?([@author])
172 describe '一覧取得に於いて' do
174 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
176 context 'page補正について' do
177 it '文字列から数値に変換される' do
178 GroundColor.page('8').should eq 8
181 GroundColor.page().should eq 1
184 GroundColor.page('0').should eq 1
187 context 'page_size補正について' do
188 it '文字列から数値に変換される' do
189 GroundColor.page_size('7').should eq 7
191 it 'nilの場合はGroundColor.default_page_sizeになる' do
192 GroundColor.page_size().should eq GroundColor.default_page_size
194 it '0以下の場合はGroundColor.default_page_sizeになる' do
195 GroundColor.page_size('0').should eq GroundColor.default_page_size
197 it 'GroundColor.max_page_sizeを超えた場合はGroundColor.max_page_sizeになる' do
198 GroundColor.page_size('1000').should eq GroundColor.max_page_size
201 context 'つつがなく終わるとき' do
202 it '一覧取得オプションを利用している' do
203 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
204 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
209 pl = GroundColor.list
213 #公開コマなら(他人のコマであっても)含んでいる
214 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
215 npl = FactoryGirl.create :ground_color, :panel_id => opl.id, :color_id => @color.id, :updated_at => Time.now + 100
216 pl = GroundColor.list
217 pl.should eq [npl, @gc]
219 it '非公開のコマの選択色地は含まない' do
220 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
221 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :updated_at => Time.now + 100
222 pl = GroundColor.list
225 context 'DBに5件あって1ページの件数を2件に変えたとして' do
227 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
228 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
229 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
230 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
231 GroundColor.stub(:default_page_size).and_return(2)
234 pl = GroundColor.list
235 pl.should have(2).items
237 it 'page=1なら末尾2件を返す' do
239 pl = GroundColor.list(1)
240 pl.should eq [@gc5, @gc4]
242 it 'page=2なら中間2件を返す' do
243 pl = GroundColor.list(2)
244 pl.should eq [@gc3, @gc2]
246 it 'page=3なら先頭1件を返す' do
247 pl = GroundColor.list(3)
251 context 'DBに5件あって1ページの件数を0件に変えたとして' do
253 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
254 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
255 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
256 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
257 GroundColor.stub(:default_page_size).and_return(2)
260 r = GroundColor.list 5, 0
261 r.should have(5).items
266 describe '自分のコマで使った選択色地一覧取得に於いて' do
268 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
270 context 'つつがなく終わるとき' do
271 it '一覧取得オプションを利用している' do
272 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
273 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
274 r = GroundColor.mylist @author
278 pl = GroundColor.mylist @author
282 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
283 pl = GroundColor.mylist @author
284 pl.should eq [npl, @gc]
286 it '他人のコマの選択色地は公開でも含まない' do
287 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
288 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id
289 pl = GroundColor.mylist @author
292 it '自分のコマの選択色地は非公開でも含んでいる' do
293 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
294 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
295 pl = GroundColor.mylist @author
296 pl.should eq [npl, @gc]
298 context 'DBに5件あって1ページの件数を2件に変えたとして' do
300 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
301 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
302 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
303 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
306 c = GroundColor.mylist @author, 1, 2
307 c.should have(2).items
309 it 'page=1なら末尾2件を返す' do
311 c = GroundColor.mylist(@author, 1, 2)
312 c.should eq [@gc5, @gc4]
314 it 'page=2なら中間2件を返す' do
315 c = GroundColor.mylist(@author, 2, 2)
316 c.should eq [@gc3, @gc2]
318 it 'page=3なら先頭1件を返す' do
319 c = GroundColor.mylist(@author, 3, 2)
323 context 'DBに5件あって1ページの件数を0件に変えたとして' do
325 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
326 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
327 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
328 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
329 Author.stub(:default_ground_color_page_size).and_return(2)
332 r = GroundColor.mylist @author, 5, 0
333 r.should have(5).items
338 describe '他作家の選択色地一覧取得に於いて' do
340 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
341 @other_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
342 @other_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id
345 r = GroundColor.himlist @other_author
346 r.should eq [@other_gc]
349 new_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :updated_at => Time.now + 100
350 new_gc = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 100
351 r = GroundColor.himlist @other_author
352 r.should eq [new_gc, @other_gc]
355 hidden_panel = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 0
356 hidden_gc = FactoryGirl.create :ground_color, :panel_id => hidden_panel.id, :color_id => @color.id
357 r = GroundColor.himlist @other_author
358 r.should eq [@other_gc]
360 context 'DBに5件あって1ページの件数を2件に変えたとして' do
362 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 100
363 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 200
364 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 300
365 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 400
368 pl = GroundColor.himlist @other_author, 1, 2
369 pl.should have(2).items
371 it 'page=1なら末尾2件を返す' do
373 pl = GroundColor.himlist @other_author, 1, 2
374 pl.should eq [@other_gc5, @other_gc4]
376 it 'page=2なら中間2件を返す' do
377 pl = GroundColor.himlist @other_author, 2, 2
378 pl.should eq [@other_gc3, @other_gc2]
380 it 'page=3なら先頭1件を返す' do
381 pl = GroundColor.himlist @other_author, 3, 2
382 pl.should eq [@other_gc]
385 context 'DBに5件あって1ページの件数を0件に変えたとして' do
387 @other_gc2 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 100
388 @other_gc3 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 200
389 @other_gc4 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 300
390 @other_gc5 = FactoryGirl.create :ground_color, :panel_id => @other_panel.id, :color_id => @color.id, :updated_at => Time.now + 400
391 Author.stub(:default_ground_color_page_size).and_return(2)
394 r = GroundColor.himlist @other_author, 5, 0
395 r.should have(5).items
400 describe '一覧取得オプションに於いて' do
401 it 'includeキーを含んでいる' do
402 r = GroundColor.list_opt
403 r.has_key?(:include).should be_true
406 r = GroundColor.list_opt[:include]
407 r.should have(2).items
410 r = GroundColor.list_opt[:include]
411 r.has_key?(:panel).should be_true
414 r = GroundColor.list_opt[:include]
415 r[:panel].has_key?(:author).should be_true
418 r = GroundColor.list_opt[:include]
419 r.has_key?(:color).should be_true
422 describe 'json一覧出力オプションに於いて' do
424 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
425 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
426 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
427 @sbt = FactoryGirl.create :speech_balloon_template
428 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
429 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
430 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
431 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
434 r = GroundColor.list.to_json GroundColor.list_json_opt
437 i.has_key?('panel').should be_true
440 r = GroundColor.list.to_json GroundColor.list_json_opt
444 s.has_key?('author').should be_true
447 r = GroundColor.list.to_json GroundColor.list_json_opt
450 i.has_key?('color').should be_true
454 describe '単体取得に於いて' do
456 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
458 context 'つつがなく終わるとき' do
459 it '単体取得オプションを利用している' do
460 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
461 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
462 r = GroundColor.show @gc.id, @author
464 it '閲覧許可を問い合わせている' do
465 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
466 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
467 r = GroundColor.show @gc.id, @author
471 GroundColor.any_instance.stub(:visible?).and_return(true)
472 pl = GroundColor.show @gc.id, @author
475 context '閲覧許可が出なかったとき' do
476 it '403Forbidden例外を返す' do
477 GroundColor.any_instance.stub(:visible?).and_return(false)
479 GroundColor.show @gc.id, @author
480 }.should raise_error(ActiveRecord::Forbidden)
483 context '存在しない選択色地を開こうとしたとき' do
484 it '404RecordNotFound例外を返す' do
486 GroundColor.show 110, @author
487 }.should raise_error(ActiveRecord::RecordNotFound)
491 describe '単体取得オプションに於いて' do
492 it 'includeキーを含んでいる' do
493 r = GroundColor.show_opt
494 r.has_key?(:include).should be_true
497 r = GroundColor.show_opt[:include]
498 r.should have(2).items
501 r = GroundColor.show_opt[:include]
502 r.has_key?(:panel).should be_true
505 r = GroundColor.show_opt[:include]
506 r[:panel].has_key?(:author).should be_true
509 r = GroundColor.show_opt[:include]
510 r.has_key?(:color).should be_true
513 describe 'json単体出力オプションに於いて' do
515 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
518 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
521 i.has_key?('panel').should be_true
524 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
528 s.has_key?('author').should be_true
531 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
534 i.has_key?('color').should be_true