Skip to content
Open
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: 0 additions & 2 deletions app/controllers/reports/annual_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ def index
@actual_year = Time.current.year

@years = (foundation_year...@actual_year).to_a

@month_remaining_to_report = 12 - Time.current.month
end

def show
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/reports/annual_reports_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Reports
module AnnualReportsHelper
def available_date
(Date.current + 1.year).beginning_of_year.strftime("%B%e, %Y")
end
end
end
2 changes: 1 addition & 1 deletion app/views/reports/annual_reports/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<div class="row">
<div class="col-md-12 mb-2">
<h5 class="mb-1">Reports are available at the end of every year.</h5>
<span class="text-muted"> <%= "#{@actual_year} (available in #{pluralize(@month_remaining_to_report, 'month')})" %> </span>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the @month_remaining_to_report instance variable now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Removed it in 44d1cfa

<span class="text-muted"> <%= "#{@actual_year} (available on #{available_date})" %> </span>
</div>
<div class="col-md-12">
<div class="card card-primary">
Expand Down
21 changes: 21 additions & 0 deletions spec/helpers/reports/annual_reports_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
RSpec.describe Reports::AnnualReportsHelper, type: :helper do
describe "#available_date" do
it "returns the first day of the following year when the current date is the first day of a given year" do
travel_to Time.zone.local(2026, 0o1, 0o1)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should have a few edge cases here. I'd probably use

  • Jan 1
  • Dec 31
  • Some time in between

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! The original test was for January 1st, so I added coverage for Dec 31 and a date during the year in ab6799a


expect(helper.available_date).to eq("January 1, 2027")
end

it "returns the first day of the following year when the current date is the last day of a given year" do
travel_to Time.zone.local(2026, 12, 31)

expect(helper.available_date).to eq("January 1, 2027")
end

it "returns the first day of the following year" do
travel_to Time.zone.local(2026, 0o4, 15)

expect(helper.available_date).to eq("January 1, 2027")
end
end
end
8 changes: 8 additions & 0 deletions spec/requests/reports/annual_reports_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
get reports_annual_reports_path(default_params)
expect(response).to have_http_status(:success)
end

it "displays the first day of the following year as the date when the report will be available" do
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make this explicit, i.e. use travel_to and check the actual date rather than just re-typing the code used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree! Updated this test in ab6799a.

travel_to Time.zone.local(2026, 12, 31)

get reports_annual_reports_path(default_params)

expect(response.body).to include("available on January 1, 2027")
end
end

describe "GET /show" do
Expand Down
Loading