aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/active_model_helper_i18n_test.rb12
-rw-r--r--actionpack/test/template/date_helper_test.rb22
-rw-r--r--actionpack/test/template/form_helper_test.rb103
-rw-r--r--actionpack/test/template/form_options_helper_i18n_test.rb6
-rw-r--r--actionpack/test/template/javascript_helper_test.rb5
-rw-r--r--actionpack/test/template/prototype_helper_test.rb5
-rw-r--r--actionpack/test/template/subscriber_test.rb102
-rw-r--r--actionpack/test/template/text_helper_test.rb14
8 files changed, 255 insertions, 14 deletions
diff --git a/actionpack/test/template/active_model_helper_i18n_test.rb b/actionpack/test/template/active_model_helper_i18n_test.rb
index 2465444fc5..4eb2f262bd 100644
--- a/actionpack/test/template/active_model_helper_i18n_test.rb
+++ b/actionpack/test/template/active_model_helper_i18n_test.rb
@@ -16,27 +16,27 @@ class ActiveModelHelperI18nTest < Test::Unit::TestCase
stubs(:content_tag).returns 'content_tag'
- I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:activemodel, :errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
- I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:activemodel, :errors, :template]).returns 'There were problems with the following fields:'
+ I18n.stubs(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').returns "1 error prohibited this from being saved"
+ I18n.stubs(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).returns 'There were problems with the following fields:'
end
def test_error_messages_for_given_a_header_option_it_does_not_translate_header_message
- I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activemodel, :errors, :template], :count => 1, :model => '').never
+ I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').never
error_messages_for(:object => @object, :header_message => 'header message', :locale => 'en')
end
def test_error_messages_for_given_no_header_option_it_translates_header_message
- I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:activemodel, :errors, :template], :count => 1, :model => '').returns 'header message'
+ I18n.expects(:t).with(:'header', :locale => 'en', :scope => [:errors, :template], :count => 1, :model => '').returns 'header message'
error_messages_for(:object => @object, :locale => 'en')
end
def test_error_messages_for_given_a_message_option_it_does_not_translate_message
- I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activemodel, :errors, :template]).never
+ I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).never
error_messages_for(:object => @object, :message => 'message', :locale => 'en')
end
def test_error_messages_for_given_no_message_option_it_translates_message
- I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:activemodel, :errors, :template]).returns 'There were problems with the following fields:'
+ I18n.expects(:t).with(:'body', :locale => 'en', :scope => [:errors, :template]).returns 'There were problems with the following fields:'
error_messages_for(:object => @object, :locale => 'en')
end
end
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb
index 9fb2080f77..fb51b67185 100644
--- a/actionpack/test/template/date_helper_test.rb
+++ b/actionpack/test/template/date_helper_test.rb
@@ -2475,6 +2475,28 @@ class DateHelperTest < ActionView::TestCase
}, options)
end
+ def test_select_html_safety
+ assert select_day(16).html_safe?
+ assert select_month(8).html_safe?
+ assert select_year(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
+ assert select_minute(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
+ assert select_second(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
+
+ assert select_minute(8, :use_hidden => true).html_safe?
+ assert select_month(8, :prompt => 'Choose month').html_safe?
+
+ assert select_time(Time.mktime(2003, 8, 16, 8, 4, 18), {}, :class => 'selector').html_safe?
+ assert select_date(Time.mktime(2003, 8, 16), :date_separator => " / ", :start_year => 2003, :end_year => 2005, :prefix => "date[first]").html_safe?
+ end
+
+ def test_object_select_html_safety
+ @post = Post.new
+ @post.written_on = Date.new(2004, 6, 15)
+
+ assert date_select("post", "written_on", :default => Time.local(2006, 9, 19, 15, 16, 35), :include_blank => true).html_safe?
+ assert time_select("post", "written_on", :ignore_date => true).html_safe?
+ end
+
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index b1e9fe99a2..0c5c5d17ee 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -16,8 +16,8 @@ class FormHelperTest < ActionView::TestCase
}
}
},
- :views => {
- :labels => {
+ :helpers => {
+ :label => {
:post => {
:body => "Write entire text here"
}
@@ -25,6 +25,20 @@ class FormHelperTest < ActionView::TestCase
}
}
+ # Create "submit" locale for testing I18n submit helpers
+ I18n.backend.store_translations 'submit', {
+ :helpers => {
+ :submit => {
+ :create => 'Create {{model}}',
+ :update => 'Confirm {{model}} changes',
+ :submit => 'Save changes',
+ :another_post => {
+ :update => 'Update your {{model}}'
+ }
+ }
+ }
+ }
+
@post = Post.new
@comment = Comment.new
def @post.errors()
@@ -190,6 +204,11 @@ class FormHelperTest < ActionView::TestCase
hidden_field("post", "title", :value => "Something Else")
end
+ def test_text_field_with_custom_type
+ assert_dom_equal '<input id="user_email" size="30" name="user[email]" type="email" />',
+ text_field("user", "email", :type => "email")
+ end
+
def test_check_box
assert_dom_equal(
'<input name="post[secret]" type="hidden" value="0" /><input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" />',
@@ -234,6 +253,19 @@ class FormHelperTest < ActionView::TestCase
)
end
+ def test_check_box_with_multiple_behavior
+ @post.comment_ids = [2,3]
+ assert_dom_equal(
+ '<input name="post[comment_ids][]" type="hidden" value="0" /><input id="post_comment_ids_1" name="post[comment_ids][]" type="checkbox" value="1" />',
+ check_box("post", "comment_ids", { :multiple => true }, 1)
+ )
+ assert_dom_equal(
+ '<input name="post[comment_ids][]" type="hidden" value="0" /><input checked="checked" id="post_comment_ids_3" name="post[comment_ids][]" type="checkbox" value="3" />',
+ check_box("post", "comment_ids", { :multiple => true }, 3)
+ )
+ end
+
+
def test_checkbox_disabled_still_submits_checked_value
assert_dom_equal(
'<input name="post[secret]" type="hidden" value="1" /><input checked="checked" disabled="disabled" id="post_secret" name="post[secret]" type="checkbox" value="1" />',
@@ -475,6 +507,67 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_submit_with_object_as_new_record_and_locale_strings
+ old_locale, I18n.locale = I18n.locale, :submit
+
+ def @post.new_record?() true; end
+ form_for(:post, @post) do |f|
+ concat f.submit
+ end
+
+ expected = "<form action='http://www.example.com' method='post'>" +
+ "<input name='commit' id='post_submit' type='submit' value='Create Post' />" +
+ "</form>"
+ assert_dom_equal expected, output_buffer
+ ensure
+ I18n.locale = old_locale
+ end
+
+ def test_submit_with_object_as_existing_record_and_locale_strings
+ old_locale, I18n.locale = I18n.locale, :submit
+
+ form_for(:post, @post) do |f|
+ concat f.submit
+ end
+
+ expected = "<form action='http://www.example.com' method='post'>" +
+ "<input name='commit' id='post_submit' type='submit' value='Confirm Post changes' />" +
+ "</form>"
+ assert_dom_equal expected, output_buffer
+ ensure
+ I18n.locale = old_locale
+ end
+
+ def test_submit_without_object_and_locale_strings
+ old_locale, I18n.locale = I18n.locale, :submit
+
+ form_for(:post) do |f|
+ concat f.submit :class => "extra"
+ end
+
+ expected = "<form action='http://www.example.com' method='post'>" +
+ "<input name='commit' class='extra' id='post_submit' type='submit' value='Save changes' />" +
+ "</form>"
+ assert_dom_equal expected, output_buffer
+ ensure
+ I18n.locale = old_locale
+ end
+
+ def test_submit_with_object_and_nested_lookup
+ old_locale, I18n.locale = I18n.locale, :submit
+
+ form_for(:another_post, @post) do |f|
+ concat f.submit
+ end
+
+ expected = "<form action='http://www.example.com' method='post'>" +
+ "<input name='commit' id='another_post_submit' type='submit' value='Update your Post' />" +
+ "</form>"
+ assert_dom_equal expected, output_buffer
+ ensure
+ I18n.locale = old_locale
+ end
+
def test_nested_fields_for
form_for(:post, @post) do |f|
f.fields_for(:comment, @post) do |c|
@@ -659,7 +752,7 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
-
+
def test_nested_fields_for_with_existing_records_on_a_nested_attributes_one_to_one_association_with_explicit_hidden_field_placement
@post.author = Author.new(321)
@@ -670,7 +763,7 @@ class FormHelperTest < ActionView::TestCase
concat af.text_field(:name)
end
end
-
+
expected = '<form action="http://www.example.com" method="post">' +
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
@@ -715,7 +808,7 @@ class FormHelperTest < ActionView::TestCase
end
end
end
-
+
expected = '<form action="http://www.example.com" method="post">' +
'<input name="post[title]" size="30" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
diff --git a/actionpack/test/template/form_options_helper_i18n_test.rb b/actionpack/test/template/form_options_helper_i18n_test.rb
index 91e370efa7..4972ea6511 100644
--- a/actionpack/test/template/form_options_helper_i18n_test.rb
+++ b/actionpack/test/template/form_options_helper_i18n_test.rb
@@ -6,7 +6,7 @@ class FormOptionsHelperI18nTests < ActionView::TestCase
def setup
@prompt_message = 'Select!'
I18n.backend.send(:init_translations)
- I18n.backend.store_translations :en, :support => { :select => { :prompt => @prompt_message } }
+ I18n.backend.store_translations :en, :helpers => { :select => { :prompt => @prompt_message } }
end
def teardown
@@ -14,7 +14,7 @@ class FormOptionsHelperI18nTests < ActionView::TestCase
end
def test_select_with_prompt_true_translates_prompt_message
- I18n.expects(:translate).with('support.select.prompt', { :default => 'Please select' })
+ I18n.expects(:translate).with('helpers.select.prompt', { :default => 'Please select' })
select('post', 'category', [], :prompt => true)
end
@@ -24,4 +24,4 @@ class FormOptionsHelperI18nTests < ActionView::TestCase
select('post', 'category', [], :prompt => true)
)
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb
index f0f686f6e2..03caad3d46 100644
--- a/actionpack/test/template/javascript_helper_test.rb
+++ b/actionpack/test/template/javascript_helper_test.rb
@@ -13,8 +13,13 @@ class JavaScriptHelperTest < ActionView::TestCase
def setup
super
+ ActiveSupport.escape_html_entities_in_json = true
@template = self
end
+
+ def teardown
+ ActiveSupport.escape_html_entities_in_json = false
+ end
def _evaluate_assigns_and_ivars() end
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
index 313a769088..9225153798 100644
--- a/actionpack/test/template/prototype_helper_test.rb
+++ b/actionpack/test/template/prototype_helper_test.rb
@@ -317,6 +317,11 @@ class JavaScriptGeneratorTest < PrototypeHelperBaseTest
def setup
super
@generator = create_generator
+ ActiveSupport.escape_html_entities_in_json = true
+ end
+
+ def teardown
+ ActiveSupport.escape_html_entities_in_json = false
end
def _evaluate_assigns_and_ivars() end
diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/subscriber_test.rb
new file mode 100644
index 0000000000..af0b3102cf
--- /dev/null
+++ b/actionpack/test/template/subscriber_test.rb
@@ -0,0 +1,102 @@
+require "abstract_unit"
+require "rails/subscriber/test_helper"
+require "action_view/railties/subscriber"
+require "controller/fake_models"
+
+module ActionViewSubscriberTest
+
+ def setup
+ @old_logger = ActionController::Base.logger
+ @view = ActionView::Base.new(ActionController::Base.view_paths, {})
+ Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH))
+ Rails::Subscriber.add(:action_view, ActionView::Railties::Subscriber.new)
+ super
+ end
+
+ def teardown
+ super
+ Rails::Subscriber.subscribers.clear
+ ActionController::Base.logger = @old_logger
+ end
+
+ def set_logger(logger)
+ ActionController::Base.logger = logger
+ end
+
+ def test_render_file_template
+ @view.render(:file => "test/hello_world.erb")
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match /Rendered test\/hello_world\.erb/, @logger.logged(:info).last
+ end
+
+ def test_render_text_template
+ @view.render(:text => "OMG")
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match /Rendered text template/, @logger.logged(:info).last
+ end
+
+ def test_render_inline_template
+ @view.render(:inline => "<%= 'OMG' %>")
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match /Rendered inline template/, @logger.logged(:info).last
+ end
+
+ def test_render_partial_template
+ @view.render(:partial => "test/customer")
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last
+ end
+
+ def test_render_partial_with_implicit_path
+ @view.stubs(:controller_path).returns("test")
+ @view.render(Customer.new("david"), :greeting => "hi")
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match /Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last
+ end
+
+ def test_render_collection_template
+ @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match /Rendered test\/_customer.erb/, @logger.logged(:info).last
+ end
+
+ def test_render_collection_with_implicit_path
+ @view.stubs(:controller_path).returns("test")
+ @view.render([ Customer.new("david"), Customer.new("mary") ], :greeting => "hi")
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match /Rendered customers\/_customer\.html\.erb/, @logger.logged(:info).last
+ end
+
+ def test_render_collection_template_without_path
+ @view.stubs(:controller_path).returns("test")
+ @view.render([ GoodCustomer.new("david"), Customer.new("mary") ], :greeting => "hi")
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_match /Rendered collection/, @logger.logged(:info).last
+ end
+
+ class SyncSubscriberTest < ActiveSupport::TestCase
+ include Rails::Subscriber::SyncTestHelper
+ include ActionViewSubscriberTest
+ end
+
+ class AsyncSubscriberTest < ActiveSupport::TestCase
+ include Rails::Subscriber::AsyncTestHelper
+ include ActionViewSubscriberTest
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 08143ba680..088c07b8bb 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -360,6 +360,20 @@ class TextHelperTest < ActionView::TestCase
assert_equal %(<p>#{link10_result} Link</p>), auto_link("<p>#{link10_raw} Link</p>")
end
+ def test_auto_link_other_protocols
+ silence_warnings do
+ begin
+ old_re_value = ActionView::Helpers::TextHelper::AUTO_LINK_RE
+ ActionView::Helpers::TextHelper.const_set :AUTO_LINK_RE, %r{(ftp://)[^\s<]+}
+ link_raw = 'ftp://example.com/file.txt'
+ link_result = generate_result(link_raw)
+ assert_equal %(Download #{link_result}), auto_link("Download #{link_raw}")
+ ensure
+ ActionView::Helpers::TextHelper.const_set :AUTO_LINK_RE, old_re_value
+ end
+ end
+ end
+
def test_auto_link_already_linked
linked1 = generate_result('Ruby On Rails', 'http://www.rubyonrails.com')
linked2 = generate_result('www.rubyonrails.com', 'http://www.rubyonrails.com')