Merge pull request #937 from consul/valuation

Valuation status
This commit is contained in:
Raimond Garcia
2016-02-26 12:32:44 +01:00
6 changed files with 77 additions and 17 deletions

View File

@@ -2,7 +2,7 @@ class Admin::SpendingProposalsController < Admin::BaseController
include FeatureFlags
feature_flag :spending_proposals
has_filters %w{all without_admin without_valuators}, only: :index
has_filters %w{all without_admin without_valuators valuating valuation_finished}, only: :index
load_and_authorize_resource

View File

@@ -20,6 +20,8 @@ class SpendingProposal < ActiveRecord::Base
scope :without_admin, -> { where(administrator_id: nil) }
scope :without_valuators, -> { where(valuation_assignments_count: 0) }
scope :valuating, -> { where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
scope :valuation_finished, -> { where(valuation_finished: true) }
def description
super.try :html_safe

View File

@@ -143,6 +143,8 @@ en:
all: All
without_admin: Without assigned admin
without_valuators: Without valuator
valuating: Under valuation
valuation_finished: Valuation finished
title: Investment projects for participatory budgeting
admin_assigned: Assigned administrator
no_admin_assigned: No admin assigned

View File

@@ -143,6 +143,8 @@ es:
all: Todas
without_admin: Sin administrador asignado
without_valuators: Sin evaluador
valuating: En evaluación
valuation_finished: Evaluación finalizada
title: Propuestas de inversión para presupuestos participativos
admin_assigned: Administrador asignado
no_admin_assigned: Sin admin asignado

View File

@@ -75,29 +75,29 @@ feature 'Admin spending proposals' do
end
scenario "Current filter is properly highlighted" do
filters_links = {'all' => 'All',
'without_admin' => 'Without assigned admin',
'without_valuators' => 'Without valuator',
'valuating' => 'Under valuation',
'valuation_finished' => 'Valuation finished'}
visit admin_spending_proposals_path
expect(page).to_not have_link('All')
expect(page).to have_link('Without assigned admin')
expect(page).to have_link('Without valuator')
expect(page).to_not have_link(filters_links.values.first)
filters_links.keys.drop(1).each { |filter| expect(page).to have_link(filters_links[filter]) }
visit admin_spending_proposals_path(filter: 'without_admin')
expect(page).to_not have_link('Without assigned admin')
expect(page).to have_link('All')
expect(page).to have_link('Without valuator')
filters_links.each_pair do |current_filter, link|
visit admin_spending_proposals_path(filter: current_filter)
visit admin_spending_proposals_path(filter: 'without_valuators')
expect(page).to_not have_link('Without valuator')
expect(page).to have_link('Without assigned admin')
expect(page).to have_link('All')
expect(page).to_not have_link(link)
visit admin_spending_proposals_path(filter: 'all')
expect(page).to_not have_link('All')
expect(page).to have_link('Without assigned admin')
expect(page).to have_link('Without valuator')
(filters_links.keys - [current_filter]).each do |filter|
expect(page).to have_link(filters_links[filter])
end
end
end
scenario "Filtering proposals" do
scenario "Index filtering by assignment status" do
assigned = create(:spending_proposal, title: "Assigned idea", administrator: create(:administrator))
valuating = create(:spending_proposal, title: "Evaluating...")
valuating.valuators << create(:valuator)
@@ -118,6 +118,28 @@ feature 'Admin spending proposals' do
expect(page).to_not have_content("Evaluating...")
end
scenario "Index filtering by valuation status" do
valuating = create(:spending_proposal, title: "Ongoing valuation")
valuated = create(:spending_proposal, title: "Old idea", valuation_finished: true)
valuating.valuators << create(:valuator)
valuated.valuators << create(:valuator)
visit admin_spending_proposals_path(filter: 'all')
expect(page).to have_content("Ongoing valuation")
expect(page).to have_content("Old idea")
visit admin_spending_proposals_path(filter: 'valuating')
expect(page).to have_content("Ongoing valuation")
expect(page).to_not have_content("Old idea")
visit admin_spending_proposals_path(filter: 'valuation_finished')
expect(page).to_not have_content("Ongoing valuation")
expect(page).to have_content("Old idea")
end
scenario 'Show' do
administrator = create(:administrator, user: create(:user, username: 'Ana', email: 'ana@admins.org'))
valuator = create(:valuator, user: create(:user, username: 'Rachel', email: 'rachel@valuators.org'))

View File

@@ -87,6 +87,38 @@ describe SpendingProposal do
expect(without_admin.first).to eq(spending_proposal2)
end
end
describe "valuating" do
it "should return all spending proposals with assigned valuator but valuation not finished" do
spending_proposal1 = create(:spending_proposal)
spending_proposal2 = create(:spending_proposal)
spending_proposal3 = create(:spending_proposal, valuation_finished: true)
spending_proposal2.valuators << create(:valuator)
spending_proposal3.valuators << create(:valuator)
without_admin = SpendingProposal.valuating
expect(without_admin.size).to eq(1)
expect(without_admin.first).to eq(spending_proposal2)
end
end
describe "valuation_finished" do
it "should return all spending proposals with valuation finished" do
spending_proposal1 = create(:spending_proposal)
spending_proposal2 = create(:spending_proposal)
spending_proposal3 = create(:spending_proposal, valuation_finished: true)
spending_proposal2.valuators << create(:valuator)
spending_proposal3.valuators << create(:valuator)
without_admin = SpendingProposal.valuation_finished
expect(without_admin.size).to eq(1)
expect(without_admin.first).to eq(spending_proposal3)
end
end
end
end