From 2fae37f0acbb4154fe75c22a892f79e158016866 Mon Sep 17 00:00:00 2001 From: Sammy Larbi Date: Sat, 30 Aug 2014 17:19:16 -0500 Subject: Allow polymorphic routes with nil when a route can still be drawn Suppose you have two resources routed in the following manner: ```ruby resources :blogs do resources :posts end resources :posts ``` When using polymorphic resource routing like `url_for([@blog, @post])`, and `@blog` is `nil` Rails should still try to match the route to the top-level posts resource. Fixes #16754 --- .../test/activerecord/polymorphic_routes_test.rb | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'actionview/test') diff --git a/actionview/test/activerecord/polymorphic_routes_test.rb b/actionview/test/activerecord/polymorphic_routes_test.rb index 0d97ddb2f6..a259c359f0 100644 --- a/actionview/test/activerecord/polymorphic_routes_test.rb +++ b/actionview/test/activerecord/polymorphic_routes_test.rb @@ -183,16 +183,33 @@ class PolymorphicRoutesTest < ActionController::TestCase end end - def test_with_nil_in_list + def test_with_entirely_nil_list with_test_routes do exception = assert_raise ArgumentError do @series.save - polymorphic_url([nil, @series]) + polymorphic_url([nil, nil]) end assert_equal "Nil location provided. Can't build URI.", exception.message end end + def test_with_nil_in_list_for_resource_that_could_be_top_level_or_nested + with_top_level_and_nested_routes do + @blog_post.save + assert_equal "http://example.com/posts/#{@blog_post.id}", polymorphic_url([nil, @blog_post]) + end + end + + def test_with_nil_in_list_does_not_generate_invalid_link + with_top_level_and_nested_routes do + exception = assert_raise NoMethodError do + @series.save + polymorphic_url([nil, @series]) + end + assert_match /undefined method `series_url' for/, exception.message + end + end + def test_with_record with_test_routes do @project.save @@ -626,6 +643,21 @@ class PolymorphicRoutesTest < ActionController::TestCase end end + def with_top_level_and_nested_routes(options = {}) + with_routing do |set| + set.draw do + resources :blogs do + resources :posts + resources :series + end + resources :posts + end + + extend @routes.url_helpers + yield + end + end + def with_admin_test_routes(options = {}) with_routing do |set| set.draw do -- cgit v1.2.3 From 5c057f925516e87b2bcd6701fab42c1454652cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 1 Sep 2014 22:20:39 -0300 Subject: Remove warning --- actionview/test/activerecord/polymorphic_routes_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionview/test') diff --git a/actionview/test/activerecord/polymorphic_routes_test.rb b/actionview/test/activerecord/polymorphic_routes_test.rb index a259c359f0..4e94304796 100644 --- a/actionview/test/activerecord/polymorphic_routes_test.rb +++ b/actionview/test/activerecord/polymorphic_routes_test.rb @@ -199,14 +199,14 @@ class PolymorphicRoutesTest < ActionController::TestCase assert_equal "http://example.com/posts/#{@blog_post.id}", polymorphic_url([nil, @blog_post]) end end - + def test_with_nil_in_list_does_not_generate_invalid_link with_top_level_and_nested_routes do exception = assert_raise NoMethodError do @series.save polymorphic_url([nil, @series]) end - assert_match /undefined method `series_url' for/, exception.message + assert_match(/undefined method `series_url' for/, exception.message) end end -- cgit v1.2.3 From 2f52f969885b2834198de0045748436a4651a94e Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Tue, 2 Sep 2014 23:48:23 +0930 Subject: Leave all our tests as order_dependent! for now We're seeing too many failures to believe otherwise. This reverts commits bc116a55ca3dd9f63a1f1ca7ade3623885adcc57, cbde413df3839e06dd14e3c220e9800af91e83ab, bf0a67931dd8e58f6f878b9510ae818ae1f29a3a, and 2440933fe2c27b27bcafcd9019717800db2641aa. --- actionview/test/abstract_unit.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionview/test') diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index d60712255b..923e637f11 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -340,3 +340,8 @@ def jruby_skip(message = '') end require 'mocha/setup' # FIXME: stop using mocha + +# FIXME: we have tests that depend on run order, we should fix that and +# remove this method call. +require 'active_support/test_case' +ActiveSupport::TestCase.my_tests_are_order_dependent! -- cgit v1.2.3 From 28eecd934b91618b1334acce859c26c1a380f51a Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 2 Sep 2014 21:07:41 +0200 Subject: Ship with rails-html-sanitizer instead. --- actionview/test/template/sanitize_helper_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview/test') diff --git a/actionview/test/template/sanitize_helper_test.rb b/actionview/test/template/sanitize_helper_test.rb index a27258a870..e4be21be2c 100644 --- a/actionview/test/template/sanitize_helper_test.rb +++ b/actionview/test/template/sanitize_helper_test.rb @@ -18,7 +18,7 @@ class SanitizeHelperTest < ActionView::TestCase def test_should_sanitize_illegal_style_properties raw = %(display:block; position:absolute; left:0; top:0; width:100%; height:100%; z-index:1; background-color:black; background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg); background-x:center; background-y:center; background-repeat:repeat;) - expected = %(display: block; width: 100%; height: 100%; background-color: black; background-image: ; background-x: center; background-y: center;) + expected = %(display: block; width: 100%; height: 100%; background-color: black; background-x: center; background-y: center;) assert_equal expected, sanitize_css(raw) end -- cgit v1.2.3 From ee61b76a810ad67ca064be2922a8b481fa840043 Mon Sep 17 00:00:00 2001 From: PaoMar Date: Wed, 3 Sep 2014 15:03:58 -0500 Subject: Add support for ARIA attributes in tags --- actionview/test/template/tag_helper_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'actionview/test') diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb index 0ea669b3d0..ce89d5728e 100644 --- a/actionview/test/template/tag_helper_test.rb +++ b/actionview/test/template/tag_helper_test.rb @@ -156,4 +156,11 @@ class TagHelperTest < ActionView::TestCase tag('a', { data => { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: 'hello', symbol: :foo, array: [1, 2, 3], hash: { key: 'value'}, string_with_quotes: 'double"quote"party"' } }) } end + + def test_aria_attributes + ['aria', :aria].each { |aria| + assert_dom_equal '', + tag('a', { aria => { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: 'hello', symbol: :foo, array: [1, 2, 3], hash: { key: 'value'}, string_with_quotes: 'double"quote"party"' } }) + } + end end -- cgit v1.2.3 From ab2ace6bbef1cc98c98e5a9a6b45e734bc5edd9d Mon Sep 17 00:00:00 2001 From: Rajarshi Das Date: Sat, 6 Sep 2014 11:49:39 +0530 Subject: fix the undefined method content_tag #15245 not required include ActionView::Helpers::TagHelper in test as well --- actionview/test/template/translation_helper_test.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'actionview/test') diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb index 41f6770f23..362f05ea70 100644 --- a/actionview/test/template/translation_helper_test.rb +++ b/actionview/test/template/translation_helper_test.rb @@ -1,7 +1,6 @@ require 'abstract_unit' class TranslationHelperTest < ActiveSupport::TestCase - include ActionView::Helpers::TagHelper include ActionView::Helpers::TranslationHelper attr_reader :request, :view -- cgit v1.2.3 From 2b41343c34bcbe809537590152506690b84832df Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Mon, 8 Sep 2014 05:32:16 -0700 Subject: Default to sorting user's test cases for now Goals: 1. Default to :random for newly generated applications 2. Default to :sorted for existing applications with a warning 3. Only show the warning once 4. Only show the warning if the app actually uses AS::TestCase Fixes #16769 --- actionview/test/abstract_unit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview/test') diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index 923e637f11..e51461d82c 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -344,4 +344,4 @@ require 'mocha/setup' # FIXME: stop using mocha # FIXME: we have tests that depend on run order, we should fix that and # remove this method call. require 'active_support/test_case' -ActiveSupport::TestCase.my_tests_are_order_dependent! +ActiveSupport::TestCase.test_order = :sorted -- cgit v1.2.3 From fb110381481fe79fa2921d08a60d343d3ea2b363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 8 Sep 2014 18:03:17 -0300 Subject: Do not memoize document_root_element in view tests Memoizing will not make possible to assert the output of the view if it is changed after the first assert_select call Related with plataformatec/simple_form#1130 and rails/rails-dom-testing#15 --- actionview/test/template/test_case_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionview/test') diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index 4582fa13ee..5697ffa317 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -293,6 +293,17 @@ module ActionView assert_select 'li', :text => 'foo' end end + + test "do not memoize the document_root_element in view tests" do + concat form_tag('/foo') + + assert_select 'form' + + concat content_tag(:b, 'Strong', class: 'foo') + + assert_select 'form' + assert_select 'b.foo' + end end class RenderTemplateTest < ActionView::TestCase -- cgit v1.2.3