Merge branch 'master' into feature/budget_phases

This commit is contained in:
BertoCQ
2018-01-16 17:47:47 +01:00
committed by GitHub
26 changed files with 166 additions and 76 deletions

View File

@@ -0,0 +1,19 @@
require 'rails_helper'
describe ApplicationController do
describe "#current_budget" do
it "returns the last budget that is not in draft phase" do
old_budget = create(:budget, phase: "finished", created_at: 2.years.ago)
previous_budget = create(:budget, phase: "accepting", created_at: 1.year.ago)
current_budget = create(:budget, phase: "accepting", created_at: 1.month.ago)
next_budget = create(:budget, phase: "drafting", created_at: 1.week.ago)
budget = subject.instance_eval{ current_budget }
expect(budget).to eq(current_budget)
end
end
end

View File

@@ -259,9 +259,10 @@ feature 'Budget Investments' do
context "Printing" do
scenario 'Printing budget investments' do
16.times { create(:budget_investment, budget: @budget) }
16.times { create(:budget_investment, budget: @budget, heading: @heading) }
click_link "Print Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Print Budget Investments"
@@ -273,15 +274,17 @@ feature 'Budget Investments' do
scenario "Filtering budget investments by heading to be printed", :js do
district_9 = create(:budget_heading, group: @group, name: "District Nine")
another_heading = create(:budget_heading, group: @group)
low_investment = create(:budget_investment, budget: @budget, title: 'Nuke district 9', heading: district_9, cached_votes_up: 1)
mid_investment = create(:budget_investment, budget: @budget, title: 'Change district 9', heading: district_9, cached_votes_up: 10)
top_investment = create(:budget_investment, budget: @budget, title: 'Destroy district 9', heading: district_9, cached_votes_up: 100)
unvoted_investment = create(:budget_investment, budget: @budget, title: 'Add new districts to the city')
unvoted_investment = create(:budget_investment, budget: @budget, heading: another_heading, title: 'Add new districts to the city')
user = create(:user, :level_two)
login_managed_user(user)
click_link "Print Budget Investments"
expect(page).to have_content(@budget.name)
within "#budget_#{@budget.id}" do
click_link "Print Budget Investments"

View File

@@ -24,18 +24,15 @@ feature 'Valuation budgets' do
end
scenario 'Filters by phase' do
budget1 = create(:budget)
budget2 = create(:budget, :accepting)
budget3 = create(:budget, :selecting)
budget4 = create(:budget, :balloting)
budget5 = create(:budget, :finished)
budget1 = create(:budget, :finished)
budget2 = create(:budget, :finished)
budget3 = create(:budget, :accepting)
visit valuation_budgets_path
expect(page).to have_content(budget1.name)
expect(page).to have_content(budget2.name)
expect(page).to_not have_content(budget1.name)
expect(page).to_not have_content(budget2.name)
expect(page).to have_content(budget3.name)
expect(page).to have_content(budget4.name)
expect(page).not_to have_content(budget5.name)
end
end

View File

@@ -66,6 +66,8 @@ feature 'Valuation' do
scenario 'Access as a valuator is authorized' do
create(:valuator, user: user)
create(:budget)
login_as(user)
visit root_path
@@ -78,6 +80,8 @@ feature 'Valuation' do
scenario 'Access as an administrator is authorized' do
create(:administrator, user: user)
create(:budget)
login_as(user)
visit root_path
@@ -90,6 +94,8 @@ feature 'Valuation' do
scenario "Valuation access links" do
create(:valuator, user: user)
create(:budget)
login_as(user)
visit root_path
@@ -100,6 +106,8 @@ feature 'Valuation' do
scenario 'Valuation dashboard' do
create(:valuator, user: user)
create(:budget)
login_as(user)
visit root_path

View File

@@ -118,6 +118,43 @@ describe Budget do
end
end
describe "#current" do
it "returns nil if there is only one budget and it is still in drafting phase" do
budget = create(:budget, phase: "drafting")
expect(Budget.current).to eq(nil)
end
it "returns the budget if there is only one and not in drafting phase" do
budget = create(:budget, phase: "accepting")
expect(Budget.current).to eq(budget)
end
it "returns the last budget created that is not in drafting phase" do
old_budget = create(:budget, phase: "finished", created_at: 2.years.ago)
previous_budget = create(:budget, phase: "accepting", created_at: 1.year.ago)
current_budget = create(:budget, phase: "accepting", created_at: 1.month.ago)
next_budget = create(:budget, phase: "drafting", created_at: 1.week.ago)
expect(Budget.current).to eq(current_budget)
end
end
describe "#open" do
it "returns all budgets that are not in the finished phase" do
phases = Budget::PHASES - ["finished"]
phases.each do |phase|
budget = create(:budget, phase: phase)
expect(Budget.open).to include(budget)
end
end
end
describe "heading_price" do
let(:group) { create(:budget_group, budget: budget) }