From ec8715efd34ed313a86e679fa3c7d15fd869265e Mon Sep 17 00:00:00 2001 From: iagirre Date: Wed, 27 Dec 2017 12:15:38 +0100 Subject: [PATCH 1/2] Budget investments cannot be edited when budget is finished. Only milestones can be managed. --- .../budget_investments/_investments.html.erb | 40 ++++++++++--------- .../admin/budget_investments/show.html.erb | 6 +-- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index fca3560a4..7996a9a2b 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -55,25 +55,27 @@ <%= investment.valuation_finished? ? t('shared.yes'): t('shared.no') %> - <% if investment.selected? %> - <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, - investment, - filter: params[:filter], - page: params[:page]), - method: :patch, - remote: true, - class: "button small expanded" do %> - <%= t("admin.budget_investments.index.selected") %> - <% end %> - <% elsif investment.feasible? && investment.valuation_finished? %> - <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, - investment, - filter: params[:filter], - page: params[:page]), - method: :patch, - remote: true, - class: "button small hollow expanded" do %> - <%= t("admin.budget_investments.index.select") %> + <% unless investment.budget.finished? %> + <% if investment.selected? %> + <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small expanded" do %> + <%= t("admin.budget_investments.index.selected") %> + <% end %> + <% elsif investment.feasible? && investment.valuation_finished? %> + <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small hollow expanded" do %> + <%= t("admin.budget_investments.index.select") %> + <% end %> <% end %> <% end %> diff --git a/app/views/admin/budget_investments/show.html.erb b/app/views/admin/budget_investments/show.html.erb index 8fd285c2e..7cf7765f7 100644 --- a/app/views/admin/budget_investments/show.html.erb +++ b/app/views/admin/budget_investments/show.html.erb @@ -6,7 +6,7 @@ <%= link_to t("admin.budget_investments.show.edit"), edit_admin_budget_budget_investment_path(@budget, @investment, - Budget::Investment.filter_params(params)) %> + Budget::Investment.filter_params(params)) unless @budget.finished? %>
@@ -34,7 +34,7 @@

<%= link_to t("admin.budget_investments.show.edit_classification"), edit_admin_budget_budget_investment_path(@budget, @investment, - {anchor: 'classification'}.merge(Budget::Investment.filter_params(params))) %> + {anchor: 'classification'}.merge(Budget::Investment.filter_params(params))) unless @budget.finished? %>


@@ -44,7 +44,7 @@ <%= render 'valuation/budget_investments/written_by_valuators' %>

- <%= link_to t("admin.budget_investments.show.edit_dossier"), edit_valuation_budget_budget_investment_path(@budget, @investment) %> + <%= link_to t("admin.budget_investments.show.edit_dossier"), edit_valuation_budget_budget_investment_path(@budget, @investment) unless @budget.finished? %>


From 64aaa97d861888f4ac168a365e18ea246400963c Mon Sep 17 00:00:00 2001 From: iagirre Date: Wed, 27 Dec 2017 16:23:21 +0100 Subject: [PATCH 2/2] Add feature specs to check that edit links and "Selected" buttons are not displayed/enabled. "Selected" button appears as text instead of dissapearing completely. --- .../budget_investments/_investments.html.erb | 40 ++++----- .../features/admin/budget_investments_spec.rb | 83 ++++++++++++++----- 2 files changed, 78 insertions(+), 45 deletions(-) diff --git a/app/views/admin/budget_investments/_investments.html.erb b/app/views/admin/budget_investments/_investments.html.erb index 7996a9a2b..f90c75ac7 100644 --- a/app/views/admin/budget_investments/_investments.html.erb +++ b/app/views/admin/budget_investments/_investments.html.erb @@ -55,28 +55,24 @@ <%= investment.valuation_finished? ? t('shared.yes'): t('shared.no') %> - <% unless investment.budget.finished? %> - <% if investment.selected? %> - <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, - investment, - filter: params[:filter], - page: params[:page]), - method: :patch, - remote: true, - class: "button small expanded" do %> - <%= t("admin.budget_investments.index.selected") %> - <% end %> - <% elsif investment.feasible? && investment.valuation_finished? %> - <%= link_to toggle_selection_admin_budget_budget_investment_path(@budget, - investment, - filter: params[:filter], - page: params[:page]), - method: :patch, - remote: true, - class: "button small hollow expanded" do %> - <%= t("admin.budget_investments.index.select") %> - <% end %> - <% end %> + <% if investment.selected? %> + <%= link_to_unless investment.budget.finished?, t("admin.budget_investments.index.selected"), + toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small expanded" %> + <% elsif investment.feasible? && investment.valuation_finished? %> + <%= link_to_unless investment.budget.finished?, t("admin.budget_investments.index.select"), + toggle_selection_admin_budget_budget_investment_path(@budget, + investment, + filter: params[:filter], + page: params[:page]), + method: :patch, + remote: true, + class: "button small hollow expanded" %> <% end %> <% if params[:filter] == 'selected' %> diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index 1ad89e6aa..8c563188e 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -36,6 +36,21 @@ feature 'Admin budget investments' do expect(page).to have_content(budget_investment.total_votes) end + scenario 'If budget is finished do not show "Selected" button' do + finished_budget = create(:budget, :finished) + budget_investment = create(:budget_investment, budget: finished_budget, cached_votes_up: 77) + + visit admin_budget_budget_investments_path(budget_id: finished_budget.id) + + within("#budget_investment_#{budget_investment.id}") do + expect(page).to have_content(budget_investment.title) + expect(page).to have_content(budget_investment.heading.name) + expect(page).to have_content(budget_investment.id) + expect(page).to have_content(budget_investment.total_votes) + expect(page).to_not have_link("Selected") + end + end + scenario 'Displaying assignments info' do budget_investment1 = create(:budget_investment, budget: @budget) budget_investment2 = create(:budget_investment, budget: @budget) @@ -279,33 +294,55 @@ feature 'Admin budget investments' do 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')) - budget_investment = create(:budget_investment, - price: 1234, - price_first_year: 1000, - feasibility: "unfeasible", - unfeasibility_explanation: 'It is impossible', - administrator: administrator) - budget_investment.valuators << valuator + context 'Show' do + background do + @administrator = create(:administrator, user: create(:user, username: 'Ana', email: 'ana@admins.org')) + end - visit admin_budget_budget_investments_path(budget_investment.budget) + scenario 'Show the investment details' do + valuator = create(:valuator, user: create(:user, username: 'Rachel', email: 'rachel@valuators.org')) + budget_investment = create(:budget_investment, + price: 1234, + price_first_year: 1000, + feasibility: "unfeasible", + unfeasibility_explanation: 'It is impossible', + administrator: @administrator) + budget_investment.valuators << valuator - click_link budget_investment.title + visit admin_budget_budget_investments_path(budget_investment.budget) - expect(page).to have_content(budget_investment.title) - expect(page).to have_content(budget_investment.description) - expect(page).to have_content(budget_investment.author.name) - expect(page).to have_content(budget_investment.heading.name) - expect(page).to have_content('1234') - expect(page).to have_content('1000') - expect(page).to have_content('Unfeasible') - expect(page).to have_content('It is impossible') - expect(page).to have_content('Ana (ana@admins.org)') + click_link budget_investment.title - within('#assigned_valuators') do - expect(page).to have_content('Rachel (rachel@valuators.org)') + expect(page).to have_content(budget_investment.title) + expect(page).to have_content(budget_investment.description) + expect(page).to have_content(budget_investment.author.name) + expect(page).to have_content(budget_investment.heading.name) + expect(page).to have_content('1234') + expect(page).to have_content('1000') + expect(page).to have_content('Unfeasible') + expect(page).to have_content('It is impossible') + expect(page).to have_content('Ana (ana@admins.org)') + + within('#assigned_valuators') do + expect(page).to have_content('Rachel (rachel@valuators.org)') + end + end + + scenario "If budget is finished, investment cannot be edited" do + # Only milestones can be managed + + finished_budget = create(:budget, :finished) + budget_investment = create(:budget_investment, + budget: finished_budget, + administrator: @administrator) + visit admin_budget_budget_investments_path(budget_investment.budget) + + click_link budget_investment.title + + expect(page).to_not have_link "Edit" + expect(page).to_not have_link "Edit classification" + expect(page).to_not have_link "Edit dossier" + expect(page).to have_link "Create new milestone" end end