From 10e8117f839288356a6b3f93ce4c8c0c53c25569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 21 Dec 2018 17:08:27 +0100 Subject: [PATCH 1/3] Remove unnecessary line We were assigning the same variable twice in a row, making the first assignment useless. --- app/controllers/valuation/budgets_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/valuation/budgets_controller.rb b/app/controllers/valuation/budgets_controller.rb index 9789ab929..990fffdda 100644 --- a/app/controllers/valuation/budgets_controller.rb +++ b/app/controllers/valuation/budgets_controller.rb @@ -7,7 +7,6 @@ class Valuation::BudgetsController < Valuation::BaseController def index @budget = current_budget if @budget.present? - @investments_with_valuation_open = {} @investments_with_valuation_open = @budget.investments .by_valuator(current_user.valuator.try(:id)) .valuation_open From b0f1b6245ec4ec5a155ec1bb2bb05156062945eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 21 Dec 2018 17:16:51 +0100 Subject: [PATCH 2/3] Simplify scope usage Rails automatically calls the `id` method inside scopes and the variable name makes more sense if it represents investments instead of the number of investments. --- app/controllers/valuation/budgets_controller.rb | 7 +++---- app/views/valuation/budgets/index.html.erb | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/valuation/budgets_controller.rb b/app/controllers/valuation/budgets_controller.rb index 990fffdda..338cccec4 100644 --- a/app/controllers/valuation/budgets_controller.rb +++ b/app/controllers/valuation/budgets_controller.rb @@ -7,10 +7,9 @@ class Valuation::BudgetsController < Valuation::BaseController def index @budget = current_budget if @budget.present? - @investments_with_valuation_open = @budget.investments - .by_valuator(current_user.valuator.try(:id)) - .valuation_open - .count + @investments = @budget.investments + .by_valuator(current_user.valuator) + .valuation_open end end end diff --git a/app/views/valuation/budgets/index.html.erb b/app/views/valuation/budgets/index.html.erb index f1fd302b6..3abc1f3c7 100644 --- a/app/views/valuation/budgets/index.html.erb +++ b/app/views/valuation/budgets/index.html.erb @@ -18,7 +18,7 @@ <%= t("budgets.phase.#{@budget.phase}") %> - <%= @investments_with_valuation_open %> + <%= @investments.count %> <%= link_to t("valuation.budgets.index.evaluate"), From fd681c17df991cfc0f272475779d2f8cb2e5128e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 21 Dec 2018 17:23:53 +0100 Subject: [PATCH 3/3] Fix crash in valuation when there are no budgets --- app/views/valuation/budgets/index.html.erb | 62 ++++++++++++---------- config/locales/en/valuation.yml | 1 + config/locales/es/valuation.yml | 1 + spec/features/valuation/budgets_spec.rb | 5 ++ 4 files changed, 41 insertions(+), 28 deletions(-) diff --git a/app/views/valuation/budgets/index.html.erb b/app/views/valuation/budgets/index.html.erb index 3abc1f3c7..1e98cf23e 100644 --- a/app/views/valuation/budgets/index.html.erb +++ b/app/views/valuation/budgets/index.html.erb @@ -1,30 +1,36 @@

<%= t("valuation.budgets.index.title") %>

- - - - - - - - - - - - - - - - - -
<%= t("valuation.budgets.index.table_name") %><%= t("valuation.budgets.index.table_phase") %><%= t("valuation.budgets.index.table_assigned_investments_valuation_open") %><%= t("valuation.budgets.index.table_actions") %>
- <%= @budget.name %> - - <%= t("budgets.phase.#{@budget.phase}") %> - - <%= @investments.count %> - - <%= link_to t("valuation.budgets.index.evaluate"), - valuation_budget_budget_investments_path(budget_id: @budget.id), - class: "button hollow expanded" %> -
+<% if @budget.present? %> + + + + + + + + + + + + + + + + + +
<%= t("valuation.budgets.index.table_name") %><%= t("valuation.budgets.index.table_phase") %><%= t("valuation.budgets.index.table_assigned_investments_valuation_open") %><%= t("valuation.budgets.index.table_actions") %>
+ <%= @budget.name %> + + <%= t("budgets.phase.#{@budget.phase}") %> + + <%= @investments.count %> + + <%= link_to t("valuation.budgets.index.evaluate"), + valuation_budget_budget_investments_path(budget_id: @budget.id), + class: "button hollow expanded" %> +
+<% else %> +
+ <%= t("valuation.budgets.index.no_budgets") %> +
+<% end %> diff --git a/config/locales/en/valuation.yml b/config/locales/en/valuation.yml index 116a86c5a..b918020af 100644 --- a/config/locales/en/valuation.yml +++ b/config/locales/en/valuation.yml @@ -17,6 +17,7 @@ en: table_assigned_investments_valuation_open: Investment projects assigned with valuation open table_actions: Actions evaluate: Evaluate + no_budgets: "There are no budgets" budget_investments: index: headings_filter_all: All headings diff --git a/config/locales/es/valuation.yml b/config/locales/es/valuation.yml index f762260b2..a0b36182f 100644 --- a/config/locales/es/valuation.yml +++ b/config/locales/es/valuation.yml @@ -17,6 +17,7 @@ es: table_assigned_investments_valuation_open: Prop. Inv. asignadas en evaluación table_actions: Acciones evaluate: Evaluar + no_budgets: "No hay presupuestos" budget_investments: index: headings_filter_all: Todas las partidas diff --git a/spec/features/valuation/budgets_spec.rb b/spec/features/valuation/budgets_spec.rb index 9057f81d3..ac8e79ab3 100644 --- a/spec/features/valuation/budgets_spec.rb +++ b/spec/features/valuation/budgets_spec.rb @@ -35,6 +35,11 @@ feature 'Valuation budgets' do expect(page).to have_content(budget3.name) end + scenario "With no budgets" do + visit valuation_budgets_path + + expect(page).to have_content "There are no budgets" + end end end