aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md58
-rw-r--r--actionview/MIT-LICENSE2
-rw-r--r--actionview/RUNNING_UNIT_TESTS.rdoc (renamed from actionview/RUNNING_UNIT_TESTS)0
-rw-r--r--actionview/Rakefile1
-rw-r--r--actionview/lib/action_view/digestor.rb10
-rw-r--r--actionview/lib/action_view/helpers/date_helper.rb10
-rw-r--r--actionview/lib/action_view/helpers/form_helper.rb6
-rw-r--r--actionview/lib/action_view/helpers/form_options_helper.rb13
-rw-r--r--actionview/lib/action_view/helpers/form_tag_helper.rb4
-rw-r--r--actionview/lib/action_view/helpers/tags/color_field.rb2
-rw-r--r--actionview/lib/action_view/helpers/tags/datetime_field.rb2
-rw-r--r--actionview/lib/action_view/helpers/url_helper.rb2
-rw-r--r--actionview/test/fixtures/digestor/level/_recursion.html.erb1
-rw-r--r--actionview/test/fixtures/digestor/level/recursion.html.erb1
-rw-r--r--actionview/test/template/digestor_test.rb25
-rw-r--r--actionview/test/template/form_helper_test.rb29
-rw-r--r--actionview/test/template/form_options_helper_test.rb17
-rw-r--r--actionview/test/template/form_tag_helper_test.rb17
-rw-r--r--actionview/test/template/url_helper_test.rb10
19 files changed, 144 insertions, 66 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index 31e123d916..2981e76ec5 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,61 @@
+* Fix `link_to` with block and url hashes.
+
+ Before:
+
+ link_to(action: 'bar', controller: 'foo') { content_tag(:span, 'Example site') }
+ # => "<a action=\"bar\" controller=\"foo\"><span>Example site</span></a>"
+
+ After:
+
+ link_to(action: 'bar', controller: 'foo') { content_tag(:span, 'Example site') }
+ # => "<a href=\"/\"><span>Example site</span></a>"
+
+ *Murahashi Sanemat Kenichi*
+
+* Fix "Stack Level Too Deep" error when redering recursive partials.
+
+ Fixes #11340.
+
+ *Rafael Mendonça França*
+
+* Added an `enforce_utf8` hash option for `form_tag` method.
+
+ Control to output a hidden input tag with name `utf8` without monkey
+ patching.
+
+ Before:
+
+ form_tag
+ # => '<form>..<input name="utf8" type="hidden" value="&#x2713;" />..</form>'
+
+ After:
+
+ form_tag
+ # => '<form>..<input name="utf8" type="hidden" value="&#x2713;" />..</form>'
+
+ form_tag({}, { :enforce_utf8 => false })
+ # => '<form>....</form>'
+
+ *ma2gedev*
+
+* Remove the deprecated `include_seconds` argument from `distance_of_time_in_words`,
+ pass in an `:include_seconds` hash option to use this feature.
+
+ *Carlos Antonio da Silva*
+
+* Remove deprecated block passing to `FormBuilder#new`.
+
+ *Vipul A M*
+
+* Pick `DateField` `DateTimeField` and `ColorField` values from stringified options allowing use of symbol keys with helpers.
+
+ *Jon Rowe*
+
+* Remove the deprecated `prompt` argument from `grouped_options_for_select`,
+ pass in a `:prompt` hash option to use this feature.
+
+ *kennyj*
+
* Always escape the result of `link_to_unless` method.
Before:
diff --git a/actionview/MIT-LICENSE b/actionview/MIT-LICENSE
index 810daf856c..5c668d9624 100644
--- a/actionview/MIT-LICENSE
+++ b/actionview/MIT-LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2004-2012 David Heinemeier Hansson
+Copyright (c) 2004-2013 David Heinemeier Hansson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/actionview/RUNNING_UNIT_TESTS b/actionview/RUNNING_UNIT_TESTS.rdoc
index a0c35e1810..a0c35e1810 100644
--- a/actionview/RUNNING_UNIT_TESTS
+++ b/actionview/RUNNING_UNIT_TESTS.rdoc
diff --git a/actionview/Rakefile b/actionview/Rakefile
index 1cbd35cda4..25365d3c3d 100644
--- a/actionview/Rakefile
+++ b/actionview/Rakefile
@@ -1,5 +1,4 @@
require 'rake/testtask'
-require 'rake/packagetask'
require 'rubygems/package_task'
desc "Default Task"
diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb
index 9324a1ac50..a674e4d7ea 100644
--- a/actionview/lib/action_view/digestor.rb
+++ b/actionview/lib/action_view/digestor.rb
@@ -7,10 +7,14 @@ module ActionView
@@cache = ThreadSafe::Cache.new
def self.digest(name, format, finder, options = {})
- cache_key = [name, format] + Array.wrap(options[:dependencies])
- @@cache[cache_key.join('.')] ||= begin
+ cache_key = ([name, format] + Array.wrap(options[:dependencies])).join('.')
+ @@cache.fetch(cache_key) do
+ @@cache[cache_key] ||= nil if options[:partial] # Prevent re-entry
+
klass = options[:partial] || name.include?("/_") ? PartialDigestor : Digestor
- klass.new(name, format, finder, options).digest
+ digest = klass.new(name, format, finder, options).digest
+
+ @@cache[cache_key] = digest # Store the value
end
end
diff --git a/actionview/lib/action_view/helpers/date_helper.rb b/actionview/lib/action_view/helpers/date_helper.rb
index 8fb5eb1548..8e1aea50a9 100644
--- a/actionview/lib/action_view/helpers/date_helper.rb
+++ b/actionview/lib/action_view/helpers/date_helper.rb
@@ -64,15 +64,7 @@ module ActionView
# distance_of_time_in_words(from_time, to_time, include_seconds: true) # => about 6 years
# distance_of_time_in_words(to_time, from_time, include_seconds: true) # => about 6 years
# distance_of_time_in_words(Time.now, Time.now) # => less than a minute
- def distance_of_time_in_words(from_time, to_time = 0, include_seconds_or_options = {}, options = {})
- if include_seconds_or_options.is_a?(Hash)
- options = include_seconds_or_options
- else
- ActiveSupport::Deprecation.warn "distance_of_time_in_words and time_ago_in_words now accept :include_seconds " +
- "as a part of options hash, not a boolean argument"
- options[:include_seconds] ||= !!include_seconds_or_options
- end
-
+ def distance_of_time_in_words(from_time, to_time = 0, options = {})
options = {
scope: :'datetime.distance_in_words'
}.merge!(options)
diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb
index f64c0ca30b..8a4830d887 100644
--- a/actionview/lib/action_view/helpers/form_helper.rb
+++ b/actionview/lib/action_view/helpers/form_helper.rb
@@ -1237,11 +1237,7 @@ module ActionView
self
end
- def initialize(object_name, object, template, options, block=nil)
- if block
- ActiveSupport::Deprecation.warn "Giving a block to FormBuilder is deprecated and has no effect anymore."
- end
-
+ def initialize(object_name, object, template, options)
@nested_child_index = {}
@object_name, @object, @template, @options = object_name, object, template, options
@default_options = @options ? @options.slice(:index, :namespace) : {}
diff --git a/actionview/lib/action_view/helpers/form_options_helper.rb b/actionview/lib/action_view/helpers/form_options_helper.rb
index 21f892f443..4e9ef94ff3 100644
--- a/actionview/lib/action_view/helpers/form_options_helper.rb
+++ b/actionview/lib/action_view/helpers/form_options_helper.rb
@@ -510,15 +510,8 @@ module ActionView
# <b>Note:</b> Only the <tt><optgroup></tt> and <tt><option></tt> tags are returned, so you still have to
# wrap the output in an appropriate <tt><select></tt> tag.
def grouped_options_for_select(grouped_options, selected_key = nil, options = {})
- if options.is_a?(Hash)
- prompt = options[:prompt]
- divider = options[:divider]
- else
- prompt = options
- message = "Passing the prompt to grouped_options_for_select as an argument is deprecated. " \
- "Please use an options hash like `{ prompt: #{prompt.inspect} }`."
- ActiveSupport::Deprecation.warn message
- end
+ prompt = options[:prompt]
+ divider = options[:divider]
body = "".html_safe
@@ -783,7 +776,7 @@ module ActionView
# Wraps ActionView::Helpers::FormOptionsHelper#grouped_collection_select for form builders:
#
# <%= form_for @city do |f| %>
- # <%= f.grouped_collection_select :country_id, :country_id, @continents, :countries, :name, :id, :name %>
+ # <%= f.grouped_collection_select :country_id, @continents, :countries, :name, :id, :name %>
# <%= f.submit %>
# <% end %>
#
diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb
index 3fa7696b83..142c27ace0 100644
--- a/actionview/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionview/lib/action_view/helpers/form_tag_helper.rb
@@ -38,6 +38,7 @@ module ActionView
# * A list of parameters to feed to the URL the form will be posted to.
# * <tt>:remote</tt> - If set to true, will allow the Unobtrusive JavaScript drivers to control the
# submit behavior. By default this behavior is an ajax submit.
+ # * <tt>:enforce_utf8</tt> - If set to false, a hidden input with name utf8 is not output.
#
# ==== Examples
# form_tag('/posts')
@@ -719,7 +720,8 @@ module ActionView
method_tag(method) + token_tag(authenticity_token)
end
- tags = utf8_enforcer_tag << method_tag
+ enforce_utf8 = html_options.delete("enforce_utf8") { true }
+ tags = (enforce_utf8 ? utf8_enforcer_tag : ''.html_safe) << method_tag
content_tag(:div, tags, :style => 'margin:0;padding:0;display:inline')
end
diff --git a/actionview/lib/action_view/helpers/tags/color_field.rb b/actionview/lib/action_view/helpers/tags/color_field.rb
index d8fc797035..b4bbe92746 100644
--- a/actionview/lib/action_view/helpers/tags/color_field.rb
+++ b/actionview/lib/action_view/helpers/tags/color_field.rb
@@ -4,7 +4,7 @@ module ActionView
class ColorField < TextField # :nodoc:
def render
options = @options.stringify_keys
- options["value"] = @options.fetch("value") { validate_color_string(value(object)) }
+ options["value"] ||= validate_color_string(value(object))
@options = options
super
end
diff --git a/actionview/lib/action_view/helpers/tags/datetime_field.rb b/actionview/lib/action_view/helpers/tags/datetime_field.rb
index 9a2279c611..25e7e05ec6 100644
--- a/actionview/lib/action_view/helpers/tags/datetime_field.rb
+++ b/actionview/lib/action_view/helpers/tags/datetime_field.rb
@@ -4,7 +4,7 @@ module ActionView
class DatetimeField < TextField # :nodoc:
def render
options = @options.stringify_keys
- options["value"] = @options.fetch("value") { format_date(value(object)) }
+ options["value"] ||= format_date(value(object))
options["min"] = format_date(options["min"])
options["max"] = format_date(options["max"])
@options = options
diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb
index 19e5941971..daa9a393b3 100644
--- a/actionview/lib/action_view/helpers/url_helper.rb
+++ b/actionview/lib/action_view/helpers/url_helper.rb
@@ -172,7 +172,7 @@ module ActionView
# link_to "Visit Other Site", "http://www.rubyonrails.org/", data: { confirm: "Are you sure?" }
# # => <a href="http://www.rubyonrails.org/" data-confirm="Are you sure?">Visit Other Site</a>
def link_to(name = nil, options = nil, html_options = nil, &block)
- html_options, options = options, name if block_given?
+ html_options, options, name = options, name, block if block_given?
options ||= {}
html_options = convert_options_to_data_attributes(options, html_options)
diff --git a/actionview/test/fixtures/digestor/level/_recursion.html.erb b/actionview/test/fixtures/digestor/level/_recursion.html.erb
new file mode 100644
index 0000000000..ee5aaf09c3
--- /dev/null
+++ b/actionview/test/fixtures/digestor/level/_recursion.html.erb
@@ -0,0 +1 @@
+<%= render 'recursion' %>
diff --git a/actionview/test/fixtures/digestor/level/recursion.html.erb b/actionview/test/fixtures/digestor/level/recursion.html.erb
new file mode 100644
index 0000000000..ee5aaf09c3
--- /dev/null
+++ b/actionview/test/fixtures/digestor/level/recursion.html.erb
@@ -0,0 +1 @@
+<%= render 'recursion' %>
diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb
index 06735c30d3..07f8d36d93 100644
--- a/actionview/test/template/digestor_test.rb
+++ b/actionview/test/template/digestor_test.rb
@@ -95,6 +95,31 @@ class TemplateDigestorTest < ActionView::TestCase
end
end
+ def test_recursion_in_renders
+ assert digest("level/recursion") # assert recursion is possible
+ assert_not_nil digest("level/recursion") # assert digest is stored
+ end
+
+ def test_chaning_the_top_templete_on_recursion
+ assert digest("level/recursion") # assert recursion is possible
+
+ assert_digest_difference("level/recursion") do
+ change_template("level/recursion")
+ end
+
+ assert_not_nil digest("level/recursion") # assert digest is stored
+ end
+
+ def test_chaning_the_partial_templete_on_recursion
+ assert digest("level/recursion") # assert recursion is possible
+
+ assert_digest_difference("level/recursion") do
+ change_template("level/_recursion")
+ end
+
+ assert_not_nil digest("level/recursion") # assert digest is stored
+ end
+
def test_dont_generate_a_digest_for_missing_templates
assert_equal '', digest("nothing/there")
end
diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb
index 1ff320224d..f05b6d0d94 100644
--- a/actionview/test/template/form_helper_test.rb
+++ b/actionview/test/template/form_helper_test.rb
@@ -702,6 +702,11 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal(expected, color_field("car", "color"))
end
+ def test_color_field_with_value_attr
+ expected = %{<input id="car_color" name="car[color]" type="color" value="#00FF00" />}
+ assert_dom_equal(expected, color_field("car", "color", value: "#00FF00"))
+ end
+
def test_search_field
expected = %{<input id="contact_notes_query" name="contact[notes_query]" type="search" />}
assert_dom_equal(expected, search_field("contact", "notes_query"))
@@ -732,6 +737,12 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal(expected, date_field("post", "written_on", min: min_value, max: max_value, step: step))
end
+ def test_date_field_with_value_attr
+ expected = %{<input id="post_written_on" name="post[written_on]" type="date" value="2013-06-29" />}
+ value = Date.new(2013,6,29)
+ assert_dom_equal(expected, date_field("post", "written_on", value: value))
+ end
+
def test_date_field_with_timewithzone_value
previous_time_zone, Time.zone = Time.zone, 'UTC'
expected = %{<input id="post_written_on" name="post[written_on]" type="date" value="2004-06-15" />}
@@ -802,6 +813,12 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal(expected, datetime_field("post", "written_on", min: min_value, max: max_value, step: step))
end
+ def test_datetime_field_with_value_attr
+ expected = %{<input id="post_written_on" name="post[written_on]" type="datetime" value="2013-06-29T13:37:00+00:00" />}
+ value = DateTime.new(2013,6,29,13,37)
+ assert_dom_equal(expected, datetime_field("post", "written_on", value: value))
+ end
+
def test_datetime_field_with_timewithzone_value
previous_time_zone, Time.zone = Time.zone, 'UTC'
expected = %{<input id="post_written_on" name="post[written_on]" type="datetime" value="2004-06-15T15:30:45.000+0000" />}
@@ -2899,18 +2916,6 @@ class FormHelperTest < ActionView::TestCase
assert_equal "fields", output
end
- def test_form_builder_block_argument_deprecation
- builder_class = Class.new(ActionView::Helpers::FormBuilder) do
- def initialize(object_name, object, template, options, block)
- super
- end
- end
-
- assert_deprecated(/Giving a block to FormBuilder is deprecated and has no effect anymore/) do
- builder_class.new(:foo, nil, nil, {}, proc {})
- end
- end
-
def test_form_for_only_instantiates_builder_once
initialization_count = 0
builder_class = Class.new(ActionView::Helpers::FormBuilder) do
diff --git a/actionview/test/template/form_options_helper_test.rb b/actionview/test/template/form_options_helper_test.rb
index 1715902927..8c90a58a84 100644
--- a/actionview/test/template/form_options_helper_test.rb
+++ b/actionview/test/template/form_options_helper_test.rb
@@ -310,15 +310,6 @@ class FormOptionsHelperTest < ActionView::TestCase
)
end
- def test_grouped_options_for_select_with_selected_and_prompt_deprecated
- assert_deprecated 'Passing the prompt to grouped_options_for_select as an argument is deprecated. Please use an options hash like `{ prompt: "Choose a product..." }`.' do
- assert_dom_equal(
- "<option value=\"\">Choose a product...</option><optgroup label=\"Hats\"><option value=\"Baseball Cap\">Baseball Cap</option>\n<option selected=\"selected\" value=\"Cowboy Hat\">Cowboy Hat</option></optgroup>",
- grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]], "Cowboy Hat", "Choose a product...")
- )
- end
- end
-
def test_grouped_options_for_select_with_selected_and_prompt
assert_dom_equal(
"<option value=\"\">Choose a product...</option><optgroup label=\"Hats\"><option value=\"Baseball Cap\">Baseball Cap</option>\n<option selected=\"selected\" value=\"Cowboy Hat\">Cowboy Hat</option></optgroup>",
@@ -337,14 +328,6 @@ class FormOptionsHelperTest < ActionView::TestCase
assert grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]]).html_safe?
end
- def test_grouped_options_for_select_with_prompt_returns_html_escaped_string_deprecated
- ActiveSupport::Deprecation.silence do
- assert_dom_equal(
- "<option value=\"\">&lt;Choose One&gt;</option><optgroup label=\"Hats\"><option value=\"Baseball Cap\">Baseball Cap</option>\n<option value=\"Cowboy Hat\">Cowboy Hat</option></optgroup>",
- grouped_options_for_select([["Hats", ["Baseball Cap","Cowboy Hat"]]], nil, '<Choose One>'))
- end
- end
-
def test_grouped_options_for_select_with_prompt_returns_html_escaped_string
assert_dom_equal(
"<option value=\"\">&lt;Choose One&gt;</option><optgroup label=\"Hats\"><option value=\"Baseball Cap\">Baseball Cap</option>\n<option value=\"Cowboy Hat\">Cowboy Hat</option></optgroup>",
diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb
index 70fc6a588b..22bf438a56 100644
--- a/actionview/test/template/form_tag_helper_test.rb
+++ b/actionview/test/template/form_tag_helper_test.rb
@@ -12,9 +12,10 @@ class FormTagHelperTest < ActionView::TestCase
def hidden_fields(options = {})
method = options[:method]
+ enforce_utf8 = options.fetch(:enforce_utf8, true)
txt = %{<div style="margin:0;padding:0;display:inline">}
- txt << %{<input name="utf8" type="hidden" value="&#x2713;" />}
+ txt << %{<input name="utf8" type="hidden" value="&#x2713;" />} if enforce_utf8
if method && !%w(get post).include?(method.to_s)
txt << %{<input name="_method" type="hidden" value="#{method}" />}
end
@@ -110,6 +111,20 @@ class FormTagHelperTest < ActionView::TestCase
assert_dom_equal expected, actual
end
+ def test_form_tag_enforce_utf8_true
+ actual = form_tag({}, { :enforce_utf8 => true })
+ expected = whole_form("http://www.example.com", :enforce_utf8 => true)
+ assert_dom_equal expected, actual
+ assert actual.html_safe?
+ end
+
+ def test_form_tag_enforce_utf8_false
+ actual = form_tag({}, { :enforce_utf8 => false })
+ expected = whole_form("http://www.example.com", :enforce_utf8 => false)
+ assert_dom_equal expected, actual
+ assert actual.html_safe?
+ end
+
def test_form_tag_with_block_in_erb
output_buffer = render_erb("<%= form_tag('http://www.example.com') do %>Hello world!<% end %>")
diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb
index 8373d7f992..851ea8796f 100644
--- a/actionview/test/template/url_helper_test.rb
+++ b/actionview/test/template/url_helper_test.rb
@@ -308,6 +308,13 @@ class UrlHelperTest < ActiveSupport::TestCase
link_to('/', class: "special") { content_tag(:span, 'Example site') }
end
+ def test_link_tag_using_block_and_hash
+ assert_dom_equal(
+ %{<a href="/"><span>Example site</span></a>},
+ link_to(url_hash) { content_tag(:span, 'Example site') }
+ )
+ end
+
def test_link_tag_using_block_in_erb
out = render_erb %{<%= link_to('/') do %>Example site<% end %>}
assert_equal '<a href="/">Example site</a>', out
@@ -336,8 +343,6 @@ class UrlHelperTest < ActiveSupport::TestCase
assert_dom_equal %{<a href="/">Listing</a>},
link_to_unless(false, "Listing", url_hash)
- assert_equal "Showing", link_to_unless(true, "Showing", url_hash)
-
assert_equal "<strong>Showing</strong>",
link_to_unless(true, "Showing", url_hash) { |name|
"<strong>#{name}</strong>".html_safe
@@ -357,7 +362,6 @@ class UrlHelperTest < ActiveSupport::TestCase
def test_link_to_if
assert_equal "Showing", link_to_if(false, "Showing", url_hash)
assert_dom_equal %{<a href="/">Listing</a>}, link_to_if(true, "Listing", url_hash)
- assert_equal "Showing", link_to_if(false, "Showing", url_hash)
end
def request_for_url(url, opts = {})