diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 5cc998fa..3dd5fbd7 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ 'develop' ] + branches: ["develop"] pull_request: - branches: ['**'] + branches: ["**"] jobs: tests: @@ -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: diff --git a/Gemfile b/Gemfile index 2dc5e6be..55383160 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Rakefile b/Rakefile index 7c629c8a..070b26fb 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/jsonapi-resources.gemspec b/jsonapi-resources.gemspec index 7b5e1397..71bfd308 100644 --- a/jsonapi-resources.gemspec +++ b/jsonapi-resources.gemspec @@ -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' diff --git a/lib/jsonapi/resources/version.rb b/lib/jsonapi/resources/version.rb index d9a2c2ba..1910ee68 100644 --- a/lib/jsonapi/resources/version.rb +++ b/lib/jsonapi/resources/version.rb @@ -1,5 +1,5 @@ module JSONAPI module Resources - VERSION = '0.1.3' + VERSION = '0.1.4' end end diff --git a/lib/jsonapi/routing_ext.rb b/lib/jsonapi/routing_ext.rb index 77af89e7..1aa3b464 100644 --- a/lib/jsonapi/routing_ext.rb +++ b/lib/jsonapi/routing_ext.rb @@ -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 @@ -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 diff --git a/test/integration/requests/request_test.rb b/test/integration/requests/request_test.rb index f6ff20e7..fbbadd14 100644 --- a/test/integration/requests/request_test.rb +++ b/test/integration/requests/request_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index a74f4a18..1003fe84 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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' @@ -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