From abc4e9dca1b577e0a3583864ac9efd11b97a4179 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 2 Feb 2022 14:52:48 +0100 Subject: [PATCH] Manage the render of the price field on public investment section --- app/components/budgets/investments/new_component.rb | 6 +++++- app/models/budget/investment.rb | 4 ++-- config/locales/en/budgets.yml | 1 + config/locales/es/budgets.yml | 1 + spec/models/budget/investment_spec.rb | 6 ++++++ spec/system/budgets/investments_spec.rb | 13 +++++++++++++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/components/budgets/investments/new_component.rb b/app/components/budgets/investments/new_component.rb index f893a2ad9..ff16bf257 100644 --- a/app/components/budgets/investments/new_component.rb +++ b/app/components/budgets/investments/new_component.rb @@ -17,10 +17,14 @@ class Budgets::Investments::NewComponent < ApplicationComponent end def subtitle - if budget.single_heading? + return unless budget.single_heading? + + if budget.show_money? tag.span t("budgets.investments.form.subtitle", heading: budget.headings.first.name, price: budget.formatted_heading_price(budget.headings.first)) + else + tag.span t("budgets.investments.form.subtitle_without_price", heading: budget.headings.first.name) end end end diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 50a403eba..76fe714f4 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -233,7 +233,7 @@ class Budget end def price_required? - feasible? && valuation_finished? + feasible? && valuation_finished? && budget.show_money? end def unfeasible_email_pending? @@ -333,7 +333,7 @@ class Budget end def should_show_price? - selected? && price.present? && budget.published_prices? + selected? && price.present? && budget.published_prices? && budget.show_money? end def should_show_price_explanation? diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 99a49af9a..1e3c6b41a 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -75,6 +75,7 @@ en: form: title: "Create a budget investment" subtitle: "%{heading} (%{price})" + subtitle_without_price: "%{heading}" tag_category_label: "Categories" tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own" tags_label: Tags diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 1fea405b4..5cf78e3d4 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -75,6 +75,7 @@ es: form: title: "Crear nuevo proyecto" subtitle: "%{heading} (%{price})" + subtitle_without_price: "%{heading}" tag_category_label: "Categorías" tags_instructions: "Etiqueta este proyecto. Puedes elegir entre las categorías propuestas o introducir las que desees" tags_label: Etiquetas diff --git a/spec/models/budget/investment_spec.rb b/spec/models/budget/investment_spec.rb index 854bb1d9c..fa8bb73f8 100644 --- a/spec/models/budget/investment_spec.rb +++ b/spec/models/budget/investment_spec.rb @@ -245,6 +245,12 @@ describe Budget::Investment do expect(investment.should_show_price?).to eq(false) end + + it "returns false if budget hide money is active" do + budget.update!(hide_money: true) + + expect(investment.should_show_price?).to eq(false) + end end describe "#should_show_price_explanation?" do diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index a48bbb1f2..0dec3fd34 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -598,6 +598,19 @@ describe "Budget Investments" do expect(page).to have_content "Build a skyscraper" end + scenario "Create with single heading and hidden money" do + budget_hide_money = create(:budget, :hide_money) + group = create(:budget_group, budget: budget_hide_money) + create(:budget_heading, name: "Heading without money", group: group) + + login_as(author) + + visit new_budget_investment_path(budget_hide_money) + + expect(page).to have_content "Heading without money" + expect(page).not_to have_content "€" + end + scenario "Create with single group and multiple headings" do create(:budget_heading, group: group, name: "Medical supplies") create(:budget_heading, group: group, name: "Even more hospitals")