diff --git a/app/views/accountable_sparklines/show.html.erb b/app/views/accountable_sparklines/show.html.erb index 05b0339c0..54072ad64 100644 --- a/app/views/accountable_sparklines/show.html.erb +++ b/app/views/accountable_sparklines/show.html.erb @@ -5,7 +5,7 @@ <%# A previous value of zero makes the percentage infinite, with nothing useful to print %> - <% if @series.trend.percent.finite? %> + <% if @series.trend && @series.trend.percent.finite? %> <%= tag.p @series.trend.percent_formatted, style: "color: #{@series.trend.color}", class: "font-mono text-right text-xs font-medium text-primary" %> diff --git a/app/views/accounts/sparkline.html.erb b/app/views/accounts/sparkline.html.erb index ba8339049..f2e75272a 100644 --- a/app/views/accounts/sparkline.html.erb +++ b/app/views/accounts/sparkline.html.erb @@ -5,7 +5,7 @@ <%# A previous value of zero makes the percentage infinite, with nothing useful to print %> - <% if @sparkline_series.trend.percent.finite? %> + <% if @sparkline_series.trend && @sparkline_series.trend.percent.finite? %> <%= tag.p @sparkline_series.trend.percent_formatted, style: "color: #{@sparkline_series.trend.color}", class: "font-mono text-right text-xs font-medium text-primary" %> diff --git a/test/controllers/accountable_sparklines_controller_test.rb b/test/controllers/accountable_sparklines_controller_test.rb index 80399b42a..4dfd67834 100644 --- a/test/controllers/accountable_sparklines_controller_test.rb +++ b/test/controllers/accountable_sparklines_controller_test.rb @@ -10,6 +10,22 @@ class AccountableSparklinesControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test "show renders an empty series without a trend" do + empty_series = Series.new( + start_date: 1.day.ago.to_date, + end_date: Date.current, + interval: "1 day", + values: [] + ) + Rails.cache.clear + Balance::ChartSeriesBuilder.any_instance.expects(:balance_series).returns(empty_series) + + get accountable_sparkline_url("depository") + + assert_response :success + assert_select "p.font-mono", count: 0 + end + test "linked investment sparkline does not load full account records" do AccountProvider.create!( account: accounts(:investment), diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb index 9ae0139a4..66b3c0f03 100644 --- a/test/controllers/accounts_controller_test.rb +++ b/test/controllers/accounts_controller_test.rb @@ -345,6 +345,21 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test "sparkline renders an empty series without a trend" do + empty_series = Series.new( + start_date: 1.day.ago.to_date, + end_date: Date.current, + interval: "1 day", + values: [] + ) + Account.any_instance.expects(:sparkline_series).returns(empty_series) + + get sparkline_account_url(@account) + + assert_response :success + assert_select "p.font-mono", count: 0 + end + test "destroys account" do delete account_url(@account) assert_redirected_to accounts_path