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 @artist.own?(@author).should == true
77 @artist.own?(@other_author).should == false
79 it 'パラメータが作家でないならならno' do
80 @artist.own?(nil).should == false
84 describe '閲覧許可に於いて' do
86 @artist = FactoryGirl.create :artist, :author_id => @author.id
88 context '検査対象がnil(ゲスト)のとき' do
89 context 'クローズドモードのとき' do
91 MagicNumber['run_mode'] = 1
94 r = @artist.visible?(nil)
98 context 'オープンモードのとき' do
100 MagicNumber['run_mode'] = 0
103 r = @artist.visible?(nil)
108 context '検査対象が作家のとき' do
110 r = @artist.visible?(@author)
114 context '検査対象がそれ以外のとき' do
116 r = @artist.visible?(@admin)
122 describe '一覧取得に於いて' do
124 @artist = FactoryGirl.create :artist, :author_id => @author.id
126 context 'page補正について' do
127 it '文字列から数値に変換される' do
128 Artist.page('8').should eq 8
131 Artist.page().should eq 1
134 Artist.page('0').should eq 1
137 context 'page_size補正について' do
138 it '文字列から数値に変換される' do
139 Artist.page_size('7').should eq 7
141 it 'nilの場合はArtist.default_page_sizeになる' do
142 Artist.page_size().should eq Artist.default_page_size
144 it '0以下の場合はArtist.default_page_sizeになる' do
145 Artist.page_size('0').should eq Artist.default_page_size
147 it 'Artist.max_page_sizeを超えた場合はArtist.max_page_sizeになる' do
148 Artist.page_size('1000').should eq Artist.max_page_size
151 context 'つつがなく終わるとき' do
152 it '一覧取得オプションを利用している' do
153 Artist.stub(:list_opt).with(any_args).and_return({})
154 Artist.should_receive(:list_opt).with(any_args).exactly(1)
160 r.should eq [@artist]
163 n = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist', :created_at => Time.now + 100
165 l.should eq [n, @artist]
167 it 'ただし、内絵師(作家idが空)だけとする' do
168 n = FactoryGirl.create :artist, :author_id => nil
170 l.should eq [@artist]
172 context 'DBに5件あって1ページの件数を2件に変えたとして' do
174 @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
175 @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
176 @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
177 @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
178 Artist.stub(:default_page_size).and_return(2)
182 r.should have(2).items
184 it 'page=1なら末尾2件を返す' do
187 r.should eq [@artist5, @artist4]
189 it 'page=2なら中間2件を返す' do
191 r.should eq [@artist3, @artist2]
193 it 'page=3なら先頭1件を返す' do
195 r.should eq [@artist]
198 context 'DBに5件あって1ページの件数を0件に変えたとして' do
200 @artist2 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist2', :created_at => Time.now + 100
201 @artist3 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist3', :created_at => Time.now + 200
202 @artist4 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist4', :created_at => Time.now + 300
203 @artist5 = FactoryGirl.create :artist, :author_id => @author.id, :name => 'artist5', :created_at => Time.now + 400
204 Artist.stub(:default_page_size).and_return(2)
208 r.should have(5).items
212 describe '一覧取得オプションに於いて' do
213 it 'includeキーを含んでいる' do
215 r.has_key?(:include).should be_true
218 r = Artist.list_opt[:include]
219 r.should have(1).items
222 r = Artist.list_opt[:include]
223 r.has_key?(:author).should be_true
226 describe 'json一覧出力オプションに於いて' do
228 @artist = FactoryGirl.create :artist, :author_id => @author.id
231 r = Artist.list.to_json Artist.list_json_opt
234 i.has_key?('author').should be_true
238 describe '単体取得に於いて' do
240 @artist = FactoryGirl.create :artist, :author_id => @author.id
242 context 'つつがなく終わるとき' do
243 it '単体取得オプションを利用している' do
244 Artist.stub(:show_opt).with(any_args).and_return({})
245 Artist.should_receive(:show_opt).with(any_args).exactly(1)
246 r = Artist.show @artist.id, @author
248 it '閲覧許可を問い合わせている' do
249 Artist.any_instance.stub(:visible?).with(any_args).and_return(true)
250 Artist.any_instance.should_receive(:visible?).with(any_args).exactly(1)
251 r = Artist.show @artist.id, @author
255 a = Artist.show @artist.id, @author
258 context '閲覧許可が出なかったとき' do
259 it '403Forbidden例外を返す' do
260 Artist.any_instance.stub(:visible?).and_return(false)
262 Artist.show @artist.id, @author
263 }.should raise_error(ActiveRecord::Forbidden)
266 context '存在しない絵師を開こうとしたとき' do
267 it '404RecordNotFound例外を返す' do
269 Artist.show 110, @author
270 }.should raise_error(ActiveRecord::RecordNotFound)
274 describe '編集取得に於いて' do
276 @artist = FactoryGirl.create :artist, :author_id => @author.id
278 context 'つつがなく終わるとき' do
279 it '単体取得オプションを利用している' do
280 Artist.stub(:show_opt).with(any_args).and_return({})
281 Artist.should_receive(:show_opt).with(any_args).exactly(1)
282 r = Artist.edit @artist.id, @author
284 it '所持判定を問い合わせている' do
285 Artist.any_instance.stub(:own?).with(any_args).and_return(true)
286 Artist.any_instance.should_receive(:own?).with(any_args).exactly(1)
287 r = Artist.edit @artist.id, @author
291 Artist.any_instance.stub(:own?).and_return(true)
292 r = Artist.edit @artist.id, @author.id
295 context '他人の絵師を開こうとしたとき' do
296 it '403Forbidden例外を返す' do
297 Artist.any_instance.stub(:own?).and_return(false)
299 Artist.edit @artist.id, @author
300 }.should raise_error(ActiveRecord::Forbidden)
303 context '存在しない絵師を開こうとしたとき' do
304 it '404RecordNotFound例外を返す' do
306 Artist.edit 110, @author
307 }.should raise_error(ActiveRecord::RecordNotFound)
311 describe '単体取得オプションに於いて' do
312 it 'includeキーを含んでいる' do
314 r.has_key?(:include).should be_true
317 r = Artist.show_opt[:include]
318 r.should have(1).items
321 describe 'json単体出力オプションに於いて' do
323 @artist = FactoryGirl.create :artist, :author_id => @author.id
326 r = Artist.show(@artist.id, @author).to_json Artist.show_json_opt
329 i.has_key?('author').should be_true
333 describe '有効絵師数に於いて' do
335 @artist = FactoryGirl.create :artist, :author_id => @author.id
336 @artist = FactoryGirl.create :artist, :author_id => @other_author.id
337 @artist = FactoryGirl.create :artist, :author_id => nil
340 r = Artist.visible_count