Skip to content

Commit 1a9c622

Browse files
committed
Use with_adapter(&block) to fix failing tests
I missed that the code was changing global state.
1 parent 5804922 commit 1a9c622

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

test/grape_test.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,35 +136,38 @@ def test_formatter_handles_collections
136136
end
137137

138138
def test_implicit_formatter
139-
ActiveModel::Serializer.config.adapter = :json_api
140-
get '/grape/render_with_implicit_formatter'
141-
142139
post = Models.model1
143140
serializable_resource = serializable(post, adapter: :json_api)
144141

142+
with_adapter :json_api do
143+
get '/grape/render_with_implicit_formatter'
144+
end
145+
145146
assert last_response.ok?
146147
assert_equal serializable_resource.to_json, last_response.body
147148
end
148149

149150
def test_implicit_formatter_handles_arrays
150-
ActiveModel::Serializer.config.adapter = :json_api
151-
get '/grape/render_array_with_implicit_formatter'
152-
153151
posts = Models.all
154152
serializable_resource = serializable(posts, adapter: :json_api)
155153

154+
with_adapter :json_api do
155+
get '/grape/render_array_with_implicit_formatter'
156+
end
157+
156158
assert last_response.ok?
157159
assert_equal serializable_resource.to_json, last_response.body
158160
ensure
159161
Models.reset_all
160162
end
161163

162164
def test_implicit_formatter_handles_collections
163-
ActiveModel::Serializer.config.adapter = :json_api
164-
get '/grape/render_collection_with_implicit_formatter'
165-
assert last_response.ok?
165+
with_adapter :json_api do
166+
get '/grape/render_collection_with_implicit_formatter'
167+
end
166168

167169
representation = JSON.parse(last_response.body)
170+
assert last_response.ok?
168171
assert representation.include?('data')
169172
assert representation['data'].count == Models.collection_per
170173
assert representation.include?('links')

0 commit comments

Comments
 (0)