Manage the render of the price field on public investment section

This commit is contained in:
decabeza
2022-02-02 14:52:48 +01:00
committed by taitus
parent 40bdd1f03a
commit abc4e9dca1
6 changed files with 28 additions and 3 deletions

View File

@@ -17,10 +17,14 @@ class Budgets::Investments::NewComponent < ApplicationComponent
end end
def subtitle def subtitle
if budget.single_heading? return unless budget.single_heading?
if budget.show_money?
tag.span t("budgets.investments.form.subtitle", tag.span t("budgets.investments.form.subtitle",
heading: budget.headings.first.name, heading: budget.headings.first.name,
price: budget.formatted_heading_price(budget.headings.first)) 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 end
end end

View File

@@ -233,7 +233,7 @@ class Budget
end end
def price_required? def price_required?
feasible? && valuation_finished? feasible? && valuation_finished? && budget.show_money?
end end
def unfeasible_email_pending? def unfeasible_email_pending?
@@ -333,7 +333,7 @@ class Budget
end end
def should_show_price? def should_show_price?
selected? && price.present? && budget.published_prices? selected? && price.present? && budget.published_prices? && budget.show_money?
end end
def should_show_price_explanation? def should_show_price_explanation?

View File

@@ -75,6 +75,7 @@ en:
form: form:
title: "Create a budget investment" title: "Create a budget investment"
subtitle: "%{heading} (%{price})" subtitle: "%{heading} (%{price})"
subtitle_without_price: "%{heading}"
tag_category_label: "Categories" tag_category_label: "Categories"
tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own" tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own"
tags_label: Tags tags_label: Tags

View File

@@ -75,6 +75,7 @@ es:
form: form:
title: "Crear nuevo proyecto" title: "Crear nuevo proyecto"
subtitle: "%{heading} (%{price})" subtitle: "%{heading} (%{price})"
subtitle_without_price: "%{heading}"
tag_category_label: "Categorías" tag_category_label: "Categorías"
tags_instructions: "Etiqueta este proyecto. Puedes elegir entre las categorías propuestas o introducir las que desees" tags_instructions: "Etiqueta este proyecto. Puedes elegir entre las categorías propuestas o introducir las que desees"
tags_label: Etiquetas tags_label: Etiquetas

View File

@@ -245,6 +245,12 @@ describe Budget::Investment do
expect(investment.should_show_price?).to eq(false) expect(investment.should_show_price?).to eq(false)
end 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 end
describe "#should_show_price_explanation?" do describe "#should_show_price_explanation?" do

View File

@@ -598,6 +598,19 @@ describe "Budget Investments" do
expect(page).to have_content "Build a skyscraper" expect(page).to have_content "Build a skyscraper"
end 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 scenario "Create with single group and multiple headings" do
create(:budget_heading, group: group, name: "Medical supplies") create(:budget_heading, group: group, name: "Medical supplies")
create(:budget_heading, group: group, name: "Even more hospitals") create(:budget_heading, group: group, name: "Even more hospitals")