Files
growstuff/spec/support/api_request_helpers.rb
T
Brenda Wallace e7387a37e0 Add API tests for dashed keys, resource ownership, and write operations
- Implement tests for handling dashed attribute names in API responses and requests in `dashed_keys_request_spec.rb`.
- Enhance error handling tests in `errors_request_spec.rb` for invalid filters and attributes.
- Refactor garden, harvest, and seed request specs to use shared examples for resource write operations.
- Introduce shared examples in `api_writes.rb` to streamline testing of create, update, and delete actions across various resources.
- Update pagination and sorting tests to include new scenarios for offsets and computed attributes.
- Remove redundant code and improve test clarity by utilizing shared contexts and helper methods.
2026-10-24 18:19:11 +13:00

35 lines
1.0 KiB
Ruby

# frozen_string_literal: true
# Headers, a member holding an API token, and the parsed response body for specs of /api/v1.
RSpec.shared_context 'with an API member' do
let(:member) { create(:member) }
let(:token) do
member.regenerate_api_token
member.api_token.token
end
let(:read_headers) { { 'Accept' => 'application/vnd.api+json' } }
let(:write_headers) { read_headers.merge('Content-Type' => 'application/vnd.api+json') }
let(:auth_headers) { write_headers.merge('Authorization' => "Bearer #{token}") }
# Not a memoised let: specs that make several requests need the body of the latest.
def json
JSON.parse(response.body)
end
# The ids of the resources in the response.
def ids
json['data'].pluck('id')
end
end
module ApiLinkHelpers
# How a resource links to what it is related to.
def related_link(path)
{ 'links' => { 'related' => "http://www.example.com/api/v1/#{path}" } }
end
end
RSpec.configure do |config|
config.include ApiLinkHelpers, file_path: %r{spec/requests/api}
end