mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added rails-dom-testing and rails-html-sanitizer to Gemfile. Added tests for assert_select_email.
This commit is contained in:
parent
fa916af696
commit
94ca27b190
2 changed files with 65 additions and 0 deletions
2
Gemfile
2
Gemfile
|
@ -15,6 +15,8 @@ gem 'jquery-rails', '~> 3.1.0'
|
|||
gem 'turbolinks'
|
||||
gem 'coffee-rails', '~> 4.0.0'
|
||||
gem 'arel', github: 'rails/arel', branch: 'master'
|
||||
gem 'rails-dom-testing', github: 'kaspth/rails-dom-testing'
|
||||
gem 'rails-html-sanitizer', github: 'rafaelfranca/rails-html-sanitizer'
|
||||
gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master'
|
||||
gem 'i18n', github: 'svenfuchs/i18n', branch: 'master'
|
||||
|
||||
|
|
63
actionmailer/test/assert_select_email_test.rb
Normal file
63
actionmailer/test/assert_select_email_test.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require 'abstract_unit'
|
||||
require 'rails-dom-testing'
|
||||
|
||||
class AssertSelectEmailTest < ActionMailer::TestCase
|
||||
Assertion = ActiveSupport::TestCase::Assertion
|
||||
|
||||
include Rails::Dom::Testing::Assertions::SelectorAssertions
|
||||
|
||||
class AssertSelectMailer < ActionMailer::Base
|
||||
def test(html)
|
||||
mail :body => html, :content_type => "text/html",
|
||||
:subject => "Test e-mail", :from => "test@test.host", :to => "test <test@test.host>"
|
||||
end
|
||||
end
|
||||
|
||||
class AssertMultipartSelectMailer < ActionMailer::Base
|
||||
def test(options)
|
||||
mail :subject => "Test e-mail", :from => "test@test.host", :to => "test <test@test.host>" do |format|
|
||||
format.text { render :text => options[:text] }
|
||||
format.html { render :text => options[:html] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Test assert_select_email
|
||||
#
|
||||
|
||||
def setup
|
||||
@response = FakeResponse.new(:html, 'some body text')
|
||||
end
|
||||
|
||||
def test_assert_select_email
|
||||
assert_raise(Assertion) { assert_select_email {} }
|
||||
AssertSelectMailer.test("<div><p>foo</p><p>bar</p></div>").deliver
|
||||
assert_select_email do
|
||||
assert_select "div:root" do
|
||||
assert_select "p:first-child", "foo"
|
||||
assert_select "p:last-child", "bar"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_select_email_multipart
|
||||
AssertMultipartSelectMailer.test(:html => "<div><p>foo</p><p>bar</p></div>", :text => 'foo bar').deliver
|
||||
assert_select_email do
|
||||
assert_select "div:root" do
|
||||
assert_select "p:first-child", "foo"
|
||||
assert_select "p:last-child", "bar"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
class FakeResponse
|
||||
attr_accessor :content_type, :body
|
||||
|
||||
def initialize(content_type, body)
|
||||
@content_type, @body = content_type, body
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue