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 'widthを検証するとき' do
40 @comic = FactoryGirl.build :comic, :author_id => @author.id, :width => nil
41 @comic.should_not be_valid
44 @comic = FactoryGirl.build :comic, :author_id => @author.id, :width => 0
45 @comic.should_not be_valid
48 @comic = FactoryGirl.build :comic, :author_id => @author.id, :width => -1
49 @comic.should_not be_valid
52 @comic = FactoryGirl.build :comic, :author_id => @author.id, :width => 1
53 @comic.should be_valid
56 context 'heightを検証するとき' do
58 @comic = FactoryGirl.build :comic, :author_id => @author.id, :height => nil
59 @comic.should_not be_valid
62 @comic = FactoryGirl.build :comic, :author_id => @author.id, :height => 0
63 @comic.should_not be_valid
66 @comic = FactoryGirl.build :comic, :author_id => @author.id, :height => -1
67 @comic.should_not be_valid
70 @comic = FactoryGirl.build :comic, :author_id => @author.id, :height => 1
71 @comic.should be_valid
74 context 'visibleを検証するとき' do
76 @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => nil
77 @comic.should_not be_valid
80 @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => -1
81 @comic.should_not be_valid
84 @comic = FactoryGirl.build :comic, :author_id => @author.id, :visible => 4
85 @comic.should_not be_valid
90 describe 'データ補充に於いて' do
95 context '初期値を補充するとき' do
98 @comic.visible.should == 0
100 it 'visibleが空でないなら変化なし' do
102 lambda{@comic.supply_default}.should_not change(@comic, :visible)
107 describe '作者判定に於いて' do
111 comic = FactoryGirl.create :comic, :author_id => @author.id
112 comic.own?(@author).should == true
115 comic = FactoryGirl.create :comic, :author_id => 0
116 comic.own?(@author).should == false
119 comic = FactoryGirl.create :comic, :author_id => @author.id
120 comic.own?(nil).should == false
123 describe '閲覧許可に於いて' do
126 it '自作の公開コミックを見るときは許可する' do
127 Comic.any_instance.stub(:own?).and_return(true)
128 comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 3
129 comic.visible?(@author).should == true
131 it '自作のコミックは非公開でも許可する' do
132 Comic.any_instance.stub(:own?).and_return(true)
133 comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
134 comic.visible?(@author).should == true
136 it '他人のコミックでも公開コミックなら許可する' do
137 Comic.any_instance.stub(:own?).and_return(false)
138 comic = FactoryGirl.create :comic, :author_id => 0, :visible => 3
139 comic.visible?(@author).should == true
141 it '他人のコミックで非公開コミックなら許可しない' do
142 Comic.any_instance.stub(:own?).and_return(false)
143 comic = FactoryGirl.create :comic, :author_id => 0, :visible => 0
144 comic.visible?(@author).should == false
147 describe '単体取得に於いて' do
149 @comic = FactoryGirl.create :comic, :author_id => @author.id
152 c = Comic.show @comic.id, @author.id
156 describe '関連テーブルプションに於いて' do
157 context 'オプションがないとき' do
159 r = Comic.show_include_opt
160 r.should have(2).items
163 r = Comic.show_include_opt
164 r.has_key?(:author).should be_true
167 r = Comic.show_include_opt
168 r.has_key?(:stories).should be_true
170 it 'ストーリーはコマを含んでいる' do
171 r = Comic.show_include_opt
172 r[:stories].has_key?(:panel).should be_true
176 describe 'json単体出力オプションに於いて' do
177 it 'includeキーを含んでいる' do
178 r = Comic.show_json_include_opt
179 r.has_key?(:include).should be_true
182 r = Comic.show_json_include_opt[:include]
183 r.should have(2).items
186 r = Comic.show_json_include_opt[:include]
187 r.has_key?(:author).should be_true
190 r = Comic.show_json_include_opt[:include]
191 r.has_key?(:stories).should be_true
193 it 'ストーリーはコマを含んでいる' do
194 r = Comic.show_json_include_opt[:include]
195 r[:stories].has_key?(:panel).should be_true
198 describe '一覧取得に於いて' do
200 @comic = FactoryGirl.create :comic, :author_id => @author.id
202 context 'page補正について' do
203 it '文字列から数値に変換される' do
204 Comic.page('8').should eq 8
207 Comic.page().should eq 1
210 Comic.page('0').should eq 1
213 context 'page_size補正について' do
214 it '文字列から数値に変換される' do
215 Comic.page_size('7').should eq 7
217 it 'nilの場合はComic.default_page_sizeになる' do
218 Comic.page_size().should eq Comic.default_page_size
220 it '0以下の場合はComic.default_page_sizeになる' do
221 Comic.page_size('0').should eq Comic.default_page_size
223 it 'Comic.max_page_sizeを超えた場合はComic.max_page_sizeになる' do
224 Comic.page_size('1000').should eq Comic.max_page_size
231 it '非公開コミックは(自分のコミックであっても)含んでいない' do
232 FactoryGirl.create :comic, :author_id => @author.id, :visible => 0
237 v = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
239 c.should eq [v, @comic]
241 context 'DBに5件あって1ページの件数を2件に変えたとして' do
243 @comic2 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
244 @comic3 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 200
245 @comic4 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 300
246 @comic5 = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 400
247 Comic.stub(:default_page_size).and_return(2)
251 c.should have(2).items
253 it 'page=1なら末尾2件を返す' do
255 c = Comic.list({}, 1)
256 c.should eq [@comic5, @comic4]
258 it 'page=2なら中間2件を返す' do
259 c = Comic.list({}, 2)
260 c.should eq [@comic3, @comic2]
262 it 'page=3なら先頭1件を返す' do
263 c = Comic.list({}, 3)
268 describe 'list関連テーブルプションに於いて' do
269 it 'includeキーを含んでいる' do
271 r.has_key?(:include).should be_true
274 r = Comic.list_opt[:include]
275 r.should have(2).items
278 r = Comic.list_opt[:include]
279 r.has_key?(:stories).should be_true
281 it 'ストーリーはコマを含んでいる' do
282 r = Comic.list_opt[:include]
283 r[:stories].has_key?(:panel).should be_true
286 r = Comic.list_opt[:include]
287 r.has_key?(:author).should be_true
290 describe 'json一覧出力オプションに於いて' do
291 it 'includeキーを含んでいる' do
292 r = Comic.list_json_opt
293 r.has_key?(:include).should be_true
296 r = Comic.list_json_opt[:include]
297 r.should have(2).items
300 r = Comic.list_json_opt[:include]
301 r.has_key?(:stories).should be_true
303 it 'ストーリーはコマを含んでいる' do
304 r = Comic.list_json_opt[:include]
305 r[:stories].has_key?(:panel).should be_true
308 r = Comic.list_json_opt[:include]
309 r.has_key?(:author).should be_true
313 describe '自分のコミック一覧取得に於いて' do
315 @comic = FactoryGirl.create :comic, :author_id => @author.id
318 c = Comic.mylist @author
322 nc = FactoryGirl.create :comic, :author_id => @author.id, :updated_at => Time.now + 100
323 cl = Comic.mylist @author
324 cl.should eq [nc, @comic]
326 it '他人のコミックは公開でも含まない' do
327 nc = FactoryGirl.create :comic, :author_id => @other_author.id, :visible => 1
328 cl = Comic.mylist @author
329 cl.should eq [@comic]
331 it '自分のコミックは非公開でも含んでいる' do
332 nc = FactoryGirl.create :comic, :author_id => @author.id, :visible => 0, :updated_at => Time.now + 100
333 cl = Comic.mylist @author
334 cl.should eq [nc, @comic]