Browse Source

Rebase changes

pull/1752/head
Kat 3 years ago
parent
commit
a80f3fbd5f
  1. 2
      app/controllers/duplicate_logs_controller.rb
  2. 12
      app/controllers/lettings_logs_controller.rb
  3. 12
      app/controllers/sales_logs_controller.rb
  4. 514
      spec/requests/duplicate_logs_controller_spec.rb

2
app/controllers/duplicate_logs_controller.rb

@ -64,4 +64,4 @@ private
%w[owning_organisation_id saledate purchid age1 sex1 ecstat1 postcode_full] %w[owning_organisation_id saledate purchid age1 sex1 ecstat1 postcode_full]
end end
end end
end end

12
app/controllers/lettings_logs_controller.rb

@ -88,18 +88,6 @@ class LettingsLogsController < LogsController
render "logs/delete_confirmation" render "logs/delete_confirmation"
end end
def delete_duplicates
@log = LettingsLog.visible.find(params[:lettings_log_id])
authorize @log
@duplicate_logs = LettingsLog.duplicate_logs_for_organisation(current_user.organisation, @log)
if @duplicate_logs.empty?
render_not_found
else
render "logs/delete_duplicates"
end
end
def download_csv def download_csv
unpaginated_filtered_logs = filter_manager.filtered_logs(current_user.lettings_logs, search_term, session_filters) unpaginated_filtered_logs = filter_manager.filtered_logs(current_user.lettings_logs, search_term, session_filters)

12
app/controllers/sales_logs_controller.rb

@ -62,18 +62,6 @@ class SalesLogsController < LogsController
render "logs/delete_confirmation" render "logs/delete_confirmation"
end end
def delete_duplicates
@log = SalesLog.visible.find(params[:sales_log_id])
authorize @log
@duplicate_logs = SalesLog.duplicate_logs_for_organisation(current_user.organisation, @log)
if @duplicate_logs.empty?
render_not_found
else
render "logs/delete_duplicates"
end
end
def download_csv def download_csv
unpaginated_filtered_logs = filter_manager.filtered_logs(current_user.sales_logs, search_term, session_filters) unpaginated_filtered_logs = filter_manager.filtered_logs(current_user.sales_logs, search_term, session_filters)

514
spec/requests/duplicate_logs_controller_spec.rb

@ -2,113 +2,67 @@ require "rails_helper"
RSpec.describe DuplicateLogsController, type: :request do RSpec.describe DuplicateLogsController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) } let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { create(:user) } let(:user) { create(:user, :data_coordinator) }
let(:lettings_log) do
context "when a user is signed in" do create(
let(:lettings_log) do :lettings_log,
create( :completed,
:lettings_log, created_by: user,
:completed, owning_organisation: user.organisation,
created_by: user, )
) end
end let(:sales_log) do
let(:sales_log) do create(
create( :sales_log,
:sales_log, :completed,
:completed, created_by: user,
created_by: user, owning_organisation: user.organisation,
) )
end end
describe "GET" do describe "GET show" do
context "when user is not signed in" do context "when user is not signed in" do
it "redirects to sign in page" do it "redirects to sign in page" do
get "/lettings-logs/#{lettings_log.id}/duplicate-logs" get "/lettings-logs/#{lettings_log.id}/duplicate-logs"
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end
end end
end
context "when the user is from different organisation" do context "when the user is from different organisation" do
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
before do before do
allow(other_user).to receive(:need_two_factor_authentication?).and_return(false) allow(other_user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in other_user sign_in other_user
end end
it "renders page not found" do it "renders page not found" do
get "/lettings-logs/#{lettings_log.id}/duplicate-logs" get "/lettings-logs/#{lettings_log.id}/duplicate-logs"
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end
end end
end
context "when user is signed in" do context "when user is signed in" do
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
end end
context "with multiple duplicate lettings logs" do
let(:duplicate_logs) { create_list(:lettings_log, 2, :completed) }
context "with multiple duplicate lettings logs" do before do
let(:duplicate_logs) { create_list(:lettings_log, 2, :completed) } allow(LettingsLog).to receive(:duplicate_logs).and_return(duplicate_logs)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs"
before do
allow(LettingsLog).to receive(:duplicate_logs).and_return(duplicate_logs)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs"
end
it "displays links to all the duplicate logs" do
expect(page).to have_link("Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/lettings-logs/#{duplicate_logs.first.id}")
expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/lettings-logs/#{duplicate_logs.second.id}")
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q5 - Tenancy start date", count: 3)
expect(page).to have_content("Q7 - Tenant code", count: 3)
expect(page).to have_content("Q12 - Postcode", count: 3)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
expect(page).to have_content("Household rent and charges", count: 3)
expect(page).to have_link("Change", count: 21)
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
end
end end
context "with multiple duplicate sales logs" do it "displays links to all the duplicate logs" do
let(:duplicate_logs) { create_list(:sales_log, 2, :completed) } expect(page).to have_link("Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/lettings-logs/#{duplicate_logs.first.id}")
before do expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/lettings-logs/#{duplicate_logs.second.id}")
allow(SalesLog).to receive(:duplicate_logs).and_return(duplicate_logs)
get "/sales-logs/#{sales_log.id}/duplicate-logs"
end
it "displays links to all the duplicate logs" do
expect(page).to have_link("Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/sales-logs/#{duplicate_logs.first.id}")
expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/sales-logs/#{duplicate_logs.second.id}")
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
expect(page).to have_content("Q15 - Postcode", count: 3)
expect(page).to have_link("Change", count: 18)
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
end
end end
it "displays check your answers for each log with correct questions" do it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Stock owner", count: 3)
expect(page).to have_content("Q5 - Tenancy start date", count: 3) expect(page).to have_content("Q5 - Tenancy start date", count: 3)
expect(page).to have_content("Q7 - Tenant code", count: 3) expect(page).to have_content("Q7 - Tenant code", count: 3)
expect(page).to have_content("Q12 - Postcode", count: 3) expect(page).to have_content("Q12 - Postcode", count: 3)
@ -116,7 +70,7 @@ RSpec.describe DuplicateLogsController, type: :request do
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3) expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3) expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
expect(page).to have_content("Household rent and charges", count: 3) expect(page).to have_content("Household rent and charges", count: 3)
expect(page).to have_link("Change", count: 24) expect(page).to have_link("Change", count: 21)
end end
it "displays buttons to delete" do it "displays buttons to delete" do
@ -124,273 +78,209 @@ RSpec.describe DuplicateLogsController, type: :request do
end end
end end
context "when the user is from different organisation" do context "with multiple duplicate sales logs" do
let(:other_user) { create(:user) } let(:duplicate_logs) { create_list(:sales_log, 2, :completed) }
before do before do
allow(other_user).to receive(:need_two_factor_authentication?).and_return(false) allow(SalesLog).to receive(:duplicate_logs).and_return(duplicate_logs)
sign_in other_user get "/sales-logs/#{sales_log.id}/duplicate-logs"
end
it "renders page not found" do
get "/lettings-logs/#{lettings_log.id}/duplicate-logs"
expect(response).to have_http_status(:not_found)
end end
end
context "when user is signed in" do it "displays links to all the duplicate logs" do
before do expect(page).to have_link("Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
allow(user).to receive(:need_two_factor_authentication?).and_return(false) expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/sales-logs/#{duplicate_logs.first.id}")
sign_in user expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/sales-logs/#{duplicate_logs.second.id}")
end end
context "with multiple duplicate lettings logs" do it "displays check your answers for each log with correct questions" do
let(:duplicate_logs) { create_list(:lettings_log, 2, :completed) } expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3)
before do expect(page).to have_content("Q20 - Lead buyer’s age", count: 3)
allow(LettingsLog).to receive(:duplicate_logs_for_organisation).and_return(duplicate_logs) expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
get "/lettings-logs/#{lettings_log.id}/duplicate-logs" expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
end expect(page).to have_content("Q15 - Postcode", count: 3)
expect(page).to have_link("Change", count: 18)
it "displays links to all the duplicate logs" do
expect(page).to have_link("Log #{lettings_log.id}", href: "/lettings-logs/#{lettings_log.id}")
expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/lettings-logs/#{duplicate_logs.first.id}")
expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/lettings-logs/#{duplicate_logs.second.id}")
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Stock owner", count: 3)
expect(page).to have_content("Q5 - Tenancy start date", count: 3)
expect(page).to have_content("Q7 - Tenant code", count: 3)
expect(page).to have_content("Q12 - Postcode", count: 3)
expect(page).to have_content("Q32 - Lead tenant’s age", count: 3)
expect(page).to have_content("Q33 - Lead tenant’s gender identity", count: 3)
expect(page).to have_content("Q37 - Lead tenant’s working situation", count: 3)
expect(page).to have_content("Household rent and charges", count: 3)
expect(page).to have_link("Change", count: 21)
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
end
end end
context "with multiple duplicate sales logs" do it "displays buttons to delete" do
let(:duplicate_logs) { create_list(:sales_log, 2, :completed) } expect(page).to have_link("Keep this log and delete duplicates", count: 3)
before do
allow(SalesLog).to receive(:duplicate_logs).and_return(duplicate_logs)
get "/sales-logs/#{sales_log.id}/duplicate-logs"
end
it "displays links to all the duplicate logs" do
expect(page).to have_link("Log #{sales_log.id}", href: "/sales-logs/#{sales_log.id}")
expect(page).to have_link("Log #{duplicate_logs.first.id}", href: "/sales-logs/#{duplicate_logs.first.id}")
expect(page).to have_link("Log #{duplicate_logs.second.id}", href: "/sales-logs/#{duplicate_logs.second.id}")
end
it "displays check your answers for each log with correct questions" do
expect(page).to have_content("Q1 - Sale completion date", count: 3)
expect(page).to have_content("Q2 - Purchaser code", count: 3)
expect(page).to have_content("Q20 - Lead buyer’s age", count: 3)
expect(page).to have_content("Q21 - Buyer 1’s gender identity", count: 3)
expect(page).to have_content("Q25 - Buyer 1's working situation", count: 3)
expect(page).to have_content("Q15 - Postcode", count: 3)
expect(page).to have_link("Change", count: 18)
end
it "displays buttons to delete" do
expect(page).to have_link("Keep this log and delete duplicates", count: 3)
end
end end
end end
end end
end
describe "GET sales delete-duplicates" do describe "GET sales delete-duplicates" do
let(:headers) { { "Accept" => "text/html" } } let(:headers) { { "Accept" => "text/html" } }
let(:page) { Capybara::Node::Simple.new(response.body) } let(:id) { sales_log.id }
let(:user) { create(:user, :data_coordinator) } let(:request) { get "/sales-logs/#{id}/delete-duplicates" }
let!(:sales_log) do
create(:sales_log, :completed, owning_organisation: user.organisation)
end
let(:id) { sales_log.id }
let(:request) { get "/sales-logs/#{id}/delete-duplicates", headers: } before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
end
before do context "when there are no duplicate logs" do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) it "renders not found" do
sign_in user request
expect(response).to have_http_status(:not_found)
end end
end
context "when there are no duplicate logs" do context "when there is 1 duplicate log being deleted" do
it "renders not found" do let!(:duplicate_log) do
request duplicate = sales_log.dup
expect(response).to have_http_status(:not_found) duplicate.id = nil
end duplicate.save!
duplicate
end end
context "when there is 1 duplicate log being deleted" do it "renders page" do
let!(:duplicate_log) do request
duplicate = sales_log.dup expect(response).to have_http_status(:ok)
duplicate.id = nil
duplicate.save!
duplicate
end
it "renders page" do
request
expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete this duplicate log?") expect(page).to have_content("Are you sure you want to delete this duplicate log?")
expect(page).to have_button(text: "Delete this log") expect(page).to have_button(text: "Delete this log")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id)) expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
expect(page).not_to have_link(text: "Log #{id}", href: sales_log_path(id)) expect(page).not_to have_link(text: "Log #{id}", href: sales_log_path(id))
expect(page).to have_link(text: "Cancel", href: sales_log_path(id)) # update with correct path when known expect(page).to have_link(text: "Cancel", href: sales_log_path(id)) # update with correct path when known
end
end end
end
context "when there are multiple duplicate logs being deleted" do context "when there are multiple duplicate logs being deleted" do
let!(:duplicate_log) do let!(:duplicate_log) do
duplicate = sales_log.dup duplicate = sales_log.dup
duplicate.id = nil duplicate.id = nil
duplicate.save! duplicate.save!
duplicate duplicate
end end
let!(:duplicate_log_2) do let!(:duplicate_log_2) do
duplicate = sales_log.dup duplicate = sales_log.dup
duplicate.id = nil duplicate.id = nil
duplicate.save! duplicate.save!
duplicate duplicate
end end
it "renders page" do it "renders page" do
request request
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete these duplicate logs?") expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
expect(page).to have_content("These logs will be deleted:") expect(page).to have_content("These logs will be deleted:")
expect(page).to have_button(text: "Delete these logs") expect(page).to have_button(text: "Delete these logs")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id)) expect(page).to have_link(text: "Log #{duplicate_log.id}", href: sales_log_path(duplicate_log.id))
expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: sales_log_path(duplicate_log_2.id)) expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: sales_log_path(duplicate_log_2.id))
expect(page).to have_link(text: "Cancel", href: sales_log_path(id)) # update with correct path when known expect(page).to have_link(text: "Cancel", href: sales_log_path(id)) # update with correct path when known
end
end end
end
context "when log does not exist" do context "when log does not exist" do
let(:id) { -1 } let(:id) { -1 }
it "returns 404" do it "returns 404" do
request request
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end
end end
end
context "when user is not authorised" do context "when user is not authorised" do
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
before do before do
allow(other_user).to receive(:need_two_factor_authentication?).and_return(false) allow(other_user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in other_user sign_in other_user
end end
it "returns 404" do it "returns 404" do
request request
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end
end end
end end
end
describe "GET lettings delete-duplicates" do describe "GET lettings delete-duplicates" do
let(:headers) { { "Accept" => "text/html" } } let(:id) { lettings_log.id }
let(:page) { Capybara::Node::Simple.new(response.body) } let(:request) { get "/lettings-logs/#{id}/delete-duplicates" }
let(:user) { create(:user, :data_coordinator) }
let!(:lettings_log) do
create(:lettings_log, :completed, owning_organisation: user.organisation)
end
let(:id) { lettings_log.id }
let(:request) { get "/lettings-logs/#{id}/delete-duplicates", headers: }
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
end end
context "when there are no duplicate logs" do context "when there are no duplicate logs" do
it "renders page not found" do it "renders page not found" do
request request
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end
end end
end
context "when there is 1 duplicate log being deleted" do context "when there is 1 duplicate log being deleted" do
let!(:duplicate_log) do let!(:duplicate_log) do
duplicate = lettings_log.dup duplicate = lettings_log.dup
duplicate.id = nil duplicate.id = nil
duplicate.save! duplicate.save!
duplicate duplicate
end end
it "renders page" do it "renders page" do
request request
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete this duplicate log?") expect(page).to have_content("Are you sure you want to delete this duplicate log?")
expect(page).to have_content("This log will be deleted:") expect(page).to have_content("This log will be deleted:")
expect(page).to have_button(text: "Delete this log") expect(page).to have_button(text: "Delete this log")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id)) expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
expect(page).not_to have_link(text: "Log #{id}", href: lettings_log_path(id)) expect(page).not_to have_link(text: "Log #{id}", href: lettings_log_path(id))
expect(page).to have_link(text: "Cancel", href: lettings_log_path(id)) # update with correct path when known expect(page).to have_link(text: "Cancel", href: lettings_log_path(id)) # update with correct path when known
end
end end
end
context "when there are multiple duplicate logs being deleted" do context "when there are multiple duplicate logs being deleted" do
let!(:duplicate_log) do let!(:duplicate_log) do
duplicate = lettings_log.dup duplicate = lettings_log.dup
duplicate.id = nil duplicate.id = nil
duplicate.save! duplicate.save!
duplicate duplicate
end end
let!(:duplicate_log_2) do let!(:duplicate_log_2) do
duplicate = lettings_log.dup duplicate = lettings_log.dup
duplicate.id = nil duplicate.id = nil
duplicate.save! duplicate.save!
duplicate duplicate
end end
it "renders page" do it "renders page" do
request request
expect(response).to have_http_status(:ok) expect(response).to have_http_status(:ok)
expect(page).to have_content("Are you sure you want to delete these duplicate logs?") expect(page).to have_content("Are you sure you want to delete these duplicate logs?")
expect(page).to have_content("These logs will be deleted:") expect(page).to have_content("These logs will be deleted:")
expect(page).to have_button(text: "Delete these logs") expect(page).to have_button(text: "Delete these logs")
expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id)) expect(page).to have_link(text: "Log #{duplicate_log.id}", href: lettings_log_path(duplicate_log.id))
expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: lettings_log_path(duplicate_log_2.id)) expect(page).to have_link(text: "Log #{duplicate_log_2.id}", href: lettings_log_path(duplicate_log_2.id))
expect(page).to have_link(text: "Cancel", href: lettings_log_path(id)) # update with correct path when known expect(page).to have_link(text: "Cancel", href: lettings_log_path(id)) # update with correct path when known
end
end end
end
context "when log does not exist" do context "when log does not exist" do
let(:id) { -1 } let(:id) { -1 }
it "returns 404" do it "returns 404" do
request request
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end
end end
end
context "when user is not authorised" do context "when user is not authorised" do
let(:other_user) { create(:user) } let(:other_user) { create(:user) }
before do before do
allow(other_user).to receive(:need_two_factor_authentication?).and_return(false) allow(other_user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in other_user sign_in other_user
end end
it "returns 404" do it "returns 404" do
request request
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end
end end
end end
end end

Loading…
Cancel
Save