1 # -*- encoding: utf-8 -*-
7 FactoryGirl.create :admin
8 @sp = FactoryGirl.create :system_picture
9 @lg = FactoryGirl.create :license_group
10 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
11 @user = FactoryGirl.create( :user_yas)
12 @author = @user.author
13 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
14 @other_user = FactoryGirl.create( :user_yas)
15 @other_author = @other_user.author
16 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
21 @comic = FactoryGirl.build :comic, :author_id => @author.id
24 context 'オーソドックスなデータのとき' do
28 @comic.should be_valid
31 @comic.title = 'a'*100
33 @comic.should be_valid
37 context 'titleを検証するとき' do
40 @comic.should_not be_valid
43 @comic.title = 'a'*101
44 @comic.should_not be_valid
47 context 'visibleを検証するとき' do
50 @comic.should_not be_valid
54 @comic.should_not be_valid
58 @comic.should_not be_valid
63 describe 'デフォルト値補充に於いて' do
64 it 'visibleが0になっている' do
65 @comic = FactoryGirl.build :comic, :visible => nil
67 @comic.visible.should eq 0
71 describe '上書き補充に於いて' do
73 @comic = FactoryGirl.build :comic, :author_id => nil
74 @comic.overwrite @author
75 @comic.author_id.should eq @author.id
79 describe '所持判定に於いて' do
81 @comic = FactoryGirl.build :comic, :author_id => @author.id
84 @comic.own?(@author).should == true
87 @comic.own?(@other_author).should == false
90 @comic.own?(nil).should == false
94 describe '閲覧許可に於いて' do
96 @comic = FactoryGirl.build :comic, :author_id => @author.id
98 it '自分の公開コミックを見るときは許可する' do
\r
99 Comic.any_instance.stub(:own?).and_return(true)
\r
100 Comic.any_instance.stub(:visible).and_return(1)
\r
101 r = @comic.visible?(@author)
104 it '自分のコミックなら非公開でも許可する' do
\r
105 Comic.any_instance.stub(:own?).and_return(true)
\r
106 Comic.any_instance.stub(:visible).and_return(0)
\r
107 r = @comic.visible?(@author)
110 it '他人のコミックでも公開なら許可する' do
\r
111 Comic.any_instance.stub(:own?).and_return(false)
\r
112 Comic.any_instance.stub(:visible).and_return(1)
\r
113 r = @comic.visible?(@author)
116 it '他人のコミックで非公開なら許可しない' do
\r
117 Comic.any_instance.stub(:own?).and_return(false)
\r
118 Comic.any_instance.stub(:visible).and_return(0)
\r
119 r = @comic.visible?(@author)
124 describe '一覧取得に於いて' do
126 @comic = FactoryGirl.create :comic, :author_id => @author.id
128 context 'page補正について' do
129 it '文字列から数値に変換される' do
130 Comic.page('8').should eq 8
133 Comic.page().should eq 1
136 Comic.page('0').should eq 1
139 context 'page_size補正について' do
140 it '文字列から数値に変換される' do
141 Comic.page_size('7').should eq 7
143 it 'nilの場合はComic.default_page_sizeになる' do
144 Comic.page_size().should eq Comic.default_page_size
146 it '0以下の場合はComic.default_page_sizeになる' do
147 Comic.page_size('0').should eq Comic.default_page_size
149 it 'Comic.max_page_sizeを超えた場合はComic.max_page_sizeになる' do
150 Comic.page_size('1000').should eq Comic.max_page_size
153 context 'つつがなく終わるとき' do
\r
154 it '一覧取得オプションを利用している' do
\r
155 Comic.stub(:list_opt).with(any_args).and_return({})
\r
156 Comic.should_receive(:list_opt).with(any_args).exactly(1)
\r
164 it '非公開コミックは(自分のコミックであっても)含んでいない' do
165 FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
170 #公開コミックは(他人のコミックであっても)含んでいる
171 v = FactoryGirl.create :comic, :author_id => @other_author.id, :updated_at => Time.now + 100
173 c.should eq [v, @comic]
175 context 'DBに5件あって1ページの件数を2件に変えたとして' do
177 @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
178 @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
179 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
180 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
181 Comic.stub(:default_page_size).and_return(2)
185 c.should have(2).items
187 it 'page=1なら末尾2件を返す' do
190 c.should eq [@comic5, @comic4]
192 it 'page=2なら中間2件を返す' do
194 c.should eq [@comic3, @comic2]
196 it 'page=3なら先頭1件を返す' do
201 context 'DBに5件あって1ページの件数を2件に変えたとして' do
203 @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
204 @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
205 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
206 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
207 Comic.stub(:default_page_size).and_return(2)
209 it '件数0は全件(5件)を返す' do
211 r.should have(5).items
215 describe 'list関連テーブルプションに於いて' do
216 it 'includeキーを含んでいる' do
218 r.has_key?(:include).should be_true
221 r = Comic.list_opt[:include]
222 r.should have(2).items
225 r = Comic.list_opt[:include]
226 r.has_key?(:stories).should be_true
228 it 'ストーリーはコマを含んでいる' do
229 r = Comic.list_opt[:include]
230 r[:stories].has_key?(:panel).should be_true
233 r = Comic.list_opt[:include]
234 r.has_key?(:author).should be_true
237 describe 'json一覧出力オプションに於いて' do
238 it 'includeキーを含んでいる' do
239 r = Comic.list_json_opt
240 r.has_key?(:include).should be_true
243 r = Comic.list_json_opt[:include]
244 r.should have(2).items
247 r = Comic.list_json_opt[:include]
248 r.has_key?(:stories).should be_true
250 it 'ストーリーはコマを含んでいる' do
251 r = Comic.list_json_opt[:include]
252 r[:stories].has_key?(:panel).should be_true
255 r = Comic.list_json_opt[:include]
256 r.has_key?(:author).should be_true
260 describe '自分のコミック一覧取得に於いて' do
262 @comic = FactoryGirl.create :comic, :author_id => @author.id
264 context 'つつがなく終わるとき' do
\r
265 it '一覧取得オプションを利用している' do
\r
266 Comic.stub(:list_opt).with(any_args).and_return({})
\r
267 Comic.should_receive(:list_opt).with(any_args).exactly(1)
\r
268 r = Comic.mylist @author
272 c = Comic.mylist @author
276 nc = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
277 cl = Comic.mylist @author
278 cl.should eq [nc, @comic]
280 it '他人のコミックは公開でも含まない' do
281 nc = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
282 cl = Comic.mylist @author
283 cl.should eq [@comic]
285 it '自分のコミックは非公開でも含んでいる' do
286 nc = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
287 cl = Comic.mylist @author
288 cl.should eq [nc, @comic]
290 context 'DBに5件あって1ページの件数を2件に変えたとして' do
292 @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
293 @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
294 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
295 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
298 c = Comic.mylist @author, 1, 2
299 c.should have(2).items
301 it 'page=1なら末尾2件を返す' do
303 c = Comic.mylist(@author, 1, 2)
304 c.should eq [@comic5, @comic4]
306 it 'page=2なら中間2件を返す' do
307 c = Comic.mylist(@author, 2, 2)
308 c.should eq [@comic3, @comic2]
310 it 'page=3なら先頭1件を返す' do
311 c = Comic.mylist(@author, 3, 2)
315 context 'DBに5件あって1ページの件数を0件に変えたとして' do
317 @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
318 @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
319 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
320 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
321 Comic.stub(:default_page_size).and_return(2)
324 r = Comic.mylist @author, 5, 0
325 r.should have(5).items
330 describe '単体取得に於いて' do
332 @comic = FactoryGirl.create :comic, :author_id => @author.id
334 context 'つつがなく終わるとき' do
\r
335 it '単体取得オプションを利用している' do
\r
336 Comic.stub(:show_opt).with(any_args).and_return({})
\r
337 Comic.should_receive(:show_opt).with(any_args).exactly(1)
\r
338 r = Comic.show @comic.id, @author
340 it '閲覧許可を問い合わせている' do
\r
341 Comic.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
342 Comic.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
343 r = Comic.show @comic.id, @author
347 c = Comic.show @comic.id, @author.id
350 context '閲覧許可が出なかったとき' do
\r
351 it '403Forbidden例外を返す' do
\r
352 Comic.any_instance.stub(:visible?).and_return(false)
\r
354 Comic.show @comic.id, @author
\r
355 }.should raise_error(ActiveRecord::Forbidden)
\r
358 context '存在しない作家を開こうとしたとき' do
\r
359 it '404RecordNotFound例外を返す' do
\r
361 Comic.show 110, @author
\r
362 }.should raise_error(ActiveRecord::RecordNotFound)
\r
367 describe '編集取得に於いて' do
369 @comic = FactoryGirl.create :comic, :author_id => @author.id
371 context 'つつがなく終わるとき' do
\r
372 it '単体取得オプションを利用している' do
\r
373 Comic.stub(:show_opt).with(any_args).and_return({})
\r
374 Comic.should_receive(:show_opt).with(any_args).exactly(1)
\r
375 r = Comic.edit @comic.id, @author
377 it '所持判定を問い合わせている' do
\r
378 Comic.any_instance.stub(:own?).with(any_args).and_return(true)
\r
379 Comic.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
380 r = Comic.edit @comic.id, @author
384 Comic.any_instance.stub(:own?).and_return(true)
385 c = Comic.edit @comic.id, @author.id
388 context '他人のコミックを開こうとしたとき' do
389 it '403Forbidden例外を返す' do
390 Comic.any_instance.stub(:own?).and_return(false)
392 Comic.edit @comic.id, @author
393 }.should raise_error(ActiveRecord::Forbidden)
396 context '存在しないコミックを開こうとしたとき' do
397 it '404RecordNotFound例外を返す' do
399 Comic.edit 110, @author
400 }.should raise_error(ActiveRecord::RecordNotFound)
404 describe '関連テーブルプションに於いて' do
405 it 'includeキーを含んでいる' do
407 r.has_key?(:include).should be_true
410 r = Comic.show_opt[:include]
411 r.should have(2).items
414 r = Comic.show_opt[:include]
415 r.has_key?(:author).should be_true
418 r = Comic.show_opt[:include]
419 r.has_key?(:stories).should be_true
421 it 'ストーリーはコマを含んでいる' do
422 r = Comic.show_opt[:include]
423 r[:stories].has_key?(:panel).should be_true
426 describe 'json単体出力オプションに於いて' do
427 it 'includeキーを含んでいる' do
428 r = Comic.show_json_opt
429 r.has_key?(:include).should be_true
432 r = Comic.show_json_opt[:include]
433 r.should have(2).items
436 r = Comic.show_json_opt[:include]
437 r.has_key?(:author).should be_true
440 r = Comic.show_json_opt[:include]
441 r.has_key?(:stories).should be_true
443 it 'ストーリーはコマを含んでいる' do
444 r = Comic.show_json_opt[:include]
445 r[:stories].has_key?(:panel).should be_true