Add budget stats permissions for normal users and admins

This commit is contained in:
María Checa
2018-07-05 18:40:17 +02:00
committed by Javi Martín
parent 70e108d593
commit c2457e36a5
3 changed files with 39 additions and 1 deletions

View File

@@ -66,6 +66,7 @@ module Abilities
can [:hide, :update, :toggle_selection], Budget::Investment can [:hide, :update, :toggle_selection], Budget::Investment
can [:valuate, :comment_valuation], Budget::Investment can [:valuate, :comment_valuation], Budget::Investment
can :create, Budget::ValuatorAssignment can :create, Budget::ValuatorAssignment
can :read_stats, Budget, phase: "reviewing_ballots"
can [:search, :edit, :update, :create, :index, :destroy], Banner can [:search, :edit, :update, :create, :index, :destroy], Banner

View File

@@ -21,7 +21,7 @@ module Abilities
can [:read], Budget::Group can [:read], Budget::Group
can [:read, :print, :json_data], Budget::Investment can [:read, :print, :json_data], Budget::Investment
can [:read_results, :read_executions], Budget, phase: "finished" can [:read_results, :read_executions], Budget, phase: "finished"
can :read_stats, Budget, phase: ["reviewing_ballots", "finished"] can :read_stats, Budget, phase: "finished"
can :new, DirectMessage can :new, DirectMessage
can [:read, :debate, :draft_publication, :allegations, :result_publication, can [:read, :debate, :draft_publication, :allegations, :result_publication,
:proposals, :milestones], Legislation::Process, published: true :proposals, :milestones], Legislation::Process, published: true

View File

@@ -0,0 +1,37 @@
require "rails_helper"
feature "Stats" do
let(:budget) { create(:budget) }
let(:group) { create(:budget_group, budget: budget) }
let(:heading) { create(:budget_heading, group: group, price: 1000) }
describe "Show" do
it "is not accessible to normal users if phase is not 'finished'" do
budget.update(phase: "reviewing_ballots")
visit budget_stats_path(budget.id)
expect(page).to have_content "You do not have permission to carry out the action "\
"'read_stats' on budget."
end
it "is accessible to normal users if phase is 'finished'" do
budget.update(phase: "finished")
visit budget_stats_path(budget.id)
expect(page).to have_content "Stats"
end
it "is accessible to administrators when budget has phase 'reviewing_ballots'" do
budget.update(phase: "reviewing_ballots")
login_as(create(:administrator).user)
visit budget_stats_path(budget.id)
expect(page).to have_content "Stats"
end
end
end