diff options
-rw-r--r-- | activejob/lib/active_job/core.rb | 2 | ||||
-rw-r--r-- | activejob/test/cases/job_serialization_test.rb | 17 |
2 files changed, 17 insertions, 2 deletions
diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb index 0b32b7263c..f7f882c998 100644 --- a/activejob/lib/active_job/core.rb +++ b/activejob/lib/active_job/core.rb @@ -108,7 +108,7 @@ module ActiveJob self.queue_name = job_data['queue_name'] self.priority = job_data['priority'] self.serialized_arguments = job_data['arguments'] - self.locale = job_data['locale'] || I18n.locale + self.locale = job_data['locale'] || I18n.locale.to_s end private diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb index 4c5a45b658..fa94209889 100644 --- a/activejob/test/cases/job_serialization_test.rb +++ b/activejob/test/cases/job_serialization_test.rb @@ -2,6 +2,7 @@ require 'helper' require 'jobs/gid_job' require 'jobs/hello_job' require 'models/person' +require 'json' class JobSerializationTest < ActiveSupport::TestCase setup do @@ -18,6 +19,20 @@ class JobSerializationTest < ActiveSupport::TestCase assert_equal 'en', HelloJob.new.serialize['locale'] end + test 'serialize and deserialize are symmetric' do + # Round trip a job in memory only + h1 = HelloJob.new + h1.deserialize(h1.serialize) + + # Now verify it's identical to a JSON round trip. + # We don't want any non-native JSON elements in the job hash, + # like symbols. + payload = JSON.dump(h1.serialize) + h2 = HelloJob.new + h2.deserialize(JSON.load(payload)) + assert_equal h1.serialize, h2.serialize + end + test 'deserialize sets locale' do job = HelloJob.new job.deserialize 'locale' => 'es' @@ -27,6 +42,6 @@ class JobSerializationTest < ActiveSupport::TestCase test 'deserialize sets default locale' do job = HelloJob.new job.deserialize({}) - assert_equal :en, job.locale + assert_equal 'en', job.locale end end |