OSDN Git Service

t#29400:update artist, author:itr1
[pettanr/pettanr.git] / spec / models / ground_picture_spec.rb
1 # -*- encoding: utf-8 -*-
2 require 'spec_helper'
3 #コマの画像背景
4
5 describe GroundPicture do
6   before do
7     FactoryGirl.create :admin
8     @user = FactoryGirl.create( :user_yas)
9     @author = @user.author
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
21   end
22   
23   describe '検証に於いて' do
24     before do
25       @gp = FactoryGirl.build :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
26     end
27     it 'オーソドックスなデータなら通る' do
28       @gp.save
29       @gp.should be_valid
30     end
31     
32     context 'panel_idを検証するとき' do
33       #ネストの保存はnilを許可しなければならないので数値チェックだけ
34       it 'テストデータの確認' do
35         @gp.panel_id = @panel.id
36         @gp.should be_valid
37       end
38       it '数値でなければ失敗する' do
39         @gp.panel_id = 'a'
40         @gp.should_not be_valid
41       end
42     end
43     context 'picture_idを検証するとき' do
44       it 'テストデータの確認' do
45         @gp.picture_id = @panel.id
46         @gp.should be_valid
47       end
48       it 'nullなら失敗する' do
49         @gp.picture_id = nil
50         @gp.should_not be_valid
51       end
52       it '数値でなければ失敗する' do
53         @gp.picture_id = 'a'
54         @gp.should_not be_valid
55       end
56       it '存在する実素材でなければ失敗する' do
57         @gp.picture_id = 0
58         @gp.should_not be_valid
59       end
60     end
61     context 'zを検証するとき' do
62       it 'テストデータの確認' do
63         @gp.z = 1
64         @gp.should be_valid
65       end
66       it 'nullなら失敗する' do
67         @gp.z = nil
68         @gp.should_not be_valid
69       end
70       it '数値でなければ失敗する' do
71         @gp.z = 'a'
72         @gp.should_not be_valid
73       end
74       it '負なら失敗する' do
75         @gp.z = -1
76         @gp.should_not be_valid
77       end
78       it '負なら失敗する' do
79         @gp.z = 0
80         @gp.should_not be_valid
81       end
82     end
83   end
84   describe '一覧取得に於いて' do
85     before do
86       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
87     end
88     context 'page補正について' do
89       it '文字列から数値に変換される' do
90         GroundPicture.page('8').should eq 8
91       end
92       it 'nilの場合は1になる' do
93         GroundPicture.page().should eq 1
94       end
95       it '0以下の場合は1になる' do
96         GroundPicture.page('0').should eq 1
97       end
98     end
99     context 'page_size補正について' do
100       it '文字列から数値に変換される' do
101         GroundPicture.page_size('7').should eq 7
102       end
103       it 'nilの場合はGroundPicture.default_page_sizeになる' do
104         GroundPicture.page_size().should eq GroundPicture.default_page_size
105       end
106       it '0以下の場合はGroundPicture.default_page_sizeになる' do
107         GroundPicture.page_size('0').should eq GroundPicture.default_page_size
108       end
109       it 'GroundPicture.max_page_sizeを超えた場合はGroundPicture.max_page_sizeになる' do
110         GroundPicture.page_size('1000').should eq GroundPicture.max_page_size
111       end
112     end
113     it 'リストを返す' do
114       pl = GroundPicture.list
115       pl.should eq [@gp]
116     end
117     it '時系列で並んでいる' do
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]
121     end
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
126       pl.should eq [@gp]
127     end
128     context 'DBに5件あって1ページの件数を2件に変えたとして' do
129       before 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)
135       end
136       it '通常は2件を返す' do
137         pl = GroundPicture.list
138         pl.should have(2).items 
139       end
140       it 'page=1なら末尾2件を返す' do
141         #時系列で並んでいる
142         pl = GroundPicture.list( {}, 1)
143         pl.should eq [@npl5, @npl4]
144       end
145       it 'page=2なら中間2件を返す' do
146         pl = GroundPicture.list({}, 2)
147         pl.should eq [@npl3, @npl2]
148       end
149       it 'page=3なら先頭1件を返す' do
150         pl = GroundPicture.list({}, 3)
151         pl.should eq [@gp]
152       end
153     end
154   end
155   describe 'list関連テーブルプションに於いて' do
156     it 'includeキーを含んでいる' do
157       r = GroundPicture.list_opt
158       r.has_key?(:include).should be_true
159     end
160     it '2つの項目を含んでいる' do
161       r = GroundPicture.list_opt[:include]
162       r.should have(2).items
163     end
164     it 'コマを含んでいる' do
165       r = GroundPicture.list_opt[:include]
166       r.has_key?(:panel).should be_true
167     end
168       it 'コマは作家を含んでいる' do
169         r = GroundPicture.list_opt[:include]
170         r[:panel].has_key?(:author).should be_true
171       end
172     it '実素材を含んでいる' do
173       r = GroundPicture.list_opt[:include]
174       r.has_key?(:picture).should be_true
175     end
176       it '実素材は絵師を含んでいる' do
177         r = GroundPicture.list_opt[:include]
178         r[:picture].has_key?(:artist).should be_true
179       end
180       it '実素材はライセンスを含んでいる' do
181         r = GroundPicture.list_opt[:include]
182         r[:picture].has_key?(:license).should be_true
183       end
184   end
185   describe 'json一覧出力オプションに於いて' do
186     it 'includeキーを含んでいる' do
187       r = GroundPicture.list_json_opt
188       r.has_key?(:include).should be_true
189     end
190     it '2つの項目を含んでいる' do
191       r = GroundPicture.list_json_opt[:include]
192       r.should have(2).items
193     end
194     it 'コマを含んでいる' do
195       r = GroundPicture.list_json_opt[:include]
196       r.has_key?(:panel).should be_true
197     end
198       it 'コマは作家を含んでいる' do
199         r = GroundPicture.list_json_opt[:include]
200         r[:panel].has_key?(:author).should be_true
201       end
202     it '実素材を含んでいる' do
203       r = GroundPicture.list_json_opt[:include]
204       r.has_key?(:picture).should be_true
205     end
206       it '実素材は絵師を含んでいる' do
207         r = GroundPicture.list_json_opt[:include]
208         r[:picture].has_key?(:artist).should be_true
209       end
210       it '実素材はライセンスを含んでいる' do
211         r = GroundPicture.list_json_opt[:include]
212         r[:picture].has_key?(:license).should be_true
213       end
214   end
215   
216   describe '自分のコマで使った景色画像一覧取得に於いて' do
217     before do
218       @gp = FactoryGirl.create :ground_picture, :panel_id => @panel.id, :picture_id => @p.id
219     end
220     it 'リストを返す' do
221       pl = GroundPicture.mylist @author
222       pl.should eq [@gp]
223     end
224     it '時系列で並んでいる' do
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]
228     end
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
233       pl.should eq [@gp]
234     end
235   end
236   
237 end