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
23 it 'オーソドックスなデータなら通る' do
24 @comic = FactoryGirl.build :comic, :author_id => @author.id
25 @comic.should be_valid
28 context 'titleを検証するとき' do
30 @comic = FactoryGirl.build :comic, :author_id => @author.id, :title => nil
31 @comic.should_not be_valid
34 @comic = FactoryGirl.build :comic, :author_id => @author.id, :title => 'a'*101
35 @comic.should_not be_valid
38 context 'visibleを検証するとき' do
40 @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => nil
41 @comic.should_not be_valid
44 @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => -1
45 @comic.should_not be_valid
48 @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => 4
49 @comic.should_not be_valid
54 describe 'データ補充に於いて' do
59 context '初期値を補充するとき' do
62 @comic.visible.should == 0
64 it 'visibleが空でないなら変化なし' do
66 lambda{@comic.supply_default}.should_not change(@comic, :visible)
71 describe '作者判定に於いて' do
75 comic = FactoryGirl.create :comic, :author_id => @author.id
76 comic.own?(@author).should == true
79 comic = FactoryGirl.create :comic, :author_id => 0
80 comic.own?(@author).should == false
83 comic = FactoryGirl.create :comic, :author_id => @author.id
84 comic.own?(nil).should == false
87 describe '閲覧許可に於いて' do
90 it '自作の公開コミックを見るときは許可する' do
91 Comic.any_instance.stub(:own?).and_return(true)
92 comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 3
93 comic.visible?(@author).should == true
95 it '自作のコミックは非公開でも許可する' do
96 Comic.any_instance.stub(:own?).and_return(true)
97 comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
98 comic.visible?(@author).should == true
100 it '他人のコミックでも公開コミックなら許可する' do
101 Comic.any_instance.stub(:own?).and_return(false)
102 comic = FactoryGirl.create :comic, :author_id => 0, :visible => 3
103 comic.visible?(@author).should == true
105 it '他人のコミックで非公開コミックなら許可しない' do
106 Comic.any_instance.stub(:own?).and_return(false)
107 comic = FactoryGirl.create :comic, :author_id => 0, :visible => 0
108 comic.visible?(@author).should == false
111 describe '単体取得に於いて' do
113 @comic = FactoryGirl.create :comic, :author_id => @author.id
116 c = Comic.show @comic.id, @author.id
120 describe '編集取得に於いて' do
122 @comic = FactoryGirl.create :comic, :author_id => @author.id
125 Comic.any_instance.stub(:own?).and_return(true)
126 c = Comic.edit @comic.id, @author.id
129 context '他人のコミックを開こうとしたとき' do
130 it '403Forbidden例外を返す' do
131 Comic.any_instance.stub(:own?).and_return(false)
133 Comic.edit @comic.id, @author
134 }.should raise_error(ActiveRecord::Forbidden)
137 context '存在しないコミックを開こうとしたとき' do
138 it '404RecordNotFound例外を返す' do
140 Comic.edit 110, @author
141 }.should raise_error(ActiveRecord::RecordNotFound)
145 describe '関連テーブルプションに於いて' do
146 context 'オプションがないとき' do
148 r = Comic.show_include_opt
149 r.should have(2).items
152 r = Comic.show_include_opt
153 r.has_key?(:author).should be_true
156 r = Comic.show_include_opt
157 r.has_key?(:stories).should be_true
159 it 'ストーリーはコマを含んでいる' do
160 r = Comic.show_include_opt
161 r[:stories].has_key?(:panel).should be_true
165 describe 'json単体出力オプションに於いて' do
166 it 'includeキーを含んでいる' do
167 r = Comic.show_json_include_opt
168 r.has_key?(:include).should be_true
171 r = Comic.show_json_include_opt[:include]
172 r.should have(2).items
175 r = Comic.show_json_include_opt[:include]
176 r.has_key?(:author).should be_true
179 r = Comic.show_json_include_opt[:include]
180 r.has_key?(:stories).should be_true
182 it 'ストーリーはコマを含んでいる' do
183 r = Comic.show_json_include_opt[:include]
184 r[:stories].has_key?(:panel).should be_true
187 describe '一覧取得に於いて' do
189 @comic = FactoryGirl.create :comic, :author_id => @author.id
191 context 'page補正について' do
192 it '文字列から数値に変換される' do
193 Comic.page('8').should eq 8
196 Comic.page().should eq 1
199 Comic.page('0').should eq 1
202 context 'page_size補正について' do
203 it '文字列から数値に変換される' do
204 Comic.page_size('7').should eq 7
206 it 'nilの場合はComic.default_page_sizeになる' do
207 Comic.page_size().should eq Comic.default_page_size
209 it '0以下の場合はComic.default_page_sizeになる' do
210 Comic.page_size('0').should eq Comic.default_page_size
212 it 'Comic.max_page_sizeを超えた場合はComic.max_page_sizeになる' do
213 Comic.page_size('1000').should eq Comic.max_page_size
220 it '非公開コミックは(自分のコミックであっても)含んでいない' do
221 FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
226 v = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
228 c.should eq [v, @comic]
230 context 'DBに5件あって1ページの件数を2件に変えたとして' do
232 @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
233 @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
234 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
235 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
236 Comic.stub(:default_page_size).and_return(2)
240 c.should have(2).items
242 it 'page=1なら末尾2件を返す' do
244 c = Comic.list({}, 1)
245 c.should eq [@comic5, @comic4]
247 it 'page=2なら中間2件を返す' do
248 c = Comic.list({}, 2)
249 c.should eq [@comic3, @comic2]
251 it 'page=3なら先頭1件を返す' do
252 c = Comic.list({}, 3)
257 describe 'list関連テーブルプションに於いて' do
258 it 'includeキーを含んでいる' do
260 r.has_key?(:include).should be_true
263 r = Comic.list_opt[:include]
264 r.should have(2).items
267 r = Comic.list_opt[:include]
268 r.has_key?(:stories).should be_true
270 it 'ストーリーはコマを含んでいる' do
271 r = Comic.list_opt[:include]
272 r[:stories].has_key?(:panel).should be_true
275 r = Comic.list_opt[:include]
276 r.has_key?(:author).should be_true
279 describe 'json一覧出力オプションに於いて' do
280 it 'includeキーを含んでいる' do
281 r = Comic.list_json_opt
282 r.has_key?(:include).should be_true
285 r = Comic.list_json_opt[:include]
286 r.should have(2).items
289 r = Comic.list_json_opt[:include]
290 r.has_key?(:stories).should be_true
292 it 'ストーリーはコマを含んでいる' do
293 r = Comic.list_json_opt[:include]
294 r[:stories].has_key?(:panel).should be_true
297 r = Comic.list_json_opt[:include]
298 r.has_key?(:author).should be_true
302 describe '自分のコミック一覧取得に於いて' do
304 @comic = FactoryGirl.create :comic, :author_id => @author.id
307 c = Comic.mylist @author
311 nc = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
312 cl = Comic.mylist @author
313 cl.should eq [nc, @comic]
315 it '他人のコミックは公開でも含まない' do
316 nc = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
317 cl = Comic.mylist @author
318 cl.should eq [@comic]
320 it '自分のコミックは非公開でも含んでいる' do
321 nc = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
322 cl = Comic.mylist @author
323 cl.should eq [nc, @comic]