-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix default response headers to work with Rack 3 (#2455)
* Default response headers are using Grape::Util::Header for rack 3 compatibility Add gcompat for nokogiri in Dockerfile. Needed for testing a Rails app Add tzinfo-data in Rails's Gemfiles. Needed for testing a Rails app Add integration test rails thats mounts a Grape API within a Rails App Move railtie_spec.rb to rails integration * Add CHANGELOG.md Add rails integrations tests * Fix config.load_defaults * Fix config.load_defaults in railtie_spec.rb * Change anonymous class to named class with stub_const * Reset Singleton ActiveSupport::Dependencies.autoload_paths and autoload_once_paths * Add comment about ActiveSupport::Dependencies * Replace responds by cascades
- Loading branch information
1 parent
3a26c2c
commit b1123d8
Showing
12 changed files
with
95 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
eval_gemfile '../Gemfile' | ||
|
||
gem 'rails', '~> 6.0.0' | ||
gem 'tzinfo-data', require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
eval_gemfile '../Gemfile' | ||
|
||
gem 'rails', '~> 6.1' | ||
gem 'tzinfo-data', require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
eval_gemfile '../Gemfile' | ||
|
||
gem 'rails', '~> 7.0.0' | ||
gem 'tzinfo-data', require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
eval_gemfile '../Gemfile' | ||
|
||
gem 'rails', '~> 7.1.0' | ||
gem 'tzinfo-data', require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
eval_gemfile '../Gemfile' | ||
|
||
gem 'rails', github: 'rails/rails' | ||
gem 'tzinfo-data', require: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# frozen_string_literal: true | ||
|
||
describe 'Rails', if: defined?(Rails) do | ||
context 'rails mounted' do | ||
let(:api) do | ||
Class.new(Grape::API) do | ||
get('/test_grape') { 'rails mounted' } | ||
end | ||
end | ||
|
||
let(:app) do | ||
require 'rails' | ||
require 'action_controller/railtie' | ||
|
||
# https://github.com/rails/rails/issues/51784 | ||
# same error as described if not redefining the following | ||
ActiveSupport::Dependencies.autoload_paths = [] | ||
ActiveSupport::Dependencies.autoload_once_paths = [] | ||
|
||
Class.new(Rails::Application) do | ||
config.eager_load = false | ||
config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}" | ||
config.api_only = true | ||
config.consider_all_requests_local = true | ||
config.hosts << 'example.org' | ||
|
||
routes.append do | ||
mount GrapeApi => '/' | ||
|
||
get 'up', to: lambda { |_env| | ||
['200', {}, ['hello world']] | ||
} | ||
end | ||
end | ||
end | ||
|
||
before do | ||
stub_const('GrapeApi', api) | ||
app.initialize! | ||
end | ||
|
||
it 'cascades' do | ||
get '/test_grape' | ||
expect(last_response).to be_successful | ||
expect(last_response.body).to eq('rails mounted') | ||
get '/up' | ||
expect(last_response).to be_successful | ||
expect(last_response.body).to eq('hello world') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
if defined?(Rails) && ActiveSupport.gem_version >= Gem::Version.new('7.1') | ||
describe Grape::Railtie do | ||
describe '.railtie' do | ||
subject { test_app.deprecators[:grape] } | ||
|
||
let(:test_app) do | ||
# https://github.com/rails/rails/issues/51784 | ||
# same error as described if not redefining the following | ||
ActiveSupport::Dependencies.autoload_paths = [] | ||
ActiveSupport::Dependencies.autoload_once_paths = [] | ||
|
||
Class.new(Rails::Application) do | ||
config.eager_load = false | ||
config.load_defaults "#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}" | ||
end | ||
end | ||
|
||
before { test_app.initialize! } | ||
|
||
it { is_expected.to be(Grape.deprecator) } | ||
end | ||
end | ||
end |