Created
August 17, 2010 21:50
-
-
Save dsingleton/532242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using standard lib methods | |
assert redirect? "not redirected" | |
query_hash = CGI.parse(URI.parse(redirected_to).query) | |
assert query_hash.fetch(query_param, false), "'#{query_param}' param is not set, or has an empty value" | |
url = URI.parse(url) | |
params = CGI.parse(url.query || '') | |
params[query_param] = query_hash[query_param] | |
url.query = params.map{|k,v| "#{CGI::escape(k)}=#{CGI::escape(v.first)}"}.join('&') | |
assert url.to_s == redirected_to, "redirection URL is incorrect" | |
# Or, a slightly shitty regex | |
assert redirect?, "not redirected" | |
assert_false "No token in query" unless redirected_to.gsub!(/(?:&|\?)token=.*/, '') | |
assert_equal redirected_to, url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment