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
267 it 'includeキーを含んでいる' do
268 r = GroundColor.list_opt
269 r.has_key?(:include).should be_true
272 r = GroundColor.list_opt[:include]
273 r.should have(2).items
276 r = GroundColor.list_opt[:include]
277 r.has_key?(:panel).should be_true
280 r = GroundColor.list_opt[:include]
281 r[:panel].has_key?(:author).should be_true
284 r = GroundColor.list_opt[:include]
285 r.has_key?(:color).should be_true
288 describe 'json一覧出力オプションに於いて' do
290 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
291 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
292 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
293 @sbt = FactoryGirl.create :speech_balloon_template
294 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
295 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
296 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
297 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
300 r = GroundColor.list.to_json GroundColor.list_json_opt
303 i.has_key?('panel').should be_true
306 r = GroundColor.list.to_json GroundColor.list_json_opt
310 s.has_key?('author').should be_true
313 r = GroundColor.list.to_json GroundColor.list_json_opt
316 i.has_key?('color').should be_true
320 describe '自分のコマで使った選択色地一覧取得に於いて' do
322 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
324 context 'つつがなく終わるとき' do
325 it '一覧取得オプションを利用している' do
326 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
327 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
328 r = GroundColor.mylist @author
332 pl = GroundColor.mylist @author
336 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
337 pl = GroundColor.mylist @author
338 pl.should eq [npl, @gc]
340 it '他人のコマの選択色地は公開でも含まない' do
341 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
342 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id
343 pl = GroundColor.mylist @author
346 it '自分のコマの選択色地は非公開でも含んでいる' do
347 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
348 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
349 pl = GroundColor.mylist @author
350 pl.should eq [npl, @gc]
352 context 'DBに5件あって1ページの件数を2件に変えたとして' do
354 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
355 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
356 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
357 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
360 c = GroundColor.mylist @author, 1, 2
361 c.should have(2).items
363 it 'page=1なら末尾2件を返す' do
365 c = GroundColor.mylist(@author, 1, 2)
366 c.should eq [@gc5, @gc4]
368 it 'page=2なら中間2件を返す' do
369 c = GroundColor.mylist(@author, 2, 2)
370 c.should eq [@gc3, @gc2]
372 it 'page=3なら先頭1件を返す' do
373 c = GroundColor.mylist(@author, 3, 2)
377 context 'DBに5件あって1ページの件数を0件に変えたとして' do
379 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
380 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
381 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
382 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
383 Author.stub(:default_ground_color_page_size).and_return(2)
386 r = GroundColor.mylist @author, 5, 0
387 r.should have(5).items
392 describe '単体取得に於いて' do
394 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
396 context 'つつがなく終わるとき' do
397 it '単体取得オプションを利用している' do
398 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
399 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
400 r = GroundColor.show @gc.id, @author
402 it '閲覧許可を問い合わせている' do
403 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
404 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
405 r = GroundColor.show @gc.id, @author
409 GroundColor.any_instance.stub(:visible?).and_return(true)
410 pl = GroundColor.show @gc.id, @author
413 context '閲覧許可が出なかったとき' do
414 it '403Forbidden例外を返す' do
415 GroundColor.any_instance.stub(:visible?).and_return(false)
417 GroundColor.show @gc.id, @author
418 }.should raise_error(ActiveRecord::Forbidden)
421 context '存在しない選択色地を開こうとしたとき' do
422 it '404RecordNotFound例外を返す' do
424 GroundColor.show 110, @author
425 }.should raise_error(ActiveRecord::RecordNotFound)
429 describe '単体取得オプションに於いて' do
430 it 'includeキーを含んでいる' do
431 r = GroundColor.show_opt
432 r.has_key?(:include).should be_true
435 r = GroundColor.show_opt[:include]
436 r.should have(2).items
439 r = GroundColor.show_opt[:include]
440 r.has_key?(:panel).should be_true
443 r = GroundColor.show_opt[:include]
444 r[:panel].has_key?(:author).should be_true
447 r = GroundColor.show_opt[:include]
448 r.has_key?(:color).should be_true
451 describe 'json単体出力オプションに於いて' do
453 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
456 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
459 i.has_key?('panel').should be_true
462 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
466 s.has_key?('author').should be_true
469 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
472 i.has_key?('color').should be_true