diff --git a/lib/couchbase-orm/base.rb b/lib/couchbase-orm/base.rb index dd741359..60e0b4e6 100644 --- a/lib/couchbase-orm/base.rb +++ b/lib/couchbase-orm/base.rb @@ -187,6 +187,10 @@ def initialize(model = nil, ignore_doc_type: false, **attributes) run_callbacks :initialize end + def attributes + super.with_indifferent_access + end + def [](key) send(key) end diff --git a/spec/base_spec.rb b/spec/base_spec.rb index d6606490..b78038a1 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -201,6 +201,11 @@ class BaseTestWithIgnoredProperties < CouchbaseOrm::Base expect{base.id = "foo"}.to raise_error(RuntimeError, 'ID cannot be changed') end + it "attributes should be HashWithIndifferentAccess" do + base = BaseTest.create!(name: 'joe') + expect(base.attributes.class).to be(HashWithIndifferentAccess) + end + if ActiveModel::VERSION::MAJOR >= 6 it "should have timestamp attributes for create in model" do expect(TimestampTest.timestamp_attributes_for_create_in_model).to eq(["created_at"])