1 # -*- encoding: utf-8 -*-
7 SpeechBalloonTemplate.delete_all
8 @admin = FactoryGirl.create :admin
9 @user = FactoryGirl.create( :user_yas)
10 @author = FactoryGirl.create :author, :user_id => @user.id
11 @other_user = FactoryGirl.create( :user_yas)
12 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
13 @sp = FactoryGirl.create :system_picture
14 @lg = FactoryGirl.create :license_group
15 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
20 @artist = FactoryGirl.build :artist, :author_id => @author.id
23 context 'オーソドックスなデータのとき' do
26 @artist.should be_valid
30 @artist.should be_valid
34 context 'nameを検証するとき' do
37 @artist.should_not be_valid
41 @artist.should_not be_valid
44 context 'author_idを検証するとき' do
47 @artist.author_id = 'a'
48 @artist.should_not be_valid
53 describe '文字コード検証に於いて' do
55 @artist = FactoryGirl.build :artist, :author_id => @author.id
58 context 'nameを検証するとき' do
59 it 'Shift JISなら失敗する' do
60 @artist.name = "\x83G\x83r\x83]\x83D"
63 }.should raise_error(Pettanr::BadRequest)
69 describe 'デフォルト値補充に於いて' do
70 it '名前がno nameになっている' do
71 @artist = FactoryGirl.build :artist, :name => nil
72 @artist.supply_default
73 @artist.name.should eq 'no name'
77 describe '上書き補充に於いて' do
79 @artist = FactoryGirl.build :artist
80 @artist.overwrite @author
81 @artist.author_id.should eq @author.id
85 describe '所持判定に於いて' do
87 @artist = FactoryGirl.create :artist, :author_id => @author.id
88 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
91 it '自身にロールリストからの作家取得を依頼している' do
92 Artist.should_receive(:get_author_from_roles).with(any_args).exactly(1)
93 r = @artist.own?([@author])
96 context 'ロール内作家が取得できるとき' do
99 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
100 Artist.stub(:get_author_from_roles).with(any_args).and_return(@author)
101 r = @artist.own?([@author])
104 it 'ロール内作家のidが自身の作家idと一致しないならno' do
105 Artist.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
106 @artist.own?(@other_author).should be_false
109 context 'ロール内作家が取得できないとき' do
111 Artist.stub(:get_author_from_roles).with(any_args).and_return(nil)
114 r = @artist.own?([@author])
120 describe '閲覧許可に於いて' do
122 @artist = FactoryGirl.create :artist, :author_id => @author.id
124 context 'オープンモードのとき' do
126 MagicNumber['run_mode'] = 0
128 it '自身にゲスト用ロールチェックを問い合わせしている' do
129 Artist.any_instance.stub(:guest_role_check).and_return(true)
130 Artist.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
131 r = @artist.visible?([@author])
133 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
134 Artist.any_instance.stub(:guest_role_check).and_return(false)
135 r = @artist.visible?([@author])
139 context 'クローズドモードのとき' do
141 MagicNumber['run_mode'] = 1
143 it '自身に素材読者用ロールチェックを問い合わせしている' do
144 Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
145 Artist.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)
146 r = @artist.visible?([@author])
148 it '素材読者用ロールチェックが失敗したとき、falseを返す' do
149 Artist.any_instance.stub(:resource_reader_role_check).and_return(false)
150 r = @artist.visible?([@author])
154 context 'つつがなく終わるとき' do
156 MagicNumber['run_mode'] = 1
157 Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
160 r = @artist.visible?([@author])
166 describe '一覧取得に於いて' do
168 @artist = FactoryGirl.create :artist, :author_id => @author.id
170 context 'page補正について' do
171 it '文字列から数値に変換される' do
172 Artist.page('8').should eq 8
175 Artist.page().should eq 1
178 Artist.page('0').should eq 1
181 context 'page_size補正について' do
182 it '文字列から数値に変換される' do
183 Artist.page_size('7').should eq 7
185 it 'nilの場合はArtist.default_page_sizeになる' do
186 Artist.page_size().should eq Artist.default_page_size
188 it '0以下の場合はArtist.default_page_sizeになる' do
189 Artist.page_size('0').should eq Artist.default_page_size
191 it 'Artist.max_page_sizeを超えた場合はArtist.max_page_sizeになる' do
192 Artist.page_size('1000').should eq Artist.max_page_size
195 context 'つつがなく終わるとき' do
196 it '一覧取得オプションを利用している' do
197 Artist.stub(:list_opt).with(any_args).and_return({})
198 Artist.should_receive(:list_opt).with(any_args).exactly(1)
204 r.should eq [@artist]
207 n = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist', :created_at => Time.now + 100
209 l.should eq [n, @artist]
211 it 'ただし、内絵師(作家idが空)だけとする' do
212 n = FactoryGirl.create :artist, :author_id => nil
214 l.should eq [@artist]
216 context 'DBに5件あって1ページの件数を2件に変えたとして' do
218 @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
219 @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
220 @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
221 @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
222 Artist.stub(:default_page_size).and_return(2)
226 r.should have(2).items
228 it 'page=1なら末尾2件を返す' do
231 r.should eq [@artist5, @artist4]
233 it 'page=2なら中間2件を返す' do
235 r.should eq [@artist3, @artist2]
237 it 'page=3なら先頭1件を返す' do
239 r.should eq [@artist]
244 describe '一覧ページ制御に於いて' do
246 Artist.stub(:count).with(any_args).and_return(100)
249 r = Artist.list_paginate
250 r.is_a?(Kaminari::PaginatableArray).should be_true
252 it '一覧の取得条件を利用している' do
253 Artist.stub(:list_where).with(any_args).and_return('')
254 Artist.should_receive(:list_where).with(any_args).exactly(1)
255 r = Artist.list_paginate
257 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
258 r = Artist.list_paginate 3, 10
259 r.limit_value.should eq 10
260 r.offset_value.should eq 20
264 describe '一覧取得オプションに於いて' do
267 r.should have(1).items
271 r.has_key?(:author).should be_true
274 describe 'json一覧出力オプションに於いて' do
276 @artist = FactoryGirl.create :artist, :author_id => @author.id
279 r = Artist.list.to_json Artist.list_json_opt
282 i.has_key?('author').should be_true
286 describe '単体取得に於いて' do
288 @artist = FactoryGirl.create :artist, :author_id => @author.id
290 context 'つつがなく終わるとき' do
291 it '単体取得オプションを利用している' do
292 Artist.stub(:show_opt).with(any_args).and_return({})
293 Artist.should_receive(:show_opt).with(any_args).exactly(1)
294 r = Artist.show @artist.id, @author
296 it '閲覧許可を問い合わせている' do
297 Artist.any_instance.stub(:visible?).with(any_args).and_return(true)
298 Artist.any_instance.should_receive(:visible?).with(any_args).exactly(1)
299 r = Artist.show @artist.id, @author
303 a = Artist.show @artist.id, @author
306 context '閲覧許可が出なかったとき' do
307 it '403Forbidden例外を返す' do
308 Artist.any_instance.stub(:visible?).and_return(false)
310 Artist.show @artist.id, @author
311 }.should raise_error(ActiveRecord::Forbidden)
314 context '存在しない絵師を開こうとしたとき' do
315 it '404RecordNotFound例外を返す' do
317 Artist.show 110, @author
318 }.should raise_error(ActiveRecord::RecordNotFound)
322 describe '編集取得に於いて' do
324 @artist = FactoryGirl.create :artist, :author_id => @author.id
326 context 'つつがなく終わるとき' do
327 it '単体取得オプションを利用している' do
328 Artist.stub(:show_opt).with(any_args).and_return({})
329 Artist.should_receive(:show_opt).with(any_args).exactly(1)
330 r = Artist.edit @artist.id, @author
332 it '所持判定を問い合わせている' do
333 Artist.any_instance.stub(:own?).with(any_args).and_return(true)
334 Artist.any_instance.should_receive(:own?).with(any_args).exactly(1)
335 r = Artist.edit @artist.id, @author
339 Artist.any_instance.stub(:own?).and_return(true)
340 r = Artist.edit @artist.id, @author.id
343 context '他人の絵師を開こうとしたとき' do
344 it '403Forbidden例外を返す' do
345 Artist.any_instance.stub(:own?).and_return(false)
347 Artist.edit @artist.id, @author
348 }.should raise_error(ActiveRecord::Forbidden)
351 context '存在しない絵師を開こうとしたとき' do
352 it '404RecordNotFound例外を返す' do
354 Artist.edit 110, @author
355 }.should raise_error(ActiveRecord::RecordNotFound)
359 describe '単体取得オプションに於いて' do
360 it 'includeキーを含んでいる' do
362 r.has_key?(:include).should be_true
365 r = Artist.show_opt[:include]
366 r.should have(1).items
369 describe 'json単体出力オプションに於いて' do
371 @artist = FactoryGirl.create :artist, :author_id => @author.id
374 r = Artist.show(@artist.id, @author).to_json Artist.show_json_opt
377 i.has_key?('author').should be_true
381 describe '有効絵師数に於いて' do
383 @artist = FactoryGirl.create :artist, :author_id => @author.id
384 @artist = FactoryGirl.create :artist, :author_id => @other_author.id
385 @artist = FactoryGirl.create :artist, :author_id => nil
388 r = Artist.visible_count
393 describe 'エクスポートに於いて' do
395 @artist = FactoryGirl.create :artist, :author_id => @author.id
396 @artist2 = FactoryGirl.create :artist, :author_id => @other_author.id, :updated_at => Time.now - 3000
397 @artist3 = FactoryGirl.create :artist, :author_id => nil
399 it '開始日時が省略された場合はすべての内絵師を返す' do
401 r.should eq [@artist, @artist2]
403 it '開始日時以降に更新された内絵師を返す' do
404 r = Artist.export @artist.updated_at - 100
405 r.should eq [@artist]