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.should be_valid
23 @author.should be_valid
27 context 'nameを検証するとき' do
30 @author.should_not be_valid
34 @author.should_not be_valid
37 context 'user_idを検証するとき' do
40 @author.should_not be_valid
44 @author.should_not be_valid
46 it '存在するアカウントでなければ失敗する' do
48 @author.should_not be_valid
53 describe '文字コード検証に於いて' do
57 context 'nameを検証するとき' do
58 it 'Shift JISなら失敗する' do
59 @author.name = "\x83G\x83r\x83]\x83D"
62 }.should raise_error(Pettanr::BadRequest)
68 describe 'デフォルト値補充に於いて' do
69 it '名前がno nameになっている' do
70 @author = FactoryGirl.build :author, :name => nil
71 @author.supply_default
72 @author.name.should eq 'no name'
76 describe '上書き補充に於いて' do
79 describe '所持判定に於いて' do
81 @other_user = FactoryGirl.create :user_yas
82 @other_author = @other_user.author
85 it '自身にロールリストからの作家取得を依頼している' do
86 Author.should_receive(:get_author_from_roles).with(any_args).exactly(1)
87 r = @author.own?([@author])
90 context 'ロール内作家が取得できるとき' do
93 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
94 Author.stub(:get_author_from_roles).with(any_args).and_return(@author)
95 r = @author.own?([@author])
98 it 'ロール内作家のidが自身の作家idと一致しないならno' do
99 Author.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
100 @author.own?(@other_author).should be_false
103 context 'ロール内作家が取得できないとき' do
105 Author.stub(:get_author_from_roles).with(any_args).and_return(nil)
108 r = @author.own?([@author])
114 describe '閲覧許可に於いて' do
117 context 'オープンモードのとき' do
119 MagicNumber['run_mode'] = 0
121 it '自身にゲスト用ロールチェックを問い合わせしている' do
122 Author.any_instance.stub(:guest_role_check).and_return(true)
123 Author.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
124 r = @author.visible?([@author])
126 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
127 Author.any_instance.stub(:guest_role_check).and_return(false)
128 r = @author.visible?([@author])
132 context 'クローズドモードのとき' do
134 MagicNumber['run_mode'] = 1
136 it '自身に読者用ロールチェックを問い合わせしている' do
137 Author.any_instance.stub(:reader_role_check).and_return(true)
138 Author.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
139 r = @author.visible?([@author])
141 it '読者用ロールチェックが失敗したとき、falseを返す' do
142 Author.any_instance.stub(:reader_role_check).and_return(false)
143 r = @author.visible?([@author])
147 context '事前チェックする' do
149 MagicNumber['run_mode'] = 1
150 Author.any_instance.stub(:reader_role_check).and_return(true)
153 context 'つつがなく終わるとき' do
155 MagicNumber['run_mode'] = 1
156 Author.any_instance.stub(:reader_role_check).and_return(true)
159 r = @author.visible?([@author])
165 describe '絵師作家判定に於いて' do
168 context 'Trueのケース' do
170 artist = FactoryGirl.create :artist, :author_id => @author.id
171 @author.artist?.should eq true
174 context 'Falseのケース' do
176 @author.artist?.should eq false
181 describe '一覧取得に於いて' do
184 context 'page補正について' do
185 it '文字列から数値に変換される' do
186 Author.page('8').should eq 8
189 Author.page().should eq 1
192 Author.page('0').should eq 1
195 context 'page_size補正について' do
196 it '文字列から数値に変換される' do
197 Author.page_size('7').should eq 7
199 it 'nilの場合はAuthor.default_page_sizeになる' do
200 Author.page_size().should eq Author.default_page_size
202 it '0以下の場合はAuthor.default_page_sizeになる' do
203 Author.page_size('0').should eq Author.default_page_size
205 it 'Author.max_page_sizeを超えた場合はAuthor.max_page_sizeになる' do
206 Author.page_size('1000').should eq Author.max_page_size
209 context 'つつがなく終わるとき' do
210 it '一覧取得オプションを利用している' do
211 Author.stub(:list_opt).with(any_args).and_return({})
212 Author.should_receive(:list_opt).with(any_args).exactly(1)
218 r.should eq [@author]
221 @other_user = FactoryGirl.create :user_yas
222 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
223 n = @other_user.author
224 n.created_at = Time.now + 100
227 l.should eq [n, @author]
229 context 'DBに5件あって1ページの件数を2件に変えたとして' do
231 @other_user2 = FactoryGirl.create :user_yas
232 @author2 = FactoryGirl.create :author, :user_id => @other_user2.id
233 @author2.created_at = Time.now + 100
235 @other_user3 = FactoryGirl.create :user_yas
236 @author3 = FactoryGirl.create :author, :user_id => @other_user3.id
237 @author3.created_at = Time.now + 200
239 @other_user4 = FactoryGirl.create :user_yas
240 @author4 = FactoryGirl.create :author, :user_id => @other_user4.id
241 @author4.created_at = Time.now + 300
243 @other_user5 = FactoryGirl.create :user_yas
244 @author5 = FactoryGirl.create :author, :user_id => @other_user5.id
245 @author5.created_at = Time.now + 400
247 Author.stub(:default_page_size).and_return(2)
251 r.should have(2).items
253 it 'page=1なら末尾2件を返す' do
256 r.should eq [@author5, @author4]
258 it 'page=2なら中間2件を返す' do
260 r.should eq [@author3, @author2]
262 it 'page=3なら先頭1件を返す' do
264 r.should eq [@author]
267 context 'DBに5件あって1ページの件数を0件に変えたとして' do
269 @other_user2 = FactoryGirl.create :user_yas
270 @author2 = FactoryGirl.create :author, :user_id => @other_user2.id
271 @author2.created_at = Time.now + 100
273 @other_user3 = FactoryGirl.create :user_yas
274 @author3 = FactoryGirl.create :author, :user_id => @other_user3.id
275 @author3.created_at = Time.now + 200
277 @other_user4 = FactoryGirl.create :user_yas
278 @author4 = FactoryGirl.create :author, :user_id => @other_user4.id
279 @author4.created_at = Time.now + 300
281 @other_user5 = FactoryGirl.create :user_yas
282 @author5 = FactoryGirl.create :author, :user_id => @other_user5.id
283 @author5.created_at = Time.now + 400
285 Author.stub(:default_page_size).and_return(2)
289 r.should have(5).items
293 describe '一覧取得オプションに於いて' do
294 it 'includeキーを含んでいる' do
296 r.has_key?(:include).should be_true
299 r = Author.list_opt[:include]
300 r.should have(1).items
303 r = Author.list_opt[:include]
304 r.has_key?(:artist).should be_true
307 describe 'json一覧出力オプションに於いて' do
309 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
312 r = Author.list.to_json Author.list_json_opt
315 i.has_key?('artist').should be_true
319 describe '単体取得に於いて' do
322 context 'つつがなく終わるとき' do
323 it '単体取得オプションを利用している' do
324 Author.stub(:show_opt).with(any_args).and_return({})
325 Author.should_receive(:show_opt).with(any_args).exactly(1)
326 r = Author.show @author.id, @author
328 it '閲覧許可を問い合わせている' do
329 Author.any_instance.stub(:visible?).with(any_args).and_return(true)
330 Author.any_instance.should_receive(:visible?).with(any_args).exactly(1)
331 r = Author.show @author.id, @author
335 r = Author.show @author.id, @author
338 context '閲覧許可が出なかったとき' do
339 it '403Forbidden例外を返す' do
340 Author.any_instance.stub(:visible?).and_return(false)
342 Author.show @author.id, @author
343 }.should raise_error(ActiveRecord::Forbidden)
346 context '存在しない作家を開こうとしたとき' do
347 it '404RecordNotFound例外を返す' do
349 Author.show 110, @author
350 }.should raise_error(ActiveRecord::RecordNotFound)
354 describe '編集取得に於いて' do
357 context 'つつがなく終わるとき' do
358 it '単体取得オプションを利用している' do
359 Author.stub(:show_opt).with(any_args).and_return({})
360 Author.should_receive(:show_opt).with(any_args).exactly(1)
361 r = Author.edit @author.id, @author
363 it '所持判定を問い合わせている' do
364 Author.any_instance.stub(:own?).with(any_args).and_return(true)
365 Author.any_instance.should_receive(:own?).with(any_args).exactly(1)
366 r = Author.edit @author.id, @author
370 Author.any_instance.stub(:own?).and_return(true)
371 r = Author.edit @author.id, @author.id
374 context '他人の作家を開こうとしたとき' do
375 it '403Forbidden例外を返す' do
376 Author.any_instance.stub(:own?).and_return(false)
378 Author.edit @author.id, @author
379 }.should raise_error(ActiveRecord::Forbidden)
382 context '存在しない作家を開こうとしたとき' do
383 it '404RecordNotFound例外を返す' do
385 Author.edit 110, @author
386 }.should raise_error(ActiveRecord::RecordNotFound)
390 describe '単体取得オプションに於いて' do
391 it 'includeキーを含んでいる' do
393 r.has_key?(:include).should be_true
396 r = Author.show_opt[:include]
397 r.should have(1).items
400 r = Author.show_opt[:include]
401 r.has_key?(:artist).should be_true
404 describe 'json単体出力オプションに於いて' do
406 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
409 r = Author.show(@author.id, @author).to_json Author.show_json_opt
412 i.has_key?('artist').should be_true
416 describe 'マイリストページ制御パラメータに於いて' do
419 context 'コミックpage_size補正について' do
420 it '文字列から数値に変換される' do
421 Author.comic_page_size('7').should eq 7
423 it 'nilの場合はAuthor.default_comic_page_sizeになる' do
424 Author.comic_page_size().should eq Author.default_comic_page_size
426 it '0以下の場合はAuthor.default_comic_page_sizeになる' do
427 Author.comic_page_size('0').should eq Author.default_comic_page_size
429 it 'Author.comic_max_page_sizeを超えた場合はAuthor.comic_max_page_sizeになる' do
430 Author.comic_page_size('1000').should eq Author.comic_max_page_size
433 context 'ストーリーpage_size補正について' do
434 it '文字列から数値に変換される' do
435 Author.story_page_size('7').should eq 7
437 it 'nilの場合はAuthor.default_story_page_sizeになる' do
438 Author.story_page_size().should eq Author.default_story_page_size
440 it '0以下の場合はAuthor.default_story_page_sizeになる' do
441 Author.story_page_size('0').should eq Author.default_story_page_size
443 it 'Author.story_max_page_sizeを超えた場合はAuthor.story_max_page_sizeになる' do
444 Author.story_page_size('1000').should eq Author.story_max_page_size
447 context 'コマ絵page_size補正について' do
448 it '文字列から数値に変換される' do
449 Author.panel_page_size('7').should eq 7
451 it 'nilの場合はAuthor.default_panel_page_sizeになる' do
452 Author.panel_page_size().should eq Author.default_panel_page_size
454 it '0以下の場合はAuthor.default_panel_page_sizeになる' do
455 Author.panel_page_size('0').should eq Author.default_panel_page_size
457 it 'Author.panel_max_page_sizeを超えた場合はAuthor.panel_max_page_sizeになる' do
458 Author.panel_page_size('1000').should eq Author.panel_max_page_size
461 context '景色素材page_size補正について' do
462 it '文字列から数値に変換される' do
463 Author.panel_picture_page_size('7').should eq 7
465 it 'nilの場合はAuthor.default_panel_picture_page_sizeになる' do
466 Author.panel_picture_page_size().should eq Author.default_panel_picture_page_size
468 it '0以下の場合はAuthor.default_panel_picture_page_sizeになる' do
469 Author.panel_picture_page_size('0').should eq Author.default_panel_picture_page_size
471 it 'Author.panel_picture_max_page_sizeを超えた場合はAuthor.panel_picture_max_page_sizeになる' do
472 Author.panel_picture_page_size('1000').should eq Author.panel_picture_max_page_size
475 context '景色カラーpage_size補正について' do
476 it '文字列から数値に変換される' do
477 Author.ground_picture_page_size('7').should eq 7
479 it 'nilの場合はAuthor.default_ground_picture_page_sizeになる' do
480 Author.ground_picture_page_size().should eq Author.default_ground_picture_page_size
482 it '0以下の場合はAuthor.default_ground_picture_page_sizeになる' do
483 Author.ground_picture_page_size('0').should eq Author.default_ground_picture_page_size
485 it 'Author.ground_picture_max_page_sizeを超えた場合はAuthor.ground_picture_max_page_sizeになる' do
486 Author.ground_picture_page_size('1000').should eq Author.ground_picture_max_page_size
489 context '景色カラーコードpage_size補正について' do
490 it '文字列から数値に変換される' do
491 Author.ground_color_page_size('7').should eq 7
493 it 'nilの場合はAuthor.default_ground_color_page_sizeになる' do
494 Author.ground_color_page_size().should eq Author.default_ground_color_page_size
496 it '0以下の場合はAuthor.default_ground_color_page_sizeになる' do
497 Author.ground_color_page_size('0').should eq Author.default_ground_color_page_size
499 it 'Author.ground_color_max_page_sizeを超えた場合はAuthor.ground_color_max_page_sizeになる' do
500 Author.ground_color_page_size('1000').should eq Author.ground_color_max_page_size
503 context '素材page_size補正について' do
504 it '文字列から数値に変換される' do
505 Author.resource_picture_page_size('7').should eq 7
507 it 'nilの場合はAuthor.default_resource_picture_page_sizeになる' do
508 Author.resource_picture_page_size().should eq Author.default_resource_picture_page_size
510 it '0以下の場合はAuthor.default_resource_picture_page_sizeになる' do
511 Author.resource_picture_page_size('0').should eq Author.default_resource_picture_page_size
513 it 'Author.resource_picture_max_page_sizeを超えた場合はAuthor.resource_picture_max_page_sizeになる' do
514 Author.resource_picture_page_size('1000').should eq Author.resource_picture_max_page_size