diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 0377aa35f..9ca78ef7f 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -998,7 +998,7 @@ footer { } .auth-image { - background: $brand image-url("auth_bg.jpg"); + background-color: $brand; background-repeat: no-repeat; background-size: cover; color: $white; diff --git a/app/components/budgets/investment_component.html.erb b/app/components/budgets/investment_component.html.erb index 1b05e2c9b..f3047550e 100644 --- a/app/components/budgets/investment_component.html.erb +++ b/app/components/budgets/investment_component.html.erb @@ -2,7 +2,7 @@ <% if investment.image.present? %> <%= image_tag investment.image.variant(:large), alt: investment.image.title.unicode_normalize %> <% else %> - <%= image_tag "budget_investment_no_image.jpg", alt: investment.title %> + <%= image_tag(image_path_for("budget_investment_no_image.jpg"), alt: investment.title) %> <% end %> <% if investment.should_show_vote_count? || investment.should_show_price? %> diff --git a/app/components/budgets/investment_component.rb b/app/components/budgets/investment_component.rb index e52af44d9..11e258deb 100644 --- a/app/components/budgets/investment_component.rb +++ b/app/components/budgets/investment_component.rb @@ -1,5 +1,5 @@ class Budgets::InvestmentComponent < ApplicationComponent - delegate :locale_and_user_status, :namespaced_budget_investment_path, to: :helpers + delegate :locale_and_user_status, :namespaced_budget_investment_path, :image_path_for, to: :helpers attr_reader :investment def initialize(investment) diff --git a/app/components/widget/feeds/process_component.html.erb b/app/components/widget/feeds/process_component.html.erb index 7bc071a2b..d05d53e3a 100644 --- a/app/components/widget/feeds/process_component.html.erb +++ b/app/components/widget/feeds/process_component.html.erb @@ -1,7 +1,7 @@
<%= link_to url_for(process) do %>
- <%= image_tag("welcome_process.png", alt: "") %> + <%= image_tag(image_path_for("welcome_process.png"), alt: "") %>
<%= t("welcome.feed.process_label") %>

<%= process.title %>

diff --git a/app/components/widget/feeds/process_component.rb b/app/components/widget/feeds/process_component.rb index ab8065663..ab38d0801 100644 --- a/app/components/widget/feeds/process_component.rb +++ b/app/components/widget/feeds/process_component.rb @@ -1,4 +1,5 @@ class Widget::Feeds::ProcessComponent < ApplicationComponent + delegate :image_path_for, to: :helpers attr_reader :process def initialize(process) diff --git a/app/models/site_customization/image.rb b/app/models/site_customization/image.rb index d832cf40a..7d69f74c1 100644 --- a/app/models/site_customization/image.rb +++ b/app/models/site_customization/image.rb @@ -6,12 +6,21 @@ class SiteCustomization::Image < ApplicationRecord "social_media_icon" => [470, 246], "social_media_icon_twitter" => [246, 246], "apple-touch-icon-200" => [200, 200], + "auth_bg" => [1280, 1500], "budget_execution_no_image" => [800, 600], + "budget_investment_no_image" => [800, 600], + "favicon" => [16, 16], "map" => [420, 500], - "logo_email" => [400, 80] + "logo_email" => [400, 80], + "welcome_process" => [370, 185] }.freeze - VALID_MIME_TYPES = %w[image/jpeg image/png].freeze + VALID_MIME_TYPES = %w[ + image/jpeg + image/png + image/vnd.microsoft.icon + image/x-icon + ].freeze has_attachment :image diff --git a/app/views/layouts/_common_head.html.erb b/app/views/layouts/_common_head.html.erb index eb64eeced..369c5261e 100644 --- a/app/views/layouts/_common_head.html.erb +++ b/app/views/layouts/_common_head.html.erb @@ -10,4 +10,4 @@ <% end %> <%= javascript_include_tag "application", "data-turbolinks-track" => "reload" %> <%= csrf_meta_tags %> -<%= favicon_link_tag "favicon.ico" %> +<%= favicon_link_tag image_path_for("favicon.ico") %> diff --git a/app/views/layouts/devise.html.erb b/app/views/layouts/devise.html.erb index c781d4403..e9ebac423 100644 --- a/app/views/layouts/devise.html.erb +++ b/app/views/layouts/devise.html.erb @@ -9,7 +9,8 @@ <%= raw setting["html.per_page_code_body"] %>
-
+
)">

<%= link_to root_path do %> <%= image_tag(image_path_for("logo_header.png"), class: "float-left", alt: setting["org_name"]) %> diff --git a/spec/components/budgets/investment_component_spec.rb b/spec/components/budgets/investment_component_spec.rb index 7db17ae8d..fe25ac490 100644 --- a/spec/components/budgets/investment_component_spec.rb +++ b/spec/components/budgets/investment_component_spec.rb @@ -11,11 +11,26 @@ describe Budgets::InvestmentComponent do expect(page).to have_css "img[alt='#{investment.image.title}']" end - it "shows the default image when investment has not an image defined" do - investment = create(:budget_investment) - render_inline Budgets::InvestmentComponent.new(investment) + context "investment without an image" do + let(:component) { Budgets::InvestmentComponent.new(create(:budget_investment)) } - expect(page).to have_css "img[src*='budget_investment_no_image']" + it "shows the default image" do + render_inline component + + expect(page).to have_css "img[src*='budget_investment_no_image']" + end + + it "shows a custom default image when available" do + stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "budget_investment_no_image" => [260, 80] }) + create(:site_customization_image, + name: "budget_investment_no_image", + image: fixture_file_upload("logo_header-260x80.png")) + + render_inline component + + expect(page).to have_css "img[src$='logo_header-260x80.png']" + expect(page).not_to have_css "img[src*='budget_investment_no_image']" + end end it "shows supports count when budget is valuating" do diff --git a/spec/components/widget/feeds/process_component_spec.rb b/spec/components/widget/feeds/process_component_spec.rb index 0f0d2327f..a7be34f17 100644 --- a/spec/components/widget/feeds/process_component_spec.rb +++ b/spec/components/widget/feeds/process_component_spec.rb @@ -20,4 +20,24 @@ describe Widget::Feeds::ProcessComponent do expect(page).to have_css("img[alt='1. No Poverty']") end + + describe "image" do + it "shows the default image" do + render_inline component + + expect(page).to have_css "img[src*='welcome_process']" + end + + it "shows a custom default image when available" do + stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "welcome_process" => [260, 80] }) + create(:site_customization_image, + name: "welcome_process", + image: fixture_file_upload("logo_header-260x80.png")) + + render_inline component + + expect(page).to have_css "img[src$='logo_header-260x80.png']" + expect(page).not_to have_css "img[src*='welcome_process']" + end + end end diff --git a/spec/fixtures/files/favicon_custom.ico b/spec/fixtures/files/favicon_custom.ico new file mode 100644 index 000000000..187043296 Binary files /dev/null and b/spec/fixtures/files/favicon_custom.ico differ diff --git a/spec/system/site_customization/images_spec.rb b/spec/system/site_customization/images_spec.rb new file mode 100644 index 000000000..4674eaf1d --- /dev/null +++ b/spec/system/site_customization/images_spec.rb @@ -0,0 +1,23 @@ +require "rails_helper" + +describe "Site customization images" do + scenario "Custom favicon" do + create(:site_customization_image, name: "favicon", image: fixture_file_upload("favicon_custom.ico")) + + visit root_path + + expect(page).to have_css("link[rel='shortcut icon'][href$='favicon_custom.ico']", visible: :hidden) + end + + scenario "Custom auth background" do + stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "auth_bg" => [260, 80] }) + create(:site_customization_image, + name: "auth_bg", + image: fixture_file_upload("logo_header-260x80.png")) + + visit new_user_session_path + + expect(page).to have_css "[style*='background-image:'][style*='logo_header-260x80.png']" + expect(page).not_to have_css "[style*='auth_bg']" + end +end