From 45f8848ca7d7a1065c4c9f3d73946d908a382a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Fri, 2 Dec 2016 16:42:37 -0500 Subject: Remove unused argument Now Text class is only used to render text mime type pages --- actionview/lib/action_view/template/text.rb | 7 +++---- actionview/test/template/text_test.rb | 14 ++------------ 2 files changed, 5 insertions(+), 16 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/template/text.rb b/actionview/lib/action_view/template/text.rb index e8d4e18f04..380528d6ef 100644 --- a/actionview/lib/action_view/template/text.rb +++ b/actionview/lib/action_view/template/text.rb @@ -4,10 +4,9 @@ module ActionView #:nodoc: class Text #:nodoc: attr_accessor :type - def initialize(string, type = nil) + def initialize(string) @string = string.to_s - @type = Types[type] || type if type - @type ||= Types[:text] + @type = Types[:text] end def identifier @@ -25,7 +24,7 @@ module ActionView #:nodoc: end def formats - [@type.respond_to?(:ref) ? @type.ref : @type.to_s] + [@type.ref] end end end diff --git a/actionview/test/template/text_test.rb b/actionview/test/template/text_test.rb index 6510688f97..ee526dc367 100644 --- a/actionview/test/template/text_test.rb +++ b/actionview/test/template/text_test.rb @@ -1,17 +1,7 @@ require "abstract_unit" class TextTest < ActiveSupport::TestCase - test "formats returns symbol for recognized MIME type" do - assert_equal [:text], ActionView::Template::Text.new("", :text).formats - end - - test "formats returns string for recognized MIME type when MIME does not have symbol" do - foo = Mime::Type.lookup("foo") - assert_nil foo.to_sym - assert_equal ["foo"], ActionView::Template::Text.new("", foo).formats - end - - test "formats returns string for unknown MIME type" do - assert_equal ["foo"], ActionView::Template::Text.new("", "foo").formats + test "formats always return :text" do + assert_equal [:text], ActionView::Template::Text.new("").formats end end -- cgit v1.2.3 From d71f289fb29d7818620725346ed42ea6952708fa Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Sat, 3 Dec 2016 15:28:59 +0900 Subject: stop using removed `render :text` Follow up to 79a5ea9eadb4d43b62afacedc0706cbe88c54496 --- actionview/test/ujs/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/test/ujs/server.rb b/actionview/test/ujs/server.rb index c7698c87fa..cc02cd8419 100644 --- a/actionview/test/ujs/server.rb +++ b/actionview/test/ujs/server.rb @@ -96,7 +96,7 @@ class TestsController < ActionController::Base render html: html.html_safe else - render text: "ERROR: #{request.path} requested without ajax", status: 404 + render plain: "ERROR: #{request.path} requested without ajax", status: 404 end end end -- cgit v1.2.3 From d52ad0541ee6f4dd1c37c12ad5a6a68d948f9aac Mon Sep 17 00:00:00 2001 From: Andreas Maierhofer Date: Mon, 5 Dec 2016 11:53:44 +0100 Subject: Update url_helper.rb, adjust link_to api doc Removed references to `button` in the `link_to` `disable_with` api description. --- actionview/lib/action_view/helpers/url_helper.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 1277126995..22cc4b2920 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -105,10 +105,9 @@ module ActionView # driver to prompt with the question specified (in this case, the # resulting text would be question?. If the user accepts, the # link is processed normally, otherwise no action is taken. - # * :disable_with - Value of this parameter will be - # used as the value for a disabled version of the submit - # button when the form is submitted. This feature is provided - # by the unobtrusive JavaScript driver. + # * :disable_with - Value of this parameter will be used as the + # name for a disabled version of the link. This feature is provided by + # the unobtrusive JavaScript driver. # # ==== Examples # Because it relies on +url_for+, +link_to+ supports both older-style controller/action/id arguments -- cgit v1.2.3 From 238035409ec0c5180b59cfbcd50cdf9a605e37cf Mon Sep 17 00:00:00 2001 From: Max Melentiev Date: Mon, 5 Dec 2016 21:30:27 +0300 Subject: Fixed usage of cache_template_loading It disables recompilation of templates on every request in test env. --- actionview/CHANGELOG.md | 8 ++++++++ actionview/lib/action_view/railtie.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 558659dd77..8da2e4ae1d 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,11 @@ +* Use `ActionView::Resolver.caching?` (`config.action_view.cache_template_loading`) + to enable template recompilation. + + Before it was enabled by `consider_all_requests_local`, which caused + recompilation in tests. + + *Max Melentiev* + * Add `form_with` to unify `form_tag` and `form_for` usage. Used like `form_tag` (where just the open tag is output): diff --git a/actionview/lib/action_view/railtie.rb b/actionview/lib/action_view/railtie.rb index ae72cea404..d344d98f4b 100644 --- a/actionview/lib/action_view/railtie.rb +++ b/actionview/lib/action_view/railtie.rb @@ -39,7 +39,7 @@ module ActionView initializer "action_view.per_request_digest_cache" do |app| ActiveSupport.on_load(:action_view) do - if app.config.consider_all_requests_local + unless ActionView::Resolver.caching? app.executor.to_run ActionView::Digestor::PerExecutionDigestCacheExpiry end end -- cgit v1.2.3 From 7407d35c5417b6ef872663936a5880ede8ab711c Mon Sep 17 00:00:00 2001 From: Toshimaru Date: Fri, 9 Dec 2016 03:08:17 +0900 Subject: Enable `block` variable in view Remove `block` keyword from reserved method names --- actionview/lib/action_view/template.rb | 2 +- actionview/test/fixtures/test/test_template_with_block_variable.erb | 1 + actionview/test/template/compiled_templates_test.rb | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 actionview/test/fixtures/test/test_template_with_block_variable.erb (limited to 'actionview') diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index 2dcd6324db..d67f37d6d1 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -326,7 +326,7 @@ module ActionView def locals_code #:nodoc: # Only locals with valid variable names get set directly. Others will # still be available in local_assigns. - locals = @locals.to_set - Module::DELEGATION_RESERVED_METHOD_NAMES + locals = @locals.to_set - Module::DELEGATION_RESERVED_METHOD_NAMES.dup.delete("block") locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/) # Double assign to suppress the dreaded 'assigned but unused variable' warning diff --git a/actionview/test/fixtures/test/test_template_with_block_variable.erb b/actionview/test/fixtures/test/test_template_with_block_variable.erb new file mode 100644 index 0000000000..2ee6a2bbdc --- /dev/null +++ b/actionview/test/fixtures/test/test_template_with_block_variable.erb @@ -0,0 +1 @@ +<%= block %> \ No newline at end of file diff --git a/actionview/test/template/compiled_templates_test.rb b/actionview/test/template/compiled_templates_test.rb index 3ecac46d34..a24a245442 100644 --- a/actionview/test/template/compiled_templates_test.rb +++ b/actionview/test/template/compiled_templates_test.rb @@ -14,6 +14,10 @@ class CompiledTemplatesTest < ActiveSupport::TestCase render(file: "test/render_file_with_ruby_keyword_locals", locals: { class: "foo" }) end + def test_template_with_block_variable + assert_equal "foo", render(file: "test/test_template_with_block_variable", locals: { block: "foo" }) + end + def test_template_with_invalid_identifier_locals locals = { foo: "bar", -- cgit v1.2.3 From d9ff835b99ff3c7567ccde9b1379b4deeabee32f Mon Sep 17 00:00:00 2001 From: Toshimaru Date: Fri, 9 Dec 2016 04:55:21 +0900 Subject: split DELEGATION_RESERVED_METHOD_NAMES in half --- actionview/lib/action_view/template.rb | 2 +- .../fixtures/test/test_template_with_block_variable.erb | 1 - .../test_template_with_delegation_reserved_keywords.erb | 1 + actionview/test/template/compiled_templates_test.rb | 14 ++++++++++---- 4 files changed, 12 insertions(+), 6 deletions(-) delete mode 100644 actionview/test/fixtures/test/test_template_with_block_variable.erb create mode 100644 actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb (limited to 'actionview') diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index d67f37d6d1..0afdcd1def 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -326,7 +326,7 @@ module ActionView def locals_code #:nodoc: # Only locals with valid variable names get set directly. Others will # still be available in local_assigns. - locals = @locals.to_set - Module::DELEGATION_RESERVED_METHOD_NAMES.dup.delete("block") + locals = @locals - Module::RUBY_RESERVED_KEYWORDS locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/) # Double assign to suppress the dreaded 'assigned but unused variable' warning diff --git a/actionview/test/fixtures/test/test_template_with_block_variable.erb b/actionview/test/fixtures/test/test_template_with_block_variable.erb deleted file mode 100644 index 2ee6a2bbdc..0000000000 --- a/actionview/test/fixtures/test/test_template_with_block_variable.erb +++ /dev/null @@ -1 +0,0 @@ -<%= block %> \ No newline at end of file diff --git a/actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb b/actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb new file mode 100644 index 0000000000..edfe52e422 --- /dev/null +++ b/actionview/test/fixtures/test/test_template_with_delegation_reserved_keywords.erb @@ -0,0 +1 @@ +<%= _ %> <%= arg %> <%= args %> <%= block %> \ No newline at end of file diff --git a/actionview/test/template/compiled_templates_test.rb b/actionview/test/template/compiled_templates_test.rb index a24a245442..40ac867b38 100644 --- a/actionview/test/template/compiled_templates_test.rb +++ b/actionview/test/template/compiled_templates_test.rb @@ -14,10 +14,6 @@ class CompiledTemplatesTest < ActiveSupport::TestCase render(file: "test/render_file_with_ruby_keyword_locals", locals: { class: "foo" }) end - def test_template_with_block_variable - assert_equal "foo", render(file: "test/test_template_with_block_variable", locals: { block: "foo" }) - end - def test_template_with_invalid_identifier_locals locals = { foo: "bar", @@ -28,6 +24,16 @@ class CompiledTemplatesTest < ActiveSupport::TestCase assert_equal locals.inspect, render(file: "test/render_file_inspect_local_assigns", locals: locals) end + def test_template_with_delegation_reserved_keywords + locals = { + _: "one", + arg: "two", + args: "three", + block: "four", + } + assert_equal "one two three four", render(file: "test/test_template_with_delegation_reserved_keywords", locals: locals) + end + def test_template_with_unicode_identifier assert_equal "🎂", render(file: "test/render_file_unicode_local", locals: { 🎃: "🎂" }) end -- cgit v1.2.3 From a6d065e39f9285119d75a05ee46c659f8b3c0db8 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Mon, 21 Nov 2016 21:48:38 +0100 Subject: form_with/fields: Don't output ids by default Continuing 67f81cc where we decided not to output ids by default in the new form helpers. Went with @dhh's suggestion of just requiring ids on fields being labelled: https://github.com/rails/rails/issues/25197#issuecomment-231797117 Seems okay enough. --- actionview/lib/action_view/helpers/form_helper.rb | 31 +- actionview/lib/action_view/helpers/tags/base.rb | 14 +- actionview/lib/action_view/helpers/tags/label.rb | 4 + .../test/template/form_helper/form_with_test.rb | 400 ++++++++++----------- 4 files changed, 243 insertions(+), 206 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index e7ea267211..55389950ed 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -595,6 +595,16 @@ module ActionView # # Where @document = Document.find(params[:id]). # + # When using labels +form_with+ requires setting the id on the field being + # labelled: + # + # <%= form_with(model: @post) do |form| %> + # <%= form.label :title %> + # <%= form.text_field :title, id: :post_title %> + # <% end %> + # + # See +label+ for more on how the +for+ attribute is derived. + # # === Mixing with other form helpers # # While +form_with+ uses a FormBuilder object it's possible to mix and @@ -690,6 +700,8 @@ module ActionView # form_with(**options.merge(builder: LabellingFormBuilder), &block) # end def form_with(model: nil, scope: nil, url: nil, format: nil, **options) + options[:skip_default_ids] = true + if model url ||= polymorphic_path(model, format: format) @@ -986,6 +998,16 @@ module ActionView # or model is yielded, so any generated field names are prefixed with # either the passed scope or the scope inferred from the :model. # + # When using labels +fields+ requires setting the id on the field being + # labelled: + # + # <%= fields :comment do |fields| %> + # <%= fields.label :body %> + # <%= fields.text_field :body, id: :comment_body %> + # <% end %> + # + # See +label+ for more on how the +for+ attribute is derived. + # # === Mixing with other form helpers # # While +form_with+ uses a FormBuilder object it's possible to mix and @@ -1003,7 +1025,8 @@ module ActionView # to work with an object as a base, like # FormOptionHelper#collection_select and DateHelper#datetime_select. def fields(scope = nil, model: nil, **options, &block) - # TODO: Remove when ids and classes are no longer output by default. + options[:skip_default_ids] = true + if model scope ||= model_name_from_record_or_class(model).param_key end @@ -1469,7 +1492,7 @@ module ActionView private def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local: false, skip_enforcing_utf8: false, **options) - html_options = options.except(:index, :include_id, :builder).merge(html) + html_options = options.except(:index, :include_id, :skip_default_ids, :builder).merge(html) html_options[:method] ||= :patch if model.respond_to?(:persisted?) && model.persisted? html_options[:enforce_utf8] = !skip_enforcing_utf8 @@ -1603,7 +1626,7 @@ module ActionView 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) : {} + @default_options = @options ? @options.slice(:index, :namespace, :skip_default_ids) : {} convert_to_legacy_options(@options) @@ -1910,6 +1933,8 @@ module ActionView # See the docs for the ActionView::FormHelper.fields helper method. def fields(scope = nil, model: nil, **options, &block) + options[:skip_default_ids] = true + convert_to_legacy_options(options) fields_for(scope || model, model, **options, &block) diff --git a/actionview/lib/action_view/helpers/tags/base.rb b/actionview/lib/action_view/helpers/tags/base.rb index cf8a6d6028..b8c446cbed 100644 --- a/actionview/lib/action_view/helpers/tags/base.rb +++ b/actionview/lib/action_view/helpers/tags/base.rb @@ -13,6 +13,7 @@ module ActionView @object_name.sub!(/\[\]$/, "") || @object_name.sub!(/\[\]\]$/, "]") @object = retrieve_object(options.delete(:object)) + @skip_default_ids = options.delete(:skip_default_ids) @options = options @auto_index = Regexp.last_match ? retrieve_autoindex(Regexp.last_match.pre_match) : nil end @@ -81,9 +82,12 @@ module ActionView def add_default_name_and_id(options) index = name_and_id_index(options) options["name"] = options.fetch("name") { tag_name(options["multiple"], index) } - options["id"] = options.fetch("id") { tag_id(index) } - if namespace = options.delete("namespace") - options["id"] = options["id"] ? "#{namespace}_#{options['id']}" : namespace + + unless skip_default_ids? + options["id"] = options.fetch("id") { tag_id(index) } + if namespace = options.delete("namespace") + options["id"] = options["id"] ? "#{namespace}_#{options['id']}" : namespace + end end end @@ -154,6 +158,10 @@ module ActionView def name_and_id_index(options) options.key?("index") ? options.delete("index") || "" : @auto_index end + + def skip_default_ids? + @skip_default_ids + end end end end diff --git a/actionview/lib/action_view/helpers/tags/label.rb b/actionview/lib/action_view/helpers/tags/label.rb index b31d5fda66..cab15ae201 100644 --- a/actionview/lib/action_view/helpers/tags/label.rb +++ b/actionview/lib/action_view/helpers/tags/label.rb @@ -73,6 +73,10 @@ module ActionView def render_component(builder) builder.translation end + + def skip_default_ids? + false # The id is used as the `for` attribute. + end end end end diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index c80a2f61b9..4efc93ca08 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -301,10 +301,10 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts/123", "create-post", method: "patch") do "" + - "" + - "" + + "" + + "" + "" + - "" + + "" + "" + "" + "" @@ -322,9 +322,9 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "" + - "" + + "" + "" + - "" + + "" + "" end @@ -345,10 +345,10 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "" + "" + "" end @@ -371,12 +371,12 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "" + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -392,9 +392,9 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "" + - "" + + "" + "" + - "" + + "" + "" end @@ -411,11 +411,11 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "" + - "" + + "" + "" + - "" + + "" + "" + - "" + + "" + "" end @@ -436,13 +436,13 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "" + "" + "" + "" end @@ -466,15 +466,15 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "" + "" + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -491,7 +491,7 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "" + - "" + + "" + "" end @@ -506,7 +506,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", "create-post", method: "patch", multipart: true) do - "" + "" end assert_dom_equal expected, output_buffer @@ -522,7 +522,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch", multipart: true) do - "" + "" end assert_dom_equal expected, output_buffer @@ -561,7 +561,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/44", method: "patch") do - "" + + "" + "" end @@ -579,10 +579,10 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts/123", "create-post", method: "patch") do "" + - "" + - "" + + "" + + "" + "" + - "" + + "" + "" end @@ -609,10 +609,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/", "create-post", method: "delete") do - "" + - "" + + "" + + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -626,10 +626,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/", "create-post", method: "delete") do - "" + - "" + + "" + + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -643,7 +643,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/search", "search-post", method: "get") do - "" + "" end assert_dom_equal expected, output_buffer @@ -657,10 +657,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/", "create-post", method: "patch") do - "" + - "" + + "" + + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -672,7 +672,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/", skip_enforcing_utf8: true) do - "" + "" end assert_dom_equal expected, output_buffer @@ -684,7 +684,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/", skip_enforcing_utf8: false) do - "" + "" end assert_dom_equal expected, output_buffer @@ -698,10 +698,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/", "create-post") do - "" + - "" + + "" + + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -717,10 +717,10 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts/123", method: "patch") do "" + - "" + - "" + + "" + + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -734,10 +734,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + - "" + + "" + + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -752,7 +752,7 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts/123", method: "patch") do "
" + - "
" + + "
" + "" end @@ -770,7 +770,7 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts/123", method: "patch") do "
" + - "
" + + "
" + "" end @@ -800,10 +800,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", "namespace_edit_post_123", "edit_post", method: "patch") do - "" + - "" + + "" + + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -877,7 +877,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + "" end assert_dom_equal expected, output_buffer @@ -897,7 +897,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form do - "" + "" end assert_dom_equal expected, output_buffer @@ -912,8 +912,8 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + - "" + "" + + "" end assert_dom_equal expected, output_buffer @@ -928,8 +928,8 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + - "" + "" + + "" end assert_dom_equal expected, output_buffer @@ -943,7 +943,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + "" end assert_dom_equal expected, output_buffer @@ -957,7 +957,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + "" end assert_dom_equal expected, output_buffer @@ -971,7 +971,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + "" end assert_dom_equal expected, output_buffer @@ -985,7 +985,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + "" end assert_dom_equal expected, output_buffer @@ -999,7 +999,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + "" end assert_dom_equal expected, output_buffer @@ -1019,9 +1019,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + "" end + whole_form("/posts/123", method: "patch") do - "" + "" end assert_dom_equal expected, output_buffer @@ -1038,8 +1038,8 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + '' + + '' end assert_dom_equal expected, output_buffer @@ -1065,9 +1065,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1084,9 +1084,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1103,8 +1103,8 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + '' + + '' end assert_dom_equal expected, output_buffer @@ -1121,8 +1121,8 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + '' + + '' end assert_dom_equal expected, output_buffer @@ -1139,9 +1139,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1159,9 +1159,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1180,11 +1180,11 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1207,11 +1207,11 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1234,10 +1234,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1260,11 +1260,11 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1283,11 +1283,11 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1307,11 +1307,11 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1330,9 +1330,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1351,10 +1351,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1369,7 +1369,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + '' end assert_dom_equal expected, output_buffer @@ -1386,11 +1386,11 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1407,11 +1407,11 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1442,11 +1442,11 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1465,10 +1465,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1485,8 +1485,8 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + '' + + '' end assert_dom_equal expected, output_buffer @@ -1502,8 +1502,8 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + '' + + '' end assert_dom_equal expected, output_buffer @@ -1525,8 +1525,8 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + '' + + '' end assert_dom_equal expected, output_buffer @@ -1611,18 +1611,18 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + - '' + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' end assert_dom_equal expected, output_buffer @@ -1638,7 +1638,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - '' + '' end assert_dom_equal expected, output_buffer @@ -1652,10 +1652,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = - "" + - "" + + "" + + "" + "" + - "" + "" assert_dom_equal expected, output_buffer end @@ -1668,10 +1668,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = - "" + - "" + + "" + + "" + "" + - "" + "" assert_dom_equal expected, output_buffer end @@ -1684,10 +1684,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = - "" + - "" + + "" + + "" + "" + - "" + "" assert_dom_equal expected, output_buffer end @@ -1700,10 +1700,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = - "" + - "" + + "" + + "" + "" + - "" + "" assert_dom_equal expected, output_buffer end @@ -1716,10 +1716,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = - "" + - "" + + "" + + "" + "" + - "" + "" assert_dom_equal expected, output_buffer end @@ -1732,10 +1732,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = - "" + - "" + + "" + + "" + "" + - "" + "" assert_dom_equal expected, output_buffer end @@ -1747,7 +1747,7 @@ class FormWithActsLikeFormForTest < FormWithTest end assert_dom_equal "" + - "", + "", output_buffer end @@ -1758,7 +1758,7 @@ class FormWithActsLikeFormForTest < FormWithTest end assert_dom_equal "" + - "", + "", output_buffer end @@ -1777,10 +1777,10 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", "create-post", method: "patch") do - "" + - "" + + "" + + "" + "" + - "" + "" end assert_dom_equal expected, output_buffer @@ -1797,9 +1797,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", "create-post", method: "patch") do - "" + - "" + - "" + "" + + "" + + "" end assert_dom_equal expected, output_buffer @@ -1813,7 +1813,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "" + "" end assert_dom_equal expected, output_buffer @@ -1837,9 +1837,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "
" + - "
" + - "
" + "
" + + "
" + + "
" end assert_dom_equal expected, output_buffer @@ -1856,9 +1856,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "
" + - "
" + - "
" + "
" + + "
" + + "
" end assert_dom_equal expected, output_buffer @@ -1875,7 +1875,7 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = whole_form("/posts/123", method: "patch") do - "
" + "
" end assert_dom_equal expected, output_buffer @@ -1890,7 +1890,7 @@ class FormWithActsLikeFormForTest < FormWithTest concat f.text_field(:title) end - expected = "
" + expected = "
" assert_dom_equal expected, output_buffer end @@ -1902,7 +1902,7 @@ class FormWithActsLikeFormForTest < FormWithTest concat f.text_field(:title) end - expected = "
" + expected = "
" assert_dom_equal expected, output_buffer end @@ -1915,9 +1915,9 @@ class FormWithActsLikeFormForTest < FormWithTest end expected = - "
" + - "
" + - "
" + "
" + + "
" + + "
" assert_dom_equal expected, output_buffer end -- cgit v1.2.3 From 5b217c3a7f294a74d4680e71ef64047432b9ffc2 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Thu, 15 Dec 2016 01:40:22 -0500 Subject: Avoid invalid attribute on local forms generated by `form_with` Fixes that the following ERB template would result in invalid HTML output: <%= form_with model: Post.new, local: true do |form| %> <% end %> Specifically, the resulting form tag would have a spurious `remote` attribute:
--- actionview/lib/action_view/helpers/form_helper.rb | 4 ---- actionview/test/template/form_helper/form_with_test.rb | 10 ++++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 55389950ed..6c632b8e75 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -2293,10 +2293,6 @@ module ActionView if options.key?(:skip_id) options[:include_id] = !options.delete(:skip_id) end - - if options.key?(:local) - options[:remote] = !options.delete(:local) - end end end end diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index 4efc93ca08..c078b47e14 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -116,6 +116,16 @@ class FormWithActsLikeFormTagTest < FormWithTest assert_dom_equal expected, output_buffer end + + def test_form_with_with_block_in_erb_and_local_true + output_buffer = render_erb("<%= form_with(url: 'http://www.example.com', local: true) do %>Hello world!<% end %>") + + expected = whole_form("http://www.example.com", local: true) do + "Hello world!" + end + + assert_dom_equal expected, output_buffer + end end class FormWithActsLikeFormForTest < FormWithTest -- cgit v1.2.3 From 61075cb79c60ee11fb9050b1a39fa8dcbcd0d71d Mon Sep 17 00:00:00 2001 From: Andreas Maierhofer Date: Thu, 15 Dec 2016 14:16:52 +0100 Subject: Add missing spaces to button_tag api doc [ci skip] (#27369) --- actionview/lib/action_view/helpers/form_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_tag_helper.rb b/actionview/lib/action_view/helpers/form_tag_helper.rb index 7bd473507b..ffc52569f2 100644 --- a/actionview/lib/action_view/helpers/form_tag_helper.rb +++ b/actionview/lib/action_view/helpers/form_tag_helper.rb @@ -461,7 +461,7 @@ module ActionView end # Creates a button element that defines a submit button, - # resetbutton or a generic button which can be used in + # reset button or a generic button which can be used in # JavaScript, for example. You can use the button tag as a regular # submit tag but it isn't supported in legacy browsers. However, # the button tag does allow for richer labels such as images and emphasis, -- cgit v1.2.3 From 2ebed7a36e74ab4609d20152a09b69abf7b94397 Mon Sep 17 00:00:00 2001 From: Pablo Ifran Date: Sat, 17 Dec 2016 10:48:50 -0300 Subject: Add missing option on numbers helper The `delimiter_pattern` option was not present on the documentaion of the helper. --- actionview/lib/action_view/helpers/number_helper.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/number_helper.rb b/actionview/lib/action_view/helpers/number_helper.rb index 75b898c3e9..9e80f0b2ee 100644 --- a/actionview/lib/action_view/helpers/number_helper.rb +++ b/actionview/lib/action_view/helpers/number_helper.rb @@ -171,6 +171,9 @@ module ActionView # to ","). # * :separator - Sets the separator between the # fractional and integer digits (defaults to "."). + # * :delimiter_pattern - Sets a custom regular expression used for + # deriving the placement of delimiter. Helpful when using currency formats + # like INR. # * :raise - If true, raises +InvalidNumberError+ when # the argument is invalid. # @@ -187,6 +190,9 @@ module ActionView # number_with_delimiter(98765432.98, delimiter: " ", separator: ",") # # => 98 765 432,98 # + # number_with_delimiter("123456.78", + # delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/) # => "1,23,456.78" + # # number_with_delimiter("112a", raise: true) # => raise InvalidNumberError def number_with_delimiter(number, options = {}) delegate_number_helper_method(:number_to_delimited, number, options) -- cgit v1.2.3 From b64467ecad9cfa450ec172f59d656c3baced57e6 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 18 Dec 2016 12:14:24 +0100 Subject: Make attributes output in html opt-in. By using `except` any option provided to `form_with` would become an html attribute unless explicitly opted out. This proved annoying when adding new internal keys in the options hash and seeing them pop up in the html output. Prevent this by inverting the `except` to `slice` out the keys we want to allow becoming html attributes, like id and class. --- actionview/lib/action_view/helpers/form_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 6c632b8e75..a94a28306a 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1492,7 +1492,7 @@ module ActionView private def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local: false, skip_enforcing_utf8: false, **options) - html_options = options.except(:index, :include_id, :skip_default_ids, :builder).merge(html) + html_options = options.slice(:id, :class, :multipart, :method, :data).merge(html) html_options[:method] ||= :patch if model.respond_to?(:persisted?) && model.persisted? html_options[:enforce_utf8] = !skip_enforcing_utf8 -- cgit v1.2.3 From 2f197022e41f07f17301e11927b602a001c71192 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 18 Dec 2016 18:13:38 +0100 Subject: [ci skip] Replace remote with local in form_with doc. Remote is gone, long live local. --- actionview/lib/action_view/helpers/form_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index a94a28306a..4a52a69b7b 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -521,7 +521,7 @@ module ActionView # By default +form_with+ attaches the data-remote attribute # submitting the form via an XMLHTTPRequest in the background if an # Unobtrusive JavaScript driver, like rails-ujs, is used. See the - # :remote option for more. + # :local option for more. # # For ease of comparison the examples above left out the submit button, # as well as the auto generated hidden fields that enable UTF-8 support -- cgit v1.2.3 From 9f0f7ec2223ae60ee6e2eab5bc9f036a480e9f81 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 18 Dec 2016 20:01:54 +0100 Subject: form_with: allow methods outside the model. Has the handy effect of making the initial examples in the form_with docs work too. Had to do some finagling such that form_with's without a scope didn't wrap their names in braces ala `[title]`. --- actionview/lib/action_view/helpers/form_helper.rb | 14 +++- actionview/lib/action_view/helpers/tags/base.rb | 17 ++++- .../test/template/form_helper/form_with_test.rb | 81 ++++++++++++++++++---- 3 files changed, 96 insertions(+), 16 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index 4a52a69b7b..c446e5bc55 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -513,6 +513,17 @@ module ActionView # # # + # # Though the fields don't have to correspond to model attributes: + # <%= form_with model: Cat.new do |form| %> + # <%= form.text_field :cats_dont_have_gills %> + # <%= form.text_field :but_in_forms_they_can %> + # <% end %> + # # => + #
+ # + # + #
+ # # The parameters in the forms are accessible in controllers according to # their name nesting. So inputs named +title+ and post[title] are # accessible as params[:title] and params[:post][:title] @@ -700,6 +711,7 @@ module ActionView # form_with(**options.merge(builder: LabellingFormBuilder), &block) # end def form_with(model: nil, scope: nil, url: nil, format: nil, **options) + options[:allow_method_names_outside_object] = true options[:skip_default_ids] = true if model @@ -1626,7 +1638,7 @@ module ActionView 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, :skip_default_ids) : {} + @default_options = @options ? @options.slice(:index, :namespace, :skip_default_ids, :allow_method_names_outside_object) : {} convert_to_legacy_options(@options) diff --git a/actionview/lib/action_view/helpers/tags/base.rb b/actionview/lib/action_view/helpers/tags/base.rb index b8c446cbed..74d6324771 100644 --- a/actionview/lib/action_view/helpers/tags/base.rb +++ b/actionview/lib/action_view/helpers/tags/base.rb @@ -14,6 +14,7 @@ module ActionView @object_name.sub!(/\[\]$/, "") || @object_name.sub!(/\[\]\]$/, "]") @object = retrieve_object(options.delete(:object)) @skip_default_ids = options.delete(:skip_default_ids) + @allow_method_names_outside_object = options.delete(:allow_method_names_outside_object) @options = options @auto_index = Regexp.last_match ? retrieve_autoindex(Regexp.last_match.pre_match) : nil end @@ -26,7 +27,11 @@ module ActionView private def value(object) - object.public_send @method_name if object + if @allow_method_names_outside_object + object.public_send @method_name if object && object.respond_to?(@method_name) + else + object.public_send @method_name if object + end end def value_before_type_cast(object) @@ -93,7 +98,10 @@ module ActionView def tag_name(multiple = false, index = nil) # a little duplication to construct less strings - if index + case + when @object_name.empty? + "#{sanitized_method_name}#{"[]" if multiple}" + when index "#{@object_name}[#{index}][#{sanitized_method_name}]#{"[]" if multiple}" else "#{@object_name}[#{sanitized_method_name}]#{"[]" if multiple}" @@ -102,7 +110,10 @@ module ActionView def tag_id(index = nil) # a little duplication to construct less strings - if index + case + when @object_name.empty? + sanitized_method_name.dup + when index "#{sanitized_object_name}_#{index}_#{sanitized_method_name}" else "#{sanitized_object_name}_#{sanitized_method_name}" diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index c078b47e14..96b797992f 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -323,6 +323,75 @@ class FormWithActsLikeFormForTest < FormWithTest assert_dom_equal expected, output_buffer end + def test_form_with_only_url_on_create + form_with(url: "/posts") do |f| + concat f.label :title, "Label me" + concat f.text_field :title + end + + expected = whole_form("/posts") do + '' + + '' + end + + assert_dom_equal expected, output_buffer + end + + def test_form_with_only_url_on_update + form_with(url: "/posts/123") do |f| + concat f.label :title, 'Label me' + concat f.text_field :title + end + + expected = whole_form("/posts/123") do + '' + + '' + end + + assert_dom_equal expected, output_buffer + end + + def test_form_with_general_attributes + form_with(url: "/posts/123") do |f| + concat f.text_field :no_model_to_back_this_badboy + end + + expected = whole_form("/posts/123") do + '' + end + + assert_dom_equal expected, output_buffer + end + + def test_form_with_attribute_not_on_model + form_with(model: @post) do |f| + concat f.text_field :this_dont_exist_on_post + end + + expected = whole_form("/posts/123", method: :patch) do + '' + end + + assert_dom_equal expected, output_buffer + end + + def test_form_with_doesnt_call_private_or_protected_properties_on_form_object_skipping_value + obj = Class.new do + private def private_property + "That would be great." + end + + protected def protected_property + "I believe you have my stapler." + end + end.new + + form_with(model: obj, scope: "other_name", url: "/", id: "edit-other-name") do |f| + assert_dom_equal '', f.hidden_field(:private_property) + assert_dom_equal '', f.hidden_field(:protected_property) + end + end + def test_form_with_with_collection_radio_buttons post = Post.new def post.active; false; end @@ -599,18 +668,6 @@ class FormWithActsLikeFormForTest < FormWithTest assert_dom_equal expected, output_buffer end - 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 - end.new - - form_with(model: obj, scope: "other_name", url: "/", id: "edit-other-name") do |f| - assert_raise(NoMethodError) { f.hidden_field(:private_property) } - end - end - def test_form_with_with_method_as_part_of_html_options form_with(model: @post, url: "/", id: "create-post", html: { method: :delete }) do |f| concat f.text_field(:title) -- cgit v1.2.3 From a52413ac91bad22de1a25660848f862a0016ba74 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 18 Dec 2016 20:09:21 +0100 Subject: [ci skip] fields don't output ids by default anymore. --- actionview/lib/action_view/helpers/form_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index c446e5bc55..ac4b4196cd 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -988,14 +988,14 @@ module ActionView # <%= fields :comment do |fields| %> # <%= fields.text_field :body %> # <% end %> - # # => + # # => # <% end %> # # => - # + # # # # Using +fields+ with +form_with+: # <%= form_with model: @post do |form| %> -- cgit v1.2.3 From b2672c739b9fe3a5b37249d899bdec9c3b9726cf Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 18 Dec 2016 20:17:52 +0100 Subject: fields: support attributes not on model. Ensure the support works like form_with. --- actionview/lib/action_view/helpers/form_helper.rb | 2 ++ .../test/template/form_helper/form_with_test.rb | 35 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index ac4b4196cd..a66a56d441 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1037,6 +1037,7 @@ module ActionView # to work with an object as a base, like # FormOptionHelper#collection_select and DateHelper#datetime_select. def fields(scope = nil, model: nil, **options, &block) + options[:allow_method_names_outside_object] = true options[:skip_default_ids] = true if model @@ -1945,6 +1946,7 @@ module ActionView # See the docs for the ActionView::FormHelper.fields helper method. def fields(scope = nil, model: nil, **options, &block) + options[:allow_method_names_outside_object] = true options[:skip_default_ids] = true convert_to_legacy_options(options) diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index 96b797992f..dd0883e071 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -935,6 +935,41 @@ class FormWithActsLikeFormForTest < FormWithTest end end + def test_fields_with_attributes_not_on_model + form_with(model: @post) do |f| + concat f.fields(:comment) { |c| + concat c.text_field :dont_exist_on_model + } + end + + expected = whole_form("/posts/123", method: :patch) do + '' + end + + assert_dom_equal expected, output_buffer + end + + def test_fields_with_attributes_not_on_model_deep_nested + @comment.save + form_with(scope: :posts) do |f| + f.fields("post[]", model: @post) do |f2| + f2.text_field(:id) + @post.comments.each do |comment| + concat f2.fields("comment[]", model: comment) { |c| + concat c.text_field(:dont_exist_on_model) + } + end + end + end + + expected = whole_form do + '' + end + + assert_dom_equal expected, output_buffer + end + + def test_nested_fields @comment.body = "Hello World" form_with(model: @post) do |f| -- cgit v1.2.3 From c945da583b8f802216300d037e5a70ebc5da834c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Ifr=C3=A1n?= Date: Tue, 20 Dec 2016 18:12:38 -0300 Subject: Improve `javascript_include_tag` documentation (#27403) Add all the available options, and correct the samples of the `javascript_include_tag`. --- .../lib/action_view/helpers/asset_tag_helper.rb | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index 4e4f4823e6..397a12f137 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -35,18 +35,37 @@ module ActionView # When the Asset Pipeline is enabled, you can pass the name of your manifest as # source, and include other JavaScript or CoffeeScript files inside the manifest. # + # ==== Options + # + # When the last parameter is a hash you can add HTML attributes using that + # parameter. That options supports the following keys as well: + # + # * :extname - Append a extention to the generated url unless the extension + # already exists. This only applies for relative urls. + # * :protocol - Sets the protocol of the generated url, this option only + # applies when a relative url and +host+ options are provided. + # * :host - When a relative url is provided the host is added to the + # that path. + # * :skip_pipeline - This option is used to bypass the asset pipeline + # when it is set to true. + # + # ==== Examples + # # javascript_include_tag "xmlhr" - # # => + # # => + # + # javascript_include_tag "xmlhr", host: "localhost", protocol: "https" + # # => # # javascript_include_tag "template.jst", extname: false - # # => + # # => # # javascript_include_tag "xmlhr.js" - # # => + # # => # # javascript_include_tag "common.javascript", "/elsewhere/cools" - # # => - # # + # # => + # # # # javascript_include_tag "http://www.example.com/xmlhr" # # => -- cgit v1.2.3 From 0dc9eb46ee47b1196583fd860b25242b6421ab1e Mon Sep 17 00:00:00 2001 From: eileencodes Date: Tue, 20 Dec 2016 16:14:42 -0500 Subject: Fix grammar in asset tag documentation Updated the docmentation because "options supports" is not grammatically correct. --- actionview/lib/action_view/helpers/asset_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index 397a12f137..72a094c629 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -38,7 +38,7 @@ module ActionView # ==== Options # # When the last parameter is a hash you can add HTML attributes using that - # parameter. That options supports the following keys as well: + # parameter. The following options are supported: # # * :extname - Append a extention to the generated url unless the extension # already exists. This only applies for relative urls. -- cgit v1.2.3 From be984f02db145c0091c265babd331127c3b408d9 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 23 Dec 2016 23:31:30 +0900 Subject: Unneeded attr_accessor with side effects --- actionview/test/template/form_helper/form_with_test.rb | 4 ---- actionview/test/template/form_helper_test.rb | 4 ---- 2 files changed, 8 deletions(-) (limited to 'actionview') diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index dd0883e071..3d93e89bcb 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -578,8 +578,6 @@ class FormWithActsLikeFormForTest < FormWithTest end def test_form_with_with_file_field_generate_multipart - Post.send :attr_accessor, :file - form_with(model: @post, id: "create-post") do |f| concat f.file_field(:file) end @@ -592,8 +590,6 @@ class FormWithActsLikeFormForTest < FormWithTest end def test_fields_with_file_field_generate_multipart - Comment.send :attr_accessor, :file - form_with(model: @post) do |f| concat f.fields(:comment, model: @post) { |c| concat c.file_field(:file) diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 022bf315ce..4c7134abac 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -1751,8 +1751,6 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_file_field_generate_multipart - Post.send :attr_accessor, :file - form_for(@post, html: { id: "create-post" }) do |f| concat f.file_field(:file) end @@ -1765,8 +1763,6 @@ class FormHelperTest < ActionView::TestCase end def test_fields_for_with_file_field_generate_multipart - Comment.send :attr_accessor, :file - form_for(@post) do |f| concat f.fields_for(:comment, @post) { |c| concat c.file_field(:file) -- cgit v1.2.3 From 21e5fd4a2a1c162ad33708d3e01b1fda165f204d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 19 Dec 2016 19:10:49 +0900 Subject: Describe what we are protecting --- actionview/lib/action_view/helpers/tags/translator.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/tags/translator.rb b/actionview/lib/action_view/helpers/tags/translator.rb index 62b1df81c6..ced835eaa8 100644 --- a/actionview/lib/action_view/helpers/tags/translator.rb +++ b/actionview/lib/action_view/helpers/tags/translator.rb @@ -14,6 +14,8 @@ module ActionView translated_attribute || human_attribute_name end + # TODO Change this to private once we've dropped Ruby 2.2 support. + # Workaround for Ruby 2.2 "private attribute?" warning. protected attr_reader :object_name, :method_and_value, :scope, :model -- cgit v1.2.3 From 1f5bed98551e08b9e8bdfabbfbb0fded665a47c4 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 23 Dec 2016 23:19:23 +0900 Subject: Privatize unneededly protected methods in Action View tests --- actionview/test/abstract_unit.rb | 2 +- actionview/test/activerecord/form_helper_activerecord_test.rb | 2 +- actionview/test/template/form_helper/form_with_test.rb | 2 +- actionview/test/template/form_helper_test.rb | 2 +- actionview/test/template/url_helper_test.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'actionview') diff --git a/actionview/test/abstract_unit.rb b/actionview/test/abstract_unit.rb index 88c7189d22..5bc4151087 100644 --- a/actionview/test/abstract_unit.rb +++ b/actionview/test/abstract_unit.rb @@ -163,7 +163,7 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase # Stub Rails dispatcher so it does not get controller references and # simply return the controller#action as Rack::Body. class StubDispatcher < ::ActionDispatch::Routing::RouteSet::Dispatcher - protected + private def controller_reference(controller_param) controller_param end diff --git a/actionview/test/activerecord/form_helper_activerecord_test.rb b/actionview/test/activerecord/form_helper_activerecord_test.rb index 6152ec4720..0f7960b408 100644 --- a/actionview/test/activerecord/form_helper_activerecord_test.rb +++ b/actionview/test/activerecord/form_helper_activerecord_test.rb @@ -52,7 +52,7 @@ class FormHelperActiveRecordTest < ActionView::TestCase assert_dom_equal expected, output_buffer end - protected + private def hidden_fields(method = nil) txt = %{} diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index 3d93e89bcb..08c685b00f 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -2184,7 +2184,7 @@ class FormWithActsLikeFormForTest < FormWithTest assert_equal 1, initialization_count, "form builder instantiated more than once" end - protected + private def hidden_fields(options = {}) method = options[:method] diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 4c7134abac..4850bc390b 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -3439,7 +3439,7 @@ class FormHelperTest < ActionView::TestCase assert_equal 1, initialization_count, "form builder instantiated more than once" end - protected + private def hidden_fields(options = {}) method = options[:method] diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index 5a2319fe96..1e64385b52 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -810,7 +810,7 @@ class TasksController < ActionController::Base render_default end - protected + private def render_default render inline: "<%= link_to_unless_current('tasks', tasks_path) %>\n" + "<%= link_to_unless_current('tasks', tasks_url) %>" -- cgit v1.2.3 From 0fdd9bd39eb7a90829260a89a4255a87698b13e1 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 24 Dec 2016 07:01:31 +0900 Subject: Wrong rake task name in the document [ci skip] --- actionview/RUNNING_UJS_TESTS.rdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/RUNNING_UJS_TESTS.rdoc b/actionview/RUNNING_UJS_TESTS.rdoc index cbf6bdccc6..a575624a06 100644 --- a/actionview/RUNNING_UJS_TESTS.rdoc +++ b/actionview/RUNNING_UJS_TESTS.rdoc @@ -4,4 +4,4 @@ Ensure that you can build the project and run tests. Run rake ujs:server first, and then run the web tests by visiting http://localhost:4567 in your browser. -rake test:server +rake ujs:server -- cgit v1.2.3 From b232c51435c7da271a0b6259124435108016070e Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sat, 24 Dec 2016 22:08:23 +0900 Subject: No need to nodoc private methods --- actionview/lib/action_view/helpers/cache_helper.rb | 8 ++++---- .../lib/action_view/helpers/tags/collection_check_boxes.rb | 2 +- .../lib/action_view/helpers/tags/collection_helpers.rb | 12 ++++++------ actionview/lib/action_view/helpers/url_helper.rb | 2 +- actionview/lib/action_view/layouts.rb | 2 +- .../lib/action_view/renderer/streaming_template_renderer.rb | 2 +- actionview/lib/action_view/renderer/template_renderer.rb | 4 ++-- actionview/lib/action_view/rendering.rb | 4 ++-- actionview/lib/action_view/template/resolver.rb | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/helpers/cache_helper.rb b/actionview/lib/action_view/helpers/cache_helper.rb index bf1c8ceaed..7fdf0fd0e1 100644 --- a/actionview/lib/action_view/helpers/cache_helper.rb +++ b/actionview/lib/action_view/helpers/cache_helper.rb @@ -215,7 +215,7 @@ module ActionView private - def fragment_name_with_digest(name, virtual_path) #:nodoc: + def fragment_name_with_digest(name, virtual_path) virtual_path ||= @virtual_path if virtual_path name = controller.url_for(name).split("://").last if name.is_a?(Hash) @@ -226,7 +226,7 @@ module ActionView end end - def fragment_for(name = {}, options = nil, &block) #:nodoc: + def fragment_for(name = {}, options = nil, &block) if content = read_fragment_for(name, options) @cache_hit = true content @@ -236,11 +236,11 @@ module ActionView end end - def read_fragment_for(name, options) #:nodoc: + def read_fragment_for(name, options) controller.read_fragment(name, options) end - def write_fragment_for(name, options) #:nodoc: + def write_fragment_for(name, options) # VIEW TODO: Make #capture usable outside of ERB # This dance is needed because Builder can't use capture pos = output_buffer.length diff --git a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb index 0359d4e65d..7252d4f2d9 100644 --- a/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb +++ b/actionview/lib/action_view/helpers/tags/collection_check_boxes.rb @@ -24,7 +24,7 @@ module ActionView builder.check_box + builder.label end - def hidden_field_name #:nodoc: + def hidden_field_name "#{super}[]" end end diff --git a/actionview/lib/action_view/helpers/tags/collection_helpers.rb b/actionview/lib/action_view/helpers/tags/collection_helpers.rb index c8be392865..75d237eb35 100644 --- a/actionview/lib/action_view/helpers/tags/collection_helpers.rb +++ b/actionview/lib/action_view/helpers/tags/collection_helpers.rb @@ -43,7 +43,7 @@ module ActionView # Generate default options for collection helpers, such as :checked and # :disabled. - def default_html_options_for_collection(item, value) #:nodoc: + def default_html_options_for_collection(item, value) html_options = @html_options.dup [:checked, :selected, :disabled, :readonly].each do |option| @@ -67,11 +67,11 @@ module ActionView html_options end - def sanitize_attribute_name(value) #:nodoc: + def sanitize_attribute_name(value) "#{sanitized_method_name}_#{sanitized_value(value)}" end - def render_collection #:nodoc: + def render_collection @collection.map do |item| value = value_for_collection(item, @value_method) text = value_for_collection(item, @text_method) @@ -82,7 +82,7 @@ module ActionView end.join.html_safe end - def render_collection_for(builder_class, &block) #:nodoc: + def render_collection_for(builder_class, &block) options = @options.stringify_keys rendered_collection = render_collection do |item, value, text, default_html_options| builder = instantiate_builder(builder_class, item, value, text, default_html_options) @@ -103,12 +103,12 @@ module ActionView end end - def hidden_field #:nodoc: + def hidden_field hidden_name = @html_options[:name] || hidden_field_name @template_object.hidden_field_tag(hidden_name, "", id: nil) end - def hidden_field_name #:nodoc: + def hidden_field_name "#{tag_name(false, @options[:index])}" end end diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 22cc4b2920..58a4a04dcb 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -614,7 +614,7 @@ module ActionView # # to_form_params({ name: 'Denmark' }, 'country') # # => [{name: 'country[name]', value: 'Denmark'}] - def to_form_params(attribute, namespace = nil) # :nodoc: + def to_form_params(attribute, namespace = nil) attribute = if attribute.respond_to?(:permitted?) unless attribute.permitted? raise ArgumentError, "Attempting to generate a buttom from non-sanitized request parameters!" \ diff --git a/actionview/lib/action_view/layouts.rb b/actionview/lib/action_view/layouts.rb index 7499e3b951..18e395a67f 100644 --- a/actionview/lib/action_view/layouts.rb +++ b/actionview/lib/action_view/layouts.rb @@ -338,7 +338,7 @@ module ActionView # # ==== Returns # * String - A template name - def _implied_layout_name # :nodoc: + def _implied_layout_name controller_path end end diff --git a/actionview/lib/action_view/renderer/streaming_template_renderer.rb b/actionview/lib/action_view/renderer/streaming_template_renderer.rb index 2434250b2d..7ede034492 100644 --- a/actionview/lib/action_view/renderer/streaming_template_renderer.rb +++ b/actionview/lib/action_view/renderer/streaming_template_renderer.rb @@ -29,7 +29,7 @@ module ActionView # This is the same logging logic as in ShowExceptions middleware. # TODO Once "exceptron" is in, refactor this piece to simply re-use exceptron. - def log_error(exception) #:nodoc: + def log_error(exception) logger = ActionView::Base.logger return unless logger diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb index f40bf8f6e2..54317199de 100644 --- a/actionview/lib/action_view/renderer/template_renderer.rb +++ b/actionview/lib/action_view/renderer/template_renderer.rb @@ -44,7 +44,7 @@ module ActionView # Renders the given template. A string representing the layout can be # supplied as well. - def render_template(template, layout_name = nil, locals = nil) #:nodoc: + def render_template(template, layout_name = nil, locals = nil) view, locals = @view, locals || {} render_with_layout(layout_name, locals) do |layout| @@ -54,7 +54,7 @@ module ActionView end end - def render_with_layout(path, locals) #:nodoc: + def render_with_layout(path, locals) layout = path && find_layout(path, locals.keys, [formats.first]) content = yield(layout) diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index b70e7239fc..0e72316eb7 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -91,7 +91,7 @@ module ActionView # Find and render a template based on the options given. # :api: private - def _render_template(options) #:nodoc: + def _render_template(options) variant = options.delete(:variant) assigns = options.delete(:assigns) context = view_context @@ -104,7 +104,7 @@ module ActionView end # Assign the rendered format to look up context. - def _process_format(format) #:nodoc: + def _process_format(format) super lookup_context.formats = [format.to_sym] lookup_context.rendered_format = lookup_context.formats.first diff --git a/actionview/lib/action_view/template/resolver.rb b/actionview/lib/action_view/template/resolver.rb index ed93ebc027..9da13663d7 100644 --- a/actionview/lib/action_view/template/resolver.rb +++ b/actionview/lib/action_view/template/resolver.rb @@ -177,7 +177,7 @@ module ActionView # always check the cache before hitting the resolver. Otherwise, # it always hits the resolver but if the key is present, check if the # resolver is fresher before returning it. - def cached(key, path_info, details, locals) #:nodoc: + def cached(key, path_info, details, locals) name, prefix, partial = path_info locals = locals.map(&:to_s).sort! @@ -191,7 +191,7 @@ module ActionView end # Ensures all the resolver information is set in the template. - def decorate(templates, path_info, details, locals) #:nodoc: + def decorate(templates, path_info, details, locals) cached = nil templates.each do |t| t.locals = locals -- cgit v1.2.3 From 7f998540af7c3398a3dae760e3e5f0218dec8897 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 19 Dec 2016 19:30:36 +0900 Subject: Privatize unneededly protected methods in Action View --- actionview/lib/action_view/log_subscriber.rb | 12 +++++------- actionview/lib/action_view/lookup_context.rb | 16 ++++++++-------- actionview/lib/action_view/record_identifier.rb | 4 ++-- .../lib/action_view/renderer/abstract_renderer.rb | 8 ++++---- actionview/lib/action_view/routing_url_for.rb | 9 +++------ actionview/lib/action_view/template.rb | 18 ++++++++---------- .../lib/action_view/template/handlers/builder.rb | 4 ++-- 7 files changed, 32 insertions(+), 39 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/log_subscriber.rb b/actionview/lib/action_view/log_subscriber.rb index c9f308c2a2..d03e1a51b8 100644 --- a/actionview/lib/action_view/log_subscriber.rb +++ b/actionview/lib/action_view/log_subscriber.rb @@ -51,20 +51,20 @@ module ActionView ActionView::Base.logger end - protected + private EMPTY = "" - def from_rails_root(string) + def from_rails_root(string) # :doc: string = string.sub(rails_root, EMPTY) string.sub!(VIEWS_PATTERN, EMPTY) string end - def rails_root + def rails_root # :doc: @root ||= "#{Rails.root}/" end - def render_count(payload) + def render_count(payload) # :doc: if payload[:cache_hits] "[#{payload[:cache_hits]} / #{payload[:count]} cache hits]" else @@ -72,7 +72,7 @@ module ActionView end end - def cache_message(payload) + def cache_message(payload) # :doc: if payload[:cache_hit] "[cache hit]" else @@ -80,8 +80,6 @@ module ActionView end end - private - def log_rendering_start(payload) info do message = " Rendering #{from_rails_root(payload[:identifier])}" diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index 50faf1b8dd..f385a7cd04 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -93,9 +93,9 @@ module ActionView @cache = old_value end - protected + private - def _set_detail(key, value) + def _set_detail(key, value) # :doc: @details = @details.dup if @details_key @details_key = nil @details[key] = value @@ -149,16 +149,16 @@ module ActionView added_resolvers.times { view_paths.pop } end - protected + private - def args_for_lookup(name, prefixes, partial, keys, details_options) #:nodoc: + def args_for_lookup(name, prefixes, partial, keys, details_options) name, prefixes = normalize_name(name, prefixes) details, details_key = detail_args_for(details_options) [name, prefixes, partial || false, details, details_key, keys] end # Compute details hash and key according to user options (e.g. passed from #render). - def detail_args_for(options) + def detail_args_for(options) # :doc: return @details, details_key if options.empty? # most common path. user_details = @details.merge(options) @@ -171,13 +171,13 @@ module ActionView [user_details, details_key] end - def args_for_any(name, prefixes, partial) # :nodoc: + def args_for_any(name, prefixes, partial) name, prefixes = normalize_name(name, prefixes) details, details_key = detail_args_for_any [name, prefixes, partial || false, details, details_key] end - def detail_args_for_any # :nodoc: + def detail_args_for_any @detail_args_for_any ||= begin details = {} @@ -200,7 +200,7 @@ module ActionView # Support legacy foo.erb names even though we now ignore .erb # as well as incorrectly putting part of the path in the template # name instead of the prefix. - def normalize_name(name, prefixes) #:nodoc: + def normalize_name(name, prefixes) prefixes = prefixes.presence parts = name.to_s.split("/".freeze) parts.shift if parts.first.empty? diff --git a/actionview/lib/action_view/record_identifier.rb b/actionview/lib/action_view/record_identifier.rb index b39acfa0b5..48bea315a9 100644 --- a/actionview/lib/action_view/record_identifier.rb +++ b/actionview/lib/action_view/record_identifier.rb @@ -92,7 +92,7 @@ module ActionView end end - protected + private # Returns a string representation of the key attribute(s) that is suitable for use in an HTML DOM id. # This can be overwritten to customize the default generated string representation if desired. @@ -102,7 +102,7 @@ module ActionView # overwritten version of the method. By default, this implementation passes the key string through a # method that replaces all characters that are invalid inside DOM ids, with valid ones. You need to # make sure yourself that your dom ids are valid, in case you overwrite this method. - def record_key_for_dom_id(record) + def record_key_for_dom_id(record) # :doc: key = convert_to_model(record).to_key key ? key.join(JOIN) : key end diff --git a/actionview/lib/action_view/renderer/abstract_renderer.rb b/actionview/lib/action_view/renderer/abstract_renderer.rb index 3c85be49cd..0b315eb569 100644 --- a/actionview/lib/action_view/renderer/abstract_renderer.rb +++ b/actionview/lib/action_view/renderer/abstract_renderer.rb @@ -25,9 +25,9 @@ module ActionView raise NotImplementedError end - protected + private - def extract_details(options) + def extract_details(options) # :doc: @lookup_context.registered_details.each_with_object({}) do |key, details| value = options[key] @@ -35,7 +35,7 @@ module ActionView end end - def instrument(name, **options) + def instrument(name, **options) # :doc: options[:identifier] ||= (@template && @template.identifier) || @path ActiveSupport::Notifications.instrument("render_#{name}.action_view", options) do |payload| @@ -43,7 +43,7 @@ module ActionView end end - def prepend_formats(formats) + def prepend_formats(formats) # :doc: formats = Array(formats) return if formats.empty? || @lookup_context.html_fallback_for_js diff --git a/actionview/lib/action_view/routing_url_for.rb b/actionview/lib/action_view/routing_url_for.rb index 669cffab1a..f6bd290bf4 100644 --- a/actionview/lib/action_view/routing_url_for.rb +++ b/actionview/lib/action_view/routing_url_for.rb @@ -122,18 +122,15 @@ module ActionView controller.url_options end - def _routes_context #:nodoc: + private + def _routes_context controller end - protected :_routes_context - def optimize_routes_generation? #:nodoc: + def optimize_routes_generation? controller.respond_to?(:optimize_routes_generation?, true) ? controller.optimize_routes_generation? : super end - protected :optimize_routes_generation? - - private def _generate_paths_by_default true diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index 0afdcd1def..45cf7e6a93 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -231,11 +231,11 @@ module ActionView end end - protected + private # Compile a template. This method ensures a template is compiled # just once and removes the source after it is compiled. - def compile!(view) #:nodoc: + def compile!(view) return if @compiled # Templates can be used concurrently in threaded environments @@ -276,7 +276,7 @@ module ActionView # encode the source into Encoding.default_internal. # In general, this means that templates will be UTF-8 inside of Rails, # regardless of the original source encoding. - def compile(mod) #:nodoc: + def compile(mod) encode! method_name = self.method_name code = @handler.call(self) @@ -309,7 +309,7 @@ module ActionView ObjectSpace.define_finalizer(self, Finalizer[method_name, mod]) end - def handle_render_error(view, e) #:nodoc: + def handle_render_error(view, e) if e.is_a?(Template::Error) e.sub_template_of(self) raise e @@ -323,7 +323,7 @@ module ActionView end end - def locals_code #:nodoc: + def locals_code # Only locals with valid variable names get set directly. Others will # still be available in local_assigns. locals = @locals - Module::RUBY_RESERVED_KEYWORDS @@ -333,7 +333,7 @@ module ActionView locals.each_with_object("") { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" } end - def method_name #:nodoc: + protected def method_name #:nodoc: @method_name ||= begin m = "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}" m.tr!("-".freeze, "_".freeze) @@ -341,16 +341,14 @@ module ActionView end end - def identifier_method_name #:nodoc: + def identifier_method_name inspect.tr("^a-z_".freeze, "_".freeze) end - def instrument(action, &block) + def instrument(action, &block) # :doc: ActiveSupport::Notifications.instrument("#{action}.action_view".freeze, instrument_payload, &block) end - private - def instrument_render_template(&block) ActiveSupport::Notifications.instrument("!render_template.action_view".freeze, instrument_payload, &block) end diff --git a/actionview/lib/action_view/template/handlers/builder.rb b/actionview/lib/action_view/template/handlers/builder.rb index e08a5b5db8..494b543152 100644 --- a/actionview/lib/action_view/template/handlers/builder.rb +++ b/actionview/lib/action_view/template/handlers/builder.rb @@ -13,9 +13,9 @@ module ActionView ";xml.target!;" end - protected + private - def require_engine + def require_engine # :doc: @required ||= begin require "builder" true -- cgit v1.2.3 From fc2aa53f875b12df93b0d07932e3ab563b89152c Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 23 Dec 2016 20:39:54 +0900 Subject: self. is not needed when calling its own instance method --- actionview/lib/action_view/template.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index 45cf7e6a93..d56239789d 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -278,7 +278,6 @@ module ActionView # regardless of the original source encoding. def compile(mod) encode! - method_name = self.method_name code = @handler.call(self) # Make sure that the resulting String to be eval'd is in the @@ -333,7 +332,7 @@ module ActionView locals.each_with_object("") { |key, code| code << "#{key} = #{key} = local_assigns[:#{key}];" } end - protected def method_name #:nodoc: + def method_name @method_name ||= begin m = "_#{identifier_method_name}__#{@identifier.hash}_#{__id__}" m.tr!("-".freeze, "_".freeze) -- cgit v1.2.3 From e8ba0c0f21e2660b90f872fa4595156ca6190c77 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 25 Dec 2016 02:29:52 +0900 Subject: "Use assert_nil if expecting nil. This will fail in minitest 6." --- actionview/test/template/asset_tag_helper_test.rb | 2 +- actionview/test/template/capture_helper_test.rb | 14 +++++++------- actionview/test/template/number_helper_test.rb | 14 +++++++------- actionview/test/template/test_case_test.rb | 2 +- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'actionview') diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index 3bdab42f7a..07a6452cc1 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -630,7 +630,7 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase end def test_should_return_nothing_if_asset_host_isnt_configured - assert_equal nil, compute_asset_host("foo") + assert_nil compute_asset_host("foo") end def test_should_current_request_host_is_always_returned_for_request diff --git a/actionview/test/template/capture_helper_test.rb b/actionview/test/template/capture_helper_test.rb index 54bf9b4c33..7f37523eeb 100644 --- a/actionview/test/template/capture_helper_test.rb +++ b/actionview/test/template/capture_helper_test.rb @@ -127,18 +127,18 @@ class CaptureHelperTest < ActionView::TestCase def test_content_for_returns_nil_when_writing assert ! content_for?(:title) - assert_equal nil, content_for(:title, "foo") - assert_equal nil, content_for(:title) { output_buffer << "bar"; nil } - assert_equal nil, content_for(:title) { output_buffer << " \n "; nil } + assert_nil content_for(:title, "foo") + assert_nil content_for(:title) { output_buffer << "bar"; nil } + assert_nil content_for(:title) { output_buffer << " \n "; nil } assert_equal "foobar", content_for(:title) - assert_equal nil, content_for(:title, "foo", flush: true) - assert_equal nil, content_for(:title, flush: true) { output_buffer << "bar"; nil } - assert_equal nil, content_for(:title, flush: true) { output_buffer << " \n "; nil } + assert_nil content_for(:title, "foo", flush: true) + assert_nil content_for(:title, flush: true) { output_buffer << "bar"; nil } + assert_nil content_for(:title, flush: true) { output_buffer << " \n "; nil } assert_equal "bar", content_for(:title) end def test_content_for_returns_nil_when_content_missing - assert_equal nil, content_for(:some_missing_key) + assert_nil content_for(:some_missing_key) end def test_content_for_question_mark diff --git a/actionview/test/template/number_helper_test.rb b/actionview/test/template/number_helper_test.rb index 2a2ada2b36..678120a9c9 100644 --- a/actionview/test/template/number_helper_test.rb +++ b/actionview/test/template/number_helper_test.rb @@ -4,7 +4,7 @@ class NumberHelperTest < ActionView::TestCase tests ActionView::Helpers::NumberHelper def test_number_to_phone - assert_equal nil, number_to_phone(nil) + assert_nil number_to_phone(nil) assert_equal "555-1234", number_to_phone(5551234) assert_equal "(800) 555-1212 x 123", number_to_phone(8005551212, area_code: true, extension: 123) assert_equal "+18005551212", number_to_phone(8005551212, country_code: 1, delimiter: "") @@ -13,7 +13,7 @@ class NumberHelperTest < ActionView::TestCase end def test_number_to_currency - assert_equal nil, number_to_currency(nil) + assert_nil number_to_currency(nil) assert_equal "$1,234,567,890.50", number_to_currency(1234567890.50) assert_equal "$1,234,567,892", number_to_currency(1234567891.50, precision: 0) assert_equal "1,234,567,890.50 - Kč", number_to_currency("-1234567890.50", unit: raw("Kč"), format: "%n %u", negative_format: "%n - %u") @@ -25,7 +25,7 @@ class NumberHelperTest < ActionView::TestCase end def test_number_to_percentage - assert_equal nil, number_to_percentage(nil) + assert_nil number_to_percentage(nil) assert_equal "100.000%", number_to_percentage(100) assert_equal "100.000 %", number_to_percentage(100, format: "%n %") assert_equal "<b>100.000</b> %", number_to_percentage(100, format: "%n %") @@ -43,13 +43,13 @@ class NumberHelperTest < ActionView::TestCase end def test_number_with_delimiter - assert_equal nil, number_with_delimiter(nil) + assert_nil number_with_delimiter(nil) assert_equal "12,345,678", number_with_delimiter(12345678) assert_equal "0", number_with_delimiter(0) end def test_number_with_precision - assert_equal nil, number_with_precision(nil) + assert_nil number_with_precision(nil) assert_equal "-111.235", number_with_precision(-111.2346) assert_equal "111.00", number_with_precision(111, precision: 2) assert_equal "0.00100", number_with_precision(0.001, precision: 5) @@ -57,13 +57,13 @@ class NumberHelperTest < ActionView::TestCase end def test_number_to_human_size - assert_equal nil, number_to_human_size(nil) + assert_nil number_to_human_size(nil) assert_equal "3 Bytes", number_to_human_size(3.14159265) assert_equal "1.2 MB", number_to_human_size(1234567, precision: 2) end def test_number_to_human - assert_equal nil, number_to_human(nil) + assert_nil number_to_human(nil) assert_equal "0", number_to_human(0) assert_equal "1.23 Thousand", number_to_human(1234) assert_equal "489.0 Thousand", number_to_human(489000, precision: 4, strip_insignificant_zeros: false) diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index 41225000f0..3deddd5706 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -50,7 +50,7 @@ module ActionView end test "retrieve non existing config values" do - assert_equal nil, ActionView::Base.new.config.something_odd + assert_nil ActionView::Base.new.config.something_odd end test "works without testing a helper module" do -- cgit v1.2.3 From a46b2f8911c5730c8c56d487b65f7c5627d334ee Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Mon, 26 Dec 2016 11:04:41 +0900 Subject: assert_equal takes expectation first --- actionview/test/template/form_tag_helper_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionview') diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 24ae6b8b90..088f5ae122 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -694,31 +694,31 @@ class FormTagHelperTest < ActionView::TestCase def test_text_area_tag_options_symbolize_keys_side_effects options = { option: "random_option" } text_area_tag "body", "hello world", options - assert_equal options, option: "random_option" + assert_equal({option: "random_option"}, options) end def test_submit_tag_options_symbolize_keys_side_effects options = { option: "random_option" } submit_tag "submit value", options - assert_equal options, option: "random_option" + assert_equal({option: "random_option"}, options) end def test_button_tag_options_symbolize_keys_side_effects options = { option: "random_option" } button_tag "button value", options - assert_equal options, option: "random_option" + assert_equal({option: "random_option"}, options) end def test_image_submit_tag_options_symbolize_keys_side_effects options = { option: "random_option" } image_submit_tag "submit source", options - assert_equal options, option: "random_option" + assert_equal({option: "random_option"}, options) end def test_image_label_tag_options_symbolize_keys_side_effects options = { option: "random_option" } label_tag "submit source", "title", options - assert_equal options, option: "random_option" + assert_equal({option: "random_option"}, options) end def protect_against_forgery? -- cgit v1.2.3 From ebeeceeb2aa34d33337f991607debae715ca061a Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Tue, 27 Dec 2016 12:47:31 +0900 Subject: do not mutate `object_name` of class in `fields_for` Since it affects the entire form, should not mutate `object_name` of class. Fixes #26931 --- actionview/CHANGELOG.md | 6 ++++++ actionview/lib/action_view/helpers/form_helper.rb | 3 ++- actionview/test/template/form_helper_test.rb | 4 +++- 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'actionview') diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md index 8da2e4ae1d..2a38ca7b63 100644 --- a/actionview/CHANGELOG.md +++ b/actionview/CHANGELOG.md @@ -1,3 +1,9 @@ +* Return correct object name in form helper method after `fields_for`. + + Fixes #26931. + + *Yuji Yaginuma* + * Use `ActionView::Resolver.caching?` (`config.action_view.cache_template_loading`) to enable template recompilation. diff --git a/actionview/lib/action_view/helpers/form_helper.rb b/actionview/lib/action_view/helpers/form_helper.rb index a66a56d441..26a625e4fe 100644 --- a/actionview/lib/action_view/helpers/form_helper.rb +++ b/actionview/lib/action_view/helpers/form_helper.rb @@ -1924,10 +1924,11 @@ module ActionView record_name = model_name_from_record_or_class(record_object).param_key end + object_name = @object_name index = if options.has_key?(:index) options[:index] elsif defined?(@auto_index) - self.object_name = @object_name.to_s.sub(/\[\]$/, "") + object_name = object_name.to_s.sub(/\[\]$/, "") @auto_index end diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 4850bc390b..3da3b95114 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -2262,11 +2262,13 @@ class FormHelperTest < ActionView::TestCase concat f.fields_for("comment[]", @comment) { |c| concat c.text_field(:name) } + concat f.text_field(:body) end expected = whole_form("/posts/123", "edit_post[]", "edit_post[]", method: "patch") do "" + - "" + "" + + "" end assert_dom_equal expected, output_buffer -- cgit v1.2.3 From 1d40743af7a98c22faec11af8d1a9f7fe322e67a Mon Sep 17 00:00:00 2001 From: kenta-s Date: Wed, 28 Dec 2016 18:57:53 +0900 Subject: Fix typo in action_view/template.rb [ci skip] --- actionview/lib/action_view/template.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionview') diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index d56239789d..4b793c3b16 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -140,7 +140,7 @@ module ActionView end # Returns whether the underlying handler supports streaming. If so, - # a streaming buffer *may* be passed when it start rendering. + # a streaming buffer *may* be passed when it starts rendering. def supports_streaming? handler.respond_to?(:supports_streaming?) && handler.supports_streaming? end -- cgit v1.2.3 From 010e246756c09f44e901f4fd8e8eab2cb3022e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 28 Dec 2016 21:53:51 -0500 Subject: Fix Rubocop violations and fix documentation visibility Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API. --- actionview/Rakefile | 2 +- actionview/lib/action_view/routing_url_for.rb | 14 ++++++------ .../test/template/form_helper/form_with_test.rb | 3 +-- actionview/test/template/form_helper_test.rb | 6 ++--- actionview/test/template/form_tag_helper_test.rb | 10 ++++----- actionview/test/ujs/config.ru | 4 ++-- actionview/test/ujs/server.rb | 26 +++++++++++----------- 7 files changed, 32 insertions(+), 33 deletions(-) (limited to 'actionview') diff --git a/actionview/Rakefile b/actionview/Rakefile index 48f17062ce..cba4684076 100644 --- a/actionview/Rakefile +++ b/actionview/Rakefile @@ -49,7 +49,7 @@ end namespace :ujs do desc "Starts the test server" task :server do - system 'bundle exec rackup test/ujs/config.ru -p 4567 -s puma' + system "bundle exec rackup test/ujs/config.ru -p 4567 -s puma" end end diff --git a/actionview/lib/action_view/routing_url_for.rb b/actionview/lib/action_view/routing_url_for.rb index f6bd290bf4..687ba7c1b4 100644 --- a/actionview/lib/action_view/routing_url_for.rb +++ b/actionview/lib/action_view/routing_url_for.rb @@ -123,14 +123,14 @@ module ActionView end private - def _routes_context - controller - end + def _routes_context + controller + end - def optimize_routes_generation? - controller.respond_to?(:optimize_routes_generation?, true) ? - controller.optimize_routes_generation? : super - end + def optimize_routes_generation? + controller.respond_to?(:optimize_routes_generation?, true) ? + controller.optimize_routes_generation? : super + end def _generate_paths_by_default true diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index 08c685b00f..3a91c7dce7 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -339,7 +339,7 @@ class FormWithActsLikeFormForTest < FormWithTest def test_form_with_only_url_on_update form_with(url: "/posts/123") do |f| - concat f.label :title, 'Label me' + concat f.label :title, "Label me" concat f.text_field :title end @@ -965,7 +965,6 @@ class FormWithActsLikeFormForTest < FormWithTest assert_dom_equal expected, output_buffer end - def test_nested_fields @comment.body = "Hello World" form_with(model: @post) do |f| diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index 4850bc390b..a345adfe6c 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -1829,9 +1829,9 @@ class FormHelperTest < ActionView::TestCase obj = Class.new do private - def private_property - raise "This method should not be called." - end + def private_property + raise "This method should not be called." + end end.new form_for(obj, as: "other_name", url: "/", html: { id: "edit-other-name" }) do |f| diff --git a/actionview/test/template/form_tag_helper_test.rb b/actionview/test/template/form_tag_helper_test.rb index 088f5ae122..1248a0bb09 100644 --- a/actionview/test/template/form_tag_helper_test.rb +++ b/actionview/test/template/form_tag_helper_test.rb @@ -694,31 +694,31 @@ class FormTagHelperTest < ActionView::TestCase def test_text_area_tag_options_symbolize_keys_side_effects options = { option: "random_option" } text_area_tag "body", "hello world", options - assert_equal({option: "random_option"}, options) + assert_equal({ option: "random_option" }, options) end def test_submit_tag_options_symbolize_keys_side_effects options = { option: "random_option" } submit_tag "submit value", options - assert_equal({option: "random_option"}, options) + assert_equal({ option: "random_option" }, options) end def test_button_tag_options_symbolize_keys_side_effects options = { option: "random_option" } button_tag "button value", options - assert_equal({option: "random_option"}, options) + assert_equal({ option: "random_option" }, options) end def test_image_submit_tag_options_symbolize_keys_side_effects options = { option: "random_option" } image_submit_tag "submit source", options - assert_equal({option: "random_option"}, options) + assert_equal({ option: "random_option" }, options) end def test_image_label_tag_options_symbolize_keys_side_effects options = { option: "random_option" } label_tag "submit source", "title", options - assert_equal({option: "random_option"}, options) + assert_equal({ option: "random_option" }, options) end def protect_against_forgery? diff --git a/actionview/test/ujs/config.ru b/actionview/test/ujs/config.ru index cb961dc140..414c2063c3 100644 --- a/actionview/test/ujs/config.ru +++ b/actionview/test/ujs/config.ru @@ -1,3 +1,3 @@ -$LOAD_PATH.unshift File.expand_path('..', __FILE__) -require 'server' +$LOAD_PATH.unshift File.expand_path("..", __FILE__) +require "server" run UJS::Server diff --git a/actionview/test/ujs/server.rb b/actionview/test/ujs/server.rb index cc02cd8419..25f70baf5f 100644 --- a/actionview/test/ujs/server.rb +++ b/actionview/test/ujs/server.rb @@ -12,7 +12,7 @@ module UJS get "/rails-ujs.js" => Blade::Assets.environment get "/" => "tests#index" match "/echo" => "tests#echo", via: :all - get "/error" => proc {|env| [403, {}, []] } + get "/error" => proc { |env| [403, {}, []] } end config.cache_classes = false @@ -26,7 +26,7 @@ module UJS end module TestsHelper - def jquery_link version + def jquery_link(version) if params[:version] == version "[#{version}]" else @@ -34,7 +34,7 @@ module TestsHelper end end - def cdn_link cdn + def cdn_link(cdn) if params[:cdn] == cdn "[#{cdn}]" else @@ -43,22 +43,22 @@ module TestsHelper end def jquery_src - if params[:version] == 'edge' + if params[:version] == "edge" "/vendor/jquery.js" - elsif params[:cdn] && params[:cdn] == 'googleapis' + elsif params[:cdn] && params[:cdn] == "googleapis" "https://ajax.googleapis.com/ajax/libs/jquery/#{params[:version]}/jquery.min.js" else "http://code.jquery.com/jquery-#{params[:version]}.js" end end - def test_to *names + def test_to(*names) names = ["/vendor/qunit.js", "settings"] + names names.map { |name| script_tag name }.join("\n").html_safe end - def script_tag src - src = "/test/#{src}.js" unless src.index('/') + def script_tag(src) + src = "/test/#{src}.js" unless src.index("/") %().html_safe end @@ -72,20 +72,20 @@ class TestsController < ActionController::Base layout "application" def index - params[:version] ||= ENV['JQUERY_VERSION'] || '1.11.0' - params[:cdn] ||= 'jquery' + params[:version] ||= ENV["JQUERY_VERSION"] || "1.11.0" + params[:cdn] ||= "jquery" render :index end def echo - data = { :params => params.to_unsafe_h }.update(request.env) + data = { params: params.to_unsafe_h }.update(request.env) - if params[:content_type] and params[:content] + if params[:content_type] && params[:content] render inline: params[:content], content_type: params[:content_type] elsif request.xhr? render json: JSON.generate(data) elsif params[:iframe] - payload = JSON.generate(data).gsub('<', '<').gsub('>', '>') + payload = JSON.generate(data).gsub("<", "<").gsub(">", ">") html = <<-HTML