Skip to content

Commit

Permalink
don't raise error when pass quiet as true in find
Browse files Browse the repository at this point in the history
  • Loading branch information
Giallombardo Nathan committed Apr 29, 2024
1 parent 83d5531 commit e56d9a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/couchbase-orm/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,14 @@ def find(*ids, quiet: false)

ids = ids.flatten.select { |id| id.present? }
if ids.empty?
raise CouchbaseOrm::Error::EmptyNotAllowed, 'no id(s) provided'
raise CouchbaseOrm::Error::EmptyNotAllowed, 'no id(s) provided' unless quiet
return nil if quiet
end

transcoder = CouchbaseOrm::JsonTranscoder.new(ignored_properties: ignored_properties)
records = quiet ? collection.get_multi(ids, transcoder: transcoder) : collection.get_multi!(ids, transcoder: transcoder)
return nil if records.nil?

CouchbaseOrm.logger.debug { "Base.find found(#{records})" }
records = records.zip(ids).map { |record, id|
self.new(record, id: id) if record
Expand Down
8 changes: 8 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ class BaseTestWithIgnoredProperties < CouchbaseOrm::Base
expect(base.created_at).to be_a(Time)
end

it 'should raise error when get object by nil id with quiet as false' do
expect { BaseTest.find(nil, quiet: false) }.to raise_error(CouchbaseOrm::Error::EmptyNotAllowed)
end

it 'should not raise error when get object by nil id with quiet as true' do
expect { BaseTest.find(nil, quiet: true) }.not_to raise_error
end

describe BaseTest do
it_behaves_like "ActiveModel"
end
Expand Down

0 comments on commit e56d9a7

Please sign in to comment.