1 # -*- encoding: utf-8 -*-
7 FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
16 context 'オーソドックスなデータのとき' do
19 @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 'user_idを検証するとき' do
41 @author.should_not be_valid
45 @author.should_not be_valid
47 it '存在するアカウントでなければ失敗する' do
49 @author.should_not be_valid
54 describe 'デフォルト値補充に於いて' do
55 it '名前がno nameになっている' do
56 @author = FactoryGirl.build :author, :name => nil
57 @author.supply_default
58 @author.name.should eq 'no name'
62 describe '上書き補充に於いて' do
65 describe '所持判定に於いて' do
67 @other_user = FactoryGirl.create :user_yas
68 #アカウントを作ると連動して作家ができる @other_author = FactoryGirl.create :author_yas, :user_id => @other_user.id
\r
71 @author.own?(@author).should == true
74 @author.own?(@other_author).should == false
77 @author.own?(nil).should == false
81 describe '閲覧許可に於いて' do
85 @author.visible?(@author).should == true
89 describe '絵師作家判定に於いて' do
94 artist = FactoryGirl.create :artist, :author_id => @author.id
95 @author.artist?.should eq true
98 context 'Falseのケース' do
100 @author.artist?.should eq false
105 describe '一覧取得に於いて' do
108 context 'page補正について' do
109 it '文字列から数値に変換される' do
110 Author.page('8').should eq 8
113 Author.page().should eq 1
116 Author.page('0').should eq 1
119 context 'page_size補正について' do
120 it '文字列から数値に変換される' do
121 Author.page_size('7').should eq 7
123 it 'nilの場合はAuthor.default_page_sizeになる' do
124 Author.page_size().should eq Author.default_page_size
126 it '0以下の場合はAuthor.default_page_sizeになる' do
127 Author.page_size('0').should eq Author.default_page_size
129 it 'Author.max_page_sizeを超えた場合はAuthor.max_page_sizeになる' do
130 Author.page_size('1000').should eq Author.max_page_size
133 context 'つつがなく終わるとき' do
\r
134 it '一覧取得オプションを利用している' do
\r
135 Author.stub(:list_opt).with(any_args).and_return({})
\r
136 Author.should_receive(:list_opt).with(any_args).exactly(1)
\r
142 r.should eq [@author]
145 @other_user = FactoryGirl.create :user_yas
147 n = @other_user.author
148 n.created_at = Time.now + 100
151 l.should eq [n, @author]
153 context 'DBに5件あって1ページの件数を2件に変えたとして' do
155 @other_user2 = FactoryGirl.create :user_yas
156 @author2 = @other_user2.author
157 @author2.created_at = Time.now + 100
159 @other_user3 = FactoryGirl.create :user_yas
160 @author3 = @other_user3.author
161 @author3.created_at = Time.now + 200
163 @other_user4 = FactoryGirl.create :user_yas
164 @author4 = @other_user4.author
165 @author4.created_at = Time.now + 300
167 @other_user5 = FactoryGirl.create :user_yas
168 @author5 = @other_user5.author
169 @author5.created_at = Time.now + 400
171 Author.stub(:default_page_size).and_return(2)
175 r.should have(2).items
177 it 'page=1なら末尾2件を返す' do
180 r.should eq [@author5, @author4]
182 it 'page=2なら中間2件を返す' do
184 r.should eq [@author3, @author2]
186 it 'page=3なら先頭1件を返す' do
188 r.should eq [@author]
191 context 'DBに5件あって1ページの件数を0件に変えたとして' do
193 @other_user2 = FactoryGirl.create :user_yas
194 @author2 = @other_user2.author
195 @author2.created_at = Time.now + 100
197 @other_user3 = FactoryGirl.create :user_yas
198 @author3 = @other_user3.author
199 @author3.created_at = Time.now + 200
201 @other_user4 = FactoryGirl.create :user_yas
202 @author4 = @other_user4.author
203 @author4.created_at = Time.now + 300
205 @other_user5 = FactoryGirl.create :user_yas
206 @author5 = @other_user5.author
207 @author5.created_at = Time.now + 400
209 Author.stub(:default_page_size).and_return(0)
213 r.should have(5).items
217 describe '一覧取得オプションに於いて' do
218 it 'includeキーを含んでいる' do
220 r.has_key?(:include).should be_true
223 r = Author.list_opt[:include]
224 r.should have(1).items
227 r = Author.list_opt[:include]
228 r.has_key?(:artist).should be_true
231 describe 'json一覧出力オプションに於いて' do
232 it 'includeキーを含んでいる' do
233 r = Author.list_json_opt
234 r.has_key?(:include).should be_true
237 r = Author.list_json_opt[:include]
238 r.should have(1).items
241 r = Author.list_json_opt[:include]
242 r.has_key?(:artist).should be_true
246 describe '単体取得に於いて' do
249 context 'つつがなく終わるとき' do
\r
250 it '単体取得オプションを利用している' do
\r
251 Author.stub(:show_opt).with(any_args).and_return({})
\r
252 Author.should_receive(:show_opt).with(any_args).exactly(1)
\r
253 r = Author.show @author.id, @author
255 it '閲覧許可を問い合わせている' do
\r
256 Author.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
257 Author.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
258 r = Author.show @author.id, @author
262 r = Author.show @author.id, @author
265 context '閲覧許可が出なかったとき' do
\r
266 it '403Forbidden例外を返す' do
\r
267 Author.any_instance.stub(:visible?).and_return(false)
\r
269 Author.show @author.id, @author
\r
270 }.should raise_error(ActiveRecord::Forbidden)
\r
273 context '存在しない作家を開こうとしたとき' do
\r
274 it '404RecordNotFound例外を返す' do
\r
276 Author.show 110, @author
\r
277 }.should raise_error(ActiveRecord::RecordNotFound)
\r
281 describe '編集取得に於いて' do
284 context 'つつがなく終わるとき' do
\r
285 it '単体取得オプションを利用している' do
\r
286 Author.stub(:show_opt).with(any_args).and_return({})
\r
287 Author.should_receive(:show_opt).with(any_args).exactly(1)
\r
288 r = Author.edit @author.id, @author
290 it '所持判定を問い合わせている' do
\r
291 Author.any_instance.stub(:own?).with(any_args).and_return(true)
\r
292 Author.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
293 r = Author.edit @author.id, @author
297 Author.any_instance.stub(:own?).and_return(true)
298 r = Author.edit @author.id, @author.id
301 context '他人の作家を開こうとしたとき' do
302 it '403Forbidden例外を返す' do
303 Author.any_instance.stub(:own?).and_return(false)
305 Author.edit @author.id, @author
306 }.should raise_error(ActiveRecord::Forbidden)
309 context '存在しない作家を開こうとしたとき' do
310 it '404RecordNotFound例外を返す' do
312 Author.edit 110, @author
313 }.should raise_error(ActiveRecord::RecordNotFound)
317 describe '単体取得オプションに於いて' do
318 it 'includeキーを含んでいる' do
320 r.has_key?(:include).should be_true
323 r = Author.show_opt[:include]
324 r.should have(1).items
327 r = Author.show_opt[:include]
328 r.has_key?(:artist).should be_true
331 describe 'json単体出力オプションに於いて' do
332 it 'includeキーを含んでいる' do
333 r = Author.show_json_opt
334 r.has_key?(:include).should be_true
337 r = Author.show_json_opt[:include]
338 r.should have(1).items
341 r = Author.show_json_opt[:include]
342 r.has_key?(:artist).should be_true
346 describe 'マイリストページ制御パラメータに於いて' do
349 context 'コミックpage_size補正について' do
350 it '文字列から数値に変換される' do
351 Author.comic_page_size('7').should eq 7
353 it 'nilの場合はAuthor.default_comic_page_sizeになる' do
354 Author.comic_page_size().should eq Author.default_comic_page_size
356 it '0以下の場合はAuthor.default_comic_page_sizeになる' do
357 Author.comic_page_size('0').should eq Author.default_comic_page_size
359 it 'Author.comic_max_page_sizeを超えた場合はAuthor.comic_max_page_sizeになる' do
360 Author.comic_page_size('1000').should eq Author.comic_max_page_size
363 context 'ストーリーpage_size補正について' do
364 it '文字列から数値に変換される' do
365 Author.story_page_size('7').should eq 7
367 it 'nilの場合はAuthor.default_story_page_sizeになる' do
368 Author.story_page_size().should eq Author.default_story_page_size
370 it '0以下の場合はAuthor.default_story_page_sizeになる' do
371 Author.story_page_size('0').should eq Author.default_story_page_size
373 it 'Author.story_max_page_sizeを超えた場合はAuthor.story_max_page_sizeになる' do
374 Author.story_page_size('1000').should eq Author.story_max_page_size
377 context 'コマ絵page_size補正について' do
378 it '文字列から数値に変換される' do
379 Author.panel_page_size('7').should eq 7
381 it 'nilの場合はAuthor.default_panel_page_sizeになる' do
382 Author.panel_page_size().should eq Author.default_panel_page_size
384 it '0以下の場合はAuthor.default_panel_page_sizeになる' do
385 Author.panel_page_size('0').should eq Author.default_panel_page_size
387 it 'Author.panel_max_page_sizeを超えた場合はAuthor.panel_max_page_sizeになる' do
388 Author.panel_page_size('1000').should eq Author.panel_max_page_size
391 context '景色素材page_size補正について' do
392 it '文字列から数値に変換される' do
393 Author.panel_picture_page_size('7').should eq 7
395 it 'nilの場合はAuthor.default_panel_picture_page_sizeになる' do
396 Author.panel_picture_page_size().should eq Author.default_panel_picture_page_size
398 it '0以下の場合はAuthor.default_panel_picture_page_sizeになる' do
399 Author.panel_picture_page_size('0').should eq Author.default_panel_picture_page_size
401 it 'Author.panel_picture_max_page_sizeを超えた場合はAuthor.panel_picture_max_page_sizeになる' do
402 Author.panel_picture_page_size('1000').should eq Author.panel_picture_max_page_size
405 context '景色カラーpage_size補正について' do
406 it '文字列から数値に変換される' do
407 Author.ground_picture_page_size('7').should eq 7
409 it 'nilの場合はAuthor.default_ground_picture_page_sizeになる' do
410 Author.ground_picture_page_size().should eq Author.default_ground_picture_page_size
412 it '0以下の場合はAuthor.default_ground_picture_page_sizeになる' do
413 Author.ground_picture_page_size('0').should eq Author.default_ground_picture_page_size
415 it 'Author.ground_picture_max_page_sizeを超えた場合はAuthor.ground_picture_max_page_sizeになる' do
416 Author.ground_picture_page_size('1000').should eq Author.ground_picture_max_page_size
419 context '景色カラーコードpage_size補正について' do
420 it '文字列から数値に変換される' do
421 Author.ground_color_page_size('7').should eq 7
423 it 'nilの場合はAuthor.default_ground_color_page_sizeになる' do
424 Author.ground_color_page_size().should eq Author.default_ground_color_page_size
426 it '0以下の場合はAuthor.default_ground_color_page_sizeになる' do
427 Author.ground_color_page_size('0').should eq Author.default_ground_color_page_size
429 it 'Author.ground_color_max_page_sizeを超えた場合はAuthor.ground_color_max_page_sizeになる' do
430 Author.ground_color_page_size('1000').should eq Author.ground_color_max_page_size