Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

clicking links in emails not working properly #108

gucki opened this Issue Jul 4, 2012 · 6 comments


None yet
6 participants

gucki commented Jul 4, 2012

Is there any special reason why not navigating to the "raw" url but wrapping it in request_uri instead? This is causing troubles when trying to follow absolte urls (with domain and/ or port).

    def click_email_link_matching(regex, email = current_email)
      url = links_in_email(email).detect { |link| link =~ regex }
      raise "No link found matching #{regex.inspect} in #{email.default_part_body}" unless url
      visit request_uri(url)

    def click_first_link_in_email(email = current_email)
      link = links_in_email(email).first
      visit request_uri(link)

bmabey commented Jul 5, 2012

I think the original reason was due to some initial limitations of webrat. I have pull request #46 that allows for using the absolute URL but I haven't looked at it in a bit.. If you can verify that the patch in #46 fixes your problem then I'd feel better about merging it in.

gucki commented Aug 14, 2012

I'd really prefer if we could check is this "hack" is still needed. As far as I can tell I never had any problems with any valid url I passed to visit. Can we give it a try?

glebm commented Oct 31, 2012

email_spec at the moment breaks subdomain routing

My fix is this

# Working around issue here: https://github.com/bmabey/email-spec/issues/108
def request_uri(link)
  link && URI::parse(link)

def parse_email_for_anchor_text_link(email, link_text)
  if textify_images(email.default_part_body) =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
    CGI::unescape_html $1

Papipo commented Feb 18, 2013

It's not just subdomains. I am using capybara and custom domains (full domains, not just subdomains), and email_spec uses relative paths, so I can't hit specific domains from emails.

vidaica commented Apr 12, 2013

links_in_email seems not to function properly. In my case, the returned urls contain an extra single quote ( ' ) at the end if the urls in the links are wrapped with single quotes.

janxious commented Feb 9, 2017

It also doesn't seemingly work properly if you anchor tag has anything in it other than an href attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment