diff --git a/lib/rest_in_peace/active_model_api.rb b/lib/rest_in_peace/active_model_api.rb index a2ed2c4..44d3544 100644 --- a/lib/rest_in_peace/active_model_api.rb +++ b/lib/rest_in_peace/active_model_api.rb @@ -46,6 +46,11 @@ def create_with_dirty_tracking valid? end + def update(attributes) + update_attributes(attributes) + save + end + def valid? !errors.any? end diff --git a/spec/rest_in_peace/active_model_api_spec.rb b/spec/rest_in_peace/active_model_api_spec.rb index 6fc317a..052c5a1 100644 --- a/spec/rest_in_peace/active_model_api_spec.rb +++ b/spec/rest_in_peace/active_model_api_spec.rb @@ -168,6 +168,27 @@ def extended_class.model_name end end + describe '#update' do + let(:new_attributes) { { name: 'new_name', description: 'yoloswag' } } + + subject { instance } + + it 'saves record after update' do + expect(subject).to receive(:save) + + subject.update(new_attributes) + end + + specify do + expect { subject.update(new_attributes) }. + to change(instance, :description).from(attributes[:description]).to(new_attributes[:description]) + end + + specify do + expect { subject.update(new_attributes) }.to_not change(instance, :name).from(attributes[:name]) + end + end + describe 'validation handling' do before do def extended_class.model_name