Sha256: 9854df96c7f1f662dd699b1686d02a549b2f3a6d06dc917231096fe0be1a495a

Contents?: true

Size: 1.19 KB

Versions: 23

Compression:

Stored size: 1.19 KB

Contents

require_relative 'helper'

module Test
  class User < MxHero::API::Resource

    attribute :name, map: 'firstName'
    attribute :last_name, map: 'lastName'
    attribute :age
    attribute :last_update, map: 'lastUpdate', date: true
  end

  class Account < MxHero::API::Resource
    attributes :name, :number, :active
    
    attribute :name, map: 'accountName'
    attribute :number, map: 'sn'
    attribute :updated, date: true
  end
end

class ResourceTest < Minitest::Test

  def info
    @info ||= {
      age: 23,
      firstName: 'John',
      lastName: 'Doe',
      lastUpdate: "1371741047000"
    }
  end

  def test_instance
    user = Test::User.new info

    assert_equal 23, user.age
    assert_equal 'John', user.name
    assert_equal 'Doe', user.last_name
    assert_equal DateTime.strptime(info[:lastUpdate].to_s, '%Q'), user.last_update
  end

  def test_to_json
    user = Test::User.new info
    assert_equal info.to_json, user.to_json
  end

  def test_attributes_and_map
    data = {
      accountName: 'account 12',
      sn: 1234567890,
      active: true,
      updated: 1371741047000
    }
    account = Test::Account.new data

    assert_equal data[:accountName], account.name

  end

end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mxhero-api-1.2.9 test/test_resource.rb
mxhero-api-1.2.8 test/test_resource.rb
mxhero-api-1.2.7 test/test_resource.rb
mxhero-api-1.2.6 test/test_resource.rb
mxhero-api-1.2.5 test/test_resource.rb
mxhero-api-1.2.4 test/test_resource.rb
mxhero-api-1.2.3 test/test_resource.rb
mxhero-api-1.2.2 test/test_resource.rb
mxhero-api-1.2.1 test/test_resource.rb
mxhero-api-1.2.0 test/test_resource.rb
mxhero-api-1.1.4 test/test_resource.rb
mxhero-api-1.1.3 test/test_resource.rb
mxhero-api-1.1.2 test/test_resource.rb
mxhero-api-1.1.1 test/test_resource.rb
mxhero-api-1.1.0 test/test_resource.rb
mxhero-api-1.0.5 test/test_resource.rb
mxhero-api-1.0.4 test/test_resource.rb
mxhero-api-1.0.3 test/test_resource.rb
mxhero-api-1.0.2 test/test_resource.rb
mxhero-api-1.0.1 test/test_resource.rb