Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions spec/models/event_procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,12 @@
require "rails_helper"

RSpec.describe EventProcedure do
describe "acts_as_paranoid" do
describe "soft delete behavior" do
let(:user) { create(:user) }
let(:patient) { create(:patient, user: user) }
let(:event_procedure) { create(:event_procedure, user: user, patient: patient) }

it "soft deletes the record" do
event_procedure.destroy

expect(event_procedure.deleted_at).to be_present
expect(described_class.with_deleted).to include(event_procedure)
end

it "does not include the record in the default scope" do
event_procedure.destroy

expect(described_class.all).not_to include(event_procedure)
end

it "includes the record in the default scope when with_deleted is called" do
event_procedure.destroy

expect(described_class.with_deleted).to include(event_procedure)
end

it "restores a soft deleted record" do
event_procedure.destroy
event_procedure.recover!

expect(event_procedure.deleted_at).to be_nil
expect(described_class.all).to include(event_procedure)
end
it_behaves_like "acts as paranoid", :event_procedure
end

describe "associations" do
Expand Down
7 changes: 7 additions & 0 deletions spec/models/health_insurance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
require "rails_helper"

RSpec.describe HealthInsurance do
describe "soft delete behavior" do
let(:user) { create(:user) }
let(:health_insurance) { create(:health_insurance, user: user) }

it_behaves_like "acts as paranoid", :health_insurance
end

describe "associations" do
it { is_expected.to belong_to(:user).optional(true) }

Expand Down
6 changes: 6 additions & 0 deletions spec/models/hospital_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
require "rails_helper"

RSpec.describe Hospital do
describe "soft delete behavior" do
let(:hospital) { create(:hospital) }

it_behaves_like "acts as paranoid", :hospital
end

describe "associations" do
it { is_expected.to have_many(:event_procedures).dependent(:destroy) }
end
Expand Down
7 changes: 7 additions & 0 deletions spec/models/medical_shift_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
require "rails_helper"

RSpec.describe MedicalShift do
describe "soft delete behavior" do
let(:user) { create(:user) }
let(:medical_shift) { create(:medical_shift, user: user) }

it_behaves_like "acts as paranoid", :medical_shift
end

describe "associations" do
it { is_expected.to belong_to(:user) }
end
Expand Down
7 changes: 7 additions & 0 deletions spec/models/patient_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
require "rails_helper"

RSpec.describe Patient do
describe "soft delete behavior" do
let(:user) { create(:user) }
let(:patient) { create(:patient, user: user) }

it_behaves_like "acts as paranoid", :patient
end

describe "associations" do
it { is_expected.to have_many(:event_procedures).dependent(:destroy) }
it { is_expected.to belong_to(:user) }
Expand Down
7 changes: 7 additions & 0 deletions spec/models/procedure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
require "rails_helper"

RSpec.describe Procedure do
describe "soft delete behavior" do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, user: user) }

it_behaves_like "acts as paranoid", :procedure
end

describe "associations" do
it { is_expected.to belong_to(:user).optional(true) }

Expand Down
6 changes: 6 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
RSpec.describe User do
subject { build(:user) }

describe "soft delete behavior" do
let(:user) { create(:user) }

it_behaves_like "acts as paranoid", :user
end

describe "associations" do
it { is_expected.to have_many(:event_procedures).dependent(:destroy) }
it { is_expected.to have_many(:medical_shifts).dependent(:destroy) }
Expand Down
26 changes: 26 additions & 0 deletions spec/support/shared_contexts/soft_delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

RSpec.shared_examples "acts as paranoid" do |record_name|
let(:record) { send(record_name) }

before { record.destroy }

it "soft deletes the record" do
expect(record.deleted_at).to be_present
expect(described_class.with_deleted).to include(record)
end

it "does not include the record in the default scope" do
expect(described_class.all).not_to include(record)
end

it "includes the record in the default scope when with_deleted is called" do
expect(described_class.with_deleted).to include(record)
end

it "restores a soft deleted record" do
record.recover!
expect(record.deleted_at).to be_nil
expect(described_class.all).to include(record)
end
end