From 82fe467f824bc028d9cfe2950a0197f93ffa0d9d Mon Sep 17 00:00:00 2001 From: Ian White Date: Sat, 31 Jul 2010 20:14:12 +0100 Subject: [PATCH] email links now visit the url, rather than just the path, this allows for features that make use of the domain to function correctly --- History.txt | 4 +++- lib/pickle/email.rb | 12 +++++------- spec/pickle/email_spec.rb | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/History.txt b/History.txt index 9cd2814b..1d5c021c 100644 --- a/History.txt +++ b/History.txt @@ -1,7 +1,9 @@ == master -* 1 minor improvement +* 2 minor improvements * Document how to use machinist named blueprints [Christopher Darroch] + * Email links now visit the url, rather than just the path, this allows for features that + make use of the domain to function correctly == 0.3.1 diff --git a/lib/pickle/email.rb b/lib/pickle/email.rb index ec30f07f..7fbadf2a 100644 --- a/lib/pickle/email.rb +++ b/lib/pickle/email.rb @@ -25,8 +25,7 @@ def visit_in_email(email, link_text) def click_first_link_in_email(email) link = links_in_email(email).first - request_uri = URI::parse(link).request_uri - visit request_uri + visit link end protected @@ -60,15 +59,14 @@ def parse_email_for_link(email, text_or_regex) # e.g. confirm in http://confirm def parse_email_for_explicit_link(email, regex) regex = /#{Regexp.escape(regex)}/ unless regex.is_a?(Regexp) - url = links_in_email(email).detect { |link| link =~ regex } - URI::parse(url).request_uri if url + links_in_email(email).detect { |link| link =~ regex } end # e.g. Click here in Click here def parse_email_for_anchor_text_link(email, link_text) - email.body =~ %r{]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?} - URI.split($~[1])[5..-1].compact!.join("?").gsub("&", "&") - # sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002) + if match_data = email.body.match(%r{]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?}) + match_data[1] + end end def links_in_email(email, protos=['http', 'https']) diff --git a/spec/pickle/email_spec.rb b/spec/pickle/email_spec.rb index ae60c8be..63e4407a 100644 --- a/spec/pickle/email_spec.rb +++ b/spec/pickle/email_spec.rb @@ -143,17 +143,17 @@ end it "should find a link for http://example.com/page" do - should_receive(:visit).with('/page') + should_receive(:visit).with('http://example.com/page') visit_in_email(@email1, 'http://example.com/page') end it "should find a link for \"example page\"" do - should_receive(:visit).with('/page') + should_receive(:visit).with('http://example.com/page') visit_in_email(@email1, 'example page') end it "should follow the first link in an email" do - should_receive(:visit).with('/page') + should_receive(:visit).with('http://example.com/page') click_first_link_in_email(@email1) end end