Sha256: e7eeef1f329dc5665a082a72aa5c02b4015144cffdcf6c6f1bac87fb98c93102

Contents?: true

Size: 803 Bytes

Versions: 2

Compression:

Stored size: 803 Bytes

Contents

require 'pr/build_model'

describe 'building a model from a form' do
  let(:model)    { Struct.new(:a,:b).new }
  let(:registry) { double fields: [:a,:b] }

  let(:field_a)    { double "field", convert: "a_value" }
  let(:field_b)    { double "field", convert: "b_value" }
  let(:form)       { double "form", __a: field_a, __b: field_b }

  let(:builder)  { PR::BuildModel.new registry }

  it 'gets the fields' do
    expect(registry).to receive(:fields)
    builder.for form, model
  end
  it 'converts fields to values' do
    expect(field_a).to receive(:convert)
    expect(field_b).to receive(:convert)
    builder.for form, model
  end
  it 'iterated over the fields and sets values' do
    builder.for form, model
    expect(model.a).to eq "a_value"
    expect(model.b).to eq "b_value"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pr-1.0.0 spec/unit/pr/build_model_spec.rb
pr-0.0.7 spec/unit/pr/build_model_spec.rb