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
54 it '名前がno nameになっている' do
55 @author = FactoryGirl.build :author, :name => nil
56 @author.supply_default
57 @author.name.should eq 'no name'
61 describe '上書き補充に於いて' do
64 describe '所持判定に於いて' do
66 @other_user = FactoryGirl.create :user_yas
67 @other_author = @other_user.author
70 it '自身にロールリストからの作家取得を依頼している' do
71 Author.should_receive(:get_author_from_roles).with(any_args).exactly(1)
72 r = @author.own?([@author])
75 context 'ロール内作家が取得できるとき' do
78 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
79 Author.stub(:get_author_from_roles).with(any_args).and_return(@author)
80 r = @author.own?([@author])
83 it 'ロール内作家のidが自身の作家idと一致しないならno' do
84 Author.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
85 @author.own?(@other_author).should be_false
88 context 'ロール内作家が取得できないとき' do
90 Author.stub(:get_author_from_roles).with(any_args).and_return(nil)
93 r = @author.own?([@author])
99 describe '閲覧許可に於いて' do
102 context 'オープンモードのとき' do
104 MagicNumber['run_mode'] = 0
106 it '自身にゲスト用ロールチェックを問い合わせしている' do
107 Author.any_instance.stub(:guest_role_check).and_return(true)
108 Author.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
109 r = @author.visible?([@author])
111 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
112 Author.any_instance.stub(:guest_role_check).and_return(false)
113 r = @author.visible?([@author])
117 context 'クローズドモードのとき' do
119 MagicNumber['run_mode'] = 1
121 it '自身に読者用ロールチェックを問い合わせしている' do
122 Author.any_instance.stub(:reader_role_check).and_return(true)
123 Author.any_instance.should_receive(:reader_role_check).with(any_args).exactly(1)
124 r = @author.visible?([@author])
126 it '読者用ロールチェックが失敗したとき、falseを返す' do
127 Author.any_instance.stub(:reader_role_check).and_return(false)
128 r = @author.visible?([@author])
132 context '事前チェックする' do
134 MagicNumber['run_mode'] = 1
135 Author.any_instance.stub(:reader_role_check).and_return(true)
138 context 'つつがなく終わるとき' do
140 MagicNumber['run_mode'] = 1
141 Author.any_instance.stub(:reader_role_check).and_return(true)
144 r = @author.visible?([@author])
150 describe '絵師作家判定に於いて' do
153 context 'Trueのケース' do
155 artist = FactoryGirl.create :artist, :author_id => @author.id
156 @author.artist?.should eq true
159 context 'Falseのケース' do
161 @author.artist?.should eq false
166 describe '一覧取得に於いて' do
169 context 'page補正について' do
170 it '文字列から数値に変換される' do
171 Author.page('8').should eq 8
174 Author.page().should eq 1
177 Author.page('0').should eq 1
180 context 'page_size補正について' do
181 it '文字列から数値に変換される' do
182 Author.page_size('7').should eq 7
184 it 'nilの場合はAuthor.default_page_sizeになる' do
185 Author.page_size().should eq Author.default_page_size
187 it '0以下の場合はAuthor.default_page_sizeになる' do
188 Author.page_size('0').should eq Author.default_page_size
190 it 'Author.max_page_sizeを超えた場合はAuthor.max_page_sizeになる' do
191 Author.page_size('1000').should eq Author.max_page_size
194 context 'つつがなく終わるとき' do
195 it '一覧取得オプションを利用している' do
196 Author.stub(:list_opt).with(any_args).and_return({})
197 Author.should_receive(:list_opt).with(any_args).exactly(1)
203 r.should eq [@author]
206 @other_user = FactoryGirl.create :user_yas
207 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
208 n = @other_user.author
209 n.created_at = Time.now + 100
212 l.should eq [n, @author]
214 context 'DBに5件あって1ページの件数を2件に変えたとして' do
216 @other_user2 = FactoryGirl.create :user_yas
217 @author2 = FactoryGirl.create :author, :user_id => @other_user2.id
218 @author2.created_at = Time.now + 100
220 @other_user3 = FactoryGirl.create :user_yas
221 @author3 = FactoryGirl.create :author, :user_id => @other_user3.id
222 @author3.created_at = Time.now + 200
224 @other_user4 = FactoryGirl.create :user_yas
225 @author4 = FactoryGirl.create :author, :user_id => @other_user4.id
226 @author4.created_at = Time.now + 300
228 @other_user5 = FactoryGirl.create :user_yas
229 @author5 = FactoryGirl.create :author, :user_id => @other_user5.id
230 @author5.created_at = Time.now + 400
232 Author.stub(:default_page_size).and_return(2)
236 r.should have(2).items
238 it 'page=1なら末尾2件を返す' do
241 r.should eq [@author5, @author4]
243 it 'page=2なら中間2件を返す' do
245 r.should eq [@author3, @author2]
247 it 'page=3なら先頭1件を返す' do
249 r.should eq [@author]
252 context 'DBに5件あって1ページの件数を0件に変えたとして' do
254 @other_user2 = FactoryGirl.create :user_yas
255 @author2 = FactoryGirl.create :author, :user_id => @other_user2.id
256 @author2.created_at = Time.now + 100
258 @other_user3 = FactoryGirl.create :user_yas
259 @author3 = FactoryGirl.create :author, :user_id => @other_user3.id
260 @author3.created_at = Time.now + 200
262 @other_user4 = FactoryGirl.create :user_yas
263 @author4 = FactoryGirl.create :author, :user_id => @other_user4.id
264 @author4.created_at = Time.now + 300
266 @other_user5 = FactoryGirl.create :user_yas
267 @author5 = FactoryGirl.create :author, :user_id => @other_user5.id
268 @author5.created_at = Time.now + 400
270 Author.stub(:default_page_size).and_return(2)
274 r.should have(5).items
278 describe '一覧取得オプションに於いて' do
279 it 'includeキーを含んでいる' do
281 r.has_key?(:include).should be_true
284 r = Author.list_opt[:include]
285 r.should have(1).items
288 r = Author.list_opt[:include]
289 r.has_key?(:artist).should be_true
292 describe 'json一覧出力オプションに於いて' do
294 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
297 r = Author.list.to_json Author.list_json_opt
300 i.has_key?('artist').should be_true
304 describe '単体取得に於いて' do
307 context 'つつがなく終わるとき' do
308 it '単体取得オプションを利用している' do
309 Author.stub(:show_opt).with(any_args).and_return({})
310 Author.should_receive(:show_opt).with(any_args).exactly(1)
311 r = Author.show @author.id, @author
313 it '閲覧許可を問い合わせている' do
314 Author.any_instance.stub(:visible?).with(any_args).and_return(true)
315 Author.any_instance.should_receive(:visible?).with(any_args).exactly(1)
316 r = Author.show @author.id, @author
320 r = Author.show @author.id, @author
323 context '閲覧許可が出なかったとき' do
324 it '403Forbidden例外を返す' do
325 Author.any_instance.stub(:visible?).and_return(false)
327 Author.show @author.id, @author
328 }.should raise_error(ActiveRecord::Forbidden)
331 context '存在しない作家を開こうとしたとき' do
332 it '404RecordNotFound例外を返す' do
334 Author.show 110, @author
335 }.should raise_error(ActiveRecord::RecordNotFound)
339 describe '編集取得に於いて' do
342 context 'つつがなく終わるとき' do
343 it '単体取得オプションを利用している' do
344 Author.stub(:show_opt).with(any_args).and_return({})
345 Author.should_receive(:show_opt).with(any_args).exactly(1)
346 r = Author.edit @author.id, @author
348 it '所持判定を問い合わせている' do
349 Author.any_instance.stub(:own?).with(any_args).and_return(true)
350 Author.any_instance.should_receive(:own?).with(any_args).exactly(1)
351 r = Author.edit @author.id, @author
355 Author.any_instance.stub(:own?).and_return(true)
356 r = Author.edit @author.id, @author.id
359 context '他人の作家を開こうとしたとき' do
360 it '403Forbidden例外を返す' do
361 Author.any_instance.stub(:own?).and_return(false)
363 Author.edit @author.id, @author
364 }.should raise_error(ActiveRecord::Forbidden)
367 context '存在しない作家を開こうとしたとき' do
368 it '404RecordNotFound例外を返す' do
370 Author.edit 110, @author
371 }.should raise_error(ActiveRecord::RecordNotFound)
375 describe '単体取得オプションに於いて' do
376 it 'includeキーを含んでいる' do
378 r.has_key?(:include).should be_true
381 r = Author.show_opt[:include]
382 r.should have(1).items
385 r = Author.show_opt[:include]
386 r.has_key?(:artist).should be_true
389 describe 'json単体出力オプションに於いて' do
391 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
394 r = Author.show(@author.id, @author).to_json Author.show_json_opt
397 i.has_key?('artist').should be_true
401 describe 'マイリストページ制御パラメータに於いて' do
404 context 'コミックpage_size補正について' do
405 it '文字列から数値に変換される' do
406 Author.comic_page_size('7').should eq 7
408 it 'nilの場合はAuthor.default_comic_page_sizeになる' do
409 Author.comic_page_size().should eq Author.default_comic_page_size
411 it '0以下の場合はAuthor.default_comic_page_sizeになる' do
412 Author.comic_page_size('0').should eq Author.default_comic_page_size
414 it 'Author.comic_max_page_sizeを超えた場合はAuthor.comic_max_page_sizeになる' do
415 Author.comic_page_size('1000').should eq Author.comic_max_page_size
418 context 'ストーリーpage_size補正について' do
419 it '文字列から数値に変換される' do
420 Author.story_page_size('7').should eq 7
422 it 'nilの場合はAuthor.default_story_page_sizeになる' do
423 Author.story_page_size().should eq Author.default_story_page_size
425 it '0以下の場合はAuthor.default_story_page_sizeになる' do
426 Author.story_page_size('0').should eq Author.default_story_page_size
428 it 'Author.story_max_page_sizeを超えた場合はAuthor.story_max_page_sizeになる' do
429 Author.story_page_size('1000').should eq Author.story_max_page_size
432 context 'コマ絵page_size補正について' do
433 it '文字列から数値に変換される' do
434 Author.panel_page_size('7').should eq 7
436 it 'nilの場合はAuthor.default_panel_page_sizeになる' do
437 Author.panel_page_size().should eq Author.default_panel_page_size
439 it '0以下の場合はAuthor.default_panel_page_sizeになる' do
440 Author.panel_page_size('0').should eq Author.default_panel_page_size
442 it 'Author.panel_max_page_sizeを超えた場合はAuthor.panel_max_page_sizeになる' do
443 Author.panel_page_size('1000').should eq Author.panel_max_page_size
446 context '景色素材page_size補正について' do
447 it '文字列から数値に変換される' do
448 Author.panel_picture_page_size('7').should eq 7
450 it 'nilの場合はAuthor.default_panel_picture_page_sizeになる' do
451 Author.panel_picture_page_size().should eq Author.default_panel_picture_page_size
453 it '0以下の場合はAuthor.default_panel_picture_page_sizeになる' do
454 Author.panel_picture_page_size('0').should eq Author.default_panel_picture_page_size
456 it 'Author.panel_picture_max_page_sizeを超えた場合はAuthor.panel_picture_max_page_sizeになる' do
457 Author.panel_picture_page_size('1000').should eq Author.panel_picture_max_page_size
460 context '景色カラーpage_size補正について' do
461 it '文字列から数値に変換される' do
462 Author.ground_picture_page_size('7').should eq 7
464 it 'nilの場合はAuthor.default_ground_picture_page_sizeになる' do
465 Author.ground_picture_page_size().should eq Author.default_ground_picture_page_size
467 it '0以下の場合はAuthor.default_ground_picture_page_sizeになる' do
468 Author.ground_picture_page_size('0').should eq Author.default_ground_picture_page_size
470 it 'Author.ground_picture_max_page_sizeを超えた場合はAuthor.ground_picture_max_page_sizeになる' do
471 Author.ground_picture_page_size('1000').should eq Author.ground_picture_max_page_size
474 context '景色カラーコードpage_size補正について' do
475 it '文字列から数値に変換される' do
476 Author.ground_color_page_size('7').should eq 7
478 it 'nilの場合はAuthor.default_ground_color_page_sizeになる' do
479 Author.ground_color_page_size().should eq Author.default_ground_color_page_size
481 it '0以下の場合はAuthor.default_ground_color_page_sizeになる' do
482 Author.ground_color_page_size('0').should eq Author.default_ground_color_page_size
484 it 'Author.ground_color_max_page_sizeを超えた場合はAuthor.ground_color_max_page_sizeになる' do
485 Author.ground_color_page_size('1000').should eq Author.ground_color_max_page_size
488 context '素材page_size補正について' do
489 it '文字列から数値に変換される' do
490 Author.resource_picture_page_size('7').should eq 7
492 it 'nilの場合はAuthor.default_resource_picture_page_sizeになる' do
493 Author.resource_picture_page_size().should eq Author.default_resource_picture_page_size
495 it '0以下の場合はAuthor.default_resource_picture_page_sizeになる' do
496 Author.resource_picture_page_size('0').should eq Author.default_resource_picture_page_size
498 it 'Author.resource_picture_max_page_sizeを超えた場合はAuthor.resource_picture_max_page_sizeになる' do
499 Author.resource_picture_page_size('1000').should eq Author.resource_picture_max_page_size