Merge pull request #2342 from wairbut-m2c/iagirre-budgets-column-show-valuators
Budget: add column show to valuators
This commit is contained in:
@@ -96,7 +96,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
def budget_investment_params
|
||||
params.require(:budget_investment)
|
||||
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list,
|
||||
:valuation_tag_list, :incompatible, :selected, valuator_ids: [],
|
||||
:valuation_tag_list, :incompatible, :visible_to_valuators, :selected, valuator_ids: [],
|
||||
valuator_group_ids: [])
|
||||
end
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class Valuation::BudgetInvestmentsController < Valuation::BaseController
|
||||
def index
|
||||
@heading_filters = heading_filters
|
||||
@investments = if current_user.valuator? && @budget.present?
|
||||
@budget.investments.scoped_filter(params_for_current_valuator, @current_filter)
|
||||
@budget.investments.visible_to_valuators.scoped_filter(params_for_current_valuator, @current_filter)
|
||||
.order(cached_votes_up: :desc)
|
||||
.page(params[:page])
|
||||
else
|
||||
|
||||
@@ -63,6 +63,7 @@ class Budget
|
||||
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 OR valuator_group_assignments_count > 0" ) }
|
||||
scope :visible_to_valuators, -> { where(visible_to_valuators: true) }
|
||||
scope :valuation_finished, -> { where(valuation_finished: true) }
|
||||
scope :valuation_finished_feasible, -> { where(valuation_finished: true, feasibility: "feasible") }
|
||||
scope :feasible, -> { where(feasibility: "feasible") }
|
||||
|
||||
@@ -28,8 +28,14 @@
|
||||
<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>
|
||||
<th class="text-center"><%= t("admin.budget_investments.index.table_selection") %></th>
|
||||
<% if params[:filter] == "selected" %>
|
||||
<th class="text-center">
|
||||
<% if params[:filter] == "under_valuation" %>
|
||||
<%= t("admin.budget_investments.index.table_evaluation") %>
|
||||
<% else %>
|
||||
<%= t("admin.budget_investments.index.table_selection") %>
|
||||
<% end %>
|
||||
</th>
|
||||
<% if params[:filter] == "selected" %>
|
||||
<th class="text-center"><%= t("admin.budget_investments.index.table_incompatible") %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
@@ -78,7 +84,15 @@
|
||||
<td class="small text-center">
|
||||
<%= investment.valuation_finished? ? t("shared.yes"): t("shared.no") %>
|
||||
</td>
|
||||
<td class="small">
|
||||
<td class="small text-center">
|
||||
<% if params[:filter] == "under_valuation" %>
|
||||
<%= form_for [:admin, investment.budget, investment], remote: true do |f| %>
|
||||
<%= f.check_box :visible_to_valuators,
|
||||
label: false,
|
||||
class: "js-submit-on-change",
|
||||
id: "budget_investment_visible_to_valuators" %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% if investment.selected? %>
|
||||
<%= link_to_unless investment.budget.finished?,
|
||||
t("admin.budget_investments.index.selected"),
|
||||
@@ -106,6 +120,7 @@
|
||||
remote: true,
|
||||
class: "button small hollow expanded" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% if params[:filter] == "selected" %>
|
||||
<td class="small text-center">
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @investments.each do |investment| %>
|
||||
<tr id="<%= dom_id(investment) %>">
|
||||
<tr id="<%= dom_id(investment) %>" class="budget_investment">
|
||||
<td>
|
||||
<strong><%= investment.id %></strong>
|
||||
</td>
|
||||
|
||||
@@ -188,6 +188,7 @@ en:
|
||||
table_feasibility: "Feasibility"
|
||||
table_valuation_finished: "Val. Fin."
|
||||
table_selection: "Selected"
|
||||
table_evaluation: "Show to valuators"
|
||||
table_incompatible: "Incompatible"
|
||||
show:
|
||||
assigned_admin: Assigned administrator
|
||||
|
||||
@@ -188,6 +188,7 @@ es:
|
||||
table_feasibility: "Viabilidad"
|
||||
table_valuation_finished: "Ev. Fin."
|
||||
table_selection: "Seleccionado"
|
||||
table_evaluation: "Mostrar a evaluadores"
|
||||
table_incompatible: "Incompatible"
|
||||
show:
|
||||
assigned_admin: Administrador asignado
|
||||
|
||||
@@ -56,6 +56,12 @@ section "Creating Investments" do
|
||||
end
|
||||
end
|
||||
|
||||
section "Marking investments as visible to valuators" do
|
||||
(1..50).to_a.sample.times do
|
||||
Budget::Investment.reorder("RANDOM()").first.update(visible_to_valuators: true)
|
||||
end
|
||||
end
|
||||
|
||||
section "Geolocating Investments" do
|
||||
Budget.all.each do |budget|
|
||||
budget.investments.each do |investment|
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddVisibleToValuatorsToBudgetInvestment < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :budget_investments, :visible_to_valuators, :boolean, default: false
|
||||
end
|
||||
end
|
||||
@@ -163,6 +163,7 @@ ActiveRecord::Schema.define(version: 20180320104823) do
|
||||
t.boolean "incompatible", default: false
|
||||
t.integer "community_id"
|
||||
t.integer "valuator_group_assignments_count", default: 0
|
||||
t.boolean "visible_to_valuators", default: false
|
||||
end
|
||||
|
||||
add_index "budget_investments", ["administrator_id"], name: "index_budget_investments_on_administrator_id", using: :btree
|
||||
|
||||
@@ -342,6 +342,10 @@ FactoryBot.define do
|
||||
winner true
|
||||
end
|
||||
|
||||
trait :visible_to_valuators do
|
||||
visible_to_valuators true
|
||||
end
|
||||
|
||||
trait :incompatible do
|
||||
selected
|
||||
incompatible true
|
||||
|
||||
@@ -8,8 +8,8 @@ feature 'Admin budget investments' do
|
||||
end
|
||||
|
||||
background do
|
||||
admin = create(:administrator)
|
||||
login_as(admin.user)
|
||||
@admin = create(:administrator)
|
||||
login_as(@admin.user)
|
||||
end
|
||||
|
||||
context "Feature flag" do
|
||||
@@ -951,6 +951,110 @@ feature 'Admin budget investments' do
|
||||
end
|
||||
end
|
||||
|
||||
context "Mark as visible to valuators" do
|
||||
let(:valuator) { create(:valuator) }
|
||||
let(:admin) { create(:administrator) }
|
||||
|
||||
let(:group) { create(:budget_group, budget: budget) }
|
||||
let(:heading) { create(:budget_heading, group: group) }
|
||||
|
||||
let(:investment1) { create(:budget_investment, heading: heading) }
|
||||
let(:investment2) { create(:budget_investment, heading: heading) }
|
||||
|
||||
scenario "Mark as visible to valuator", :js do
|
||||
investment1.valuators << valuator
|
||||
investment2.valuators << valuator
|
||||
investment1.update(administrator: admin)
|
||||
investment2.update(administrator: admin)
|
||||
|
||||
visit admin_budget_budget_investments_path(budget)
|
||||
within('#filter-subnav') { click_link 'Under valuation' }
|
||||
|
||||
within("#budget_investment_#{investment1.id}") do
|
||||
check "budget_investment_visible_to_valuators"
|
||||
end
|
||||
|
||||
visit admin_budget_budget_investments_path(budget)
|
||||
within('#filter-subnav') { click_link 'Under valuation' }
|
||||
|
||||
within("#budget_investment_#{investment1.id}") do
|
||||
expect(find("#budget_investment_visible_to_valuators")).to be_checked
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Shows the correct investments to valuators" do
|
||||
investment1.update(visible_to_valuators: true)
|
||||
investment2.update(visible_to_valuators: false)
|
||||
|
||||
investment1.valuators << valuator
|
||||
investment2.valuators << valuator
|
||||
investment1.update(administrator: admin)
|
||||
investment2.update(administrator: admin)
|
||||
|
||||
login_as(valuator.user.reload)
|
||||
visit root_path
|
||||
click_link "Admin"
|
||||
click_link "Valuation"
|
||||
|
||||
within "#budget_#{budget.id}" do
|
||||
click_link "Evaluate"
|
||||
end
|
||||
|
||||
expect(page).to have_content investment1.title
|
||||
expect(page).not_to have_content investment2.title
|
||||
end
|
||||
|
||||
scenario "Unmark as visible to valuator", :js do
|
||||
Setting['feature.budgets.valuators_allowed'] = true
|
||||
|
||||
investment1.valuators << valuator
|
||||
investment2.valuators << valuator
|
||||
investment1.update(administrator: admin)
|
||||
investment2.update(administrator: admin)
|
||||
|
||||
visit admin_budget_budget_investments_path(budget)
|
||||
within('#filter-subnav') { click_link 'Under valuation' }
|
||||
|
||||
within("#budget_investment_#{investment1.id}") do
|
||||
uncheck "budget_investment_visible_to_valuators"
|
||||
end
|
||||
|
||||
visit admin_budget_budget_investments_path(budget)
|
||||
within('#filter-subnav') { click_link 'Under valuation' }
|
||||
|
||||
within("#budget_investment_#{investment1.id}") do
|
||||
expect(find("#budget_investment_visible_to_valuators")).not_to be_checked
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Showing the valuating checkbox" do
|
||||
investment1 = create(:budget_investment, budget: budget, visible_to_valuators: true)
|
||||
investment2 = create(:budget_investment, budget: budget, visible_to_valuators: false)
|
||||
|
||||
investment1.valuators << create(:valuator)
|
||||
investment2.valuators << create(:valuator)
|
||||
investment2.valuators << create(:valuator)
|
||||
investment1.update(administrator: create(:administrator))
|
||||
investment2.update(administrator: create(:administrator))
|
||||
|
||||
visit admin_budget_budget_investments_path(budget)
|
||||
|
||||
expect(page).not_to have_css("#budget_investment_visible_to_valuators")
|
||||
|
||||
within('#filter-subnav') { click_link 'Under valuation' }
|
||||
|
||||
within("#budget_investment_#{investment1.id}") do
|
||||
valuating_checkbox = find('#budget_investment_visible_to_valuators')
|
||||
expect(valuating_checkbox).to be_checked
|
||||
end
|
||||
|
||||
within("#budget_investment_#{investment2.id}") do
|
||||
valuating_checkbox = find('#budget_investment_visible_to_valuators')
|
||||
expect(valuating_checkbox).not_to be_checked
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Selecting csv" do
|
||||
|
||||
scenario "Downloading CSV file" do
|
||||
|
||||
@@ -26,8 +26,8 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario 'Index shows budget investments assigned to current valuator' do
|
||||
investment1 = create(:budget_investment, budget: budget)
|
||||
investment2 = create(:budget_investment, budget: budget)
|
||||
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget)
|
||||
investment2 = create(:budget_investment, :visible_to_valuators, budget: budget)
|
||||
|
||||
investment1.valuators << valuator
|
||||
|
||||
@@ -38,8 +38,8 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario 'Index shows no budget investment to admins no valuators' do
|
||||
investment1 = create(:budget_investment, budget: budget)
|
||||
investment2 = create(:budget_investment, budget: budget)
|
||||
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget)
|
||||
investment2 = create(:budget_investment, :visible_to_valuators, budget: budget)
|
||||
|
||||
investment1.valuators << valuator
|
||||
|
||||
@@ -52,9 +52,9 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario 'Index orders budget investments by votes' do
|
||||
investment10 = create(:budget_investment, budget: budget, cached_votes_up: 10)
|
||||
investment100 = create(:budget_investment, budget: budget, cached_votes_up: 100)
|
||||
investment1 = create(:budget_investment, budget: budget, cached_votes_up: 1)
|
||||
investment10 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 10)
|
||||
investment100 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 100)
|
||||
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 1)
|
||||
|
||||
investment1.valuators << valuator
|
||||
investment10.valuators << valuator
|
||||
@@ -66,27 +66,48 @@ feature 'Valuation budget investments' do
|
||||
expect(investment10.title).to appear_before(investment1.title)
|
||||
end
|
||||
|
||||
scenario 'Index displays investments paginated' do
|
||||
per_page = Kaminari.config.default_per_page
|
||||
(per_page + 2).times do
|
||||
investment = create(:budget_investment, :visible_to_valuators, budget: budget)
|
||||
investment.valuators << valuator
|
||||
end
|
||||
|
||||
visit valuation_budget_budget_investments_path(budget)
|
||||
|
||||
expect(page).to have_css('.budget_investment', count: per_page)
|
||||
|
||||
within("ul.pagination") do
|
||||
expect(page).to have_content("1")
|
||||
expect(page).to have_content("2")
|
||||
expect(page).not_to have_content("3")
|
||||
click_link "Next", exact: false
|
||||
end
|
||||
|
||||
expect(page).to have_css('.budget_investment', count: 2)
|
||||
end
|
||||
|
||||
scenario "Index filtering by heading", :js do
|
||||
group = create(:budget_group, budget: budget)
|
||||
valuating_heading = create(:budget_heading, name: "Only Valuating", group: group)
|
||||
valuating_finished_heading = create(:budget_heading, name: "Valuating&Finished", group: group)
|
||||
finished_heading = create(:budget_heading, name: "Only Finished", group: group)
|
||||
create(:budget_investment, title: "Valuating Investment ONE",
|
||||
create(:budget_investment, :visible_to_valuators, title: "Valuating Investment ONE",
|
||||
heading: valuating_heading,
|
||||
group: group,
|
||||
budget: budget,
|
||||
valuators: [valuator])
|
||||
create(:budget_investment, title: "Valuating Investment TWO",
|
||||
create(:budget_investment, :visible_to_valuators, title: "Valuating Investment TWO",
|
||||
heading: valuating_finished_heading,
|
||||
group: group,
|
||||
budget: budget,
|
||||
valuators: [valuator])
|
||||
create(:budget_investment, :finished, title: "Finished ONE",
|
||||
create(:budget_investment, :finished, :visible_to_valuators, title: "Finished ONE",
|
||||
heading: valuating_finished_heading,
|
||||
group: group,
|
||||
budget: budget,
|
||||
valuators: [valuator])
|
||||
create(:budget_investment, :finished, title: "Finished TWO",
|
||||
create(:budget_investment, :finished, :visible_to_valuators, title: "Finished TWO",
|
||||
heading: finished_heading,
|
||||
group: group,
|
||||
budget: budget,
|
||||
@@ -162,9 +183,10 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario "Index filtering by valuation status" do
|
||||
valuating = create(:budget_investment, budget: budget, title: "Ongoing valuation")
|
||||
valuated = create(:budget_investment, budget: budget, title: "Old idea",
|
||||
valuation_finished: true)
|
||||
valuating = create(:budget_investment, :visible_to_valuators,
|
||||
budget: budget, title: "Ongoing valuation")
|
||||
valuated = create(:budget_investment, :visible_to_valuators,
|
||||
budget: budget, title: "Old idea", valuation_finished: true)
|
||||
valuating.valuators << valuator
|
||||
valuated.valuators << valuator
|
||||
|
||||
@@ -194,7 +216,7 @@ feature 'Valuation budget investments' do
|
||||
let(:investment) do
|
||||
create(:budget_investment, budget: budget, price: 1234, feasibility: 'unfeasible',
|
||||
unfeasibility_explanation: 'It is impossible',
|
||||
administrator: administrator)
|
||||
administrator: administrator,)
|
||||
end
|
||||
|
||||
background do
|
||||
@@ -202,8 +224,10 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario 'visible for assigned valuators' do
|
||||
investment.update(visible_to_valuators: true)
|
||||
visit valuation_budget_budget_investments_path(budget)
|
||||
|
||||
|
||||
click_link investment.title
|
||||
|
||||
expect(page).to have_content(investment.title)
|
||||
@@ -267,6 +291,8 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario 'Dossier empty by default' do
|
||||
investment.update(visible_to_valuators: true)
|
||||
|
||||
visit valuation_budget_budget_investments_path(budget)
|
||||
click_link investment.title
|
||||
|
||||
@@ -278,6 +304,7 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario 'Edit dossier' do
|
||||
investment.update(visible_to_valuators: true)
|
||||
visit valuation_budget_budget_investments_path(budget)
|
||||
within("#budget_investment_#{investment.id}") do
|
||||
click_link "Edit dossier"
|
||||
@@ -379,6 +406,8 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario 'Finish valuation' do
|
||||
investment.update(visible_to_valuators: true)
|
||||
|
||||
visit valuation_budget_budget_investment_path(budget, investment)
|
||||
click_link 'Edit dossier'
|
||||
|
||||
@@ -436,7 +465,10 @@ feature 'Valuation budget investments' do
|
||||
end
|
||||
|
||||
scenario 'Validates price formats' do
|
||||
investment.update(visible_to_valuators: true)
|
||||
|
||||
visit valuation_budget_budget_investments_path(budget)
|
||||
|
||||
within("#budget_investment_#{investment.id}") do
|
||||
click_link "Edit dossier"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user