Sha256: 8a4e0a232ea998b30348ed5998d798a7713ce34db56d6e12d5b5a1cbf032d734

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'

describe 'Schema#walk' do
  let(:schema) do
    Paradocs::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

10 entries across 10 versions & 1 rubygems

Version Path
paradocs-1.1.6 spec/schema_walk_spec.rb
paradocs-1.1.5 spec/schema_walk_spec.rb
paradocs-1.1.4 spec/schema_walk_spec.rb
paradocs-1.1.3 spec/schema_walk_spec.rb
paradocs-1.1.2 spec/schema_walk_spec.rb
paradocs-1.1.1 spec/schema_walk_spec.rb
paradocs-1.1.0 spec/schema_walk_spec.rb
paradocs-1.0.24 spec/schema_walk_spec.rb
paradocs-1.0.23 spec/schema_walk_spec.rb
paradocs-1.0.22 spec/schema_walk_spec.rb