Skip to content

Commit

Permalink
email links now visit the url, rather than just the path, this allows…
Browse files Browse the repository at this point in the history
… for features that

    make use of the domain to function correctly
  • Loading branch information
ianwhite committed Aug 2, 2010
1 parent 0f30ec9 commit 82fe467
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 3 additions & 1 deletion 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
Expand Down
12 changes: 5 additions & 7 deletions lib/pickle/email.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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 <a href="http://confirm">Click here</a>
def parse_email_for_anchor_text_link(email, link_text)
email.body =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
URI.split($~[1])[5..-1].compact!.join("?").gsub("&amp;", "&")
# sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
if match_data = email.body.match(%r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>})
match_data[1]
end
end

def links_in_email(email, protos=['http', 'https'])
Expand Down
6 changes: 3 additions & 3 deletions spec/pickle/email_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 82fe467

Please sign in to comment.