]> git.openstreetmap.org Git - rails.git/blob - test/integration/short_links_test.rb
Merge remote-tracking branch 'upstream/pull/3125'
[rails.git] / test / integration / short_links_test.rb
1 require "test_helper"
2
3 class ShortLinksTest < ActionDispatch::IntegrationTest
4   ##
5   # test the short link with various parameters and ensure they're
6   # kept in the redirect.
7   def test_short_link_params
8     assert_short_link_redirect("1N8H@P_5W")
9     assert_short_link_redirect(ShortLink.encode(-0.107846, 51.50771, 18))
10   end
11
12   private
13
14   ##
15   # utility method to test short links
16   def assert_short_link_redirect(short_link)
17     lon, lat, zoom = ShortLink.decode(short_link)
18     anchor = "map=#{zoom}/#{lat}/#{lon}"
19
20     # test without marker
21     get "/go/#{short_link}"
22     assert_redirected_to :controller => "site", :action => "index", :anchor => anchor
23
24     # test with marker
25     get "/go/#{short_link}?m"
26     assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => anchor
27
28     # test with layers and a marker
29     get "/go/#{short_link}?m&layers=B000FTF"
30     assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => "#{anchor}&layers=B000FTF"
31     get "/go/#{short_link}?layers=B000FTF&m"
32     assert_redirected_to :controller => "site", :action => "index", :mlat => lat.to_s, :mlon => lon.to_s, :anchor => "#{anchor}&layers=B000FTF"
33
34     # test with some random query parameters we haven't even implemented yet
35     get "/go/#{short_link}?foobar=yes"
36     assert_redirected_to :controller => "site", :action => "index", :foobar => "yes", :anchor => anchor
37   end
38 end