Skip to content

Commit 71a0af4

Browse files
sc-16940 handle nil options in report intializer (#5712)
Story card: [sc-16940](https://app.shortcut.com/simpledotorg/story/16940/fix-template-error-in-user-analytics-dashbooard) ### Because A NoMethodError was raised in Dashboard::DrRaiReport when the options parameter was nil. This caused the User Analytics (Dr. Rai Report) dashboard to fail rendering. ### This addresses Safely accesses optional parameters using options&.dig(:selected_quarter) and options&.dig(:with_non_contactable) instead of directly referencing options[:selected_quarter] and options[:with_non_contactable]. ### Test instructions - Open the app. - Click on the Sync API. - Check whether the sync request fails or completes successfully. - Ensure no errors are raised during sync.
1 parent 91fbcb1 commit 71a0af4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

app/components/dashboard/dr_rai_report.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ class Dashboard::DrRaiReport < ApplicationComponent
33
attr_reader :periods, :region
44
attr_accessor :selected_period
55

6-
def initialize(periods, region_slug, options, lite = false)
6+
def initialize(periods, region_slug, options = {}, lite = false)
77
@lite = lite
88
@periods = periods
99
@region = Region.find_by(slug: region_slug)
10-
@selected_period = if options[:selected_quarter].nil?
10+
@selected_period = if options&.dig(:selected_quarter).nil?
1111
Period.new(type: :quarter, value: current_period.value.to_s)
1212
else
13-
Period.new(type: :quarter, value: options[:selected_quarter])
13+
Period.new(type: :quarter, value: options&.dig(:selected_quarter))
1414
end
15-
@with_non_contactable = options[:with_non_contactable].present?
15+
@with_non_contactable = options&.dig(:with_non_contactable).present?
1616
end
1717

1818
def indicators

spec/components/dashboard/dr_rai_report_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
render_inline(described_class.new(periods, region, rai_options))
4040
expect(page).to have_text("Q2 2024")
4141
end
42+
43+
it "handles nil options without error and defaults to the current period" do
44+
allow(Period).to receive(:current).and_return(quarter1)
45+
expect {
46+
render_inline(described_class.new(periods, region, nil))
47+
}.not_to raise_error
48+
expect(page).to have_text("Q1 2024")
49+
end
4250
end
4351

4452
describe "#classes_for_period" do

0 commit comments

Comments
 (0)