Permalink
Browse files

Merge branch 'loofah'

Conflicts:
	Gemfile
  • Loading branch information...
2 parents cc9091c + c78da4d commit cdc00aba62ffb0f0af452f5152aafeb5e490962e Rafael Mendonça França committed Aug 18, 2014
Showing with 281 additions and 4,739 deletions.
  1. +3 −0 Gemfile
  2. +1 −0 actionmailer/actionmailer.gemspec
  3. +4 −3 actionmailer/lib/action_mailer/test_case.rb
  4. +1 −1 actionmailer/test/abstract_unit.rb
  5. +47 −0 actionmailer/test/assert_select_email_test.rb
  6. +4 −0 actionpack/CHANGELOG.md
  7. +1 −0 actionpack/actionpack.gemspec
  8. +8 −0 actionpack/lib/action_controller/test_case.rb
  9. +11 −7 actionpack/lib/action_dispatch/testing/assertions.rb
  10. +2 −26 actionpack/lib/action_dispatch/testing/assertions/dom.rb
  11. +2 −429 actionpack/lib/action_dispatch/testing/assertions/selector.rb
  12. +0 −135 actionpack/lib/action_dispatch/testing/assertions/tag.rb
  13. +4 −0 actionpack/lib/action_dispatch/testing/integration.rb
  14. +0 −6 actionpack/test/controller/action_pack_assertions_test.rb
  15. +0 −356 actionpack/test/controller/assert_select_test.rb
  16. +3 −4 actionpack/test/controller/integration_test.rb
  17. +2 −1 actionpack/test/controller/request_forgery_protection_test.rb
  18. +0 −629 actionpack/test/controller/selector_test.rb
  19. +0 −179 actionpack/test/controller/test_case_test.rb
  20. +1 −0 actionview/actionview.gemspec
  21. +0 −1 actionview/lib/action_view.rb
  22. +64 −106 actionview/lib/action_view/helpers/sanitize_helper.rb
  23. +11 −6 actionview/lib/action_view/test_case.rb
  24. +0 −20 actionview/lib/action_view/vendor/html-scanner.rb
  25. +0 −68 actionview/lib/action_view/vendor/html-scanner/html/document.rb
  26. +0 −532 actionview/lib/action_view/vendor/html-scanner/html/node.rb
  27. +0 −188 actionview/lib/action_view/vendor/html-scanner/html/sanitizer.rb
  28. +0 −830 actionview/lib/action_view/vendor/html-scanner/html/selector.rb
  29. +0 −107 actionview/lib/action_view/vendor/html-scanner/html/tokenizer.rb
  30. +0 −11 actionview/lib/action_view/vendor/html-scanner/html/version.rb
  31. +5 −5 actionview/test/template/atom_feed_helper_test.rb
  32. +15 −14 actionview/test/template/date_helper_test.rb
  33. +44 −44 actionview/test/template/form_collections_helper_test.rb
  34. +1 −1 actionview/test/template/form_tag_helper_test.rb
  35. +0 −15 actionview/test/template/html-scanner/cdata_node_test.rb
  36. +0 −148 actionview/test/template/html-scanner/document_test.rb
  37. +0 −89 actionview/test/template/html-scanner/node_test.rb
  38. +0 −330 actionview/test/template/html-scanner/sanitizer_test.rb
  39. +0 −243 actionview/test/template/html-scanner/tag_node_test.rb
  40. +0 −50 actionview/test/template/html-scanner/text_node_test.rb
  41. +0 −131 actionview/test/template/html-scanner/tokenizer_test.rb
  42. +3 −19 actionview/test/template/sanitize_helper_test.rb
  43. +2 −0 actionview/test/template/text_helper_test.rb
  44. +1 −1 actionview/test/template/url_helper_test.rb
  45. +4 −4 guides/source/testing.md
  46. +32 −0 guides/source/upgrading_ruby_on_rails.md
  47. +5 −0 railties/lib/rails/generators/rails/app/templates/Gemfile
View
@@ -12,6 +12,9 @@ gem 'rack-cache', '~> 1.2'
gem 'jquery-rails', '~> 3.1.0'
gem 'turbolinks', github: 'rails/turbolinks', branch: 'master'
gem 'coffee-rails', '~> 4.0.0'
+gem 'rails-html-sanitizer', github: 'rails/rails-html-sanitizer'
+#temporary gem until a new version of loofah is released
+gem 'loofah', github: 'kaspth/loofah', branch: 'single-scrub'
gem 'sprockets-rails', github: 'rails/sprockets-rails', branch: 'master'
gem 'i18n', github: 'svenfuchs/i18n', branch: 'master'
@@ -23,4 +23,5 @@ Gem::Specification.new do |s|
s.add_dependency 'actionview', version
s.add_dependency 'mail', ['~> 2.5', '>= 2.5.4']
+ s.add_dependency 'rails-dom-testing'
end
@@ -1,4 +1,5 @@
require 'active_support/test_case'
+require 'rails-dom-testing'
module ActionMailer
class NonInferrableMailerError < ::StandardError
@@ -15,6 +16,7 @@ module Behavior
include ActiveSupport::Testing::ConstantLookup
include TestHelper
+ include Rails::Dom::Testing::Assertions::SelectorAssertions
included do
class_attribute :_mailer_class
@@ -55,14 +57,13 @@ def determine_default_mailer(name)
protected
def initialize_test_deliveries
- @old_delivery_method = ActionMailer::Base.delivery_method
+ set_delivery_method :test
@old_perform_deliveries = ActionMailer::Base.perform_deliveries
- ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
end
def restore_test_deliveries
- ActionMailer::Base.delivery_method = @old_delivery_method
+ restore_delivery_method
ActionMailer::Base.perform_deliveries = @old_perform_deliveries
ActionMailer::Base.deliveries.clear
end
@@ -26,7 +26,7 @@
FIXTURE_LOAD_PATH = File.expand_path('fixtures', File.dirname(__FILE__))
ActionMailer::Base.view_paths = FIXTURE_LOAD_PATH
-class Rails
+module Rails
def self.root
File.expand_path('../', File.dirname(__FILE__))
end
@@ -0,0 +1,47 @@
+require 'abstract_unit'
+
+class AssertSelectEmailTest < ActionMailer::TestCase
+ 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 test_assert_select_email
+ assert_raise ActiveSupport::TestCase::Assertion do
+ assert_select_email {}
+ end
+
+ 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
+end
View
@@ -1,3 +1,7 @@
+* Deleted the deprecated TagAssertions.
+
+ *Kasper Timm Hansen*
+
* Use the Active Support JSON encoder for cookie jars using the `:json` or
`:hybrid` serializer. This allows you to serialize custom Ruby objects into
cookies by defining the `#as_json` hook on such objects.
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
s.add_dependency 'rack', '~> 1.6.0.alpha'
s.add_dependency 'rack-test', '~> 0.6.2'
+ s.add_dependency 'rails-deprecated_sanitizer'
s.add_dependency 'actionview', version
s.add_development_dependency 'activemodel', version
@@ -3,6 +3,8 @@
require 'active_support/core_ext/module/anonymous'
require 'active_support/core_ext/hash/keys'
+require 'rails-dom-testing'
+
module ActionController
module TemplateAssertions
extend ActiveSupport::Concern
@@ -442,6 +444,7 @@ module Behavior
extend ActiveSupport::Concern
include ActionDispatch::TestProcess
include ActiveSupport::Testing::ConstantLookup
+ include Rails::Dom::Testing::Assertions
attr_reader :response, :request
@@ -684,6 +687,11 @@ def build_response(klass)
end
private
+
+ def document_root_element
+ html_document.root
+ end
+
def check_required_ivars
# Sanity check for required instance variables so we can give an
# understandable error message.
@@ -1,18 +1,22 @@
+require 'rails-dom-testing'
+
module ActionDispatch
module Assertions
- autoload :DomAssertions, 'action_dispatch/testing/assertions/dom'
autoload :ResponseAssertions, 'action_dispatch/testing/assertions/response'
autoload :RoutingAssertions, 'action_dispatch/testing/assertions/routing'
- autoload :SelectorAssertions, 'action_dispatch/testing/assertions/selector'
- autoload :TagAssertions, 'action_dispatch/testing/assertions/tag'
extend ActiveSupport::Concern
- include DomAssertions
include ResponseAssertions
include RoutingAssertions
- include SelectorAssertions
- include TagAssertions
+ include Rails::Dom::Testing::Assertions
+
+ def html_document
+ @html_document ||= if @response.content_type =~ /xml$/
+ Nokogiri::XML::Document.parse(@response.body)
+ else
+ Nokogiri::HTML::Document.parse(@response.body)
+ end
+ end
end
end
-
@@ -1,27 +1,3 @@
-require 'action_view/vendor/html-scanner'
+require 'active_support/deprecation'
-module ActionDispatch
- module Assertions
- module DomAssertions
- # \Test two HTML strings for equivalency (e.g., identical up to reordering of attributes)
- #
- # # assert that the referenced method generates the appropriate HTML string
- # assert_dom_equal '<a href="http://www.example.com">Apples</a>', link_to("Apples", "http://www.example.com")
- def assert_dom_equal(expected, actual, message = nil)
- expected_dom = HTML::Document.new(expected).root
- actual_dom = HTML::Document.new(actual).root
- assert_equal expected_dom, actual_dom, message
- end
-
- # The negated form of +assert_dom_equivalent+.
- #
- # # assert that the referenced method does not generate the specified HTML string
- # assert_dom_not_equal '<a href="http://www.example.com">Apples</a>', link_to("Oranges", "http://www.example.com")
- def assert_dom_not_equal(expected, actual, message = nil)
- expected_dom = HTML::Document.new(expected).root
- actual_dom = HTML::Document.new(actual).root
- assert_not_equal expected_dom, actual_dom, message
- end
- end
- end
-end
+ActiveSupport::Deprecation.warn("ActionDispatch::Assertions::DomAssertions has been extracted to the rails-dom-testing gem.")
Oops, something went wrong.

0 comments on commit cdc00ab

Please sign in to comment.