Fix referer params for welcome page
authorJohn Firebaugh <john.firebaugh@gmail.com>
Thu, 8 Aug 2013 23:34:10 +0000 (16:34 -0700)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Mon, 12 Aug 2013 20:34:46 +0000 (13:34 -0700)
app/controllers/user_controller.rb
test/functional/user_controller_test.rb

index d89d483f2a72ab5f490a469307cff9daf33accaf..c3cd9fcf22f4cbf994555a00240895ffde9f3b52 100644 (file)
@@ -88,11 +88,18 @@ class UserController < ApplicationController
         if @user.save
           flash[:piwik_goal] = PIWIK_SIGNUP_GOAL if defined?(PIWIK_SIGNUP_GOAL)
 
+          referer = welcome_path
+
           begin
-            referer_params = Rack::Utils.parse_query(URI(session[:referer]).query)
-            referer = welcome_path(referer_params.slice(:lat, :lon, :zoom, :editor))
+            uri = URI(session[:referer])
+            /map=(.*)\/(.*)\/(.*)/.match(uri.fragment) do |m|
+              editor = Rack::Utils.parse_query(uri.query).slice('editor')
+              referer = welcome_path({'zoom' => m[1],
+                                      'lat' => m[2],
+                                      'lon' => m[3]}.merge(editor))
+            end
           rescue
-            referer = welcome_path
+            # Use default
           end
 
           if @user.status == "active"
index c49073e683888d0019da30855c9afd29d79418ec..cb40659a7d6bfe80bb268c3a939607753900b733 100644 (file)
@@ -308,6 +308,16 @@ class UserControllerTest < ActionController::TestCase
     assert_select "form > fieldset > div.form-row > div.field_with_errors > input#user_display_name"
   end
 
+  def test_user_save_referer_params
+    user = new_user
+
+    post :save, {}, {:new_user => user,
+                     :referer => '/edit?editor=id#map=1/2/3'}
+
+    assert_equal welcome_path(:editor => 'id', :zoom => 1, :lat => 2, :lon => 3),
+                 user.tokens.first.referer
+  end
+
   def test_user_confirm_expired_token
     user = users(:inactive_user)
     token = user.tokens.new