Sha256: 3d9d5ea94ef49fd7b6c69bf0720fc59d68e13619584113baa09e65adb1737e86

Contents?: true

Size: 1.24 KB

Versions: 9

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe Azeroth::RequestHandler::Update do
  describe '#process' do
    let!(:document) { create(:document) }

    it_behaves_like 'a request handler' do
      let(:expected_resource) { document }

      let(:extra_params) do
        {
          id: document.id,
          document: {
            name: 'New Name'
          }
        }
      end

      let(:expected_json) do
        decorator.as_json.merge('name' => 'New Name')
      end

      it 'updates the values' do
        expect { handler.process }
          .to change { document.reload.name }
          .from(document.name)
          .to('New Name')
      end
    end

    context 'when payload is invalid' do
      it_behaves_like 'a request handler',
                      status: :unprocessable_entity do
        let(:expected_resource) { document }
        let(:extra_params) do
          {
            id: document.id,
            document: {
              name: nil
            }
          }
        end

        let(:expected_json) do
          { 'name' => nil }
        end

        it 'does not update entry' do
          expect { handler.process }
            .not_to(change { document.reload.name })
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
azeroth-0.6.5 spec/lib/azeroth/request_handler/update_spec.rb
azeroth-0.6.4 spec/lib/azeroth/request_handler/update_spec.rb
azeroth-0.6.3 spec/lib/azeroth/request_handler/update_spec.rb
azeroth-0.6.2 spec/lib/azeroth/request_handler/update_spec.rb
azeroth-0.6.1 spec/lib/azeroth/request_handler/update_spec.rb
azeroth-0.6.0 spec/lib/azeroth/request_handler/update_spec.rb
azeroth-0.5.0 spec/lib/azeroth/request_handler/update_spec.rb
azeroth-0.4.0 spec/lib/azeroth/request_handler/update_spec.rb
azeroth-0.3.0 spec/lib/azeroth/request_handler/update_spec.rb