Move ballot partial to a component
This way it'll be easier to extract methods from its code and modify them.
This commit is contained in:
62
app/components/budgets/ballot/ballot_component.html.erb
Normal file
62
app/components/budgets/ballot/ballot_component.html.erb
Normal file
@@ -0,0 +1,62 @@
|
||||
<header>
|
||||
<%= back_link_to session[:ballot_referer] %>
|
||||
|
||||
<h1 class="text-center"><%= t("budgets.ballots.show.title") %></h1>
|
||||
|
||||
<div class="small-12 medium-8 column small-centered text-center">
|
||||
<h2>
|
||||
<%= sanitize(t("budgets.ballots.show.voted", count: ballot.investments.count)) %>
|
||||
</h2>
|
||||
<p class="confirmed">
|
||||
<%= t("budgets.ballots.show.voted_info") %>
|
||||
<p>
|
||||
<p><%= t("budgets.ballots.show.voted_info_2") %></p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="row ballot">
|
||||
<% ballot_groups = ballot.groups.sort_by_name %>
|
||||
<% ballot_groups.each do |group| %>
|
||||
<% heading = ballot.heading_for_group(group) %>
|
||||
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
|
||||
<div class="margin-top ballot-content">
|
||||
<div class="subtitle">
|
||||
<h3>
|
||||
<%= group.name %> - <%= heading.name %>
|
||||
</h3>
|
||||
<%= link_to sanitize(ballot.amount_available_info(heading)),
|
||||
budget_group_path(budget, group) %>
|
||||
</div>
|
||||
<% if ballot.has_lines_in_group?(group) %>
|
||||
<h4 class="amount-spent text-right">
|
||||
<%= sanitize(ballot.amount_spent_info(heading)) %>
|
||||
</h4>
|
||||
<% else %>
|
||||
<p>
|
||||
<%= t("budgets.ballots.show.zero") %><br>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<ul class="ballot-list">
|
||||
<%= render Budgets::Ballot::InvestmentComponent.with_collection(
|
||||
ballot.investments.by_group(group.id)
|
||||
) %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% no_balloted_groups = budget.groups.sort_by_name - ballot_groups %>
|
||||
<% no_balloted_groups.each do |group| %>
|
||||
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
|
||||
<div class="margin-top ballot-content">
|
||||
<div class="subtitle">
|
||||
<h3>
|
||||
<%= group.name %>
|
||||
</h3>
|
||||
<%= link_to t("budgets.ballots.show.no_balloted_group_yet"), budget_group_path(budget, group) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
11
app/components/budgets/ballot/ballot_component.rb
Normal file
11
app/components/budgets/ballot/ballot_component.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Budgets::Ballot::BallotComponent < ApplicationComponent
|
||||
attr_reader :ballot
|
||||
|
||||
def initialize(ballot)
|
||||
@ballot = ballot
|
||||
end
|
||||
|
||||
def budget
|
||||
ballot.budget
|
||||
end
|
||||
end
|
||||
@@ -1,63 +1 @@
|
||||
<header>
|
||||
<%= back_link_to session[:ballot_referer] %>
|
||||
|
||||
<h1 class="text-center"><%= t("budgets.ballots.show.title") %></h1>
|
||||
|
||||
<div class="small-12 medium-8 column small-centered text-center">
|
||||
<h2>
|
||||
<%= sanitize(t("budgets.ballots.show.voted", count: @ballot.investments.count)) %>
|
||||
</h2>
|
||||
<p class="confirmed">
|
||||
<%= t("budgets.ballots.show.voted_info") %>
|
||||
<p>
|
||||
<p><%= t("budgets.ballots.show.voted_info_2") %></p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="row ballot">
|
||||
<% ballot_groups = @ballot.groups.sort_by_name %>
|
||||
<% ballot_groups.each do |group| %>
|
||||
<% heading = @ballot.heading_for_group(group) %>
|
||||
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
|
||||
<div class="margin-top ballot-content">
|
||||
<div class="subtitle">
|
||||
<h3>
|
||||
<%= group.name %> - <%= heading.name %>
|
||||
</h3>
|
||||
<%= link_to sanitize(@ballot.amount_available_info(heading)),
|
||||
budget_group_path(@budget, group) %>
|
||||
</div>
|
||||
<% if @ballot.has_lines_in_group?(group) %>
|
||||
<h4 class="amount-spent text-right">
|
||||
<%= sanitize(@ballot.amount_spent_info(heading)) %>
|
||||
</h4>
|
||||
<% else %>
|
||||
<p>
|
||||
<%= t("budgets.ballots.show.zero") %><br>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
<ul class="ballot-list">
|
||||
<%= render Budgets::Ballot::InvestmentComponent.with_collection(
|
||||
@ballot.investments.by_group(group.id)
|
||||
) %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% no_balloted_groups = @budget.groups.sort_by_name - ballot_groups %>
|
||||
<% no_balloted_groups.each do |group| %>
|
||||
<div id="<%= dom_id(group) %>" class="small-12 medium-6 column end">
|
||||
<div class="margin-top ballot-content">
|
||||
<div class="subtitle">
|
||||
<h3>
|
||||
<%= group.name %>
|
||||
</h3>
|
||||
<%= link_to t("budgets.ballots.show.no_balloted_group_yet"), budget_group_path(@budget, group) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
<%= render Budgets::Ballot::BallotComponent.new(@ballot) %>
|
||||
|
||||
19
spec/components/budgets/ballot/ballot_component_spec.rb
Normal file
19
spec/components/budgets/ballot/ballot_component_spec.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Budgets::Ballot::BallotComponent do
|
||||
include Rails.application.routes.url_helpers
|
||||
before { request.session[:ballot_referer] = "/" }
|
||||
|
||||
describe "link to group" do
|
||||
let(:budget) { create(:budget, :balloting) }
|
||||
let(:ballot) { create(:budget_ballot, user: create(:user), budget: budget) }
|
||||
|
||||
it "displays links to vote on groups with no investments voted yet" do
|
||||
group = create(:budget_group, budget: budget)
|
||||
|
||||
render_inline Budgets::Ballot::BallotComponent.new(ballot)
|
||||
|
||||
expect(page).to have_link "You have not voted on this group yet, go vote!", href: budget_group_path(budget, group)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -344,15 +344,6 @@ describe "Ballots" do
|
||||
expect(page).to have_content "Still available to you €35"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Display links to vote on groups with no investments voted yet" do
|
||||
group = create(:budget_group, budget: budget)
|
||||
|
||||
login_as(user)
|
||||
visit budget_ballot_path(budget)
|
||||
|
||||
expect(page).to have_link "You have not voted on this group yet, go vote!", href: budget_group_path(budget, group)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Removing investments from ballot" do
|
||||
|
||||
Reference in New Issue
Block a user