actionview 7.1.4 → 7.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -148,6 +148,20 @@ module ActionView
148
148
  # <p><%= alert %></p>
149
149
  # <% end %>
150
150
  #
151
+ # By default, templates will accept any <tt>locals</tt> as keyword arguments
152
+ # and make them available to <tt>local_assigns</tt>. To restrict what
153
+ # <tt>local_assigns</tt> a template will accept, add a <tt>locals:</tt> magic comment:
154
+ #
155
+ # <%# locals: (headline:, alerts: []) %>
156
+ #
157
+ # <h1><%= headline %></h1>
158
+ #
159
+ # <% alerts.each do |alert| %>
160
+ # <p><%= alert %></p>
161
+ # <% end %>
162
+ #
163
+ # Read more about strict locals in {Action View Overview}[https://guides.rubyonrails.org/action_view_overview.html#strict-locals]
164
+ # in the guides.
151
165
 
152
166
  eager_autoload do
153
167
  autoload :Error
@@ -424,9 +438,13 @@ module ActionView
424
438
 
425
439
  method_arguments =
426
440
  if set_strict_locals
427
- "output_buffer, #{set_strict_locals}"
441
+ if set_strict_locals.include?("&")
442
+ "output_buffer, #{set_strict_locals}"
443
+ else
444
+ "output_buffer, #{set_strict_locals}, &_"
445
+ end
428
446
  else
429
- "local_assigns, output_buffer"
447
+ "local_assigns, output_buffer, &_"
430
448
  end
431
449
 
432
450
  # Make sure that the resulting String to be eval'd is in the
@@ -491,6 +509,8 @@ module ActionView
491
509
  ![:keyreq, :key, :keyrest, :nokey].include?(parameter[0])
492
510
  end
493
511
 
512
+ non_kwarg_parameters.pop if non_kwarg_parameters.last == %i(block _)
513
+
494
514
  unless non_kwarg_parameters.empty?
495
515
  mod.undef_method(method_name)
496
516
 
@@ -525,12 +545,15 @@ module ActionView
525
545
  end
526
546
  end
527
547
 
548
+ RUBY_RESERVED_KEYWORDS = ::ActiveSupport::Delegation::RUBY_RESERVED_KEYWORDS
549
+ private_constant :RUBY_RESERVED_KEYWORDS
550
+
528
551
  def locals_code
529
552
  return "" if strict_locals?
530
553
 
531
554
  # Only locals with valid variable names get set directly. Others will
532
555
  # still be available in local_assigns.
533
- locals = @locals - Module::RUBY_RESERVED_KEYWORDS
556
+ locals = @locals - RUBY_RESERVED_KEYWORDS
534
557
 
535
558
  locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
536
559
 
@@ -171,10 +171,9 @@ module ActionView
171
171
  # Almost a duplicate from ActionController::Helpers
172
172
  methods.flatten.each do |method|
173
173
  _helpers_for_modification.module_eval <<~end_eval, __FILE__, __LINE__ + 1
174
- def #{method}(*args, &block) # def current_user(*args, &block)
175
- _test_case.send(:'#{method}', *args, &block) # _test_case.send(:'current_user', *args, &block)
176
- end # end
177
- ruby2_keywords(:'#{method}')
174
+ def #{method}(...) # def current_user(...)
175
+ _test_case.send(:'#{method}', ...) # _test_case.send(:'current_user', ...)
176
+ end # end
178
177
  end_eval
179
178
  end
180
179
  end
@@ -202,7 +201,7 @@ module ActionView
202
201
 
203
202
  setup :setup_with_controller
204
203
 
205
- register_parser :html, -> rendered { Rails::Dom::Testing.html_document.parse(rendered).root }
204
+ register_parser :html, -> rendered { Rails::Dom::Testing.html_document_fragment.parse(rendered) }
206
205
  register_parser :json, -> rendered { JSON.parse(rendered, object_class: ActiveSupport::HashWithIndifferentAccess) }
207
206
 
208
207
  ActiveSupport.run_load_hooks(:action_view_test_case, self)
@@ -416,7 +415,7 @@ module ActionView
416
415
  end]
417
416
  end
418
417
 
419
- def method_missing(selector, *args)
418
+ def method_missing(selector, ...)
420
419
  begin
421
420
  routes = @controller.respond_to?(:_routes) && @controller._routes
422
421
  rescue
@@ -426,16 +425,15 @@ module ActionView
426
425
  if routes &&
427
426
  (routes.named_routes.route_defined?(selector) ||
428
427
  routes.mounted_helpers.method_defined?(selector))
429
- @controller.__send__(selector, *args)
428
+ @controller.__send__(selector, ...)
430
429
  else
431
430
  super
432
431
  end
433
432
  end
434
- ruby2_keywords(:method_missing)
435
433
 
436
434
  def respond_to_missing?(name, include_private = false)
437
435
  begin
438
- routes = defined?(@controller) && @controller.respond_to?(:_routes) && @controller._routes
436
+ routes = @controller.respond_to?(:_routes) && @controller._routes
439
437
  rescue
440
438
  # Don't call routes, if there is an error on _routes call
441
439
  end