diff --git a/app/models/site_customization/image.rb b/app/models/site_customization/image.rb index c3219e427..e933c40a0 100644 --- a/app/models/site_customization/image.rb +++ b/app/models/site_customization/image.rb @@ -4,13 +4,14 @@ class SiteCustomization::Image < ActiveRecord::Base "social_media_icon" => [470, 246], "social_media_icon_twitter" => [246, 246], "apple-touch-icon-200" => [200, 200], - "budget_execution_no_image" => [800, 600] + "budget_execution_no_image" => [800, 600], + "map" => [420, 500] } has_attached_file :image validates :name, presence: true, uniqueness: true, inclusion: { in: VALID_IMAGES.keys } - validates_attachment_content_type :image, content_type: ["image/png"] + validates_attachment_content_type :image, content_type: ["image/png", "image/jpeg"] validate :check_image def self.all_images diff --git a/app/views/admin/site_customization/images/index.html.erb b/app/views/admin/site_customization/images/index.html.erb index 95b9e18a7..cc974c279 100644 --- a/app/views/admin/site_customization/images/index.html.erb +++ b/app/views/admin/site_customization/images/index.html.erb @@ -9,7 +9,7 @@ <% @images.each do |image| %> - + <%= image.name %> (<%= image.required_width %>x<%= image.required_height %>) diff --git a/app/views/proposals/_geozones.html.erb b/app/views/proposals/_geozones.html.erb index 7e4dbcaa4..9840f8fdc 100644 --- a/app/views/proposals/_geozones.html.erb +++ b/app/views/proposals/_geozones.html.erb @@ -2,5 +2,5 @@
<%= link_to map_proposals_path, id: 'map', title: t("shared.tags_cloud.districts_list") do %> - <%= image_tag("map.jpg", alt: t("shared.tags_cloud.districts_list")) %> + <%= image_tag(image_path_for("map.jpg"), alt: t("shared.tags_cloud.districts_list")) %> <% end %> diff --git a/spec/features/admin/site_customization/images_spec.rb b/spec/features/admin/site_customization/images_spec.rb index f4419e97e..d2f23d34e 100644 --- a/spec/features/admin/site_customization/images_spec.rb +++ b/spec/features/admin/site_customization/images_spec.rb @@ -7,22 +7,57 @@ feature "Admin custom images" do login_as(admin.user) end - scenario "Upload valid image" do + scenario "Upload valid png image" do visit admin_root_path within("#side_menu") do click_link "Custom images" end - within("tr.logo_header") do + within("tr#image_logo_header") do attach_file "site_customization_image_image", "spec/fixtures/files/logo_header.png" click_button "Update" end - expect(page).to have_css("tr.logo_header img[src*='logo_header.png']") + expect(page).to have_css("tr#image_logo_header img[src*='logo_header.png']") expect(page).to have_css("img[src*='logo_header.png']", count: 1) end + scenario "Upload valid jpg image" do + visit admin_root_path + + within("#side_menu") do + click_link "Custom images" + end + + within("tr#image_map") do + attach_file "site_customization_image_image", "spec/fixtures/files/custom_map.jpg" + click_button "Update" + end + + expect(page).to have_css("tr#image_map img[src*='custom_map.jpg']") + expect(page).to have_css("img[src*='custom_map.jpg']", count: 1) + end + + scenario "Image is replaced on front view" do + visit admin_root_path + + within("#side_menu") do + click_link "Custom images" + end + + within("tr#image_map") do + attach_file "site_customization_image_image", "spec/fixtures/files/custom_map.jpg" + click_button "Update" + end + + visit proposals_path + + within("#map") do + expect(page).to have_css("img[src*='custom_map.jpg']") + end + end + scenario "Upload invalid image" do visit admin_root_path @@ -30,7 +65,7 @@ feature "Admin custom images" do click_link "Custom images" end - within("tr.social_media_icon") do + within("tr#image_social_media_icon") do attach_file "site_customization_image_image", "spec/fixtures/files/logo_header.png" click_button "Update" end @@ -46,14 +81,14 @@ feature "Admin custom images" do click_link "Custom images" end - within("tr.social_media_icon") do + within("tr#image_social_media_icon") do attach_file "site_customization_image_image", "spec/fixtures/files/social_media_icon.png" click_button "Update" end expect(page).to have_css("img[src*='social_media_icon.png']") - within("tr.social_media_icon") do + within("tr#image_social_media_icon") do click_link "Delete" end diff --git a/spec/fixtures/files/custom_map.jpg b/spec/fixtures/files/custom_map.jpg new file mode 100644 index 000000000..d5fbd5bb5 Binary files /dev/null and b/spec/fixtures/files/custom_map.jpg differ