From ded02ef8132a5ffd083850e1e34c42bacd54be40 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Thu, 13 Jul 2023 17:29:45 +0100 Subject: [PATCH] feat: start to update tests --- app/models/lettings_log.rb | 2 +- app/models/log.rb | 6 +++--- app/models/sales_log.rb | 2 +- app/services/filter_manager.rb | 2 +- app/views/logs/_log_filters.html.erb | 2 +- spec/components/lettings_log_summary_component_spec.rb | 2 +- spec/features/lettings_log_spec.rb | 2 +- spec/features/organisation_spec.rb | 4 ++-- spec/features/sales_log_spec.rb | 2 +- spec/models/lettings_log_spec.rb | 6 +++--- spec/models/user_spec.rb | 6 +++--- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index 4662cf7ec..a1094ee37 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -52,7 +52,7 @@ class LettingsLog < Log } scope :filter_by_before_startdate, ->(date) { where("lettings_logs.startdate >= ?", date) } scope :unresolved, -> { where(unresolved: true) } - scope :filter_by_organisation, ->(org) { where(owning_organisation: org).or(where(managing_organisation: org)) } + scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :duplicate_logs, lambda { |log| visible .where(log.slice(*DUPLICATE_LOG_ATTRIBUTES)) diff --git a/app/models/log.rb b/app/models/log.rb index 04c3f1ca2..45f638c56 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -29,8 +29,8 @@ class Log < ApplicationRecord scope :visible, -> { where(status: %w[not_started in_progress completed]) } scope :exportable, -> { where(status: %w[not_started in_progress completed deleted]) } - scope :filter_by_status, ->(status) { where status: } - scope :filter_by_years, lambda { |years| + scope :filter_by_status, ->(status, _user = nil) { where status: } + scope :filter_by_years, lambda { |years, _user = nil| first_year = years.shift query = filter_by_year(first_year) years.each { |year| query = query.or(filter_by_year(year)) } @@ -38,7 +38,7 @@ class Log < ApplicationRecord } scope :filter_by_postcode, ->(postcode_full) { where("REPLACE(postcode_full, ' ', '') ILIKE ?", "%#{postcode_full.delete(' ')}%") } scope :filter_by_id, ->(id) { where(id:) } - scope :filter_by_user, ->(selected_user) { where(created_by: selected_user) } + scope :filter_by_user, ->(selected_user, _user = nil) { where(created_by: selected_user) } scope :filter_by_bulk_upload_id, lambda { |bulk_upload_id, user| joins(:bulk_upload) .where(bulk_upload: { id: bulk_upload_id, user: }) diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 053327563..ae76e32c3 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -40,7 +40,7 @@ class SalesLog < Log .or(filter_by_postcode(param)) .or(filter_by_id(param)) } - scope :filter_by_organisation, ->(org) { where(owning_organisation: org) } + scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org) } scope :duplicate_logs, lambda { |log| visible.where(log.slice(*DUPLICATE_LOG_ATTRIBUTES)) .where.not(id: log.id) diff --git a/app/services/filter_manager.rb b/app/services/filter_manager.rb index 17f0aae52..09e08893b 100644 --- a/app/services/filter_manager.rb +++ b/app/services/filter_manager.rb @@ -24,7 +24,7 @@ class FilterManager next if category == "organisation" && all_orgs next if category == "assigned_to" - logs = logs.public_send("filter_by_#{category}", values) + logs = logs.public_send("filter_by_#{category}", values, user) end logs = logs.order(created_at: :desc) if user.support? diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index 33a38434d..2aa66b418 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -41,6 +41,7 @@ label: "Status", category: "status", } %> + <% end %> <%= render partial: "filters/radio_filter", locals: { @@ -61,7 +62,6 @@ label: "Assigned to", category: "assigned_to", } %> - <% end %> <% if (@current_user.support? || @current_user.organisation.has_managing_agents?) && request.path == "/lettings-logs" %> <%= render partial: "filters/radio_filter", locals: { diff --git a/spec/components/lettings_log_summary_component_spec.rb b/spec/components/lettings_log_summary_component_spec.rb index 50885af3c..0c30a1fd8 100644 --- a/spec/components/lettings_log_summary_component_spec.rb +++ b/spec/components/lettings_log_summary_component_spec.rb @@ -17,7 +17,7 @@ RSpec.describe LettingsLogSummaryComponent, type: :component do expect(result).to have_text("General needs") expect(result).to have_text("Tenancy starts #{Time.zone.today.strftime('%e %B %Y').strip}") expect(result).to have_text("Created #{Time.zone.today.strftime('%e %B %Y').strip}") - expect(result).to have_text("by Danny Rojas") + expect(result).to have_text("Assigned to Danny Rojas") expect(result).to have_content("Owned by\n DLUHC") expect(result).to have_content("Managed by\n DLUHC") end diff --git a/spec/features/lettings_log_spec.rb b/spec/features/lettings_log_spec.rb index f74091f5b..df881d824 100644 --- a/spec/features/lettings_log_spec.rb +++ b/spec/features/lettings_log_spec.rb @@ -79,7 +79,7 @@ RSpec.describe "Lettings Log Features" do before do check("Not started") check("In progress") - choose("Yours") + choose("You") click_button("Apply filters") end diff --git a/spec/features/organisation_spec.rb b/spec/features/organisation_spec.rb index 53b8a75cc..e7c853ac2 100644 --- a/spec/features/organisation_spec.rb +++ b/spec/features/organisation_spec.rb @@ -194,7 +194,7 @@ RSpec.describe "User Features" do end check("years-2021-field") click_button("Apply filters") - expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2021&status[]=&user=all") + expect(page).to have_current_path("/organisations/#{org_id}/lettings-logs?years[]=&years[]=2021&status[]=&assigned_to=all") expect(page).not_to have_link first_log.id.to_s, href: "/lettings-logs/#{first_log.id}" end end @@ -227,7 +227,7 @@ RSpec.describe "User Features" do end check("years-2021-field") click_button("Apply filters") - expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?years[]=&years[]=2021&status[]=&user=all") + expect(page).to have_current_path("/organisations/#{org_id}/sales-logs?years[]=&years[]=2021&status[]=&assigned_to=all") expect(page).not_to have_link first_log.id.to_s, href: "/sales-logs/#{first_log.id}" end end diff --git a/spec/features/sales_log_spec.rb b/spec/features/sales_log_spec.rb index 9a2fec455..d39df431b 100644 --- a/spec/features/sales_log_spec.rb +++ b/spec/features/sales_log_spec.rb @@ -116,7 +116,7 @@ RSpec.describe "Sales Log Features" do before do check("Not started") check("In progress") - choose("Yours") + choose("You") click_button("Apply filters") end diff --git a/spec/models/lettings_log_spec.rb b/spec/models/lettings_log_spec.rb index e2a15874a..6a965f1d5 100644 --- a/spec/models/lettings_log_spec.rb +++ b/spec/models/lettings_log_spec.rb @@ -2786,15 +2786,15 @@ RSpec.describe LettingsLog do end it "allows filtering on current user" do - expect(described_class.filter_by_user(%w[yours], created_by_user).count).to eq(2) + expect(described_class.filter_by_user(%w[you]).count).to eq(2) end it "returns all logs when all logs selected" do - expect(described_class.filter_by_user(%w[all], created_by_user).count).to eq(3) + expect(described_class.filter_by_user(%w[all]).count).to eq(3) end it "returns all logs when all and your users selected" do - expect(described_class.filter_by_user(%w[all yours], created_by_user).count).to eq(3) + expect(described_class.filter_by_user(%w[all you]).count).to eq(3) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b9fb91c06..4ec316368 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -142,7 +142,7 @@ RSpec.describe User, type: :model do end it "can filter lettings logs by user, year and status" do - expect(user.logs_filters).to eq(%w[status years user bulk_upload_id]) + expect(user.logs_filters).to eq(%w[status years assigned_to user bulk_upload_id]) end end @@ -152,7 +152,7 @@ RSpec.describe User, type: :model do end it "can filter lettings logs by user, year, status and organisation" do - expect(user.logs_filters).to eq(%w[status years user organisation bulk_upload_id]) + expect(user.logs_filters).to eq(%w[status years assigned_to user organisation bulk_upload_id]) end end end @@ -193,7 +193,7 @@ RSpec.describe User, type: :model do end it "can filter lettings logs by user, year, status and organisation" do - expect(user.logs_filters).to eq(%w[status years user organisation bulk_upload_id]) + expect(user.logs_filters).to eq(%w[status years assigned_to user organisation bulk_upload_id]) end end