1 # -*- encoding: utf-8 -*-
7 @license = Factory :license
8 @user = Factory( :user_yas)
10 @artist = Factory :artist_yas, :author_id => @author.id
17 it 'オーソドックスなデータなら通る' do
18 @comic = Factory.build :comic, :author_id => @author.id
19 @comic.should be_valid
22 context 'titleを検証するとき' do
24 @comic = Factory.build :comic, :author_id => @author.id, :title => nil
25 @comic.should_not be_valid
28 @comic = Factory.build :comic, :author_id => @author.id, :title => 'a'*101
29 @comic.should_not be_valid
32 context 'widthを検証するとき' do
34 @comic = Factory.build :comic, :author_id => @author.id, :width => nil
35 @comic.should_not be_valid
38 @comic = Factory.build :comic, :author_id => @author.id, :width => 0
39 @comic.should_not be_valid
42 @comic = Factory.build :comic, :author_id => @author.id, :width => -1
43 @comic.should_not be_valid
46 @comic = Factory.build :comic, :author_id => @author.id, :width => 1
47 @comic.should be_valid
50 context 'heightを検証するとき' do
52 @comic = Factory.build :comic, :author_id => @author.id, :height => nil
53 @comic.should_not be_valid
56 @comic = Factory.build :comic, :author_id => @author.id, :height => 0
57 @comic.should_not be_valid
60 @comic = Factory.build :comic, :author_id => @author.id, :height => -1
61 @comic.should_not be_valid
64 @comic = Factory.build :comic, :author_id => @author.id, :height => 1
65 @comic.should be_valid
68 context 'visibleを検証するとき' do
70 @comic = Factory.build :comic, :author_id => @author.id, :visible => nil
71 @comic.should_not be_valid
74 @comic = Factory.build :comic, :author_id => @author.id, :visible => -1
75 @comic.should_not be_valid
78 @comic = Factory.build :comic, :author_id => @author.id, :visible => 4
79 @comic.should_not be_valid
84 describe 'データ補充に於いて' do
89 context '初期値を補充するとき' do
92 @comic.visible.should == 0
94 it 'visibleが空でないなら変化なし' do
96 lambda{@comic.supply_default}.should_not change(@comic, :visible)
101 describe '作者判定に於いて' do
105 comic = Factory :comic, :author_id => @author.id
106 comic.own?(@author).should == true
109 comic = Factory :comic, :author_id => 0
110 comic.own?(@author).should == false
113 comic = Factory :comic, :author_id => @author.id
114 comic.own?(nil).should == false
117 describe '閲覧許可に於いて' do
120 it '自作の公開コミックを見るときは許可する' do
121 Comic.any_instance.stub(:own?).and_return(true)
122 comic = Factory :comic, :author_id => @author.id, :visible => 3
123 comic.visible?(@author).should == true
125 it '自作のコミックは非公開でも許可する' do
126 Comic.any_instance.stub(:own?).and_return(true)
127 comic = Factory :comic, :author_id => @author.id, :visible => 0
128 comic.visible?(@author).should == true
130 it '他人のコミックでも公開コミックなら許可する' do
131 Comic.any_instance.stub(:own?).and_return(false)
132 comic = Factory :comic, :author_id => 0, :visible => 3
133 comic.visible?(@author).should == true
135 it '他人のコミックで非公開コミックなら許可しない' do
136 Comic.any_instance.stub(:own?).and_return(false)
137 comic = Factory :comic, :author_id => 0, :visible => 0
138 comic.visible?(@author).should == false
141 describe '単体取得に於いて' do
143 @comic = Factory :comic, :author_id => @author.id
146 c = Comic.show @comic.id, @author.id
150 describe '関連テーブルプションに於いて' do
151 context 'オプションがないとき' do
153 r = Comic.show_include_opt
154 r.should have(2).items
157 r = Comic.show_include_opt
158 r.has_key?(:author).should be_true
161 r = Comic.show_include_opt
162 r.has_key?(:stories).should be_true
164 it 'ストーリーはコマを含んでいる' do
165 r = Comic.show_include_opt
166 r[:stories].has_key?(:panel).should be_true
170 describe 'json単体出力オプションに於いて' do
171 it 'includeキーを含んでいる' do
172 r = Comic.show_json_include_opt
173 r.has_key?(:include).should be_true
176 r = Comic.show_json_include_opt[:include]
177 r.should have(2).items
180 r = Comic.show_json_include_opt[:include]
181 r.has_key?(:author).should be_true
184 r = Comic.show_json_include_opt[:include]
185 r.has_key?(:stories).should be_true
187 it 'ストーリーはコマを含んでいる' do
188 r = Comic.show_json_include_opt[:include]
189 r[:stories].has_key?(:panel).should be_true
192 describe '一覧取得に於いて' do
194 @comic = Factory :comic, :author_id => @author.id
196 context 'page補正について' do
197 it '文字列から数値に変換される' do
198 Comic.page('8').should eq 8
201 Comic.page().should eq 1
204 Comic.page('0').should eq 1
207 context 'page_size補正について' do
208 it '文字列から数値に変換される' do
209 Comic.page_size('7').should eq 7
211 it 'nilの場合はComic.default_page_sizeになる' do
212 Comic.page_size().should eq Comic.default_page_size
214 it '0以下の場合はComic.default_page_sizeになる' do
215 Comic.page_size('0').should eq Comic.default_page_size
217 it 'Comic.max_page_sizeを超えた場合はComic.max_page_sizeになる' do
218 Comic.page_size('1000').should eq Comic.max_page_size
225 it '非公開コミックは(自分のコミックであっても)含んでいない' do
226 Factory :comic, :author_id => @author.id, :visible => 0
231 v = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 100
233 c.should eq [v, @comic]
235 context 'DBに5件あって1ページの件数を2件に変えたとして' do
237 @comic2 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 100
238 @comic3 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 200
239 @comic4 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 300
240 @comic5 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 400
241 Comic.stub(:default_page_size).and_return(2)
245 c.should have(2).items
247 it 'page=1なら末尾2件を返す' do
249 c = Comic.list({}, 1)
250 c.should eq [@comic5, @comic4]
252 it 'page=2なら中間2件を返す' do
253 c = Comic.list({}, 2)
254 c.should eq [@comic3, @comic2]
256 it 'page=3なら先頭1件を返す' do
257 c = Comic.list({}, 3)
262 describe 'list関連テーブルプションに於いて' do
263 it 'includeキーを含んでいる' do
265 r.has_key?(:include).should be_true
268 r = Comic.list_opt[:include]
269 r.should have(2).items
272 r = Comic.list_opt[:include]
273 r.has_key?(:stories).should be_true
275 it 'ストーリーはコマを含んでいる' do
276 r = Comic.list_opt[:include]
277 r[:stories].has_key?(:panel).should be_true
280 r = Comic.list_opt[:include]
281 r.has_key?(:author).should be_true
284 describe 'json一覧出力オプションに於いて' do
285 it 'includeキーを含んでいる' do
286 r = Comic.list_json_opt
287 r.has_key?(:include).should be_true
290 r = Comic.list_json_opt[:include]
291 r.should have(2).items
294 r = Comic.list_json_opt[:include]
295 r.has_key?(:stories).should be_true
297 it 'ストーリーはコマを含んでいる' do
298 r = Comic.list_json_opt[:include]
299 r[:stories].has_key?(:panel).should be_true
302 r = Comic.list_json_opt[:include]
303 r.has_key?(:author).should be_true