1 # -*- encoding: utf-8 -*-
7 FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
10 @other_user = FactoryGirl.create( :user_yas)
\r
11 @other_author = @other_user.author
\r
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
\r
74 @artist.own?(@author).should == true
77 @artist.own?(@other_author).should == false
80 @artist.own?(nil).should == false
84 describe '閲覧許可に於いて' do
86 @artist = FactoryGirl.create :artist, :author_id => @author.id
88 it '自分の絵師を見るときは許可する' do
\r
89 Artist.any_instance.stub(:own?).and_return(true)
\r
90 @artist.visible?(@author).should == true
93 Artist.any_instance.stub(:own?).and_return(false)
\r
94 @artist.visible?(@author).should == true
98 describe '一覧取得に於いて' do
100 @artist = FactoryGirl.create :artist, :author_id => @author.id
102 context 'page補正について' do
103 it '文字列から数値に変換される' do
104 Artist.page('8').should eq 8
107 Artist.page().should eq 1
110 Artist.page('0').should eq 1
113 context 'page_size補正について' do
114 it '文字列から数値に変換される' do
115 Artist.page_size('7').should eq 7
117 it 'nilの場合はArtist.default_page_sizeになる' do
118 Artist.page_size().should eq Artist.default_page_size
120 it '0以下の場合はArtist.default_page_sizeになる' do
121 Artist.page_size('0').should eq Artist.default_page_size
123 it 'Artist.max_page_sizeを超えた場合はArtist.max_page_sizeになる' do
124 Artist.page_size('1000').should eq Artist.max_page_size
127 context 'つつがなく終わるとき' do
\r
128 it '一覧取得オプションを利用している' do
\r
129 Artist.stub(:list_opt).with(any_args).and_return({})
\r
130 Artist.should_receive(:list_opt).with(any_args).exactly(1)
\r
136 r.should eq [@artist]
139 n = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist', :created_at => Time.now + 100
141 l.should eq [n, @artist]
143 context 'DBに5件あって1ページの件数を2件に変えたとして' do
145 @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
146 @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
147 @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
148 @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
149 Artist.stub(:default_page_size).and_return(2)
153 r.should have(2).items
155 it 'page=1なら末尾2件を返す' do
158 r.should eq [@artist5, @artist4]
160 it 'page=2なら中間2件を返す' do
162 r.should eq [@artist3, @artist2]
164 it 'page=3なら先頭1件を返す' do
166 r.should eq [@artist]
169 context 'DBに5件あって1ページの件数を0件に変えたとして' do
171 @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
172 @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
173 @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
174 @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
175 Artist.stub(:default_page_size).and_return(0)
179 r.should have(5).items
183 describe '一覧取得オプションに於いて' do
184 it 'includeキーを含んでいる' do
186 r.has_key?(:include).should be_true
189 r = Artist.list_opt[:include]
190 r.should have(4).items
193 r = Artist.list_opt[:include]
194 r.has_key?(:author).should be_true
197 r = Artist.list_opt[:include]
198 r.has_key?(:original_pictures).should be_true
201 r = Artist.list_opt[:include]
202 r.has_key?(:pictures).should be_true
205 r = Artist.list_opt[:include]
206 r.has_key?(:resource_pictures).should be_true
209 describe 'json一覧出力オプションに於いて' do
210 it 'includeキーを含んでいる' do
211 r = Artist.list_json_opt
212 r.has_key?(:include).should be_true
215 r = Artist.list_json_opt[:include]
216 r.should have(4).items
219 r = Artist.list_json_opt[:include]
220 r.has_key?(:author).should be_true
223 r = Artist.list_json_opt[:include]
224 r.has_key?(:original_pictures).should be_true
227 r = Artist.list_json_opt[:include]
228 r.has_key?(:pictures).should be_true
231 r = Artist.list_json_opt[:include]
232 r.has_key?(:resource_pictures).should be_true
236 describe '単体取得に於いて' do
238 @artist = FactoryGirl.create :artist, :author_id => @author.id
240 context 'つつがなく終わるとき' do
\r
241 it '単体取得オプションを利用している' do
\r
242 Artist.stub(:show_opt).with(any_args).and_return({})
\r
243 Artist.should_receive(:show_opt).with(any_args).exactly(1)
\r
244 r = Artist.show @artist.id, @author
246 it '閲覧許可を問い合わせている' do
\r
247 Artist.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
248 Artist.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
249 r = Artist.show @artist.id, @author
253 a = Artist.show @artist.id, @author
256 context '閲覧許可が出なかったとき' do
\r
257 it '403Forbidden例外を返す' do
\r
258 Artist.any_instance.stub(:visible?).and_return(false)
\r
260 Artist.show @artist.id, @author
\r
261 }.should raise_error(ActiveRecord::Forbidden)
\r
264 context '存在しない絵師を開こうとしたとき' do
\r
265 it '404RecordNotFound例外を返す' do
\r
267 Artist.show 110, @author
\r
268 }.should raise_error(ActiveRecord::RecordNotFound)
\r
272 describe '編集取得に於いて' do
274 @artist = FactoryGirl.create :artist, :author_id => @author.id
276 context 'つつがなく終わるとき' do
\r
277 it '単体取得オプションを利用している' do
\r
278 Artist.stub(:show_opt).with(any_args).and_return({})
\r
279 Artist.should_receive(:show_opt).with(any_args).exactly(1)
\r
280 r = Artist.edit @artist.id, @author
282 it '所持判定を問い合わせている' do
\r
283 Artist.any_instance.stub(:own?).with(any_args).and_return(true)
\r
284 Artist.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
285 r = Artist.edit @artist.id, @author
289 Artist.any_instance.stub(:own?).and_return(true)
290 r = Artist.edit @artist.id, @author.id
293 context '他人の絵師を開こうとしたとき' do
294 it '403Forbidden例外を返す' do
295 Artist.any_instance.stub(:own?).and_return(false)
297 Artist.edit @artist.id, @author
298 }.should raise_error(ActiveRecord::Forbidden)
301 context '存在しない絵師を開こうとしたとき' do
302 it '404RecordNotFound例外を返す' do
304 Artist.edit 110, @author
305 }.should raise_error(ActiveRecord::RecordNotFound)
309 describe '単体取得オプションに於いて' do
310 it 'includeキーを含んでいる' do
312 r.has_key?(:include).should be_true
315 r = Artist.show_opt[:include]
316 r.should have(4).items
319 r = Artist.show_opt[:include]
320 r.has_key?(:author).should be_true
323 r = Artist.show_opt[:include]
324 r.has_key?(:original_pictures).should be_true
327 r = Artist.show_opt[:include]
328 r.has_key?(:pictures).should be_true
331 r = Artist.show_opt[:include]
332 r.has_key?(:resource_pictures).should be_true
335 describe 'json単体出力オプションに於いて' do
336 it 'includeキーを含んでいる' do
337 r = Artist.show_json_opt
338 r.has_key?(:include).should be_true
341 r = Artist.show_json_opt[:include]
342 r.should have(4).items
345 r = Artist.show_json_opt[:include]
346 r.has_key?(:author).should be_true
349 r = Artist.show_json_opt[:include]
350 r.has_key?(:original_pictures).should be_true
353 r = Artist.show_json_opt[:include]
354 r.has_key?(:pictures).should be_true
357 r = Artist.show_json_opt[:include]
358 r.has_key?(:resource_pictures).should be_true