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::Unit::TestCase 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