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 '検査対象がnil(ゲスト)のとき' do
100 context 'クローズドモードのとき' do
102 MagicNumber['run_mode'] = 1
105 r = @gc.visible?(nil)
109 context 'オープンモードのとき' do
111 MagicNumber['run_mode'] = 0
113 it '公開されたコマの選択色地なら許可する' do
114 Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
115 r = @gc.visible?(nil)
119 Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
120 r = @gc.visible?(nil)
125 context '検査対象が作家のとき' do
126 it '公開されたコマの選択色地なら許可する' do
127 Panel.any_instance.stub(:publish?).with(any_args).and_return(true)
128 r = @gc.visible?(@author)
132 Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
133 r = @gc.visible?(@author)
137 context '検査対象が管理者のとき' do
139 Panel.any_instance.stub(:publish?).with(any_args).and_return(false)
140 r = @gc.visible?(@admin)
144 context '検査対象がそれ以外のとき' do
152 describe '一覧取得に於いて' do
154 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
156 context 'page補正について' do
157 it '文字列から数値に変換される' do
158 GroundColor.page('8').should eq 8
161 GroundColor.page().should eq 1
164 GroundColor.page('0').should eq 1
167 context 'page_size補正について' do
168 it '文字列から数値に変換される' do
169 GroundColor.page_size('7').should eq 7
171 it 'nilの場合はGroundColor.default_page_sizeになる' do
172 GroundColor.page_size().should eq GroundColor.default_page_size
174 it '0以下の場合はGroundColor.default_page_sizeになる' do
175 GroundColor.page_size('0').should eq GroundColor.default_page_size
177 it 'GroundColor.max_page_sizeを超えた場合はGroundColor.max_page_sizeになる' do
178 GroundColor.page_size('1000').should eq GroundColor.max_page_size
181 context 'つつがなく終わるとき' do
182 it '一覧取得オプションを利用している' do
183 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
184 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
189 pl = GroundColor.list
193 #公開コマなら(他人のコマであっても)含んでいる
194 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
195 npl = FactoryGirl.create :ground_color, :panel_id => opl.id, :color_id => @color.id, :updated_at => Time.now + 100
196 pl = GroundColor.list
197 pl.should eq [npl, @gc]
199 it '非公開のコマの選択色地は含まない' do
200 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
201 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :updated_at => Time.now + 100
202 pl = GroundColor.list
205 context 'DBに5件あって1ページの件数を2件に変えたとして' do
207 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
208 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
209 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
210 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
211 GroundColor.stub(:default_page_size).and_return(2)
214 pl = GroundColor.list
215 pl.should have(2).items
217 it 'page=1なら末尾2件を返す' do
219 pl = GroundColor.list(1)
220 pl.should eq [@gc5, @gc4]
222 it 'page=2なら中間2件を返す' do
223 pl = GroundColor.list(2)
224 pl.should eq [@gc3, @gc2]
226 it 'page=3なら先頭1件を返す' do
227 pl = GroundColor.list(3)
231 context 'DBに5件あって1ページの件数を0件に変えたとして' do
233 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
234 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
235 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
236 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
237 GroundColor.stub(:default_page_size).and_return(2)
240 r = GroundColor.list 5, 0
241 r.should have(5).items
246 describe '一覧取得オプションに於いて' do
247 it 'includeキーを含んでいる' do
248 r = GroundColor.list_opt
249 r.has_key?(:include).should be_true
252 r = GroundColor.list_opt[:include]
253 r.should have(2).items
256 r = GroundColor.list_opt[:include]
257 r.has_key?(:panel).should be_true
260 r = GroundColor.list_opt[:include]
261 r[:panel].has_key?(:author).should be_true
264 r = GroundColor.list_opt[:include]
265 r.has_key?(:color).should be_true
268 describe 'json一覧出力オプションに於いて' do
270 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
271 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
272 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
273 @sbt = FactoryGirl.create :speech_balloon_template
274 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
275 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
276 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
277 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
280 r = GroundColor.list.to_json GroundColor.list_json_opt
283 i.has_key?('panel').should be_true
286 r = GroundColor.list.to_json GroundColor.list_json_opt
290 s.has_key?('author').should be_true
293 r = GroundColor.list.to_json GroundColor.list_json_opt
296 i.has_key?('color').should be_true
300 describe '自分のコマで使った選択色地一覧取得に於いて' do
302 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
304 context 'つつがなく終わるとき' do
305 it '一覧取得オプションを利用している' do
306 GroundColor.stub(:list_opt).with(any_args).and_return({:include => :panel})
307 GroundColor.should_receive(:list_opt).with(any_args).exactly(1)
308 r = GroundColor.mylist @author
312 pl = GroundColor.mylist @author
316 npl = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
317 pl = GroundColor.mylist @author
318 pl.should eq [npl, @gc]
320 it '他人のコマの選択色地は公開でも含まない' do
321 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
322 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id
323 pl = GroundColor.mylist @author
326 it '自分のコマの選択色地は非公開でも含んでいる' do
327 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
328 npl = FactoryGirl.create :ground_color, :panel_id => hpl.id, :color_id => @color.id, :z => 2, :updated_at => Time.now + 100
329 pl = GroundColor.mylist @author
330 pl.should eq [npl, @gc]
332 context 'DBに5件あって1ページの件数を2件に変えたとして' do
334 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
335 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
336 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
337 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
340 c = GroundColor.mylist @author, 1, 2
341 c.should have(2).items
343 it 'page=1なら末尾2件を返す' do
345 c = GroundColor.mylist(@author, 1, 2)
346 c.should eq [@gc5, @gc4]
348 it 'page=2なら中間2件を返す' do
349 c = GroundColor.mylist(@author, 2, 2)
350 c.should eq [@gc3, @gc2]
352 it 'page=3なら先頭1件を返す' do
353 c = GroundColor.mylist(@author, 3, 2)
357 context 'DBに5件あって1ページの件数を0件に変えたとして' do
359 @gc2 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 1, :color_id => @color.id, :updated_at => Time.now + 100
360 @gc3 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 2, :color_id => @color.id, :updated_at => Time.now + 200
361 @gc4 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 3, :color_id => @color.id, :updated_at => Time.now + 300
362 @gc5 = FactoryGirl.create :ground_color, :panel_id => @panel.id, :z => 4, :color_id => @color.id, :updated_at => Time.now + 400
363 Author.stub(:default_ground_color_page_size).and_return(2)
366 r = GroundColor.mylist @author, 5, 0
367 r.should have(5).items
372 describe '単体取得に於いて' do
374 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
376 context 'つつがなく終わるとき' do
377 it '単体取得オプションを利用している' do
378 GroundColor.stub(:show_opt).with(any_args).and_return({:include => :panel})
379 GroundColor.should_receive(:show_opt).with(any_args).exactly(1)
380 r = GroundColor.show @gc.id, @author
382 it '閲覧許可を問い合わせている' do
383 GroundColor.any_instance.stub(:visible?).with(any_args).and_return(true)
384 GroundColor.any_instance.should_receive(:visible?).with(any_args).exactly(1)
385 r = GroundColor.show @gc.id, @author
389 GroundColor.any_instance.stub(:visible?).and_return(true)
390 pl = GroundColor.show @gc.id, @author
393 context '閲覧許可が出なかったとき' do
394 it '403Forbidden例外を返す' do
395 GroundColor.any_instance.stub(:visible?).and_return(false)
397 GroundColor.show @gc.id, @author
398 }.should raise_error(ActiveRecord::Forbidden)
401 context '存在しない選択色地を開こうとしたとき' do
402 it '404RecordNotFound例外を返す' do
404 GroundColor.show 110, @author
405 }.should raise_error(ActiveRecord::RecordNotFound)
409 describe '単体取得オプションに於いて' do
410 it 'includeキーを含んでいる' do
411 r = GroundColor.show_opt
412 r.has_key?(:include).should be_true
415 r = GroundColor.show_opt[:include]
416 r.should have(2).items
419 r = GroundColor.show_opt[:include]
420 r.has_key?(:panel).should be_true
423 r = GroundColor.show_opt[:include]
424 r[:panel].has_key?(:author).should be_true
427 r = GroundColor.show_opt[:include]
428 r.has_key?(:color).should be_true
431 describe 'json単体出力オプションに於いて' do
433 @gc = FactoryGirl.create :ground_color, :panel_id => @panel.id, :color_id => @color.id
436 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
439 i.has_key?('panel').should be_true
442 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
446 s.has_key?('author').should be_true
449 r = GroundColor.show(@gc.id, @author).to_json GroundColor.show_json_opt
452 i.has_key?('color').should be_true