Skip to content

Commit

Permalink
attributes method will return HashWithIndifferentAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
Giallombardo Nathan committed May 28, 2024
1 parent 5b31677 commit bf2fbbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/couchbase-orm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down

0 comments on commit bf2fbbd

Please sign in to comment.