diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 40bd96b671..86ef4c90f7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: fail-fast: false matrix: ruby: ['2.7', '3.0', '3.1', '3.2'] - gemfile: [rack_2_0, rack_3_0, rails_6_0, rails_6_1, rails_7_0, rails_7_1] + gemfile: [rack_2_0, rails_6_0, rails_6_1, rails_7_0] include: - ruby: '2.6' gemfile: rails_5_2 diff --git a/Appraisals b/Appraisals index a9d68682db..cc02edd938 100644 --- a/Appraisals +++ b/Appraisals @@ -16,14 +16,6 @@ appraise 'rails-7' do gem 'rails', '~> 7.0' end -appraise 'rails-edge' do - gem 'rails', github: 'rails/rails' -end - -appraise 'rack-edge' do - gem 'rack', github: 'rack/rack' -end - appraise 'multi_json' do gem 'multi_json', require: 'multi_json' end @@ -39,7 +31,3 @@ end appraise 'rack2' do gem 'rack', '~> 2.0.0' end - -appraise 'rack3' do - gem 'rack', '~> 3.0.0' -end diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e1200ea8a..cd0e7cacb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ #### Features -* [#2353](https://github.com/ruby-grape/grape/pull/2353): Added Rails 7.1 support - [@ericproulx](https://github.com/ericproulx). * [#2360](https://github.com/ruby-grape/grape/pull/2360): Reduce gem size by removing specs - [@ericproulx](https://github.com/ericproulx). * Your contribution here. diff --git a/README.md b/README.md index b0fe3375f5..bb9925a673 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ - [Grape for Enterprise](#grape-for-enterprise) - [Installation](#installation) - [Basic Usage](#basic-usage) -- [Rails 7.1](#rails-71) - [Mounting](#mounting) - [All](#all) - [Rack](#rack) @@ -26,6 +25,7 @@ - [Rails](#rails) - [Rails < 5.2](#rails--52) - [Rails 6.0](#rails-60) + - [Rails >= 7.1](#rails--71) - [Modules](#modules) - [Remounting](#remounting) - [Mount Configuration](#mount-configuration) @@ -269,10 +269,6 @@ module Twitter end ``` -## Rails 7.1 - -Grape's [deprecator](https://api.rubyonrails.org/v7.1.0/classes/ActiveSupport/Deprecation.html) will be added to your application's deprecators [automatically](lib/grape/railtie.rb) as `:grape`, so that your application's configuration can be applied to it. - ## Mounting ### All @@ -396,6 +392,10 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| end ``` +#### Rails >= 7.1 + +You will need to use version >= 2.0.0 of Grape as that supports Rack >= 3.0, which Rails bumped to in >= 7.1. + ### Modules You can mount multiple API implementations inside another one. These don't have to be diff --git a/gemfiles/rack_3_0.gemfile b/gemfiles/rack_3_0.gemfile deleted file mode 100644 index 2da2241a91..0000000000 --- a/gemfiles/rack_3_0.gemfile +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -# This file was generated by Appraisal - -source 'https://rubygems.org' - -gem 'rack', '~> 3.0.0' - -group :development, :test do - gem 'bundler' - gem 'hashie' - gem 'rake' - gem 'rubocop', '1.50.2', require: false - gem 'rubocop-performance', '1.17.1', require: false - gem 'rubocop-rspec', '2.20.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'cookiejar' - gem 'grape-entity', '~> 0.6' - gem 'mime-types' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rack_edge.gemfile b/gemfiles/rack_edge.gemfile deleted file mode 100644 index 5d9c93ae02..0000000000 --- a/gemfiles/rack_edge.gemfile +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -# This file was generated by Appraisal - -source 'https://rubygems.org' - -gem 'rack', github: 'rack/rack' - -group :development, :test do - gem 'bundler' - gem 'hashie' - gem 'rake' - gem 'rubocop', '1.50.2', require: false - gem 'rubocop-performance', '1.17.1', require: false - gem 'rubocop-rspec', '2.20.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'cookiejar' - gem 'grape-entity', '~> 0.6' - gem 'mime-types' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rails_7_1.gemfile b/gemfiles/rails_7_1.gemfile deleted file mode 100644 index 01fbd7900d..0000000000 --- a/gemfiles/rails_7_1.gemfile +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -# This file was generated by Appraisal - -source 'https://rubygems.org' - -gem 'rails', '~> 7.1.0' -gem 'tzinfo-data', require: false - -group :development, :test do - gem 'bundler' - gem 'hashie' - gem 'rake' - gem 'rubocop', '1.50.2', require: false - gem 'rubocop-performance', '1.17.1', require: false - gem 'rubocop-rspec', '2.20.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'cookiejar' - gem 'grape-entity', '~> 0.6' - gem 'mime-types' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/gemfiles/rails_edge.gemfile b/gemfiles/rails_edge.gemfile deleted file mode 100644 index cc01d9f976..0000000000 --- a/gemfiles/rails_edge.gemfile +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -# This file was generated by Appraisal - -source 'https://rubygems.org' - -gem 'rails', github: 'rails/rails' - -group :development, :test do - gem 'bundler' - gem 'hashie' - gem 'rake' - gem 'rubocop', '1.50.2', require: false - gem 'rubocop-performance', '1.17.1', require: false - gem 'rubocop-rspec', '2.20.0', require: false -end - -group :development do - gem 'appraisal' - gem 'benchmark-ips' - gem 'benchmark-memory' - gem 'guard' - gem 'guard-rspec' - gem 'guard-rubocop' -end - -group :test do - gem 'cookiejar' - gem 'grape-entity', '~> 0.6' - gem 'mime-types' - gem 'rack-jsonp', require: 'rack/jsonp' - gem 'rack-test', '< 2.1' - gem 'rspec', '< 4' - gem 'ruby-grape-danger', '~> 0.2.0', require: false - gem 'simplecov', '~> 0.21.2' - gem 'simplecov-lcov', '~> 0.8.0' - gem 'test-prof', require: false -end - -platforms :jruby do - gem 'racc' -end - -gemspec path: '../' diff --git a/grape.gemspec b/grape.gemspec index 9e53ddea75..d644420add 100644 --- a/grape.gemspec +++ b/grape.gemspec @@ -20,11 +20,11 @@ Gem::Specification.new do |s| 'source_code_uri' => "https://github.com/ruby-grape/grape/tree/v#{s.version}" } - s.add_runtime_dependency 'activesupport', '>= 5' + s.add_runtime_dependency 'activesupport', '>= 5', '< 7.1' s.add_runtime_dependency 'builder' s.add_runtime_dependency 'dry-types', '>= 1.1' s.add_runtime_dependency 'mustermann-grape', '~> 1.0.0' - s.add_runtime_dependency 'rack', '>= 1.3.0' + s.add_runtime_dependency 'rack', '>= 1.3.0', '< 3' s.add_runtime_dependency 'rack-accept' s.files = Dir['lib/**/*', 'CHANGELOG.md', 'CONTRIBUTING.md', 'README.md', 'grape.png', 'UPGRADING.md', 'LICENSE', 'grape.gemspec'] diff --git a/lib/grape.rb b/lib/grape.rb index 680bea819f..39f3905c07 100644 --- a/lib/grape.rb +++ b/lib/grape.rb @@ -38,10 +38,6 @@ module Grape include ActiveSupport::Configurable extend ::ActiveSupport::Autoload - def self.deprecator - @deprecator ||= ActiveSupport::Deprecation.new('2.0', 'Grape') - end - eager_autoload do autoload :API autoload :Endpoint @@ -305,8 +301,5 @@ module Types require 'grape/util/lazy_value' require 'grape/util/lazy_block' require 'grape/util/endpoint_configuration' -require 'grape/version' -# https://api.rubyonrails.org/classes/ActiveSupport/Deprecation.html -# adding Grape.deprecator to Rails App if any -require 'grape/railtie' if defined?(Rails::Railtie) && ActiveSupport.gem_version >= Gem::Version.new('7.1') +require 'grape/version' diff --git a/lib/grape/dsl/desc.rb b/lib/grape/dsl/desc.rb index e1611bf7f2..64d5eed910 100644 --- a/lib/grape/dsl/desc.rb +++ b/lib/grape/dsl/desc.rb @@ -68,7 +68,7 @@ def desc(description, options = {}, &config_block) end config_class.configure(&config_block) - Grape.deprecator.warn('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') if options.any? + ActiveSupport::Deprecation.warn('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') if options.any? options = config_class.settings else options = options.merge(description: description) diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index 7023d69dd9..4299888722 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -280,13 +280,13 @@ def return_no_content # Deprecated method to send files to the client. Use `sendfile` or `stream` def file(value = nil) if value.is_a?(String) - Grape.deprecator.warn('Use sendfile or stream to send files.') + ActiveSupport::Deprecation.warn('Use sendfile or stream to send files.') sendfile(value) elsif !value.is_a?(NilClass) - Grape.deprecator.warn('Use stream to use a Stream object.') + ActiveSupport::Deprecation.warn('Use stream to use a Stream object.') stream(value) else - Grape.deprecator.warn('Use sendfile or stream to send files.') + ActiveSupport::Deprecation.warn('Use sendfile or stream to send files.') sendfile end end diff --git a/lib/grape/exceptions/missing_group_type.rb b/lib/grape/exceptions/missing_group_type.rb index 9a7d3180a0..1f104321f5 100644 --- a/lib/grape/exceptions/missing_group_type.rb +++ b/lib/grape/exceptions/missing_group_type.rb @@ -10,4 +10,4 @@ def initialize end end -Grape::Exceptions::MissingGroupTypeError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Grape::Exceptions::MissingGroupTypeError', 'Grape::Exceptions::MissingGroupType', Grape.deprecator) +Grape::Exceptions::MissingGroupTypeError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Grape::Exceptions::MissingGroupTypeError', 'Grape::Exceptions::MissingGroupType') diff --git a/lib/grape/exceptions/unsupported_group_type.rb b/lib/grape/exceptions/unsupported_group_type.rb index 4c5e6396a3..da45abafdd 100644 --- a/lib/grape/exceptions/unsupported_group_type.rb +++ b/lib/grape/exceptions/unsupported_group_type.rb @@ -10,4 +10,4 @@ def initialize end end -Grape::Exceptions::UnsupportedGroupTypeError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Grape::Exceptions::UnsupportedGroupTypeError', 'Grape::Exceptions::UnsupportedGroupType', Grape.deprecator) +Grape::Exceptions::UnsupportedGroupTypeError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Grape::Exceptions::UnsupportedGroupTypeError', 'Grape::Exceptions::UnsupportedGroupType') diff --git a/lib/grape/railtie.rb b/lib/grape/railtie.rb deleted file mode 100644 index 42eb3442cb..0000000000 --- a/lib/grape/railtie.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module Grape - class Railtie < ::Rails::Railtie - initializer 'grape.deprecator' do |app| - app.deprecators[:grape] = Grape.deprecator - end - end -end diff --git a/lib/grape/router/route.rb b/lib/grape/router/route.rb index d5600df1c9..7bbfe6a0c5 100644 --- a/lib/grape/router/route.rb +++ b/lib/grape/router/route.rb @@ -84,7 +84,7 @@ def warn_route_methods(name, location, expected = nil) path, line = *location.scan(SOURCE_LOCATION_REGEXP).first path = File.realpath(path) if Pathname.new(path).relative? expected ||= name - Grape.deprecator.warn("#{path}:#{line}: The route_xxx methods such as route_#{name} have been deprecated, please use #{expected}.") + ActiveSupport::Deprecation.warn("#{path}:#{line}: The route_xxx methods such as route_#{name} have been deprecated, please use #{expected}.") end end end diff --git a/lib/grape/validations/validators/base.rb b/lib/grape/validations/validators/base.rb index c76eb4b394..ae0f0f48e5 100644 --- a/lib/grape/validations/validators/base.rb +++ b/lib/grape/validations/validators/base.rb @@ -85,7 +85,7 @@ def fail_fast? Grape::Validations::Base = Class.new(Grape::Validations::Validators::Base) do def self.inherited(*) - Grape.deprecator.warn 'Grape::Validations::Base is deprecated! Use Grape::Validations::Validators::Base instead.' + ActiveSupport::Deprecation.warn 'Grape::Validations::Base is deprecated! Use Grape::Validations::Validators::Base instead.' super end end diff --git a/lib/grape/validations/validators/values_validator.rb b/lib/grape/validations/validators/values_validator.rb index 3be7d609b6..2b7aca76ed 100644 --- a/lib/grape/validations/validators/values_validator.rb +++ b/lib/grape/validations/validators/values_validator.rb @@ -10,11 +10,11 @@ def initialize(attrs, options, required, scope, **opts) @values = options[:value] @proc = options[:proc] - Grape.deprecator.warn('The values validator except option is deprecated. Use the except validator instead.') if @excepts + ActiveSupport::Deprecation.warn('The values validator except option is deprecated. Use the except validator instead.') if @excepts raise ArgumentError, 'proc must be a Proc' if @proc && !@proc.is_a?(Proc) - Grape.deprecator.warn('The values validator proc option is deprecated. The lambda expression can now be assigned directly to values.') if @proc + ActiveSupport::Deprecation.warn('The values validator proc option is deprecated. The lambda expression can now be assigned directly to values.') if @proc else @excepts = nil @values = nil diff --git a/spec/config/spec_test_prof.rb b/spec/config/spec_test_prof.rb deleted file mode 100644 index e5259e110b..0000000000 --- a/spec/config/spec_test_prof.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require 'test_prof/recipes/rspec/let_it_be' - -TestProf::BeforeAll.adapter = Class.new do - def begin_transaction; end - - def rollback_transaction; end -end.new diff --git a/spec/grape/dsl/desc_spec.rb b/spec/grape/dsl/desc_spec.rb index fa3ae7f9ea..c2acde9105 100644 --- a/spec/grape/dsl/desc_spec.rb +++ b/spec/grape/dsl/desc_spec.rb @@ -83,7 +83,7 @@ end it 'can be set with options and a block' do - expect(Grape.deprecator).to receive(:warn).with('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') + expect(ActiveSupport::Deprecation).to receive(:warn).with('Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.') desc_text = 'The description' detail_text = 'more details' diff --git a/spec/grape/dsl/inside_route_spec.rb b/spec/grape/dsl/inside_route_spec.rb index 9547af46b2..e9a529b513 100644 --- a/spec/grape/dsl/inside_route_spec.rb +++ b/spec/grape/dsl/inside_route_spec.rb @@ -208,7 +208,7 @@ def initialize let(:file_path) { '/some/file/path' } it 'emits a warning that this method is deprecated' do - expect(Grape.deprecator).to receive(:warn).with(/Use sendfile or stream/) + expect(ActiveSupport::Deprecation).to receive(:warn).with(/Use sendfile or stream/) subject.file file_path end @@ -224,7 +224,7 @@ def initialize let(:file_object) { double('StreamerObject', each: nil) } it 'emits a warning that this method is deprecated' do - expect(Grape.deprecator).to receive(:warn).with(/Use stream to use a Stream object/) + expect(ActiveSupport::Deprecation).to receive(:warn).with(/Use stream to use a Stream object/) subject.file file_object end @@ -239,7 +239,7 @@ def initialize describe 'get' do it 'emits a warning that this method is deprecated' do - expect(Grape.deprecator).to receive(:warn).with(/Use sendfile or stream/) + expect(ActiveSupport::Deprecation).to receive(:warn).with(/Use sendfile or stream/) subject.file end @@ -269,7 +269,7 @@ def initialize end it 'sends no deprecation warnings' do - expect(Grape.deprecator).not_to receive(:warn) + expect(ActiveSupport::Deprecation).not_to receive(:warn) subject.sendfile file_path end @@ -330,7 +330,7 @@ def initialize end it 'emits no deprecation warnings' do - expect(Grape.deprecator).not_to receive(:warn) + expect(ActiveSupport::Deprecation).not_to receive(:warn) subject.stream file_path end @@ -380,7 +380,7 @@ def initialize end it 'emits no deprecation warnings' do - expect(Grape.deprecator).not_to receive(:warn) + expect(ActiveSupport::Deprecation).not_to receive(:warn) subject.stream stream_object end diff --git a/spec/grape/railtie_spec.rb b/spec/grape/railtie_spec.rb deleted file mode 100644 index 4a95551087..0000000000 --- a/spec/grape/railtie_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -if defined?(Rails::Railtie) && ActiveSupport.gem_version >= Gem::Version.new('7.1') - describe Grape::Railtie do - describe '.railtie' do - subject { test_app.deprecators[:grape] } - - let(:test_app) do - Class.new(Rails::Application) do - config.eager_load = false - config.load_defaults 7.1 - end - end - - before { test_app.initialize! } - - it { is_expected.to be(Grape.deprecator) } - end - end -end diff --git a/spec/shared/deprecated_class_examples.rb b/spec/shared/deprecated_class_examples.rb index 7909798ea8..93a4f120cf 100644 --- a/spec/shared/deprecated_class_examples.rb +++ b/spec/shared/deprecated_class_examples.rb @@ -4,10 +4,10 @@ subject { deprecated_class.new } around do |example| - old_deprec_behavior = Grape.deprecator.behavior - Grape.deprecator.behavior = :raise + old_deprec_behavior = ActiveSupport::Deprecation.behavior + ActiveSupport::Deprecation.behavior = :raise example.run - Grape.deprecator.behavior = old_deprec_behavior + ActiveSupport::Deprecation.behavior = old_deprec_behavior end it 'raises an ActiveSupport::DeprecationException' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1a2581ae75..f09fdd3567 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,16 +4,23 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'support')) +require 'grape' +require 'test_prof/recipes/rspec/let_it_be' + +class NullAdapter + def begin_transaction; end + + def rollback_transaction; end +end + +TestProf::BeforeAll.adapter = NullAdapter.new + require 'rubygems' require 'bundler' Bundler.require :default, :test -require 'grape' - -%w[config support].each do |dir| - Dir["#{File.dirname(__FILE__)}/#{dir}/**/*.rb"].sort.each do |file| - require file - end +Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each do |file| + require file end # The default value for this setting is true in a standard Rails app,