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 @lg = Factory :license_group
180 @fs = Rails.root + 'spec/json/license_groups.json'
181 @ts = File.open(@fs, 'r').read
185 @attr = @a["licenses_attributes"]
187 context '2件データでつつがなく終わるとき' do
189 License.stub(:store).with(any_args).and_return(License.new)
190 License.should_receive(:store).with(any_args).exactly(2)
191 License.any_instance.stub(:valid?).with(any_args).and_return(true)
192 r = License.stores(@attr, @lg.id)
195 License.stub(:store).with(any_args).and_return(License.new)
196 License.any_instance.stub(:valid?).with(any_args).and_return(true)
197 r = License.stores(@attr, @lg.id)
201 context '2件データで失敗するとき' do
203 License.stub(:store).with(any_args).and_return(License.new)
204 License.should_receive(:store).with(any_args).exactly(2)
205 License.any_instance.stub(:valid?).with(any_args).and_return(false)
206 r = License.stores(@attr, @lg.id)
209 License.stub(:store).with(any_args).and_return(License.new)
210 License.any_instance.stub(:valid?).with(any_args).and_return(false)
211 r = License.stores(@attr, @lg.id)
215 context 'attrsがnilなどのHashでないとき' do
217 r = License.stores(nil, @lg.id)
223 describe '単体取得に於いて' do
225 @sp = Factory :system_picture
226 @lg = Factory :license_group
227 @l = Factory :license, :license_group_id => @lg.id, :system_picture_id => @sp.id
230 l = License.show @l.id
234 describe '関連テーブルプションに於いて' do
235 context 'オプションがないとき' do
236 it 'ライセンスグループを含んでいる' do
237 r = License.show_include_opt
238 r.should eq [:license_group]
241 context 'オプションで素材ライセンスを含ませたとき' do
242 it 'ライセンスグループと素材ライセンスを含んでいる' do
243 r = License.show_include_opt(:include => :resource_picture_license)
244 r.should eq [:license_group, :resource_picture_license]
248 describe 'json単体出力オプションに於いて' do
249 it 'includeキーを含んでいる' do
250 r = License.show_json_include_opt
251 r.has_key?(:include).should be_true
254 r = License.show_json_include_opt[:include]
255 r.should have(1).items
257 it 'ライセンスグループを含んでいる' do
258 r = License.show_json_include_opt[:include]
259 r.has_key?(:license_group).should be_true
262 describe '一覧取得に於いて' do
264 @sp = Factory :system_picture
265 @lg = Factory :license_group
266 @l = Factory :license, :name => 'peta2.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
267 @lg2 = Factory :license_group, :name => 'pubdm'
274 @l2 = Factory :license, :name => 'peta3.0', :url => 'http://pe.ta/3.0', :license_group_id => @lg.id, :system_picture_id => @sp.id
275 @l3 = Factory :license, :name => 'pd1.0', :url => 'http://pb.dm/1.0', :license_group_id => @lg2.id, :system_picture_id => @sp.id
277 l.should eq [@l3, @l, @l2]
280 describe 'list関連テーブルプションに於いて' do
281 it 'includeキーを含んでいる' do
283 r.has_key?(:include).should be_true
286 r = License.list_opt[:include]
287 r.should have(1).items
289 it 'ライセンスグループを含んでいる' do
290 r = License.list_opt[:include]
291 r.has_key?(:license_group).should be_true
294 describe 'json一覧出力オプションに於いて' do
295 it 'includeキーを含んでいる' do
296 r = License.list_json_opt
297 r.has_key?(:include).should be_true
300 r = License.list_json_opt[:include]
301 r.should have(1).items
303 it 'ライセンスグループを含んでいる' do
304 r = License.list_json_opt[:include]
305 r.has_key?(:license_group).should be_true