Compare commits

...

12 Commits

Author SHA1 Message Date
Marcos Ferreira
f78eed69e9 wip 2019-10-29 15:35:54 -03:00
Rafael França
885c61ece3 Merge pull request #5157 from tabakazu/add_assert_and_replace_mathcer
Add assert to Lockable integration test and Replace mathcer `assert_not` to `refute`
2019-10-25 11:54:53 -04:00
tabakazu
940b939791 Add assert for check last_sign_in_ip value 2019-10-24 21:12:27 +09:00
Looi David
406915cb78 changed? behaviour has been updated (#5135)
* `changed?` behaviour has been updated

Due to 16ae3db5a5 `changed?` has been updated to check for dirtiness after save. The new method that behaves like the old `changed` is `saved_changes?`.

* Add comment to explain which method to used based on which rails version it is
2019-10-22 10:39:34 -03:00
Leonardo Tegon
c5de662454 Merge pull request #5153 from storrence88/patch-1
Update README.md
2019-10-14 14:21:00 -03:00
Steven Torrence
0a6cd99d03 Update README.md
Change before filter to before action to match the code example given below.
2019-10-11 09:27:46 -05:00
Leonardo Tegon
ffeb942699 Merge pull request #5148 from gurgelrenan/flash_message
Call set_flash_message helper instead of flash accessor
2019-10-07 15:35:00 -03:00
Leonardo Tegon
f148c90fc7 Merge pull request #5142 from rlue/doc/initializer
Explain layout of default config initializer
2019-10-07 15:02:24 -03:00
Renan Gurgel
d022fb8cc4 Update code with single-quotes 2019-10-03 14:27:59 -03:00
Renan Gurgel
421ffc479f Add test to admin error message 2019-10-03 14:15:47 -03:00
Renan Gurgel
0f134f7030 Call set_flash_message helper instead of flash accessor 2019-10-03 00:15:15 -03:00
Ryan Lue
5d73e1e3bb Explain layout of default config initializer [ci skip] 2019-09-27 06:21:27 +08:00
11 changed files with 60 additions and 4 deletions

View File

@@ -289,7 +289,7 @@ There are just three actions in Devise that allow any set of parameters to be pa
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
* `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before filter in your `ApplicationController`:
In case you want to permit additional parameters (the lazy way™), you can do so using a simple before action in your `ApplicationController`:
```ruby
class ApplicationController < ActionController::Base

View File

@@ -112,7 +112,7 @@ MESSAGE
end
if authenticated && resource = warden.user(resource_name)
flash[:alert] = I18n.t("devise.failure.already_authenticated")
set_flash_message(:alert, 'already_authenticated', scope: 'devise.failure')
redirect_to after_sign_in_path_for(resource)
end
end

View File

@@ -305,6 +305,10 @@ module Devise
defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
end
def self.rails6_and_up?
Rails.gem_version >= Gem::Version.new("6.0.x")
end
# Default way to set up Devise. Run rails generate devise_install to create
# a fresh initializer with all configuration values.
def self.setup

View File

@@ -152,7 +152,8 @@ module Devise
# # If the record is new or changed then delay the
# # delivery until the after_commit callback otherwise
# # send now because after_commit will not be called.
# if new_record? || changed?
# # For Rails < 6 is `changed?` instead of `saved_changes?`.
# if new_record? || saved_changes?
# pending_devise_notifications << [notification, args]
# else
# render_and_send_devise_message(notification, *args)

View File

@@ -43,5 +43,11 @@ module Devise
)
end
end
initializer "devise.zeitwerk" do
if Devise.rails6_and_up? && Rails.autoloaders.zeitwerk_enabled? && !Object.const_defined?(Devise.parent_mailer)
Rails.autoloaders.main.ignore("#{__dir__}/app/mailers/devise/mailer.rb")
end
end
end
end

View File

@@ -1,5 +1,11 @@
# frozen_string_literal: true
# Assuming you have not yet modified this file, each configuration option below
# is set to its default value. Note that some are commented out while others
# are not: uncommented lines are intended to protect your configuration from
# breaking changes in upgrades (i.e., in the event that future versions of
# Devise change the default values for those options).
#
# Use this hook to configure devise mailer, warden hooks and so forth.
# Many of these configuration options can be set straight in your model.
Devise.setup do |config|

View File

@@ -323,6 +323,14 @@ class AuthenticationRedirectTest < Devise::IntegrationTest
visit new_user_session_path
assert_equal flash[:alert], I18n.t("devise.failure.already_authenticated")
end
test 'require_no_authentication should set the already_authenticated flash message as admin' do
store_translations :en, devise: { failure: { admin: { already_authenticated: 'You are already signed in as admin.' } } } do
sign_in_as_admin
visit new_admin_session_path
assert_equal flash[:alert], "You are already signed in as admin."
end
end
end
class AuthenticationSessionTest < Devise::IntegrationTest

View File

@@ -44,7 +44,7 @@ class TrackableHooksTest < Devise::IntegrationTest
assert_equal "127.0.0.1", user.last_sign_in_ip
end
test "current remote ip returns original ip behind a non transparent proxy" do
test "current and last sign in remote ip returns original ip behind a non transparent proxy" do
user = create_user
arbitrary_ip = '200.121.1.69'
@@ -53,6 +53,7 @@ class TrackableHooksTest < Devise::IntegrationTest
end
user.reload
assert_equal arbitrary_ip, user.current_sign_in_ip
assert_equal arbitrary_ip, user.last_sign_in_ip
end
test "increase sign in count" do

View File

@@ -49,5 +49,9 @@ module RailsApp
if Devise::Test.rails52_and_up? && !Devise::Test.rails6?
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
end
if Devise.rails6_and_up?
config.autoloader = :zeitwerk
end
end
end

View File

@@ -3,6 +3,12 @@
require "omniauth-facebook"
require "omniauth-openid"
# Assuming you have not yet modified this file, each configuration option below
# is set to its default value. Note that some are commented out while others
# are not: uncommented lines are intended to protect your configuration from
# breaking changes in upgrades (i.e., in the event that future versions of
# Devise change the default values for those options).
#
# Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models.
Devise.setup do |config|

View File

@@ -8,4 +8,24 @@ class RailsTest < ActiveSupport::TestCase
assert_equal :load_config_initializers, initializer.after
assert_equal :build_middleware_stack, initializer.before
end
test 'ignore devise mailer loading when ActionMailer is not defined with zeitwerk' do
if Devise.rails6_and_up?
begin
swap Devise, parent_mailer: 'NotDefinedParentMailer' do
Devise::Engine.initializers.detect { |initializer| initializer.name == 'devise.zeitwerk' }.block.call
assert Rails.autoloaders.main.ignored_glob_patterns.any? { |pattern| pattern.include?("mailer.rb") }
end
ensure
Rails.autoloaders.main.instance_variable_set(:@ignored_glob_patterns, Set.new)
end
end
end
test 'load devise mailer file when Devise.parent_mailer is defined with zeitwerk' do
if Devise.rails6_and_up?
Devise::Engine.initializers.detect { |initializer| initializer.name == 'devise.zeitwerk' }.block.call
refute Rails.autoloaders.main.ignored_glob_patterns.any? { |pattern| pattern.include?("mailer.rb") }
end
end
end