mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-08 22:37:57 -05:00
In Rack v3.1.0, the symbol for HTTP status code 422 was changed from `:unprocessable_entity` to `:unprocessable_content`. As a result, when using rack 3.2 with the following configuration in `config/initializers/devise.rb`, a warning is shown on login failure: ```ruby # config/initializers/devise.rb Devise.setup do |config| ... config.responder.error_status = :unprocessable_entity ``` Warning message: ```sh /path-to-app/vendor/bundle/ruby/3.4.0/gems/devise-4.9.4/lib/devise/failure_app.rb:80: warning: Status code :unprocessable_entity is deprecated and will be removed in a future version of Rack. Please use :unprocessable_content instead. ``` This warning can be resolved by updating the config as follows: ```diff # config/initializers/devise.rb Devise.setup do |config| ... + config.responder.error_status = :unprocessable_content - config.responder.error_status = :unprocessable_entity ``` This fixes the root cause of the warning for new apps by adjusting the generated config during `$ rails generate devise:install` depending on the rack version, so new apps using newer Rack versions generate `error_status = :unprocessable_content` instead of `:unprocessable_entity`. Existing apps are handled by [latest versions of Rails, which will now transparently convert the code under the hood to avoid the Rack warning](https://github.com/rails/rails/pull/53383), and Devise will use that translation layer when available in the failure app to prevent the warning there as well (since that isn't covered by Rails automatic conversion). Signed-off-by: Carlos Antonio da Silva <carlosantoniodasilva@gmail.com>
35 lines
1.0 KiB
Ruby
35 lines
1.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "test_helper"
|
|
|
|
class InstallGeneratorTest < Rails::Generators::TestCase
|
|
tests Devise::Generators::InstallGenerator
|
|
destination File.expand_path("../../tmp", __FILE__)
|
|
setup :prepare_destination
|
|
|
|
test "assert all files are properly created" do
|
|
run_generator(["--orm=active_record"])
|
|
assert_file "config/initializers/devise.rb", /devise\/orm\/active_record/
|
|
assert_file "config/locales/devise.en.yml"
|
|
end
|
|
|
|
test "fails if no ORM is specified" do
|
|
stderr = capture(:stderr) do
|
|
run_generator
|
|
end
|
|
|
|
assert_match %r{An ORM must be set to install Devise}, stderr
|
|
|
|
assert_no_file "config/initializers/devise.rb"
|
|
assert_no_file "config/locales/devise.en.yml"
|
|
end
|
|
|
|
test "responder error_status based on rack version" do
|
|
run_generator(["--orm=active_record"])
|
|
|
|
error_status = Rack::RELEASE >= "3.1" ? :unprocessable_content : :unprocessable_entity
|
|
|
|
assert_file "config/initializers/devise.rb", /config\.responder\.error_status = #{error_status.inspect}/
|
|
end
|
|
end
|