Hide single heading select on new budget investment form

This commit is contained in:
decabeza
2020-04-06 14:11:05 +02:00
committed by Javi Martín
parent eb733d1880
commit 0488b3735f
11 changed files with 52 additions and 27 deletions

View File

@@ -67,6 +67,7 @@ module Budgets
def create def create
@investment.author = current_user @investment.author = current_user
@investment.heading = @budget.headings.first if @budget.single_heading?
if @investment.save if @investment.save
Mailer.budget_investment_created(@investment).deliver_later Mailer.budget_investment_created(@investment).deliver_later

View File

@@ -25,6 +25,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController
def create def create
@investment.terms_of_service = "1" @investment.terms_of_service = "1"
@investment.author = managed_user @investment.author = managed_user
@investment.heading = @budget.headings.first if @budget.single_heading?
if @investment.save if @investment.save
notice = t("flash.actions.create.notice", resource_name: Budget::Investment.model_name.human, count: 1) notice = t("flash.actions.create.notice", resource_name: Budget::Investment.model_name.human, count: 1)

View File

@@ -3,9 +3,12 @@
<%= render "shared/errors", resource: @investment %> <%= render "shared/errors", resource: @investment %>
<div class="row column"> <div class="row column">
<% unless @budget.single_heading? %>
<div class="small-12 medium-8 column"> <div class="small-12 medium-8 column">
<%= f.select :heading_id, budget_heading_select_options(@budget), { include_blank: true } %> <%= f.select :heading_id, budget_heading_select_options(@budget), { include_blank: true } %>
</div> </div>
<% end %>
<div class="row"> <div class="row">
<div class="small-12 column"> <div class="small-12 column">
<%= render "shared/globalize_locales", resource: @investment %> <%= render "shared/globalize_locales", resource: @investment %>

View File

@@ -319,7 +319,6 @@ def validate_latitude_longitude(mappable_factory_name)
end end
def fill_in_budget_investment_form def fill_in_budget_investment_form
page.select mappable.heading.name_scoped_by_group, from: :budget_investment_heading_id
fill_in "Title", with: "Budget investment title" fill_in "Title", with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description" fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service check :budget_investment_terms_of_service

View File

@@ -361,7 +361,6 @@ def documentable_fill_new_valid_dashboard_action
end end
def documentable_fill_new_valid_budget_investment def documentable_fill_new_valid_budget_investment
page.select documentable.heading.name_scoped_by_group, from: :budget_investment_heading_id
fill_in "Title", with: "Budget investment title" fill_in "Title", with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description" fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service check :budget_investment_terms_of_service

View File

@@ -294,7 +294,6 @@ def imageable_fill_new_valid_budget
end end
def imageable_fill_new_valid_budget_investment def imageable_fill_new_valid_budget_investment
page.select imageable.heading.name_scoped_by_group, from: :budget_investment_heading_id
fill_in "Title", with: "Budget investment title" fill_in "Title", with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description" fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service check :budget_investment_terms_of_service

View File

@@ -511,7 +511,6 @@ describe "Budget Investments" do
login_as(author) login_as(author)
visit new_budget_investment_path(budget) visit new_budget_investment_path(budget)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "I am a bot" fill_in "Title", with: "I am a bot"
fill_in "budget_investment_subtitle", with: "This is the honeypot" fill_in "budget_investment_subtitle", with: "This is the honeypot"
fill_in "Description", with: "This is the description" fill_in "Description", with: "This is the description"
@@ -530,7 +529,6 @@ describe "Budget Investments" do
login_as(author) login_as(author)
visit new_budget_investment_path(budget) visit new_budget_investment_path(budget)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "I am a bot" fill_in "Title", with: "I am a bot"
fill_in_ckeditor "Description", with: "This is the description" fill_in_ckeditor "Description", with: "This is the description"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
@@ -541,18 +539,20 @@ describe "Budget Investments" do
expect(page).to have_current_path(new_budget_investment_path(budget)) expect(page).to have_current_path(new_budget_investment_path(budget))
end end
scenario "Create" do scenario "Create with single heading" do
login_as(author) login_as(author)
visit new_budget_investment_path(budget) visit new_budget_investment_path(budget)
select heading.name, from: "budget_investment_heading_id" expect(page).not_to have_field "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper" fill_in "Title", with: "Build a skyscraper"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds" fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
fill_in "budget_investment_location", with: "City center" fill_in "Location additional info", with: "City center"
fill_in "budget_investment_organization_name", with: "T.I.A." fill_in "If you are proposing in the name of a collective/organization, "\
fill_in "budget_investment_tag_list", with: "Towers" "or on behalf of more people, write its name", with: "T.I.A."
check "budget_investment_terms_of_service" fill_in "Tags", with: "Towers"
check "I agree to the Privacy Policy and the Terms and conditions of use"
click_button "Create Investment" click_button "Create Investment"
@@ -563,7 +563,42 @@ describe "Budget Investments" do
expect(page).to have_content "T.I.A." expect(page).to have_content "T.I.A."
expect(page).to have_content "Towers" expect(page).to have_content "Towers"
visit user_url(author, filter: :budget_investments) visit user_path(author, filter: :budget_investments)
expect(page).to have_content "1 Investment"
expect(page).to have_content "Build a skyscraper"
end
scenario "Create with multiple headings" do
create(:budget_heading, budget: budget, name: "Medical supplies")
create(:budget_heading, budget: budget, name: "Even more hospitals")
login_as(author)
visit new_budget_investment_path(budget)
expect(page).to have_select "Heading",
options: ["", "More hospitals", "Medical supplies", "Even more hospitals"]
select "Medical supplies", from: "Heading"
fill_in "Title", with: "Build a skyscraper"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
fill_in "Location additional info", with: "City center"
fill_in "If you are proposing in the name of a collective/organization, "\
"or on behalf of more people, write its name", with: "T.I.A."
fill_in "Tags", with: "Towers"
check "I agree to the Privacy Policy and the Terms and conditions of use"
click_button "Create Investment"
expect(page).to have_content "Investment created successfully"
expect(page).to have_content "Build a skyscraper"
expect(page).to have_content "I want to live in a high tower over the clouds"
expect(page).to have_content "City center"
expect(page).to have_content "T.I.A."
expect(page).to have_content "Towers"
visit user_path(author, filter: :budget_investments)
expect(page).to have_content "1 Investment" expect(page).to have_content "1 Investment"
expect(page).to have_content "Build a skyscraper" expect(page).to have_content "Build a skyscraper"
end end
@@ -1561,7 +1596,6 @@ describe "Budget Investments" do
scenario "create budget investment with sdg related list" do scenario "create budget investment with sdg related list" do
login_as(author) login_as(author)
visit new_budget_investment_path(budget) visit new_budget_investment_path(budget)
select heading.name, from: "Heading"
fill_in "Title", with: "A title for a budget investment related with SDG related content" fill_in "Title", with: "A title for a budget investment related with SDG related content"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds" fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
click_sdg_goal(1) click_sdg_goal(1)

View File

@@ -350,7 +350,6 @@ describe "Emails" do
login_as(author) login_as(author)
visit new_budget_investment_path(budget_id: budget.id) visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a hospital" fill_in "Title", with: "Build a hospital"
fill_in_ckeditor "Description", with: "We have lots of people that require medical attention" fill_in_ckeditor "Description", with: "We have lots of people that require medical attention"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"

View File

@@ -65,7 +65,6 @@ describe "Budget Investments" do
expect(page).to have_content user.document_number expect(page).to have_content user.document_number
end end
select "Health", from: "budget_investment_heading_id"
fill_in "Title", with: "Build a park in my neighborhood" fill_in "Title", with: "Build a park in my neighborhood"
fill_in_ckeditor "Description", with: "There is no parks here..." fill_in_ckeditor "Description", with: "There is no parks here..."
fill_in "budget_investment_location", with: "City center" fill_in "budget_investment_location", with: "City center"

View File

@@ -66,7 +66,6 @@ describe "Tags" do
visit new_budget_investment_path(budget_id: budget.id) visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper" fill_in "Title", with: "Build a skyscraper"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds" fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
@@ -85,7 +84,6 @@ describe "Tags" do
visit new_budget_investment_path(budget_id: budget.id) visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper" fill_in "Title", with: "Build a skyscraper"
fill_in_ckeditor "Description", with: "If I had a gym near my place I could go do Zumba" fill_in_ckeditor "Description", with: "If I had a gym near my place I could go do Zumba"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
@@ -110,7 +108,6 @@ describe "Tags" do
visit budget_path(budget) visit budget_path(budget)
click_link "Create a budget investment" click_link "Create a budget investment"
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper" fill_in "Title", with: "Build a skyscraper"
fill_in_ckeditor "Description", with: "If I had a gym near my place I could go do Zumba" fill_in_ckeditor "Description", with: "If I had a gym near my place I could go do Zumba"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
@@ -135,7 +132,6 @@ describe "Tags" do
visit budget_investments_path(budget, heading_id: heading.id) visit budget_investments_path(budget, heading_id: heading.id)
click_link "Create a budget investment" click_link "Create a budget investment"
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper" fill_in "Title", with: "Build a skyscraper"
fill_in_ckeditor "Description", with: "If I had a gym near my place I could go do Zumba" fill_in_ckeditor "Description", with: "If I had a gym near my place I could go do Zumba"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
@@ -157,7 +153,6 @@ describe "Tags" do
visit new_budget_investment_path(budget_id: budget.id) visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper" fill_in "Title", with: "Build a skyscraper"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds" fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
@@ -175,7 +170,6 @@ describe "Tags" do
visit new_budget_investment_path(budget_id: budget.id) visit new_budget_investment_path(budget_id: budget.id)
select heading.name, from: "budget_investment_heading_id"
fill_in "Title", with: "Build a skyscraper" fill_in "Title", with: "Build a skyscraper"
fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds" fill_in_ckeditor "Description", with: "I want to live in a high tower over the clouds"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"

View File

@@ -47,7 +47,6 @@ describe "Public area translatable records" do
fill_in "Title", with: "Titre en Français" fill_in "Title", with: "Titre en Français"
fill_in_ckeditor "Description", with: "Contenu en Français" fill_in_ckeditor "Description", with: "Contenu en Français"
select "Everywhere", from: "budget_investment_heading_id"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
click_button "Create Investment" click_button "Create Investment"
@@ -76,7 +75,6 @@ describe "Public area translatable records" do
fill_in "Title", with: "Titre en Français" fill_in "Title", with: "Titre en Français"
fill_in_ckeditor "Description", with: "Contenu en Français" fill_in_ckeditor "Description", with: "Contenu en Français"
select "Everywhere", from: "budget_investment_heading_id"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
click_button "Create Investment" click_button "Create Investment"
@@ -99,7 +97,6 @@ describe "Public area translatable records" do
visit new_budget_investment_path(budget) visit new_budget_investment_path(budget)
click_link "Remove language" click_link "Remove language"
select "Everywhere", from: "budget_investment_heading_id"
check "budget_investment_terms_of_service" check "budget_investment_terms_of_service"
click_button "Create Investment" click_button "Create Investment"