Skip to content

Commit

Permalink
Merge pull request email-spec#86 from bcardarella/master
Browse files Browse the repository at this point in the history
Resolve href surrounded by single quote issue
  • Loading branch information
bmabey committed Dec 28, 2011
2 parents 1d514c0 + 3aa83a2 commit 7283719
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
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
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
@@ -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
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
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 7283719

Please sign in to comment.