spec/lib/azeroth/request_handler/update_spec.rb in azeroth-0.8.2 vs spec/lib/azeroth/request_handler/update_spec.rb in azeroth-0.9.0
- old
+ new
@@ -28,9 +28,121 @@
.from(document.name)
.to('New Name')
end
end
+ context 'when update_with option is given ' do
+ context 'with block' do
+ it_behaves_like 'a request handler' do
+ let(:block) do
+ proc do
+ document.assign_attributes(document_params)
+ document.name = "#{document.name}!"
+ document.save
+ end
+ end
+
+ let(:options_hash) do
+ {
+ update_with: block
+ }
+ end
+
+ let(:expected_resource) { document }
+
+ let(:extra_params) do
+ {
+ id: document.id,
+ document: {
+ name: 'New Name'
+ }
+ }
+ end
+
+ let(:expected_json) do
+ {
+ 'name' => 'New Name!'
+ }
+ end
+
+ it 'updates the values given by request' do
+ expect { handler.process }
+ .to change { document.reload.name }
+ .from(document.name)
+ .to('New Name!')
+ end
+ end
+ end
+
+ context 'with symbol' do
+ it_behaves_like 'a request handler' do
+ let(:options_hash) do
+ {
+ update_with: :add_bang_name
+ }
+ end
+
+ let(:expected_resource) { document }
+
+ let(:extra_params) do
+ {
+ id: document.id,
+ document: {
+ name: 'New Name'
+ }
+ }
+ end
+
+ let(:expected_json) do
+ {
+ 'name' => 'New Name!'
+ }
+ end
+
+ it 'updates the values given by request' do
+ expect { handler.process }
+ .to change { document.reload.name }
+ .from(document.name)
+ .to('New Name!')
+ end
+ end
+ end
+
+ context 'with string' do
+ it_behaves_like 'a request handler' do
+ let(:options_hash) do
+ {
+ update_with: 'add_bang_name'
+ }
+ end
+
+ let(:expected_resource) { document }
+
+ let(:extra_params) do
+ {
+ id: document.id,
+ document: {
+ name: 'New Name'
+ }
+ }
+ end
+
+ let(:expected_json) do
+ {
+ 'name' => 'New Name!'
+ }
+ end
+
+ it 'updates the values given by request' do
+ expect { handler.process }
+ .to change { document.reload.name }
+ .from(document.name)
+ .to('New Name!')
+ end
+ end
+ end
+ end
+
context 'with before_save block option' do
it_behaves_like 'a request handler' do
let(:block) do
value = 10
proc do