Sha256: b7a45a01a8ee9a291aba2a0815e84826b4ca43e7efa1c45751eebebe52697e14

Contents?: true

Size: 825 Bytes

Versions: 22

Compression:

Stored size: 825 Bytes

Contents

require 'spec_helper'

describe Parametric::Schema do
  it "expands fields dynamically" do
    schema = described_class.new do
      field(:title).type(:string).present
      expand(/^attr_(.+)/) do |match|
        field(match[1]).type(:string)
      end
      expand(/^validate_(.+)/) do |match|
        field(match[1]).type(:string).present
      end
    end

    out = schema.resolve({
      title: "foo",
      :"attr_Attribute 1" => "attr 1",
      :"attr_Attribute 2" => "attr 2",
      :"validate_valid_attr" => "valid",
      :"validate_invalid_attr" => "",
    })

    expect(out.output[:title]).to eq 'foo'
    expect(out.output[:"Attribute 1"]).to eq 'attr 1'
    expect(out.output[:"Attribute 2"]).to eq 'attr 2'

    expect(out.errors['$.invalid_attr']).to eq ['is required and value must be present']
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
parametric-0.2.21 spec/expand_spec.rb
parametric-0.2.20 spec/expand_spec.rb
parametric-0.2.19 spec/expand_spec.rb
parametric-0.2.18 spec/expand_spec.rb
parametric-0.2.17 spec/expand_spec.rb
parametric-0.2.16 spec/expand_spec.rb
parametric-0.2.15 spec/expand_spec.rb
parametric-0.2.14 spec/expand_spec.rb
parametric-0.2.13 spec/expand_spec.rb
parametric-0.2.12 spec/expand_spec.rb
parametric-0.2.11 spec/expand_spec.rb
parametric-0.2.10 spec/expand_spec.rb
parametric-0.2.9 spec/expand_spec.rb
parametric-0.2.8 spec/expand_spec.rb
parametric-0.2.7 spec/expand_spec.rb
parametric-0.2.6 spec/expand_spec.rb
parametric-0.2.5 spec/expand_spec.rb
parametric-0.2.4 spec/expand_spec.rb
parametric-0.2.3 spec/expand_spec.rb
parametric-0.2.2 spec/expand_spec.rb