1 # -*- encoding: utf-8 -*-
5 describe GroundPicture do
7 FactoryGirl.create :admin
8 @user = FactoryGirl.create( :user_yas)
10 @artist = FactoryGirl.create :artist_yas, :author_id => @author.id
11 @other_user = FactoryGirl.create( :user_yas)
12 @other_author = @other_user.author
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
40 context 'panel_idを検証するとき' do
41 #ネストの保存はnilを許可しなければならないので数値チェックだけ
44 @gp.should_not be_valid
47 context 'picture_idを検証するとき' do
50 @gp.should_not be_valid
54 @gp.should_not be_valid
56 it '存在する実素材でなければ失敗する' do
58 @gp.should_not be_valid
64 @gp.should_not be_valid
68 @gp.should_not be_valid
72 @gp.should_not be_valid
76 @gp.should_not be_valid
81 describe 'デフォルト値補充に於いて' do
83 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
88 describe '上書き補充に於いて' do
90 @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
95 describe '一覧取得に於いて' do
97 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
99 context 'page補正について' do
100 it '文字列から数値に変換される' do
101 GroundPicture.page('8').should eq 8
104 GroundPicture.page().should eq 1
107 GroundPicture.page('0').should eq 1
110 context 'page_size補正について' do
111 it '文字列から数値に変換される' do
112 GroundPicture.page_size('7').should eq 7
114 it 'nilの場合はGroundPicture.default_page_sizeになる' do
115 GroundPicture.page_size().should eq GroundPicture.default_page_size
117 it '0以下の場合はGroundPicture.default_page_sizeになる' do
118 GroundPicture.page_size('0').should eq GroundPicture.default_page_size
120 it 'GroundPicture.max_page_sizeを超えた場合はGroundPicture.max_page_sizeになる' do
121 GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
124 context 'つつがなく終わるとき' do
\r
125 it '一覧取得オプションを利用している' do
\r
126 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
\r
127 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
\r
128 r = GroundPicture.list
132 pl = GroundPicture.list
136 #公開コマなら(他人のコマであっても)含んでいる
137 opl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
138 npl = FactoryGirl.create :ground_picture, :panel_id => opl.id, :picture_id => @p.id, :updated_at => Time.now + 100
139 pl = GroundPicture.list
140 pl.should eq [npl, @gp]
142 it '非公開のコマの景色は含まない' do
143 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
144 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
145 pl = GroundPicture.list
148 context 'DBに5件あって1ページの件数を2件に変えたとして' do
150 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
151 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
152 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
153 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
154 GroundPicture.stub(:default_page_size).and_return(2)
157 pl = GroundPicture.list
158 pl.should have(2).items
160 it 'page=1なら末尾2件を返す' do
162 pl = GroundPicture.list(1)
163 pl.should eq [@gp5, @gp4]
165 it 'page=2なら中間2件を返す' do
166 pl = GroundPicture.list(2)
167 pl.should eq [@gp3, @gp2]
169 it 'page=3なら先頭1件を返す' do
170 pl = GroundPicture.list(3)
174 context 'DBに5件あって1ページの件数を0件に変えたとして' do
176 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
177 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
178 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
179 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
182 r = GroundPicture.list 5, 0
183 r.should have(5).items
187 describe 'list関連テーブルプションに於いて' do
188 it 'includeキーを含んでいる' do
189 r = GroundPicture.list_opt
190 r.has_key?(:include).should be_true
193 r = GroundPicture.list_opt[:include]
194 r.should have(2).items
197 r = GroundPicture.list_opt[:include]
198 r.has_key?(:panel).should be_true
201 r = GroundPicture.list_opt[:include]
202 r[:panel].has_key?(:author).should be_true
205 r = GroundPicture.list_opt[:include]
206 r.has_key?(:picture).should be_true
209 r = GroundPicture.list_opt[:include]
210 r[:picture].has_key?(:artist).should be_true
212 it '実素材はライセンスを含んでいる' do
213 r = GroundPicture.list_opt[:include]
214 r[:picture].has_key?(:license).should be_true
217 describe 'json一覧出力オプションに於いて' do
218 it 'includeキーを含んでいる' do
219 r = GroundPicture.list_json_opt
220 r.has_key?(:include).should be_true
223 r = GroundPicture.list_json_opt[:include]
224 r.should have(2).items
227 r = GroundPicture.list_json_opt[:include]
228 r.has_key?(:panel).should be_true
231 r = GroundPicture.list_json_opt[:include]
232 r[:panel].has_key?(:author).should be_true
235 r = GroundPicture.list_json_opt[:include]
236 r.has_key?(:picture).should be_true
239 r = GroundPicture.list_json_opt[:include]
240 r[:picture].has_key?(:artist).should be_true
242 it '実素材はライセンスを含んでいる' do
243 r = GroundPicture.list_json_opt[:include]
244 r[:picture].has_key?(:license).should be_true
248 describe '自分のコマで使った景色画像一覧取得に於いて' do
250 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
252 context 'つつがなく終わるとき' do
\r
253 it '一覧取得オプションを利用している' do
\r
254 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
\r
255 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
\r
256 r = GroundPicture.mylist @author
260 pl = GroundPicture.mylist @author
264 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
265 pl = GroundPicture.mylist @author
266 pl.should eq [npl, @gp]
268 it '他人のコマの景色は公開でも含まない' do
269 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
270 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
271 pl = GroundPicture.mylist @author
274 it '自分のコマの景色は非公開でも含んでいる' do
275 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
276 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
277 pl = GroundPicture.mylist @author
278 pl.should eq [npl, @gp]
280 context 'DBに5件あって1ページの件数を2件に変えたとして' do
282 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
283 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
284 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
285 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
288 c = GroundPicture.mylist @author, 1, 2
289 c.should have(2).items
291 it 'page=1なら末尾2件を返す' do
293 c = GroundPicture.mylist(@author, 1, 2)
294 c.should eq [@gp5, @gp4]
296 it 'page=2なら中間2件を返す' do
297 c = GroundPicture.mylist(@author, 2, 2)
298 c.should eq [@gp3, @gp2]
300 it 'page=3なら先頭1件を返す' do
301 c = GroundPicture.mylist(@author, 3, 2)
305 context 'DBに5件あって1ページの件数を0件に変えたとして' do
307 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
308 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
309 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
310 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
313 r = GroundPicture.mylist @author, 5, 0
314 r.should have(5).items