Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add breaking test to cover double join errors #512

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions spec/services/forest_liana/resources_getter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,36 @@ def init_scopes
expect(count).to eq 5
expect(records.map(&:id)).to eq [1, 4, 5, 3, 2]
end

it 'should include associated table only once' do
sql_query = getter.perform.to_sql
location_includes_count = sql_query.scan('LEFT OUTER JOIN "locations"').count
expect(location_includes_count).to eq(1)
end

context 'when fields is given' do
let(:filters) { {
field: 'location:id',
operator: 'equal',
value: 1,
}.to_json }

it 'should get only the expected records' do
getter.perform
records = getter.records
count = getter.count

expect(records.count).to eq 1
expect(count).to eq 1
expect(records.map(&:id)).to eq [1]
end

it 'should include associated table only once' do
sql_query = getter.perform.to_sql
location_includes_count = sql_query.scan('LEFT OUTER JOIN "locations"').count
expect(location_includes_count).to eq(1)
end
end
end

describe 'when filtering on an ambiguous field' do
Expand Down