Skip to content
Draft
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
2 changes: 1 addition & 1 deletion app/models/affiliation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Affiliation < ApplicationRecord

# Not flagged inactive and not past its end date. Includes affiliations whose
# start_date is still in the future (e.g. a Facilitator affiliation dated to an
# upcoming training's month) β€” they are "pending" but counted here.
# upcoming training) β€” they are "pending" but counted here.
scope :active_or_pending, -> {
where(inactive: false)
.where("affiliations.end_date IS NULL OR affiliations.end_date >= ?", Date.current)
Expand Down
12 changes: 6 additions & 6 deletions app/services/affiliation_services/create_from_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ module AffiliationServices
# facilitator-ish job title that isn't exactly "Facilitator" (e.g. "Lead
# Facilitator") still gets its own standing "Facilitator" affiliation alongside it.
#
# Start dates: the facilitator affiliation begins on the first day of the
# training's month (that's when they become a facilitator). The job affiliation
# is left without a start date β€” we don't know when the person began that role
# (they may have been with the org for years before this training), and dating it
# to registration would misrepresent that.
# Start dates: the facilitator affiliation begins on the training date itself
# (that's when they become a facilitator). The job affiliation is left without a
# start date β€” we don't know when the person began that role (they may have been
# with the org for years before this training), and dating it to registration
# would misrepresent that.
class CreateFromRegistration
def self.call(person:, organization:, job_title: nil, training_date: nil, organization_address: nil)
new(person:, organization:, job_title:, training_date:, organization_address:).call
Expand Down Expand Up @@ -82,7 +82,7 @@ def create_affiliation(title, start_date:)
end

def facilitator_start_date
(@training_date || Date.current).to_date.beginning_of_month
(@training_date || Date.current).to_date
end

def active_or_pending_affiliations_with_title(title)
Expand Down
2 changes: 1 addition & 1 deletion app/views/affiliations/_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
label_html: { class: "block text-sm font-medium text-gray-700 mb-1" },
input_html: {
type: "date",
value: (f.object.start_date || (Date.current.beginning_of_month unless f.object.persisted?))&.strftime("%Y-%m-%d"),
value: (f.object.start_date || (Date.current unless f.object.persisted?))&.strftime("%Y-%m-%d"),
class: "rounded-md border-gray-300 focus:ring-blue-500 focus:border-blue-500 text-sm",
data: { action: "change->affiliation-dates#recalculate" }
} %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,18 @@ def titles
expect(job.start_date).to be_nil
end

it "starts the facilitator affiliation on the first day of the training's month" do
it "starts the facilitator affiliation on the training date" do
described_class.call(person: person, organization: organization,
job_title: "Counselor", training_date: Date.new(2026, 9, 17))

facilitator = person.affiliations.find_by(organization: organization, title: "Facilitator")
expect(facilitator.start_date).to eq(Date.new(2026, 9, 1))
expect(facilitator.start_date).to eq(Date.new(2026, 9, 17))
end

it "falls back to the current month for the facilitator affiliation when no training date is given" do
it "falls back to today for the facilitator affiliation when no training date is given" do
described_class.call(person: person, organization: organization, job_title: nil)

facilitator = person.affiliations.find_by(organization: organization, title: "Facilitator")
expect(facilitator.start_date).to eq(Date.current.beginning_of_month)
expect(facilitator.start_date).to eq(Date.current)
end
end
4 changes: 2 additions & 2 deletions spec/views/organizations/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def org_with_status(name)
end

describe "new affiliation defaults" do
it "defaults the start date to the first of the current month and leaves primary contact unchecked" do
it "defaults the start date to today and leaves primary contact unchecked" do
organization.affiliations.build
render
assert_select "input[name*='start_date'][value=?]",
Date.current.beginning_of_month.strftime("%Y-%m-%d")
Date.current.strftime("%Y-%m-%d")
assert_select "input[type=checkbox][name*='primary_contact']"
assert_select "input[type=checkbox][name*='primary_contact'][checked]", false
end
Expand Down