Sha256: 0f5411aef18de7e999493bf1e54064c0518cbe82d8b8f3176c0c2ea0d14e9be8

Contents?: true

Size: 988 Bytes

Versions: 9

Compression:

Stored size: 988 Bytes

Contents

module LightServiceExt
  RSpec.describe ApplicationValidatorAction do
    let(:action_class) do
      Class.new(ApplicationValidatorAction) do
        self.contract_class = Class.new(ApplicationContract) do
          params { required(:key).filled(:string) }
        end
      end
    end

    let(:value) { 'some-value' }
    let(:input) { { key: value } }
    let(:ctx) { ApplicationContext.make_with_defaults(input) }

    subject(:context) { action_class.execute(ctx) }

    context 'with valid attributes' do
      it 'returns promised params and empty errors' do
        expect(context.success?).to be(true)
        expect(context.errors).to be_empty
        expect(context[:params].keys).to eql(%i[key])
      end
    end

    context 'with invalid attributes' do
      let(:value) { nil }

      it 'returns promised params and filled in errors' do
        expect(context).to be_failure
        expect(context.errors).to eql(key: ['must be filled'])
      end
    end
  end
end


Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
light-service-ext-0.1.11 spec/light-service-ext/application_validator_action_spec.rb
light-service-ext-0.1.10 spec/light-service-ext/application_validator_action_spec.rb
light-service-ext-0.1.9 spec/light-service-ext/application_validator_action_spec.rb
light-service-ext-0.1.8 spec/light-service-ext/application_validator_action_spec.rb
light-service-ext-0.1.7 spec/light-service-ext/application_validator_action_spec.rb
light-service-ext-0.1.6 spec/light-service-ext/application_validator_action_spec.rb
light-service-ext-0.1.5 spec/light-service-ext/application_validator_action_spec.rb
light-service-ext-0.1.4 spec/light-service-ext/application_validator_action_spec.rb
light-service-ext-0.1.3 spec/light-service-ext/application_validator_action_spec.rb