1 # -*- encoding: utf-8 -*-
10 @sp = Factory :system_picture
11 @lg = Factory :license_group
12 @l = Factory.build :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
15 it 'オーソドックスなデータなら通る' do
19 context 'license_group_idを検証するとき' do
21 @l.license_group_id = @lg.id
\r
25 @l.license_group_id = ''
26 @l.should_not be_valid
29 @l.license_group_id = 'a'
\r
30 @l.should_not be_valid
\r
32 it '存在するライセンスグループでなければ失敗する' do
\r
33 @l.license_group_id = 0
\r
34 @l.should_not be_valid
\r
37 context 'nameを検証するとき' do
44 @l.should_not be_valid
48 @l.should_not be_valid
52 @l.should_not be_valid
55 context 'captionを検証するとき' do
62 @l.should_not be_valid
66 @l.should_not be_valid
69 context 'urlを検証するとき' do
71 @l.url = 'http://test.jp/aaaaa' + 'a' * 180
77 @l.should_not be_valid
80 @l.url = 'http://test.jp/aaaaa' + 'a' * 181
81 @l.should_not be_valid
85 @l.should_not be_valid
\r
88 context 'system_picture_idを検証するとき' do
90 @l.system_picture_id = @sp.id
\r
94 @l.system_picture_id = ''
95 @l.should_not be_valid
98 @l.system_picture_id = 'a'
\r
99 @l.should_not be_valid
\r
101 it '存在するシステム画像でなければ失敗する' do
\r
102 @l.system_picture_id = 0
\r
103 @l.should_not be_valid
\r
110 @lg = Factory :license_group
111 @f = Rails.root + 'spec/json/license_group.json'
112 @t = File.open(@f, 'r').read
116 @attr = @a["licenses_attributes"]
117 @ln = @attr.keys.first
118 @la = @attr.values.first
119 @la["license_group_id"] = @lg.id
121 context 'つつがなく終わるとき' do
122 it 'システム画像置換を依頼する' do
123 License.stub(:replace_system_picture).with(any_args).and_return(true)
124 License.should_receive(:replace_system_picture).with(any_args).exactly(1)
125 License.stub(:modify_object).with(any_args).and_return(License.new)
126 License.any_instance.stub(:save).with(any_args).and_return(true)
127 r = License.store(@ln, @la)
130 License.stub(:replace_system_picture).with(any_args).and_return(true)
131 License.stub(:modify_object).with(any_args).and_return(License.new)
132 License.should_receive(:modify_object).with(any_args).exactly(1)
133 License.any_instance.stub(:save).with(any_args).and_return(true)
134 r = License.store(@ln, @la)
137 License.stub(:replace_system_picture).with(any_args).and_return(true)
138 License.stub(:modify_object).with(any_args).and_return(License.new)
139 License.any_instance.stub(:save).with(any_args).and_return(true)
140 License.any_instance.should_receive(:save).with(any_args).exactly(1)
141 r = License.store(@ln, @la)
144 r = License.store(@ln, @la)
145 r.is_a?(License).should be_true
147 r.url.should eq @la["url"]
149 it 'ライセンスが作成されている' do
151 r = License.store(@ln, @la)
152 }.should change License, :count
154 it 'システム画像が作成されている' do
156 r = License.store(@ln, @la)
157 }.should change SystemPicture, :count
160 context 'システム画像置換が失敗するとき' do
162 License.stub(:replace_system_picture).with(any_args).and_return(false)
163 License.stub(:modify_object).with(any_args).and_return(License.new)
165 it '全体エラーメッセージがセットされている' do
166 r = License.store(@ln, @la)
167 r.errors[:base].should_not be_blank
169 it 'ライセンスが作成されていない' do
171 r = License.store(@ln, @la)
172 }.should_not change License, :count
177 describe '複数の更新に於いて' do
179 @fs = Rails.root + 'spec/json/license_groups.json'
180 @ts = File.open(@fs, 'r').read
184 @attr = @a["licenses_attributes"]
186 context '2件データでつつがなく終わるとき' do
188 License.stub(:store).with(any_args).and_return(License.new)
189 License.should_receive(:store).with(any_args).exactly(2)
190 License.any_instance.stub(:valid?).with(any_args).and_return(true)
191 r = License.stores(@attr)
194 License.stub(:store).with(any_args).and_return(License.new)
195 License.any_instance.stub(:valid?).with(any_args).and_return(true)
196 r = License.stores(@attr)
200 context '2件データで失敗するとき' do
202 License.stub(:store).with(any_args).and_return(License.new)
203 License.should_receive(:store).with(any_args).exactly(2)
204 License.any_instance.stub(:valid?).with(any_args).and_return(false)
205 r = License.stores(@attr)
208 License.stub(:store).with(any_args).and_return(License.new)
209 License.any_instance.stub(:valid?).with(any_args).and_return(false)
210 r = License.stores(@attr)
214 context 'attrsがnilなどのHashでないとき' do
216 r = License.stores(nil)
222 describe '単体取得に於いて' do
224 @sp = Factory :system_picture
225 @lg = Factory :license_group
226 @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
229 l = License.show @l.id
233 describe '関連テーブルプションに於いて' do
234 context 'オプションがないとき' do
235 it 'ライセンスグループを含んでいる' do
236 r = License.show_include_opt
237 r.should eq [:license_group]
240 context 'オプションで素材ライセンスを含ませたとき' do
241 it 'ライセンスグループと素材ライセンスを含んでいる' do
242 r = License.show_include_opt(:include => :resource_picture_license)
243 r.should eq [:license_group, :resource_picture_license]
247 describe 'json単体出力オプションに於いて' do
248 it 'includeキーを含んでいる' do
249 r = License.show_json_include_opt
250 r.has_key?(:include).should be_true
253 r = License.show_json_include_opt[:include]
254 r.should have(1).items
256 it 'ライセンスグループを含んでいる' do
257 r = License.show_json_include_opt[:include]
258 r.has_key?(:license_group).should be_true
261 describe '一覧取得に於いて' do
263 @sp = Factory :system_picture
264 @lg = Factory :license_group
265 @l = Factory :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
266 @lg2 = Factory :license_group, :name => 'pubdm'
269 l = License.list @lg.id
272 it 'グループ順,名前順で並んでいる' do
273 @l2 = Factory :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
274 @l3 = Factory :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id
275 l = License.list @lg.id
276 l.should eq [@l, @l2]
279 describe 'list関連テーブルプションに於いて' do
280 it 'includeキーを含んでいる' do
282 r.has_key?(:include).should be_true
285 r = License.list_opt[:include]
286 r.should have(1).items
288 it 'ライセンスグループを含んでいる' do
289 r = License.list_opt[:include]
290 r.has_key?(:license_group).should be_true
293 describe 'json一覧出力オプションに於いて' do
294 it 'includeキーを含んでいる' do
295 r = License.list_json_opt
296 r.has_key?(:include).should be_true
299 r = License.list_json_opt[:include]
300 r.should have(1).items
302 it 'ライセンスグループを含んでいる' do
303 r = License.list_json_opt[:include]
304 r.has_key?(:license_group).should be_true