lib/rubocop/cop/rails/freeze_time.rb in rubocop-rails-2.17.2 vs lib/rubocop/cop/rails/freeze_time.rb in rubocop-rails-2.17.3
- old
+ new
@@ -27,21 +27,21 @@
class FreezeTime < Base
extend AutoCorrector
MSG = 'Use `freeze_time` instead of `travel_to`.'
NOW_METHODS = %i[now new current].freeze
- CONV_METHODS = %i[to_time in_time_zone].freeze
+ CONVERT_METHODS = %i[to_time in_time_zone].freeze
RESTRICT_ON_SEND = %i[travel_to].freeze
# @!method time_now?(node)
def_node_matcher :time_now?, <<~PATTERN
- (const nil? {:Time :DateTime})
+ (const {nil? cbase} {:Time :DateTime})
PATTERN
# @!method zoned_time_now?(node)
def_node_matcher :zoned_time_now?, <<~PATTERN
- (send (const nil? :Time) :zone)
+ (send (const {nil? cbase} :Time) :zone)
PATTERN
def on_send(node)
child_node, method_name, time_argument = *node.first_argument&.children
return if time_argument || !child_node
@@ -61,12 +61,14 @@
node.send_type? ? zoned_time_now?(node) : time_now?(node)
end
def current_time_with_convert?(node, method_name)
- return false unless CONV_METHODS.include?(method_name)
+ return false unless CONVERT_METHODS.include?(method_name)
- child_node, child_method_name = *node.children
+ child_node, child_method_name, time_argument = *node.children
+ return if time_argument
+
current_time?(child_node, child_method_name)
end
end
end
end