Skip to content

Commit

Permalink
Resolve email link extraction issue
Browse files Browse the repository at this point in the history
In emails that had links who's href values were surrounded by
single-quotes the URI.extract method does not work. It will leave a
trailing single quote if there are any paths on the the matched URI.
  • Loading branch information
bcardarella committed Dec 27, 2011
1 parent 1d514c0 commit 3aa83a2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gem "rack-test"
gem "mail"
gem 'rails', '3.0.0.rc'
gem 'sqlite3-ruby', :require=>'sqlite3'
gem 'nokogiri'
#gem 'email_spec', :path => '.'
gem 'capybara'
gem 'database_cleaner'
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ begin
s.rubyforge_project = 'email-spec'
s.add_runtime_dependency "mail", "~> 2.2"
s.add_runtime_dependency "rspec", "~> 2.0"
s.add_runtime_dependency "nokogiri"
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
Expand Down
3 changes: 2 additions & 1 deletion lib/email_spec/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'uri'
require 'nokogiri'
require 'email_spec/deliveries'

module EmailSpec
Expand Down Expand Up @@ -69,7 +70,7 @@ def find_email(address, opts={})
end

def links_in_email(email)
URI.extract(email.default_part_body.to_s, ['http', 'https'])
Nokogiri::HTML.parse(email.default_part_body.to_s).css('a').map { |link| link['href'] }
end

private
Expand Down
7 changes: 7 additions & 0 deletions spec/email_spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
end
end

describe '#links_in_email' do
it "properly finds links surrounded by single quotes" do
email = Mail.new(:body => %{<a href='http://www.example.com/test'>Click Here</a>})
links_in_email(email).should include %{http://www.example.com/test}
end
end

describe "#set_current_email" do
it "should cope with a nil email" do
lambda do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def with_inspect_stub(str = "email")

RSpec.configure do |config|
config.mock_with :rspec
end
end

0 comments on commit 3aa83a2

Please sign in to comment.