aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test
diff options
context:
space:
mode:
authorMike Perham <mperham@gmail.com>2016-03-09 09:28:16 -0800
committerMike Perham <mperham@gmail.com>2016-03-09 09:28:16 -0800
commit8c98186742c5fd3301906c85117f50973989c3dd (patch)
tree92967363d7508b0e7a2a384e7e7f373af7ee2b8e /activejob/test
parent702ef37767da7a32d34d29f8936c056d70e8fc56 (diff)
downloadrails-8c98186742c5fd3301906c85117f50973989c3dd.tar.gz
rails-8c98186742c5fd3301906c85117f50973989c3dd.tar.bz2
rails-8c98186742c5fd3301906c85117f50973989c3dd.zip
Add JSON round trip verification testcase
Diffstat (limited to 'activejob/test')
-rw-r--r--activejob/test/cases/job_serialization_test.rb17
1 files changed, 16 insertions, 1 deletions
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