jsonapi.rb icon indicating copy to clipboard operation
jsonapi.rb copied to clipboard

Add links attribute and gem setup fixes

Open sosolidkk opened this issue 6 months ago • 3 comments

What is the current behavior?

  1. Unable to run gem specs after the initial bundle install.
  2. Specs fail after executing bundle exec rake spec.
  3. Missing links attributes as per JSON:API Specification.

What is the new behavior?

1. Solved an issue with Rails secret_key_base config

I couldn't find any mention of secrets or secrets.yml in the project, and it also doesn't have an encrypted secrets file (credentials, secrets.yml.enc), any .env file or a in instruction on README to add the expect ENV var. Because of this, every time I tried to run the project, I encountered the following error:

An error occurred while loading spec_helper.
Failure/Error: secrets.secret_key_base = '_'

NameError:
  undefined local variable or method `secrets' for class Dummy
# ./spec/dummy.rb:87:in `<class:Dummy>'
# ./spec/dummy.rb:86:in `<top (required)>'
# ./spec/spec_helper.rb:10:in `<top (required)>'
No examples found.
No examples found.


Finished in 0.00003 seconds (files took 1.09 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

Finished in 0.00003 seconds (files took 1.09 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples

To address this, I updated the configuration to match what the Rails::Application object expects. Now, the specs and gem setup work correctly, allowing the tests and QA rake tasks to run as expected without any additional changes.

2. Resolved an Issue with the 422 Error Description

The Rack utils.rb defines the HTTP 422 error as Unprocessable Content, but the specs expect it to be Unprocessable Entity. I'm not entirely sure which is correct, but according to the specification, it should be Unprocessable Content. In any case, I've updated the specs to accept both.

3. Added links Attribute in ErrorSerializer

I implemented a monkey patch in my app to provide this attribute, but I believe it should be included by default, similar to how the code attribute was previously added. Here's the specification reference for this attribute:

Checklist

Please make sure the following requirements are complete:

  • [x] Tests for the changes have been added (for bug fixes / features)
  • [x] Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • [x] All automated checks pass (CI/CD)

sosolidkk avatar Aug 14 '24 14:08 sosolidkk