mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Use with_adapter(&block) to fix failing tests
I missed that the code was changing global state.
This commit is contained in:
parent
580492282f
commit
1a9c62215a
@ -136,23 +136,25 @@ class ActiveModelSerializers::GrapeTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_implicit_formatter
|
def test_implicit_formatter
|
||||||
ActiveModel::Serializer.config.adapter = :json_api
|
|
||||||
get '/grape/render_with_implicit_formatter'
|
|
||||||
|
|
||||||
post = Models.model1
|
post = Models.model1
|
||||||
serializable_resource = serializable(post, adapter: :json_api)
|
serializable_resource = serializable(post, adapter: :json_api)
|
||||||
|
|
||||||
|
with_adapter :json_api do
|
||||||
|
get '/grape/render_with_implicit_formatter'
|
||||||
|
end
|
||||||
|
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
assert_equal serializable_resource.to_json, last_response.body
|
assert_equal serializable_resource.to_json, last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_implicit_formatter_handles_arrays
|
def test_implicit_formatter_handles_arrays
|
||||||
ActiveModel::Serializer.config.adapter = :json_api
|
|
||||||
get '/grape/render_array_with_implicit_formatter'
|
|
||||||
|
|
||||||
posts = Models.all
|
posts = Models.all
|
||||||
serializable_resource = serializable(posts, adapter: :json_api)
|
serializable_resource = serializable(posts, adapter: :json_api)
|
||||||
|
|
||||||
|
with_adapter :json_api do
|
||||||
|
get '/grape/render_array_with_implicit_formatter'
|
||||||
|
end
|
||||||
|
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
assert_equal serializable_resource.to_json, last_response.body
|
assert_equal serializable_resource.to_json, last_response.body
|
||||||
ensure
|
ensure
|
||||||
@ -160,11 +162,12 @@ class ActiveModelSerializers::GrapeTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_implicit_formatter_handles_collections
|
def test_implicit_formatter_handles_collections
|
||||||
ActiveModel::Serializer.config.adapter = :json_api
|
with_adapter :json_api do
|
||||||
get '/grape/render_collection_with_implicit_formatter'
|
get '/grape/render_collection_with_implicit_formatter'
|
||||||
assert last_response.ok?
|
end
|
||||||
|
|
||||||
representation = JSON.parse(last_response.body)
|
representation = JSON.parse(last_response.body)
|
||||||
|
assert last_response.ok?
|
||||||
assert representation.include?('data')
|
assert representation.include?('data')
|
||||||
assert representation['data'].count == Models.collection_per
|
assert representation['data'].count == Models.collection_per
|
||||||
assert representation.include?('links')
|
assert representation.include?('links')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user