1 # -*- encoding: utf-8 -*-
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
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 = FactoryGirl.create :author_yas, :user_id => @other_user.id
\r
70 @author.own?(@author).should == true
73 @author.own?(@other_author).should == false
75 it 'パラメータが作家でないならno' do
76 @author.own?(nil).should == false
80 describe '閲覧許可に於いて' do
83 context '検査対象がnil(ゲスト)のとき' do
84 context 'クローズドモードのとき' do
86 MagicNumber['run_mode'] = 1
89 r = @author.visible?(nil)
93 context 'オープンモードのとき' do
95 MagicNumber['run_mode'] = 0
98 r = @author.visible?(nil)
103 context '検査対象が作家のとき' do
105 r = @author.visible?(@author)
109 context '検査対象がそれ以外のとき' do
111 r = @author.visible?(@admin)
117 describe '絵師作家判定に於いて' do
120 context 'Trueのケース' do
122 artist = FactoryGirl.create :artist, :author_id => @author.id
123 @author.artist?.should eq true
126 context 'Falseのケース' do
128 @author.artist?.should eq false
133 describe '一覧取得に於いて' do
136 context 'page補正について' do
137 it '文字列から数値に変換される' do
138 Author.page('8').should eq 8
141 Author.page().should eq 1
144 Author.page('0').should eq 1
147 context 'page_size補正について' do
148 it '文字列から数値に変換される' do
149 Author.page_size('7').should eq 7
151 it 'nilの場合はAuthor.default_page_sizeになる' do
152 Author.page_size().should eq Author.default_page_size
154 it '0以下の場合はAuthor.default_page_sizeになる' do
155 Author.page_size('0').should eq Author.default_page_size
157 it 'Author.max_page_sizeを超えた場合はAuthor.max_page_sizeになる' do
158 Author.page_size('1000').should eq Author.max_page_size
161 context 'つつがなく終わるとき' do
\r
162 it '一覧取得オプションを利用している' do
\r
163 Author.stub(:list_opt).with(any_args).and_return({})
\r
164 Author.should_receive(:list_opt).with(any_args).exactly(1)
\r
170 r.should eq [@author]
173 @other_user = FactoryGirl.create :user_yas
175 n = @other_user.author
176 n.created_at = Time.now + 100
179 l.should eq [n, @author]
181 context 'DBに5件あって1ページの件数を2件に変えたとして' do
183 @other_user2 = FactoryGirl.create :user_yas
184 @author2 = @other_user2.author
185 @author2.created_at = Time.now + 100
187 @other_user3 = FactoryGirl.create :user_yas
188 @author3 = @other_user3.author
189 @author3.created_at = Time.now + 200
191 @other_user4 = FactoryGirl.create :user_yas
192 @author4 = @other_user4.author
193 @author4.created_at = Time.now + 300
195 @other_user5 = FactoryGirl.create :user_yas
196 @author5 = @other_user5.author
197 @author5.created_at = Time.now + 400
199 Author.stub(:default_page_size).and_return(2)
203 r.should have(2).items
205 it 'page=1なら末尾2件を返す' do
208 r.should eq [@author5, @author4]
210 it 'page=2なら中間2件を返す' do
212 r.should eq [@author3, @author2]
214 it 'page=3なら先頭1件を返す' do
216 r.should eq [@author]
219 context 'DBに5件あって1ページの件数を0件に変えたとして' do
221 @other_user2 = FactoryGirl.create :user_yas
222 @author2 = @other_user2.author
223 @author2.created_at = Time.now + 100
225 @other_user3 = FactoryGirl.create :user_yas
226 @author3 = @other_user3.author
227 @author3.created_at = Time.now + 200
229 @other_user4 = FactoryGirl.create :user_yas
230 @author4 = @other_user4.author
231 @author4.created_at = Time.now + 300
233 @other_user5 = FactoryGirl.create :user_yas
234 @author5 = @other_user5.author
235 @author5.created_at = Time.now + 400
237 Author.stub(:default_page_size).and_return(2)
241 r.should have(5).items
245 describe '一覧取得オプションに於いて' do
246 it 'includeキーを含んでいる' do
248 r.has_key?(:include).should be_true
251 r = Author.list_opt[:include]
252 r.should have(1).items
255 r = Author.list_opt[:include]
256 r.has_key?(:artist).should be_true
259 describe 'json一覧出力オプションに於いて' do
261 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
264 r = Author.list.to_json Author.list_json_opt
267 i.has_key?('artist').should be_true
271 describe '単体取得に於いて' do
274 context 'つつがなく終わるとき' do
\r
275 it '単体取得オプションを利用している' do
\r
276 Author.stub(:show_opt).with(any_args).and_return({})
\r
277 Author.should_receive(:show_opt).with(any_args).exactly(1)
\r
278 r = Author.show @author.id, @author
280 it '閲覧許可を問い合わせている' do
\r
281 Author.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
282 Author.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
283 r = Author.show @author.id, @author
287 r = Author.show @author.id, @author
290 context '閲覧許可が出なかったとき' do
\r
291 it '403Forbidden例外を返す' do
\r
292 Author.any_instance.stub(:visible?).and_return(false)
\r
294 Author.show @author.id, @author
\r
295 }.should raise_error(ActiveRecord::Forbidden)
\r
298 context '存在しない作家を開こうとしたとき' do
\r
299 it '404RecordNotFound例外を返す' do
\r
301 Author.show 110, @author
\r
302 }.should raise_error(ActiveRecord::RecordNotFound)
\r
306 describe '編集取得に於いて' do
309 context 'つつがなく終わるとき' do
\r
310 it '単体取得オプションを利用している' do
\r
311 Author.stub(:show_opt).with(any_args).and_return({})
\r
312 Author.should_receive(:show_opt).with(any_args).exactly(1)
\r
313 r = Author.edit @author.id, @author
315 it '所持判定を問い合わせている' do
\r
316 Author.any_instance.stub(:own?).with(any_args).and_return(true)
\r
317 Author.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
318 r = Author.edit @author.id, @author
322 Author.any_instance.stub(:own?).and_return(true)
323 r = Author.edit @author.id, @author.id
326 context '他人の作家を開こうとしたとき' do
327 it '403Forbidden例外を返す' do
328 Author.any_instance.stub(:own?).and_return(false)
330 Author.edit @author.id, @author
331 }.should raise_error(ActiveRecord::Forbidden)
334 context '存在しない作家を開こうとしたとき' do
335 it '404RecordNotFound例外を返す' do
337 Author.edit 110, @author
338 }.should raise_error(ActiveRecord::RecordNotFound)
342 describe '単体取得オプションに於いて' do
343 it 'includeキーを含んでいる' do
345 r.has_key?(:include).should be_true
348 r = Author.show_opt[:include]
349 r.should have(1).items
352 r = Author.show_opt[:include]
353 r.has_key?(:artist).should be_true
356 describe 'json単体出力オプションに於いて' do
358 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
361 r = Author.show(@author.id, @author).to_json Author.show_json_opt
364 i.has_key?('artist').should be_true
368 describe 'マイリストページ制御パラメータに於いて' do
371 context 'コミックpage_size補正について' do
372 it '文字列から数値に変換される' do
373 Author.comic_page_size('7').should eq 7
375 it 'nilの場合はAuthor.default_comic_page_sizeになる' do
376 Author.comic_page_size().should eq Author.default_comic_page_size
378 it '0以下の場合はAuthor.default_comic_page_sizeになる' do
379 Author.comic_page_size('0').should eq Author.default_comic_page_size
381 it 'Author.comic_max_page_sizeを超えた場合はAuthor.comic_max_page_sizeになる' do
382 Author.comic_page_size('1000').should eq Author.comic_max_page_size
385 context 'ストーリーpage_size補正について' do
386 it '文字列から数値に変換される' do
387 Author.story_page_size('7').should eq 7
389 it 'nilの場合はAuthor.default_story_page_sizeになる' do
390 Author.story_page_size().should eq Author.default_story_page_size
392 it '0以下の場合はAuthor.default_story_page_sizeになる' do
393 Author.story_page_size('0').should eq Author.default_story_page_size
395 it 'Author.story_max_page_sizeを超えた場合はAuthor.story_max_page_sizeになる' do
396 Author.story_page_size('1000').should eq Author.story_max_page_size
399 context 'コマ絵page_size補正について' do
400 it '文字列から数値に変換される' do
401 Author.panel_page_size('7').should eq 7
403 it 'nilの場合はAuthor.default_panel_page_sizeになる' do
404 Author.panel_page_size().should eq Author.default_panel_page_size
406 it '0以下の場合はAuthor.default_panel_page_sizeになる' do
407 Author.panel_page_size('0').should eq Author.default_panel_page_size
409 it 'Author.panel_max_page_sizeを超えた場合はAuthor.panel_max_page_sizeになる' do
410 Author.panel_page_size('1000').should eq Author.panel_max_page_size
413 context '景色素材page_size補正について' do
414 it '文字列から数値に変換される' do
415 Author.panel_picture_page_size('7').should eq 7
417 it 'nilの場合はAuthor.default_panel_picture_page_sizeになる' do
418 Author.panel_picture_page_size().should eq Author.default_panel_picture_page_size
420 it '0以下の場合はAuthor.default_panel_picture_page_sizeになる' do
421 Author.panel_picture_page_size('0').should eq Author.default_panel_picture_page_size
423 it 'Author.panel_picture_max_page_sizeを超えた場合はAuthor.panel_picture_max_page_sizeになる' do
424 Author.panel_picture_page_size('1000').should eq Author.panel_picture_max_page_size
427 context '景色カラーpage_size補正について' do
428 it '文字列から数値に変換される' do
429 Author.ground_picture_page_size('7').should eq 7
431 it 'nilの場合はAuthor.default_ground_picture_page_sizeになる' do
432 Author.ground_picture_page_size().should eq Author.default_ground_picture_page_size
434 it '0以下の場合はAuthor.default_ground_picture_page_sizeになる' do
435 Author.ground_picture_page_size('0').should eq Author.default_ground_picture_page_size
437 it 'Author.ground_picture_max_page_sizeを超えた場合はAuthor.ground_picture_max_page_sizeになる' do
438 Author.ground_picture_page_size('1000').should eq Author.ground_picture_max_page_size
441 context '景色カラーコードpage_size補正について' do
442 it '文字列から数値に変換される' do
443 Author.ground_color_page_size('7').should eq 7
445 it 'nilの場合はAuthor.default_ground_color_page_sizeになる' do
446 Author.ground_color_page_size().should eq Author.default_ground_color_page_size
448 it '0以下の場合はAuthor.default_ground_color_page_sizeになる' do
449 Author.ground_color_page_size('0').should eq Author.default_ground_color_page_size
451 it 'Author.ground_color_max_page_sizeを超えた場合はAuthor.ground_color_max_page_sizeになる' do
452 Author.ground_color_page_size('1000').should eq Author.ground_color_max_page_size