Skip to content

Commit

Permalink
bug(CustomerQuery) - Allow searching on legal_name (#2851)
Browse files Browse the repository at this point in the history
## Description

We're allowing searching on name, firstname, lastname.
we've forgotten legal_name. This PR fixes that.
  • Loading branch information
nudded authored Nov 22, 2024
1 parent 681d847 commit eb186ee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Customer < ApplicationRecord
validates :email, email: true, if: :email?

def self.ransackable_attributes(_auth_object = nil)
%w[id name firstname lastname external_id email]
%w[id name firstname lastname legal_name external_id email]
end

def display_name(prefer_legal_name: true)
Expand Down
1 change: 1 addition & 0 deletions app/queries/customers_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def search_params
name_cont: search_term,
firstname_cont: search_term,
lastname_cont: search_term,
legal_name_cont: search_term,
external_id_cont: search_term,
email_cont: search_term
}
Expand Down
21 changes: 18 additions & 3 deletions spec/queries/customers_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
let(:organization) { membership.organization }

let(:customer_first) do
create(:customer, organization:, name: 'defgh', firstname: 'John', lastname: 'Doe', external_id: '11', email: '1@example.com')
create(:customer, organization:, name: 'defgh', firstname: 'John', lastname: 'Doe', legal_name: "Legalname", external_id: '11', email: '1@example.com')
end
let(:customer_second) do
create(:customer, organization:, name: 'abcde', firstname: 'Jane', lastname: 'Smith', external_id: '22', email: '2@example.com')
create(:customer, organization:, name: 'abcde', firstname: 'Jane', lastname: 'Smith', legal_name: "other name", external_id: '22', email: '2@example.com')
end
let(:customer_third) do
create(:customer, organization:, name: 'presuv', firstname: 'Mary', lastname: 'Johnson', external_id: '33', email: '3@example.com')
create(:customer, organization:, name: 'presuv', firstname: 'Mary', lastname: 'Johnson', legal_name: "Company name", external_id: '33', email: '3@example.com')
end

before do
Expand Down Expand Up @@ -101,4 +101,19 @@
end
end
end

context 'when searching for legalname "Company"' do
let(:search_term) { 'Company' }

it 'returns only one customer' do
returned_ids = result.customers.pluck(:id)

aggregate_failures do
expect(returned_ids.count).to eq(1)
expect(returned_ids).not_to include(customer_first.id)
expect(returned_ids).not_to include(customer_second.id)
expect(returned_ids).to include(customer_third.id)
end
end
end
end

0 comments on commit eb186ee

Please sign in to comment.