aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorRyan Davis <ryand-ruby@zenspider.com>2013-05-03 15:37:18 -0700
committerRyan Davis <ryand-ruby@zenspider.com>2013-05-03 15:37:18 -0700
commitadc049b06fe309a330feea3d3d0b389557357757 (patch)
treea34151578c6df49817616a7238a41f1ee230d3f9 /activesupport/test
parent16ef4e4157a60d342e1649937f226f7eaa9e2cd1 (diff)
downloadrails-adc049b06fe309a330feea3d3d0b389557357757.tar.gz
rails-adc049b06fe309a330feea3d3d0b389557357757.tar.bz2
rails-adc049b06fe309a330feea3d3d0b389557357757.zip
Fixed bad tests to clean up after themselves.
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/json/decoding_test.rb4
-rw-r--r--activesupport/test/json/encoding_test.rb15
-rw-r--r--activesupport/test/message_encryptor_test.rb7
-rw-r--r--activesupport/test/message_verifier_test.rb7
4 files changed, 27 insertions, 6 deletions
diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb
index d1454902e5..a2d1d0dc39 100644
--- a/activesupport/test/json/decoding_test.rb
+++ b/activesupport/test/json/decoding_test.rb
@@ -62,21 +62,25 @@ class TestJSONDecoding < ActiveSupport::TestCase
backends.each do |backend|
TESTS.each do |json, expected|
test "json decodes #{json} with the #{backend} backend" do
+ prev = ActiveSupport.parse_json_times
ActiveSupport.parse_json_times = true
silence_warnings do
ActiveSupport::JSON.with_backend backend do
assert_equal expected, ActiveSupport::JSON.decode(json)
end
end
+ ActiveSupport.parse_json_times = prev
end
end
test "json decodes time json with time parsing disabled with the #{backend} backend" do
+ prev = ActiveSupport.parse_json_times
ActiveSupport.parse_json_times = false
expected = {"a" => "2007-01-01 01:12:34 Z"}
ActiveSupport::JSON.with_backend backend do
assert_equal expected, ActiveSupport::JSON.decode(%({"a": "2007-01-01 01:12:34 Z"}))
end
+ ActiveSupport.parse_json_times = prev
end
end
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 12ce250eb3..8686dcf929 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -82,6 +82,8 @@ class TestJSONEncoding < ActiveSupport::TestCase
constants.grep(/Tests$/).each do |class_tests|
define_method("test_#{class_tests[0..-6].underscore}") do
begin
+ prev = ActiveSupport.use_standard_json_time_format
+
ActiveSupport.escape_html_entities_in_json = class_tests !~ /^Standard/
ActiveSupport.use_standard_json_time_format = class_tests =~ /^Standard/
self.class.const_get(class_tests).each do |pair|
@@ -89,7 +91,7 @@ class TestJSONEncoding < ActiveSupport::TestCase
end
ensure
ActiveSupport.escape_html_entities_in_json = false
- ActiveSupport.use_standard_json_time_format = false
+ ActiveSupport.use_standard_json_time_format = prev
end
end
end
@@ -172,16 +174,21 @@ class TestJSONEncoding < ActiveSupport::TestCase
end
def test_time_to_json_includes_local_offset
+ prev = ActiveSupport.use_standard_json_time_format
ActiveSupport.use_standard_json_time_format = true
with_env_tz 'US/Eastern' do
assert_equal %("2005-02-01T15:15:10-05:00"), ActiveSupport::JSON.encode(Time.local(2005,2,1,15,15,10))
end
ensure
- ActiveSupport.use_standard_json_time_format = false
+ ActiveSupport.use_standard_json_time_format = prev
end
def test_hash_with_time_to_json
+ prev = ActiveSupport.use_standard_json_time_format
+ ActiveSupport.use_standard_json_time_format = false
assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { :time => Time.utc(2009) }.to_json
+ ensure
+ ActiveSupport.use_standard_json_time_format = prev
end
def test_nested_hash_with_float
@@ -302,12 +309,12 @@ class TestJSONEncoding < ActiveSupport::TestCase
assert_equal({"name" => "David",
"sub" => {
"name" => "David",
- "date" => "2010/01/01" }}, JSON.parse(json_custom))
+ "date" => "2010-01-01" }}, JSON.parse(json_custom))
assert_equal({"name" => "David", "email" => "sample@example.com"},
JSON.parse(json_strings))
- assert_equal({"name" => "David", "date" => "2010/01/01"},
+ assert_equal({"name" => "David", "date" => "2010-01-01"},
JSON.parse(json_string_and_date))
end
diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb
index 06c7e8a1a7..509c453b5c 100644
--- a/activesupport/test/message_encryptor_test.rb
+++ b/activesupport/test/message_encryptor_test.rb
@@ -56,9 +56,14 @@ class MessageEncryptorTest < ActiveSupport::TestCase
end
def test_alternative_serialization_method
+ prev = ActiveSupport.use_standard_json_time_format
+ ActiveSupport.use_standard_json_time_format = true
encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.hex(64), SecureRandom.hex(64), :serializer => JSONSerializer.new)
message = encryptor.encrypt_and_sign({ :foo => 123, 'bar' => Time.utc(2010) })
- assert_equal encryptor.decrypt_and_verify(message), { "foo" => 123, "bar" => "2010-01-01T00:00:00Z" }
+ exp = { "foo" => 123, "bar" => "2010-01-01T00:00:00Z" }
+ assert_equal exp, encryptor.decrypt_and_verify(message)
+ ensure
+ ActiveSupport.use_standard_json_time_format = prev
end
private
diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb
index 5adff41653..a8633f7299 100644
--- a/activesupport/test/message_verifier_test.rb
+++ b/activesupport/test/message_verifier_test.rb
@@ -45,9 +45,14 @@ class MessageVerifierTest < ActiveSupport::TestCase
end
def test_alternative_serialization_method
+ prev = ActiveSupport.use_standard_json_time_format
+ ActiveSupport.use_standard_json_time_format = true
verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!", :serializer => JSONSerializer.new)
message = verifier.generate({ :foo => 123, 'bar' => Time.utc(2010) })
- assert_equal verifier.verify(message), { "foo" => 123, "bar" => "2010-01-01T00:00:00Z" }
+ exp = { "foo" => 123, "bar" => "2010-01-01T00:00:00Z" }
+ assert_equal exp, verifier.verify(message)
+ ensure
+ ActiveSupport.use_standard_json_time_format = prev
end
def assert_not_verified(message)