forked from stas/jsonapi.rb
-
Notifications
You must be signed in to change notification settings - Fork 0
Merge upstream master into master #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alecho
wants to merge
49
commits into
SimplyBinary:master
Choose a base branch
from
stas:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Add total records to pagination * Spec for total records
Allow builds sans git.
`#count` will always execute an SQL COUNT query whereas `#size` will check if the records are already loaded (and then call `#length`). It only executes a count when necessary. See https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-size
* Remove hard coded maximum per-page limit of 30. * Don't include total in pagination links. * Wrap default per_page in a method. * Update readme with jsonapi_page_size example. * Skip :records in pagination with next.
Starting with Rails 6.1 ActiveModel::Error is an actual class: > Active Model's errors are now objects with an interface that allows > your application to more easily handle and interact with errors thrown > by models. The feature[1] includes a query interface, enables more > precise testing, and access to error details. > > [1] rails/rails#32313 As a result of this `resource.details` looks slightly different than in previous versions and notably doesn't contain `:message` anymore, if `object.errors.add(:something, message: 'some error')` was used to specify a validation error. https://github.com/rails/rails/blob/2a7ff0a5f54979b14b19f827c99295297dda411d/activemodel/lib/active_model/error.rb#L149 From the test suite: ``` note.errors.add(:title, message: 'has typos') if note.errors.key?(:title) ``` Rails 6.0: ``` { :title=>[{:error=>:invalid, :value=>"BAD_TITLE"}, {:error=>{:message=>"has typos"}}], :quantity=>[{:error=>:less_than, :value=>109, :count=>100}] } ``` Rails 6.1: ``` { :title=>[{:error=>:invalid, :value=>"BAD_TITLE"}, {:error=>:invalid}], :quantity=>[{:error=>:less_than, :value=>100, :count=>100}] } ``` The patch addresses this change by merging the error.message into its detail.
Due to the change in b019536 the validation error message for a required field changes from "$x can't be blank" to "$x must exist".
* Add Ruby 3.0 to test matrix * Exclude Ruby 3 + Rails 5 Rails 5 doesn't support Ruby 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]>
- When resources are empty, but it's an array, we should be removing empty links and meta fields if they are nil. This matches the behaviour in fast_jsonapi: https://github.com/jsonapi-serializer/jsonapi-serializer/blob/master/lib/fast_jsonapi/object_serializer.rb#L71-L72 - Currently, links will be nil if there is 1+ resource, but present when there are none
Thought it would be helpful to add an example similar to how it's done in other sections
Ransack 4 requires explicitly allowlisting ransackable attributes and associations for each model. This causes the specs to fail with the most recent Ransack version. This fixes those spec failures.
* Rubocop fix: Use filter_map instead of map { ... }.compact Currently, builds are failing because of Rubocop complaining about these three lines. * Drop support for Ruby 2.6 Array#filter_map is only introduced in Ruby 2.7. This ensures we're still supporting the 2.x series, but drops support for the now pretty old Ruby 2.6.
* Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Cleanup rubies/rails. --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Stas SUȘCOV <[email protected]>
Test Ruby 3.3 and Rails 6.1 instead
* CI Matrix: Drop Rails 6, Ruby 2.7 Test Ruby 3.3 and Rails 6.1 instead * Refactor error spec The previous specs were harder to read, and they relied on the ordering of the errors, which is unnecessary. * Add spec for non-interpolated error messages * Simplify ActiveModel::ErrorSerializer We're only running CI for Rails 6.1+ now, and we can now rely on a stable API for ActiveModel::Errors.
* Rubocop fix: Use filter_map instead of map { ... }.compact Currently, builds are failing because of Rubocop complaining about these three lines. * Fix specs with Ransack 4.0 Ransack 4 requires explicitly allowlisting ransackable attributes and associations for each model. This causes the specs to fail with the most recent Ransack version. This fixes those spec failures. * Allow decorating objects after pagination This simplification allows decorating objects after they are paginated, without losing the correct total object count. I'm using an instance variable on the including controller here, because the decorating the paginated collection will have us lose the instance variable we set on it. Here's the case where this happens: We have a complex ActiveRecord collection that we run through Ransack and Kaminari, but before rendering we want to convert each object in it using a `SimpleDelegator`. Here's a simplified version of the controller action we're looking at: ``` class UserDecorator < SimpleDelegator def fantastic_for_rendering "Whoah" end end def index allowed_fields = [ :first_name, :last_name, :created_at, :notes_created_at, :notes_quantity ] options = { sort_with_expressions: true } jsonapi_filter(User.all, allowed_fields, options) do |filtered| result = filtered.result jsonapi_paginate(result) do |paginated| paginated = paginated.map { |user| UserDecorator.new() } render jsonapi: paginated end end end ``` --------- Co-authored-by: Stas <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.