Allow to create an investment with images

In the Management section when creating an investment we were not passing the
images attributes, so we were never able to associate images.

Make the nested_imageable spec compatible with the Management section.
This commit is contained in:
taitus
2021-03-29 12:27:15 +02:00
parent fa12528581
commit 82cd019b40
3 changed files with 37 additions and 19 deletions

View File

@@ -1,5 +1,6 @@
class Management::Budgets::InvestmentsController < Management::BaseController class Management::Budgets::InvestmentsController < Management::BaseController
include Translatable include Translatable
include ImageAttributes
include MapLocationAttributes include MapLocationAttributes
include FeatureFlags include FeatureFlags
feature_flag :budgets feature_flag :budgets
@@ -59,6 +60,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController
def investment_params def investment_params
attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, :skip_map, attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, :skip_map,
image_attributes: image_attributes,
map_location_attributes: map_location_attributes] map_location_attributes: map_location_attributes]
params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment)) params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment))
end end

View File

@@ -1,7 +1,10 @@
shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments, fill_resource_method_name, submit_button, imageable_success_notice, has_many_images = false| shared_examples "nested imageable" do |imageable_factory_name, path, imageable_path_arguments,
fill_resource_method_name, submit_button, imageable_success_notice,
has_many_images = false, management: false|
let!(:user) { create(:user, :level_two) } let!(:user) { create(:user, :level_two) }
let!(:arguments) { {} } let!(:arguments) { {} }
let!(:imageable) { create(imageable_factory_name) } let!(:imageable) { create(imageable_factory_name) }
let(:management) { management }
before do before do
create(:administrator, user: user) create(:administrator, user: user)
@@ -15,14 +18,14 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
describe "at #{path}" do describe "at #{path}" do
scenario "Should show new image link when imageable has not an associated image defined" do scenario "Should show new image link when imageable has not an associated image defined" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_selector "#new_image_link" expect(page).to have_selector "#new_image_link"
end end
scenario "Should hide new image link after adding one image" do scenario "Should hide new image link after adding one image" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_on "Add image" click_on "Add image"
@@ -31,7 +34,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update nested image file name after choosing any file" do scenario "Should update nested image file name after choosing any file" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_link "Add image" click_link "Add image"
@@ -46,7 +49,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update nested image file title with file name after choosing a file when no title defined" do scenario "Should update nested image file title with file name after choosing a file when no title defined" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -58,7 +61,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should not update nested image file title with file name after choosing a file when title already defined" do scenario "Should not update nested image file title with file name after choosing a file when title already defined" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_link "Add image" click_link "Add image"
@@ -79,7 +82,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update loading bar style after valid file upload" do scenario "Should update loading bar style after valid file upload" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -91,7 +94,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update loading bar style after invalid file upload" do scenario "Should update loading bar style after invalid file upload" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -104,7 +107,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should update image cached_attachment field after valid file upload" do scenario "Should update image cached_attachment field after valid file upload" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -116,7 +119,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should not update image cached_attachment field after invalid file upload" do scenario "Should not update image cached_attachment field after invalid file upload" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -129,7 +132,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should show nested image errors after invalid form submit" do scenario "Should show nested image errors after invalid form submit" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_link "Add image" click_link "Add image"
@@ -145,7 +148,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should remove nested image after valid file upload and click on remove button" do scenario "Should remove nested image after valid file upload and click on remove button" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
imageable_attach_new_file( imageable_attach_new_file(
@@ -164,7 +167,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
if has_many_images if has_many_images
skip "no need to test, there are no attributes for the parent resource" skip "no need to test, there are no attributes for the parent resource"
else else
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -174,7 +177,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should show successful notice when resource filled correctly and after valid file uploads" do scenario "Should show successful notice when resource filled correctly and after valid file uploads" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -191,7 +194,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
scenario "Should show new image after successful creation with one uploaded file" do scenario "Should show new image after successful creation with one uploaded file" do
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name send(fill_resource_method_name) if fill_resource_method_name
@@ -216,7 +219,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
if path.include? "edit" if path.include? "edit"
scenario "Should show persisted image" do scenario "Should show persisted image" do
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
expect(page).to have_css ".image", count: 1 expect(page).to have_css ".image", count: 1
@@ -224,7 +227,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "Should not show add image button when image already exists" do scenario "Should not show add image button when image already exists" do
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
expect(page).not_to have_css "a#new_image_link" expect(page).not_to have_css "a#new_image_link"
@@ -232,7 +235,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "Should remove nested field after remove image" do scenario "Should remove nested field after remove image" do
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_on "Remove image" click_on "Remove image"
@@ -241,7 +244,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "Should show add image button after remove image" do scenario "Should show add image button after remove image" do
create(:image, imageable: imageable) create(:image, imageable: imageable)
login_as user do_login_for user
visit send(path, arguments) visit send(path, arguments)
click_on "Remove image" click_on "Remove image"
@@ -251,6 +254,10 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end end
end end
def do_login_for(user)
common_do_login_for(user, management: management)
end
def imageable_redirected_to_resource_show_or_navigate_to def imageable_redirected_to_resource_show_or_navigate_to
find("a", text: "Not now, go to my proposal") find("a", text: "Not now, go to my proposal")
click_on "Not now, go to my proposal" click_on "Not now, go to my proposal"

View File

@@ -7,6 +7,15 @@ describe "Budget Investments" do
let(:heading) { create(:budget_heading, group: group, name: "Health") } let(:heading) { create(:budget_heading, group: group, name: "Health") }
let(:user) { create(:user, :level_two) } let(:user) { create(:user, :level_two) }
it_behaves_like "nested imageable",
"budget_investment",
"new_management_budget_investment_path",
{ "budget_id": "budget_id" },
"imageable_fill_new_valid_budget_investment",
"Create Investment",
"Investment created successfully.",
management: true
it_behaves_like "mappable", it_behaves_like "mappable",
"budget_investment", "budget_investment",
"investment", "investment",