diff --git a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee index 2efdb843f3..430b7530db 100644 --- a/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee +++ b/app/assets/javascripts/admin/line_items/controllers/line_items_controller.js.coffee @@ -22,6 +22,7 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout, "order_bill_address_phone", "order_bill_address_firstname", "order_bill_address_lastname", + "order_bill_address_full_name", "variant_product_supplier_name", "order_email", "order_number", diff --git a/app/models/spree/address.rb b/app/models/spree/address.rb index 998cb0ec4f..2b917f18cb 100644 --- a/app/models/spree/address.rb +++ b/app/models/spree/address.rb @@ -4,7 +4,7 @@ module Spree class Address < ApplicationRecord include AddressDisplay - searchable_attributes :firstname, :lastname, :phone + searchable_attributes :firstname, :lastname, :phone, :full_name searchable_associations :country, :state belongs_to :country, class_name: "Spree::Country" @@ -28,6 +28,12 @@ module Spree alias_attribute :last_name, :lastname delegate :name, to: :state, prefix: true, allow_nil: true + ransacker :full_name, formatter: proc { |value| value.to_s } do |parent| + Arel::Nodes::SqlLiteral.new( + "CONCAT(#{parent.table_name}.firstname, ' ', #{parent.table_name}.lastname)" + ) + end + def self.default new(country: DefaultCountry.country) end diff --git a/spec/models/spree/address_spec.rb b/spec/models/spree/address_spec.rb index a1cb4fa8dd..a19eba80f6 100644 --- a/spec/models/spree/address_spec.rb +++ b/spec/models/spree/address_spec.rb @@ -187,4 +187,19 @@ describe Spree::Address do specify { expect(address.state_text).to eq 'virginia' } end end + + describe "ransacker :full_name" do + it "searches for records with matching full names" do + address1 = create(:address, firstname: 'John', lastname: 'Doe') + address2 = create(:address, firstname: 'Jane', lastname: 'Smith') + + result1 = described_class.ransack(full_name_cont: 'John Doe').result + expect(result1).to include(address1) + expect(result1).not_to include(address2) + + result2 = described_class.ransack(full_name_cont: 'Jane Smith').result + expect(result2).to include(address2) + expect(result2).not_to include(address1) + end + end end diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 286984b6be..f20e839ca6 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -158,7 +158,7 @@ distributors: [distributor4, distributor5]) } # filtering by first name fill_in "First name begins with", with: billing_address2.firstname page.find('.filter-actions .button.icon-search').click - # Order 3 should show, but not 2 and 4 + # Order 2 should show, but not 3 and 4 expect(page).to have_content order2.number expect(page).to_not have_content order3.number expect(page).to_not have_content order4.number @@ -172,6 +172,17 @@ distributors: [distributor4, distributor5]) } expect(page).to_not have_content order2.number expect(page).to_not have_content order3.number expect(page).to have_content order4.number + + find("a#clear_filters_button").click + # filtering by first and last name together + + fill_in "First name begins with", with: billing_address3.firstname + fill_in "Last name begins with", with: billing_address3.lastname + page.find('.filter-actions .button.icon-search').click + # Order 3 should show, but not 2 and 4 + expect(page).not_to have_content order2.number + expect(page).to have_content order3.number + expect(page).not_to have_content order4.number end it "filter by shipping methods" do