adds new filters to admin valuations

This commit is contained in:
Juanjo Bazán
2016-03-03 19:02:13 +01:00
parent 2a4adc2e60
commit fb5e2beb54
6 changed files with 45 additions and 32 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 valuating valuation_finished}, only: :index
has_filters %w{valuation_open without_admin managed valuating valuation_finished}, only: :index
load_and_authorize_resource
@@ -26,5 +26,4 @@ class Admin::SpendingProposalsController < Admin::BaseController
@spending_proposal.update(params.require(:spending_proposal).permit(valuator_ids: []))
end
end

View File

@@ -18,9 +18,10 @@ class SpendingProposal < ActiveRecord::Base
validates :description, length: { maximum: SpendingProposal.description_max_length }
validates :terms_of_service, acceptance: { allow_nil: false }, on: :create
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_open, -> { where(valuation_finished: false) }
scope :without_admin, -> { valuation_open.where(administrator_id: nil) }
scope :managed, -> { valuation_open.where(valuation_assignments_count: 0).where("administrator_id IS NOT ?", nil) }
scope :valuating, -> { valuation_open.where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
scope :valuation_finished, -> { where(valuation_finished: true) }
scope :for_render, -> { includes(:geozone, administrator: :user, valuators: :user) }

View File

@@ -151,9 +151,9 @@ en:
geozone_filter_all: All zones
administrator_filter_all: All administrators
filters:
all: All
valuation_open: Open
without_admin: Without assigned admin
without_valuators: Without valuator
managed: Managed
valuating: Under valuation
valuation_finished: Valuation finished
title: Investment projects for participatory budgeting

View File

@@ -151,9 +151,9 @@ es:
geozone_filter_all: Todos los ámbitos de actuación
administrator_filter_all: Todos los administradores
filters:
all: Todas
valuation_open: Abiertas
without_admin: Sin administrador asignado
without_valuators: Sin evaluador
managed: Gestionando
valuating: En evaluación
valuation_finished: Evaluación finalizada
title: Propuestas de inversión para presupuestos participativos

View File

@@ -97,9 +97,9 @@ feature 'Admin spending proposals' do
end
scenario "Current filter is properly highlighted" do
filters_links = {'all' => 'All',
filters_links = {'valuation_open' => 'Open',
'without_admin' => 'Without assigned admin',
'without_valuators' => 'Without valuator',
'managed' => 'Managed',
'valuating' => 'Under valuation',
'valuation_finished' => 'Valuation finished'}
@@ -124,7 +124,7 @@ feature 'Admin spending proposals' do
valuating = create(:spending_proposal, title: "Evaluating...")
valuating.valuators << create(:valuator)
visit admin_spending_proposals_path(filter: 'all')
visit admin_spending_proposals_path(filter: 'valuation_open')
expect(page).to have_content("Assigned idea")
expect(page).to have_content("Evaluating...")
@@ -134,7 +134,7 @@ feature 'Admin spending proposals' do
expect(page).to have_content("Evaluating...")
expect(page).to_not have_content("Assigned idea")
visit admin_spending_proposals_path(filter: 'without_valuators')
visit admin_spending_proposals_path(filter: 'managed')
expect(page).to have_content("Assigned idea")
expect(page).to_not have_content("Evaluating...")
@@ -146,10 +146,10 @@ feature 'Admin spending proposals' do
valuating.valuators << create(:valuator)
valuated.valuators << create(:valuator)
visit admin_spending_proposals_path(filter: 'all')
visit admin_spending_proposals_path(filter: 'valuation_open')
expect(page).to have_content("Ongoing valuation")
expect(page).to have_content("Old idea")
expect(page).to_not have_content("Old idea")
visit admin_spending_proposals_path(filter: 'valuating')

View File

@@ -61,30 +61,43 @@ describe SpendingProposal do
end
end
describe "scopes" do
describe "valuation_open" do
it "should return all spending proposals with false valuation_finished" do
spending_proposal1 = create(:spending_proposal, valuation_finished: true)
spending_proposal2 = create(:spending_proposal)
valuation_open = SpendingProposal.valuation_open
expect(valuation_open.size).to eq(1)
expect(valuation_open.first).to eq(spending_proposal2)
end
end
describe "without_admin" do
it "should return all spending proposals without assigned admin" do
spending_proposal1 = create(:spending_proposal)
it "should return all open spending proposals without assigned admin" do
spending_proposal1 = create(:spending_proposal, valuation_finished: true)
spending_proposal2 = create(:spending_proposal, administrator: create(:administrator))
spending_proposal3 = create(:spending_proposal)
without_admin = SpendingProposal.without_admin
expect(without_admin.size).to eq(1)
expect(without_admin.first).to eq(spending_proposal1)
expect(without_admin.first).to eq(spending_proposal3)
end
end
describe "without_valuators" do
it "should return all spending proposals without assigned valuators" do
spending_proposal1 = create(:spending_proposal)
spending_proposal2 = create(:spending_proposal)
describe "managed" do
it "should return all open spending proposals with assigned admin but without assigned valuators" do
spending_proposal1 = create(:spending_proposal, administrator: create(:administrator))
spending_proposal2 = create(:spending_proposal, administrator: create(:administrator), valuation_finished: true)
spending_proposal3 = create(:spending_proposal, administrator: create(:administrator))
spending_proposal1.valuators << create(:valuator)
without_admin = SpendingProposal.without_valuators
managed = SpendingProposal.managed
expect(without_admin.size).to eq(1)
expect(without_admin.first).to eq(spending_proposal2)
expect(managed.size).to eq(1)
expect(managed.first).to eq(spending_proposal3)
end
end
@@ -97,10 +110,10 @@ describe SpendingProposal do
spending_proposal2.valuators << create(:valuator)
spending_proposal3.valuators << create(:valuator)
without_admin = SpendingProposal.valuating
valuating = SpendingProposal.valuating
expect(without_admin.size).to eq(1)
expect(without_admin.first).to eq(spending_proposal2)
expect(valuating.size).to eq(1)
expect(valuating.first).to eq(spending_proposal2)
end
end
@@ -113,10 +126,10 @@ describe SpendingProposal do
spending_proposal2.valuators << create(:valuator)
spending_proposal3.valuators << create(:valuator)
without_admin = SpendingProposal.valuation_finished
valuation_finished = SpendingProposal.valuation_finished
expect(without_admin.size).to eq(1)
expect(without_admin.first).to eq(spending_proposal3)
expect(valuation_finished.size).to eq(1)
expect(valuation_finished.first).to eq(spending_proposal3)
end
end
end