diff --git a/app/components/search_component.rb b/app/components/search_component.rb index 676257263..eefdc5309 100644 --- a/app/components/search_component.rb +++ b/app/components/search_component.rb @@ -9,10 +9,12 @@ class SearchComponent < ViewComponent::Base end def path(current_user) - if request.path.include?("users") - user_path(current_user) + if request.path.include?("organisations") && request.path.include?("users") + request.path elsif request.path.include?("organisations") && request.path.include?("logs") request.path + elsif request.path.include?("users") + user_path(current_user) elsif request.path.include?("organisations") organisations_path elsif request.path.include?("logs") diff --git a/app/views/organisations/users.html.erb b/app/views/organisations/users.html.erb index 082ffb384..67df43109 100644 --- a/app/views/organisations/users.html.erb +++ b/app/views/organisations/users.html.erb @@ -1,6 +1,6 @@ <% item_label = @pagy.count > 1 ? "users" : "user" %> <% if @searched.present? %> - <% title = "Your organisation (#{@pagy.count} #{item_label} matching ‘#{@searched}’ of #{@total_count} total logs)" %> + <% title = "Your organisation (#{@pagy.count} #{item_label} matching ‘#{@searched}’ of #{@total_count} total users)" %> <% else %> <% title = "Your organisation (User)" %> <% end %> diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index b281cbb71..05f400804 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -617,7 +617,9 @@ RSpec.describe OrganisationsController, type: :request do end context "when our search term matches an email and a name" do + let!(:matching_user) { FactoryBot.create(:user, organisation: user.organisation, name: "Matching", email: "some@example.com") } let!(:other_matching_user) { FactoryBot.create(:user, organisation: user.organisation, name: "matching", email: "foobar@example.com") } + let(:org_user_count) { User.where(organisation: user.organisation).count } let(:search_param) { "matching" } it "returns only matching results" do