aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/serializers/json_serialization_test.rb
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-12-21 02:44:01 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-12-21 06:12:42 +0900
commit892e38c78e03c11afaa5f01d995e3a21bd92b415 (patch)
tree628ab7a9e9e81ee778844acfd25860e2bd3ccf20 /activemodel/test/cases/serializers/json_serialization_test.rb
parentd5699198a45a91250e1adb3ed899b0b46b4ac879 (diff)
downloadrails-892e38c78e03c11afaa5f01d995e3a21bd92b415.tar.gz
rails-892e38c78e03c11afaa5f01d995e3a21bd92b415.tar.bz2
rails-892e38c78e03c11afaa5f01d995e3a21bd92b415.zip
Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
Diffstat (limited to 'activemodel/test/cases/serializers/json_serialization_test.rb')
-rw-r--r--activemodel/test/cases/serializers/json_serialization_test.rb48
1 files changed, 22 insertions, 26 deletions
diff --git a/activemodel/test/cases/serializers/json_serialization_test.rb b/activemodel/test/cases/serializers/json_serialization_test.rb
index 625e0a427a..84efc8de0d 100644
--- a/activemodel/test/cases/serializers/json_serialization_test.rb
+++ b/activemodel/test/cases/serializers/json_serialization_test.rb
@@ -26,20 +26,18 @@ class JsonSerializationTest < ActiveModel::TestCase
end
test "should include root in json if include_root_in_json is true" do
- begin
- original_include_root_in_json = Contact.include_root_in_json
- Contact.include_root_in_json = true
- json = @contact.to_json
-
- assert_match %r{^\{"contact":\{}, json
- assert_match %r{"name":"Konata Izumi"}, json
- assert_match %r{"age":16}, json
- assert_includes json, %("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))})
- assert_match %r{"awesome":true}, json
- assert_match %r{"preferences":\{"shows":"anime"\}}, json
- ensure
- Contact.include_root_in_json = original_include_root_in_json
- end
+ original_include_root_in_json = Contact.include_root_in_json
+ Contact.include_root_in_json = true
+ json = @contact.to_json
+
+ assert_match %r{^\{"contact":\{}, json
+ assert_match %r{"name":"Konata Izumi"}, json
+ assert_match %r{"age":16}, json
+ assert_includes json, %("created_at":#{ActiveSupport::JSON.encode(Time.utc(2006, 8, 1))})
+ assert_match %r{"awesome":true}, json
+ assert_match %r{"preferences":\{"shows":"anime"\}}, json
+ ensure
+ Contact.include_root_in_json = original_include_root_in_json
end
test "should include root in json (option) even if the default is set to false" do
@@ -134,19 +132,17 @@ class JsonSerializationTest < ActiveModel::TestCase
end
test "as_json should return a hash if include_root_in_json is true" do
- begin
- original_include_root_in_json = Contact.include_root_in_json
- Contact.include_root_in_json = true
- json = @contact.as_json
-
- assert_kind_of Hash, json
- assert_kind_of Hash, json["contact"]
- %w(name age created_at awesome preferences).each do |field|
- assert_equal @contact.send(field).as_json, json["contact"][field]
- end
- ensure
- Contact.include_root_in_json = original_include_root_in_json
+ original_include_root_in_json = Contact.include_root_in_json
+ Contact.include_root_in_json = true
+ json = @contact.as_json
+
+ assert_kind_of Hash, json
+ assert_kind_of Hash, json["contact"]
+ %w(name age created_at awesome preferences).each do |field|
+ assert_equal @contact.send(field).as_json, json["contact"][field]
end
+ ensure
+ Contact.include_root_in_json = original_include_root_in_json
end
test "from_json should work without a root (class attribute)" do