Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8f9c257
style: lint ci
StephenHulme Aug 20, 2026
b284212
ci: actions/checkout version
StephenHulme Aug 20, 2026
6e868d4
ci: update Rails versions in test matrix
StephenHulme Aug 20, 2026
f802996
build: update min versions
StephenHulme Jul 3, 2026
9cee43c
build: limit rails versions to 7.2, 8.0+, not including 9+
StephenHulme Aug 20, 2026
88487bb
build: add rack 2 as a dependency
StephenHulme Aug 20, 2026
41c6eaa
release: bump version
StephenHulme Aug 11, 2026
8dbb966
test: repair old ruby 2 -> 3 errors
StephenHulme Aug 11, 2026
917c37c
build: add minitest-mock as a development dependency
StephenHulme Jul 3, 2026
d5afb85
test: repair test runner not being invoked
StephenHulme Aug 11, 2026
ed2929e
build: add minitest reporters for better test feedback
StephenHulme Aug 11, 2026
20f32ec
test: reduce verbosity of minitest output
StephenHulme Aug 11, 2026
5ec8202
test: separate rails version text
StephenHulme Aug 17, 2026
1154079
test: ignore temporary test files
StephenHulme Aug 12, 2026
8ace43f
test: update deprecation warning test
StephenHulme Aug 17, 2026
de41a93
fix: use Rails 8 style deprecation warning messages
StephenHulme Aug 17, 2026
1dab6ce
fix: improve handling of deprecation warnings
StephenHulme Aug 17, 2026
fd893ea
fix: repair deprecated code
StephenHulme Aug 17, 2026
49b976e
test: remove test-db as part of the rake task run
StephenHulme Aug 20, 2026
3d5dabb
build: add test support for Rails 7.1 for overlap with previous release
StephenHulme Aug 20, 2026
105fb13
docs: update README with Sanger release process
StephenHulme Aug 17, 2026
805e177
docs: update Rails versions aim
StephenHulme Aug 20, 2026
6017814
test: use the best reporter for each test environment
StephenHulme Aug 20, 2026
3463786
test: add patch to Rails version specifier for correct resolution
StephenHulme Aug 20, 2026
315d19c
test: file deprecation behaviour silencing for Rails 7.2
StephenHulme Aug 20, 2026
5bc93eb
fix: remove Rails 4 routing
StephenHulme Aug 20, 2026
6c55de1
fix: add support for keyword options in resources
StephenHulme Aug 20, 2026
ad1a448
test: update error message for Rails 8.1
StephenHulme Aug 17, 2026
042816e
test: handle different database True when on SQLite 8.1
StephenHulme Aug 20, 2026
ff5107f
build: set development rails to 8.1
StephenHulme Aug 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ 'master' ]
branches: ["master"]
Comment thread
BenTopping marked this conversation as resolved.
pull_request:
branches: ['**']
branches: ["**"]

jobs:
tests:
Expand All @@ -13,21 +13,22 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.4'
- '3.3'
- '3.2'
- "3.2"
- "3.3"
- "3.4"
rails:
- '7.1'
- '7.0'
- '8.0.2'
- "7.1"
- "7.2"
- "8.0"
- "8.1"
database_url:
- sqlite3:test_db
env:
RAILS_VERSION: ${{ matrix.rails }}
DATABASE_URL: ${{ matrix.database_url }}
name: Ruby ${{ matrix.ruby }} Rails ${{ matrix.rails }} DB ${{ matrix.database_url }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v7
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ coverage
test/log
test_db
test_db-journal
test/test_db-*
.idea
*.iml
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ platforms :jruby do
end

version = ENV['RAILS_VERSION'] || 'default'
# If version is like 'x.y' add a '.0' to make it 'x.y.0' for correct resolution
version = "#{version}.0" if version =~ /^\d+\.\d+$/

platforms :ruby do
gem 'pg'
Expand All @@ -20,7 +22,7 @@ when 'master'
gem 'railties', { git: 'https://github.com/rails/rails.git' }
gem 'arel', { git: 'https://github.com/rails/arel.git' }
when 'default'
gem 'railties', '>= 6.0'
gem 'railties', '~> 8.1.0'
else
gem 'railties', "~> #{version}"
end
56 changes: 48 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# JSONAPI::Resources [![Gem Version](https://badge.fury.io/rb/jsonapi-resources.svg)](https://badge.fury.io/rb/jsonapi-resources) [![Build Status](https://secure.travis-ci.org/cerebris/jsonapi-resources.svg?branch=master)](http://travis-ci.org/cerebris/jsonapi-resources) [![Code Climate](https://codeclimate.com/github/cerebris/jsonapi-resources/badges/gpa.svg)](https://codeclimate.com/github/cerebris/jsonapi-resources)

[![Join the chat at https://gitter.im/cerebris/jsonapi-resources](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cerebris/jsonapi-resources?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
# JSONAPI::Resources (Sanger fork)

`JSONAPI::Resources`, or "JR", provides a framework for developing an API server that complies with the
[JSON:API](http://jsonapi.org/) specification.
Expand All @@ -13,7 +11,7 @@ backed by ActiveRecord models or by custom objects.

## Documentation

Full documentation can be found at [http://jsonapi-resources.com](http://jsonapi-resources.com), including the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/) specific to this version.
Full documentation can be found at [http://jsonapi-resources.com](http://jsonapi-resources.com), including the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/) specific to this version.

## Demo App

Expand All @@ -22,31 +20,73 @@ We have a simple demo app, called [Peeps](https://github.com/cerebris/peeps), av
## Client Libraries

JSON:API maintains a (non-verified) listing of [client libraries](http://jsonapi.org/implementations/#client-libraries)
which *should* be compatible with JSON:API compliant server implementations such as JR.
which _should_ be compatible with JSON:API compliant server implementations such as JR.

## Installation

Add JR to your application's `Gemfile`:

```
```
gem 'jsonapi-resources'
```

And then execute:

```bash
```bash
bundle
```

Or install it yourself as:

```bash
```bash
gem install jsonapi-resources
```

**For further usage see the [v0.10 alpha Guide](http://jsonapi-resources.com/v0.10/guide/)**

## Sanger-specific release process

There are two versions of the gem which we use for production. The version 1 series has unique customisations and is used by Sequencescape. The version 2 series is a more generic version which is used by Traction.

The aim is to support the 3 most recent Rails versions for each series to allow for seamless upgrades between releases.

Check which versions we have published at https://rubygems.org/gems/sanger-jsonapi-resources

### For version 1 series

- Create a branch from **develop**, apply fixes.
- Change version number in `lib/jsonapi/resources/version.rb` . This file is read by the gemspec during publication.
- Test Sequencescape with the gem from the branch.
- Merge the branch into develop.
- Create a release from the develop branch with the new version number as the tag. Set Release label to _None_.
<!-- list separator -->
- Checkout the newly-created tag on develop.
- Execute `bundle install` to ensure the gemspec is up to date.
- Execute `gem build jsonapi-resources.gemspec` which builds sanger-jsonapi-resources-0.1.x.gem in this case.
- Execute `gem push sanger-jsonapi-resources-0.1.x.gem` which publishes the gem.

### For version 2 series

- Create a branch from **master**, apply fixes.
- Change version number in `lib/jsonapi/resources/version.rb` . This file is read by the gemspec during publication.
- Test Traction with the gem from the branch.
- Merge the branch into master.
- Create a release from the master branch with the new version number as the tag. Set Release label to _Latest_.
<!-- list separator -->
- Checkout the newly-created tag on master.
- Execute `bundle install` to ensure the gemspec is up to date.
- Execute `gem build jsonapi-resources.gemspec` which builds sanger-jsonapi-resources-0.2.x.gem in this case.
- Execute `gem push sanger-jsonapi-resources-0.2.x.gem` which publishes the gem.

### Publication

You will be notified by email for each. You will also receive one email for API key setup. The first push will ask email and password for the account, which are in KeePass (search for "gem").

> [!NOTE]
> The email and password for gem publication is a recent addition to the credentials database. Pull latest changes in the credentials repo.

## Contributing

See CONTRIBUTING.md for details.

## License
Expand Down
9 changes: 8 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
#!/usr/bin/env rake
require 'bundler/gem_tasks'
require 'fileutils'
require 'rake/testtask'

task :remove_test_db do
FileUtils.rm_f(File.expand_path('test/test_db', __dir__))
end

Rake::TestTask.new do |t|
t.verbose = true
t.verbose = false
t.warning = false
t.test_files = FileList['test/**/*_test.rb']
end

Rake::Task[:test].enhance([:remove_test_db])

task default: [:test]

desc 'Run benchmarks'
Expand Down
11 changes: 7 additions & 4 deletions jsonapi-resources.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']
spec.required_ruby_version = '>= 2.3'
spec.required_ruby_version = '>= 3.2'

spec.add_development_dependency 'bundler', '>= 1.17'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'minitest', '~> 5.10', '!= 5.10.2'
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'minitest-mock'
spec.add_development_dependency 'minitest-spec-rails'
spec.add_development_dependency 'minitest-reporters'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'concurrent-ruby-ext'
spec.add_development_dependency 'database_cleaner'
spec.add_dependency 'activerecord', '>= 5.1'
spec.add_dependency 'railties', '>= 5.1'
spec.add_dependency 'activerecord', '>= 7.1', '< 9.0' # versions 7.1, 7.2, 8.0, 8.1, and above, but not 9.0
spec.add_dependency 'railties', '>= 7.1', '< 9.0' # versions 7.1, 7.2, 8.0, 8.1, and above, but not 9.0
spec.add_dependency 'rack', '~> 2.0'
Comment thread
BenTopping marked this conversation as resolved.
spec.add_dependency 'concurrent-ruby'
end
9 changes: 2 additions & 7 deletions lib/jsonapi/compatibility_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@
# JSONAPI::CompatibilityHelper.deprecation_warn("Your deprecation message")
#
# The method will use the public `warn` method if available, otherwise it will
# use `send(:warn, ...)` to maintain compatibility with Rails 8+ where `warn`
# is private.
# use Rails 8+ style deprecation warnings.
#
# Example:
# JSONAPI::CompatibilityHelper.deprecation_warn("This feature is deprecated.")

module JSONAPI
module CompatibilityHelper
def deprecation_warn(message)
if ActiveSupport::Deprecation.respond_to?(:warn) && ActiveSupport::Deprecation.public_method_defined?(:warn)
ActiveSupport::Deprecation.warn(message)
else
ActiveSupport::Deprecation.send(:warn, message)
end
ActiveSupport::Deprecation.new(nil, 'JSONAPI').warn(message)
end
module_function :deprecation_warn
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jsonapi/resources/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module JSONAPI
module Resources
VERSION = '0.3.0'
VERSION = '0.4.0'
end
end
35 changes: 4 additions & 31 deletions lib/jsonapi/routing_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,14 @@ def jsonapi_resource(*resources, &_block)
options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy')
end

resource @resource_type, options do
# :nocov:
if @scope.respond_to? :[]=
# Rails 4
@scope[:jsonapi_resource] = @resource_type

resource @resource_type, **options do
jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do
if block_given?
yield
else
jsonapi_relationships
end
else
# Rails 5
jsonapi_resource_scope(SingletonResource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do
if block_given?
yield
else
jsonapi_relationships
end
end
end
# :nocov:
end
end

Expand Down Expand Up @@ -121,27 +107,14 @@ def jsonapi_resources(*resources, &_block)
options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy')
end

resources @resource_type, options do
# :nocov:
if @scope.respond_to? :[]=
# Rails 4
@scope[:jsonapi_resource] = @resource_type
resources @resource_type, **options do
jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do
if block_given?
yield
else
jsonapi_relationships
end
else
# Rails 5
jsonapi_resource_scope(Resource.new(@resource_type, api_only?, @scope[:shallow], **options), @resource_type) do
if block_given?
yield
else
jsonapi_relationships
end
end
end
# :nocov:
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ class PlanetResource < JSONAPI::Resource
attribute :description

has_many :moons
belongs_to :planet_type
has_one :planet_type

has_many :tags, acts_as_set: true
end
Expand Down
8 changes: 5 additions & 3 deletions test/integration/requests/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ def test_put_invalid_json

assert_equal 400, status
assert_equal 'Bad Request', json_response['errors'][0]['title']
assert_match 'unexpected token at', json_response['errors'][0]['detail']
rails_old_msg = 'unexpected token at'
rails_8_1_msg = "expected ',' or '}' after object value, got: '\"attributes\":'"
assert_match (/(#{rails_old_msg}|#{rails_8_1_msg})/), json_response['errors'][0]['detail']
end

def test_put_valid_json_but_array
Expand Down Expand Up @@ -1367,7 +1369,7 @@ def test_deprecated_include_parameter_not_allowed
end

def test_deprecated_include_message
ActiveSupport::Deprecation.silenced = false
set_deprecation_behavior(:report)
original_config = JSONAPI.configuration.dup
_out, err = capture_io do
eval <<-CODE
Expand All @@ -1377,7 +1379,7 @@ def test_deprecated_include_message
assert_match /DEPRECATION WARNING: `allow_include` has been replaced by `default_allow_include_to_one` and `default_allow_include_to_many` options./, err
ensure
JSONAPI.configuration = original_config
ActiveSupport::Deprecation.silenced = true
set_deprecation_behavior(:silence)
end


Expand Down
Loading