Skip to content

Commit be40caa

Browse files
committed
Creates load_seed subject for dev seeds specs
1 parent acef5af commit be40caa

9 files changed

+40
-60
lines changed

spec/db/seeds/event_procedures_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require "rails_helper"
44

55
RSpec.describe "Event Procedures seed" do
6+
subject(:load_seed) { load seed_file }
7+
68
let(:seed_file) { Rails.root.join("db/seeds/09_event_procedures.rb") }
79

810
before do
@@ -17,14 +19,10 @@
1719
end
1820

1921
it "runs without errors" do
20-
expect { load seed_file }.not_to raise_error
22+
expect { load_seed }.not_to raise_error
2123
end
2224

2325
it "creates records in the database" do
24-
expect(EventProcedure.count).to be(0)
25-
26-
load seed_file
27-
28-
expect(EventProcedure.count).to be(15)
26+
expect { load_seed }.to change(EventProcedure, :count).from(0).to(15)
2927
end
3028
end

spec/db/seeds/health_insurances_custom_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
require "rails_helper"
44

55
RSpec.describe "Custom Health Insurances seed" do
6+
subject(:load_seed) { load seed_file }
7+
68
let(:seed_file) { Rails.root.join("db/seeds/05_health_insurances_custom.rb") }
79

810
before do
911
create(:user)
1012
end
1113

1214
it "runs without errors" do
13-
expect { load seed_file }.not_to raise_error
15+
expect { load_seed }.not_to raise_error
1416
end
1517

1618
it "creates records in the database" do
17-
expect(HealthInsurance.count).to be(0)
18-
19-
load seed_file
20-
21-
expect(HealthInsurance.count).to be(1)
19+
expect { load_seed }.to change(HealthInsurance, :count).from(0).to(1)
2220
end
2321
end

spec/db/seeds/health_insurances_default_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
require "rails_helper"
44

55
RSpec.describe "Default Health Insurances seed" do
6+
subject(:load_seed) { load seed_file }
7+
68
let(:seed_file) { Rails.root.join("db/seeds/04_health_insurances_default.rb") }
79

810
it "runs without errors" do
9-
expect { load seed_file }.not_to raise_error
11+
expect { load_seed }.not_to raise_error
1012
end
1113

1214
it "creates records in the database" do
13-
expect(HealthInsurance.count).to be(0)
14-
15-
load seed_file
16-
17-
expect(HealthInsurance.count).to be(9)
15+
expect { load_seed }.to change(HealthInsurance, :count).from(0).to(9)
1816
end
1917
end

spec/db/seeds/hospitals_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
require "rails_helper"
44

55
RSpec.describe "Hospitals seed" do
6+
subject(:load_seed) { load seed_file }
7+
68
let(:seed_file) { Rails.root.join("db/seeds/06_hospitals.rb") }
79

810
it "runs without errors" do
9-
expect { load seed_file }.not_to raise_error
11+
expect { load_seed }.not_to raise_error
1012
end
1113

1214
it "creates records in the database" do
13-
expect(Hospital.count).to be(0)
14-
15-
load seed_file
16-
17-
expect(Hospital.count).to be(1)
15+
expect { load_seed }.to change(Hospital, :count).from(0).to(1)
1816
end
1917
end

spec/db/seeds/medical_shifts_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require "rails_helper"
44

55
RSpec.describe "Medical Shifts seed" do
6+
subject(:load_seed) { load seed_file }
7+
68
let(:seed_file) { Rails.root.join("db/seeds/08_medical_shifts.rb") }
79

810
before do
@@ -11,14 +13,10 @@
1113
end
1214

1315
it "runs without errors" do
14-
expect { load seed_file }.not_to raise_error
16+
expect { load_seed }.not_to raise_error
1517
end
1618

1719
it "creates records in the database" do
18-
expect(MedicalShift.count).to be(0)
19-
20-
load seed_file
21-
22-
expect(MedicalShift.count).to be(2)
20+
expect { load_seed }.to change(MedicalShift, :count).from(0).to(2)
2321
end
2422
end

spec/db/seeds/patients_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
require "rails_helper"
44

55
RSpec.describe "Patients seed" do
6+
subject(:load_seed) { load seed_file }
7+
68
let(:seed_file) { Rails.root.join("db/seeds/07_patients.rb") }
79

810
before do
911
create(:user)
1012
end
1113

1214
it "runs without errors" do
13-
expect { load seed_file }.not_to raise_error
15+
expect { load_seed }.not_to raise_error
1416
end
1517

1618
it "creates records in the database" do
17-
expect(Patient.count).to be(0)
18-
19-
load seed_file
20-
21-
expect(Patient.count).to be(1)
19+
expect { load_seed }.to change(Patient, :count).from(0).to(1)
2220
end
2321
end

spec/db/seeds/procedures_custom_spec.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
require "rails_helper"
44

55
RSpec.describe "Custom Procedures seed" do
6+
subject(:load_seed) { load seed_file }
7+
68
let(:seed_file) { Rails.root.join("db/seeds/03_procedures_custom.rb") }
79

810
before do
911
create(:user)
1012
end
1113

1214
it "runs without errors" do
13-
expect { load seed_file }.not_to raise_error
15+
expect { load_seed }.not_to raise_error
1416
end
1517

1618
it "creates records in the database" do
17-
expect(Procedure.count).to be(0)
18-
19-
load seed_file
20-
21-
expect(Procedure.count).to be(1)
19+
expect { load_seed }.to change(Procedure, :count).from(0).to(1)
2220
end
2321
end

spec/db/seeds/procedures_default_spec.rb

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require "rails_helper"
44

55
RSpec.describe "Default Procedures seed" do
6+
subject(:load_seed) { load seed_file }
7+
68
let(:seed_file) { Rails.root.join("db/seeds/02_procedures_default.rb") }
79

810
before do
@@ -62,20 +64,12 @@
6264
end
6365

6466
it "runs without errors" do
65-
expect { load seed_file }.not_to raise_error
66-
end
67-
68-
it "starts with no records in the database" do
69-
expect(PortValue.count).to be(0)
70-
expect(Procedure.count).to be(0)
71-
expect(CbhpmProcedure.count).to be(0)
67+
expect { load_seed }.not_to raise_error
7268
end
7369

7470
it "creates records in the database" do
75-
load seed_file
76-
77-
expect(PortValue.count).to be(3)
78-
expect(Procedure.count).to be(3)
79-
expect(CbhpmProcedure.count).to be(3)
71+
expect { load_seed }.to change(PortValue, :count).from(0).to(3)
72+
.and change(Procedure, :count).from(0).to(3)
73+
.and change(CbhpmProcedure, :count).from(0).to(3)
8074
end
8175
end

spec/db/seeds/users_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44

55
RSpec.describe "User seeds" do
66
describe "users.rb seed" do
7+
subject(:load_seed) { load seed_file }
8+
79
let(:seed_file) { Rails.root.join("db/seeds/01_users.rb") }
810

911
it "creates user without errors" do
1012
expect do
11-
load seed_file
13+
load_seed
1214
end.not_to raise_error
1315
end
1416

1517
it "creates exactly one user" do
16-
expect do
17-
load seed_file
18-
end.to change(User, :count).by(1)
18+
expect { load_seed }.to change(User, :count).by(1)
1919
end
2020

2121
it "creates user with correct email" do
22-
load seed_file
22+
load_seed
2323
user = User.find_by(email: "user@email.com")
2424
expect(user).not_to be_nil
2525
end
2626

2727
it "creates user with valid password" do
28-
load seed_file
28+
load_seed
2929
user = User.find_by(email: "user@email.com")
3030
expect(user.valid_password?("qwe123")).to be true
3131
end

0 commit comments

Comments
 (0)