Sha256: 4d9f6ada2efdc7132efcf334d2158ec36ea3733e9149e1ad60a950f665041360

Contents?: true

Size: 1017 Bytes

Versions: 7

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

RSpec.describe Macros::Contract::ExtractParams do
  subject(:extract_params_step) { described_class.new(params) }

  let(:params) { { from: from } }

  class self::UserForm < Reform::Form # rubocop:disable Style/ClassAndModuleChildren
    property :password

    def build_errors; end
  end

  let(:user) { stub_model(User) }
  let(:contract) { self.class::UserForm.new(user) }
  let(:scope) { :user }
  let(:password) { '$3cr3t' }
  let(:from) { :scope }
  let(:ctx) { { scope: :user, params: { user: { password: password } } } }

  it 'expects to set params in contract' do
    extract_params_step.call(ctx, params: params)

    expect(ctx['contract.default.params'][:password]).to eql password
  end

  context 'from key does not exist' do
    let(:from) { :scoped_to }

    it 'expects to fail and do not set any params in contract' do
      expect(extract_params_step.call(ctx, params: params)).to eql false
      expect(ctx['contract.default.params']).to be nil
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ff-tbl-macros-2.0.2 spec/lib/contract/extract_params_spec.rb
ff-tbl-macros-2.0.1 spec/lib/contract/extract_params_spec.rb
ff-tbl-macros-2.0.0 spec/lib/contract/extract_params_spec.rb
ff-tbl-macros-1.0.2 spec/lib/contract/extract_params_spec.rb
ff-tbl-macros-1.0.1 spec/lib/contract/extract_params_spec.rb
ff-tbl-macros-1.0.0 spec/lib/contract/extract_params_spec.rb
ff-tbl-macros-0.1.8 spec/lib/contract/extract_params_spec.rb