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
54 @artist = FactoryGirl.build :artist, :author_id => @author.id
57 context 'nameを検証するとき' do
58 it 'Shift JISなら失敗する' do
59 @artist.name = "\x83G\x83r\x83]\x83D"
62 }.should raise_error(Pettanr::BadRequest)
68 describe 'デフォルト値補充に於いて' do
69 it '名前がno nameになっている' do
70 @artist = FactoryGirl.build :artist, :name => nil
71 @artist.supply_default
72 @artist.name.should eq 'no name'
76 describe '上書き補充に於いて' do
78 @artist = FactoryGirl.build :artist
79 @artist.overwrite @author
80 @artist.author_id.should eq @author.id
84 describe '所持判定に於いて' do
86 @artist = FactoryGirl.create :artist, :author_id => @author.id
87 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
90 it '自身にロールリストからの作家取得を依頼している' do
91 Artist.should_receive(:get_author_from_roles).with(any_args).exactly(1)
92 r = @artist.own?([@author])
95 context 'ロール内作家が取得できるとき' do
98 it 'ロール内作家のidが自身の作家idと一致するなら許可する' do
99 Artist.stub(:get_author_from_roles).with(any_args).and_return(@author)
100 r = @artist.own?([@author])
103 it 'ロール内作家のidが自身の作家idと一致しないならno' do
104 Artist.stub(:get_author_from_roles).with(any_args).and_return(@other_author)
105 @artist.own?(@other_author).should be_false
108 context 'ロール内作家が取得できないとき' do
110 Artist.stub(:get_author_from_roles).with(any_args).and_return(nil)
113 r = @artist.own?([@author])
119 describe '閲覧許可に於いて' do
121 @artist = FactoryGirl.create :artist, :author_id => @author.id
123 context 'オープンモードのとき' do
125 MagicNumber['run_mode'] = 0
127 it '自身にゲスト用ロールチェックを問い合わせしている' do
128 Artist.any_instance.stub(:guest_role_check).and_return(true)
129 Artist.any_instance.should_receive(:guest_role_check).with(any_args).exactly(1)
130 r = @artist.visible?([@author])
132 it 'ゲスト用ロールチェックが失敗したとき、falseを返す' do
133 Artist.any_instance.stub(:guest_role_check).and_return(false)
134 r = @artist.visible?([@author])
138 context 'クローズドモードのとき' do
140 MagicNumber['run_mode'] = 1
142 it '自身に素材読者用ロールチェックを問い合わせしている' do
143 Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
144 Artist.any_instance.should_receive(:resource_reader_role_check).with(any_args).exactly(1)
145 r = @artist.visible?([@author])
147 it '素材読者用ロールチェックが失敗したとき、falseを返す' do
148 Artist.any_instance.stub(:resource_reader_role_check).and_return(false)
149 r = @artist.visible?([@author])
153 context 'つつがなく終わるとき' do
155 MagicNumber['run_mode'] = 1
156 Artist.any_instance.stub(:resource_reader_role_check).and_return(true)
159 r = @artist.visible?([@author])
165 describe '一覧取得に於いて' do
167 @artist = FactoryGirl.create :artist, :author_id => @author.id
169 context 'page補正について' do
170 it '文字列から数値に変換される' do
171 Artist.page('8').should eq 8
174 Artist.page().should eq 1
177 Artist.page('0').should eq 1
180 context 'page_size補正について' do
181 it '文字列から数値に変換される' do
182 Artist.page_size('7').should eq 7
184 it 'nilの場合はArtist.default_page_sizeになる' do
185 Artist.page_size().should eq Artist.default_page_size
187 it '0以下の場合はArtist.default_page_sizeになる' do
188 Artist.page_size('0').should eq Artist.default_page_size
190 it 'Artist.max_page_sizeを超えた場合はArtist.max_page_sizeになる' do
191 Artist.page_size('1000').should eq Artist.max_page_size
194 context 'つつがなく終わるとき' do
195 it '一覧取得オプションを利用している' do
196 Artist.stub(:list_opt).with(any_args).and_return({})
197 Artist.should_receive(:list_opt).with(any_args).exactly(1)
203 r.should eq [@artist]
206 n = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist', :created_at => Time.now + 100
208 l.should eq [n, @artist]
210 it 'ただし、内絵師(作家idが空)だけとする' do
211 n = FactoryGirl.create :artist, :author_id => nil
213 l.should eq [@artist]
215 context 'DBに5件あって1ページの件数を2件に変えたとして' do
217 @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
218 @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
219 @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
220 @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
221 Artist.stub(:default_page_size).and_return(2)
225 r.should have(2).items
227 it 'page=1なら末尾2件を返す' do
230 r.should eq [@artist5, @artist4]
232 it 'page=2なら中間2件を返す' do
234 r.should eq [@artist3, @artist2]
236 it 'page=3なら先頭1件を返す' do
238 r.should eq [@artist]
243 describe '一覧ページ制御に於いて' do
245 Artist.stub(:count).with(any_args).and_return(100)
248 r = Artist.list_paginate
249 r.is_a?(Kaminari::PaginatableArray).should be_true
251 it '一覧の取得条件を利用している' do
252 Artist.stub(:list_where).with(any_args).and_return('')
253 Artist.should_receive(:list_where).with(any_args).exactly(1)
254 r = Artist.list_paginate
256 it 'ページ件数10のとき、3ページ目のオフセットは20から始まる' do
257 r = Artist.list_paginate 3, 10
258 r.limit_value.should eq 10
259 r.offset_value.should eq 20
263 describe '一覧取得オプションに於いて' do
266 r.should have(1).items
270 r.has_key?(:author).should be_true
273 describe 'json一覧出力オプションに於いて' do
275 @artist = FactoryGirl.create :artist, :author_id => @author.id
278 r = Artist.list.to_json Artist.list_json_opt
281 i.has_key?('author').should be_true
285 describe '単体取得に於いて' do
287 @artist = FactoryGirl.create :artist, :author_id => @author.id
289 context 'つつがなく終わるとき' do
290 it '単体取得オプションを利用している' do
291 Artist.stub(:show_opt).with(any_args).and_return({})
292 Artist.should_receive(:show_opt).with(any_args).exactly(1)
293 r = Artist.show @artist.id, @author
295 it '閲覧許可を問い合わせている' do
296 Artist.any_instance.stub(:visible?).with(any_args).and_return(true)
297 Artist.any_instance.should_receive(:visible?).with(any_args).exactly(1)
298 r = Artist.show @artist.id, @author
302 a = Artist.show @artist.id, @author
305 context '閲覧許可が出なかったとき' do
306 it '403Forbidden例外を返す' do
307 Artist.any_instance.stub(:visible?).and_return(false)
309 Artist.show @artist.id, @author
310 }.should raise_error(ActiveRecord::Forbidden)
313 context '存在しない絵師を開こうとしたとき' do
314 it '404RecordNotFound例外を返す' do
316 Artist.show 110, @author
317 }.should raise_error(ActiveRecord::RecordNotFound)
321 describe '編集取得に於いて' do
323 @artist = FactoryGirl.create :artist, :author_id => @author.id
325 context 'つつがなく終わるとき' do
326 it '単体取得オプションを利用している' do
327 Artist.stub(:show_opt).with(any_args).and_return({})
328 Artist.should_receive(:show_opt).with(any_args).exactly(1)
329 r = Artist.edit @artist.id, @author
331 it '所持判定を問い合わせている' do
332 Artist.any_instance.stub(:own?).with(any_args).and_return(true)
333 Artist.any_instance.should_receive(:own?).with(any_args).exactly(1)
334 r = Artist.edit @artist.id, @author
338 Artist.any_instance.stub(:own?).and_return(true)
339 r = Artist.edit @artist.id, @author.id
342 context '他人の絵師を開こうとしたとき' do
343 it '403Forbidden例外を返す' do
344 Artist.any_instance.stub(:own?).and_return(false)
346 Artist.edit @artist.id, @author
347 }.should raise_error(ActiveRecord::Forbidden)
350 context '存在しない絵師を開こうとしたとき' do
351 it '404RecordNotFound例外を返す' do
353 Artist.edit 110, @author
354 }.should raise_error(ActiveRecord::RecordNotFound)
358 describe '単体取得オプションに於いて' do
359 it 'includeキーを含んでいる' do
361 r.has_key?(:include).should be_true
364 r = Artist.show_opt[:include]
365 r.should have(1).items
368 describe 'json単体出力オプションに於いて' do
370 @artist = FactoryGirl.create :artist, :author_id => @author.id
373 r = Artist.show(@artist.id, @author).to_json Artist.show_json_opt
376 i.has_key?('author').should be_true
380 describe '有効絵師数に於いて' do
382 @artist = FactoryGirl.create :artist, :author_id => @author.id
383 @artist = FactoryGirl.create :artist, :author_id => @other_author.id
384 @artist = FactoryGirl.create :artist, :author_id => nil
387 r = Artist.visible_count
392 describe 'エクスポートに於いて' do
394 @artist = FactoryGirl.create :artist, :author_id => @author.id
395 @artist2 = FactoryGirl.create :artist, :author_id => @other_author.id, :updated_at => Time.now - 3000
396 @artist3 = FactoryGirl.create :artist, :author_id => nil
398 it '開始日時が省略された場合はすべての内絵師を返す' do
400 r.should eq [@artist, @artist2]
402 it '開始日時以降に更新された内絵師を返す' do
403 r = Artist.export @artist.updated_at - 100
404 r.should eq [@artist]