From 4e3b3f2028998ae6404730392997c9746d33fb0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 29 Sep 2021 04:06:51 +0200 Subject: [PATCH] Extract methods in votes components This way we can make the view code a bit easier to read. We're also changing the order of the conditions a little bit so we only check for the presence of a current user once. To make sure we aren't breaking anything with these changes, we're adding some tests. We're also replacing one system test checking content with a component test, since component tests are much faster. --- .../investments/ballot_component.html.erb | 15 +--- .../budgets/investments/ballot_component.rb | 19 +++++ .../debates/votes_component.html.erb | 13 ++-- app/components/debates/votes_component.rb | 14 ++++ .../proposals/votes_component.html.erb | 13 ++-- .../legislation/proposals/votes_component.rb | 14 ++++ .../proposals/votes_component.html.erb | 18 ++--- app/components/proposals/votes_component.rb | 14 ++++ .../proposals/votes_component_spec.rb | 77 +++++++++++++++++++ spec/system/votes_spec.rb | 22 ------ 10 files changed, 163 insertions(+), 56 deletions(-) create mode 100644 spec/components/proposals/votes_component_spec.rb diff --git a/app/components/budgets/investments/ballot_component.html.erb b/app/components/budgets/investments/ballot_component.html.erb index 189236531..0bf6ee56a 100644 --- a/app/components/budgets/investments/ballot_component.html.erb +++ b/app/components/budgets/investments/ballot_component.html.erb @@ -1,6 +1,5 @@ -<% reason = investment.reason_for_not_being_ballotable_by(current_user, ballot) %>
- <% if ballot.has_investment?(investment) %> + <% if voted? %>
"> @@ -36,20 +35,14 @@
<% end %> - <% if reason.present? && !ballot.has_investment?(investment) %> + <% if reason.present? && !voted? %>