1 # -*- encoding: utf-8 -*-
5 describe GroundPicture do
7 @admin = FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
9 @author = FactoryGirl.create :author, :user_id => @user.id
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @other_user = FactoryGirl.create( :user_yas)
12 @other_author = FactoryGirl.create :author, :user_id => @other_user.id
13 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
14 @sp = FactoryGirl.create :system_picture
15 @lg = FactoryGirl.create :license_group
16 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
17 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
18 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
19 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
20 @panel = FactoryGirl.create :panel, :author_id => @author.id
25 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
28 context 'オーソドックスなデータのとき' do
46 context 'panel_idを検証するとき' do
47 #ネストの保存はnilを許可しなければならないので数値チェックだけ
50 @gp.should_not be_valid
53 context 'picture_idを検証するとき' do
56 @gp.should_not be_valid
60 @gp.should_not be_valid
62 it '存在する実素材でなければ失敗する' do
64 @gp.should_not be_valid
67 context 'repeatを検証するとき' do
70 @gp.should_not be_valid
74 @gp.should_not be_valid
78 @gp.should_not be_valid
82 @gp.should_not be_valid
88 @gp.should_not be_valid
92 @gp.should_not be_valid
98 @gp.should_not be_valid
102 @gp.should_not be_valid
105 context 'zを検証するとき' do
108 @gp.should_not be_valid
112 @gp.should_not be_valid
116 @gp.should_not be_valid
120 @gp.should_not be_valid
125 describe 'デフォルト値補充に於いて' do
127 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
137 it '繰り返しに0を補充している' do
139 @gp.repeat.should eq 0
143 describe '上書き補充に於いて' do
145 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
150 describe '一覧取得に於いて' do
152 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
154 context 'page補正について' do
155 it '文字列から数値に変換される' do
156 GroundPicture.page('8').should eq 8
159 GroundPicture.page().should eq 1
162 GroundPicture.page('0').should eq 1
165 context 'page_size補正について' do
166 it '文字列から数値に変換される' do
167 GroundPicture.page_size('7').should eq 7
169 it 'nilの場合はGroundPicture.default_page_sizeになる' do
170 GroundPicture.page_size().should eq GroundPicture.default_page_size
172 it '0以下の場合はGroundPicture.default_page_sizeになる' do
173 GroundPicture.page_size('0').should eq GroundPicture.default_page_size
175 it 'GroundPicture.max_page_sizeを超えた場合はGroundPicture.max_page_sizeになる' do
176 GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
179 context 'つつがなく終わるとき' do
180 it '一覧取得オプションを利用している' do
181 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
182 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
183 r = GroundPicture.list
187 pl = GroundPicture.list
191 #公開コマなら(他人のコマであっても)含んでいる
192 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
193 npl = FactoryGirl.create :ground_picture, :panel_id => opl.id, :picture_id => @p.id, :updated_at => Time.now + 100
194 pl = GroundPicture.list
195 pl.should eq [npl, @gp]
197 it '非公開のコマの景色は含まない' do
198 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
199 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
200 pl = GroundPicture.list
203 context 'DBに5件あって1ページの件数を2件に変えたとして' do
205 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
206 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
207 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
208 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
209 GroundPicture.stub(:default_page_size).and_return(2)
212 pl = GroundPicture.list
213 pl.should have(2).items
215 it 'page=1なら末尾2件を返す' do
217 pl = GroundPicture.list(1)
218 pl.should eq [@gp5, @gp4]
220 it 'page=2なら中間2件を返す' do
221 pl = GroundPicture.list(2)
222 pl.should eq [@gp3, @gp2]
224 it 'page=3なら先頭1件を返す' do
225 pl = GroundPicture.list(3)
229 context 'DBに5件あって1ページの件数を0件に変えたとして' do
231 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
232 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
233 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
234 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
235 GroundPicture.stub(:default_page_size).and_return(2)
238 r = GroundPicture.list 5, 0
239 r.should have(5).items
243 describe '一覧取得オプションに於いて' do
244 it 'includeキーを含んでいる' do
245 r = GroundPicture.list_opt
246 r.has_key?(:include).should be_true
249 r = GroundPicture.list_opt[:include]
250 r.should have(2).items
253 r = GroundPicture.list_opt[:include]
254 r.has_key?(:panel).should be_true
257 r = GroundPicture.list_opt[:include]
258 r[:panel].has_key?(:author).should be_true
261 r = GroundPicture.list_opt[:include]
262 r.has_key?(:picture).should be_true
265 r = GroundPicture.list_opt[:include]
266 r[:picture].has_key?(:artist).should be_true
268 it '実素材はライセンスを含んでいる' do
269 r = GroundPicture.list_opt[:include]
270 r[:picture].has_key?(:license).should be_true
273 describe 'json一覧出力オプションに於いて' do
275 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
276 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
277 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
278 @sbt = FactoryGirl.create :speech_balloon_template
279 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
280 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
281 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
282 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
285 r = GroundPicture.list.to_json GroundPicture.list_json_opt
288 i.has_key?('panel').should be_true
291 r = GroundPicture.list.to_json GroundPicture.list_json_opt
295 s.has_key?('author').should be_true
298 r = GroundPicture.list.to_json GroundPicture.list_json_opt
301 i.has_key?('picture').should be_true
304 r = GroundPicture.list.to_json GroundPicture.list_json_opt
308 s.has_key?('artist').should be_true
310 it '実素材はライセンスを含んでいる' do
311 r = GroundPicture.list.to_json GroundPicture.list_json_opt
315 s.has_key?('license').should be_true
319 describe '自分のコマで使った景色画像一覧取得に於いて' do
321 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
323 context 'つつがなく終わるとき' do
324 it '一覧取得オプションを利用している' do
325 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
326 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
327 r = GroundPicture.mylist @author
331 pl = GroundPicture.mylist @author
335 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
336 pl = GroundPicture.mylist @author
337 pl.should eq [npl, @gp]
339 it '他人のコマの景色は公開でも含まない' do
340 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
341 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
342 pl = GroundPicture.mylist @author
345 it '自分のコマの景色は非公開でも含んでいる' do
346 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
347 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
348 pl = GroundPicture.mylist @author
349 pl.should eq [npl, @gp]
351 context 'DBに5件あって1ページの件数を2件に変えたとして' do
353 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
354 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
355 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
356 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
359 c = GroundPicture.mylist @author, 1, 2
360 c.should have(2).items
362 it 'page=1なら末尾2件を返す' do
364 c = GroundPicture.mylist(@author, 1, 2)
365 c.should eq [@gp5, @gp4]
367 it 'page=2なら中間2件を返す' do
368 c = GroundPicture.mylist(@author, 2, 2)
369 c.should eq [@gp3, @gp2]
371 it 'page=3なら先頭1件を返す' do
372 c = GroundPicture.mylist(@author, 3, 2)
376 context 'DBに5件あって1ページの件数を0件に変えたとして' do
378 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
379 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
380 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
381 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
382 Author.stub(:default_ground_picture_page_size).and_return(2)
385 r = GroundPicture.mylist @author, 5, 0
386 r.should have(5).items