Show assigned heading on investment show

This commit is contained in:
Julian Herrero
2022-01-17 16:47:37 +07:00
committed by taitus
parent 78ab37db09
commit 0c9a46221e
4 changed files with 24 additions and 7 deletions

View File

@@ -1,12 +1,11 @@
class Budgets::Investments::BallotComponent < ApplicationComponent class Budgets::Investments::BallotComponent < ApplicationComponent
attr_reader :investment, :investment_ids, :ballot, :assigned_heading attr_reader :investment, :investment_ids, :ballot
delegate :current_user, :heading_link, :link_to_verify_account, to: :helpers delegate :current_user, :heading_link, :link_to_verify_account, to: :helpers
def initialize(investment:, investment_ids:, ballot:, assigned_heading:) def initialize(investment:, investment_ids:, ballot:)
@investment = investment @investment = investment
@investment_ids = investment_ids @investment_ids = investment_ids
@ballot = ballot @ballot = ballot
@assigned_heading = assigned_heading
end end
private private
@@ -42,6 +41,10 @@ class Budgets::Investments::BallotComponent < ApplicationComponent
budget_ballot_path(budget)) budget_ballot_path(budget))
end end
def assigned_heading
ballot.heading_for_group(investment.group)
end
def cannot_vote_text def cannot_vote_text
if reason.present? && !voted? if reason.present? && !voted?
t("budgets.ballots.reasons_for_not_balloting.#{reason}", t("budgets.ballots.reasons_for_not_balloting.#{reason}",

View File

@@ -1,6 +1,5 @@
<%= render Budgets::Investments::BallotComponent.new( <%= render Budgets::Investments::BallotComponent.new(
investment: investment, investment: investment,
investment_ids: investment_ids, investment_ids: investment_ids,
ballot: ballot, ballot: ballot
assigned_heading: @assigned_heading
) %> ) %>

View File

@@ -8,8 +8,7 @@ describe Budgets::Investments::BallotComponent do
Budgets::Investments::BallotComponent.new( Budgets::Investments::BallotComponent.new(
investment: investment, investment: investment,
investment_ids: [], investment_ids: [],
ballot: Budget::Ballot.where(budget: budget, user: controller.current_user).first_or_create!, ballot: Budget::Ballot.where(budget: budget, user: controller.current_user).first_or_create!
assigned_heading: nil
) )
end end

View File

@@ -1389,6 +1389,22 @@ describe "Budget Investments" do
expect(page).to have_content "€10,000" expect(page).to have_content "€10,000"
end end
scenario "Show message if user already voted in other heading" do
group = create(:budget_group, budget: budget, name: "Global Group")
heading = create(:budget_heading, group: group, name: "Heading 1")
investment = create(:budget_investment, :selected, heading: heading)
heading2 = create(:budget_heading, group: group, name: "Heading 2")
investment2 = create(:budget_investment, :selected, heading: heading2)
user = create(:user, :level_two, ballot_lines: [investment])
login_as(user)
visit budget_investment_path(budget, investment2)
expect(page).to have_selector(".participation-not-allowed",
text: "You have already voted a different heading: Heading 1",
visible: :hidden)
end
scenario "Sidebar in show should display vote text" do scenario "Sidebar in show should display vote text" do
investment = create(:budget_investment, :selected, budget: budget) investment = create(:budget_investment, :selected, budget: budget)
visit budget_investment_path(budget, investment) visit budget_investment_path(budget, investment)