Skip to content

Commit

Permalink
Merge branch 'main' into fix_eager_load_of_scoped_associations
Browse files Browse the repository at this point in the history
  • Loading branch information
asedge authored Sep 29, 2023
2 parents e9eb7ec + 11a9e10 commit 969e963
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Not released

- Adding `.blank?`, `.present?`, and `.any?` delegators to `ActiveQuery`. (https://github.com/Beyond-Finance/active_force/pull/68)
- Adding `update` and `update!` class methods on `SObject`. (https://github.com/Beyond-Finance/active_force/pull/66)

## 0.17.0
Expand Down
4 changes: 2 additions & 2 deletions lib/active_force/active_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ActiveQuery < Query
attr_reader :sobject, :association_mapping, :belongs_to_association_mapping

def_delegators :sobject, :sfdc_client, :build, :table_name, :mappings
def_delegators :to_a, :each, :map, :inspect, :pluck, :each_with_object
def_delegators :to_a, :blank?, :present?, :any?, :each, :map, :inspect, :pluck, :each_with_object

def initialize (sobject, custom_table_name = nil)
def initialize(sobject, custom_table_name = nil)
@sobject = sobject
@association_mapping = {}
@belongs_to_association_mapping = {}
Expand Down
67 changes: 66 additions & 1 deletion spec/active_force/active_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
]
end


before do
allow(active_query).to receive(:sfdc_client).and_return client
allow(active_query).to receive(:build).and_return Object.new
Expand All @@ -40,6 +39,72 @@
end
end

describe '#blank? delegation' do
before do
allow(client).to receive(:query).and_return(api_result)
end

context 'when there are no records' do
let(:api_result) { [] }

it 'returns true' do
result = active_query.where("Text_Label = 'foo'").blank?
expect(result).to be true
end
end

context 'when records are returned' do
it 'returns false' do
result = active_query.where("Text_Label = 'foo'").blank?
expect(result).to be false
end
end
end

describe '#present? delegation' do
before do
allow(client).to receive(:query).and_return(api_result)
end

context 'when there are no records' do
let(:api_result) { [] }

it 'returns false' do
result = active_query.where("Text_Label = 'foo'").present?
expect(result).to be false
end
end

context 'when there are records' do
it 'returns true' do
result = active_query.where("Text_Label = 'foo'").present?
expect(result).to be true
end
end
end

describe '#any? delegation' do
before do
allow(client).to receive(:query).and_return(api_result)
end

context 'when there are no records' do
let(:api_result) { [] }

it 'returns true' do
result = active_query.where("Text_Label = 'foo'").any?
expect(result).to be false
end
end

context 'when records are returned' do
it 'returns false' do
result = active_query.where("Text_Label = 'foo'").any?
expect(result).to be true
end
end
end

describe "select only some field using mappings" do
it "should return a query only with selected field" do
new_query = active_query.select(:field)
Expand Down

0 comments on commit 969e963

Please sign in to comment.