lib/rubocop/cop/rails/freeze_time.rb in rubocop-rails-2.16.0 vs lib/rubocop/cop/rails/freeze_time.rb in rubocop-rails-2.16.1

- old
+ new

@@ -41,13 +41,18 @@ def_node_matcher :zoned_time_now?, <<~PATTERN (send (const nil? :Time) :zone) PATTERN def on_send(node) - child_node, method_name = *node.first_argument.children + child_node, method_name, time_argument = *node.first_argument.children + return if time_argument || !child_node return unless current_time?(child_node, method_name) || current_time_with_convert?(child_node, method_name) - add_offense(node) { |corrector| corrector.replace(node, 'freeze_time') } + add_offense(node) do |corrector| + last_argument = node.last_argument + freeze_time_method = last_argument.block_pass_type? ? "freeze_time(#{last_argument.source})" : 'freeze_time' + corrector.replace(node, freeze_time_method) + end end private def current_time?(node, method_name)