Fix condition to show the "see results" link
This condition was obsolete since we introduced the `results_enabled`
field in commit 4f4dc2c2a.
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
<div class="budgets-links">
|
<div class="budgets-links">
|
||||||
<% if budget.has_winning_investments? %>
|
<% if can?(:read_results, budget) %>
|
||||||
<%= action(:results,
|
<%= action(:results, text: results_text, path: budget_results_path(budget)) %>
|
||||||
text: t("budgets.show.see_results"),
|
|
||||||
path: budget_results_path(budget)) %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= action(:preview, text: t("admin.budgets.actions.preview"), path: budget_path(budget), target: "_blank") %>
|
<%= action(:preview, text: t("admin.budgets.actions.preview"), path: budget_path(budget), target: "_blank") %>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class Admin::Budgets::LinksComponent < ApplicationComponent
|
class Admin::Budgets::LinksComponent < ApplicationComponent
|
||||||
attr_reader :budget
|
attr_reader :budget
|
||||||
|
delegate :can?, to: :helpers
|
||||||
|
|
||||||
def initialize(budget)
|
def initialize(budget)
|
||||||
@budget = budget
|
@budget = budget
|
||||||
@@ -10,4 +11,12 @@ class Admin::Budgets::LinksComponent < ApplicationComponent
|
|||||||
def action(action_name, **options)
|
def action(action_name, **options)
|
||||||
render Admin::ActionComponent.new(action_name, budget, **options)
|
render Admin::ActionComponent.new(action_name, budget, **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def results_text
|
||||||
|
if Abilities::Everyone.new(User.new).can?(:read_results, budget)
|
||||||
|
t("budgets.show.see_results")
|
||||||
|
else
|
||||||
|
t("admin.budgets.actions.preview_results")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ module Abilities
|
|||||||
can [:index, :read, :new, :create, :update, :destroy], Budget
|
can [:index, :read, :new, :create, :update, :destroy], Budget
|
||||||
can :publish, Budget, id: Budget.drafting.ids
|
can :publish, Budget, id: Budget.drafting.ids
|
||||||
can :calculate_winners, Budget, &:reviewing_ballots?
|
can :calculate_winners, Budget, &:reviewing_ballots?
|
||||||
|
can :read_results, Budget do |budget|
|
||||||
|
budget.balloting_finished? && budget.has_winning_investments?
|
||||||
|
end
|
||||||
|
|
||||||
can [:read, :create, :update, :destroy], Budget::Group
|
can [:read, :create, :update, :destroy], Budget::Group
|
||||||
can [:read, :create, :update, :destroy], Budget::Heading
|
can [:read, :create, :update, :destroy], Budget::Heading
|
||||||
|
|||||||
@@ -158,6 +158,10 @@ class Budget < ApplicationRecord
|
|||||||
current_phase&.balloting_or_later?
|
current_phase&.balloting_or_later?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def balloting_finished?
|
||||||
|
balloting_or_later? && !balloting?
|
||||||
|
end
|
||||||
|
|
||||||
def single_group?
|
def single_group?
|
||||||
groups.one?
|
groups.one?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<% if @budget.has_winning_investments? %>
|
<% if can?(:read_results, @budget) %>
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<%= link_to t("admin.budget_investments.index.see_results"),
|
<%= link_to t("admin.budget_investments.index.see_results"),
|
||||||
budget_results_path(@budget, heading_id: @budget.headings.first),
|
budget_results_path(@budget, heading_id: @budget.headings.first),
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ en:
|
|||||||
actions:
|
actions:
|
||||||
edit: "Edit budget"
|
edit: "Edit budget"
|
||||||
preview: "Preview"
|
preview: "Preview"
|
||||||
|
preview_results: "Preview results"
|
||||||
index:
|
index:
|
||||||
title: Participatory budgets
|
title: Participatory budgets
|
||||||
new_link: Create new budget
|
new_link: Create new budget
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ es:
|
|||||||
actions:
|
actions:
|
||||||
edit: "Editar presupuesto"
|
edit: "Editar presupuesto"
|
||||||
preview: "Previsualizar"
|
preview: "Previsualizar"
|
||||||
|
preview_results: "Previsualizar resultados"
|
||||||
index:
|
index:
|
||||||
title: Presupuestos participativos
|
title: Presupuestos participativos
|
||||||
new_link: Crear nuevo presupuesto
|
new_link: Crear nuevo presupuesto
|
||||||
|
|||||||
59
spec/components/admin/budgets/links_component_spec.rb
Normal file
59
spec/components/admin/budgets/links_component_spec.rb
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Admin::Budgets::LinksComponent, controller: Admin::BaseController do
|
||||||
|
before { sign_in(create(:administrator).user) }
|
||||||
|
|
||||||
|
describe "see results link" do
|
||||||
|
let(:budget) { create(:budget, :finished) }
|
||||||
|
let(:component) { Admin::Budgets::LinksComponent.new(budget) }
|
||||||
|
|
||||||
|
it "is shown for budgets with results enabled" do
|
||||||
|
budget.update!(results_enabled: true)
|
||||||
|
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_link "See results"
|
||||||
|
expect(page).not_to have_link "Preview results"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is not shown for budgets with results disabled" do
|
||||||
|
budget.update!(results_enabled: false)
|
||||||
|
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).not_to have_link "See results"
|
||||||
|
expect(page).not_to have_link "Preview results"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "after calculating winners" do
|
||||||
|
let(:budget) { create(:budget, :with_winner) }
|
||||||
|
|
||||||
|
it "is shown as a preview link after finishing the process" do
|
||||||
|
budget.update!(phase: "finished", results_enabled: false)
|
||||||
|
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_link "Preview results"
|
||||||
|
expect(page).not_to have_link "See results"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is shown as a preview link after balloting has finished" do
|
||||||
|
budget.update!(phase: "reviewing_ballots", results_enabled: false)
|
||||||
|
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_link "Preview results"
|
||||||
|
expect(page).not_to have_link "See results"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is not shown while balloting" do
|
||||||
|
budget.update!(phase: "balloting", results_enabled: true)
|
||||||
|
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).not_to have_link "Preview results"
|
||||||
|
expect(page).not_to have_link "See results"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -64,6 +64,10 @@ FactoryBot.define do
|
|||||||
trait :approval do
|
trait :approval do
|
||||||
voting_style { "approval" }
|
voting_style { "approval" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
trait :with_winner do
|
||||||
|
after(:create) { |budget| create(:budget_investment, :winner, budget: budget) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :budget_group, class: "Budget::Group" do
|
factory :budget_group, class: "Budget::Group" do
|
||||||
|
|||||||
@@ -77,7 +77,14 @@ describe Abilities::Administrator do
|
|||||||
|
|
||||||
it { should be_able_to(:create, Budget) }
|
it { should be_able_to(:create, Budget) }
|
||||||
it { should be_able_to(:update, Budget) }
|
it { should be_able_to(:update, Budget) }
|
||||||
it { should be_able_to(:read_results, Budget) }
|
|
||||||
|
it { should be_able_to(:read_results, create(:budget, :reviewing_ballots, :with_winner)) }
|
||||||
|
it { should be_able_to(:read_results, create(:budget, :finished, :with_winner)) }
|
||||||
|
it { should be_able_to(:read_results, create(:budget, :finished, results_enabled: true)) }
|
||||||
|
it { should_not be_able_to(:read_results, create(:budget, :balloting, :with_winner, results_enabled: true)) }
|
||||||
|
it { should_not be_able_to(:read_results, create(:budget, :reviewing_ballots, results_enabled: true)) }
|
||||||
|
it { should_not be_able_to(:read_results, create(:budget, :finished, results_enabled: false)) }
|
||||||
|
|
||||||
it { should be_able_to(:calculate_winners, create(:budget, :reviewing_ballots)) }
|
it { should be_able_to(:calculate_winners, create(:budget, :reviewing_ballots)) }
|
||||||
it { should_not be_able_to(:calculate_winners, create(:budget, :balloting)) }
|
it { should_not be_able_to(:calculate_winners, create(:budget, :balloting)) }
|
||||||
it { should_not be_able_to(:calculate_winners, create(:budget, :finished)) }
|
it { should_not be_able_to(:calculate_winners, create(:budget, :finished)) }
|
||||||
|
|||||||
@@ -351,6 +351,14 @@ describe "Admin budgets", :admin do
|
|||||||
|
|
||||||
visit admin_budget_path(budget)
|
visit admin_budget_path(budget)
|
||||||
|
|
||||||
|
expect(page).not_to have_link "See results"
|
||||||
|
|
||||||
|
click_link "Edit budget"
|
||||||
|
select "Finished budget", from: "Active phase"
|
||||||
|
check "Show results"
|
||||||
|
click_button "Update Budget"
|
||||||
|
|
||||||
|
expect(page).to have_content "Participatory budget updated successfully"
|
||||||
expect(page).to have_link "See results"
|
expect(page).to have_link "See results"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user