Skip to content

Commit

Permalink
Added test for valid session storage save
Browse files Browse the repository at this point in the history
  • Loading branch information
SleekMutt committed Nov 29, 2024
1 parent ceb3393 commit 6da8e16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/calculators/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</div>
<% end %>
<%= turbo_frame_tag "calc-results" do %>
<% if session.dig(:calculation_results, @calculator.slug)&.presence %>
<% if session.dig(:calculation_results, @calculator.slug).present? %>
<%= render "calculators/partials/calculation_results", results: session[:calculation_results][@calculator.slug].map(&:symbolize_keys) %>
<% end %>
<% end %>
Expand Down
13 changes: 13 additions & 0 deletions spec/requests/calculators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,17 @@
end
end
end

describe "POST #calculate" do
let(:calculator) { create(:calculator) }
let(:formula) { build(:formula, expression: "a + 5", calculator: calculator) }
let(:field) { build(:field, var_name: "a", calculator: calculator) }

it "stores the results in the session under the calculator slug" do
post calculate_calculator_path(calculator), params: { calculator: calculator, inputs: { a: 5 }, format: :turbo_stream }

expect(session[:calculation_results]).to have_key(calculator.slug)
expect(session[:calculation_results][calculator.slug]).to eq(assigns(:results))
end
end
end

0 comments on commit 6da8e16

Please sign in to comment.