spec/acfs/model/persistance_spec.rb in acfs-0.22.0 vs spec/acfs/model/persistance_spec.rb in acfs-0.22.1.b192
- old
+ new
@@ -170,13 +170,24 @@
end
it 'should set local errors hash' do
model.name = ''
model.save! rescue nil
- expect(model.errors.to_hash).to be == { name: %w(required) }.stringify_keys
+ expect(model.errors.to_hash).to be == { name: %w(required) }
end
end
+
+ context 'hash modification on iteration in ActiveModel when errors on field is nil' do
+ let(:model) { model_class.find 1 }
+ before { model; Acfs.run }
+
+ before do
+ stub_request(:put, 'http://users.example.org/users/1')
+ .with(body: '{"id":1,"name":"","age":12}')
+ .to_return response({ errors: { name: [ 'required' ] }}, status: 422)
+ end
+ end
end
describe '.create!' do
context 'with valid data' do
let(:data) { { name: 'Idefix', age: 12 } }
@@ -196,11 +207,11 @@
context 'with invalid data' do
let(:data) { { age: 12 } }
it 'should raise an error' do
expect { model_class.create! data }.to raise_error ::Acfs::InvalidResource do |error|
- expect(error.errors).to be == { name: %w(required) }.stringify_keys
+ expect(error.errors).to be == { name: %w(required) }
end
end
end
end
@@ -228,10 +239,10 @@
expect(model).to_not be_persisted
end
it 'should contain error hash' do
model = model_class.create data
- expect(model.errors.to_hash).to be == { name: %w(required) }.stringify_keys
+ expect(model.errors.to_hash).to be == { name: %w(required) }
end
end
end
end