diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index b30d230ff..e681160bc 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -67,6 +67,7 @@ module Budgets def create @investment.author = current_user + @investment.heading = @budget.headings.first if @budget.single_heading? if @investment.save Mailer.budget_investment_created(@investment).deliver_later diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb index 537c1bc70..3a642e173 100644 --- a/app/controllers/management/budgets/investments_controller.rb +++ b/app/controllers/management/budgets/investments_controller.rb @@ -25,6 +25,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController def create @investment.terms_of_service = "1" @investment.author = managed_user + @investment.heading = @budget.headings.first if @budget.single_heading? if @investment.save notice = t("flash.actions.create.notice", resource_name: Budget::Investment.model_name.human, count: 1) diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index c7c85e686..8296a2e30 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -3,9 +3,12 @@ <%= render "shared/errors", resource: @investment %>
-
- <%= f.select :heading_id, budget_heading_select_options(@budget), { include_blank: true } %> -
+ <% unless @budget.single_heading? %> +
+ <%= f.select :heading_id, budget_heading_select_options(@budget), { include_blank: true } %> +
+ <% end %> +
<%= render "shared/globalize_locales", resource: @investment %> diff --git a/spec/shared/system/mappable.rb b/spec/shared/system/mappable.rb index f31ac7108..332c57bda 100644 --- a/spec/shared/system/mappable.rb +++ b/spec/shared/system/mappable.rb @@ -319,7 +319,6 @@ def validate_latitude_longitude(mappable_factory_name) end 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_ckeditor "Description", with: "Budget investment description" check :budget_investment_terms_of_service diff --git a/spec/shared/system/nested_documentable.rb b/spec/shared/system/nested_documentable.rb index c25baeb20..b6b1175a6 100644 --- a/spec/shared/system/nested_documentable.rb +++ b/spec/shared/system/nested_documentable.rb @@ -361,7 +361,6 @@ def documentable_fill_new_valid_dashboard_action end 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_ckeditor "Description", with: "Budget investment description" check :budget_investment_terms_of_service diff --git a/spec/shared/system/nested_imageable.rb b/spec/shared/system/nested_imageable.rb index fb754f8cb..eddc3bab2 100644 --- a/spec/shared/system/nested_imageable.rb +++ b/spec/shared/system/nested_imageable.rb @@ -294,7 +294,6 @@ def imageable_fill_new_valid_budget end 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_ckeditor "Description", with: "Budget investment description" check :budget_investment_terms_of_service diff --git a/spec/system/budgets/investments_spec.rb b/spec/system/budgets/investments_spec.rb index 7b23df531..a63963319 100644 --- a/spec/system/budgets/investments_spec.rb +++ b/spec/system/budgets/investments_spec.rb @@ -511,7 +511,6 @@ describe "Budget Investments" do login_as(author) visit new_budget_investment_path(budget) - select heading.name, from: "budget_investment_heading_id" fill_in "Title", with: "I am a bot" fill_in "budget_investment_subtitle", with: "This is the honeypot" fill_in "Description", with: "This is the description" @@ -530,7 +529,6 @@ describe "Budget Investments" do login_as(author) visit new_budget_investment_path(budget) - select heading.name, from: "budget_investment_heading_id" fill_in "Title", with: "I am a bot" fill_in_ckeditor "Description", with: "This is the description" 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)) end - scenario "Create" do + scenario "Create with single heading" do login_as(author) 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_ckeditor "Description", with: "I want to live in a high tower over the clouds" - fill_in "budget_investment_location", with: "City center" - fill_in "budget_investment_organization_name", with: "T.I.A." - fill_in "budget_investment_tag_list", with: "Towers" - check "budget_investment_terms_of_service" + 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" @@ -563,7 +563,42 @@ describe "Budget Investments" do expect(page).to have_content "T.I.A." 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 "Build a skyscraper" end @@ -1561,7 +1596,6 @@ describe "Budget Investments" do scenario "create budget investment with sdg related list" do login_as(author) 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_ckeditor "Description", with: "I want to live in a high tower over the clouds" click_sdg_goal(1) diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index e352bba26..c617c5246 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -350,7 +350,6 @@ describe "Emails" do login_as(author) 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_ckeditor "Description", with: "We have lots of people that require medical attention" check "budget_investment_terms_of_service" diff --git a/spec/system/management/budget_investments_spec.rb b/spec/system/management/budget_investments_spec.rb index 4d35c64d3..04b0cd87a 100644 --- a/spec/system/management/budget_investments_spec.rb +++ b/spec/system/management/budget_investments_spec.rb @@ -65,7 +65,6 @@ describe "Budget Investments" do expect(page).to have_content user.document_number end - select "Health", from: "budget_investment_heading_id" fill_in "Title", with: "Build a park in my neighborhood" fill_in_ckeditor "Description", with: "There is no parks here..." fill_in "budget_investment_location", with: "City center" diff --git a/spec/system/tags/budget_investments_spec.rb b/spec/system/tags/budget_investments_spec.rb index 9f5f38284..3e051e1bf 100644 --- a/spec/system/tags/budget_investments_spec.rb +++ b/spec/system/tags/budget_investments_spec.rb @@ -66,7 +66,6 @@ describe "Tags" do 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_ckeditor "Description", with: "I want to live in a high tower over the clouds" check "budget_investment_terms_of_service" @@ -85,7 +84,6 @@ describe "Tags" do 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_ckeditor "Description", with: "If I had a gym near my place I could go do Zumba" check "budget_investment_terms_of_service" @@ -110,7 +108,6 @@ describe "Tags" do visit budget_path(budget) click_link "Create a budget investment" - select heading.name, from: "budget_investment_heading_id" 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" check "budget_investment_terms_of_service" @@ -135,7 +132,6 @@ describe "Tags" do visit budget_investments_path(budget, heading_id: heading.id) click_link "Create a budget investment" - select heading.name, from: "budget_investment_heading_id" 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" check "budget_investment_terms_of_service" @@ -157,7 +153,6 @@ describe "Tags" do 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_ckeditor "Description", with: "I want to live in a high tower over the clouds" check "budget_investment_terms_of_service" @@ -175,7 +170,6 @@ describe "Tags" do 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_ckeditor "Description", with: "I want to live in a high tower over the clouds" check "budget_investment_terms_of_service" diff --git a/spec/system/translatable_spec.rb b/spec/system/translatable_spec.rb index b55fde31c..4b8697e21 100644 --- a/spec/system/translatable_spec.rb +++ b/spec/system/translatable_spec.rb @@ -47,7 +47,6 @@ describe "Public area translatable records" do fill_in "Title", with: "Titre 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" click_button "Create Investment" @@ -76,7 +75,6 @@ describe "Public area translatable records" do fill_in "Title", with: "Titre 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" click_button "Create Investment" @@ -99,7 +97,6 @@ describe "Public area translatable records" do visit new_budget_investment_path(budget) click_link "Remove language" - select "Everywhere", from: "budget_investment_heading_id" check "budget_investment_terms_of_service" click_button "Create Investment"