1 # -*- encoding: utf-8 -*-
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
16 context 'オーソドックスなデータのとき' do
19 @author.working_panel_id = 0
20 @author.should be_valid
24 @author.should be_valid
28 context 'nameを検証するとき' do
31 @author.should_not be_valid
35 @author.should_not be_valid
38 context 'working_panel_idを検証するとき' do
40 @author.working_panel_id = 'a'
41 @author.should_not be_valid
44 context 'user_idを検証するとき' do
47 @author.should_not be_valid
51 @author.should_not be_valid
53 it '存在するアカウントでなければ失敗する' do
55 @author.should_not be_valid
60 describe '文字コード検証に於いて' do
64 context 'nameを検証するとき' do
65 it 'Shift JISなら失敗する' do
66 @author.name = "\x83G\x83r\x83]\x83D"
69 }.should raise_error(Pettanr::BadRequest)
75 describe 'デフォルト値補充に於いて' do
76 it '名前がno nameになっている' do
77 @author = FactoryGirl.build :author, :name => nil
78 @author.supply_default
79 @author.name.should eq 'no name'
83 describe '上書き補充に於いて' do
86 describe '所持判定に於いて' do
88 @other_user = FactoryGirl.create :user_yas
89 @other_author = @other_user.author
92 it '自身にロールリストからの作家取得を依頼している' do
93 Author.should_receive(:get_author_from_roles).with(any_args).exactly(1)
94 r = @author.own?([@author])
97 context 'ロール内作家が取得できるとき' do
100 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
101 Author.stub(:get_author_from_roles).with(any_args).and_return(@author)
102 r = @author.own?([@author])
105 it 'ロール内作家のidが自身の作家idと一致しないならno' do
106 Author.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
107 @author.own?(@other_author).should be_false
110 context 'ロール内作家が取得できないとき' do
112 Author.stub(:get_author_from_roles).with(any_args).and_return(nil)
115 r = @author.own?([@author])
121 describe '閲覧許可に於いて' do
124 context 'オープンモードのとき' do
126 MagicNumber['run_mode'] = 0
128 it '自身にゲスト用ロールチェックを問い合わせしている' do
129 Author.any_instance.stub(:guest_role_check).and_return(true)
130 Author.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
131 r = @author.visible?([@author])
133 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
134 Author.any_instance.stub(:guest_role_check).and_return(false)
135 r = @author.visible?([@author])
139 context 'クローズドモードのとき' do
141 MagicNumber['run_mode'] = 1
143 it '自身に読者用ロールチェックを問い合わせしている' do
144 Author.any_instance.stub(:reader_role_check).and_return(true)
145 Author.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
146 r = @author.visible?([@author])
148 it '読者用ロールチェックが失敗したとき、falseを返す' do
149 Author.any_instance.stub(:reader_role_check).and_return(false)
150 r = @author.visible?([@author])
154 context '事前チェックする' do
156 MagicNumber['run_mode'] = 1
157 Author.any_instance.stub(:reader_role_check).and_return(true)
160 context 'つつがなく終わるとき' do
162 MagicNumber['run_mode'] = 1
163 Author.any_instance.stub(:reader_role_check).and_return(true)
166 r = @author.visible?([@author])
172 describe '絵師作家判定に於いて' do
175 context 'Trueのケース' do
177 artist = FactoryGirl.create :artist, :author_id => @author.id
178 @author.artist?.should eq true
181 context 'Falseのケース' do
183 @author.artist?.should eq false
188 describe '一覧取得に於いて' do
191 context 'page補正について' do
192 it '文字列から数値に変換される' do
193 Author.page('8').should eq 8
196 Author.page().should eq 1
199 Author.page('0').should eq 1
202 context 'page_size補正について' do
203 it '文字列から数値に変換される' do
204 Author.page_size('7').should eq 7
206 it 'nilの場合はAuthor.default_page_sizeになる' do
207 Author.page_size().should eq Author.default_page_size
209 it '0以下の場合はAuthor.default_page_sizeになる' do
210 Author.page_size('0').should eq Author.default_page_size
212 it 'Author.max_page_sizeを超えた場合はAuthor.max_page_sizeになる' do
213 Author.page_size('1000').should eq Author.max_page_size
216 context 'つつがなく終わるとき' do
217 it '一覧取得オプションを利用している' do
218 Author.stub(:list_opt).with(any_args).and_return({})
219 Author.should_receive(:list_opt).with(any_args).exactly(1)
225 r.should eq [@author]
228 @other_user = FactoryGirl.create :user_yas
229 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
230 n = @other_user.author
231 n.created_at = Time.now + 100
234 l.should eq [n, @author]
236 context 'DBに5件あって1ページの件数を2件に変えたとして' do
238 @other_user2 = FactoryGirl.create :user_yas
239 @author2 = FactoryGirl.create :author, :user_id => @other_user2.id
240 @author2.created_at = Time.now + 100
242 @other_user3 = FactoryGirl.create :user_yas
243 @author3 = FactoryGirl.create :author, :user_id => @other_user3.id
244 @author3.created_at = Time.now + 200
246 @other_user4 = FactoryGirl.create :user_yas
247 @author4 = FactoryGirl.create :author, :user_id => @other_user4.id
248 @author4.created_at = Time.now + 300
250 @other_user5 = FactoryGirl.create :user_yas
251 @author5 = FactoryGirl.create :author, :user_id => @other_user5.id
252 @author5.created_at = Time.now + 400
254 Author.stub(:default_page_size).and_return(2)
258 r.should have(2).items
260 it 'page=1なら末尾2件を返す' do
263 r.should eq [@author5, @author4]
265 it 'page=2なら中間2件を返す' do
267 r.should eq [@author3, @author2]
269 it 'page=3なら先頭1件を返す' do
271 r.should eq [@author]
276 describe '一覧ページ制御に於いて' do
278 Author.stub(:count).with(any_args).and_return(100)
281 r = Author.list_paginate
282 r.is_a?(Kaminari::PaginatableArray).should be_true
284 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
285 r = Author.list_paginate 3, 10
286 r.limit_value.should eq 10
287 r.offset_value.should eq 20
291 describe '一覧取得オプションに於いて' do
294 r.should have(1).items
298 r.has_key?(:artist).should be_true
301 describe 'json一覧出力オプションに於いて' do
303 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
306 r = Author.list.to_json Author.list_json_opt
309 i.has_key?('artist').should be_true
313 describe '単体取得に於いて' do
316 context 'つつがなく終わるとき' do
317 it '単体取得オプションを利用している' do
318 Author.stub(:show_opt).with(any_args).and_return({})
319 Author.should_receive(:show_opt).with(any_args).exactly(1)
320 r = Author.show @author.id, @author
322 it '閲覧許可を問い合わせている' do
323 Author.any_instance.stub(:visible?).with(any_args).and_return(true)
324 Author.any_instance.should_receive(:visible?).with(any_args).exactly(1)
325 r = Author.show @author.id, @author
329 r = Author.show @author.id, @author
332 context '閲覧許可が出なかったとき' do
333 it '403Forbidden例外を返す' do
334 Author.any_instance.stub(:visible?).and_return(false)
336 Author.show @author.id, @author
337 }.should raise_error(ActiveRecord::Forbidden)
340 context '存在しない作家を開こうとしたとき' do
341 it '404RecordNotFound例外を返す' do
343 Author.show 110, @author
344 }.should raise_error(ActiveRecord::RecordNotFound)
348 describe '編集取得に於いて' do
351 context 'つつがなく終わるとき' do
352 it '単体取得オプションを利用している' do
353 Author.stub(:show_opt).with(any_args).and_return({})
354 Author.should_receive(:show_opt).with(any_args).exactly(1)
355 r = Author.edit @author.id, @author
357 it '所持判定を問い合わせている' do
358 Author.any_instance.stub(:own?).with(any_args).and_return(true)
359 Author.any_instance.should_receive(:own?).with(any_args).exactly(1)
360 r = Author.edit @author.id, @author
364 Author.any_instance.stub(:own?).and_return(true)
365 r = Author.edit @author.id, @author.id
368 context '他人の作家を開こうとしたとき' do
369 it '403Forbidden例外を返す' do
370 Author.any_instance.stub(:own?).and_return(false)
372 Author.edit @author.id, @author
373 }.should raise_error(ActiveRecord::Forbidden)
376 context '存在しない作家を開こうとしたとき' do
377 it '404RecordNotFound例外を返す' do
379 Author.edit 110, @author
380 }.should raise_error(ActiveRecord::RecordNotFound)
384 describe '単体取得オプションに於いて' do
385 it 'includeキーを含んでいる' do
387 r.has_key?(:include).should be_true
390 r = Author.show_opt[:include]
391 r.should have(1).items
394 r = Author.show_opt[:include]
395 r.has_key?(:artist).should be_true
398 describe 'json単体出力オプションに於いて' do
400 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
403 r = Author.show(@author.id, @author).to_json Author.show_json_opt
406 i.has_key?('artist').should be_true
410 describe 'マイリストページ制御パラメータに於いて' do
413 context 'コミックpage_size補正について' do
414 it '文字列から数値に変換される' do
415 Author.comic_page_size('7').should eq 7
417 it 'nilの場合はAuthor.default_comic_page_sizeになる' do
418 Author.comic_page_size().should eq Author.default_comic_page_size
420 it '0以下の場合はAuthor.default_comic_page_sizeになる' do
421 Author.comic_page_size('0').should eq Author.default_comic_page_size
423 it 'Author.comic_max_page_sizeを超えた場合はAuthor.comic_max_page_sizeになる' do
424 Author.comic_page_size('1000').should eq Author.comic_max_page_size
427 context 'ストーリーpage_size補正について' do
428 it '文字列から数値に変換される' do
429 Author.story_page_size('7').should eq 7
431 it 'nilの場合はAuthor.default_story_page_sizeになる' do
432 Author.story_page_size().should eq Author.default_story_page_size
434 it '0以下の場合はAuthor.default_story_page_sizeになる' do
435 Author.story_page_size('0').should eq Author.default_story_page_size
437 it 'Author.story_max_page_sizeを超えた場合はAuthor.story_max_page_sizeになる' do
438 Author.story_page_size('1000').should eq Author.story_max_page_size
441 context 'コマ絵page_size補正について' do
442 it '文字列から数値に変換される' do
443 Author.panel_page_size('7').should eq 7
445 it 'nilの場合はAuthor.default_panel_page_sizeになる' do
446 Author.panel_page_size().should eq Author.default_panel_page_size
448 it '0以下の場合はAuthor.default_panel_page_sizeになる' do
449 Author.panel_page_size('0').should eq Author.default_panel_page_size
451 it 'Author.panel_max_page_sizeを超えた場合はAuthor.panel_max_page_sizeになる' do
452 Author.panel_page_size('1000').should eq Author.panel_max_page_size
455 context '景色素材page_size補正について' do
456 it '文字列から数値に変換される' do
457 Author.panel_picture_page_size('7').should eq 7
459 it 'nilの場合はAuthor.default_panel_picture_page_sizeになる' do
460 Author.panel_picture_page_size().should eq Author.default_panel_picture_page_size
462 it '0以下の場合はAuthor.default_panel_picture_page_sizeになる' do
463 Author.panel_picture_page_size('0').should eq Author.default_panel_picture_page_size
465 it 'Author.panel_picture_max_page_sizeを超えた場合はAuthor.panel_picture_max_page_sizeになる' do
466 Author.panel_picture_page_size('1000').should eq Author.panel_picture_max_page_size
469 context '景色カラーpage_size補正について' do
470 it '文字列から数値に変換される' do
471 Author.ground_picture_page_size('7').should eq 7
473 it 'nilの場合はAuthor.default_ground_picture_page_sizeになる' do
474 Author.ground_picture_page_size().should eq Author.default_ground_picture_page_size
476 it '0以下の場合はAuthor.default_ground_picture_page_sizeになる' do
477 Author.ground_picture_page_size('0').should eq Author.default_ground_picture_page_size
479 it 'Author.ground_picture_max_page_sizeを超えた場合はAuthor.ground_picture_max_page_sizeになる' do
480 Author.ground_picture_page_size('1000').should eq Author.ground_picture_max_page_size
483 context '景色カラーコードpage_size補正について' do
484 it '文字列から数値に変換される' do
485 Author.ground_color_page_size('7').should eq 7
487 it 'nilの場合はAuthor.default_ground_color_page_sizeになる' do
488 Author.ground_color_page_size().should eq Author.default_ground_color_page_size
490 it '0以下の場合はAuthor.default_ground_color_page_sizeになる' do
491 Author.ground_color_page_size('0').should eq Author.default_ground_color_page_size
493 it 'Author.ground_color_max_page_sizeを超えた場合はAuthor.ground_color_max_page_sizeになる' do
494 Author.ground_color_page_size('1000').should eq Author.ground_color_max_page_size
497 context '素材page_size補正について' do
498 it '文字列から数値に変換される' do
499 Author.resource_picture_page_size('7').should eq 7
501 it 'nilの場合はAuthor.default_resource_picture_page_sizeになる' do
502 Author.resource_picture_page_size().should eq Author.default_resource_picture_page_size
504 it '0以下の場合はAuthor.default_resource_picture_page_sizeになる' do
505 Author.resource_picture_page_size('0').should eq Author.default_resource_picture_page_size
507 it 'Author.resource_picture_max_page_sizeを超えた場合はAuthor.resource_picture_max_page_sizeになる' do
508 Author.resource_picture_page_size('1000').should eq Author.resource_picture_max_page_size