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
180 GroundPicture.stub(:default_page_size).and_return(2)
183 r = GroundPicture.list 5, 0
184 r.should have(5).items
188 describe '一覧取得オプションに於いて' do
189 it 'includeキーを含んでいる' do
190 r = GroundPicture.list_opt
191 r.has_key?(:include).should be_true
194 r = GroundPicture.list_opt[:include]
195 r.should have(2).items
198 r = GroundPicture.list_opt[:include]
199 r.has_key?(:panel).should be_true
202 r = GroundPicture.list_opt[:include]
203 r[:panel].has_key?(:author).should be_true
206 r = GroundPicture.list_opt[:include]
207 r.has_key?(:picture).should be_true
210 r = GroundPicture.list_opt[:include]
211 r[:picture].has_key?(:artist).should be_true
213 it '実素材はライセンスを含んでいる' do
214 r = GroundPicture.list_opt[:include]
215 r[:picture].has_key?(:license).should be_true
218 describe 'json一覧出力オプションに於いて' do
220 @op = FactoryGirl.create :original_picture, :artist_id => @artist.id
\r
221 @p = FactoryGirl.create :picture, :original_picture_id => @op.id, :license_id => @license.id, :artist_id => @artist.id
\r
222 @rp = FactoryGirl.create :resource_picture, :artist_id => @artist.id, :license_id => @license.id, :original_picture_id => @op.id, :picture_id => @p.id
\r
223 @sbt = FactoryGirl.create :speech_balloon_template
\r
224 @comic = FactoryGirl.create :comic, :author_id => @author.id, :visible => 1
225 @panel = FactoryGirl.create :panel, :author_id => @author.id, :publish => 1
226 @story = FactoryGirl.create :story, :author_id => @author.id, :comic_id => @comic.id, :panel_id => @panel.id
227 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
230 r = GroundPicture.list.to_json GroundPicture.list_json_opt
233 i.has_key?('panel').should be_true
236 r = GroundPicture.list.to_json GroundPicture.list_json_opt
240 s.has_key?('author').should be_true
243 r = GroundPicture.list.to_json GroundPicture.list_json_opt
246 i.has_key?('picture').should be_true
249 r = GroundPicture.list.to_json GroundPicture.list_json_opt
253 s.has_key?('artist').should be_true
255 it '実素材はライセンスを含んでいる' do
256 r = GroundPicture.list.to_json GroundPicture.list_json_opt
260 s.has_key?('license').should be_true
264 describe '自分のコマで使った景色画像一覧取得に於いて' do
266 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
268 context 'つつがなく終わるとき' do
\r
269 it '一覧取得オプションを利用している' do
\r
270 GroundPicture.stub(:list_opt).with(any_args).and_return({:include => :panel})
\r
271 GroundPicture.should_receive(:list_opt).with(any_args).exactly(1)
\r
272 r = GroundPicture.mylist @author
276 pl = GroundPicture.mylist @author
280 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
281 pl = GroundPicture.mylist @author
282 pl.should eq [npl, @gp]
284 it '他人のコマの景色は公開でも含まない' do
285 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
286 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
287 pl = GroundPicture.mylist @author
290 it '自分のコマの景色は非公開でも含んでいる' do
291 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
292 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
293 pl = GroundPicture.mylist @author
294 pl.should eq [npl, @gp]
296 context 'DBに5件あって1ページの件数を2件に変えたとして' do
298 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
299 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
300 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
301 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
304 c = GroundPicture.mylist @author, 1, 2
305 c.should have(2).items
307 it 'page=1なら末尾2件を返す' do
309 c = GroundPicture.mylist(@author, 1, 2)
310 c.should eq [@gp5, @gp4]
312 it 'page=2なら中間2件を返す' do
313 c = GroundPicture.mylist(@author, 2, 2)
314 c.should eq [@gp3, @gp2]
316 it 'page=3なら先頭1件を返す' do
317 c = GroundPicture.mylist(@author, 3, 2)
321 context 'DBに5件あって1ページの件数を0件に変えたとして' do
323 @gp2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
324 @gp3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
325 @gp4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
326 @gp5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
327 Author.stub(:default_ground_picture_page_size).and_return(2)
\r
330 r = GroundPicture.mylist @author, 5, 0
331 r.should have(5).items