diff options
author | Mike Perham <mperham@gmail.com> | 2016-03-09 09:28:16 -0800 |
---|---|---|
committer | Mike Perham <mperham@gmail.com> | 2016-03-09 09:28:16 -0800 |
commit | 8c98186742c5fd3301906c85117f50973989c3dd (patch) | |
tree | 92967363d7508b0e7a2a384e7e7f373af7ee2b8e | |
parent | 702ef37767da7a32d34d29f8936c056d70e8fc56 (diff) | |
download | rails-8c98186742c5fd3301906c85117f50973989c3dd.tar.gz rails-8c98186742c5fd3301906c85117f50973989c3dd.tar.bz2 rails-8c98186742c5fd3301906c85117f50973989c3dd.zip |
Add JSON round trip verification testcase
-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 |