Skip to content

Commit

Permalink
Remove Rails 4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
feliperenan authored and mracos committed Sep 19, 2019
1 parent 195cbfb commit 2d1a961
Show file tree
Hide file tree
Showing 30 changed files with 54 additions and 229 deletions.
18 changes: 1 addition & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ gemfile:
- gemfiles/Gemfile.rails-6.0-stable
- gemfiles/Gemfile.rails-5.2-stable
- gemfiles/Gemfile.rails-5.0-stable
- gemfiles/Gemfile.rails-4.2-stable
- gemfiles/Gemfile.rails-4.1-stable

matrix:
exclude:
Expand All @@ -35,20 +33,9 @@ matrix:
gemfile: gemfiles/Gemfile.rails-5.2-stable
- rvm: 2.3.8
gemfile: gemfiles/Gemfile.rails-6.0-stable
- rvm: 2.4.5
gemfile: gemfiles/Gemfile.rails-4.1-stable
- rvm: 2.4.5
gemfile: gemfiles/Gemfile.rails-6.0-stable
- rvm: 2.5.3
gemfile: gemfiles/Gemfile.rails-4.1-stable
- rvm: 2.6.0
gemfile: gemfiles/Gemfile.rails-4.1-stable
- rvm: 2.6.0
gemfile: gemfiles/Gemfile.rails-4.2-stable
- rvm: ruby-head
gemfile: gemfiles/Gemfile.rails-4.1-stable
- rvm: ruby-head
gemfile: gemfiles/Gemfile.rails-4.2-stable
- env: DEVISE_ORM=mongoid
gemfile: Gemfile
- env: DEVISE_ORM=mongoid
Expand All @@ -71,10 +58,7 @@ env:
- DEVISE_ORM=active_record
- DEVISE_ORM=mongoid

before_install:
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
- gem install bundler -v '< 2'
- "rm ${BUNDLE_GEMFILE}.lock"
before_install: "rm ${BUNDLE_GEMFILE}.lock"

before_script: "bundle update"

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
railties (>= 5.0)
responders
warden (~> 1.2.3)

Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ Please note that the command output will show the variable value being used.
### BUNDLE_GEMFILE
We can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).
Inside the [gemfiles](https://github.com/plataformatec/devise/tree/master/gemfiles) directory, we have one for each version of Rails we support. When you send us a pull request, it may happen that the test suite breaks on Travis using some of them. If that's the case, you can simulate the same environment using the `BUNDLE_GEMFILE` variable.
For example, if the tests broke using Ruby 2.4.2 and Rails 4.1, you can do the following:
For example, if the tests broke using Ruby 2.5.0 and Rails 5.0, you can do the following:
```bash
rbenv shell 2.4.2 # or rvm use 2.4.2
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bin/test
rbenv shell 2.5.0 # or rvm use 2.5.0
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.0-stable bundle install
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.0-stable bin/test
```

You can also combine both of them if the tests broke for Mongoid:
```bash
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable bundle install
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.1-stable DEVISE_ORM=mongoid bin/test
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.0-stable bundle install
BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.0-stable DEVISE_ORM=mongoid bin/test
```

### Running tests
Expand Down Expand Up @@ -180,7 +180,7 @@ Once you have solidified your understanding of Rails and authentication mechanis

## Getting started

Devise 4.0 works with Rails 4.1 onwards. Add the following line to your Gemfile:
Devise 5.0 works with Rails 5.0 onwards. Add the following line to your Gemfile:

```ruby
gem 'devise'
Expand Down
4 changes: 2 additions & 2 deletions devise.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ Gem::Specification.new do |s|

s.files = Dir["{app,config,lib}/**/*", "CHANGELOG.md", "MIT-LICENSE", "README.md"]
s.require_paths = ["lib"]
s.required_ruby_version = '>= 2.1.0'
s.required_ruby_version = '>= 2.3.0'

s.add_dependency("warden", "~> 1.2.3")
s.add_dependency("orm_adapter", "~> 0.1")
s.add_dependency("bcrypt", "~> 3.0")
s.add_dependency("railties", ">= 4.1.0")
s.add_dependency("railties", ">= 5.0")
s.add_dependency("responders")
end
1 change: 0 additions & 1 deletion gemfiles/Gemfile.rails-5.0-stable
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ group :test do
gem "timecop"
gem "webrat", "0.7.3", require: false
gem "mocha", "~> 1.1", require: false
gem 'test_after_commit', require: false
end

platforms :ruby do
Expand Down
4 changes: 1 addition & 3 deletions gemfiles/Gemfile.rails-5.0-stable.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
railties (>= 5.0)
responders
warden (~> 1.2.3)

Expand Down Expand Up @@ -153,8 +153,6 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
test_after_commit (1.1.0)
activerecord (>= 3.2)
thor (0.19.4)
thread_safe (0.3.6)
timecop (0.8.1)
Expand Down
1 change: 0 additions & 1 deletion gemfiles/Gemfile.rails-5.2-stable
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ group :test do
gem "timecop"
gem "webrat", "0.7.3", require: false
gem "mocha", "~> 1.1", require: false
gem 'test_after_commit', require: false
end

platforms :ruby do
Expand Down
4 changes: 1 addition & 3 deletions gemfiles/Gemfile.rails-5.2-stable.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
railties (>= 5.0)
responders
warden (~> 1.2.3)

Expand Down Expand Up @@ -162,8 +162,6 @@ GEM
activesupport (>= 4.0)
sprockets (>= 3.0.0)
sqlite3 (1.3.13)
test_after_commit (1.1.0)
activerecord (>= 3.2)
thor (0.20.0)
thread_safe (0.3.6)
timecop (0.9.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/Gemfile.rails-6.0-stable.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
devise (4.7.1)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
railties (>= 5.0)
responders
warden (~> 1.2.3)

Expand Down
12 changes: 2 additions & 10 deletions lib/devise/models/authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,16 @@ def devise_mailer
# # Deliver later with Active Job's `deliver_later`
# if message.respond_to?(:deliver_later)
# message.deliver_later
# # Remove once we move to Rails 4.2+ only, as `deliver` is deprecated.
# elsif message.respond_to?(:deliver_now)
# message.deliver_now
# else
# message.deliver
# message.deliver_now
# end
# end
#
# end
#
def send_devise_notification(notification, *args)
message = devise_mailer.send(notification, self, *args)
# Remove once we move to Rails 4.2+ only.
if message.respond_to?(:deliver_now)
message.deliver_now
else
message.deliver
end
message.deliver_now
end

def downcase_keys
Expand Down
28 changes: 5 additions & 23 deletions lib/devise/models/database_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,7 @@ def clean_up_passwords
# users to change relevant information like the e-mail without changing
# their password). In case the password field is rejected, the confirmation
# is also rejected as long as it is also blank.
def update_with_password(params, *options)
if options.present?
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
[Devise] The second argument of `DatabaseAuthenticatable#update_with_password`
(`options`) is deprecated and it will be removed in the next major version.
It was added to support a feature deprecated in Rails 4, so you can safely remove it
from your code.
DEPRECATION
end

def update_with_password(params)
current_password = params.delete(:current_password)

if params[:password].blank?
Expand All @@ -98,9 +89,9 @@ def update_with_password(params, *options)
end

result = if valid_password?(current_password)
update(params, *options)
update(params)
else
assign_attributes(params, *options)
assign_attributes(params)
valid?
errors.add(:current_password, current_password.blank? ? :blank : :invalid)
false
Expand All @@ -122,20 +113,11 @@ def update_with_password(params, *options)
# super(params)
# end
#
def update_without_password(params, *options)
if options.present?
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
[Devise] The second argument of `DatabaseAuthenticatable#update_without_password`
(`options`) is deprecated and it will be removed in the next major version.
It was added to support a feature deprecated in Rails 4, so you can safely remove it
from your code.
DEPRECATION
end

def update_without_password(params)
params.delete(:password)
params.delete(:password_confirmation)

result = update(params, *options)
result = update(params)
clean_up_passwords
result
end
Expand Down
3 changes: 1 addition & 2 deletions lib/devise/parameter_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def permit(action, keys: nil, except: nil, &block)
#
# Returns an +ActiveSupport::HashWithIndifferentAccess+.
def cast_to_hash(params)
# TODO: Remove the `with_indifferent_access` method call when we only support Rails 5+.
params && params.to_h.with_indifferent_access
params && params.to_h
end

def default_params
Expand Down
1 change: 0 additions & 1 deletion lib/devise/test/controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ def _process_unauthenticated(env, options = {})

status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
@controller.response.headers.merge!(headers)
@controller.response.content_type = headers["Content-Type"] unless Rails::VERSION::MAJOR >= 5
@controller.status = status
@controller.response.body = response.body
nil # causes process return @response
Expand Down
10 changes: 2 additions & 8 deletions lib/generators/active_record/devise_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,17 @@ def inet?
postgresql?
end

def rails5_and_up?
Rails::VERSION::MAJOR >= 5
end

def postgresql?
config = ActiveRecord::Base.configurations[Rails.env]
config && config['adapter'] == 'postgresql'
end

def migration_version
if rails5_and_up?
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end

def primary_key_type
primary_key_string if rails5_and_up?
primary_key_string
end

def primary_key_string
Expand Down
4 changes: 0 additions & 4 deletions lib/generators/devise/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ def copy_locale
def show_readme
readme "README" if behavior == :invoke
end

def rails_4?
Rails::VERSION::MAJOR == 4
end
end
end
end
7 changes: 1 addition & 6 deletions test/generators/active_record_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class ActiveRecordGeneratorTest < Rails::Generators::TestCase
run_generator %w(monster)
assert_file "app/models/monster.rb"
run_generator %w(monster)

if Rails.version >= '5.0.3'
assert_migration "db2/migrate/add_devise_to_monsters.rb"
else
Expand Down Expand Up @@ -84,11 +83,7 @@ class ActiveRecordGeneratorTest < Rails::Generators::TestCase

test "add primary key type with rails 5 when specified in rails generator" do
run_generator ["monster", "--primary_key_type=uuid"]
if Devise::Test.rails5_and_up?
assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters, id: :uuid do/
else
assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters do/
end
assert_migration "db/migrate/devise_create_monsters.rb", /create_table :monsters, id: :uuid do/
end
end

Expand Down
4 changes: 1 addition & 3 deletions test/integration/rememberable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ def create_user_and_remember(add_to_token='')
def generate_signed_cookie(raw_cookie)
request = if Devise::Test.rails51? || Devise::Test.rails52_and_up?
ActionController::TestRequest.create(Class.new) # needs a "controller class"
elsif Devise::Test.rails5?
ActionController::TestRequest.create
else
ActionController::TestRequest.new
ActionController::TestRequest.create
end
request.cookie_jar.signed['raw_cookie'] = raw_cookie
request.cookie_jar['raw_cookie']
Expand Down
8 changes: 1 addition & 7 deletions test/orm/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
end

class ActiveSupport::TestCase
if Devise::Test.rails5_and_up?
self.use_transactional_tests = true
else
# Let `after_commit` work with transactional fixtures, however this is not needed for Rails 5.
require 'test_after_commit'
self.use_transactional_fixtures = true
end
self.use_transactional_tests = true

self.use_instantiated_fixtures = false
end
2 changes: 1 addition & 1 deletion test/rails_app/app/active_record/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class User < ActiveRecord::Base
include Shim
include SharedUser
include ActiveModel::Serializers::Xml if Devise::Test.rails5_and_up?
include ActiveModel::Serializers::Xml

validates :sign_in_count, presence: true

Expand Down
6 changes: 1 addition & 5 deletions test/rails_app/app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ def set
end

def unauthenticated
if Devise::Test.rails5_and_up?
render body: "unauthenticated", status: :unauthorized
else
render text: "unauthenticated", status: :unauthorized
end
render body: "unauthenticated", status: :unauthorized
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ def sign_in_facebook
user = User.to_adapter.find_first(email: '[email protected]')
user.remember_me = true
sign_in user
render (Devise::Test.rails5_and_up? ? :body : :text) => ""
render body: ""
end
end
6 changes: 3 additions & 3 deletions test/rails_app/app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ def edit_form
end

def update_form
render (Devise::Test.rails5_and_up? ? :body : :text) => 'Update'
render body: 'Update'
end

def accept
@current_user = current_user
end

def exhibit
render (Devise::Test.rails5_and_up? ? :body : :text) => current_user ? "User is authenticated" : "User is not authenticated"
render body: current_user ? "User is authenticated" : "User is not authenticated"
end

def expire
user_session['last_request_at'] = 31.minutes.ago.utc
render (Devise::Test.rails5_and_up? ? :body : :text) => 'User will be expired on next request'
render body: 'User will be expired on next request'
end
end
Loading

0 comments on commit 2d1a961

Please sign in to comment.