1 # -*- encoding: utf-8 -*-
7 @sp = Factory :system_picture
8 @lg = Factory :license_group
9 @license = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
10 @user = Factory( :user_yas)
11 @author = @user.author
12 @artist = Factory :artist_yas, :author_id => @author.id
19 it 'オーソドックスなデータなら通る' do
20 @comic = Factory.build :comic, :author_id => @author.id
21 @comic.should be_valid
24 context 'titleを検証するとき' do
26 @comic = Factory.build :comic, :author_id => @author.id, :title => nil
27 @comic.should_not be_valid
30 @comic = Factory.build :comic, :author_id => @author.id, :title => 'a'*101
31 @comic.should_not be_valid
34 context 'widthを検証するとき' do
36 @comic = Factory.build :comic, :author_id => @author.id, :width => nil
37 @comic.should_not be_valid
40 @comic = Factory.build :comic, :author_id => @author.id, :width => 0
41 @comic.should_not be_valid
44 @comic = Factory.build :comic, :author_id => @author.id, :width => -1
45 @comic.should_not be_valid
48 @comic = Factory.build :comic, :author_id => @author.id, :width => 1
49 @comic.should be_valid
52 context 'heightを検証するとき' do
54 @comic = Factory.build :comic, :author_id => @author.id, :height => nil
55 @comic.should_not be_valid
58 @comic = Factory.build :comic, :author_id => @author.id, :height => 0
59 @comic.should_not be_valid
62 @comic = Factory.build :comic, :author_id => @author.id, :height => -1
63 @comic.should_not be_valid
66 @comic = Factory.build :comic, :author_id => @author.id, :height => 1
67 @comic.should be_valid
70 context 'visibleを検証するとき' do
72 @comic = Factory.build :comic, :author_id => @author.id, :visible => nil
73 @comic.should_not be_valid
76 @comic = Factory.build :comic, :author_id => @author.id, :visible => -1
77 @comic.should_not be_valid
80 @comic = Factory.build :comic, :author_id => @author.id, :visible => 4
81 @comic.should_not be_valid
86 describe 'データ補充に於いて' do
91 context '初期値を補充するとき' do
94 @comic.visible.should == 0
96 it 'visibleが空でないなら変化なし' do
98 lambda{@comic.supply_default}.should_not change(@comic, :visible)
103 describe '作者判定に於いて' do
107 comic = Factory :comic, :author_id => @author.id
108 comic.own?(@author).should == true
111 comic = Factory :comic, :author_id => 0
112 comic.own?(@author).should == false
115 comic = Factory :comic, :author_id => @author.id
116 comic.own?(nil).should == false
119 describe '閲覧許可に於いて' do
122 it '自作の公開コミックを見るときは許可する' do
123 Comic.any_instance.stub(:own?).and_return(true)
124 comic = Factory :comic, :author_id => @author.id, :visible => 3
125 comic.visible?(@author).should == true
127 it '自作のコミックは非公開でも許可する' do
128 Comic.any_instance.stub(:own?).and_return(true)
129 comic = Factory :comic, :author_id => @author.id, :visible => 0
130 comic.visible?(@author).should == true
132 it '他人のコミックでも公開コミックなら許可する' do
133 Comic.any_instance.stub(:own?).and_return(false)
134 comic = Factory :comic, :author_id => 0, :visible => 3
135 comic.visible?(@author).should == true
137 it '他人のコミックで非公開コミックなら許可しない' do
138 Comic.any_instance.stub(:own?).and_return(false)
139 comic = Factory :comic, :author_id => 0, :visible => 0
140 comic.visible?(@author).should == false
143 describe '単体取得に於いて' do
145 @comic = Factory :comic, :author_id => @author.id
148 c = Comic.show @comic.id, @author.id
152 describe '関連テーブルプションに於いて' do
153 context 'オプションがないとき' do
155 r = Comic.show_include_opt
156 r.should have(2).items
159 r = Comic.show_include_opt
160 r.has_key?(:author).should be_true
163 r = Comic.show_include_opt
164 r.has_key?(:stories).should be_true
166 it 'ストーリーはコマを含んでいる' do
167 r = Comic.show_include_opt
168 r[:stories].has_key?(:panel).should be_true
172 describe 'json単体出力オプションに於いて' do
173 it 'includeキーを含んでいる' do
174 r = Comic.show_json_include_opt
175 r.has_key?(:include).should be_true
178 r = Comic.show_json_include_opt[:include]
179 r.should have(2).items
182 r = Comic.show_json_include_opt[:include]
183 r.has_key?(:author).should be_true
186 r = Comic.show_json_include_opt[:include]
187 r.has_key?(:stories).should be_true
189 it 'ストーリーはコマを含んでいる' do
190 r = Comic.show_json_include_opt[:include]
191 r[:stories].has_key?(:panel).should be_true
194 describe '一覧取得に於いて' do
196 @comic = Factory :comic, :author_id => @author.id
198 context 'page補正について' do
199 it '文字列から数値に変換される' do
200 Comic.page('8').should eq 8
203 Comic.page().should eq 1
206 Comic.page('0').should eq 1
209 context 'page_size補正について' do
210 it '文字列から数値に変換される' do
211 Comic.page_size('7').should eq 7
213 it 'nilの場合はComic.default_page_sizeになる' do
214 Comic.page_size().should eq Comic.default_page_size
216 it '0以下の場合はComic.default_page_sizeになる' do
217 Comic.page_size('0').should eq Comic.default_page_size
219 it 'Comic.max_page_sizeを超えた場合はComic.max_page_sizeになる' do
220 Comic.page_size('1000').should eq Comic.max_page_size
227 it '非公開コミックは(自分のコミックであっても)含んでいない' do
228 Factory :comic, :author_id => @author.id, :visible => 0
233 v = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 100
235 c.should eq [v, @comic]
237 context 'DBに5件あって1ページの件数を2件に変えたとして' do
239 @comic2 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 100
240 @comic3 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 200
241 @comic4 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 300
242 @comic5 = Factory :comic, :author_id => @author.id, :updated_at => Time.now + 400
243 Comic.stub(:default_page_size).and_return(2)
247 c.should have(2).items
249 it 'page=1なら末尾2件を返す' do
251 c = Comic.list({}, 1)
252 c.should eq [@comic5, @comic4]
254 it 'page=2なら中間2件を返す' do
255 c = Comic.list({}, 2)
256 c.should eq [@comic3, @comic2]
258 it 'page=3なら先頭1件を返す' do
259 c = Comic.list({}, 3)
264 describe 'list関連テーブルプションに於いて' do
265 it 'includeキーを含んでいる' do
267 r.has_key?(:include).should be_true
270 r = Comic.list_opt[:include]
271 r.should have(2).items
274 r = Comic.list_opt[:include]
275 r.has_key?(:stories).should be_true
277 it 'ストーリーはコマを含んでいる' do
278 r = Comic.list_opt[:include]
279 r[:stories].has_key?(:panel).should be_true
282 r = Comic.list_opt[:include]
283 r.has_key?(:author).should be_true
286 describe 'json一覧出力オプションに於いて' do
287 it 'includeキーを含んでいる' do
288 r = Comic.list_json_opt
289 r.has_key?(:include).should be_true
292 r = Comic.list_json_opt[:include]
293 r.should have(2).items
296 r = Comic.list_json_opt[:include]
297 r.has_key?(:stories).should be_true
299 it 'ストーリーはコマを含んでいる' do
300 r = Comic.list_json_opt[:include]
301 r[:stories].has_key?(:panel).should be_true
304 r = Comic.list_json_opt[:include]
305 r.has_key?(:author).should be_true