diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb
index 63fd316a6..416799535 100644
--- a/app/controllers/admin/budget_investments_controller.rb
+++ b/app/controllers/admin/budget_investments_controller.rb
@@ -7,11 +7,12 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
has_orders %w{oldest}, only: [:show, :edit]
has_filters(%w{all without_admin without_valuator under_valuation
valuation_finished winners},
- only: [:index, :toggle_selection])
+ only: [:index, :toggle_selection])
before_action :load_budget
before_action :load_investment, only: [:show, :edit, :update, :toggle_selection]
before_action :load_ballot, only: [:show, :index]
+ before_action :parse_valuation_filters
before_action :load_investments, only: [:index, :toggle_selection]
def index
@@ -46,6 +47,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
else
load_admins
load_valuators
+ load_valuator_groups
load_tags
render :edit
end
@@ -131,4 +133,16 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
params[:budget_investment] = params[:budget_investment].except(:valuation_tag_list)
end
+ def parse_valuation_filters
+ if params[:valuator_or_group_id]
+ model, id = params[:valuator_or_group_id].split("_")
+
+ if model == "group"
+ params[:valuator_group_id] = id
+ else
+ params[:valuator_id] = id
+ end
+ end
+ end
+
end
diff --git a/app/controllers/admin/valuator_groups_controller.rb b/app/controllers/admin/valuator_groups_controller.rb
index 054fe15ce..6e8930122 100644
--- a/app/controllers/admin/valuator_groups_controller.rb
+++ b/app/controllers/admin/valuator_groups_controller.rb
@@ -19,8 +19,8 @@ class Admin::ValuatorGroupsController < Admin::BaseController
def create
@group = ValuatorGroup.new(group_params)
if @group.save
- notice = t("user_group.notice.created")
- redirect_to admin_valuator_groups_path, notice: notice
+ notice = t("flash.actions.create.valuator_group")
+ redirect_to [:admin, :valuator_groups], notice: notice
else
render :new
end
@@ -29,7 +29,7 @@ class Admin::ValuatorGroupsController < Admin::BaseController
def update
@group = ValuatorGroup.find(params[:id])
if @group.update(group_params)
- notice = t("user_group.notice.updated")
+ notice = t("flash.actions.update.valuator_group")
redirect_to [:admin, @group], notice: notice
else
render :edit
@@ -39,8 +39,8 @@ class Admin::ValuatorGroupsController < Admin::BaseController
def destroy
@group = ValuatorGroup.find(params[:id])
@group.destroy
- notice = t("user_group.notice.destroyed")
- redirect_to admin_valuator_groups_path, notice: notice
+ notice = t("flash.actions.destroy.valuator_group")
+ redirect_to [:admin, :valuator_groups], notice: notice
end
private
diff --git a/app/helpers/valuation_helper.rb b/app/helpers/valuation_helper.rb
index 3a7e3dba7..311f8e6ec 100644
--- a/app/helpers/valuation_helper.rb
+++ b/app/helpers/valuation_helper.rb
@@ -1,23 +1,21 @@
module ValuationHelper
- def valuator_select_options(valuator = nil)
- if valuator.present?
- Valuator.where.not(id: valuator.id).order("description ASC").order("users.email ASC")
- .includes(:user).collect { |v| [ v.description_or_email, v.id ] }
- .prepend([valuator.description_or_email, valuator.id])
- else
- Valuator.all.order("description ASC").order("users.email ASC").includes(:user).collect { |v| [ v.description_or_email, v.id ] }
- end
+ def valuator_or_group_select_options
+ valuator_group_select_options + valuator_select_options
end
- def valuator_group_select_options(group = nil)
- if group.present?
- ValuatorGroup.where.not(id: group.id).order("name ASC")
- .collect { |g| [ g.name, g.id ] }
- .prepend([valuator.name, valuator.id])
- else
- ValuatorGroup.order("name ASC").collect { |g| [ g.name, g.id ] }
- end
+ def valuator_select_options
+ Valuator.order("description ASC").order("users.email ASC").includes(:user).
+ collect { |v| [ v.description_or_email, "valuator_#{v.id}"] }
+ end
+
+ def valuator_group_select_options
+ ValuatorGroup.order("name ASC").collect { |g| [ g.name, "group_#{g.id}"] }
+ end
+
+ def assigned_valuators(investment)
+ [investment.valuator_groups.collect(&:name) +
+ investment.valuators.collect(&:description_or_name)].flatten.join(', ')
end
def assigned_valuators_info(valuators)
diff --git a/app/models/abilities/valuator.rb b/app/models/abilities/valuator.rb
index 8ea8d71cf..cec3e5f1d 100644
--- a/app/models/abilities/valuator.rb
+++ b/app/models/abilities/valuator.rb
@@ -4,6 +4,7 @@ module Abilities
def initialize(user)
valuator = user.valuator
+
can [:read, :update, :valuate], SpendingProposal
can [:read, :update, :comment_valuation], Budget::Investment, id: valuator.investment_ids + valuator.valuator_group.investment_ids
can [:valuate], Budget::Investment, { id: valuator.investment_ids + valuator.valuator_group.investment_ids, valuation_finished: false }
diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb
index 34565a7d4..c8c12e0f8 100644
--- a/app/models/budget/investment.rb
+++ b/app/models/budget/investment.rb
@@ -62,9 +62,9 @@ class Budget
scope :valuation_open, -> { where(valuation_finished: false) }
scope :without_admin, -> { valuation_open.where(administrator_id: nil) }
scope :without_valuator, -> { valuation_open.where(valuator_assignments_count: 0) }
- scope :under_valuation, -> { valuation_open.where("valuator_assignments_count > 0 AND administrator_id IS NOT ?", nil) }
+ scope :under_valuation, -> { valuation_open.valuating.where("administrator_id IS NOT ?", nil) }
scope :managed, -> { valuation_open.where(valuator_assignments_count: 0).where("administrator_id IS NOT ?", nil) }
- scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0") }
+ scope :valuating, -> { valuation_open.where("valuator_assignments_count > 0 OR valuator_group_assignments_count > 0" ) }
scope :valuation_finished, -> { where(valuation_finished: true) }
scope :valuation_finished_feasible, -> { where(valuation_finished: true, feasibility: "feasible") }
scope :feasible, -> { where(feasibility: "feasible") }
diff --git a/app/models/budget/valuator_group_assignment.rb b/app/models/budget/valuator_group_assignment.rb
index 1aa4331fc..88a04ae1a 100644
--- a/app/models/budget/valuator_group_assignment.rb
+++ b/app/models/budget/valuator_group_assignment.rb
@@ -1,6 +1,6 @@
class Budget
class ValuatorGroupAssignment < ActiveRecord::Base
- belongs_to :valuator_group
- belongs_to :investment
+ belongs_to :valuator_group, counter_cache: :budget_investments_count
+ belongs_to :investment, counter_cache: true
end
end
\ No newline at end of file
diff --git a/app/models/valuator.rb b/app/models/valuator.rb
index 85f199adb..30b171823 100644
--- a/app/models/valuator.rb
+++ b/app/models/valuator.rb
@@ -18,4 +18,9 @@ class Valuator < ActiveRecord::Base
def description_or_name
description.present? ? description : name
end
+
+ def assigned_investment_ids
+ investment_ids + [valuator_group.try(:investment_ids)].flatten
+ end
+
end
diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb
index 33ae48d36..9d52f78d6 100644
--- a/app/views/admin/budget_investments/_investments.html.erb
+++ b/app/views/admin/budget_investments/_investments.html.erb
@@ -24,7 +24,6 @@
<%= t("admin.budget_investments.index.table_supports") %> |
<%= t("admin.budget_investments.index.table_admin") %> |
<%= t("admin.budget_investments.index.table_valuator") %> |
- <%= t("admin.budget_investments.index.table_valuator_group") %> |
<%= t("admin.budget_investments.index.table_geozone") %> |
<%= t("admin.budget_investments.index.table_feasibility") %> |
<%= t("admin.budget_investments.index.table_valuation_finished") %> |
@@ -61,17 +60,10 @@
<% end %>
- <% if investment.valuators.size.zero? %>
+ <% if investment.valuators.size == 0 && investment.valuator_groups.size == 0 %>
<%= t("admin.budget_investments.index.no_valuators_assigned") %>
<% else %>
- <%= investment.valuators.collect(&:description_or_name).join(", ") %>
- <% end %>
- |
-
- <% if investment.valuator_groups.size.zero? %>
- <%= t("admin.budget_investments.index.no_valuator_groups_assigned") %>
- <% else %>
- <%= investment.valuator_groups.collect(&:name).join(", ") %>
+ <%= assigned_valuators(investment) %>
<% end %>
|
diff --git a/app/views/admin/budget_investments/index.html.erb b/app/views/admin/budget_investments/index.html.erb
index c7417be45..4548e47c0 100644
--- a/app/views/admin/budget_investments/index.html.erb
+++ b/app/views/admin/budget_investments/index.html.erb
@@ -12,21 +12,13 @@
- <%= select_tag :valuator_id,
- options_for_select(valuator_select_options, params[:valuator_id]),
+ <%= select_tag :valuator_or_group_id,
+ options_for_select(valuator_or_group_select_options, params[:valuator_or_group_id]),
{ prompt: t("admin.budget_investments.index.valuator_filter_all"),
label: false,
class: "js-submit-on-change" } %>
-
- <%= select_tag :valuator_group_id,
- options_for_select(valuator_group_select_options, params[:valuator_group_id]),
- { prompt: t("admin.budget_investments.index.valuator_group_filter_all"),
- label: false,
- class: "js-submit-on-change" } %>
-
-
<%= select_tag :heading_id,
options_for_select(budget_heading_select_options(@budget), params[:heading_id]),
diff --git a/app/views/admin/valuator_groups/_valuator.html.erb b/app/views/admin/valuator_groups/_valuator.html.erb
new file mode 100644
index 000000000..8f98a8173
--- /dev/null
+++ b/app/views/admin/valuator_groups/_valuator.html.erb
@@ -0,0 +1,4 @@
+
+ <%= link_to valuator.description_or_email,
+ admin_valuator_path(valuator) %>
+
\ No newline at end of file
diff --git a/app/views/admin/valuator_groups/show.html.erb b/app/views/admin/valuator_groups/show.html.erb
index 2cd295a3f..f75490c1b 100644
--- a/app/views/admin/valuator_groups/show.html.erb
+++ b/app/views/admin/valuator_groups/show.html.erb
@@ -3,10 +3,11 @@
<%= t("admin.valuator_groups.show.title", group: @group.name) %>
diff --git a/app/views/admin/valuators/search.html.erb b/app/views/admin/valuators/search.html.erb
index 3a2f48be7..93907ceb9 100644
--- a/app/views/admin/valuators/search.html.erb
+++ b/app/views/admin/valuators/search.html.erb
@@ -30,6 +30,10 @@
<% end %>
<% if user.valuator? %>
+ <%= link_to t("admin.actions.edit"),
+ edit_admin_valuator_path(user.valuator),
+ class: "button hollow" %>
+
<%= link_to t("admin.valuators.valuator.delete"),
admin_valuator_path(user),
method: :delete,
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 70f326d6b..f85d6a8c8 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -140,7 +140,6 @@ en:
heading_filter_all: All headings
administrator_filter_all: All administrators
valuator_filter_all: All valuators
- valuator_group_filter_all: All groups
tags_filter_all: All tags
advanced_filters: Advanced filters
placeholder: Search projects
@@ -172,7 +171,6 @@ en:
assigned_admin: Assigned administrator
no_admin_assigned: No admin assigned
no_valuators_assigned: No valuators assigned
- no_valuator_groups_assigned: No valuator groups assigned
feasibility:
feasible: "Feasible (%{price})"
unfeasible: "Unfeasible"
@@ -184,7 +182,6 @@ en:
table_supports: "Supports"
table_admin: "Administrator"
table_valuator: "Valuator"
- table_valuator_group: "Valuator group"
table_geozone: "Scope of operation"
table_feasibility: "Feasibility"
table_valuation_finished: "Val. Fin."
@@ -590,7 +587,6 @@ en:
group: "Group"
no_group: "No group"
valuator:
- description_placeholder: 'Description (optional)'
add: Add to valuators
delete: Delete
search:
@@ -623,6 +619,7 @@ en:
no_groups: "There are no valuator groups"
show:
title: "Valuators group: %{group}"
+ no_valuators: "There are no valuators assigned to this group"
form:
name: "Group name"
new: "Create valuators group"
@@ -959,7 +956,6 @@ en:
geozone_filter_all: All zones
administrator_filter_all: All administrators
valuator_filter_all: All valuators
- valuator_group_filter_all: All groups
tags_filter_all: All tags
filters:
valuation_open: Open
@@ -972,7 +968,6 @@ en:
assigned_admin: Assigned administrator
no_admin_assigned: No admin assigned
no_valuators_assigned: No valuators assigned
- no_valuator_groups_assigned: No valuator groups assigned
summary_link: "Investment project summary"
valuator_summary_link: "Valuator summary"
feasibility:
diff --git a/config/locales/en/responders.yml b/config/locales/en/responders.yml
index cc6d58bb0..f91cb807c 100644
--- a/config/locales/en/responders.yml
+++ b/config/locales/en/responders.yml
@@ -16,6 +16,7 @@ en:
budget_investment: "Budget Investment created successfully."
signature_sheet: "Signature sheet created successfully"
topic: "Topic created successfully."
+ valuator_group: "Valuator group created successfully"
save_changes:
notice: Changes saved
update:
@@ -27,9 +28,11 @@ en:
spending_proposal: "Investment project updated succesfully."
budget_investment: "Investment project updated succesfully."
topic: "Topic updated successfully."
+ valuator_group: "Valuator group updated successfully"
destroy:
spending_proposal: "Spending proposal deleted succesfully."
budget_investment: "Investment project deleted succesfully."
error: "Could not delete"
topic: "Topic deleted successfully."
poll_question_answer_video: "Answer video deleted successfully."
+ valuator_group: "Valuator group deleted successfully"
diff --git a/config/locales/en/user_groups.yml b/config/locales/en/user_groups.yml
deleted file mode 100644
index 6b44b5495..000000000
--- a/config/locales/en/user_groups.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-en:
- user_group:
- notice:
- created: "User group created successfully"
- updated: "User group updated successfully"
- destroyed: "User group deleted successfully"
diff --git a/config/locales/en/valuation.yml b/config/locales/en/valuation.yml
index 18587e772..18fb6ab87 100644
--- a/config/locales/en/valuation.yml
+++ b/config/locales/en/valuation.yml
@@ -31,7 +31,6 @@ en:
one: Assigned valuator
other: "%{count} valuators assigned"
no_valuators_assigned: No valuators assigned
- no_valuator_groups_assigned: No valuator groups assigned
table_id: ID
table_title: Title
table_heading_name: Heading name
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 0840479bd..64e7dafd0 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -140,7 +140,6 @@ es:
heading_filter_all: Todas las partidas
administrator_filter_all: Todos los administradores
valuator_filter_all: Todos los evaluadores
- valuator_group_filter_all: Todos los grupos
tags_filter_all: Todas las etiquetas
advanced_filters: Filtros avanzados
placeholder: Buscar proyectos
@@ -172,7 +171,6 @@ es:
assigned_admin: Administrador asignado
no_admin_assigned: Sin admin asignado
no_valuators_assigned: Sin evaluador
- no_valuator_groups_assigned: Sin grupo evaluador
feasibility:
feasible: "Viable (%{price})"
unfeasible: "Inviable"
@@ -184,7 +182,6 @@ es:
table_supports: "Apoyos"
table_admin: "Administrador"
table_valuator: "Evaluador"
- table_valuator_group: "Grupo Evaluador"
table_geozone: "Ámbito de actuación"
table_feasibility: "Viabilidad"
table_valuation_finished: "Ev. Fin."
@@ -590,7 +587,6 @@ es:
group: "Grupo"
no_group: "Sin grupo"
valuator:
- description_placeholder: 'Descripción (opcional)'
add: Añadir como evaluador
delete: Borrar
search:
@@ -623,6 +619,7 @@ es:
no_groups: "No hay grupos de evaluadores"
show:
title: "Grupo de evaluadores: %{group}"
+ no_valuators: "No hay evaluadores asigandos a este grupo"
form:
name: "Nombre del grupo"
new: "Crear grupo de evaluadores"
@@ -959,7 +956,6 @@ es:
geozone_filter_all: Todos los ámbitos de actuación
administrator_filter_all: Todos los administradores
valuator_filter_all: Todos los evaluadores
- valuator_group_filter_all: Todos los grupos
tags_filter_all: Todas las etiquetas
filters:
valuation_open: Abiertas
@@ -972,7 +968,6 @@ es:
assigned_admin: Administrador asignado
no_admin_assigned: Sin admin asignado
no_valuators_assigned: Sin evaluador
- no_valuator_groups_assigned: Sin grupo evaluador
summary_link: "Resumen de propuestas"
valuator_summary_link: "Resumen de evaluadores"
feasibility:
diff --git a/config/locales/es/responders.yml b/config/locales/es/responders.yml
index 006bcab2d..3674a0290 100644
--- a/config/locales/es/responders.yml
+++ b/config/locales/es/responders.yml
@@ -16,6 +16,7 @@ es:
budget_investment: "Proyecto de gasto creado correctamente."
signature_sheet: "Hoja de firmas creada correctamente"
topic: "Tema creado correctamente."
+ valuator_group: "Grupo de evaluadores creado correctamente"
save_changes:
notice: Cambios guardados
update:
@@ -27,9 +28,11 @@ es:
spending_proposal: "Propuesta de inversión actualizada correctamente."
budget_investment: "Proyecto de gasto actualizado correctamente"
topic: "Tema actualizado correctamente."
+ valuator_group: "Grupo de evaluadores actualizado correctamente"
destroy:
spending_proposal: "Propuesta de inversión eliminada."
budget_investment: "Proyecto de gasto eliminado."
error: "No se pudo borrar"
topic: "Tema eliminado."
poll_question_answer_video: "Vídeo de respuesta eliminado."
+ valuator_group: "Grupo de evaluadores eliminado correctamente"
diff --git a/config/locales/es/user_groups.yml b/config/locales/es/user_groups.yml
deleted file mode 100644
index 5f4d690cf..000000000
--- a/config/locales/es/user_groups.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-es:
- user_group:
- notice:
- created: "Grupo de usuarios creado correctamente"
- updated: "Grupo de usuarios actualizado correctamente"
- destroyed: "Grupo de usuarios eliminado correctamente"
diff --git a/config/locales/es/valuation.yml b/config/locales/es/valuation.yml
index fa7748524..48fb68846 100644
--- a/config/locales/es/valuation.yml
+++ b/config/locales/es/valuation.yml
@@ -31,7 +31,6 @@ es:
one: Evaluador asignado
other: "%{count} evaluadores asignados"
no_valuators_assigned: Sin evaluador
- no_valuator_groups_assigned: Sin grupo evaluador
table_id: ID
table_title: Título
table_heading_name: Nombre de la partida
diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml
index b9cdfcfd3..7c2d63e03 100644
--- a/config/locales/fr/admin.yml
+++ b/config/locales/fr/admin.yml
@@ -246,7 +246,6 @@ fr:
index:
title: Évaluateurs
valuator:
- description_placeholder: 'Description (optionnel)'
user_found: Utilisateur trouvé
add: Ajouter un évaluateur
search:
diff --git a/config/locales/he/admin.yml b/config/locales/he/admin.yml
index 35700ec03..c5cbdf9ac 100644
--- a/config/locales/he/admin.yml
+++ b/config/locales/he/admin.yml
@@ -179,7 +179,6 @@ he:
index:
title: Valuators
valuator:
- description_placeholder: 'Description (optional)'
add: Add to valuators
summary:
title: Valuator summary for investment projects
diff --git a/config/locales/nl/admin.yml b/config/locales/nl/admin.yml
index 8a30b0d21..5dcb86fe6 100644
--- a/config/locales/nl/admin.yml
+++ b/config/locales/nl/admin.yml
@@ -246,7 +246,6 @@ nl:
index:
title: Valuators
valuator:
- description_placeholder: 'Description (optional)'
user_found: User found
add: Add to valuators
search:
diff --git a/config/locales/val/admin.yml b/config/locales/val/admin.yml
index 2b64276f4..3e3a09f6e 100644
--- a/config/locales/val/admin.yml
+++ b/config/locales/val/admin.yml
@@ -494,7 +494,6 @@ val:
no_description: Sense descripció
no_valuators: No hi ha avaluadors.
valuator:
- description_placeholder: 'Descripció (opcional)'
add: Afegir com a avaluador
delete: Borrar
search:
diff --git a/db/migrate/20180211182635_add_budget_valuator_group_assignments_counters.rb b/db/migrate/20180211182635_add_budget_valuator_group_assignments_counters.rb
new file mode 100644
index 000000000..93619a5a9
--- /dev/null
+++ b/db/migrate/20180211182635_add_budget_valuator_group_assignments_counters.rb
@@ -0,0 +1,6 @@
+class AddBudgetValuatorGroupAssignmentsCounters < ActiveRecord::Migration
+ def change
+ add_column :budget_investments, :valuator_group_assignments_count, :integer, default: 0
+ add_column :valuator_groups, :budget_investments_count, :integer, default: 0
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 45deca085..6336dd302 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -133,35 +133,38 @@ ActiveRecord::Schema.define(version: 20180320104823) do
t.string "title"
t.text "description"
t.string "external_url"
- t.integer "price", limit: 8
- t.string "feasibility", limit: 15, default: "undecided"
+ t.integer "price", limit: 8
+ t.string "feasibility", limit: 15, default: "undecided"
t.text "price_explanation"
t.text "unfeasibility_explanation"
- t.boolean "valuation_finished", default: false
- t.integer "valuator_assignments_count", default: 0
- t.integer "price_first_year", limit: 8
+ t.text "internal_comments"
+ t.boolean "valuation_finished", default: false
+ t.integer "valuator_assignments_count", default: 0
+ t.integer "price_first_year", limit: 8
t.string "duration"
t.datetime "hidden_at"
- t.integer "cached_votes_up", default: 0
- t.integer "comments_count", default: 0
- t.integer "confidence_score", default: 0, null: false
- t.integer "physical_votes", default: 0
+ t.integer "cached_votes_up", default: 0
+ t.integer "comments_count", default: 0
+ t.integer "confidence_score", default: 0, null: false
+ t.integer "physical_votes", default: 0
t.tsvector "tsv"
- t.datetime "created_at", null: false
- t.datetime "updated_at", null: false
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
t.integer "heading_id"
t.string "responsible_name"
t.integer "budget_id"
t.integer "group_id"
- t.boolean "selected", default: false
+ t.boolean "selected", default: false
t.string "location"
t.string "organization_name"
t.datetime "unfeasible_email_sent_at"
t.integer "ballot_lines_count", default: 0
t.integer "previous_heading_id"
- t.boolean "winner", default: false
- t.boolean "incompatible", default: false
+ t.integer "ballot_lines_count", default: 0
+ t.boolean "winner", default: false
+ t.boolean "incompatible", default: false
t.integer "community_id"
+ t.integer "valuator_group_assignments_count", default: 0
end
add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree
@@ -186,6 +189,16 @@ ActiveRecord::Schema.define(version: 20180320104823) do
add_index "budget_phases", ["next_phase_id"], name: "index_budget_phases_on_next_phase_id", using: :btree
add_index "budget_phases", ["starts_at"], name: "index_budget_phases_on_starts_at", using: :btree
+ create_table "budget_polls", force: :cascade do |t|
+ t.string "name"
+ t.string "email"
+ t.string "preferred_subject"
+ t.boolean "collective"
+ t.boolean "public_worker"
+ t.boolean "proposal_author"
+ t.boolean "selected_proposal_author"
+ end
+
create_table "budget_reclassified_votes", force: :cascade do |t|
t.integer "user_id"
t.integer "investment_id"
@@ -1058,11 +1071,6 @@ ActiveRecord::Schema.define(version: 20180320104823) do
add_index "topics", ["community_id"], name: "index_topics_on_community_id", using: :btree
add_index "topics", ["hidden_at"], name: "index_topics_on_hidden_at", using: :btree
- create_table "user_groups", force: :cascade do |t|
- t.string "name"
- t.string "kind"
- end
-
create_table "users", force: :cascade do |t|
t.string "email", default: ""
t.string "encrypted_password", default: "", null: false
@@ -1139,7 +1147,8 @@ ActiveRecord::Schema.define(version: 20180320104823) do
end
create_table "valuator_groups", force: :cascade do |t|
- t.string "name"
+ t.string "name"
+ t.integer "budget_investments_count", default: 0
end
create_table "valuators", force: :cascade do |t|
diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb
index 3d4351b6c..cd802486e 100644
--- a/spec/features/admin/budget_investments_spec.rb
+++ b/spec/features/admin/budget_investments_spec.rb
@@ -109,7 +109,7 @@ feature 'Admin budget investments' do
end
within("#budget_investment_#{budget_investment3.id}") do
- expect(page).to have_content("No valuator groups assigned")
+ expect(page).to have_content("No valuators assigned")
end
end
@@ -198,19 +198,19 @@ feature 'Admin budget investments' do
expect(page).to have_link("Realocate visitors")
expect(page).to have_link("Destroy the city")
- select "Valuator 1", from: "valuator_id"
+ select "Valuator 1", from: "valuator_or_group_id"
expect(page).to have_content('There is 1 investment')
expect(page).not_to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
- select "All valuators", from: "valuator_id"
+ select "All valuators", from: "valuator_or_group_id"
expect(page).to have_content('There are 2 investments')
expect(page).to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
- select "Valuator 1", from: "valuator_id"
+ select "Valuator 1", from: "valuator_or_group_id"
expect(page).to have_content('There is 1 investment')
expect(page).not_to have_link("Destroy the city")
expect(page).to have_link("Realocate visitors")
@@ -231,19 +231,19 @@ feature 'Admin budget investments' do
expect(page).to have_link("Build a hospital")
expect(page).to have_link("Build a theatre")
- select "Health", from: "valuator_group_id"
+ select "Health", from: "valuator_or_group_id"
expect(page).to have_content('There is 1 investment')
expect(page).to have_link("Build a hospital")
expect(page).not_to have_link("Build a theatre")
- select "All groups", from: "valuator_group_id"
+ select "All valuators", from: "valuator_or_group_id"
expect(page).to have_content('There are 2 investments')
expect(page).to have_link("Build a hospital")
expect(page).to have_link("Build a theatre")
- select "Culture", from: "valuator_group_id"
+ select "Culture", from: "valuator_or_group_id"
expect(page).to have_content('There is 1 investment')
expect(page).to have_link("Build a theatre")
expect(page).not_to have_link("Build a hospital")
diff --git a/spec/features/admin/valuator_groups_spec.rb b/spec/features/admin/valuator_groups_spec.rb
index 014a6f863..c939922a4 100644
--- a/spec/features/admin/valuator_groups_spec.rb
+++ b/spec/features/admin/valuator_groups_spec.rb
@@ -51,7 +51,7 @@ feature "Valuator groups" do
fill_in "valuator_group_name", with: "Health"
click_button "Create valuators group"
- expect(page).to have_content "User group created successfully"
+ expect(page).to have_content "Valuator group created successfully"
expect(page).to have_content "There is 1 valuator group"
expect(page).to have_content "Health"
end
@@ -65,7 +65,7 @@ feature "Valuator groups" do
fill_in "valuator_group_name", with: "Health and Sports"
click_button "Save valuators group"
- expect(page).to have_content "User group updated successfully"
+ expect(page).to have_content "Valuator group updated successfully"
expect(page).to have_content "Health and Sports"
end
@@ -75,10 +75,52 @@ feature "Valuator groups" do
visit admin_valuator_groups_path
click_link "Delete"
- expect(page).to have_content "User group deleted successfully"
+ expect(page).to have_content "Valuator group deleted successfully"
expect(page).to have_content "There are no valuator groups"
end
- pending "When we change the group of a Valuator we should also change the valuator_assignments"
+ context "Assign valuators to groups" do
+
+ scenario "Add a valuator to a group" do
+ valuator = create(:valuator)
+ group = create(:valuator_group, name: "Health")
+
+ visit edit_admin_valuator_path(valuator)
+
+ select "Health", from: "valuator_valuator_group_id"
+ click_button "Update valuator"
+
+ expect(page).to have_content "Valuator updated successfully"
+ expect(page).to have_content "Health"
+ end
+
+ scenario "Update a valuator's group" do
+ valuator = create(:valuator)
+ group1 = create(:valuator_group, name: "Health")
+ group2 = create(:valuator_group, name: "Economy")
+ valuator.update(valuator_group: group1)
+
+ visit edit_admin_valuator_path(valuator)
+ select "Economy", from: "valuator_valuator_group_id"
+ click_button "Update valuator"
+
+ expect(page).to have_content "Valuator updated successfully"
+ expect(page).to have_content "Economy"
+ end
+
+ scenario "Remove a valuator from a group" do
+ valuator = create(:valuator)
+ group1 = create(:valuator_group, name: "Health")
+ valuator.update(valuator_group: group1)
+
+ visit edit_admin_valuator_path(valuator)
+ select "", from: "valuator_valuator_group_id"
+ click_button "Update valuator"
+
+ expect(page).to have_content "Valuator updated successfully"
+ expect(page).to_not have_content "Health"
+ end
+
+ end
end
\ No newline at end of file
diff --git a/spec/features/admin/valuators_spec.rb b/spec/features/admin/valuators_spec.rb
index 1e1de562c..ba6792b49 100644
--- a/spec/features/admin/valuators_spec.rb
+++ b/spec/features/admin/valuators_spec.rb
@@ -1,6 +1,7 @@
require 'rails_helper'
feature 'Admin valuators' do
+
background do
@admin = create(:administrator)
@user = create(:user, username: 'Jose Luis Balbin')
@@ -102,48 +103,4 @@ feature 'Admin valuators' do
end
end
- context "Valuator Group" do
-
- scenario "Add a valuator to a group" do
- valuator = create(:valuator)
- group = create(:valuator_group, name: "Health")
-
- visit edit_admin_valuator_path(valuator)
-
- select "Health", from: "valuator_valuator_group_id"
- click_button "Update valuator"
-
- expect(page).to have_content "Valuator updated successfully"
- expect(page).to have_content "Health"
- end
-
- scenario "Update a valuator's group" do
- valuator = create(:valuator)
- group1 = create(:valuator_group, name: "Health")
- group2 = create(:valuator_group, name: "Economy")
- valuator.update(valuator_group: group1)
-
- visit edit_admin_valuator_path(valuator)
- select "Economy", from: "valuator_valuator_group_id"
- click_button "Update valuator"
-
- expect(page).to have_content "Valuator updated successfully"
- expect(page).to have_content "Economy"
- end
-
- scenario "Remove a valuator from a group" do
- valuator = create(:valuator)
- group1 = create(:valuator_group, name: "Health")
- valuator.update(valuator_group: group1)
-
- visit edit_admin_valuator_path(valuator)
- select "", from: "valuator_valuator_group_id"
- click_button "Update valuator"
-
- expect(page).to have_content "Valuator updated successfully"
- expect(page).to_not have_content "Health"
- end
-
- end
-
end
diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb
index cdee81087..5e0a24487 100644
--- a/spec/models/budget/investment_spec.rb
+++ b/spec/models/budget/investment_spec.rb
@@ -349,6 +349,20 @@ describe Budget::Investment do
expect(valuating.size).to eq(1)
expect(valuating.first).to eq(investment2)
end
+
+ it "returns all investments with assigned valuator groups but valuation not finished" do
+ investment1 = create(:budget_investment)
+ investment2 = create(:budget_investment)
+ investment3 = create(:budget_investment, valuation_finished: true)
+
+ investment2.valuator_groups << create(:valuator_group)
+ investment3.valuator_groups << create(:valuator_group)
+
+ valuating = described_class.valuating
+
+ expect(valuating.size).to eq(1)
+ expect(valuating.first).to eq(investment2)
+ end
end
describe "valuation_finished" do
diff --git a/spec/models/valuator_spec.rb b/spec/models/valuator_spec.rb
index c9387a150..7f2ffecfa 100644
--- a/spec/models/valuator_spec.rb
+++ b/spec/models/valuator_spec.rb
@@ -16,7 +16,38 @@ describe Valuator do
end
end
- describe "Group" do
- pending "should reasign investments when the group changes"
+ describe "#assigned_investment_ids" do
+
+ it "returns investments assigned to a valuator" do
+ valuator = create(:valuator)
+ investment1 = create(:budget_investment)
+ investment2 = create(:budget_investment)
+ investment3 = create(:budget_investment)
+
+ investment1.valuators << valuator
+ investment2.valuators << valuator
+
+ assigned_investment_ids = valuator.assigned_investment_ids
+ expect(assigned_investment_ids).to include investment1.id
+ expect(assigned_investment_ids).to include investment2.id
+ expect(assigned_investment_ids).to_not include investment3.id
+ end
+
+ it "returns investments assigned to a valuator group" do
+ group = create(:valuator_group)
+ valuator = create(:valuator, valuator_group: group)
+
+ investment1 = create(:budget_investment)
+ investment2 = create(:budget_investment)
+ investment3 = create(:budget_investment)
+
+ investment1.valuator_groups << group
+ investment2.valuator_groups << group
+
+ assigned_investment_ids = valuator.assigned_investment_ids
+ expect(assigned_investment_ids).to include investment1.id
+ expect(assigned_investment_ids).to include investment2.id
+ expect(assigned_investment_ids).to_not include investment3.id
+ end
end
end
| |