|
|
@ -225,20 +225,35 @@ RSpec.describe "User Features" do |
|
|
|
|
|
|
|
|
|
|
|
describe "delete cascade" do |
|
|
|
describe "delete cascade" do |
|
|
|
context "when the organisation is deleted" do |
|
|
|
context "when the organisation is deleted" do |
|
|
|
let!(:organisation) { user.organisation } |
|
|
|
let!(:organisation) { FactoryBot.create(:organisation) } |
|
|
|
let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } |
|
|
|
let!(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now, organisation: organisation) } |
|
|
|
let!(:scheme_to_delete) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } |
|
|
|
let!(:scheme_to_delete) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } |
|
|
|
let!(:log_to_delete) { FactoryBot.create(:case_log, owning_organisation: user.organisation) } |
|
|
|
let!(:log_to_delete) { FactoryBot.create(:case_log, owning_organisation: user.organisation) } |
|
|
|
|
|
|
|
|
|
|
|
context "when organisation is deleted" do |
|
|
|
context "when organisation is deleted" do |
|
|
|
it "child relationships ie logs, schemes and users are deleted too" do |
|
|
|
it "child relationships ie logs, schemes and users are deleted too - application" do |
|
|
|
organisation.destroy |
|
|
|
organisation.destroy! |
|
|
|
expect { organisation.reload }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
expect { organisation.reload }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
expect { CaseLog.find(log_to_delete.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
expect { CaseLog.find(log_to_delete.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
expect { CaseLog.find(scheme_to_delete.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
expect { Scheme.find(scheme_to_delete.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
expect { CaseLog.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when the organisation is deleted" do |
|
|
|
|
|
|
|
let!(:organisation) { FactoryBot.create(:organisation) } |
|
|
|
|
|
|
|
let!(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now, organisation: organisation) } |
|
|
|
|
|
|
|
let!(:scheme_to_delete) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } |
|
|
|
|
|
|
|
let!(:log_to_delete) { FactoryBot.create(:case_log, owning_organisation: user.organisation) } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "child relationships ie logs, schemes and users are deleted too - database" do |
|
|
|
|
|
|
|
ActiveRecord::Base.connection.exec_query("DELETE FROM organisations WHERE id = #{organisation.id};") |
|
|
|
|
|
|
|
expect { CaseLog.find(log_to_delete.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
|
|
|
|
expect { Scheme.find(scheme_to_delete.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
|
|
|
|
expect { User.find(user.id) }.to raise_error(ActiveRecord::RecordNotFound) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|