Skip to content

Commit

Permalink
fixes for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Williams committed Feb 11, 2024
1 parent 6f728d5 commit 420efb1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def no_attempt_for_two_weeks
if volunteer.supervisor.active? &&
volunteer.case_assignments.any? { |assignment| assignment.active? } &&
(volunteer.case_contacts.none? ||
volunteer.case_contacts.maximum(:occurred_at) < (Time.zone.now - 14.days))
volunteer.case_contacts.maximum(:created_at) < (Time.zone.now - 14.days))

no_attempt_count += 1
end
Expand Down
10 changes: 5 additions & 5 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
volunteer_1 = create(:volunteer, :with_casa_cases, supervisor: supervisor)

case_of_interest_1 = volunteer_1.casa_cases.first
create(:case_contact, creator: volunteer_1, casa_case: case_of_interest_1, contact_made: true, occurred_at: 1.week.ago)
create(:case_contact, creator: volunteer_1, casa_case: case_of_interest_1, contact_made: true, created_at: 1.week.ago)
expect(supervisor.no_attempt_for_two_weeks).to eq(0)
end

Expand All @@ -143,8 +143,8 @@

case_of_interest_1 = volunteer_1.casa_cases.first
case_of_interest_2 = volunteer_2.casa_cases.first
create(:case_contact, creator: volunteer_1, casa_case: case_of_interest_1, contact_made: true, occurred_at: 1.week.ago)
create(:case_contact, creator: volunteer_2, casa_case: case_of_interest_2, contact_made: true, occurred_at: 3.weeks.ago)
create(:case_contact, creator: volunteer_1, casa_case: case_of_interest_1, contact_made: true, created_at: 1.week.ago)
create(:case_contact, creator: volunteer_2, casa_case: case_of_interest_2, contact_made: true, created_at: 3.weeks.ago)
expect(supervisor.no_attempt_for_two_weeks).to eq(1)
end

Expand All @@ -158,12 +158,12 @@
expect(supervisor.no_attempt_for_two_weeks).to eq(0)
end

it "returns one for a volunteer who has attempted contact in at least one contact_case with occurred_at after 2 weeks" do
it "returns one for a volunteer who has attempted contact in at least one contact_case with created_at after 2 weeks" do
volunteer_1 = create(:volunteer, :with_casa_cases, supervisor: supervisor)

case_of_interest_1 = volunteer_1.casa_cases.first

build_stubbed(:case_contact, creator: volunteer_1, casa_case: case_of_interest_1, contact_made: true, occurred_at: 3.weeks.ago)
build_stubbed(:case_contact, creator: volunteer_1, casa_case: case_of_interest_1, contact_made: true, created_at: 3.weeks.ago)
expect(supervisor.no_attempt_for_two_weeks).to eq(1)
end

Expand Down
14 changes: 9 additions & 5 deletions spec/system/volunteers/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@
describe "Manage Volunteers button" do
before do
sign_in admin
visit volunteers_path
end

it "does not display by default" do
visit volunteers_path
expect(page).not_to have_text "Manage Volunteer"
end

Expand All @@ -197,29 +197,33 @@
}

it "is displayed" do
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}").click
visit volunteers_path
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}", wait: 3).click

expect(page).to have_text "Manage Volunteer"
end

it "displays number of volunteers selected" do
visit volunteers_path
volunteers.each_with_index do |volunteer, index|
find("#supervisor_volunteer_volunteer_ids_#{volunteer.id}").click
find("#supervisor_volunteer_volunteer_ids_#{volunteer.id}", wait: 3).click
button = find("[data-select-all-target='buttonLabel']")
expect(button).to have_text "(#{index + 1})"
end
end

it "text matches pluralization of volunteers selected" do
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}").click
visit volunteers_path
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}", wait: 3).click
expect(page).not_to have_text "Manage Volunteers"

find("#supervisor_volunteer_volunteer_ids_#{volunteers[1].id}").click
expect(page).to have_text "Manage Volunteers"
end

it "is hidden when all volunteers unchecked" do
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}").click
visit volunteers_path
find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}", wait: 3).click
expect(page).to have_text "Manage Volunteer"

find("#supervisor_volunteer_volunteer_ids_#{volunteers[0].id}").click
Expand Down

0 comments on commit 420efb1

Please sign in to comment.