Rails 4.2 compatibility#3153
Conversation
There was a problem hiding this comment.
Will you still need this constant, then?
|
Seems good to me 👍 |
|
Merge this with master branch |
|
I would really like to remove the warning before merging this (@josevalim, any ideas?), and probably deal with #3157 before releasing a 4.2.0 compatible version. Once we are good to go this will be merged, don't worry :). |
|
@carlosantoniodasilva @josevalim another detail that we need to address: Devise does a hard use of |
This was broken in Rails 4.2.0+ because the `@scope` object is no longer a Hash
but an internal structure that supports a better override/rollback flow for cases
like this. If we would only support Rails 4.2, this method could be something
like this:
```ruby
def with_devise_exclusive_scope(new_path, new_as, options)
overrides = { as: new_as, path: new_path, module: nil }
overrides.merge!(options.slice(:constraints, :defaults, :options))
@scope = @scope.new(overrides)
yield
ensure
@scope = @scope.parent
end
```
064680b to
0b13f58
Compare
|
Updated the whole thing, testing against the released |
|
Those changes look great. Will Devise depend just on Rails 4.2 then? It kinda sucks that Rails is basically forcing us to do backwards incompatible changes. I am also fine with depending on responders, at least for now, because most Rails devs will still expect this kind of stuff to just work. |
|
We could try to move on to respond_to block rather than respond_with in most cases, just not sure it's totally worth it anyway. The other changes doesn't seem to be totally back imcompatible, they should work the same way on Rails 4.x apparently, but I might be wrong. Looking good 👍 |
There was a problem hiding this comment.
Isn't it better to just replace to: by controller:? Would that get rid of the warning?
There was a problem hiding this comment.
Nope, it crashes the app with the second message I've posted on this pull request description.
|
I don' think that rewriting the I'm thinking of going with an exception for now (something like 'Devise depends on the respond_to/respond_with API that was extracted to the responders gem. Please add gem "responders", "~> 2.0"' to your Gemfile') so we can support multiple versions with Devise 3.x and then look for a major release that drops this backwards support - something like Devise 4 is only for Rails 4.2+. Does it sounds too complicated? |
|
@lucasmazza this sounds good to me, I've been limited before by gem dependencies of libraries, when a perfectly good API compatible alternative exists (eg cancan dependency and I wanted to use cancancan), this approach will allow us to use super_awesome_mega_reponders.gem (which I made up) if it provided all the necessary functions I presume? |
|
@trinode sort of. Once we add |
|
@lucasmazza If it achieves the goal of older version compatibility it can only be a good thing, and like mentioned before, dropping 4.1 and below (or perhaps anything below 5 if there are features for Devise to take advantage of in Rails 5) from the next major version. Perhaps update the docs to mention to include it since it doesn't appear to be a default include in a new app, so long as it's clear in the exception output I don't think it'd cause too much friction. |
|
I'd go with the path of avoiding using responders, unless we have behaviour coupled in the gem. |
|
@rafaelfranca I think we are too coupled to drop it right now. |
|
I see. Can't we just say we depends on responders without specifying any version and let bundler resolve it correctly to different Rails versions? responders 2.0 requires 4.2 so bundler will never let 1.x be installed. Same when you are using 4.1. |
|
👍 for that If we are ok with shipping responders for free for everyone 😄 |
|
Yes, there is no problem on shipping responders for free. It doesn't inject code automatically anyway. |
|
So I'll cut a 3.3.1 release for #3157 and 3.4.0.beta for Rails 4.2, and look through the test failures later. |
|
Fan-fucking-tastic! |
|
I've been trying to migrate an application (which I haven't developed before) to Rails 4.2 (mainly due to ActiveJob) and I'm using this branch due to incompatibility with Rails 4.2 instead of Devise 3.3.0 (where everything works fine) . Unfortunately, I haven't worked with Devise for a while (I was stuck in 2.x). So I'm not sure how to deal with this issue. I'm getting the following issue when I run it in production environment (no problem in development or test environment). My class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
alias_method :current_user, :current_api_user
alias_method :user_signed_in?, :api_user_signed_in?
endIn namespace :api, defaults: { format: :json } do
devise_for :users, skip: :registrations, controllers: { sessions: 'api/auth', omniauth_callbacks: 'api/omniauth_callbacks' }
devise_scope :api_user do
post :logout, to: 'auth#destroy', as: :destroy_user_session
post :login, to: 'auth#create', as: :create_user_session
get 'auth/facebook/callback', to: 'api/omniauth_callbacks#facebook'
get 'auth/google/callback', to: 'api/omniauth_callbacks#google'
end
endI'm not sure if the customized Devise configuration is used properly. The same problem I'm getting with Rails 4.1.6 when I use this branch. There is no problem with Devise 3.3.0. I use Ruby 2.1.3. |
|
@deepj please don't piggy back on other issues. File a new issue. |
|
@zenspider I don't think that belongs to somewhere else. I just describe my issues and experiences related to this pull request. |
|
@deepj can you replicate this in a fresh app and push it to GitHub? Then I take a look and check what is really going wrong with this branch. |
|
@lucasmazza Here is the repository for replication of the problem https://github.com/deepj/devise-rails42 Just run it like |
|
@deepj thanks! I took a look on your app and seems to me that, when the Rails config |
|
Dug some more, the culprit is #3195, not the 4.2 compatibility code. |
|
@deepj can you test this branch one more time? ❤️ 💚 💙 💛 💜 |
|
@lucasmazza It seems everything is green! 👍 |
|
Awesome! |
|
Having an initialiser for splitting up routes like so: class ActionDispatch::Routing::Mapper Still breaks rails 4.2beta2 |
Still happening in 4.2.0.rc1 |
|
replace |
|
I was still having errors. This SO answer fixed it for me - http://stackoverflow.com/questions/27611947/devise-raises-error-with-rails-4-2-upgrade |
|
Use devise 3.4.1. |
This Pull Request aims to bring back compatibility with Rails 4.2/master since rails/rails@dc3f25c has changed the
@scopedata structure from the router, without losing compatibility with existing versions of Rails where this object is aHash.In the matter of Rails 4.2, we also have this deprecation warning:
Changing the router code to use
controller: controllers[:omniauth_callbacks]leads to the following error:respond_withremoval.Gemfiles.