Skip to content

Commit

Permalink
Merge pull request #82 from Mapotempo/fix_attributes
Browse files Browse the repository at this point in the history
Attributes method will return HashWithIndifferentAccess
  • Loading branch information
giallon committed May 28, 2024
2 parents 5b31677 + bf2fbbd commit 6c59e64
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 6c59e64

Please sign in to comment.