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
27 it 'オーソドックスなデータなら通る' do
32 context 'panel_idを検証するとき' do
33 #ネストの保存はnilを許可しなければならないので数値チェックだけ
35 @gp.panel_id = @panel.id
40 @gp.should_not be_valid
43 context 'picture_idを検証するとき' do
45 @gp.picture_id = @panel.id
50 @gp.should_not be_valid
54 @gp.should_not be_valid
56 it '存在する実素材でなければ失敗する' do
58 @gp.should_not be_valid
68 @gp.should_not be_valid
72 @gp.should_not be_valid
76 @gp.should_not be_valid
80 @gp.should_not be_valid
84 describe '一覧取得に於いて' do
86 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
88 context 'page補正について' do
90 GroundPicture.page('8').should eq 8
93 GroundPicture.page().should eq 1
96 GroundPicture.page('0').should eq 1
99 context 'page_size補正について' do
100 it '文字列から数値に変換される' do
101 GroundPicture.page_size('7').should eq 7
103 it 'nilの場合はGroundPicture.default_page_sizeになる' do
104 GroundPicture.page_size().should eq GroundPicture.default_page_size
106 it '0以下の場合はGroundPicture.default_page_sizeになる' do
107 GroundPicture.page_size('0').should eq GroundPicture.default_page_size
109 it 'GroundPicture.max_page_sizeを超えた場合はGroundPicture.max_page_sizeになる' do
110 GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
114 pl = GroundPicture.list
118 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
119 pl = GroundPicture.list
120 pl.should eq [npl, @gp]
122 it '非公開のコマの景色は含まない' do
123 hpl = FactoryGirl.create :panel, :author_id => @author.id, :publish => 0
124 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id, :updated_at => Time.now + 100
125 pl = GroundPicture.list
128 context 'DBに5件あって1ページの件数を2件に変えたとして' do
130 @npl2 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 1, :picture_id => @p.id, :updated_at => Time.now + 100
131 @npl3 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 2, :picture_id => @p.id, :updated_at => Time.now + 200
132 @npl4 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 3, :picture_id => @p.id, :updated_at => Time.now + 300
133 @npl5 = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :z => 4, :picture_id => @p.id, :updated_at => Time.now + 400
134 GroundPicture.stub(:default_page_size).and_return(2)
137 pl = GroundPicture.list
138 pl.should have(2).items
140 it 'page=1なら末尾2件を返す' do
142 pl = GroundPicture.list( {}, 1)
143 pl.should eq [@npl5, @npl4]
145 it 'page=2なら中間2件を返す' do
146 pl = GroundPicture.list({}, 2)
147 pl.should eq [@npl3, @npl2]
149 it 'page=3なら先頭1件を返す' do
150 pl = GroundPicture.list({}, 3)
155 describe 'list関連テーブルプションに於いて' do
156 it 'includeキーを含んでいる' do
157 r = GroundPicture.list_opt
158 r.has_key?(:include).should be_true
161 r = GroundPicture.list_opt[:include]
162 r.should have(2).items
165 r = GroundPicture.list_opt[:include]
166 r.has_key?(:panel).should be_true
169 r = GroundPicture.list_opt[:include]
170 r[:panel].has_key?(:author).should be_true
173 r = GroundPicture.list_opt[:include]
174 r.has_key?(:picture).should be_true
177 r = GroundPicture.list_opt[:include]
178 r[:picture].has_key?(:artist).should be_true
180 it '実素材はライセンスを含んでいる' do
181 r = GroundPicture.list_opt[:include]
182 r[:picture].has_key?(:license).should be_true
185 describe 'json一覧出力オプションに於いて' do
186 it 'includeキーを含んでいる' do
187 r = GroundPicture.list_json_opt
188 r.has_key?(:include).should be_true
191 r = GroundPicture.list_json_opt[:include]
192 r.should have(2).items
195 r = GroundPicture.list_json_opt[:include]
196 r.has_key?(:panel).should be_true
199 r = GroundPicture.list_json_opt[:include]
200 r[:panel].has_key?(:author).should be_true
203 r = GroundPicture.list_json_opt[:include]
204 r.has_key?(:picture).should be_true
207 r = GroundPicture.list_json_opt[:include]
208 r[:picture].has_key?(:artist).should be_true
210 it '実素材はライセンスを含んでいる' do
211 r = GroundPicture.list_json_opt[:include]
212 r[:picture].has_key?(:license).should be_true
216 describe '自分のコマで使った景色画像一覧取得に於いて' do
218 @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
221 pl = GroundPicture.mylist @author
225 npl = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id, :z => 2, :updated_at => Time.now + 100
226 pl = GroundPicture.mylist @author
227 pl.should eq [npl, @gp]
229 it '他人のコマの景色は公開でも含まない' do
230 hpl = FactoryGirl.create :panel, :author_id => @other_author.id, :publish => 1
231 npl = FactoryGirl.create :ground_picture, :panel_id => hpl.id, :picture_id => @p.id
232 pl = GroundPicture.mylist @author