From 8b028325003e91155d228882444199c1aedf31f7 Mon Sep 17 00:00:00 2001 From: Alex Robbin Date: Sat, 9 Aug 2014 00:10:54 -0400 Subject: add I18n support for `:placeholder` HTML option is passed to form fields --- actionview/test/template/form_helper_test.rb | 168 +++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) (limited to 'actionview/test') diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index a9f137aec6..d944214961 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -59,6 +59,35 @@ class FormHelperTest < ActionView::TestCase } } + I18n.backend.store_translations 'placeholder', { + activemodel: { + attributes: { + post: { + cost: "Total cost" + }, + :"post/cost" => { + uk: "Pounds" + } + } + }, + helpers: { + placeholder: { + post: { + title: "What is this about?", + written_on: { + spanish: "Escrito en" + }, + comments: { + body: "Write body here" + } + }, + tag: { + value: "Tag" + } + } + } + } + @post = Post.new @comment = Comment.new def @post.errors() @@ -297,6 +326,68 @@ class FormHelperTest < ActionView::TestCase ) end + def test_text_field_placeholder_without_locales + with_locale :placeholder do + assert_dom_equal('', text_field(:post, :body, placeholder: true)) + end + end + + def test_text_field_placeholder_with_locales + with_locale :placeholder do + assert_dom_equal('', text_field(:post, :title, placeholder: true)) + end + end + + def test_text_field_placeholder_with_human_attribute_name + with_locale :placeholder do + assert_dom_equal('', text_field(:post, :cost, placeholder: true)) + end + end + + def test_text_field_placeholder_with_human_attribute_name_and_value + with_locale :placeholder do + assert_dom_equal('', text_field(:post, :cost, placeholder: "uk")) + end + end + + def test_text_field_placeholder_with_locales_and_value + with_locale :placeholder do + assert_dom_equal('', text_field(:post, :written_on, placeholder: "spanish")) + end + end + + def test_text_field_placeholder_with_locales_and_nested_attributes + with_locale :placeholder do + form_for(@post, html: { id: 'create-post' }) do |f| + f.fields_for(:comments) do |cf| + concat cf.text_field(:body, placeholder: true) + end + end + + expected = whole_form("/posts/123", "create-post", "edit_post", method: "patch") do + '' + end + + assert_dom_equal expected, output_buffer + end + end + + def test_text_field_placeholder_with_locales_fallback_and_nested_attributes + with_locale :placeholder do + form_for(@post, html: { id: 'create-post' }) do |f| + f.fields_for(:tags) do |cf| + concat cf.text_field(:value, placeholder: true) + end + end + + expected = whole_form("/posts/123", "create-post", "edit_post", method: "patch") do + '' + end + + assert_dom_equal expected, output_buffer + end + end + def test_text_field assert_dom_equal( '', @@ -665,6 +756,83 @@ class FormHelperTest < ActionView::TestCase ) end + def test_text_area_placeholder_without_locales + with_locale :placeholder do + assert_dom_equal( + %{}, + text_area(:post, :body, placeholder: true) + ) + end + end + + def test_text_area_placeholder_with_locales + with_locale :placeholder do + assert_dom_equal( + %{}, + text_area(:post, :title, placeholder: true) + ) + end + end + + def test_text_area_placeholder_with_human_attribute_name + with_locale :placeholder do + assert_dom_equal( + %{}, + text_area(:post, :cost, placeholder: true) + ) + end + end + + def test_text_area_placeholder_with_human_attribute_name_and_value + with_locale :placeholder do + assert_dom_equal( + %{}, + text_area(:post, :cost, placeholder: "uk") + ) + end + end + + def test_text_area_placeholder_with_locales_and_value + with_locale :placeholder do + assert_dom_equal( + %{}, + text_area(:post, :written_on, placeholder: "spanish") + ) + end + end + + def test_text_area_placeholder_with_locales_and_nested_attributes + with_locale :placeholder do + form_for(@post, html: { id: 'create-post' }) do |f| + f.fields_for(:comments) do |cf| + concat cf.text_area(:body, placeholder: true) + end + end + + expected = whole_form("/posts/123", "create-post", "edit_post", method: "patch") do + %{} + end + + assert_dom_equal expected, output_buffer + end + end + + def test_text_area_placeholder_with_locales_fallback_and_nested_attributes + with_locale :placeholder do + form_for(@post, html: { id: 'create-post' }) do |f| + f.fields_for(:tags) do |cf| + concat cf.text_area(:value, placeholder: true) + end + end + + expected = whole_form("/posts/123", "create-post", "edit_post", method: "patch") do + %{} + end + + assert_dom_equal expected, output_buffer + end + end + def test_text_area assert_dom_equal( %{}, -- cgit v1.2.3 From bc116a55ca3dd9f63a1f1ca7ade3623885adcc57 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 13 Aug 2014 18:26:41 +0900 Subject: AM, AP, AV, and AMo tests are already order_independent! --- actionview/test/abstract_unit.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'actionview/test') diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index 923e637f11..d60712255b 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -340,8 +340,3 @@ 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 2b0c602bc3dd2928b8a77465f305c765dbb447e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sat, 16 Aug 2014 16:45:11 -0400 Subject: Remove usafe of respond_to in ActionView tests --- actionview/test/activerecord/controller_runtime_test.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'actionview/test') diff --git a/actionview/test/activerecord/controller_runtime_test.rb b/actionview/test/activerecord/controller_runtime_test.rb index 368bec1c70..b5bfcf12a3 100644 --- a/actionview/test/activerecord/controller_runtime_test.rb +++ b/actionview/test/activerecord/controller_runtime_test.rb @@ -8,8 +8,6 @@ ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime class ControllerRuntimeLogSubscriberTest < ActionController::TestCase class LogSubscriberController < ActionController::Base - respond_to :html - def show render :inline => "<%= Project.all %>" end @@ -21,7 +19,7 @@ class ControllerRuntimeLogSubscriberTest < ActionController::TestCase def create ActiveRecord::LogSubscriber.runtime += 100 project = Project.last - respond_with(project, location: url_for(action: :show)) + redirect_to "/" end def redirect -- cgit v1.2.3