1 # -*- encoding: utf-8 -*-
4 describe PanelPicture do
6 FactoryGirl.create :admin
7 @user = FactoryGirl.create( :user_yas)
9 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
10 @other_user = FactoryGirl.create( :user_yas)
11 @other_author = @other_user.author
12 @other_artist = FactoryGirl.create :artist_yas, :author_id => @other_author.id
13 @sp = FactoryGirl.create :system_picture
14 @lg = FactoryGirl.create :license_group
15 @license = FactoryGirl.create :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
16 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
17 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
18 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
19 @panel = FactoryGirl.create :panel, :author_id => @author.id
24 @pp = FactoryGirl.build :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
25 :width => @p.width, :height => @p.height
27 it 'オーソドックスなデータなら通る' do
32 context 'panel_idを検証するとき' do
33 #ネストの保存はnilを許可しなければならないので数値チェックだけ
35 @pp.panel_id = @panel.id
40 @pp.should_not be_valid
43 context 'linkを検証するとき' do
45 @pp.link = 'abcdefghi0abcdefghi0abcdefghi0abcdefghi0abcdefghi0'*4
54 @pp.should_not be_valid
64 @pp.should_not be_valid
68 @pp.should_not be_valid
86 @pp.should_not be_valid
90 @pp.should_not be_valid
101 context 'widthを検証するとき' do
103 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
104 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
105 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
113 @pp.should_not be_valid
117 @pp.should_not be_valid
121 @pp.should_not be_valid
125 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
134 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
138 @pp.should_not be_valid
141 context 'サイズ変更許可のとき' do
143 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
145 it '実素材のサイズと違っても通る' do
146 @pp.width = @p.width-1
150 context 'サイズ変更禁止のとき' do
152 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(-1)
154 it '実素材のサイズと違うなら失敗する' do
155 @pp.width = @p.width-1
156 @pp.should_not be_valid
159 context '縦横比変更許可のとき' do
161 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
163 it '実素材の縦横比と違っても通る' do
164 @pp.width = @p.width / 2
168 context '縦横比変更禁止のとき' do
170 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(-1)
172 it '実素材の縦横比と違うなら失敗する' do
173 @pp.width = @p.width / 2
174 @pp.should_not be_valid
178 context 'heightを検証するとき' do
180 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
181 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
182 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
190 @pp.should_not be_valid
194 @pp.should_not be_valid
198 @pp.should_not be_valid
206 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(0)
215 Picture.any_instance.stub(:flag_reverse).with(any_args).and_return(-1)
219 @pp.should_not be_valid
222 context 'サイズ変更許可のとき' do
224 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(0)
226 it '実素材のサイズと違っても通る' do
227 @pp.height = @p.height-1
231 context 'サイズ変更禁止のとき' do
233 Picture.any_instance.stub(:flag_resize).with(any_args).and_return(-1)
235 it '実素材のサイズと違うなら失敗する' do
236 @pp.height = @p.height-1
237 @pp.should_not be_valid
240 context '縦横比変更許可のとき' do
242 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(0)
244 it '実素材の縦横比と違っても通る' do
245 @pp.height = @p.height / 2
249 context '縦横比変更禁止のとき' do
251 Picture.any_instance.stub(:flag_sync_vh).with(any_args).and_return(-1)
253 it '実素材の縦横比と違うなら失敗する' do
254 @pp.height = @p.height / 2
255 @pp.should_not be_valid
259 context 'zを検証するとき' do
266 @pp.should_not be_valid
270 @pp.should_not be_valid
274 @pp.should_not be_valid
278 @pp.should_not be_valid
281 context 'tを検証するとき' do
288 @pp.should_not be_valid
292 @pp.should_not be_valid
296 @pp.should_not be_valid
300 describe '一覧取得に於いて' do
302 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
303 :width => @p.width, :height => @p.height
305 context 'page補正について' do
306 it '文字列から数値に変換される' do
307 PanelPicture.page('8').should eq 8
310 PanelPicture.page().should eq 1
313 PanelPicture.page('0').should eq 1
316 context 'page_size補正について' do
317 it '文字列から数値に変換される' do
318 PanelPicture.page_size('7').should eq 7
320 it 'nilの場合はPanelPicture.default_page_sizeになる' do
321 PanelPicture.page_size().should eq PanelPicture.default_page_size
323 it '0以下の場合はPanelPicture.default_page_sizeになる' do
324 PanelPicture.page_size('0').should eq PanelPicture.default_page_size
326 it 'PanelPicture.max_page_sizeを超えた場合はPanelPicture.max_page_sizeになる' do
327 PanelPicture.page_size('1000').should eq PanelPicture.max_page_size
331 pl = PanelPicture.list
335 npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
336 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
337 pl = PanelPicture.list
338 pl.should eq [npl, @pp]
341 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
342 npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
343 :width => @p.width, :height => @p.height
344 pl = PanelPicture.list
347 context 'DBに5件あって1ページの件数を2件に変えたとして' do
349 @npl2 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
350 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
351 @npl3 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 2, :picture_id => @p.id,
352 :width => @p.width, :height => @p.height, :updated_at => Time.now + 200
353 @npl4 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 3, :picture_id => @p.id,
354 :width => @p.width, :height => @p.height, :updated_at => Time.now + 300
355 @npl5 = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 4, :picture_id => @p.id,
356 :width => @p.width, :height => @p.height, :updated_at => Time.now + 400
357 PanelPicture.stub(:default_page_size).and_return(2)
360 pl = PanelPicture.list
361 pl.should have(2).items
363 it 'page=1なら末尾2件を返す' do
365 pl = PanelPicture.list( {}, 1)
366 pl.should eq [@npl5, @npl4]
368 it 'page=2なら中間2件を返す' do
369 pl = PanelPicture.list({}, 2)
370 pl.should eq [@npl3, @npl2]
372 it 'page=3なら先頭1件を返す' do
373 pl = PanelPicture.list({}, 3)
378 describe 'list関連テーブルプションに於いて' do
379 it 'includeキーを含んでいる' do
380 r = PanelPicture.list_opt
381 r.has_key?(:include).should be_true
384 r = PanelPicture.list_opt[:include]
385 r.should have(2).items
388 r = PanelPicture.list_opt[:include]
389 r.has_key?(:panel).should be_true
392 r = PanelPicture.list_opt[:include]
393 r[:panel].has_key?(:author).should be_true
396 r = PanelPicture.list_opt[:include]
397 r.has_key?(:picture).should be_true
400 r = PanelPicture.list_opt[:include]
401 r[:picture].has_key?(:artist).should be_true
403 it '実素材はライセンスを含んでいる' do
404 r = PanelPicture.list_opt[:include]
405 r[:picture].has_key?(:license).should be_true
408 describe 'json一覧出力オプションに於いて' do
409 it 'includeキーを含んでいる' do
410 r = PanelPicture.list_json_opt
411 r.has_key?(:include).should be_true
414 r = PanelPicture.list_json_opt[:include]
415 r.should have(2).items
418 r = PanelPicture.list_json_opt[:include]
419 r.has_key?(:panel).should be_true
422 r = PanelPicture.list_json_opt[:include]
423 r[:panel].has_key?(:author).should be_true
426 r = PanelPicture.list_json_opt[:include]
427 r.has_key?(:picture).should be_true
430 r = PanelPicture.list_json_opt[:include]
431 r[:picture].has_key?(:artist).should be_true
433 it '実素材はライセンスを含んでいる' do
434 r = PanelPicture.list_json_opt[:include]
435 r[:picture].has_key?(:license).should be_true
439 describe '自分のコマ一覧取得に於いて' do
441 @pp = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :picture_id => @p.id,
442 :width => @p.width, :height => @p.height
445 pl = PanelPicture.mylist @author
449 npl = FactoryGirl.create :panel_picture, :panel_id => @panel.id, :t => 1, :picture_id => @p.id,
450 :width => @p.width, :height => @p.height, :updated_at => Time.now + 100
451 pl = PanelPicture.mylist @author
452 pl.should eq [npl, @pp]
454 it '他人のコマは公開でも含まない' do
455 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
456 npl = FactoryGirl.create :panel_picture, :panel_id => hpl.id, :picture_id => @p.id,
457 :width => @p.width, :height => @p.height
458 pl = PanelPicture.mylist @author