This commit is contained in:
rgarcia
2018-02-09 22:08:52 +01:00
parent 2d3c4e1fbd
commit 00c965b715
31 changed files with 206 additions and 158 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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 }

View File

@@ -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") }

View File

@@ -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

View File

@@ -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

View File

@@ -24,7 +24,6 @@
<th><%= t("admin.budget_investments.index.table_supports") %></th>
<th><%= t("admin.budget_investments.index.table_admin") %></th>
<th><%= t("admin.budget_investments.index.table_valuator") %></th>
<th><%= t("admin.budget_investments.index.table_valuator_group") %></th>
<th><%= t("admin.budget_investments.index.table_geozone") %></th>
<th><%= t("admin.budget_investments.index.table_feasibility") %></th>
<th class="text-center"><%= t("admin.budget_investments.index.table_valuation_finished") %></th>
@@ -61,17 +60,10 @@
<% end %>
</td>
<td class="small">
<% 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 %>
</td>
<td class="small">
<% 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 %>
</td>
<td class="small">

View File

@@ -12,21 +12,13 @@
</div>
<div class="small-12 medium-3 column">
<%= 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" } %>
</div>
<div class="small-12 medium-3 column">
<%= 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" } %>
</div>
<div class="small-12 medium-3 column">
<%= select_tag :heading_id,
options_for_select(budget_heading_select_options(@budget), params[:heading_id]),

View File

@@ -0,0 +1,4 @@
<li>
<%= link_to valuator.description_or_email,
admin_valuator_path(valuator) %>
</li>

View File

@@ -3,10 +3,11 @@
<h2><%= t("admin.valuator_groups.show.title", group: @group.name) %></h2>
<ul id="valuators">
<% @group.valuators.each do |valuator| %>
<li>
<%= link_to valuator.description_or_email,
admin_valuator_path(valuator) %>
</li>
<% if @group.valuators.any? %>
<%= render partial: 'valuator', collection: @group.valuators %>
<% else %>
<div class="callout primary">
<%= t("admin.valuator_groups.show.no_valuators") %>
</div>
<% end %>
</ul>

View File

@@ -30,6 +30,10 @@
<% end %>
<td>
<% 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,

View File

@@ -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:

View File

@@ -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"

View File

@@ -1,6 +0,0 @@
en:
user_group:
notice:
created: "User group created successfully"
updated: "User group updated successfully"
destroyed: "User group deleted successfully"

View File

@@ -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

View File

@@ -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:

View File

@@ -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"

View File

@@ -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"

View File

@@ -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

View File

@@ -246,7 +246,6 @@ fr:
index:
title: Évaluateurs
valuator:
description_placeholder: 'Description (optionnel)'
user_found: Utilisateur trouvé
add: Ajouter un évaluateur
search:

View File

@@ -179,7 +179,6 @@ he:
index:
title: Valuators
valuator:
description_placeholder: 'Description (optional)'
add: Add to valuators
summary:
title: Valuator summary for investment projects

View File

@@ -246,7 +246,6 @@ nl:
index:
title: Valuators
valuator:
description_placeholder: 'Description (optional)'
user_found: User found
add: Add to valuators
search:

View File

@@ -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:

View File

@@ -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

View File

@@ -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|

View File

@@ -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")

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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