Merge pull request #4769 from consul/assigned_heading

Show assigned heading on investment show
This commit is contained in:
Sebastia
2022-03-31 17:20:50 +02:00
committed by GitHub
5 changed files with 32 additions and 14 deletions

View File

@@ -1,12 +1,11 @@
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
def initialize(investment:, investment_ids:, ballot:, assigned_heading:)
def initialize(investment:, investment_ids:, ballot:)
@investment = investment
@investment_ids = investment_ids
@ballot = ballot
@assigned_heading = assigned_heading
end
private
@@ -42,6 +41,10 @@ class Budgets::Investments::BallotComponent < ApplicationComponent
budget_ballot_path(budget))
end
def assigned_heading
ballot.heading_for_group(investment.group)
end
def cannot_vote_text
if reason.present? && !voted?
t("budgets.ballots.reasons_for_not_balloting.#{reason}",

View File

@@ -20,6 +20,7 @@ module Budgets
before_action :load_ballot, only: [:index, :show]
before_action :load_heading, only: [:index, :show]
before_action :load_map, only: [:index]
before_action :set_random_seed, only: :index
before_action :load_categories, only: :index
before_action :set_default_investment_filter, only: :index
@@ -134,10 +135,8 @@ module Budgets
if params[:heading_id].present?
@heading = @budget.headings.find_by_slug_or_id! params[:heading_id]
@assigned_heading = @ballot&.heading_for_group(@heading.group)
load_map
elsif @budget.single_heading?
@heading = @budget.headings.first
load_map
end
end
@@ -161,13 +160,15 @@ module Budgets
@view = (params[:view] == "minimal") ? "minimal" : "default"
end
def investments_with_filters
@budget.investments.apply_filters_and_search(@budget, params, @current_filter)
end
def investments
if @current_order == "random"
@budget.investments.apply_filters_and_search(@budget, params, @current_filter)
.sort_by_random(session[:random_seed])
investments_with_filters.sort_by_random(session[:random_seed])
else
@budget.investments.apply_filters_and_search(@budget, params, @current_filter)
.send("sort_by_#{@current_order}")
investments_with_filters.send("sort_by_#{@current_order}")
end
end
@@ -180,7 +181,7 @@ module Budgets
end
def load_map
@map_location = MapLocation.load_from_heading(@heading)
@map_location = MapLocation.load_from_heading(@heading) if @heading.present?
end
end
end

View File

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

View File

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

View File

@@ -1389,6 +1389,22 @@ describe "Budget Investments" do
expect(page).to have_content "€10,000"
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
investment = create(:budget_investment, :selected, budget: budget)
visit budget_investment_path(budget, investment)