aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test
diff options
context:
space:
mode:
authorSharang Dashputre <sharang.d@gmail.com>2018-09-12 10:52:17 +0530
committerSharang Dashputre <sharang.d@gmail.com>2018-09-21 00:09:40 +0530
commit14e278f876bb0def5378db78f53024c2a7553fa0 (patch)
tree75355b024595f58e351415a541a79b52d63e960c /activejob/test
parentd99d4a58fa5c1344196ab1cb1b162348597f67bf (diff)
downloadrails-14e278f876bb0def5378db78f53024c2a7553fa0.tar.gz
rails-14e278f876bb0def5378db78f53024c2a7553fa0.tar.bz2
rails-14e278f876bb0def5378db78f53024c2a7553fa0.zip
Make `assert_<enqueued|performed>_with()` compare hashes ignoring order of keys
The test helpers now treat `{ a: 1, b: 2 }` and `{ b: 2, a: 1 }` as equals
Diffstat (limited to 'activejob/test')
-rw-r--r--activejob/test/cases/test_helper_test.rb13
-rw-r--r--activejob/test/jobs/multiple_kwargs_job.rb9
2 files changed, 22 insertions, 0 deletions
diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb
index 160b876e85..1e3fcf1fc2 100644
--- a/activejob/test/cases/test_helper_test.rb
+++ b/activejob/test/cases/test_helper_test.rb
@@ -8,6 +8,7 @@ require "jobs/logging_job"
require "jobs/nested_job"
require "jobs/rescue_job"
require "jobs/inherited_job"
+require "jobs/multiple_kwargs_job"
require "models/person"
class EnqueuedJobsTest < ActiveJob::TestCase
@@ -555,6 +556,12 @@ class EnqueuedJobsTest < ActiveJob::TestCase
assert_enqueued_with(job: HelloJob, at: Date.tomorrow.noon)
end
+ def test_assert_enqueued_with_with_hash_arg
+ assert_enqueued_with(job: MultipleKwargsJob, args: [{ argument1: 1, argument2: { a: 1, b: 2 } }]) do
+ MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
+ end
+ end
+
def test_assert_enqueued_with_with_global_id_args
ricardo = Person.new(9)
assert_enqueued_with(job: HelloJob, args: [ricardo]) do
@@ -1566,6 +1573,12 @@ class PerformedJobsTest < ActiveJob::TestCase
end
end
+ def test_assert_performed_with_with_hash_arg
+ assert_performed_with(job: MultipleKwargsJob, args: [{ argument1: 1, argument2: { a: 1, b: 2 } }]) do
+ MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
+ end
+ end
+
def test_assert_performed_with_with_global_id_args
ricardo = Person.new(9)
assert_performed_with(job: HelloJob, args: [ricardo]) do
diff --git a/activejob/test/jobs/multiple_kwargs_job.rb b/activejob/test/jobs/multiple_kwargs_job.rb
new file mode 100644
index 0000000000..b355c4ce1a
--- /dev/null
+++ b/activejob/test/jobs/multiple_kwargs_job.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+require_relative "../support/job_buffer"
+
+class MultipleKwargsJob < ActiveJob::Base
+ def perform(argument1:, argument2:)
+ JobBuffer.add("Job with argument1: #{argument1}, argument2: #{argument2}")
+ end
+end