Browse Source

Do not reset created by for sales

pull/2064/head
Kat 3 years ago
parent
commit
d98cc98d00
  1. 1
      app/models/sales_log.rb
  2. 56
      spec/requests/form_controller_spec.rb

1
app/models/sales_log.rb

@ -318,6 +318,7 @@ class SalesLog < Log
return unless updated_by&.support? return unless updated_by&.support?
return if owning_organisation.blank? || created_by.blank? return if owning_organisation.blank? || created_by.blank?
return if created_by&.organisation == owning_organisation return if created_by&.organisation == owning_organisation
return if created_by&.organisation == owning_organisation.absorbing_organisation
update!(created_by: nil) update!(created_by: nil)
end end

56
spec/requests/form_controller_spec.rb

@ -189,6 +189,62 @@ RSpec.describe FormController, type: :request do
end end
end end
context "when submitting a sales log with valid owning organisation" do
let(:sales_log) { create(:sales_log) }
let(:created_by) { managing_organisation.users.first }
let(:params) do
{
id: sales_log.id,
sales_log: {
page: "organisation",
owning_organisation_id: managing_organisation.id,
},
}
end
before do
sales_log.update!(owning_organisation: managing_organisation, created_by:)
sales_log.reload
end
it "does not reset created by" do
post "/sales-logs/#{sales_log.id}/organisation", params: params
expect(response).to redirect_to("/sales-logs/#{sales_log.id}/created-by")
follow_redirect!
sales_log.reload
expect(sales_log.created_by).to eq(created_by)
end
end
context "when submitting a sales log with valid merged owning organisation" do
let(:sales_log) { create(:sales_log) }
let(:created_by) { managing_organisation.users.first }
let(:merged_organisation) { create(:organisation) }
let(:params) do
{
id: sales_log.id,
sales_log: {
page: "organisation",
owning_organisation_id: merged_organisation.id,
},
}
end
before do
merged_organisation.update!(merge_date: Time.zone.today, absorbing_organisation: managing_organisation)
sales_log.update!(owning_organisation: managing_organisation, created_by:)
sales_log.reload
end
it "does not reset created by" do
post "/sales-logs/#{sales_log.id}/organisation", params: params
expect(response).to redirect_to("/sales-logs/#{sales_log.id}/created-by")
follow_redirect!
sales_log.reload
expect(sales_log.created_by).to eq(created_by)
end
end
context "with valid managing organisation" do context "with valid managing organisation" do
let(:params) do let(:params) do
{ {

Loading…
Cancel
Save