Skip to content

Commit

Permalink
Merge pull request #291 from alphagov/fix_apple_icon_redirects
Browse files Browse the repository at this point in the history
 Fix redirects for apple-touch icons
  • Loading branch information
bradwright committed Jul 23, 2013
2 parents a6893bb + fbb1d5c commit 89ac064
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/controllers/icon_redirects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class IconRedirectsController < ApplicationController
def show
redirect_to view_context.asset_path(request.fullpath.to_s[1..-1]), :status => 301
redirect_to view_context.asset_path(request.path.to_s[1..-1]), :status => 301
end

def apple_57_57
redirect_to view_context.asset_path('apple-touch-icon-57x57.png'), :status => 301
end
end
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

# Icon redirects
get "/favicon.ico", :to => "icon_redirects#show"
get "/apple-touch-icon.png", :to => "icon_redirects#show"
get "/apple-touch-icon.png", :to => "icon_redirects#apple_57_57"
get "/apple-touch-icon-144x144.png", :to => "icon_redirects#show"
get "/apple-touch-icon-114x114.png", :to => "icon_redirects#show"
get "/apple-touch-icon-72x72.png", :to => "icon_redirects#show"
get "/apple-touch-icon-57x57.png", :to => "icon_redirects#show"
get "/apple-touch-icon-precomposed.png", :to => "icon_redirects#show"
get "/apple-touch-icon-precomposed.png", :to => "icon_redirects#apple_57_57"
end
26 changes: 24 additions & 2 deletions test/integration/icon_redirects_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,40 @@ class IconRedirectsTest < ActionDispatch::IntegrationTest

[
'favicon.ico',
'apple-touch-icon.png',
'apple-touch-icon-144x144.png',
'apple-touch-icon-114x114.png',
'apple-touch-icon-72x72.png',
'apple-touch-icon-57x57.png',
'apple-touch-icon-precomposed.png',
].each do |file|
should "redirect #{file} to the asset path" do
get "/#{file}"
assert_equal 301, last_response.status
# In development and test mode the asset pipeline doesn't add the hashes to the URLs
assert_equal "http://example.org/static/#{file}", last_response.location
end

should "redirect #{file} to a location that exists" do
get "/static/#{file}"
assert_equal 200, last_response.status
assert last_response.body.size > 100
end

should "ignore query string when redirecting #{file}" do
get "/#{file}?foo=bar"
assert_equal 301, last_response.status
assert_equal "http://example.org/static/#{file}", last_response.location
end
end

[
'apple-touch-icon.png',
'apple-touch-icon-precomposed.png',
].each do |file|
should "redirect #{file} to the 57x57 icon" do
get "/#{file}"
assert_equal 301, last_response.status
# In development and test mode the asset pipeline doesn't add the hashes to the URLs
assert_equal "http://example.org/static/apple-touch-icon-57x57.png", last_response.location
end
end
end

0 comments on commit 89ac064

Please sign in to comment.