From 0c589e5bcc3f3c412f0c3c8b128c3e29a3e7be81 Mon Sep 17 00:00:00 2001 From: JG Date: Wed, 1 Jun 2022 08:26:43 +0100 Subject: [PATCH] expanded tests --- .../requests/organisations_controller_spec.rb | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 05f400804..5647cfe7a 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -520,7 +520,7 @@ RSpec.describe OrganisationsController, type: :request do end context "when viewing a specific organisation users" do - let!(:users) { FactoryBot.create_list(:user, 5, organisation: user.organisation) } + let!(:users) { FactoryBot.create_list(:user, 5, organisation:) } let!(:different_org_users) { FactoryBot.create_list(:user, 5) } before do @@ -550,8 +550,8 @@ RSpec.describe OrganisationsController, type: :request do end context "when a search parameter is passed" do - let!(:matching_user) { FactoryBot.create(:user, organisation: user.organisation, name: "joe", email: "matching@example.com") } - let(:org_user_count) { User.where(organisation: user.organisation).count } + let!(:matching_user) { FactoryBot.create(:user, organisation:, name: "joe", email: "matching@example.com") } + let(:org_user_count) { User.where(organisation:).count } before do get "/organisations/#{user.organisation.id}/users?search=#{search_param}" @@ -562,6 +562,7 @@ RSpec.describe OrganisationsController, type: :request do it "returns only matching results" do expect(page).to have_content(matching_user.name) + expect(page).not_to have_link(user.name) different_org_users.each do |different_org_user| expect(page).not_to have_content(different_org_user.email) @@ -581,6 +582,7 @@ RSpec.describe OrganisationsController, type: :request do it "returns only matching results" do expect(page).to have_content(matching_user.name) + expect(page).not_to have_link(user.name) different_org_users.each do |different_org_user| expect(page).not_to have_content(different_org_user.email) @@ -602,6 +604,7 @@ RSpec.describe OrganisationsController, type: :request do it "returns only matching results" do expect(page).to have_content(matching_user.name) + expect(page).not_to have_link(user.name) different_org_users.each do |different_org_user| expect(page).not_to have_content(different_org_user.email) @@ -617,14 +620,19 @@ 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" } + let!(:matching_user) { FactoryBot.create(:user, organisation:, name: "Foobar", email: "some@example.com") } + let!(:another_matching_user) { FactoryBot.create(:user, organisation:, name: "Joe", email: "foobar@example.com") } + let!(:org_user_count) { User.where(organisation:).count } + let(:search_param) { "Foobar" } + + before do + get "/organisations/#{user.organisation.id}/users?search=#{search_param}" + end it "returns only matching results" do - expect(page).to have_content(matching_user.name) - expect(page).to have_content(other_matching_user.name) + expect(page).to have_link(matching_user.name) + expect(page).to have_link(another_matching_user.name) + expect(page).not_to have_link(user.name) different_org_users.each do |different_org_user| expect(page).not_to have_content(different_org_user.email)