Sha256: 9504d606b632331a0813a4fc19719d7a4ae302e1fccde1ef0d767e41e61be703

Contents?: true

Size: 1.03 KB

Versions: 26

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'

describe 'Schema#walk' do
  let(:schema) do
    Parametric::Schema.new do
      field(:title).meta(example: 'a title', label: 'custom title')
      field(:tags).policy(:array).meta(example: ['tag1', 'tag2'], label: 'comma-separated tags')
      field(:friends).policy(:array).schema do
        field(:name).meta(example: 'a friend', label: 'friend full name')
        field(:age).meta(example: 34, label: 'age')
      end
    end
  end

  it "recursively walks the schema and collects meta data" do
    results = schema.walk(:label)
    expect(results.output).to eq({
      title: 'custom title',
      tags: 'comma-separated tags',
      friends: [
        {
          name: 'friend full name',
          age: 'age'
        }
      ]
    })
  end

  it "works with blocks" do
    results = schema.walk{|field| field.meta_data[:example]}
    expect(results.output).to eq({
      title: 'a title',
      tags: ['tag1', 'tag2'],
      friends: [
        {
          name: 'a friend',
          age: 34
        }
      ]
    })
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

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