Skip to content

Commit

Permalink
Merge pull request consuldemocracy#68 from democrateam/favicon
Browse files Browse the repository at this point in the history
Add favicon to site customization images
  • Loading branch information
microweb10 committed Mar 31, 2022
2 parents 5b134f7 + c868110 commit 1d0dde9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
12 changes: 10 additions & 2 deletions app/models/site_customization/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ class SiteCustomization::Image < ApplicationRecord
"welcome_process" => [370, 185],
"auth_bg" => [934, 1398],
"bg_footer" => [1200, 300],
"logo_footer" => [260, 80]
"logo_footer" => [260, 80],
"favicon" => [16, 16]
}.freeze

VALID_MIME_TYPES = %w[
image/png
image/jpeg
image/x-icon
image/vnd.microsoft.icon
].freeze

has_attachment :image

validates :name, presence: true, uniqueness: true, inclusion: { in: VALID_IMAGES.keys }
validates_attachment_content_type :image, content_type: ["image/png", "image/jpeg"]
validates_attachment_content_type :image, content_type: VALID_MIME_TYPES
validate :check_image

def self.all_images
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/_common_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,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") %>
2 changes: 1 addition & 1 deletion app/views/layouts/dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application", "data-turbolinks-track" => "reload" %>
<%= csrf_meta_tags %>
<%= favicon_link_tag "favicon.ico" %>
<%= favicon_link_tag image_path_for("favicon.ico") %>
<%= favicon_link_tag image_path_for("apple-touch-icon-200.png"),
rel: "icon apple-touch-icon",
sizes: "200x200",
Expand Down
Binary file added spec/fixtures/files/favicon_custom.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion spec/system/admin/site_customization/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
scenario "List of customizable images" do
valid_images = SiteCustomization::Image::VALID_IMAGES
%w[logo_header social_media_icon social_media_icon_twitter apple-touch-icon-200 budget_execution_no_image
budget_no_image budget_investment_no_image map logo_email welcome_process
budget_no_image budget_investment_no_image map logo_email welcome_process favicon
welcome/step_1 welcome/step_2 welcome/step_3 auth_bg bg_footer logo_footer].each do |image_name|
expect(valid_images.keys).to include(image_name)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/system/home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,20 @@ def ie_alert_box_xpath
within(".header-card") { expect(page).not_to have_link }
end
end

scenario "Favicon custom" do
visit root_path

expect(page).to have_css("link[rel=\"shortcut icon\"]", visible: :hidden)
expect(page).to have_xpath("//link[contains(@href, \"favicon-\")]", visible: :hidden)

create(:site_customization_image, name: "favicon",
image: File.new("spec/fixtures/files/favicon_custom.ico"))

visit root_path

expect(page).to have_css("link[rel=\"shortcut icon\"]", visible: :hidden)
expect(page).not_to have_xpath("//link[contains(@href, \"favicon-\")]", visible: :hidden)
expect(page).to have_xpath("//link[contains(@href, \"favicon_custom\")]", visible: :hidden)
end
end

0 comments on commit 1d0dde9

Please sign in to comment.