mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Drop microseconds in job argument assertions
This commit is contained in:
parent
4c8a333ac1
commit
7f038621df
3 changed files with 73 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
* Make job argument assertions with `Time`, `ActiveSupport::TimeWithZone`, and `DateTime` work by dropping microseconds. Microsecond precision is lost during serialization.
|
||||
|
||||
*Gannon McGibbon*
|
||||
|
||||
|
||||
## Rails 6.0.0.beta3 (March 11, 2019) ##
|
||||
|
||||
* No changes.
|
||||
|
|
|
@ -631,6 +631,20 @@ module ActiveJob
|
|||
def prepare_args_for_assertion(args)
|
||||
args.dup.tap do |arguments|
|
||||
arguments[:at] = arguments[:at].to_f if arguments[:at]
|
||||
arguments[:args] = round_time_arguments(arguments[:args]) if arguments[:args]
|
||||
end
|
||||
end
|
||||
|
||||
def round_time_arguments(argument)
|
||||
case argument
|
||||
when Time, ActiveSupport::TimeWithZone, DateTime
|
||||
argument.change(usec: 0)
|
||||
when Hash
|
||||
argument.transform_values { |value| round_time_arguments(value) }
|
||||
when Array
|
||||
argument.map { |element| round_time_arguments(element) }
|
||||
else
|
||||
argument
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -581,6 +581,33 @@ class EnqueuedJobsTest < ActiveJob::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_assert_enqueued_with_time
|
||||
now = Time.now
|
||||
args = [{ argument1: [now] }]
|
||||
|
||||
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
||||
MultipleKwargsJob.perform_later(argument1: [now])
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_enqueued_with_date_time
|
||||
now = DateTime.now
|
||||
args = [{ argument1: [now] }]
|
||||
|
||||
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
||||
MultipleKwargsJob.perform_later(argument1: [now])
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_enqueued_with_time_with_zone
|
||||
now = Time.now.in_time_zone("Tokyo")
|
||||
args = [{ argument1: [now] }]
|
||||
|
||||
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
||||
MultipleKwargsJob.perform_later(argument1: [now])
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_enqueued_with_with_no_block_args
|
||||
assert_raise ArgumentError do
|
||||
NestedJob.set(wait_until: Date.tomorrow.noon).perform_later
|
||||
|
@ -1681,6 +1708,33 @@ class PerformedJobsTest < ActiveJob::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_assert_performed_with_time
|
||||
now = Time.now
|
||||
args = [{ argument1: { now: now } }]
|
||||
|
||||
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
||||
MultipleKwargsJob.perform_later(argument1: { now: now })
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_performed_with_date_time
|
||||
now = DateTime.now
|
||||
args = [{ argument1: { now: now } }]
|
||||
|
||||
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
||||
MultipleKwargsJob.perform_later(argument1: { now: now })
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_performed_with_time_with_zone
|
||||
now = Time.now.in_time_zone("Tokyo")
|
||||
args = [{ argument1: { now: now } }]
|
||||
|
||||
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
||||
MultipleKwargsJob.perform_later(argument1: { now: now })
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_performed_with_with_global_id_args
|
||||
ricardo = Person.new(9)
|
||||
assert_performed_with(job: HelloJob, args: [ricardo]) do
|
||||
|
|
Loading…
Reference in a new issue