Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
16 changes: 8 additions & 8 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: [ 'develop' ]
branches: ["develop"]
pull_request:
branches: ['**']
branches: ["**"]

jobs:
tests:
Expand All @@ -13,13 +13,13 @@ jobs:
fail-fast: false
matrix:
ruby:
- '3.2'
- '3.3'
- '3.4'
- "3.2"
- "3.3"
- "3.4"
rails:
- '7.1'
- '7.2'
- '8.0'
- "7.2"
- "8.0"
- "8.1"
database_url:
- sqlite3:test_db
env:
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ 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+$/

case version
when 'master'
gem 'railties', { git: 'https://github.com/rails/rails.git' }
gem 'arel', { git: 'https://github.com/rails/arel.git' }
when 'default'
gem 'railties', '~> 8.0.0'
gem 'railties', '~> 8.1.0'
else
gem 'railties', "~> #{version}"
end
11 changes: 9 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#!/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

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

task default: [:test]

desc 'Run benchmarks'
namespace :test do
Expand Down
4 changes: 2 additions & 2 deletions jsonapi-resources.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'concurrent-ruby-ext'
spec.add_dependency 'activerecord', '>= 7.1', '< 8.1' # versions 7.1, 7.2, 8.0
spec.add_dependency 'railties', '>= 7.1', '< 8.1' # versions 7.1, 7.2, 8.0
spec.add_dependency 'activerecord', '>= 7.2', '< 9.0' # versions 7.2, 8.0, 8.1, and above, but not 9.0
spec.add_dependency 'railties', '>= 7.2', '< 9.0' # versions 7.2, 8.0, 8.1, and above, but not 9.0
spec.add_dependency 'rack', '~> 3.0'
spec.add_dependency 'concurrent-ruby'
spec.add_runtime_dependency 'csv'
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.1.3'
VERSION = '0.1.4'
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 @@ -38,28 +38,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 @@ -107,27 +93,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
4 changes: 3 additions & 1 deletion test/integration/requests/request_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,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_7_2_msg = 'unexpected token at'
rails_8_1_msg = "expected ',' or '}' after object value, got: '\"attributes\":'"
assert_match (/(#{rails_7_2_msg}|#{rails_8_1_msg})/), json_response['errors'][0]['detail']
end

def test_put_valid_json_but_array
Expand Down
10 changes: 9 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
require File.expand_path('../helpers/functional_helpers', __FILE__)
require File.expand_path('../helpers/configuration_helpers', __FILE__)

Minitest::Reporters.use!
if ENV['CI'] == 'true'
# The SpecReporter is easier to read on GitHub
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
else
Minitest::Reporters.use!
end

Rails.env = 'test'

Expand All @@ -41,6 +46,9 @@
config.json_key_format = :camelized_key
end

puts "-" * 32
puts "Testing With RAILS VERSION #{Rails.version}"
puts "-" * 32

class TestApp < Rails::Application
config.eager_load = false
Expand Down