1 # -*- encoding: utf-8 -*-
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
10 @other_user = FactoryGirl.create( :user_yas)
11 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
12 @sp = FactoryGirl.create :system_picture
13 @lg = FactoryGirl.create :license_group
14 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
19 @artist = FactoryGirl.build :artist, :author_id => @author.id
22 context 'オーソドックスなデータのとき' do
25 @artist.should be_valid
29 @artist.should be_valid
33 context 'nameを検証するとき' do
36 @artist.should_not be_valid
40 @artist.should_not be_valid
43 context 'author_idを検証するとき' do
46 @artist.author_id = 'a'
47 @artist.should_not be_valid
52 describe 'デフォルト値補充に於いて' do
53 it '名前がno nameになっている' do
54 @artist = FactoryGirl.build :artist, :name => nil
55 @artist.supply_default
56 @artist.name.should eq 'no name'
60 describe '上書き補充に於いて' do
62 @artist = FactoryGirl.build :artist
63 @artist.overwrite @author
64 @artist.author_id.should eq @author.id
68 describe '所持判定に於いて' do
70 @artist = FactoryGirl.create :artist, :author_id => @author.id
71 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
74 it '自身にロールリストからの作家取得を依頼している' do
75 Artist.should_receive(:get_author_from_roles).with(any_args).exactly(1)
76 r = @artist.own?([@author])
79 context 'ロール内作家が取得できるとき' do
82 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
83 Artist.stub(:get_author_from_roles).with(any_args).and_return(@author)
84 r = @artist.own?([@author])
87 it 'ロール内作家のidが自身の作家idと一致しないならno' do
88 Artist.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
89 @artist.own?(@other_author).should be_false
92 context 'ロール内作家が取得できないとき' do
94 Artist.stub(:get_author_from_roles).with(any_args).and_return(nil)
97 r = @artist.own?([@author])
103 describe '閲覧許可に於いて' do
105 @artist = FactoryGirl.create :artist, :author_id => @author.id
107 context 'オープンモードのとき' do
109 MagicNumber['run_mode'] = 0
111 it '自身にゲスト用ロールチェックを問い合わせしている' do
112 Artist.any_instance.stub(:guest_role_check).and_return(true)
113 Artist.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
114 r = @artist.visible?([@author])
116 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
117 Artist.any_instance.stub(:guest_role_check).and_return(false)
118 r = @artist.visible?([@author])
122 context 'クローズドモードのとき' do
124 MagicNumber['run_mode'] = 1
126 it '自身に素材読者用ロールチェックを問い合わせしている' do
127 Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
128 Artist.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)
129 r = @artist.visible?([@author])
131 it '素材読者用ロールチェックが失敗したとき、falseを返す' do
132 Artist.any_instance.stub(:resource_reader_role_check).and_return(false)
133 r = @artist.visible?([@author])
137 context 'つつがなく終わるとき' do
139 MagicNumber['run_mode'] = 1
140 Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
143 r = @artist.visible?([@author])
149 describe '一覧取得に於いて' do
151 @artist = FactoryGirl.create :artist, :author_id => @author.id
153 context 'page補正について' do
154 it '文字列から数値に変換される' do
155 Artist.page('8').should eq 8
158 Artist.page().should eq 1
161 Artist.page('0').should eq 1
164 context 'page_size補正について' do
165 it '文字列から数値に変換される' do
166 Artist.page_size('7').should eq 7
168 it 'nilの場合はArtist.default_page_sizeになる' do
169 Artist.page_size().should eq Artist.default_page_size
171 it '0以下の場合はArtist.default_page_sizeになる' do
172 Artist.page_size('0').should eq Artist.default_page_size
174 it 'Artist.max_page_sizeを超えた場合はArtist.max_page_sizeになる' do
175 Artist.page_size('1000').should eq Artist.max_page_size
178 context 'つつがなく終わるとき' do
179 it '一覧取得オプションを利用している' do
180 Artist.stub(:list_opt).with(any_args).and_return({})
181 Artist.should_receive(:list_opt).with(any_args).exactly(1)
187 r.should eq [@artist]
190 n = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist', :created_at => Time.now + 100
192 l.should eq [n, @artist]
194 it 'ただし、内絵師(作家idが空)だけとする' do
195 n = FactoryGirl.create :artist, :author_id => nil
197 l.should eq [@artist]
199 context 'DBに5件あって1ページの件数を2件に変えたとして' do
201 @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
202 @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
203 @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
204 @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
205 Artist.stub(:default_page_size).and_return(2)
209 r.should have(2).items
211 it 'page=1なら末尾2件を返す' do
214 r.should eq [@artist5, @artist4]
216 it 'page=2なら中間2件を返す' do
218 r.should eq [@artist3, @artist2]
220 it 'page=3なら先頭1件を返す' do
222 r.should eq [@artist]
225 context 'DBに5件あって1ページの件数を0件に変えたとして' do
227 @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
228 @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
229 @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
230 @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
231 Artist.stub(:default_page_size).and_return(2)
235 r.should have(5).items
239 describe '一覧取得オプションに於いて' do
240 it 'includeキーを含んでいる' do
242 r.has_key?(:include).should be_true
245 r = Artist.list_opt[:include]
246 r.should have(1).items
249 r = Artist.list_opt[:include]
250 r.has_key?(:author).should be_true
253 describe 'json一覧出力オプションに於いて' do
255 @artist = FactoryGirl.create :artist, :author_id => @author.id
258 r = Artist.list.to_json Artist.list_json_opt
261 i.has_key?('author').should be_true
265 describe '単体取得に於いて' do
267 @artist = FactoryGirl.create :artist, :author_id => @author.id
269 context 'つつがなく終わるとき' do
270 it '単体取得オプションを利用している' do
271 Artist.stub(:show_opt).with(any_args).and_return({})
272 Artist.should_receive(:show_opt).with(any_args).exactly(1)
273 r = Artist.show @artist.id, @author
275 it '閲覧許可を問い合わせている' do
276 Artist.any_instance.stub(:visible?).with(any_args).and_return(true)
277 Artist.any_instance.should_receive(:visible?).with(any_args).exactly(1)
278 r = Artist.show @artist.id, @author
282 a = Artist.show @artist.id, @author
285 context '閲覧許可が出なかったとき' do
286 it '403Forbidden例外を返す' do
287 Artist.any_instance.stub(:visible?).and_return(false)
289 Artist.show @artist.id, @author
290 }.should raise_error(ActiveRecord::Forbidden)
293 context '存在しない絵師を開こうとしたとき' do
294 it '404RecordNotFound例外を返す' do
296 Artist.show 110, @author
297 }.should raise_error(ActiveRecord::RecordNotFound)
301 describe '編集取得に於いて' do
303 @artist = FactoryGirl.create :artist, :author_id => @author.id
305 context 'つつがなく終わるとき' do
306 it '単体取得オプションを利用している' do
307 Artist.stub(:show_opt).with(any_args).and_return({})
308 Artist.should_receive(:show_opt).with(any_args).exactly(1)
309 r = Artist.edit @artist.id, @author
311 it '所持判定を問い合わせている' do
312 Artist.any_instance.stub(:own?).with(any_args).and_return(true)
313 Artist.any_instance.should_receive(:own?).with(any_args).exactly(1)
314 r = Artist.edit @artist.id, @author
318 Artist.any_instance.stub(:own?).and_return(true)
319 r = Artist.edit @artist.id, @author.id
322 context '他人の絵師を開こうとしたとき' do
323 it '403Forbidden例外を返す' do
324 Artist.any_instance.stub(:own?).and_return(false)
326 Artist.edit @artist.id, @author
327 }.should raise_error(ActiveRecord::Forbidden)
330 context '存在しない絵師を開こうとしたとき' do
331 it '404RecordNotFound例外を返す' do
333 Artist.edit 110, @author
334 }.should raise_error(ActiveRecord::RecordNotFound)
338 describe '単体取得オプションに於いて' do
339 it 'includeキーを含んでいる' do
341 r.has_key?(:include).should be_true
344 r = Artist.show_opt[:include]
345 r.should have(1).items
348 describe 'json単体出力オプションに於いて' do
350 @artist = FactoryGirl.create :artist, :author_id => @author.id
353 r = Artist.show(@artist.id, @author).to_json Artist.show_json_opt
356 i.has_key?('author').should be_true
360 describe '有効絵師数に於いて' do
362 @artist = FactoryGirl.create :artist, :author_id => @author.id
363 @artist = FactoryGirl.create :artist, :author_id => @other_author.id
364 @artist = FactoryGirl.create :artist, :author_id => nil
367 r = Artist.visible_count
372 describe 'エクスポートに於いて' do
374 @artist = FactoryGirl.create :artist, :author_id => @author.id
375 @artist2 = FactoryGirl.create :artist, :author_id => @other_author.id, :updated_at => Time.now - 3000
376 @artist3 = FactoryGirl.create :artist, :author_id => nil
378 it '開始日時が省略された場合はすべての内絵師を返す' do
380 r.should eq [@artist, @artist2]
382 it '開始日時以降に更新された内絵師を返す' do
383 r = Artist.export @artist.updated_at - 100
384 r.should eq [@artist]