mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Use model that doesn't fail with race condition
For some reason, the post would sometimes be serialized as
"{\"id\":\"1\",
+ \"type\":\"posts\", \"attributes\":{\"title\":\"New Post\",\"body\":\"Body\"},
\"comments\":[{\"id\":1,\"body\":\"ZOMG A COMMENT\"}],
\"blog\":{\"id\":999,\"name\":\"Custom blog\"},
\"author\":{\"id\":1,\"name\":\"Joao Moura.\"}}"
instead of:
"{\"id\":1,
- \"title\":\"New Post\",\"body\":\"Body\",
\"comments\":[{\"id\":1,\"body\":\"ZOMG A COMMENT\"}],
\"blog\":{\"id\":999,\"name\":\"Custom blog\"},\
"author\":{\"id\":1,\"name\":\"Joao Moura.\"}}"
To reproduce prior to this PR:
SEED=55284 rake
1) Failure:
ActionController::Serialization::ExplicitSerializerTest#test_render_using_explicit_each_serializer
[active_model_serializers/test/action_controller/explicit_serializer_test.rb:139]:
--- expected
+++ actual
@@ -1 +1 @@
-"{\"id\":1,\"title\":\"New
Post\",\"body\":\"Body\",\"comments\":[{\"id\":1,\"body\":\"ZOMG A
COMMENT\"}],\"blog\":{\"id\":999,\"name\":\"Custom
blog\"},\"author\":{\"id\":1,\"name\":\"Joao Moura.\"}}"
+"{\"id\":\"1\",\"type\":\"posts\",\"attributes\":{\"title\":\"New
Post\",\"body\":\"Body\"},\"comments\":[{\"id\":1,\"body\":\"ZOMG A
COMMENT\"}],\"blog\":{\"id\":999,\"name\":\"Custom
blog\"},\"author\":{\"id\":1,\"name\":\"Joao Moura.\"}}"
137 runs, 211 assertions, 1 failures, 0 errors, 0 skips
rake aborted!
Command failed with status (1): [ruby -I"lib:test"
-r./test/test_helper.rb
"/$HOME/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_test_loader.rb"
"test/action_controller/adapter_selector_test.rb"
"test/action_controller/explicit_serializer_test.rb"
"test/action_controller/json_api_linked_test.rb"
"test/action_controller/rescue_from_test.rb"
"test/action_controller/serialization_scope_name_test.rb"
"test/action_controller/serialization_test.rb"
"test/adapter/fragment_cache_test.rb"
"test/adapter/json/belongs_to_test.rb"
"test/adapter/json/collection_test.rb"
"test/adapter/json/has_many_test.rb"
"test/adapter/json_api/belongs_to_test.rb"
"test/adapter/json_api/collection_test.rb"
"test/adapter/json_api/has_many_embed_ids_test.rb"
"test/adapter/json_api/has_many_explicit_serializer_test.rb"
"test/adapter/json_api/has_many_test.rb"
"test/adapter/json_api/has_one_test.rb"
"test/adapter/json_api/linked_test.rb" "test/adapter/json_test.rb"
"test/adapter/null_test.rb" "test/adapter_test.rb"
"test/array_serializer_test.rb" "test/serializers/adapter_for_test.rb"
"test/serializers/associations_test.rb"
"test/serializers/attribute_test.rb"
"test/serializers/attributes_test.rb" "test/serializers/cache_test.rb"
"test/serializers/configuration_test.rb"
"test/serializers/fieldset_test.rb"
"test/serializers/generators_test.rb" "test/serializers/meta_test.rb"
"test/serializers/options_test.rb"
"test/serializers/serializer_for_test.rb"
"test/serializers/urls_test.rb" ]
/$HOME/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in
`eval'
/$HOME/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in
`<main>'
Tasks: TOP => default => test
(See full trace by running task with --trace)
This commit is contained in:
parent
a5554e0d9f
commit
14439aada4
@ -57,11 +57,10 @@ module ActionController
|
||||
end
|
||||
|
||||
def render_using_explicit_each_serializer
|
||||
@comment = Comment.new({ id: 1, body: 'ZOMG A COMMENT' })
|
||||
@author = Author.new(id: 1, name: 'Joao Moura.')
|
||||
@post = Post.new({ id: 1, title: 'New Post', body: 'Body', comments: [@comment], author: @author })
|
||||
location = Location.new(id: 42, lat: '-23.550520', lng: '-46.633309')
|
||||
place = Place.new(id: 1337, name: 'Amazing Place', locations: [location])
|
||||
|
||||
render json: @post, each_serializer: PostSerializer
|
||||
render json: place, each_serializer: PlaceSerializer
|
||||
end
|
||||
end
|
||||
|
||||
@ -118,25 +117,19 @@ module ActionController
|
||||
get :render_using_explicit_each_serializer
|
||||
|
||||
expected = {
|
||||
id: 1,
|
||||
title: 'New Post',
|
||||
body: 'Body',
|
||||
comments: [
|
||||
id: 1337,
|
||||
name: "Amazing Place",
|
||||
locations: [
|
||||
{
|
||||
id: 1,
|
||||
body: 'ZOMG A COMMENT' }
|
||||
],
|
||||
blog: {
|
||||
id: 999,
|
||||
name: 'Custom blog'
|
||||
},
|
||||
author: {
|
||||
id: 1,
|
||||
name: 'Joao Moura.'
|
||||
}
|
||||
id: 42,
|
||||
lat: "-23.550520",
|
||||
lng: "-46.633309",
|
||||
place: "Nowhere" # is a virtual attribute on LocationSerializer
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert_equal expected.to_json, @response.body
|
||||
assert_equal expected.to_json, response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user