diff --git a/CHANGELOG.md b/CHANGELOG.md index 458e55a..dcde3f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Changed ### Fixed +- Stopped an issue of primary_key detection failing due to invalid attribute types being passed in (`.to_sym` occurs earlier) ### Security diff --git a/lib/testing_record/model.rb b/lib/testing_record/model.rb index 9cff562..6c96a3e 100644 --- a/lib/testing_record/model.rb +++ b/lib/testing_record/model.rb @@ -25,6 +25,7 @@ class << self # # @return [TestingRecord::Model] def create(attributes) + attributes.transform_keys!(&:to_sym) if respond_to?(:all) create_with_caching(attributes) else @@ -66,7 +67,7 @@ def delete_by_id(id) def create_with_caching(attributes) ensure_primary_key_presence(attributes) ensure_deduplication(attributes) - new(attributes.transform_keys(&:to_sym)).tap do |entity| + new(attributes).tap do |entity| configure_data(entity, attributes) add_helpers(attributes) if entity.class.instance_variable_get(:@include_helpers) cache_entity(entity) @@ -75,7 +76,7 @@ def create_with_caching(attributes) def create_without_caching(attributes) ensure_primary_key_presence(attributes) - new(attributes.transform_keys(&:to_sym)).tap do |entity| + new(attributes).tap do |entity| configure_data(entity, attributes) add_helpers(attributes) if entity.class.instance_variable_get(:@include_helpers) end