add indifferent access to the attributes
Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
parent
f4f68885ef
commit
8377646d68
@ -1,6 +1,7 @@
|
||||
require 'active_support'
|
||||
require 'active_support/core_ext/class/attribute_accessors'
|
||||
require 'active_support/core_ext/class/inheritable_attributes'
|
||||
require 'active_support/core_ext/hash/indifferent_access'
|
||||
require 'active_support/core_ext/kernel/reporting'
|
||||
require 'active_support/core_ext/module/attr_accessor_with_default'
|
||||
require 'active_support/core_ext/module/delegation'
|
||||
@ -770,7 +771,7 @@ def split_options(options = {})
|
||||
# my_other_course = Course.new(:name => "Philosophy: Reason and Being", :lecturer => "Ralph Cling")
|
||||
# my_other_course.save
|
||||
def initialize(attributes = {})
|
||||
@attributes = {}
|
||||
@attributes = {}.with_indifferent_access
|
||||
@prefix_options = {}
|
||||
load(attributes)
|
||||
end
|
||||
|
@ -68,6 +68,19 @@ def test_load_simple_hash
|
||||
assert_equal @matz.stringify_keys, @person.load(@matz).attributes
|
||||
end
|
||||
|
||||
def test_after_load_attributes_are_accessible
|
||||
assert_equal Hash.new, @person.attributes
|
||||
assert_equal @matz.stringify_keys, @person.load(@matz).attributes
|
||||
assert_equal @matz[:name], @person.attributes['name']
|
||||
end
|
||||
|
||||
def test_after_load_attributes_are_accessible_via_indifferent_access
|
||||
assert_equal Hash.new, @person.attributes
|
||||
assert_equal @matz.stringify_keys, @person.load(@matz).attributes
|
||||
assert_equal @matz[:name], @person.attributes['name']
|
||||
assert_equal @matz[:name], @person.attributes[:name]
|
||||
end
|
||||
|
||||
def test_load_one_with_existing_resource
|
||||
address = @person.load(:street_address => @first_address).street_address
|
||||
assert_kind_of StreetAddress, address
|
||||
|
@ -102,6 +102,9 @@ def setup
|
||||
Person.password = nil
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Tests relating to setting up the API-connection configuration
|
||||
########################################################################
|
||||
|
||||
def test_site_accessor_accepts_uri_or_string_argument
|
||||
site = URI.parse('http://localhost')
|
||||
@ -509,6 +512,11 @@ def test_updating_baseclass_timeout_wipes_descendent_cached_connection_objects
|
||||
assert_not_equal(first_connection, second_connection, 'Connection should be re-created')
|
||||
end
|
||||
|
||||
|
||||
########################################################################
|
||||
# Tests for setting up remote URLs for a given model (including adding
|
||||
# parameters appropriately)
|
||||
########################################################################
|
||||
def test_collection_name
|
||||
assert_equal "people", Person.collection_name
|
||||
end
|
||||
@ -637,6 +645,10 @@ def test_custom_prefix
|
||||
assert_equal [:person_id].to_set, StreetAddress.__send__(:prefix_parameters)
|
||||
end
|
||||
|
||||
|
||||
########################################################################
|
||||
# Tests basic CRUD functions (find/save/create etc)
|
||||
########################################################################
|
||||
def test_respond_to
|
||||
matz = Person.find(1)
|
||||
assert matz.respond_to?(:name)
|
||||
@ -910,6 +922,9 @@ def test_delete_with_410_gone
|
||||
assert_raise(ActiveResource::ResourceGone) { Person.find(1) }
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Tests the more miscelaneous helper methods
|
||||
########################################################################
|
||||
def test_exists
|
||||
# Class method.
|
||||
assert !Person.exists?(nil)
|
||||
|
Loading…
Reference in New Issue
Block a user