Skip to content

Commit c8bb896

Browse files
committed
spec improvements
1 parent e3e4273 commit c8bb896

7 files changed

Lines changed: 59 additions & 62 deletions

File tree

spec/models/casa_case_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
end
3939

4040
it "is valid today" do
41-
casa_case = CasaCase.new(date_in_care: Time.now)
41+
casa_case = CasaCase.new(date_in_care: Time.current)
4242
casa_case.valid?
4343
expect(casa_case.errors[:date_in_care]).to eq([])
4444
end
@@ -66,7 +66,7 @@
6666
end
6767

6868
it "is valid today" do
69-
casa_case = CasaCase.new(birth_month_year_youth: Time.now)
69+
casa_case = CasaCase.new(birth_month_year_youth: Time.current)
7070
casa_case.valid?
7171
expect(casa_case.errors[:birth_month_year_youth]).to eq([])
7272
end
@@ -195,18 +195,18 @@
195195

196196
describe ".should_transition" do
197197
it "returns only youth who should have transitioned but have not" do
198-
not_transitioned_13_yo = build(:casa_case,
198+
not_transitioned_13_yo = create(:casa_case,
199199
birth_month_year_youth: Date.current - 13.years)
200-
transitioned_14_yo = build(:casa_case,
201-
birth_month_year_youth: Date.current - 14.years)
202-
not_transitioned_14_yo = create(:casa_case,
200+
already_transitioned_15_yo = create(:casa_case,
201+
birth_month_year_youth: Date.current - 15.years)
202+
should_transition_14_yo = create(:casa_case,
203203
birth_month_year_youth: Date.current - 14.years)
204204
cases = CasaCase.should_transition
205205
aggregate_failures do
206-
expect(cases.length).to eq 1
207-
expect(cases.include?(not_transitioned_14_yo)).to eq true
206+
expect(cases.length).to eq 2
207+
expect(cases.include?(should_transition_14_yo)).to eq true
208+
expect(cases.include?(already_transitioned_15_yo)).to eq true
208209
expect(cases.include?(not_transitioned_13_yo)).to eq false
209-
expect(cases.include?(transitioned_14_yo)).to eq false
210210
end
211211
end
212212
end
@@ -228,7 +228,7 @@
228228
let(:casa_case) { create(:casa_case) }
229229
let(:emancipation_category) { create(:emancipation_category) }
230230

231-
it "associates an emacipation category with the case when passed the id of the category" do
231+
it "associates an emancipation category with the case when passed the id of the category" do
232232
expect {
233233
casa_case.add_emancipation_category(emancipation_category.id)
234234
}.to change { casa_case.emancipation_categories.count }.from(0).to(1)
@@ -241,7 +241,7 @@
241241
let(:emancipation_option_a) { create(:emancipation_option, emancipation_category: emancipation_category) }
242242
let(:emancipation_option_b) { create(:emancipation_option, emancipation_category: emancipation_category, name: "Not the same name as option A to satisfy unique contraints") }
243243

244-
it "associates an emacipation option with the case when passed the id of the option" do
244+
it "associates an emancipation option with the case when passed the id of the option" do
245245
expect {
246246
casa_case.add_emancipation_option(emancipation_option_a.id)
247247
}.to change { casa_case.emancipation_options.count }.from(0).to(1)

spec/models/case_assignment_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
require "rails_helper"
22

33
RSpec.describe CaseAssignment, type: :model do
4-
let(:casa_org_1) { build(:casa_org) }
4+
let(:casa_org_1) { create(:casa_org) }
55
let(:casa_case_1) { create(:casa_case, casa_org: casa_org_1) }
66
let(:volunteer_1) { create(:volunteer, casa_org: casa_org_1) }
7-
let(:inactive) { build(:volunteer, :inactive, casa_org: casa_org_1) }
8-
let(:supervisor) { build(:supervisor, casa_org: casa_org_1) }
9-
let(:casa_case_2) { build(:casa_case, casa_org: casa_org_1) }
10-
let(:volunteer_2) { build(:volunteer, casa_org: casa_org_1) }
11-
let(:casa_org_2) { build(:casa_org) }
7+
let(:inactive) { create(:volunteer, :inactive, casa_org: casa_org_1) }
8+
let(:supervisor) { create(:supervisor, casa_org: casa_org_1) }
9+
let(:casa_case_2) { create(:casa_case, casa_org: casa_org_1) }
10+
let(:volunteer_2) { create(:volunteer, casa_org: casa_org_1) }
11+
let(:casa_org_2) { create(:casa_org) }
1212

1313
it "only allow active volunteers to be assigned" do
1414
expect(casa_case_1.case_assignments.new(volunteer: volunteer_1)).to be_valid
@@ -52,8 +52,8 @@
5252

5353
describe ".active" do
5454
it "only includes active case assignments" do
55-
casa_case = build(:casa_case)
56-
case_assignments = 2.times.map { create(:case_assignment, casa_case: casa_case, volunteer: build(:volunteer, casa_org: casa_case.casa_org)) }
55+
casa_case = create(:casa_case)
56+
case_assignments = 2.times.map { create(:case_assignment, casa_case: casa_case, volunteer: create(:volunteer, casa_org: casa_case.casa_org)) }
5757
expect(CaseAssignment.active).to match_array(case_assignments)
5858

5959
case_assignments.first.update(active: false)

spec/models/case_contact_spec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,15 @@
3838
end
3939

4040
it "verifies occurred at is not in the future" do
41-
case_contact = build_stubbed(:case_contact, occurred_at: Time.now + 1.week)
41+
case_contact = build_stubbed(:case_contact, occurred_at: Time.current + 1.week)
4242
expect(case_contact).not_to be_valid
4343
expect(case_contact.errors[:occurred_at]).to eq(["can't be in the future"])
44-
expect(case_contact.errors.full_messages).to include("Date can't be in the future")
4544
end
4645

4746
it "verifies occurred at is not before 1/1/1989" do
4847
case_contact = build_stubbed(:case_contact, occurred_at: "1984-01-01".to_date)
4948
expect(case_contact).not_to be_valid
5049
expect(case_contact.errors[:occurred_at]).to eq(["can't be prior to 01/01/1989."])
51-
expect(case_contact.errors.full_messages).to include("Date can't be prior to 01/01/1989.")
5250
end
5351

5452
it "validates want_driving_reimbursement can be true when miles_driven is positive" do
@@ -120,7 +118,6 @@
120118
it "requires occurred at" do
121119
case_contact = build_stubbed(:case_contact, :details_status, occurred_at: nil)
122120
expect(case_contact).not_to be_valid
123-
expect(case_contact.errors[:occurred_at]).to eq(["can't be blank"])
124121
expect(case_contact.errors.full_messages).to include("Date can't be blank")
125122
end
126123

spec/models/mileage_rate_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@
2222

2323
describe "#effective_date" do
2424
it "cannot be before 1/1/1989" do
25-
mileage_rate = build_stubbed(:mileage_rate, effective_date: "1984-01-01".to_date)
25+
mileage_rate = build(:mileage_rate, effective_date: "1984-01-01".to_date)
2626
expect(mileage_rate).not_to be_valid
2727
expect(mileage_rate.errors[:effective_date]).to eq(["cannot be prior to 1/1/1989."])
2828
end
2929

3030
it "cannot be more than one year in the future" do
31-
mileage_rate = build_stubbed(:mileage_rate, effective_date: 367.days.from_now)
31+
mileage_rate = build(:mileage_rate, effective_date: 367.days.from_now)
3232
expect(mileage_rate).not_to be_valid
3333
expect(mileage_rate.errors[:effective_date]).to eq(["must not be more than one year in the future."])
3434
end
3535

3636
it "is valid in the past after 1/1/1989" do
37-
mileage_rate = build_stubbed(:mileage_rate, effective_date: "1997-08-29".to_date)
37+
mileage_rate = build(:mileage_rate, effective_date: "1997-08-29".to_date)
3838
expect(mileage_rate).to be_valid
3939
expect(mileage_rate.errors[:effective_date]).to eq([])
4040
end
4141

4242
it "is valid today" do
43-
mileage_rate = build_stubbed(:mileage_rate, effective_date: DateTime.now)
43+
mileage_rate = build(:mileage_rate, effective_date: Time.current)
4444
expect(mileage_rate).to be_valid
4545
expect(mileage_rate.errors[:effective_date]).to eq([])
4646
end

spec/models/placement_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@
99

1010
context "placement_started_at" do
1111
it "cannot be before 1/1/1989" do
12-
placement = build_stubbed(:placement, placement_started_at: "1984-01-01".to_date)
12+
placement = build(:placement, placement_started_at: "1984-01-01".to_date)
1313
expect(placement).not_to be_valid
1414
expect(placement.errors[:placement_started_at]).to eq(["cannot be prior to 1/1/1989."])
1515
end
1616

1717
it "cannot be more than one year in the future" do
18-
placement = build_stubbed(:placement, placement_started_at: 367.days.from_now)
18+
placement = build(:placement, placement_started_at: 367.days.from_now)
1919
expect(placement).not_to be_valid
2020
expect(placement.errors[:placement_started_at]).to eq(["must not be more than one year in the future."])
2121
end
2222

2323
it "is valid in the past after 1/1/1989" do
24-
placement = build_stubbed(:placement, placement_started_at: "1997-08-29".to_date)
24+
placement = build(:placement, placement_started_at: "1997-08-29".to_date)
2525
expect(placement).to be_valid
2626
expect(placement.errors[:placement_started_at]).to eq([])
2727
end
2828

2929
it "is valid today" do
30-
placement = build_stubbed(:placement, placement_started_at: DateTime.now)
30+
placement = build(:placement, placement_started_at: Time.current)
3131
expect(placement).to be_valid
3232
expect(placement.errors[:placement_started_at]).to eq([])
3333
end

spec/models/user_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
end
9999

100100
it "does not return case_contacts neither unassigned cases or inactive cases" do
101-
inactive_case_assignment = build_stubbed(:case_assignment, casa_case: build_stubbed(:casa_case, casa_org: volunteer.casa_org), active: false, volunteer: volunteer)
102-
case_assignment_to_inactve_case = build_stubbed(:case_assignment, casa_case: build_stubbed(:casa_case, active: false, casa_org: volunteer.casa_org), volunteer: volunteer)
101+
inactive_case_assignment = create(:case_assignment, casa_case: create(:casa_case, casa_org: volunteer.casa_org), active: false, volunteer: volunteer)
102+
case_assignment_to_inactve_case = create(:case_assignment, casa_case: create(:casa_case, active: false, casa_org: volunteer.casa_org), volunteer: volunteer)
103103

104104
expect {
105105
volunteer.case_contacts_for(inactive_case_assignment.casa_case.id)
@@ -133,8 +133,8 @@
133133

134134
it "ignores volunteers' inactive and unassgined cases" do
135135
volunteer = create(:volunteer, supervisor: supervisor, casa_org: casa_org)
136-
build_stubbed(:case_assignment, casa_case: build_stubbed(:casa_case, casa_org: casa_org, active: false), volunteer: volunteer)
137-
build_stubbed(:case_assignment, casa_case: build_stubbed(:casa_case, casa_org: casa_org), active: false, volunteer: volunteer)
136+
create(:case_assignment, casa_case: create(:casa_case, casa_org: casa_org, active: false), volunteer: volunteer)
137+
create(:case_assignment, casa_case: create(:casa_case, casa_org: casa_org), active: false, volunteer: volunteer)
138138

139139
expect(supervisor.volunteers_serving_transition_aged_youth).to eq(0)
140140
end
@@ -168,7 +168,7 @@
168168
end
169169

170170
it "returns zero for a volunteer that is not assigned to any casa cases" do
171-
build_stubbed(:volunteer, supervisor: supervisor)
171+
create(:volunteer, supervisor: supervisor)
172172
expect(supervisor.no_attempt_for_two_weeks).to eq(0)
173173
end
174174

@@ -177,7 +177,7 @@
177177

178178
case_of_interest_1 = volunteer_1.casa_cases.first
179179

180-
build_stubbed(:case_contact, creator: volunteer_1, casa_case: case_of_interest_1, contact_made: true, created_at: 3.weeks.ago)
180+
create(:case_contact, creator: volunteer_1, casa_case: case_of_interest_1, contact_made: true, created_at: 3.weeks.ago)
181181
expect(supervisor.no_attempt_for_two_weeks).to eq(1)
182182
end
183183

@@ -198,16 +198,16 @@
198198

199199
describe "#active_for_authentication?" do
200200
it "is false when the user is inactive" do
201-
user = build_stubbed(:volunteer, :inactive)
201+
user = build(:volunteer, :inactive)
202202
expect(user).not_to be_active_for_authentication
203203
expect(user.inactive_message).to eq(:inactive)
204204
end
205205

206206
it "is true otherwise" do
207-
user = build_stubbed(:volunteer)
207+
user = build(:volunteer)
208208
expect(user).to be_active_for_authentication
209209

210-
user = build_stubbed(:supervisor)
210+
user = build(:supervisor)
211211
expect(user).to be_active_for_authentication
212212
end
213213
end
@@ -235,12 +235,12 @@
235235
describe "#serving_transition_aged_youth?" do
236236
let(:user) { build(:volunteer) }
237237
let!(:case_assignment_without_transition_aged_youth) do
238-
build(:case_assignment, casa_case: build_stubbed(:casa_case, :pre_transition, casa_org: user.casa_org), volunteer: user)
238+
create(:case_assignment, casa_case: create(:casa_case, :pre_transition, casa_org: user.casa_org), volunteer: user)
239239
end
240240

241241
context "when the user has a transition-aged-youth case" do
242242
it "is true" do
243-
create(:case_assignment, casa_case: build(:casa_case, casa_org: user.casa_org), volunteer: user)
243+
create(:case_assignment, casa_case: create(:casa_case, casa_org: user.casa_org), volunteer: user)
244244
expect(user).to be_serving_transition_aged_youth
245245
end
246246
end
@@ -253,15 +253,15 @@
253253

254254
context "when the user's only transition-aged-youth case is inactive" do
255255
it "is false" do
256-
build(:case_assignment, casa_case: build_stubbed(:casa_case, casa_org: user.casa_org, active: false), volunteer: user)
256+
create(:case_assignment, casa_case: create(:casa_case, casa_org: user.casa_org, active: false), volunteer: user)
257257

258258
expect(user).not_to be_serving_transition_aged_youth
259259
end
260260
end
261261

262262
context "when the user is unassigned from a transition-aged-youth case" do
263263
it "is false" do
264-
build(:case_assignment, casa_case: build_stubbed(:casa_case, casa_org: user.casa_org), volunteer: user, active: false)
264+
create(:case_assignment, casa_case: create(:casa_case, casa_org: user.casa_org), volunteer: user, active: false)
265265

266266
expect(user).not_to be_serving_transition_aged_youth
267267
end

spec/models/volunteer_spec.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
let(:case_assignment5) { build(:case_assignment, casa_org: casa_org_twilio_disabled, casa_case: casa_case5) }
2626

2727
let!(:v1) { create(:volunteer, casa_org: casa_org, case_assignments: [case_assignment1, case_assignment2, case_assignment3]) }
28-
let!(:v2) { build_stubbed(:volunteer, casa_org: casa_org, active: false) }
29-
let!(:v3) { build_stubbed(:volunteer, casa_org: casa_org) }
30-
let!(:v4) { build_stubbed(:volunteer, casa_org: casa_org, case_assignments: [case_assignment_unassigned]) }
28+
let!(:v2) { create(:volunteer, casa_org: casa_org, active: false) }
29+
let!(:v3) { create(:volunteer, casa_org: casa_org) }
30+
let!(:v4) { create(:volunteer, casa_org: casa_org, case_assignments: [case_assignment_unassigned]) }
3131
let!(:v5) { create(:volunteer, casa_org: casa_org_twilio_disabled, case_assignments: [case_assignment5]) }
3232

3333
before do
@@ -205,18 +205,18 @@
205205

206206
context "when a volunteer has only an inactive case where contact was not made recently" do
207207
it "returns true" do
208-
inactive_case = build_stubbed(:casa_case, casa_org: volunteer.casa_org, active: false)
209-
build_stubbed(:case_assignment, casa_case: inactive_case, volunteer: volunteer)
210-
build_stubbed(:case_contact, casa_case: inactive_case, creator: volunteer, occurred_at: Date.current - 60.days, contact_made: true)
208+
inactive_case = create(:casa_case, casa_org: volunteer.casa_org, active: false)
209+
create(:case_assignment, casa_case: inactive_case, volunteer: volunteer)
210+
create(:case_contact, casa_case: inactive_case, creator: volunteer, occurred_at: Date.current - 60.days, contact_made: true)
211211

212212
expect(volunteer.made_contact_with_all_cases_in_days?).to eq(true)
213213
end
214214
end
215215

216216
context "when a volunteer has only an unassigned case where contact was not made recently" do
217217
it "returns true" do
218-
build_stubbed(:case_assignment, casa_case: casa_case, volunteer: volunteer, active: false)
219-
build_stubbed(:case_contact, casa_case: casa_case, creator: volunteer, occurred_at: Date.current - 60.days, contact_made: true)
218+
create(:case_assignment, casa_case: casa_case, volunteer: volunteer, active: false)
219+
create(:case_contact, casa_case: casa_case, creator: volunteer, occurred_at: Date.current - 60.days, contact_made: true)
220220

221221
expect(volunteer.made_contact_with_all_cases_in_days?).to eq(true)
222222
end
@@ -225,15 +225,15 @@
225225

226226
describe "#supervised_by?" do
227227
it "is supervised by the currently active supervisor" do
228-
supervisor = build_stubbed :supervisor
229-
volunteer = build_stubbed :volunteer, supervisor: supervisor
228+
supervisor = create :supervisor
229+
volunteer = create :volunteer, supervisor: supervisor
230230

231231
expect(volunteer).to be_supervised_by(supervisor)
232232
end
233233

234234
it "is not supervised by supervisors that have never supervised the volunteer before" do
235-
supervisor = build_stubbed :supervisor
236-
volunteer = build_stubbed :volunteer
235+
supervisor = create :supervisor
236+
volunteer = create :volunteer
237237

238238
expect(volunteer).not_to be_supervised_by(supervisor)
239239
end
@@ -251,7 +251,7 @@
251251
end
252252

253253
describe "#role" do
254-
subject(:volunteer) { build_stubbed :volunteer }
254+
subject(:volunteer) { build :volunteer }
255255

256256
it { expect(volunteer.role).to eq "Volunteer" }
257257
end
@@ -271,15 +271,15 @@
271271
let!(:unassigned1) { create(:volunteer, display_name: "aaa", casa_org: casa_org) }
272272
let!(:unassigned2) { create(:volunteer, display_name: "bbb", casa_org: casa_org) }
273273
let!(:unassigned_inactive) { create(:volunteer, display_name: "unassigned inactive", casa_org: casa_org, active: false) }
274-
let!(:different_org) { build(:casa_org) }
275-
let!(:unassigned2_different_org) { build(:volunteer, display_name: "ccc", casa_org: different_org) }
276-
let!(:assigned1) { build(:volunteer, display_name: "ddd", casa_org: casa_org) }
274+
let!(:different_org) { create(:casa_org) }
275+
let!(:unassigned2_different_org) { create(:volunteer, display_name: "ccc", casa_org: different_org) }
276+
let!(:assigned1) { create(:volunteer, display_name: "ddd", casa_org: casa_org) }
277277
let!(:supervisor) { create(:supervisor, display_name: "supe", casa_org: casa_org) }
278278
let!(:assignment1) { create(:supervisor_volunteer, volunteer: assigned1, supervisor: supervisor) }
279279
let!(:assigned2_different_org) { assignment1.volunteer }
280-
let!(:unassigned_inactive_volunteer) { build(:volunteer, display_name: "eee", casa_org: casa_org, active: false) }
280+
let!(:unassigned_inactive_volunteer) { create(:volunteer, display_name: "eee", casa_org: casa_org, active: false) }
281281
let!(:previously_assigned) { create(:volunteer, display_name: "fff", casa_org: casa_org) }
282-
let!(:inactive_assignment) { build(:supervisor_volunteer, volunteer: previously_assigned, is_active: false, supervisor: supervisor) }
282+
let!(:inactive_assignment) { create(:supervisor_volunteer, volunteer: previously_assigned, is_active: false, supervisor: supervisor) }
283283

284284
it "returns unassigned volunteers" do
285285
expect(subject.map(&:display_name).sort).to eq ["aaa", "bbb", "fff"]

0 commit comments

Comments
 (0)