From c00203f7f5b97d403db067b42329697f0761fd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 29 Apr 2019 18:58:25 +0200 Subject: [PATCH] Move budget stats permission tests to the model They're easier to test and to read in the model. --- spec/features/budgets/stats_spec.rb | 16 ---------------- spec/models/abilities/everyone_spec.rb | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/spec/features/budgets/stats_spec.rb b/spec/features/budgets/stats_spec.rb index 6318b1cea..c014389cb 100644 --- a/spec/features/budgets/stats_spec.rb +++ b/spec/features/budgets/stats_spec.rb @@ -7,22 +7,6 @@ feature "Stats" do let(:heading) { create(:budget_heading, group: group, price: 1000) } describe "Show" do - - it "is not accessible if supports phase is not finished" do - budget.update(phase: "selecting") - - 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 if supports phase is finished" do - budget.update(phase: "valuating") - - visit budget_stats_path(budget.id) - expect(page).to have_content "Stats" - end - end end diff --git a/spec/models/abilities/everyone_spec.rb b/spec/models/abilities/everyone_spec.rb index e2fcc3a43..671294ac5 100644 --- a/spec/models/abilities/everyone_spec.rb +++ b/spec/models/abilities/everyone_spec.rb @@ -73,4 +73,18 @@ describe Abilities::Everyone do it { should_not be_able_to(:stats, poll) } end end + + context "when accessing budget stats" do + context "supports phase is not finished" do + let(:budget) { create(:budget, phase: "selecting") } + + it { should_not be_able_to(:read_stats, budget) } + end + + context "supports phase is finished" do + let(:budget) { create(:budget, phase: "valuating") } + + it { should be_able_to(:read_stats, budget) } + end + end end