make parameter 'skip_map' accessible on creating an investment

This commit is contained in:
Julian Herrero
2018-12-26 12:58:43 +01:00
parent f7022b36b4
commit bf7112f090
3 changed files with 47 additions and 18 deletions

View File

@@ -52,7 +52,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end end
def investment_params def investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list, :organization_name, :location) params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id,
:tag_list, :organization_name, :location, :skip_map)
end end
def only_verified_users def only_verified_users

View File

@@ -9,6 +9,15 @@ feature 'Budget Investments' do
@heading = create(:budget_heading, group: @group, name: "Health") @heading = create(:budget_heading, group: @group, name: "Health")
end end
it_behaves_like "mappable",
"budget_investment",
"investment",
"new_management_budget_investment_path",
"",
"management_budget_investment_path",
{ "budget_id": "budget_id" },
management = true
context "Create" do context "Create" do
before { @budget.update(phase: 'accepting') } before { @budget.update(phase: 'accepting') }

View File

@@ -1,4 +1,10 @@
shared_examples "mappable" do |mappable_factory_name, mappable_association_name, mappable_new_path, mappable_edit_path, mappable_show_path, mappable_path_arguments| shared_examples "mappable" do |mappable_factory_name,
mappable_association_name,
mappable_new_path,
mappable_edit_path,
mappable_show_path,
mappable_path_arguments,
management = false|
include ActionView::Helpers include ActionView::Helpers
@@ -6,6 +12,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
let!(:arguments) { {} } let!(:arguments) { {} }
let!(:mappable) { create(mappable_factory_name.to_s.to_sym) } let!(:mappable) { create(mappable_factory_name.to_s.to_sym) }
let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) } let!(:map_location) { create(:map_location, "#{mappable_factory_name}_map_location".to_sym, "#{mappable_association_name}": mappable) }
let(:management) { management }
before do before do
Setting['feature.map'] = true Setting['feature.map'] = true
@@ -16,7 +23,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
before { set_arguments(arguments, mappable, mappable_path_arguments) } before { set_arguments(arguments, mappable, mappable_path_arguments) }
scenario "Should not show marker by default on create #{mappable_factory_name}", :js do scenario "Should not show marker by default on create #{mappable_factory_name}", :js do
login_as user do_login_for user
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form") send("fill_in_#{mappable_factory_name}_form")
@@ -27,7 +34,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario "Should show marker on create #{mappable_factory_name} when click on map", :js do scenario "Should show marker on create #{mappable_factory_name} when click on map", :js do
login_as user do_login_for user
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form") send("fill_in_#{mappable_factory_name}_form")
@@ -39,7 +46,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario "Should create #{mappable_factory_name} with map", :js do scenario "Should create #{mappable_factory_name} with map", :js do
login_as user do_login_for user
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form") send("fill_in_#{mappable_factory_name}_form")
@@ -50,7 +57,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario "Can not display map on #{mappable_factory_name} when not fill marker on map", :js do scenario "Can not display map on #{mappable_factory_name} when not fill marker on map", :js do
login_as user do_login_for user
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form") send("fill_in_#{mappable_factory_name}_form")
@@ -63,7 +70,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
scenario "Can not display map on #{mappable_factory_name} when feature.map is disabled", :js do scenario "Can not display map on #{mappable_factory_name} when feature.map is disabled", :js do
Setting['feature.map'] = false Setting['feature.map'] = false
login_as user do_login_for user
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form") send("fill_in_#{mappable_factory_name}_form")
@@ -74,7 +81,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario 'Errors on create' do scenario 'Errors on create' do
login_as user do_login_for user
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
send("submit_#{mappable_factory_name}_form") send("submit_#{mappable_factory_name}_form")
@@ -83,7 +90,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario 'Skip map', :js do scenario 'Skip map', :js do
login_as user do_login_for user
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form") send("fill_in_#{mappable_factory_name}_form")
@@ -94,7 +101,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario 'Toggle map', :js do scenario 'Toggle map', :js do
login_as user do_login_for user
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
check "#{mappable_factory_name}_skip_map" check "#{mappable_factory_name}_skip_map"
@@ -115,7 +122,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
before { skip } if mappable_edit_path.blank? before { skip } if mappable_edit_path.blank?
scenario "Should edit map on #{mappable_factory_name} and contain default values", :js do scenario "Should edit map on #{mappable_factory_name} and contain default values", :js do
login_as mappable.author do_login_for mappable.author
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
@@ -124,7 +131,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario "Should edit default values from map on #{mappable_factory_name} edit page", :js do scenario "Should edit default values from map on #{mappable_factory_name} edit page", :js do
login_as mappable.author do_login_for mappable.author
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
find(".map_location").click find(".map_location").click
@@ -137,7 +144,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario "Should edit mappable on #{mappable_factory_name} without change map", :js do scenario "Should edit mappable on #{mappable_factory_name} without change map", :js do
login_as mappable.author do_login_for mappable.author
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
fill_in "#{mappable_factory_name}_title", with: "New title" fill_in "#{mappable_factory_name}_title", with: "New title"
@@ -150,7 +157,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario "Can not display map on #{mappable_factory_name} edit when remove map marker", :js do scenario "Can not display map on #{mappable_factory_name} edit when remove map marker", :js do
login_as mappable.author do_login_for mappable.author
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker" click_link "Remove map marker"
@@ -162,7 +169,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
scenario "Can not display map on #{mappable_factory_name} edit when feature.map is disabled", :js do scenario "Can not display map on #{mappable_factory_name} edit when feature.map is disabled", :js do
Setting['feature.map'] = false Setting['feature.map'] = false
login_as mappable.author do_login_for mappable.author
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
fill_in "#{mappable_factory_name}_title", with: "New title" fill_in "#{mappable_factory_name}_title", with: "New title"
@@ -173,7 +180,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
scenario 'No errors on update', :js do scenario 'No errors on update', :js do
skip "" skip ""
login_as mappable.author do_login_for mappable.author
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker" click_link "Remove map marker"
@@ -183,7 +190,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
scenario 'No need to skip map on update' do scenario 'No need to skip map on update' do
login_as mappable.author do_login_for mappable.author
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker" click_link "Remove map marker"
@@ -196,7 +203,10 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
describe "At #{mappable_show_path}" do describe "At #{mappable_show_path}" do
before { set_arguments(arguments, mappable, mappable_path_arguments) } before do
set_arguments(arguments, mappable, mappable_path_arguments)
do_login_for(user) if management
end
scenario "Should display map on #{mappable_factory_name} show page", :js do scenario "Should display map on #{mappable_factory_name} show page", :js do
arguments[:id] = mappable.id arguments[:id] = mappable.id
@@ -229,6 +239,15 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end end
def do_login_for(user)
if management
login_as_manager
login_managed_user(user)
else
login_as(user)
end
end
def fill_in_proposal_form def fill_in_proposal_form
fill_in 'proposal_title', with: 'Help refugees' fill_in 'proposal_title', with: 'Help refugees'
fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?' fill_in 'proposal_question', with: '¿Would you like to give assistance to war refugees?'