Module: JSONAPI::Testing::TestHelper
- Defined in:
- lib/json_api/testing/test_helper.rb
Overview
Test helper for Rails integration/request tests that provides consistent ‘as: :jsonapi` behavior across all HTTP methods.
Usage in RSpec:
RSpec.configure do |config|
config.include JSONAPI::Testing::TestHelper, type: :request
end
Then use ‘as: :jsonapi` in your tests:
get users_path, params: { filter: { active: true } }, headers:, as: :jsonapi
post users_path, params: payload, headers:, as: :jsonapi
Behavior:
-
GET: Sets Accept header, params go to query string (no body encoding)
-
POST/PATCH/PUT/DELETE: Sets Content-Type and Accept headers, JSON-encodes body
Constant Summary collapse
- JSONAPI_MIME =
"application/vnd.api+json"
Instance Method Summary collapse
- #delete(path, **options) ⇒ Object
- #get(path, **options) ⇒ Object
- #patch(path, **options) ⇒ Object
- #post(path, **options) ⇒ Object
- #put(path, **options) ⇒ Object
Instance Method Details
#delete(path, **options) ⇒ Object
47 48 49 50 |
# File 'lib/json_api/testing/test_helper.rb', line 47 def delete(path, **) = () if [:as] == :jsonapi super end |
#get(path, **options) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/json_api/testing/test_helper.rb', line 24 def get(path, **) if [:as] == :jsonapi = apply_jsonapi_headers(, include_content_type: false) .delete(:as) end super end |
#patch(path, **options) ⇒ Object
37 38 39 40 |
# File 'lib/json_api/testing/test_helper.rb', line 37 def patch(path, **) = () if [:as] == :jsonapi super end |
#post(path, **options) ⇒ Object
32 33 34 35 |
# File 'lib/json_api/testing/test_helper.rb', line 32 def post(path, **) = () if [:as] == :jsonapi super end |
#put(path, **options) ⇒ Object
42 43 44 45 |
# File 'lib/json_api/testing/test_helper.rb', line 42 def put(path, **) = () if [:as] == :jsonapi super end |