Sha256: 6a6a5caf66fc51bd8c2a20d12b30d8fb5582eba1970e9113486a31ca2328d188

Contents?: true

Size: 1.24 KB

Versions: 4

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

class Client
  attr_accessor :first_name, :last_name, :addresses, :id
end

describe SchemaTools::Hash do

  context 'from_schema' do
    let(:client){Client.new}
    before :each do
      client.first_name = 'Peter'
      client.last_name = 'Paul'
      client.id = 'SomeID'
    end
    after :each do
      SchemaTools::Reader.registry_reset
    end

    it 'should return hash' do
      hash = SchemaTools::Hash.from_schema(client)
      hash['client']['last_name'].should == 'Paul'
    end

    it 'should use custom schema path' do
      custom_path = File.expand_path('../../fixtures', __FILE__)
      hash = SchemaTools::Hash.from_schema(client, path: custom_path)
      hash['client']['last_name'].should == 'Paul'
    end

    it 'should use custom schema' do
      hash = SchemaTools::Hash.from_schema(client, class_name: :contact)
      hash['contact']['last_name'].should == 'Paul'
    end

    it 'should use only give fields' do
      hash = SchemaTools::Hash.from_schema(client, fields: ['id', 'last_name'])
      hash['client'].keys.length.should == 2
      hash['client']['last_name'].should == client.last_name
      hash['client']['id'].should == client.id
      hash['client']['first_name'].should be_nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
json_schema_tools-0.0.5 spec/schema_tools/hash_spec.rb
json_schema_tools-0.0.4 spec/schema_tools/hash_spec.rb
json_schema_tools-0.0.3 spec/schema_tools/hash_spec.rb
json_schema_tools-0.0.2 spec/schema_tools/hash_spec.rb