Skip to content

Commit

Permalink
Use the released version of responders v3.1.0
Browse files Browse the repository at this point in the history
Unfortunately we can't enforce the version in the gemspec because
responders only supports Rails 5.2 now, and Devise still supports
previous versions.

We'll drop support for those in a future major release, so for now I'm
not adding any version.

This also adds a warning in case someone is using an older version of
responders and tries to set the error/redirect statuses via Devise, so
that they know what to do (upgrade responders) in that case.
  • Loading branch information
carlosantoniodasilva committed Feb 3, 2023
1 parent 88625d4 commit 0d392fa
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* enhancements
* Add support for Ruby 3.1/3.2.
* Add support for Hotwire + Turbo, default in Rails 7+.
* `:turbo_stream` is now treated as a navigational format, so it works like HTML navigation when using Turbo. Note: if you relied on `:turbo_stream` to be treated as a non-navigational format before, you can reconfigure your `navigational_formats` in the Devise initializer file to exclude it.
* Devise requires the latest `responders` version, which allows configuring the status used for validation error responses (`error_status`) and for redirects after POST/PUT/PATCH/DELETE requests (`redirect_status`). For backwards compatibility, Devise keeps `error_status` as `:ok` which returns a `200 OK` response, and `redirect_status` to `:found` which returns a `302 Found` response, but you can configure it to return `422 Unprocessable Entity` and `303 See Other` to match the behavior expected by Hotwire/Turbo:
* Devise uses the latest `responders` version (v3.1.0 or higher), which allows configuring the status used for validation error responses (`error_status`) and for redirects after POST/PUT/PATCH/DELETE requests (`redirect_status`). For backwards compatibility, Devise keeps `error_status` as `:ok` which returns a `200 OK` response, and `redirect_status` to `:found` which returns a `302 Found` response, but you can configure it to return `422 Unprocessable Entity` and `303 See Other` respectively, to match the behavior expected by Hotwire/Turbo:

```ruby
# config/initializers/devise.rb
Expand All @@ -16,7 +15,10 @@
end
```

These configs are already generated by default with new apps, and existing apps may opt-in as described above. Note that these defaults may change in future versions of Devise, to better match the Rails + Hotwire/Turbo defaults across the board.
These configs are already generated by default with new apps, and existing apps may opt-in as described above. Trying to set these with an older version of `responders` will issue a warning and have no effect, so please upgrade the `responders` version if you're upgrading Devise for this integration. Note that these defaults may change in future versions of Devise, to better match the Rails + Hotwire/Turbo defaults across the board.
* If you have a custom responder set on your application and expect it to affect Devise as well, you may need to override the Devise responder entirely with `config.responder = MyApplicationResponder`, so that it uses your custom one. The main reason Devise uses a custom responder is to be able to configure the statuses as described above, but you can also change that config on your own responder if you want. Check the `responders` readme for more info on that.
* If you have created a custom responder and/or failure app just to customize responses for better Hotwire/Turbo integration, they should no longer be necessary.
* `:turbo_stream` is now treated as a navigational format, so it works like HTML navigation when using Turbo. Note: if you relied on `:turbo_stream` to be treated as a non-navigational format before, you can reconfigure your `navigational_formats` in the Devise initializer file to exclude it.
* OmniAuth "Sign in with" links were changed to buttons that generate HTML forms with method=POST, instead of using link + method=POST that required rails/ujs to work. Since rails/ujs is no longer the default for new Rails apps, this allows the OmniAuth buttons to work in any scenario, with or without rails/ujs and/or Turbo. This only affects apps that are using the default `devise/shared/_links.html.erb` partial from Devise with OmniAuth enabled.

### 4.8.1 - 2021-12-16
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gem "rdoc"

gem "rails-controller-testing", github: "rails/rails-controller-testing"

gem "responders", github: "heartcombo/responders", branch: "main"
gem "responders", "~> 3.1"

group :test do
gem "nokogiri", "< 1.13"
Expand Down
14 changes: 4 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
GIT
remote: https://github.com/heartcombo/responders.git
revision: fb9f787055a7a842584ce351793b249676290090
branch: main
specs:
responders (3.0.1)
actionpack (>= 5.2)
railties (>= 5.2)

GIT
remote: https://github.com/rails/rails-controller-testing.git
revision: 351c0162df0771c0c48e6a5a886c4c2f0a5d1a74
Expand Down Expand Up @@ -198,6 +189,9 @@ GEM
rake (13.0.6)
rdoc (6.5.0)
psych (>= 4.0.0)
responders (3.1.0)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.2.5)
ruby-openid (2.9.2)
ruby2_keywords (0.0.5)
Expand Down Expand Up @@ -237,7 +231,7 @@ DEPENDENCIES
rails (~> 7.0.0)
rails-controller-testing!
rdoc
responders!
responders (~> 3.1)
rexml
sqlite3 (~> 1.4)
timecop
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ Devise.setup do |config|
end
```

**Important**: these custom responses require the `responders` gem version to be `3.1.0` or higher, please make sure you update it if you're going to use this configuration.

_Note_: the above statuses configuration may become the default for Devise in a future release.

### I18n
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/Gemfile-rails-6-0
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem "rdoc"

gem "rails-controller-testing", github: "rails/rails-controller-testing"

gem "responders", github: "heartcombo/responders", branch: "main"
gem "responders", "~> 3.1"

group :test do
gem "nokogiri", "< 1.13"
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/Gemfile-rails-6-1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem "rdoc"

gem "rails-controller-testing", github: "rails/rails-controller-testing"

gem "responders", github: "heartcombo/responders", branch: "main"
gem "responders", "~> 3.1"

if RUBY_VERSION >= "3.1"
gem "net-smtp", require: false
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/Gemfile-rails-main
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gem "rdoc"

gem "rails-controller-testing", github: "rails/rails-controller-testing"

gem "responders", github: "heartcombo/responders", branch: "main"
gem "responders", "~> 3.1"

group :test do
gem "nokogiri", "< 1.13"
Expand Down
10 changes: 10 additions & 0 deletions lib/devise/controllers/responder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def self.error_status
def self.redirect_status
:found
end

def self.error_status=(*)
warn "[DEVISE] Setting the error status on the Devise responder has no effect with this " \
"version of `responders`, please make sure you're using a newer version. Check the changelog for more info."
end

def self.redirect_status=(*)
warn "[DEVISE] Setting the redirect status on the Devise responder has no effect with this " \
"version of `responders`, please make sure you're using a newer version. Check the changelog for more info."
end
end
end
end
Expand Down

0 comments on commit 0d392fa

Please sign in to comment.