aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/test')
-rw-r--r--actionview/test/abstract_unit.rb2
-rw-r--r--actionview/test/actionpack/abstract/abstract_controller_test.rb2
-rw-r--r--actionview/test/actionpack/abstract/layouts_test.rb3
-rw-r--r--actionview/test/actionpack/controller/render_test.rb25
-rw-r--r--actionview/test/active_record_unit.rb10
-rw-r--r--actionview/test/activerecord/form_helper_activerecord_test.rb1
-rw-r--r--actionview/test/lib/test_component.rb45
-rw-r--r--actionview/test/template/compiled_templates_test.rb40
-rw-r--r--actionview/test/template/form_helper_test.rb1
-rw-r--r--actionview/test/template/form_options_helper_test.rb1
-rw-r--r--actionview/test/template/form_tag_helper_test.rb8
-rw-r--r--actionview/test/template/render_test.rb36
-rw-r--r--actionview/test/template/template_error_test.rb16
-rw-r--r--actionview/test/template/testing/fixture_resolver_test.rb22
-rw-r--r--actionview/test/template/translation_helper_test.rb5
-rw-r--r--actionview/test/template/url_helper_test.rb126
-rw-r--r--actionview/test/ujs/public/test/data-remote.js32
17 files changed, 303 insertions, 72 deletions
diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb
index 2c1b277b41..b652f2e6cb 100644
--- a/actionview/test/abstract_unit.rb
+++ b/actionview/test/abstract_unit.rb
@@ -192,6 +192,8 @@ module ActionDispatch
end
class ActiveSupport::TestCase
+ parallelize
+
include ActiveSupport::Testing::MethodCallAssertions
private
diff --git a/actionview/test/actionpack/abstract/abstract_controller_test.rb b/actionview/test/actionpack/abstract/abstract_controller_test.rb
index eecc19d413..2de81596b5 100644
--- a/actionview/test/actionpack/abstract/abstract_controller_test.rb
+++ b/actionview/test/actionpack/abstract/abstract_controller_test.rb
@@ -230,6 +230,7 @@ module AbstractController
class ActionMissingRespondToActionController < AbstractController::Base
# No actions
+
private
def action_missing(action_name)
self.response_body = "success"
@@ -242,7 +243,6 @@ module AbstractController
def fail() self.response_body = "fail" end
private
-
def method_for_action(action_name)
action_name.to_s != "fail" && action_name
end
diff --git a/actionview/test/actionpack/abstract/layouts_test.rb b/actionview/test/actionpack/abstract/layouts_test.rb
index 1146e6f64b..15643c161d 100644
--- a/actionview/test/actionpack/abstract/layouts_test.rb
+++ b/actionview/test/actionpack/abstract/layouts_test.rb
@@ -140,6 +140,7 @@ module AbstractControllerTests
def index
render template: ActionView::Template::Text.new("Hello symbol!")
end
+
private
def hello
"overwrite"
@@ -295,7 +296,7 @@ module AbstractControllerTests
10.times do |x|
controller = WithString.new
controller.define_singleton_method :index do
- render template: ActionView::Template::Text.new("Hello string!"), locals: { :"x#{x}" => :omg }
+ render template: ActionView::Template::Text.new("Hello string!"), locals: { "x#{x}": :omg }
end
controller.process(:index)
end
diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb
index c8ce7366d1..64070a9542 100644
--- a/actionview/test/actionpack/controller/render_test.rb
+++ b/actionview/test/actionpack/controller/render_test.rb
@@ -607,7 +607,6 @@ class TestController < ActionController::Base
end
private
-
def set_variable_for_layout
@variable_for_layout = nil
end
@@ -1003,14 +1002,14 @@ class RenderTest < ActionController::TestCase
def test_render_xml
get :render_xml_hello
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
- assert_equal "application/xml", @response.content_type
+ assert_equal "application/xml", @response.media_type
end
# :ported:
def test_render_xml_as_string_template
get :render_xml_hello_as_string_template
assert_equal "<html>\n <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
- assert_equal "application/xml", @response.content_type
+ assert_equal "application/xml", @response.media_type
end
# :ported:
@@ -1039,7 +1038,7 @@ class RenderTest < ActionController::TestCase
def test_rendered_format_without_format
get :inline_rendered_format_without_format
assert_equal "test", @response.body
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_partials_list
@@ -1077,7 +1076,7 @@ class RenderTest < ActionController::TestCase
def test_accessing_local_assigns_in_inline_template
get :accessing_local_assigns_in_inline_template, params: { local_name: "Local David" }
assert_equal "Goodbye, Local David", @response.body
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_should_implicitly_render_html_template_from_xhr_request
@@ -1264,13 +1263,13 @@ class RenderTest < ActionController::TestCase
def test_partial_only
get :partial_only
assert_equal "only partial", @response.body
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_should_render_html_formatted_partial
get :partial
assert_equal "partial html", @response.body
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_render_html_formatted_partial_even_with_other_mime_time_in_accept
@@ -1279,20 +1278,20 @@ class RenderTest < ActionController::TestCase
get :partial_html_erb
assert_equal "partial.html.erb", @response.body.strip
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_should_render_html_partial_with_formats
get :partial_formats_html
assert_equal "partial html", @response.body
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_render_to_string_partial
get :render_to_string_with_partial
assert_equal "only partial", @controller.instance_variable_get(:@partial_only)
assert_equal "Hello: david", @controller.instance_variable_get(:@partial_with_locals)
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_render_to_string_with_template_and_html_partial
@@ -1300,21 +1299,21 @@ class RenderTest < ActionController::TestCase
assert_equal "**only partial**\n", @controller.instance_variable_get(:@text)
assert_equal "<strong>only partial</strong>\n", @controller.instance_variable_get(:@html)
assert_equal "<strong>only html partial</strong>\n", @response.body
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_render_to_string_and_render_with_different_formats
get :render_to_string_and_render_with_different_formats
assert_equal "<strong>only partial</strong>\n", @controller.instance_variable_get(:@html)
assert_equal "**only partial**\n", @response.body
- assert_equal "text/plain", @response.content_type
+ assert_equal "text/plain", @response.media_type
end
def test_render_template_within_a_template_with_other_format
get :render_template_within_a_template_with_other_format
expected = "only html partial<p>This is grand!</p>"
assert_equal expected, @response.body.strip
- assert_equal "text/html", @response.content_type
+ assert_equal "text/html", @response.media_type
end
def test_partial_with_counter
diff --git a/actionview/test/active_record_unit.rb b/actionview/test/active_record_unit.rb
index e4ea6a426d..4efb31a360 100644
--- a/actionview/test/active_record_unit.rb
+++ b/actionview/test/active_record_unit.rb
@@ -42,6 +42,12 @@ class ActiveRecordTestConnector
self.able_to_connect = false
end
+ def reconnect
+ return unless able_to_connect
+ ActiveRecord::Base.connection.reconnect!
+ load_schema
+ end
+
private
def setup_connection
if Object.const_defined?(:ActiveRecord)
@@ -102,3 +108,7 @@ class ActiveRecordTestCase < ActionController::TestCase
end
ActiveRecordTestConnector.setup
+
+ActiveSupport::Testing::Parallelization.after_fork_hook do
+ ActiveRecordTestConnector.reconnect
+end
diff --git a/actionview/test/activerecord/form_helper_activerecord_test.rb b/actionview/test/activerecord/form_helper_activerecord_test.rb
index 34655bfe23..1b196ade6d 100644
--- a/actionview/test/activerecord/form_helper_activerecord_test.rb
+++ b/actionview/test/activerecord/form_helper_activerecord_test.rb
@@ -58,7 +58,6 @@ class FormHelperActiveRecordTest < ActionView::TestCase
end
private
-
def hidden_fields(method = nil)
txt = +%{<input name="utf8" type="hidden" value="&#x2713;" />}
diff --git a/actionview/test/lib/test_component.rb b/actionview/test/lib/test_component.rb
new file mode 100644
index 0000000000..0d45d6e25f
--- /dev/null
+++ b/actionview/test/lib/test_component.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+class TestComponent < ActionView::Base
+ include ActiveModel::Validations
+
+ validates :content, :title, presence: true
+ delegate :render, to: :view_context
+
+ def initialize(title:)
+ @title = title
+ end
+
+ # Entrypoint for rendering. Called by ActionView::RenderingHelper#render.
+ #
+ # Returns ActionView::OutputBuffer.
+ def render_in(view_context, &block)
+ self.class.compile
+ @view_context = view_context
+ @content = view_context.capture(&block) if block_given?
+ validate!
+ rendered_template
+ end
+
+ def self.template
+ <<~'erb'
+ <span title="<%= title %>"><%= content %> (<%= render(plain: "Inline render") %>)</span>
+ erb
+ end
+
+ def self.compile
+ @compiled ||= nil
+ return if @compiled
+
+ class_eval(
+ "def rendered_template; @output_buffer = ActionView::OutputBuffer.new; " +
+ ActionView::Template::Handlers::ERB.erb_implementation.new(template, trim: true).src +
+ "; end"
+ )
+
+ @compiled = true
+ end
+
+private
+ attr_reader :content, :title, :view_context
+end
diff --git a/actionview/test/template/compiled_templates_test.rb b/actionview/test/template/compiled_templates_test.rb
index d7f2e8ee07..59fa058bed 100644
--- a/actionview/test/template/compiled_templates_test.rb
+++ b/actionview/test/template/compiled_templates_test.rb
@@ -60,46 +60,8 @@ class CompiledTemplatesTest < ActiveSupport::TestCase
assert_equal "two", render(template: "test/render_file_with_locals_and_default", locals: { secret: "two" })
end
- def test_template_changes_are_not_reflected_with_cached_templates
- assert_equal "Hello world!", render(template: "test/hello_world")
- modify_template "test/hello_world.erb", "Goodbye world!" do
- assert_equal "Hello world!", render(template: "test/hello_world")
- end
- assert_equal "Hello world!", render(template: "test/hello_world")
- end
-
- def test_template_changes_are_reflected_with_uncached_templates
- assert_equal "Hello world!", render_without_cache(template: "test/hello_world")
- modify_template "test/hello_world.erb", "Goodbye world!" do
- assert_equal "Goodbye world!", render_without_cache(template: "test/hello_world")
- end
- assert_equal "Hello world!", render_without_cache(template: "test/hello_world")
- end
-
private
def render(*args)
- render_with_cache(*args)
- end
-
- def render_with_cache(*args)
- view_paths = ActionController::Base.view_paths
- view_class.with_view_paths(view_paths, {}).render(*args)
- end
-
- def render_without_cache(*args)
- path = ActionView::FileSystemResolver.new(FIXTURE_LOAD_PATH)
- view_paths = ActionView::PathSet.new([path])
- view_class.with_view_paths(view_paths, {}).render(*args)
- end
-
- def modify_template(template, content)
- filename = "#{FIXTURE_LOAD_PATH}/#{template}"
- old_content = File.read(filename)
- begin
- File.open(filename, "wb+") { |f| f.write(content) }
- yield
- ensure
- File.open(filename, "wb+") { |f| f.write(old_content) }
- end
+ ActionController::Base.render(*args)
end
end
diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb
index 91052e5ae2..83b089397c 100644
--- a/actionview/test/template/form_helper_test.rb
+++ b/actionview/test/template/form_helper_test.rb
@@ -1897,7 +1897,6 @@ class FormHelperTest < ActionView::TestCase
def test_form_tags_do_not_call_private_properties_on_form_object
obj = Class.new do
private
-
def private_property
raise "This method should not be called."
end
diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb
index c9c36917d6..d7a7b95ab3 100644
--- a/actionview/test/template/form_options_helper_test.rb
+++ b/actionview/test/template/form_options_helper_test.rb
@@ -1472,7 +1472,6 @@ class FormOptionsHelperTest < ActionView::TestCase
end
private
-
def dummy_posts
[ Post.new("<Abe> went home", "<Abe>", "To a little house", "shh!"),
Post.new("Babe went home", "Babe", "To a little house", "shh!"),
diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb
index 9ece9f3ad1..80afed96e5 100644
--- a/actionview/test/template/form_tag_helper_test.rb
+++ b/actionview/test/template/form_tag_helper_test.rb
@@ -301,6 +301,13 @@ class FormTagHelperTest < ActionView::TestCase
assert_dom_equal expected, actual
end
+ def test_select_tag_with_include_blank_doesnt_change_options
+ options = { include_blank: true, prompt: "string" }
+ expected_options = options.dup
+ select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), options
+ expected_options.each { |k, v| assert_equal v, options[k] }
+ end
+
def test_select_tag_with_include_blank_false
actual = select_tag "places", raw("<option>Home</option><option>Work</option><option>Pub</option>"), include_blank: false
expected = %(<select id="places" name="places"><option>Home</option><option>Work</option><option>Pub</option></select>)
@@ -796,7 +803,6 @@ class FormTagHelperTest < ActionView::TestCase
end
private
-
def root_elem(rendered_content)
Nokogiri::HTML::DocumentFragment.parse(rendered_content).children.first # extract from nodeset
end
diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb
index f0b5d7d95e..c82264a170 100644
--- a/actionview/test/template/render_test.rb
+++ b/actionview/test/template/render_test.rb
@@ -2,6 +2,8 @@
require "abstract_unit"
require "controller/fake_models"
+require "test_component"
+require "active_model/validations"
class TestController < ActionController::Base
end
@@ -33,6 +35,11 @@ module RenderTestCases
assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort
end
+ def teardown
+ I18n.reload!
+ ActionController::Base.view_paths.map(&:clear_cache)
+ end
+
def test_implicit_format_comes_from_parent_template
rendered_templates = JSON.parse(@controller_view.render(template: "test/mixing_formats"))
assert_equal({ "format" => "HTML",
@@ -665,6 +672,21 @@ module RenderTestCases
def test_render_throws_exception_when_no_extensions_passed_to_register_template_handler_function_call
assert_raises(ArgumentError) { ActionView::Template.register_template_handler CustomHandler }
end
+
+ def test_render_component
+ assert_equal(
+ %(<span title="my title">Hello, World! (Inline render)</span>),
+ @view.render(TestComponent.new(title: "my title")) { "Hello, World!" }.strip
+ )
+ end
+
+ def test_render_component_with_validation_error
+ error = assert_raises(ActiveModel::ValidationError) do
+ @view.render(TestComponent.new(title: "my title")).strip
+ end
+
+ assert_match "Content can't be blank", error.message
+ end
end
class CachedViewRenderTest < ActiveSupport::TestCase
@@ -677,11 +699,6 @@ class CachedViewRenderTest < ActiveSupport::TestCase
assert_equal ActionView::OptimizedFileSystemResolver, view_paths.first.class
setup_view(view_paths)
end
-
- def teardown
- GC.start
- I18n.reload!
- end
end
class LazyViewRenderTest < ActiveSupport::TestCase
@@ -697,11 +714,6 @@ class LazyViewRenderTest < ActiveSupport::TestCase
setup_view(view_paths)
end
- def teardown
- GC.start
- I18n.reload!
- end
-
def test_render_utf8_template_with_magic_comment
with_external_encoding Encoding::ASCII_8BIT do
result = @view.render(template: "test/utf8_magic", formats: [:html], layouts: "layouts/yield")
@@ -758,10 +770,6 @@ class CachedCollectionViewRenderTest < ActiveSupport::TestCase
setup_view(view_paths)
end
- teardown do
- I18n.reload!
- end
-
test "template body written to cache" do
customer = Customer.new("david", 1)
key = cache_key(customer, "test/_customer")
diff --git a/actionview/test/template/template_error_test.rb b/actionview/test/template/template_error_test.rb
index c4dc88e4aa..643c29602b 100644
--- a/actionview/test/template/template_error_test.rb
+++ b/actionview/test/template/template_error_test.rb
@@ -34,4 +34,20 @@ class TemplateErrorTest < ActiveSupport::TestCase
assert_equal "#<ActionView::Template::Error: original>", error.inspect
end
+
+ def test_annotated_source_code_returns_empty_array_if_source_cant_be_found
+ template = Class.new do
+ def identifier
+ "something"
+ end
+ end.new
+
+ error = begin
+ raise
+ rescue
+ raise ActionView::Template::Error.new(template) rescue $!
+ end
+
+ assert_equal [], error.annotated_source_code
+ end
end
diff --git a/actionview/test/template/testing/fixture_resolver_test.rb b/actionview/test/template/testing/fixture_resolver_test.rb
index 6d0317e0c9..a6066e94c6 100644
--- a/actionview/test/template/testing/fixture_resolver_test.rb
+++ b/actionview/test/template/testing/fixture_resolver_test.rb
@@ -27,4 +27,26 @@ class FixtureResolverTest < ActiveSupport::TestCase
assert_equal :html, templates.first.format
assert_equal "variant", templates.first.variant
end
+
+ def test_should_match_locales
+ resolver = ActionView::FixtureResolver.new("arbitrary/path.erb" => "this text", "arbitrary/path.fr.erb" => "ce texte")
+ en = resolver.find_all("path", "arbitrary", false, locale: [:en], formats: [:html], variants: [], handlers: [:erb])
+ fr = resolver.find_all("path", "arbitrary", false, locale: [:fr], formats: [:html], variants: [], handlers: [:erb])
+
+ assert_equal 1, en.size
+ assert_equal 2, fr.size
+
+ assert_equal "this text", en[0].source
+ assert_equal "ce texte", fr[0].source
+ assert_equal "this text", fr[1].source
+ end
+
+ def test_should_return_all_variants_for_any
+ resolver = ActionView::FixtureResolver.new("arbitrary/path.html.erb" => "this html", "arbitrary/path.html+varient.erb" => "this text")
+ templates = resolver.find_all("path", "arbitrary", false, locale: [], formats: [:html], variants: [], handlers: [:erb])
+ assert_equal 1, templates.size, "expected one template"
+ assert_equal "this html", templates.first.source
+ templates = resolver.find_all("path", "arbitrary", false, locale: [], formats: [:html], variants: :any, handlers: [:erb])
+ assert_equal 2, templates.size, "expected all templates"
+ end
end
diff --git a/actionview/test/template/translation_helper_test.rb b/actionview/test/template/translation_helper_test.rb
index 9afdc3c68f..3475a1dada 100644
--- a/actionview/test/template/translation_helper_test.rb
+++ b/actionview/test/template/translation_helper_test.rb
@@ -121,6 +121,11 @@ class TranslationHelperTest < ActiveSupport::TestCase
I18n.exception_handler = old_exception_handler
end
+ def test_hash_default
+ default = { separator: ".", delimiter: "," }
+ assert_equal default, translate(:'special.number.format', default: default)
+ end
+
def test_translation_returning_an_array
expected = %w(foo bar)
assert_equal expected, translate(:"translations.array")
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb
index 632b32f09f..08413a65c8 100644
--- a/actionview/test/template/url_helper_test.rb
+++ b/actionview/test/template/url_helper_test.rb
@@ -708,6 +708,132 @@ class UrlHelperTest < ActiveSupport::TestCase
assert_equal({ class: "special" }, options)
end
+ def test_sms_to
+ assert_dom_equal %{<a href="sms:15155555785;">15155555785</a>}, sms_to("15155555785")
+ assert_dom_equal %{<a href="sms:15155555785;">Jim Jones</a>}, sms_to("15155555785", "Jim Jones")
+ assert_dom_equal(
+ %{<a class="admin" href="sms:15155555785;">Jim Jones</a>},
+ sms_to("15155555785", "Jim Jones", "class" => "admin")
+ )
+ assert_equal sms_to("15155555785", "Jim Jones", "class" => "admin"),
+ sms_to("15155555785", "Jim Jones", class: "admin")
+ end
+
+ def test_sms_to_with_options
+ assert_dom_equal(
+ %{<a class="simple-class" href="sms:15155555785;?&body=Hello%20from%20Jim">Text me</a>},
+ sms_to("15155555785", "Text me", class: "simple-class", body: "Hello from Jim")
+ )
+
+ assert_dom_equal(
+ %{<a href="sms:15155555785;?&body=This%20is%20the%20body%20of%20the%20message.">Text me</a>},
+ sms_to("15155555785", "Text me", body: "This is the body of the message.")
+ )
+ end
+
+ def test_sms_to_with_img
+ assert_dom_equal %{<a href="sms:15155555785;"><img src="/feedback.png" /></a>},
+ sms_to("15155555785", raw('<img src="/feedback.png" />'))
+ end
+
+ def test_sms_to_with_html_safe_string
+ assert_dom_equal(
+ %{<a href="sms:1%2B5155555785;">1+5155555785</a>},
+ sms_to(raw("1+5155555785"))
+ )
+ end
+
+ def test_sms_to_with_nil
+ assert_dom_equal(
+ %{<a href="sms:;"></a>},
+ sms_to(nil)
+ )
+ end
+
+ def test_sms_to_returns_html_safe_string
+ assert_predicate sms_to("15155555785"), :html_safe?
+ end
+
+ def test_sms_to_with_block
+ assert_dom_equal %{<a href="sms:15155555785;"><span>Text me</span></a>},
+ sms_to("15155555785") { content_tag(:span, "Text me") }
+ end
+
+ def test_sms_to_with_block_and_options
+ assert_dom_equal %{<a class="special" href="sms:15155555785;?&body=Hello%20from%20Jim"><span>Text me</span></a>},
+ sms_to("15155555785", body: "Hello from Jim", class: "special") { content_tag(:span, "Text me") }
+ end
+
+ def test_sms_to_does_not_modify_html_options_hash
+ options = { class: "special" }
+ sms_to "15155555785", "ME!", options
+ assert_equal({ class: "special" }, options)
+ end
+
+ def test_phone_to
+ assert_dom_equal %{<a href="tel:1234567890">1234567890</a>},
+ phone_to("1234567890")
+ assert_dom_equal %{<a href="tel:1234567890">Bob</a>},
+ phone_to("1234567890", "Bob")
+ assert_dom_equal(
+ %{<a class="phoner" href="tel:1234567890">Bob</a>},
+ phone_to("1234567890", "Bob", "class" => "phoner")
+ )
+ assert_equal phone_to("1234567890", "Bob", "class" => "admin"),
+ phone_to("1234567890", "Bob", class: "admin")
+ end
+
+ def test_phone_to_with_options
+ assert_dom_equal(
+ %{<a class="example-class" href="tel:+011234567890">Phone</a>},
+ phone_to("1234567890", "Phone", class: "example-class", country_code: "01")
+ )
+
+ assert_dom_equal(
+ %{<a href="tel:+011234567890">Phone</a>},
+ phone_to("1234567890", "Phone", country_code: "01")
+ )
+ end
+
+ def test_phone_with_img
+ assert_dom_equal %{<a href="tel:1234567890"><img src="/feedback.png" /></a>},
+ phone_to("1234567890", raw('<img src="/feedback.png" />'))
+ end
+
+ def test_phone_with_html_safe_string
+ assert_dom_equal(
+ %{<a href="tel:1%2B234567890">1+234567890</a>},
+ phone_to(raw("1+234567890"))
+ )
+ end
+
+ def test_phone_with_nil
+ assert_dom_equal(
+ %{<a href="tel:"></a>},
+ phone_to(nil)
+ )
+ end
+
+ def test_phone_returns_html_safe_string
+ assert_predicate phone_to("1234567890"), :html_safe?
+ end
+
+ def test_phone_with_block
+ assert_dom_equal %{<a href="tel:1234567890"><span>Phone</span></a>},
+ phone_to("1234567890") { content_tag(:span, "Phone") }
+ end
+
+ def test_phone_with_block_and_options
+ assert_dom_equal %{<a class="special" href="tel:+011234567890"><span>Phone</span></a>},
+ phone_to("1234567890", country_code: "01", class: "special") { content_tag(:span, "Phone") }
+ end
+
+ def test_phone_does_not_modify_html_options_hash
+ options = { class: "special" }
+ phone_to "1234567890", "ME!", options
+ assert_equal({ class: "special" }, options)
+ end
+
def protect_against_forgery?
request_forgery
end
diff --git a/actionview/test/ujs/public/test/data-remote.js b/actionview/test/ujs/public/test/data-remote.js
index 9e41067549..dbbb383995 100644
--- a/actionview/test/ujs/public/test/data-remote.js
+++ b/actionview/test/ujs/public/test/data-remote.js
@@ -82,6 +82,20 @@ asyncTest('right/mouse-wheel-clicking on a link does not fire ajaxyness', 0, fun
setTimeout(function() { start() }, 13)
})
+asyncTest('clicking on a link via a non-mouse Event (such as from js) works', 1, function() {
+ var link = $('a[data-remote]')
+
+ link
+ .removeAttr('data-params')
+ .bindNative('ajax:beforeSend', function() {
+ ok(true, 'ajax should be triggered')
+ })
+
+ Rails.fire(link[0], 'click')
+
+ setTimeout(function() { start() }, 13)
+})
+
asyncTest('ctrl-clicking on a link still fires ajax for non-GET links and for links with "data-params"', 2, function() {
var link = $('a[data-remote]')
@@ -476,4 +490,22 @@ asyncTest('changing a select option without "data-url" attribute still fires aja
setTimeout(function() { start() }, 20)
})
+asyncTest('inputs inside disabled fieldset are not submited on remote forms', 3, function() {
+ $('form')
+ .append('<fieldset>\
+ <input name="description" value="A wise man" />\
+ </fieldset>')
+ .append('<fieldset disabled="disabled">\
+ <input name="age" />\
+ </fieldset>')
+ .bindNative('ajax:success', function(e, data, status, xhr) {
+ equal(data.params.user_name, 'john')
+ equal(data.params.description, 'A wise man')
+ equal(data.params.age, undefined)
+
+ start()
+ })
+ .triggerNative('submit')
+})
+
})()