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 '一覧取得オプションに於いて' 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
239 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
240 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
241 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
242 @sbt = FactoryGirl.create :speech_balloon_template
\r
243 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
244 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
245 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
248 r = Comic.list.to_json Comic.list_json_opt
251 i.has_key?('stories').should be_true
253 it 'ストーリーはコマを含んでいる' do
254 r = Comic.list.to_json Comic.list_json_opt
257 s = i['stories'].first
258 s.has_key?('panel').should be_true
261 r = Comic.list.to_json Comic.list_json_opt
264 i.has_key?('author').should be_true
268 describe '自分のコミック一覧取得に於いて' do
270 @comic = FactoryGirl.create :comic, :author_id => @author.id
272 context 'つつがなく終わるとき' do
\r
273 it '一覧取得オプションを利用している' do
\r
274 Comic.stub(:list_opt).with(any_args).and_return({})
\r
275 Comic.should_receive(:list_opt).with(any_args).exactly(1)
\r
276 r = Comic.mylist @author
280 c = Comic.mylist @author
284 nc = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
285 cl = Comic.mylist @author
286 cl.should eq [nc, @comic]
288 it '他人のコミックは公開でも含まない' do
289 nc = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
290 cl = Comic.mylist @author
291 cl.should eq [@comic]
293 it '自分のコミックは非公開でも含んでいる' do
294 nc = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
295 cl = Comic.mylist @author
296 cl.should eq [nc, @comic]
298 context 'DBに5件あって1ページの件数を2件に変えたとして' do
300 @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
301 @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
302 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
303 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
306 c = Comic.mylist @author, 1, 2
307 c.should have(2).items
309 it 'page=1なら末尾2件を返す' do
311 c = Comic.mylist(@author, 1, 2)
312 c.should eq [@comic5, @comic4]
314 it 'page=2なら中間2件を返す' do
315 c = Comic.mylist(@author, 2, 2)
316 c.should eq [@comic3, @comic2]
318 it 'page=3なら先頭1件を返す' do
319 c = Comic.mylist(@author, 3, 2)
323 context 'DBに5件あって1ページの件数を0件に変えたとして' do
325 @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
326 @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
327 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
328 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
329 Author.stub(:default_comic_page_size).and_return(2)
\r
332 r = Comic.mylist @author, 5, 0
333 r.should have(5).items
338 describe '単体取得に於いて' do
340 @comic = FactoryGirl.create :comic, :author_id => @author.id
342 context 'つつがなく終わるとき' do
\r
343 it '単体取得オプションを利用している' do
\r
344 Comic.stub(:show_opt).with(any_args).and_return({})
\r
345 Comic.should_receive(:show_opt).with(any_args).exactly(1)
\r
346 r = Comic.show @comic.id, @author
348 it '閲覧許可を問い合わせている' do
\r
349 Comic.any_instance.stub(:visible?).with(any_args).and_return(true)
\r
350 Comic.any_instance.should_receive(:visible?).with(any_args).exactly(1)
\r
351 r = Comic.show @comic.id, @author
355 c = Comic.show @comic.id, @author.id
358 context '閲覧許可が出なかったとき' do
\r
359 it '403Forbidden例外を返す' do
\r
360 Comic.any_instance.stub(:visible?).and_return(false)
\r
362 Comic.show @comic.id, @author
\r
363 }.should raise_error(ActiveRecord::Forbidden)
\r
366 context '存在しない作家を開こうとしたとき' do
\r
367 it '404RecordNotFound例外を返す' do
\r
369 Comic.show 110, @author
\r
370 }.should raise_error(ActiveRecord::RecordNotFound)
\r
375 describe '編集取得に於いて' do
377 @comic = FactoryGirl.create :comic, :author_id => @author.id
379 context 'つつがなく終わるとき' do
\r
380 it '単体取得オプションを利用している' do
\r
381 Comic.stub(:show_opt).with(any_args).and_return({})
\r
382 Comic.should_receive(:show_opt).with(any_args).exactly(1)
\r
383 r = Comic.edit @comic.id, @author
385 it '所持判定を問い合わせている' do
\r
386 Comic.any_instance.stub(:own?).with(any_args).and_return(true)
\r
387 Comic.any_instance.should_receive(:own?).with(any_args).exactly(1)
\r
388 r = Comic.edit @comic.id, @author
392 Comic.any_instance.stub(:own?).and_return(true)
393 c = Comic.edit @comic.id, @author.id
396 context '他人のコミックを開こうとしたとき' do
397 it '403Forbidden例外を返す' do
398 Comic.any_instance.stub(:own?).and_return(false)
400 Comic.edit @comic.id, @author
401 }.should raise_error(ActiveRecord::Forbidden)
404 context '存在しないコミックを開こうとしたとき' do
405 it '404RecordNotFound例外を返す' do
407 Comic.edit 110, @author
408 }.should raise_error(ActiveRecord::RecordNotFound)
412 describe '単体取得オプションに於いて' do
413 it 'includeキーを含んでいる' do
415 r.has_key?(:include).should be_true
418 r = Comic.show_opt[:include]
419 r.should have(2).items
422 r = Comic.show_opt[:include]
423 r.has_key?(:author).should be_true
426 r = Comic.show_opt[:include]
427 r.has_key?(:stories).should be_true
429 it 'ストーリーはコマを含んでいる' do
430 r = Comic.show_opt[:include]
431 r[:stories].has_key?(:panel).should be_true
434 describe 'json単体出力オプションに於いて' do
436 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
437 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
438 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
439 @sbt = FactoryGirl.create :speech_balloon_template
\r
440 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
441 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
442 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
445 r = Comic.show(@comic.id, @author).to_json Comic.show_json_opt
448 i.has_key?('stories').should be_true
450 it 'ストーリーはコマを含んでいる' do
451 r = Comic.show(@comic.id, @author).to_json Comic.show_json_opt
454 s = i['stories'].first
455 s.has_key?('panel').should be_true
458 r = Comic.show(@comic.id, @author).to_json Comic.show_json_opt
461 i.has_key?('author').should be_true