From 7d07f357ea67addf4ad782405a45db3cb6685c20 Mon Sep 17 00:00:00 2001 From: Igor Gonchar Date: Wed, 16 Dec 2020 10:03:36 +0200 Subject: [PATCH] rails v6.1 compatibility --- .travis.yml | 5 +++++ lib/jsonapi/resource_controller_metal.rb | 4 ++-- test/fixtures/active_record.rb | 2 +- test/integration/requests/request_test.rb | 8 ++++---- test/unit/resource/resource_test.rb | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 187cd740a..24969d811 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ env: - "RAILS_VERSION=5.1.7" - "RAILS_VERSION=5.2.3" - "RAILS_VERSION=6.0.0" + - "RAILS_VERSION=6.1.0" rvm: - 2.3.8 - 2.4.7 @@ -22,5 +23,9 @@ matrix: env: "RAILS_VERSION=6.0.0" - rvm: 2.4.7 env: "RAILS_VERSION=6.0.0" + - rvm: 2.3.8 + env: "RAILS_VERSION=6.1.0" + - rvm: 2.4.7 + env: "RAILS_VERSION=6.1.0" before_install: - gem install bundler --version 1.17.3 diff --git a/lib/jsonapi/resource_controller_metal.rb b/lib/jsonapi/resource_controller_metal.rb index bf5bc9410..11e1a9bfd 100644 --- a/lib/jsonapi/resource_controller_metal.rb +++ b/lib/jsonapi/resource_controller_metal.rb @@ -5,10 +5,10 @@ class ResourceControllerMetal < ActionController::Metal ActionController::Rendering, ActionController::Renderers::All, ActionController::StrongParameters, - ActionController::ForceSSL, + Gem::Requirement.new('< 6.1').satisfied_by?(ActionPack.gem_version) ? ActionController::ForceSSL : nil, ActionController::Instrumentation, JSONAPI::ActsAsResourceController - ].freeze + ].compact.freeze MODULES.each do |mod| include mod diff --git a/test/fixtures/active_record.rb b/test/fixtures/active_record.rb index adbb99969..746307c9d 100644 --- a/test/fixtures/active_record.rb +++ b/test/fixtures/active_record.rb @@ -370,7 +370,7 @@ class Post < ActiveRecord::Base belongs_to :writer, class_name: 'Person', foreign_key: 'author_id' has_many :comments has_and_belongs_to_many :tags, join_table: :posts_tags - has_many :special_post_tags, source: :tag + has_many :special_post_tags has_many :special_tags, through: :special_post_tags, source: :tag belongs_to :section has_one :parent_post, class_name: 'Post', foreign_key: 'parent_post_id' diff --git a/test/integration/requests/request_test.rb b/test/integration/requests/request_test.rb index 4dfc967db..797f588b0 100644 --- a/test/integration/requests/request_test.rb +++ b/test/integration/requests/request_test.rb @@ -1430,7 +1430,7 @@ def test_caching_included_singleton } $test_user = Person.find(1) - assert_equal 2, JSONAPI.configuration.resource_cache.instance_variable_get(:@key_access).length + assert_equal 2, JSONAPI.configuration.resource_cache.instance_variable_get(:@data).length get "/api/v9/people/#{$test_user.id}?include=preferences" assert_jsonapi_response 200 @@ -1477,7 +1477,7 @@ def test_caching_included_singleton ] } - assert_equal 4, JSONAPI.configuration.resource_cache.instance_variable_get(:@key_access).length + assert_equal 4, JSONAPI.configuration.resource_cache.instance_variable_get(:@data).length ensure JSONAPI.configuration = original_config @@ -1522,7 +1522,7 @@ def test_caching_singleton_primary } } - assert_equal 1, JSONAPI.configuration.resource_cache.instance_variable_get(:@key_access).length + assert_equal 1, JSONAPI.configuration.resource_cache.instance_variable_get(:@data).length $test_user = Person.find(1) @@ -1550,7 +1550,7 @@ def test_caching_singleton_primary } } - assert_equal 2, JSONAPI.configuration.resource_cache.instance_variable_get(:@key_access).length + assert_equal 2, JSONAPI.configuration.resource_cache.instance_variable_get(:@data).length ensure JSONAPI.configuration = original_config diff --git a/test/unit/resource/resource_test.rb b/test/unit/resource/resource_test.rb index d6defa527..7fe44bbd8 100644 --- a/test/unit/resource/resource_test.rb +++ b/test/unit/resource/resource_test.rb @@ -13,7 +13,7 @@ class PostWithBadAfterSave < ActiveRecord::Base after_save :do_some_after_save_stuff def do_some_after_save_stuff - errors[:base] << 'Boom! Error added in after_save callback.' + errors.add(:base, 'Boom! Error added in after_save callback.') raise ActiveRecord::RecordInvalid.new(self) end end @@ -23,7 +23,7 @@ class PostWithCustomValidationContext < ActiveRecord::Base validate :api_specific_check, on: :json_api_create def api_specific_check - errors[:base] << 'Record is invalid' + errors.add(:base, 'Record is invalid') end end