Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
first implem
Browse files Browse the repository at this point in the history
  • Loading branch information
pimpin committed Dec 27, 2022
1 parent 3bfab24 commit 320a42b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/couchbase-orm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
require 'couchbase-orm/utilities/index'
require 'couchbase-orm/utilities/has_many'
require 'couchbase-orm/utilities/ensure_unique'
require 'couchbase-orm/utilities/ignored_properties'


module CouchbaseOrm
Expand Down Expand Up @@ -127,6 +128,7 @@ class Base
extend EnsureUnique
extend HasMany
extend Index
extend IgnoredProperties


Metadata = Struct.new(:key, :cas)
Expand Down Expand Up @@ -176,6 +178,9 @@ def find(*ids, quiet: false)
}
records.compact!
ids.length > 1 ? records : records[0]
rescue ActiveModel::UnknownAttributeError => e
unknown_attribute = e.attribute
raise e unless ignored_properties.include? unknown_attribute
end

def find_by_id(*ids, **options)
Expand Down
25 changes: 25 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,29 @@ class TimestampTest < CouchbaseOrm::Base
describe CompareTest do
it_behaves_like "ActiveModel"
end

describe '.ignored_properties' do
class BaseTestWithIgnoredProperties < CouchbaseOrm::Base
ignored_properties :depracted_property
attribute :name, :string
attribute :job, :string
end

it 'returns an array of ignored properties' do
expect(BaseTestWithIgnoredProperties.ignored_properties).to eq(['depracted_property'])
end

it 'ignores the ignored properties on load from db' do
too_much_properties_doc = {
type: BaseTestWithIgnoredProperties.design_document,
name: 'Pierre',
job: 'dev',
depracted_property: 'depracted that could be removed on next save'
}
BaseTestWithIgnoredProperties.bucket.default_collection.upsert 'doc_1', too_much_properties_doc

base = BaseTestWithIgnoredProperties.find_by_id('doc_1')
BaseTestWithIgnoredProperties.bucket.default_collection.remove 'doc_1'
end
end
end

0 comments on commit 320a42b

Please sign in to comment.