Skip to content

Commit

Permalink
have_enqueued_job supports Time object
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Sep 9, 2019
1 parent 1d56c29 commit e8bc2d9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/rspec/rails/matchers/active_job.rb
Expand Up @@ -140,8 +140,9 @@ def job_match?(job)

def arguments_match?(job)
if @args.any?
args = serialize_and_deserialize_arguments(@args)
deserialized_args = deserialize_arguments(job)
RSpec::Mocks::ArgumentListMatcher.new(*@args).args_match?(*deserialized_args)
RSpec::Mocks::ArgumentListMatcher.new(*args).args_match?(*deserialized_args)
else
true
end
Expand Down Expand Up @@ -172,6 +173,13 @@ def set_expected_number(relativity, count)
end
end

def serialize_and_deserialize_arguments(args)
serialized = ::ActiveJob::Arguments.serialize(args)
::ActiveJob::Arguments.deserialize(serialized)
rescue ::ActiveJob::SerializationError
args
end

def deserialize_arguments(job)
::ActiveJob::Arguments.deserialize(job[:args])
rescue ::ActiveJob::DeserializationError
Expand Down
18 changes: 18 additions & 0 deletions spec/rspec/rails/matchers/active_job_spec.rb
Expand Up @@ -328,6 +328,24 @@ def self.name; "LoggingJob"; end
expect(arg).to eq("asdf")
}
end

if Rails.version.to_f >= 6.0
it "passes with Time" do
usec_time = Time.iso8601('2016-07-01T00:00:00.000001Z')

expect {
hello_job.perform_later(usec_time)
}.to have_enqueued_job(hello_job).with(usec_time)
end

it "passes with ActiveSupport::TimeWithZone" do
usec_time = Time.iso8601('2016-07-01T00:00:00.000001Z').in_time_zone

expect {
hello_job.perform_later(usec_time)
}.to have_enqueued_job(hello_job).with(usec_time)
end
end
end

describe "have_been_enqueued" do
Expand Down

0 comments on commit e8bc2d9

Please sign in to comment.