require "schema/field_definitions"
require "schema/document_types"

def schema_dir
  File.expand_path('../config/schema', File.dirname(__FILE__))
end

def sample_field_definitions(fields=nil)
  @sample_field_definitions ||= FieldDefinitionParser.new(schema_dir).parse
  if fields.nil?
    @sample_field_definitions
  else
    @sample_field_definitions.select { |field, _|
      fields.include?(field)
    }
  end
end

def sample_document_types
  @sample_document_types ||= DocumentTypesParser.new(schema_dir, sample_field_definitions).parse
end

Add helper to get sample schemas for use in tests
Add helper to get sample schemas for use in tests

The schemas provided by these helpers are based on the "real" schema in
config.  This is more like the normal pattern of an app testing against
the database models it's actually using, rather than abstract potential
models.  I want to move rummager's tests in this direction in general,
since they're often testing for more generic support for things that
we're not actually using.  We'll then be able to remove code from
rummager that is only being run by tests, not by production systems.

Two helpers are provided:
 - `sample_field_definitions`: returns a hash from field_name to
   FieldDefinition.  Can be parameterised to specify a subset of fields
   to return.
 - `sample_document_types`: returns a hash from document type name to
   DocumentType.
