mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-11 00:27:55 -05:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
755219ccfc | ||
|
|
9044631f4c | ||
|
|
a05d001c41 | ||
|
|
a8e1d42097 | ||
|
|
0df786c849 | ||
|
|
ccfe389be1 | ||
|
|
a79e0f6bca | ||
|
|
3640abc933 | ||
|
|
09ebe833b3 | ||
|
|
4a0bc7692a | ||
|
|
0d06ed6c79 | ||
|
|
71eb6176c3 | ||
|
|
7e6dd5022b | ||
|
|
286eefa9b4 | ||
|
|
5e00be4af8 | ||
|
|
a89af190e2 | ||
|
|
aea82d0b03 | ||
|
|
3d9dea39b2 | ||
|
|
dc1b399a8b | ||
|
|
a5ad61c167 | ||
|
|
146a2e500e | ||
|
|
4995d3c221 | ||
|
|
1987ffc171 | ||
|
|
16b29baa5b | ||
|
|
49403267cf | ||
|
|
4d7473634e | ||
|
|
13b50d63ca | ||
|
|
46c01d642b |
16
CHANGELOG.md
16
CHANGELOG.md
@@ -1,5 +1,11 @@
|
||||
### Unreleased
|
||||
|
||||
### 3.2.4
|
||||
|
||||
* enchancements
|
||||
* `bcrypt` dependency updated due https://github.com/codahale/bcrypt-ruby/pull/86.
|
||||
* View generator now can generate specific views with the `-v` flag, like `rails g devise:views -v sessions` (by @kayline)
|
||||
|
||||
### 3.2.3
|
||||
|
||||
* enhancements
|
||||
@@ -170,6 +176,16 @@ Security announcement: http://blog.plataformatec.com.br/2013/01/security-announc
|
||||
* `update_with_password` doesn't change encrypted password when it is invalid (by @nashby)
|
||||
* Properly handle namespaced models on Active Record generator (by @nashby)
|
||||
|
||||
### 2.1.4
|
||||
|
||||
* bugfix
|
||||
* Do not confirm account after reset password
|
||||
|
||||
### 2.1.3
|
||||
|
||||
* bugfix
|
||||
* Require string conversion for all values
|
||||
|
||||
### 2.1.2
|
||||
|
||||
* enhancements
|
||||
|
||||
4
Gemfile
4
Gemfile
@@ -10,8 +10,8 @@ gem "rdoc"
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "webrat", "0.7.3", :require => false
|
||||
gem "mocha", "~> 0.13.1", :require => false
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.0.0", require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
|
||||
12
Gemfile.lock
12
Gemfile.lock
@@ -12,8 +12,8 @@ GIT
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
devise (3.2.3)
|
||||
bcrypt-ruby (~> 3.0)
|
||||
devise (3.2.4)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 3.2.6, < 5)
|
||||
thread_safe (~> 0.1)
|
||||
@@ -48,7 +48,7 @@ GEM
|
||||
tzinfo (~> 0.3.37)
|
||||
arel (4.0.0)
|
||||
atomic (1.1.12)
|
||||
bcrypt-ruby (3.1.2)
|
||||
bcrypt (3.1.7)
|
||||
builder (3.1.4)
|
||||
erubis (2.7.0)
|
||||
faraday (0.8.8)
|
||||
@@ -63,10 +63,10 @@ GEM
|
||||
mail (2.5.4)
|
||||
mime-types (~> 1.16)
|
||||
treetop (~> 1.4.8)
|
||||
metaclass (0.0.1)
|
||||
metaclass (0.0.4)
|
||||
mime-types (1.23)
|
||||
minitest (4.7.5)
|
||||
mocha (0.13.3)
|
||||
mocha (1.0.0)
|
||||
metaclass (~> 0.0.1)
|
||||
moped (1.5.1)
|
||||
multi_json (1.7.9)
|
||||
@@ -148,7 +148,7 @@ DEPENDENCIES
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 0.13.1)
|
||||
mocha (~> 1.0.0)
|
||||
mongoid!
|
||||
omniauth (~> 1.0.0)
|
||||
omniauth-facebook
|
||||
|
||||
@@ -267,6 +267,13 @@ After doing so, you will be able to have views based on the role like `users/ses
|
||||
rails generate devise:views users
|
||||
```
|
||||
|
||||
If you want to generate only a few set of views, like the ones for the `registrable` and `confirmable` module,
|
||||
you can pass a list of modules to the generator with the `-v` flag.
|
||||
|
||||
```console
|
||||
rails generate devise:views -v registrations confirmations
|
||||
```
|
||||
|
||||
### Configuring controllers
|
||||
|
||||
If the customization at the views level is not enough, you can customize each controller by following these steps:
|
||||
|
||||
2
Rakefile
2
Rakefile
@@ -4,7 +4,7 @@ require 'rake/testtask'
|
||||
require 'rdoc/task'
|
||||
|
||||
desc 'Default: run tests for all ORMs.'
|
||||
task :default => :test
|
||||
task default: :test
|
||||
|
||||
desc 'Run Devise tests for all ORMs.'
|
||||
task :pre_commit do
|
||||
|
||||
@@ -10,7 +10,7 @@ class Devise::ConfirmationsController < DeviseController
|
||||
yield resource if block_given?
|
||||
|
||||
if successfully_sent?(resource)
|
||||
respond_with({}, :location => after_resending_confirmation_instructions_path_for(resource_name))
|
||||
respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))
|
||||
else
|
||||
respond_with(resource)
|
||||
end
|
||||
@@ -25,7 +25,7 @@ class Devise::ConfirmationsController < DeviseController
|
||||
set_flash_message(:notice, :confirmed) if is_flashing_format?
|
||||
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
|
||||
else
|
||||
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
|
||||
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ class Devise::OmniauthCallbacksController < DeviseController
|
||||
prepend_before_filter { request.env["devise.skip_timeout"] = true }
|
||||
|
||||
def passthru
|
||||
render :status => 404, :text => "Not found. Authentication passthru."
|
||||
render status: 404, text: "Not found. Authentication passthru."
|
||||
end
|
||||
|
||||
def failure
|
||||
set_flash_message :alert, :failure, :kind => OmniAuth::Utils.camelize(failed_strategy.name), :reason => failure_message
|
||||
set_flash_message :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message
|
||||
redirect_to after_omniauth_failure_path_for(resource_name)
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Devise::PasswordsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication
|
||||
# Render the #edit only if coming from a reset password email link
|
||||
append_before_filter :assert_reset_token_passed, :only => :edit
|
||||
append_before_filter :assert_reset_token_passed, only: :edit
|
||||
|
||||
# GET /resource/password/new
|
||||
def new
|
||||
@@ -14,7 +14,7 @@ class Devise::PasswordsController < DeviseController
|
||||
yield resource if block_given?
|
||||
|
||||
if successfully_sent?(resource)
|
||||
respond_with({}, :location => after_sending_reset_password_instructions_path_for(resource_name))
|
||||
respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
|
||||
else
|
||||
respond_with(resource)
|
||||
end
|
||||
@@ -36,7 +36,7 @@ class Devise::PasswordsController < DeviseController
|
||||
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
||||
set_flash_message(:notice, flash_message) if is_flashing_format?
|
||||
sign_in(resource_name, resource)
|
||||
respond_with resource, :location => after_resetting_password_path_for(resource)
|
||||
respond_with resource, location: after_resetting_password_path_for(resource)
|
||||
else
|
||||
respond_with resource
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Devise::RegistrationsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
|
||||
prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
|
||||
prepend_before_filter :require_no_authentication, only: [ :new, :create, :cancel ]
|
||||
prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy]
|
||||
|
||||
# GET /resource/sign_up
|
||||
def new
|
||||
@@ -17,11 +17,11 @@ class Devise::RegistrationsController < DeviseController
|
||||
if resource.active_for_authentication?
|
||||
set_flash_message :notice, :signed_up if is_flashing_format?
|
||||
sign_up(resource_name, resource)
|
||||
respond_with resource, :location => after_sign_up_path_for(resource)
|
||||
respond_with resource, location: after_sign_up_path_for(resource)
|
||||
else
|
||||
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
|
||||
expire_data_after_sign_in!
|
||||
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
|
||||
respond_with resource, location: after_inactive_sign_up_path_for(resource)
|
||||
end
|
||||
else
|
||||
clean_up_passwords resource
|
||||
@@ -48,8 +48,8 @@ class Devise::RegistrationsController < DeviseController
|
||||
:update_needs_confirmation : :updated
|
||||
set_flash_message :notice, flash_key
|
||||
end
|
||||
sign_in resource_name, resource, :bypass => true
|
||||
respond_with resource, :location => after_update_path_for(resource)
|
||||
sign_in resource_name, resource, bypass: true
|
||||
respond_with resource, location: after_update_path_for(resource)
|
||||
else
|
||||
clean_up_passwords resource
|
||||
respond_with resource
|
||||
@@ -121,7 +121,7 @@ class Devise::RegistrationsController < DeviseController
|
||||
|
||||
# Authenticates the current scope and gets the current resource from the session.
|
||||
def authenticate_scope!
|
||||
send(:"authenticate_#{resource_name}!", :force => true)
|
||||
send(:"authenticate_#{resource_name}!", force: true)
|
||||
self.resource = send(:"current_#{resource_name}")
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Devise::SessionsController < DeviseController
|
||||
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
|
||||
prepend_before_filter :allow_params_authentication!, :only => :create
|
||||
prepend_before_filter :only => [ :create, :destroy ] { request.env["devise.skip_timeout"] = true }
|
||||
prepend_before_filter :require_no_authentication, only: [ :new, :create ]
|
||||
prepend_before_filter :allow_params_authentication!, only: :create
|
||||
prepend_before_filter only: [ :create, :destroy ] { request.env["devise.skip_timeout"] = true }
|
||||
|
||||
# GET /resource/sign_in
|
||||
def new
|
||||
@@ -16,7 +16,7 @@ class Devise::SessionsController < DeviseController
|
||||
set_flash_message(:notice, :signed_in) if is_flashing_format?
|
||||
sign_in(resource_name, resource)
|
||||
yield resource if block_given?
|
||||
respond_with resource, :location => after_sign_in_path_for(resource)
|
||||
respond_with resource, location: after_sign_in_path_for(resource)
|
||||
end
|
||||
|
||||
# DELETE /resource/sign_out
|
||||
@@ -44,10 +44,10 @@ class Devise::SessionsController < DeviseController
|
||||
methods = resource_class.authentication_keys.dup
|
||||
methods = methods.keys if methods.is_a?(Hash)
|
||||
methods << :password if resource.respond_to?(:password)
|
||||
{ :methods => methods, :only => [:password] }
|
||||
{ methods: methods, only: [:password] }
|
||||
end
|
||||
|
||||
def auth_options
|
||||
{ :scope => resource_name, :recall => "#{controller_path}#new" }
|
||||
{ scope: resource_name, recall: "#{controller_path}#new" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,7 @@ class Devise::UnlocksController < DeviseController
|
||||
yield resource if block_given?
|
||||
|
||||
if successfully_sent?(resource)
|
||||
respond_with({}, :location => after_sending_unlock_instructions_path_for(resource))
|
||||
respond_with({}, location: after_sending_unlock_instructions_path_for(resource))
|
||||
else
|
||||
respond_with(resource)
|
||||
end
|
||||
@@ -27,7 +27,7 @@ class Devise::UnlocksController < DeviseController
|
||||
set_flash_message :notice, :unlocked if is_flashing_format?
|
||||
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
|
||||
else
|
||||
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
|
||||
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class DeviseController < Devise.parent_controller.constantize
|
||||
|
||||
# Returns a signed in resource from session (if one exists)
|
||||
def signed_in_resource
|
||||
warden.authenticate(:scope => resource_name)
|
||||
warden.authenticate(scope: resource_name)
|
||||
end
|
||||
|
||||
# Attempt to find the mapped route for devise based on request path
|
||||
@@ -92,14 +92,14 @@ MESSAGE
|
||||
# Helper for use in before_filters where no authentication is required.
|
||||
#
|
||||
# Example:
|
||||
# before_filter :require_no_authentication, :only => :new
|
||||
# before_filter :require_no_authentication, only: :new
|
||||
def require_no_authentication
|
||||
assert_is_devise_resource!
|
||||
return unless is_navigational_format?
|
||||
no_input = devise_mapping.no_input_strategies
|
||||
|
||||
authenticated = if no_input.present?
|
||||
args = no_input.dup.push :scope => resource_name
|
||||
args = no_input.dup.push scope: resource_name
|
||||
warden.authenticate?(*args)
|
||||
else
|
||||
warden.authenticated?(resource_name)
|
||||
|
||||
@@ -10,8 +10,8 @@ module DeviseHelper
|
||||
|
||||
messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
|
||||
sentence = I18n.t("errors.messages.not_saved",
|
||||
:count => resource.errors.count,
|
||||
:resource => resource.class.model_name.human.downcase)
|
||||
count: resource.errors.count,
|
||||
resource: resource.class.model_name.human.downcase)
|
||||
|
||||
html = <<-HTML
|
||||
<div id="error_explanation">
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<h2>Resend confirmation instructions</h2>
|
||||
|
||||
<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
<%= f.email_field :email, autofocus: true %></div>
|
||||
|
||||
<div><%= f.submit "Resend confirmation instructions" %></div>
|
||||
<% end %>
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
|
||||
<p>You can confirm your account email through the link below:</p>
|
||||
|
||||
<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @token) %></p>
|
||||
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
|
||||
|
||||
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token) %></p>
|
||||
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
|
||||
|
||||
<p>If you didn't request this, please ignore this email.</p>
|
||||
<p>Your password won't change until you access the link above and create a new one.</p>
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
<p>Click the link below to unlock your account:</p>
|
||||
|
||||
<p><%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @token) %></p>
|
||||
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<h2>Change your password</h2>
|
||||
|
||||
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
<%= f.hidden_field :reset_password_token %>
|
||||
|
||||
<div><%= f.label :password, "New password" %><br />
|
||||
<%= f.password_field :password, :autofocus => true %></div>
|
||||
<%= f.password_field :password, autofocus: true, autocomplete: "off" %></div>
|
||||
|
||||
<div><%= f.label :password_confirmation, "Confirm new password" %><br />
|
||||
<%= f.password_field :password_confirmation %></div>
|
||||
<%= f.password_field :password_confirmation, autocomplete: "off" %></div>
|
||||
|
||||
<div><%= f.submit "Change my password" %></div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<h2>Forgot your password?</h2>
|
||||
|
||||
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
<%= f.email_field :email, autofocus: true %></div>
|
||||
|
||||
<div><%= f.submit "Send me reset password instructions" %></div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
||||
|
||||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
<%= f.email_field :email, autofocus: true %></div>
|
||||
|
||||
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
|
||||
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
|
||||
<% end %>
|
||||
|
||||
<div><%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
||||
<%= f.password_field :password, :autocomplete => "off" %></div>
|
||||
<%= f.password_field :password, autocomplete: "off" %></div>
|
||||
|
||||
<div><%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation %></div>
|
||||
<%= f.password_field :password_confirmation, autocomplete: "off" %></div>
|
||||
|
||||
<div><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
||||
<%= f.password_field :current_password %></div>
|
||||
<%= f.password_field :current_password, autocomplete: "off" %></div>
|
||||
|
||||
<div><%= f.submit "Update" %></div>
|
||||
<% end %>
|
||||
|
||||
<h3>Cancel my account</h3>
|
||||
|
||||
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>
|
||||
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
|
||||
|
||||
<%= link_to "Back", :back %>
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<h2>Sign up</h2>
|
||||
|
||||
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
<%= f.email_field :email, autofocus: true %></div>
|
||||
|
||||
<div><%= f.label :password %><br />
|
||||
<%= f.password_field :password %></div>
|
||||
<%= f.password_field :password, autocomplete: "off" %></div>
|
||||
|
||||
<div><%= f.label :password_confirmation %><br />
|
||||
<%= f.password_field :password_confirmation %></div>
|
||||
<%= f.password_field :password_confirmation, autocomplete: "off" %></div>
|
||||
|
||||
<div><%= f.submit "Sign up" %></div>
|
||||
<% end %>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<h2>Sign in</h2>
|
||||
|
||||
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
||||
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
<%= f.email_field :email, autofocus: true %></div>
|
||||
|
||||
<div><%= f.label :password %><br />
|
||||
<%= f.password_field :password %></div>
|
||||
<%= f.password_field :password, autocomplete: "off" %></div>
|
||||
|
||||
<% if devise_mapping.rememberable? -%>
|
||||
<div><%= f.check_box :remember_me %> <%= f.label :remember_me %></div>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<h2>Resend unlock instructions</h2>
|
||||
|
||||
<%= form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
|
||||
<%= devise_error_messages! %>
|
||||
|
||||
<div><%= f.label :email %><br />
|
||||
<%= f.email_field :email, :autofocus => true %></div>
|
||||
<%= f.email_field :email, autofocus: true %></div>
|
||||
|
||||
<div><%= f.submit "Resend unlock instructions" %></div>
|
||||
<% end %>
|
||||
|
||||
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
||||
|
||||
s.add_dependency("warden", "~> 1.2.3")
|
||||
s.add_dependency("orm_adapter", "~> 0.1")
|
||||
s.add_dependency("bcrypt-ruby", "~> 3.0")
|
||||
s.add_dependency("bcrypt", "~> 3.0")
|
||||
s.add_dependency("thread_safe", "~> 0.1")
|
||||
s.add_dependency("railties", ">= 3.2.6", "< 5")
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gemspec :path => '..'
|
||||
gemspec path: '..'
|
||||
|
||||
gem "rails", github: 'rails/rails', branch: '3-2-stable'
|
||||
gem "omniauth", "~> 1.0.0"
|
||||
@@ -10,8 +10,8 @@ gem "rdoc"
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "webrat", "0.7.3", :require => false
|
||||
gem "mocha", "~> 0.13.1", :require => false
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.0.0", require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gemspec :path => '..'
|
||||
gemspec path: '..'
|
||||
|
||||
gem "rails", github: 'rails/rails', branch: '4-0-stable'
|
||||
gem "omniauth", "~> 1.0.0"
|
||||
@@ -10,8 +10,8 @@ gem "rdoc"
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "webrat", "0.7.3", :require => false
|
||||
gem "mocha", "~> 0.13.1", :require => false
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.0.0", require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gemspec :path => '..'
|
||||
gemspec path: '..'
|
||||
|
||||
gem "rails", github: 'rails/rails'
|
||||
gem "omniauth", "~> 1.0.0"
|
||||
@@ -10,8 +10,8 @@ gem "rdoc"
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "webrat", "0.7.3", :require => false
|
||||
gem "mocha", "~> 0.14", :require => false
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.0.0", require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
|
||||
@@ -350,8 +350,8 @@ module Devise
|
||||
# == Examples:
|
||||
#
|
||||
# Devise.add_module(:party_module)
|
||||
# Devise.add_module(:party_module, :strategy => true, :controller => :sessions)
|
||||
# Devise.add_module(:party_module, :model => 'party_module/model')
|
||||
# Devise.add_module(:party_module, strategy: true, controller: :sessions)
|
||||
# Devise.add_module(:party_module, model: 'party_module/model')
|
||||
#
|
||||
def self.add_module(module_name, options = {})
|
||||
ALL << module_name
|
||||
@@ -449,7 +449,7 @@ module Devise
|
||||
warden_config.intercept_401 = false
|
||||
|
||||
Devise.mappings.each_value do |mapping|
|
||||
warden_config.scope_defaults mapping.name, :strategies => mapping.strategies
|
||||
warden_config.scope_defaults mapping.name, strategies: mapping.strategies
|
||||
|
||||
warden_config.serialize_into_session(mapping.name) do |record|
|
||||
mapping.to.serialize_into_session(record)
|
||||
|
||||
@@ -55,7 +55,7 @@ module Devise
|
||||
end
|
||||
|
||||
def current_#{mapping}
|
||||
@current_#{mapping} ||= warden.authenticate(:scope => :#{mapping})
|
||||
@current_#{mapping} ||= warden.authenticate(scope: :#{mapping})
|
||||
end
|
||||
|
||||
def #{mapping}_session
|
||||
@@ -77,9 +77,9 @@ module Devise
|
||||
# the controllers defined inside devise. Useful if you want to apply a before
|
||||
# filter to all controllers, except the ones in devise:
|
||||
#
|
||||
# before_filter :my_filter, :unless => :devise_controller?
|
||||
# before_filter :my_filter, unless: :devise_controller?
|
||||
def devise_controller?
|
||||
is_a?(DeviseController)
|
||||
is_a?(::DeviseController)
|
||||
end
|
||||
|
||||
# Setup a param sanitizer to filter parameters using strong_parameters. See
|
||||
@@ -121,10 +121,10 @@ module Devise
|
||||
# root path. For a user scope, you can define the default url in
|
||||
# the following way:
|
||||
#
|
||||
# map.user_root '/users', :controller => 'users' # creates user_root_path
|
||||
# map.user_root '/users', controller: 'users' # creates user_root_path
|
||||
#
|
||||
# map.namespace :user do |user|
|
||||
# user.root :controller => 'users' # creates user_root_path
|
||||
# user.root controller: 'users' # creates user_root_path
|
||||
# end
|
||||
#
|
||||
# If the resource root path is not defined, root_path is used. However,
|
||||
|
||||
@@ -31,11 +31,11 @@ module Devise
|
||||
end
|
||||
|
||||
def remember_cookie_values(resource)
|
||||
options = { :httponly => true }
|
||||
options = { httponly: true }
|
||||
options.merge!(forget_cookie_values(resource))
|
||||
options.merge!(
|
||||
:value => resource.class.serialize_into_cookie(resource),
|
||||
:expires => resource.remember_expires_at
|
||||
value: resource.class.serialize_into_cookie(resource),
|
||||
expires: resource.remember_expires_at
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ module Devise
|
||||
# true if any scope is signed in. Does not run authentication hooks.
|
||||
def signed_in?(scope=nil)
|
||||
[ scope || Devise.mappings.keys ].flatten.any? do |_scope|
|
||||
warden.authenticate?(:scope => _scope)
|
||||
warden.authenticate?(scope: _scope)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,9 +23,9 @@ module Devise
|
||||
#
|
||||
# sign_in :user, @user # sign_in(scope, resource)
|
||||
# sign_in @user # sign_in(resource)
|
||||
# sign_in @user, :event => :authentication # sign_in(resource, options)
|
||||
# sign_in @user, :store => false # sign_in(resource, options)
|
||||
# sign_in @user, :bypass => true # sign_in(resource, options)
|
||||
# sign_in @user, event: :authentication # sign_in(resource, options)
|
||||
# sign_in @user, store: false # sign_in(resource, options)
|
||||
# sign_in @user, bypass: true # sign_in(resource, options)
|
||||
#
|
||||
def sign_in(resource_or_scope, *args)
|
||||
options = args.extract_options!
|
||||
@@ -40,7 +40,7 @@ module Devise
|
||||
# Do nothing. User already signed in and we are not forcing it.
|
||||
true
|
||||
else
|
||||
warden.set_user(resource, options.merge!(:scope => scope))
|
||||
warden.set_user(resource, options.merge!(scope: scope))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,11 +56,11 @@ module Devise
|
||||
def sign_out(resource_or_scope=nil)
|
||||
return sign_out_all_scopes unless resource_or_scope
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
user = warden.user(:scope => scope, :run_callbacks => false) # If there is no user
|
||||
user = warden.user(scope: scope, run_callbacks: false) # If there is no user
|
||||
|
||||
warden.raw_session.inspect # Without this inspect here. The session does not clear.
|
||||
warden.logout(scope)
|
||||
warden.clear_strategies_cache!(:scope => scope)
|
||||
warden.clear_strategies_cache!(scope: scope)
|
||||
instance_variable_set(:"@current_#{scope}", nil)
|
||||
|
||||
!!user
|
||||
@@ -70,7 +70,7 @@ module Devise
|
||||
# in one click. This signs out ALL scopes in warden. Returns true if there was at least one logout
|
||||
# and false if there was no user logged in on all scopes.
|
||||
def sign_out_all_scopes(lock=true)
|
||||
users = Devise.mappings.keys.map { |s| warden.user(:scope => s, :run_callbacks => false) }
|
||||
users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }
|
||||
|
||||
warden.raw_session.inspect
|
||||
warden.logout
|
||||
|
||||
@@ -15,7 +15,7 @@ module Devise
|
||||
|
||||
include Devise::Controllers::StoreLocation
|
||||
|
||||
delegate :flash, :to => :request
|
||||
delegate :flash, to: :request
|
||||
|
||||
def self.call(env)
|
||||
@respond ||= action(:respond)
|
||||
@@ -151,9 +151,9 @@ module Devise
|
||||
return i18n_message unless request_format
|
||||
method = "to_#{request_format}"
|
||||
if method == "to_xml"
|
||||
{ :error => i18n_message }.to_xml(:root => "errors")
|
||||
{ error: i18n_message }.to_xml(root: "errors")
|
||||
elsif {}.respond_to?(method)
|
||||
{ :error => i18n_message }.send(method)
|
||||
{ error: i18n_message }.send(method)
|
||||
else
|
||||
i18n_message
|
||||
end
|
||||
|
||||
@@ -6,6 +6,6 @@ Warden::Manager.after_set_user do |record, warden, options|
|
||||
if record && record.respond_to?(:active_for_authentication?) && !record.active_for_authentication?
|
||||
scope = options[:scope]
|
||||
warden.logout(scope)
|
||||
throw :warden, :scope => scope, :message => record.inactive_message
|
||||
throw :warden, scope: scope, message: record.inactive_message
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# After each sign in, if resource responds to failed_attempts, sets it to 0
|
||||
# This is only triggered when the user is explicitly set (with set_user)
|
||||
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
||||
Warden::Manager.after_set_user except: :fetch do |record, warden, options|
|
||||
if record.respond_to?(:failed_attempts) && warden.authenticated?(options[:scope])
|
||||
record.update_attribute(:failed_attempts, 0) unless record.failed_attempts.to_i.zero?
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ module Devise
|
||||
include Devise::Controllers::SignInOut
|
||||
|
||||
attr_reader :warden
|
||||
delegate :cookies, :env, :to => :warden
|
||||
delegate :cookies, :env, to: :warden
|
||||
|
||||
def initialize(warden)
|
||||
@warden = warden
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
||||
Warden::Manager.after_set_user except: :fetch do |record, warden, options|
|
||||
scope = options[:scope]
|
||||
if record.respond_to?(:remember_me) && options[:store] != false &&
|
||||
record.remember_me && warden.authenticated?(scope)
|
||||
|
||||
@@ -18,7 +18,7 @@ Warden::Manager.after_set_user do |record, warden, options|
|
||||
record.reset_authentication_token!
|
||||
end
|
||||
|
||||
throw :warden, :scope => scope, :message => :timeout
|
||||
throw :warden, scope: scope, message: :timeout
|
||||
end
|
||||
|
||||
unless env['devise.skip_trackable']
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# This is only triggered when the user is explicitly set (with set_user)
|
||||
# and on authentication. Retrieving the user from session (:fetch) does
|
||||
# not trigger it.
|
||||
Warden::Manager.after_set_user :except => :fetch do |record, warden, options|
|
||||
Warden::Manager.after_set_user except: :fetch do |record, warden, options|
|
||||
if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope]) && !warden.request.env['devise.skip_trackable']
|
||||
record.update_tracked_fields!(warden.request)
|
||||
end
|
||||
|
||||
@@ -27,12 +27,12 @@ module Devise
|
||||
|
||||
def headers_for(action, opts)
|
||||
headers = {
|
||||
:subject => subject_for(action),
|
||||
:to => resource.email,
|
||||
:from => mailer_sender(devise_mapping),
|
||||
:reply_to => mailer_reply_to(devise_mapping),
|
||||
:template_path => template_paths,
|
||||
:template_name => action
|
||||
subject: subject_for(action),
|
||||
to: resource.email,
|
||||
from: mailer_sender(devise_mapping),
|
||||
reply_to: mailer_reply_to(devise_mapping),
|
||||
template_path: template_paths,
|
||||
template_name: action
|
||||
}.merge(opts)
|
||||
|
||||
@email = headers[:to]
|
||||
@@ -82,8 +82,8 @@ module Devise
|
||||
# subject: '...'
|
||||
#
|
||||
def subject_for(key)
|
||||
I18n.t(:"#{devise_mapping.name}_subject", :scope => [:devise, :mailer, key],
|
||||
:default => [:subject, key.to_s.humanize])
|
||||
I18n.t(:"#{devise_mapping.name}_subject", scope: [:devise, :mailer, key],
|
||||
default: [:subject, key.to_s.humanize])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ module Devise
|
||||
# It also accepts an array specifying the strategies that should allow params authentication.
|
||||
#
|
||||
# * +skip_session_storage+: By default Devise will store the user in session.
|
||||
# By default is set to :skip_session_storage => [:http_auth].
|
||||
# By default is set to skip_session_storage: [:http_auth].
|
||||
#
|
||||
# == active_for_authentication?
|
||||
#
|
||||
@@ -59,7 +59,7 @@ module Devise
|
||||
:remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at]
|
||||
|
||||
included do
|
||||
class_attribute :devise_modules, :instance_writer => false
|
||||
class_attribute :devise_modules, instance_writer: false
|
||||
self.devise_modules ||= []
|
||||
|
||||
before_validation :downcase_keys
|
||||
@@ -231,7 +231,7 @@ module Devise
|
||||
# Example:
|
||||
#
|
||||
# def self.find_for_authentication(tainted_conditions)
|
||||
# find_first_by_auth_conditions(tainted_conditions, :active => true)
|
||||
# find_first_by_auth_conditions(tainted_conditions, active: true)
|
||||
# end
|
||||
#
|
||||
# Finally, notice that Devise also queries for users in other scenarios
|
||||
|
||||
@@ -33,10 +33,10 @@ module Devise
|
||||
include ActionView::Helpers::DateHelper
|
||||
|
||||
included do
|
||||
before_create :generate_confirmation_token, :if => :confirmation_required?
|
||||
after_create :send_on_create_confirmation_instructions, :if => :send_confirmation_notification?
|
||||
before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, :if => :postpone_email_change?
|
||||
after_update :send_reconfirmation_instructions, :if => :reconfirmation_required?
|
||||
before_create :generate_confirmation_token, if: :confirmation_required?
|
||||
after_create :send_on_create_confirmation_instructions, if: :send_confirmation_notification?
|
||||
before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, if: :postpone_email_change?
|
||||
after_update :send_reconfirmation_instructions, if: :reconfirmation_required?
|
||||
end
|
||||
|
||||
def initialize(*args, &block)
|
||||
@@ -60,7 +60,7 @@ module Devise
|
||||
pending_any_confirmation do
|
||||
if confirmation_period_expired?
|
||||
self.errors.add(:email, :confirmation_period_expired,
|
||||
:period => Devise::TimeInflector.time_ago_in_words(self.class.confirm_within.ago))
|
||||
period: Devise::TimeInflector.time_ago_in_words(self.class.confirm_within.ago))
|
||||
return false
|
||||
end
|
||||
|
||||
@@ -73,9 +73,9 @@ module Devise
|
||||
self.unconfirmed_email = nil
|
||||
|
||||
# We need to validate in such cases to enforce e-mail uniqueness
|
||||
save(:validate => true)
|
||||
save(validate: true)
|
||||
else
|
||||
save(:validate => false)
|
||||
save(validate: false)
|
||||
end
|
||||
|
||||
after_confirmation if saved
|
||||
@@ -98,7 +98,7 @@ module Devise
|
||||
generate_confirmation_token!
|
||||
end
|
||||
|
||||
opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
|
||||
opts = pending_reconfirmation? ? { to: unconfirmed_email } : { }
|
||||
send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
|
||||
end
|
||||
|
||||
@@ -225,7 +225,7 @@ module Devise
|
||||
end
|
||||
|
||||
def generate_confirmation_token!
|
||||
generate_confirmation_token && save(:validate => false)
|
||||
generate_confirmation_token && save(validate: false)
|
||||
end
|
||||
|
||||
def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
|
||||
|
||||
@@ -4,7 +4,7 @@ require 'bcrypt'
|
||||
module Devise
|
||||
# Digests the password using bcrypt.
|
||||
def self.bcrypt(klass, password)
|
||||
::BCrypt::Password.create("#{password}#{klass.pepper}", :cost => klass.stretches).to_s
|
||||
::BCrypt::Password.create("#{password}#{klass.pepper}", cost: klass.stretches).to_s
|
||||
end
|
||||
|
||||
module Models
|
||||
|
||||
@@ -22,7 +22,7 @@ module Devise
|
||||
module Lockable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class"
|
||||
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, to: "self.class"
|
||||
|
||||
def self.required_fields(klass)
|
||||
attributes = []
|
||||
@@ -36,14 +36,14 @@ module Devise
|
||||
# Lock a user setting its locked_at to actual time.
|
||||
# * +opts+: Hash options if you don't want to send email
|
||||
# when you lock access, you could pass the next hash
|
||||
# `{ :send_instructions => false } as option`.
|
||||
# `{ send_instructions: false } as option`.
|
||||
def lock_access!(opts = { })
|
||||
self.locked_at = Time.now.utc
|
||||
|
||||
if unlock_strategy_enabled?(:email) && opts.fetch(:send_instructions, true)
|
||||
send_unlock_instructions
|
||||
else
|
||||
save(:validate => false)
|
||||
save(validate: false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ module Devise
|
||||
self.locked_at = nil
|
||||
self.failed_attempts = 0 if respond_to?(:failed_attempts=)
|
||||
self.unlock_token = nil if respond_to?(:unlock_token=)
|
||||
save(:validate => false)
|
||||
save(validate: false)
|
||||
end
|
||||
|
||||
# Verifies whether a user is locked or not.
|
||||
@@ -64,7 +64,7 @@ module Devise
|
||||
def send_unlock_instructions
|
||||
raw, enc = Devise.token_generator.generate(self.class, :unlock_token)
|
||||
self.unlock_token = enc
|
||||
self.save(:validate => false)
|
||||
self.save(validate: false)
|
||||
send_devise_notification(:unlock_instructions, raw, {})
|
||||
raw
|
||||
end
|
||||
@@ -104,7 +104,7 @@ module Devise
|
||||
if attempts_exceeded?
|
||||
lock_access! unless access_locked?
|
||||
else
|
||||
save(:validate => false)
|
||||
save(validate: false)
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ module Devise
|
||||
#
|
||||
# * +omniauth_providers+: Which providers are available to this model. It expects an array:
|
||||
#
|
||||
# devise_for :database_authenticatable, :omniauthable, :omniauth_providers => [:twitter]
|
||||
# devise_for :database_authenticatable, :omniauthable, omniauth_providers: [:twitter]
|
||||
#
|
||||
module Omniauthable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
@@ -49,7 +49,7 @@ module Devise
|
||||
|
||||
self.reset_password_token = enc
|
||||
self.reset_password_sent_at = Time.now.utc
|
||||
self.save(:validate => false)
|
||||
self.save(validate: false)
|
||||
|
||||
send_devise_notification(:reset_password_instructions, raw, {})
|
||||
raw
|
||||
|
||||
@@ -50,7 +50,7 @@ module Devise
|
||||
def remember_me!(extend_period=false)
|
||||
self.remember_token = self.class.remember_token if generate_remember_token?
|
||||
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
|
||||
save(:validate => false) if self.changed?
|
||||
save(validate: false) if self.changed?
|
||||
end
|
||||
|
||||
# If the record is persisted, remove the remember token (but only if
|
||||
@@ -59,7 +59,7 @@ module Devise
|
||||
return unless persisted?
|
||||
self.remember_token = nil if respond_to?(:remember_token=)
|
||||
self.remember_created_at = nil
|
||||
save(:validate => false)
|
||||
save(validate: false)
|
||||
end
|
||||
|
||||
# Remember token should be expired if expiration time not overpass now.
|
||||
@@ -118,7 +118,7 @@ module Devise
|
||||
def remember_token #:nodoc:
|
||||
loop do
|
||||
token = Devise.friendly_token
|
||||
break token unless to_adapter.find_first({ :remember_token => token })
|
||||
break token unless to_adapter.find_first({ remember_token: token })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ module Devise
|
||||
self.sign_in_count ||= 0
|
||||
self.sign_in_count += 1
|
||||
|
||||
save(:validate => false) or raise "Devise trackable could not save #{inspect}." \
|
||||
save(validate: false) or raise "Devise trackable could not save #{inspect}." \
|
||||
"Please make sure a model using trackable can be saved at sign in."
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,13 +26,13 @@ module Devise
|
||||
assert_validations_api!(base)
|
||||
|
||||
base.class_eval do
|
||||
validates_presence_of :email, :if => :email_required?
|
||||
validates_uniqueness_of :email, :allow_blank => true, :if => :email_changed?
|
||||
validates_format_of :email, :with => email_regexp, :allow_blank => true, :if => :email_changed?
|
||||
validates_presence_of :email, if: :email_required?
|
||||
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
|
||||
validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
|
||||
|
||||
validates_presence_of :password, :if => :password_required?
|
||||
validates_confirmation_of :password, :if => :password_required?
|
||||
validates_length_of :password, :within => password_length, :allow_blank => true
|
||||
validates_presence_of :password, if: :password_required?
|
||||
validates_confirmation_of :password, if: :password_required?
|
||||
validates_length_of :password, within: password_length, allow_blank: true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
require 'active_support/core_ext/object/with_options'
|
||||
|
||||
Devise.with_options :model => true do |d|
|
||||
Devise.with_options model: true do |d|
|
||||
# Strategies first
|
||||
d.with_options :strategy => true do |s|
|
||||
d.with_options strategy: true do |s|
|
||||
routes = [nil, :new, :destroy]
|
||||
s.add_module :database_authenticatable, :controller => :sessions, :route => { :session => routes }
|
||||
s.add_module :rememberable, :no_input => true
|
||||
s.add_module :database_authenticatable, controller: :sessions, route: { session: routes }
|
||||
s.add_module :rememberable, no_input: true
|
||||
end
|
||||
|
||||
# Other authentications
|
||||
d.add_module :omniauthable, :controller => :omniauth_callbacks, :route => :omniauth_callback
|
||||
d.add_module :omniauthable, controller: :omniauth_callbacks, route: :omniauth_callback
|
||||
|
||||
# Misc after
|
||||
routes = [nil, :new, :edit]
|
||||
d.add_module :recoverable, :controller => :passwords, :route => { :password => routes }
|
||||
d.add_module :registerable, :controller => :registrations, :route => { :registration => (routes << :cancel) }
|
||||
d.add_module :recoverable, controller: :passwords, route: { password: routes }
|
||||
d.add_module :registerable, controller: :registrations, route: { registration: (routes << :cancel) }
|
||||
d.add_module :validatable
|
||||
|
||||
# The ones which can sign out after
|
||||
routes = [nil, :new]
|
||||
d.add_module :confirmable, :controller => :confirmations, :route => { :confirmation => routes }
|
||||
d.add_module :lockable, :controller => :unlocks, :route => { :unlock => routes }
|
||||
d.add_module :confirmable, controller: :confirmations, route: { confirmation: routes }
|
||||
d.add_module :lockable, controller: :unlocks, route: { unlock: routes }
|
||||
d.add_module :timeoutable
|
||||
|
||||
# Stats for last, so we make sure the user is really signed in
|
||||
|
||||
@@ -6,12 +6,12 @@ module Devise
|
||||
|
||||
def omniauth_authorize_path(resource_or_scope, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
send("#{scope}_omniauth_authorize_path", *args)
|
||||
_devise_route_context.send("#{scope}_omniauth_authorize_path", *args)
|
||||
end
|
||||
|
||||
def omniauth_callback_path(resource_or_scope, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
send("#{scope}_omniauth_callback_path", *args)
|
||||
_devise_route_context.send("#{scope}_omniauth_callback_path", *args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
config.after_initialize do |app|
|
||||
initializer "devise.secret_key" do |app|
|
||||
if app.respond_to?(:secrets)
|
||||
Devise.secret_key ||= app.secrets.secret_key_base
|
||||
elsif app.config.respond_to?(:secret_key_base)
|
||||
|
||||
@@ -43,20 +43,20 @@ module ActionDispatch::Routing
|
||||
# needed routes:
|
||||
#
|
||||
# # Session routes for Authenticatable (default)
|
||||
# new_user_session GET /users/sign_in {:controller=>"devise/sessions", :action=>"new"}
|
||||
# user_session POST /users/sign_in {:controller=>"devise/sessions", :action=>"create"}
|
||||
# destroy_user_session DELETE /users/sign_out {:controller=>"devise/sessions", :action=>"destroy"}
|
||||
# new_user_session GET /users/sign_in {controller:"devise/sessions", action:"new"}
|
||||
# user_session POST /users/sign_in {controller:"devise/sessions", action:"create"}
|
||||
# destroy_user_session DELETE /users/sign_out {controller:"devise/sessions", action:"destroy"}
|
||||
#
|
||||
# # Password routes for Recoverable, if User model has :recoverable configured
|
||||
# new_user_password GET /users/password/new(.:format) {:controller=>"devise/passwords", :action=>"new"}
|
||||
# edit_user_password GET /users/password/edit(.:format) {:controller=>"devise/passwords", :action=>"edit"}
|
||||
# user_password PUT /users/password(.:format) {:controller=>"devise/passwords", :action=>"update"}
|
||||
# POST /users/password(.:format) {:controller=>"devise/passwords", :action=>"create"}
|
||||
# new_user_password GET /users/password/new(.:format) {controller:"devise/passwords", action:"new"}
|
||||
# edit_user_password GET /users/password/edit(.:format) {controller:"devise/passwords", action:"edit"}
|
||||
# user_password PUT /users/password(.:format) {controller:"devise/passwords", action:"update"}
|
||||
# POST /users/password(.:format) {controller:"devise/passwords", action:"create"}
|
||||
#
|
||||
# # Confirmation routes for Confirmable, if User model has :confirmable configured
|
||||
# new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"devise/confirmations", :action=>"new"}
|
||||
# user_confirmation GET /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"show"}
|
||||
# POST /users/confirmation(.:format) {:controller=>"devise/confirmations", :action=>"create"}
|
||||
# new_user_confirmation GET /users/confirmation/new(.:format) {controller:"devise/confirmations", action:"new"}
|
||||
# user_confirmation GET /users/confirmation(.:format) {controller:"devise/confirmations", action:"show"}
|
||||
# POST /users/confirmation(.:format) {controller:"devise/confirmations", action:"create"}
|
||||
#
|
||||
# ==== Routes integration
|
||||
#
|
||||
@@ -84,22 +84,22 @@ module ActionDispatch::Routing
|
||||
#
|
||||
# You can configure your routes with some options:
|
||||
#
|
||||
# * :class_name => setup a different class to be looked up by devise, if it cannot be
|
||||
# * class_name: setup a different class to be looked up by devise, if it cannot be
|
||||
# properly found by the route name.
|
||||
#
|
||||
# devise_for :users, :class_name => 'Account'
|
||||
# devise_for :users, class_name: 'Account'
|
||||
#
|
||||
# * :path => allows you to setup path name that will be used, as rails routes does.
|
||||
# * path: allows you to setup path name that will be used, as rails routes does.
|
||||
# The following route configuration would setup your route as /accounts instead of /users:
|
||||
#
|
||||
# devise_for :users, :path => 'accounts'
|
||||
# devise_for :users, path: 'accounts'
|
||||
#
|
||||
# * :singular => setup the singular name for the given resource. This is used as the instance variable
|
||||
# * singular: setup the singular name for the given resource. This is used as the instance variable
|
||||
# name in controller, as the name in routes and the scope given to warden.
|
||||
#
|
||||
# devise_for :users, :singular => :user
|
||||
# devise_for :users, singular: :user
|
||||
#
|
||||
# * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
|
||||
# * path_names: configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,
|
||||
# :password, :confirmation, :unlock.
|
||||
#
|
||||
# devise_for :users, path_names: {
|
||||
@@ -108,50 +108,50 @@ module ActionDispatch::Routing
|
||||
# registration: 'register', edit: 'edit/profile'
|
||||
# }
|
||||
#
|
||||
# * :controllers => the controller which should be used. All routes by default points to Devise controllers.
|
||||
# * controllers: the controller which should be used. All routes by default points to Devise controllers.
|
||||
# However, if you want them to point to custom controller, you should do:
|
||||
#
|
||||
# devise_for :users, :controllers => { :sessions => "users/sessions" }
|
||||
# devise_for :users, controllers: { sessions: "users/sessions" }
|
||||
#
|
||||
# * :failure_app => a rack app which is invoked whenever there is a failure. Strings representing a given
|
||||
# * failure_app: a rack app which is invoked whenever there is a failure. Strings representing a given
|
||||
# are also allowed as parameter.
|
||||
#
|
||||
# * :sign_out_via => the HTTP method(s) accepted for the :sign_out action (default: :get),
|
||||
# * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :get),
|
||||
# if you wish to restrict this to accept only :post or :delete requests you should do:
|
||||
#
|
||||
# devise_for :users, :sign_out_via => [ :post, :delete ]
|
||||
# devise_for :users, sign_out_via: [ :post, :delete ]
|
||||
#
|
||||
# You need to make sure that your sign_out controls trigger a request with a matching HTTP method.
|
||||
#
|
||||
# * :module => the namespace to find controllers (default: "devise", thus
|
||||
# * module: the namespace to find controllers (default: "devise", thus
|
||||
# accessing devise/sessions, devise/registrations, and so on). If you want
|
||||
# to namespace all at once, use module:
|
||||
#
|
||||
# devise_for :users, :module => "users"
|
||||
# devise_for :users, module: "users"
|
||||
#
|
||||
# * :skip => tell which controller you want to skip routes from being created:
|
||||
# * skip: tell which controller you want to skip routes from being created:
|
||||
#
|
||||
# devise_for :users, :skip => :sessions
|
||||
# devise_for :users, skip: :sessions
|
||||
#
|
||||
# * :only => the opposite of :skip, tell which controllers only to generate routes to:
|
||||
# * only: the opposite of :skip, tell which controllers only to generate routes to:
|
||||
#
|
||||
# devise_for :users, :only => :sessions
|
||||
# devise_for :users, only: :sessions
|
||||
#
|
||||
# * :skip_helpers => skip generating Devise url helpers like new_session_path(@user).
|
||||
# * skip_helpers: skip generating Devise url helpers like new_session_path(@user).
|
||||
# This is useful to avoid conflicts with previous routes and is false by default.
|
||||
# It accepts true as option, meaning it will skip all the helpers for the controllers
|
||||
# given in :skip but it also accepts specific helpers to be skipped:
|
||||
#
|
||||
# devise_for :users, :skip => [:registrations, :confirmations], :skip_helpers => true
|
||||
# devise_for :users, :skip_helpers => [:registrations, :confirmations]
|
||||
# devise_for :users, skip: [:registrations, :confirmations], skip_helpers: true
|
||||
# devise_for :users, skip_helpers: [:registrations, :confirmations]
|
||||
#
|
||||
# * :format => include "(.:format)" in the generated routes? true by default, set to false to disable:
|
||||
# * format: include "(.:format)" in the generated routes? true by default, set to false to disable:
|
||||
#
|
||||
# devise_for :users, :format => false
|
||||
# devise_for :users, format: false
|
||||
#
|
||||
# * :constraints => works the same as Rails' constraints
|
||||
# * constraints: works the same as Rails' constraints
|
||||
#
|
||||
# * :defaults => works the same as Rails' defaults
|
||||
# * defaults: works the same as Rails' defaults
|
||||
#
|
||||
# ==== Scoping
|
||||
#
|
||||
@@ -173,7 +173,7 @@ module ActionDispatch::Routing
|
||||
#
|
||||
# class ApplicationController < ActionController::Base
|
||||
# def self.default_url_options
|
||||
# { :locale => I18n.locale }
|
||||
# { locale: I18n.locale }
|
||||
# end
|
||||
# end
|
||||
#
|
||||
@@ -198,7 +198,7 @@ module ActionDispatch::Routing
|
||||
# In order to get Devise to recognize the deactivate action, your devise_scope entry should look like this:
|
||||
#
|
||||
# devise_scope :owner do
|
||||
# post "deactivate", :to => "registrations#deactivate", :as => "deactivate_registration"
|
||||
# post "deactivate", to: "registrations#deactivate", as: "deactivate_registration"
|
||||
# end
|
||||
#
|
||||
def devise_for(*resources)
|
||||
@@ -263,7 +263,7 @@ module ActionDispatch::Routing
|
||||
# end
|
||||
#
|
||||
# authenticate :user, lambda {|u| u.role == "admin"} do
|
||||
# root :to => "admin/dashboard#show", :as => :user_root
|
||||
# root to: "admin/dashboard#show", as: :user_root
|
||||
# end
|
||||
#
|
||||
def authenticate(scope=nil, block=nil)
|
||||
@@ -277,18 +277,18 @@ module ActionDispatch::Routing
|
||||
# a model and allows extra constraints to be done on the instance.
|
||||
#
|
||||
# authenticated :admin do
|
||||
# root :to => 'admin/dashboard#show', :as => :admin_root
|
||||
# root to: 'admin/dashboard#show', as: :admin_root
|
||||
# end
|
||||
#
|
||||
# authenticated do
|
||||
# root :to => 'dashboard#show', :as => :authenticated_root
|
||||
# root to: 'dashboard#show', as: :authenticated_root
|
||||
# end
|
||||
#
|
||||
# authenticated :user, lambda {|u| u.role == "admin"} do
|
||||
# root :to => "admin/dashboard#show", :as => :user_root
|
||||
# root to: "admin/dashboard#show", as: :user_root
|
||||
# end
|
||||
#
|
||||
# root :to => 'landing#show'
|
||||
# root to: 'landing#show'
|
||||
#
|
||||
def authenticated(scope=nil, block=nil)
|
||||
constraints_for(:authenticate?, scope, block) do
|
||||
@@ -301,15 +301,15 @@ module ActionDispatch::Routing
|
||||
#
|
||||
# unauthenticated do
|
||||
# as :user do
|
||||
# root :to => 'devise/registrations#new'
|
||||
# root to: 'devise/registrations#new'
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# root :to => 'dashboard#show'
|
||||
# root to: 'dashboard#show'
|
||||
#
|
||||
def unauthenticated(scope=nil)
|
||||
constraint = lambda do |request|
|
||||
not request.env["warden"].authenticate? :scope => scope
|
||||
not request.env["warden"].authenticate? scope: scope
|
||||
end
|
||||
|
||||
constraints(constraint) do
|
||||
@@ -322,7 +322,7 @@ module ActionDispatch::Routing
|
||||
# to which controller it is targetted.
|
||||
#
|
||||
# as :user do
|
||||
# get "sign_in", :to => "devise/sessions#new"
|
||||
# get "sign_in", to: "devise/sessions#new"
|
||||
# end
|
||||
#
|
||||
# Notice you cannot have two scopes mapping to the same URL. And remember, if
|
||||
@@ -354,42 +354,42 @@ module ActionDispatch::Routing
|
||||
protected
|
||||
|
||||
def devise_session(mapping, controllers) #:nodoc:
|
||||
resource :session, :only => [], :controller => controllers[:sessions], :path => "" do
|
||||
get :new, :path => mapping.path_names[:sign_in], :as => "new"
|
||||
post :create, :path => mapping.path_names[:sign_in]
|
||||
match :destroy, :path => mapping.path_names[:sign_out], :as => "destroy", :via => mapping.sign_out_via
|
||||
resource :session, only: [], controller: controllers[:sessions], path: "" do
|
||||
get :new, path: mapping.path_names[:sign_in], as: "new"
|
||||
post :create, path: mapping.path_names[:sign_in]
|
||||
match :destroy, path: mapping.path_names[:sign_out], as: "destroy", via: mapping.sign_out_via
|
||||
end
|
||||
end
|
||||
|
||||
def devise_password(mapping, controllers) #:nodoc:
|
||||
resource :password, :only => [:new, :create, :edit, :update],
|
||||
:path => mapping.path_names[:password], :controller => controllers[:passwords]
|
||||
resource :password, only: [:new, :create, :edit, :update],
|
||||
path: mapping.path_names[:password], controller: controllers[:passwords]
|
||||
end
|
||||
|
||||
def devise_confirmation(mapping, controllers) #:nodoc:
|
||||
resource :confirmation, :only => [:new, :create, :show],
|
||||
:path => mapping.path_names[:confirmation], :controller => controllers[:confirmations]
|
||||
resource :confirmation, only: [:new, :create, :show],
|
||||
path: mapping.path_names[:confirmation], controller: controllers[:confirmations]
|
||||
end
|
||||
|
||||
def devise_unlock(mapping, controllers) #:nodoc:
|
||||
if mapping.to.unlock_strategy_enabled?(:email)
|
||||
resource :unlock, :only => [:new, :create, :show],
|
||||
:path => mapping.path_names[:unlock], :controller => controllers[:unlocks]
|
||||
resource :unlock, only: [:new, :create, :show],
|
||||
path: mapping.path_names[:unlock], controller: controllers[:unlocks]
|
||||
end
|
||||
end
|
||||
|
||||
def devise_registration(mapping, controllers) #:nodoc:
|
||||
path_names = {
|
||||
:new => mapping.path_names[:sign_up],
|
||||
:edit => mapping.path_names[:edit],
|
||||
:cancel => mapping.path_names[:cancel]
|
||||
new: mapping.path_names[:sign_up],
|
||||
edit: mapping.path_names[:edit],
|
||||
cancel: mapping.path_names[:cancel]
|
||||
}
|
||||
|
||||
options = {
|
||||
:only => [:new, :create, :edit, :update, :destroy],
|
||||
:path => mapping.path_names[:registration],
|
||||
:path_names => path_names,
|
||||
:controller => controllers[:registrations]
|
||||
only: [:new, :create, :edit, :update, :destroy],
|
||||
path: mapping.path_names[:registration],
|
||||
path_names: path_names,
|
||||
controller: controllers[:registrations]
|
||||
}
|
||||
|
||||
resource :registration, options do
|
||||
@@ -405,16 +405,16 @@ and you have set #{mapping.fullpath.inspect}. You can work around by passing
|
||||
`skip: :omniauth_callbacks` and manually defining the routes. Here is an example:
|
||||
|
||||
match "/users/auth/:provider",
|
||||
:constraints => { :provider => /google|facebook/ },
|
||||
:to => "devise/omniauth_callbacks#passthru",
|
||||
:as => :omniauth_authorize,
|
||||
:via => [:get, :post]
|
||||
constraints: { provider: /google|facebook/ },
|
||||
to: "devise/omniauth_callbacks#passthru",
|
||||
as: :omniauth_authorize,
|
||||
via: [:get, :post]
|
||||
|
||||
match "/users/auth/:action/callback",
|
||||
:constraints => { :action => /google|facebook/ },
|
||||
:to => "devise/omniauth_callbacks",
|
||||
:as => :omniauth_callback,
|
||||
:via => [:get, :post]
|
||||
constraints: { action: /google|facebook/ },
|
||||
to: "devise/omniauth_callbacks",
|
||||
as: :omniauth_callback,
|
||||
via: [:get, :post]
|
||||
ERROR
|
||||
end
|
||||
|
||||
@@ -426,16 +426,16 @@ ERROR
|
||||
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
|
||||
|
||||
match "#{path_prefix}/:provider",
|
||||
:constraints => { :provider => providers },
|
||||
:to => "#{controllers[:omniauth_callbacks]}#passthru",
|
||||
:as => :omniauth_authorize,
|
||||
:via => [:get, :post]
|
||||
constraints: { provider: providers },
|
||||
to: "#{controllers[:omniauth_callbacks]}#passthru",
|
||||
as: :omniauth_authorize,
|
||||
via: [:get, :post]
|
||||
|
||||
match "#{path_prefix}/:action/callback",
|
||||
:constraints => { :action => providers },
|
||||
:to => controllers[:omniauth_callbacks],
|
||||
:as => :omniauth_callback,
|
||||
:via => [:get, :post]
|
||||
constraints: { action: providers },
|
||||
to: controllers[:omniauth_callbacks],
|
||||
as: :omniauth_callback,
|
||||
via: [:get, :post]
|
||||
ensure
|
||||
@scope[:path] = path
|
||||
end
|
||||
@@ -446,7 +446,7 @@ ERROR
|
||||
old = {}
|
||||
DEVISE_SCOPE_KEYS.each { |k| old[k] = @scope[k] }
|
||||
|
||||
new = { :as => new_as, :path => new_path, :module => nil }
|
||||
new = { as: new_as, path: new_path, module: nil }
|
||||
new.merge!(options.slice(:constraints, :defaults, :options))
|
||||
|
||||
@scope.merge!(new)
|
||||
@@ -457,7 +457,7 @@ ERROR
|
||||
|
||||
def constraints_for(method_to_apply, scope=nil, block=nil)
|
||||
constraint = lambda do |request|
|
||||
request.env['warden'].send(method_to_apply, :scope => scope) &&
|
||||
request.env['warden'].send(method_to_apply, scope: scope) &&
|
||||
(block.nil? || block.call(request.env["warden"].user(scope)))
|
||||
end
|
||||
|
||||
|
||||
@@ -109,8 +109,8 @@ module Devise
|
||||
|
||||
status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
|
||||
@controller.response.headers.merge!(headers)
|
||||
@controller.send :render, :status => status, :text => response.body,
|
||||
:content_type => headers["Content-Type"], :location => headers["Location"]
|
||||
@controller.send :render, status: status, text: response.body,
|
||||
content_type: headers["Content-Type"], location: headers["Location"]
|
||||
nil # causes process return @response
|
||||
end
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ module Devise
|
||||
|
||||
class << self
|
||||
attr_reader :instance
|
||||
delegate :time_ago_in_words, :to => :instance
|
||||
delegate :time_ago_in_words, to: :instance
|
||||
end
|
||||
|
||||
@instance = new
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Devise
|
||||
VERSION = "3.2.3".freeze
|
||||
VERSION = "3.2.4".freeze
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ require 'generators/devise/orm_helpers'
|
||||
module ActiveRecord
|
||||
module Generators
|
||||
class DeviseGenerator < ActiveRecord::Generators::Base
|
||||
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
||||
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
||||
|
||||
include Devise::Generators::OrmHelpers
|
||||
source_root File.expand_path("../templates", __FILE__)
|
||||
@@ -18,7 +18,7 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
def generate_model
|
||||
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
||||
invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
|
||||
end
|
||||
|
||||
def inject_devise_content
|
||||
@@ -39,8 +39,8 @@ module ActiveRecord
|
||||
def migration_data
|
||||
<<RUBY
|
||||
## Database authenticatable
|
||||
t.string :email, :null => false, :default => ""
|
||||
t.string :encrypted_password, :null => false, :default => ""
|
||||
t.string :email, null: false, default: ""
|
||||
t.string :encrypted_password, null: false, default: ""
|
||||
|
||||
## Recoverable
|
||||
t.string :reset_password_token
|
||||
@@ -50,7 +50,7 @@ module ActiveRecord
|
||||
t.datetime :remember_created_at
|
||||
|
||||
## Trackable
|
||||
t.integer :sign_in_count, :default => 0, :null => false
|
||||
t.integer :sign_in_count, default: 0, null: false
|
||||
t.datetime :current_sign_in_at
|
||||
t.datetime :last_sign_in_at
|
||||
t.string :current_sign_in_ip
|
||||
@@ -63,7 +63,7 @@ module ActiveRecord
|
||||
# t.string :unconfirmed_email # Only if using reconfirmable
|
||||
|
||||
## Lockable
|
||||
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
|
||||
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
||||
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
||||
# t.datetime :locked_at
|
||||
RUBY
|
||||
|
||||
@@ -10,9 +10,9 @@ class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :<%= table_name %>, :email, :unique => true
|
||||
add_index :<%= table_name %>, :reset_password_token, :unique => true
|
||||
# add_index :<%= table_name %>, :confirmation_token, :unique => true
|
||||
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
||||
add_index :<%= table_name %>, :email, unique: true
|
||||
add_index :<%= table_name %>, :reset_password_token, unique: true
|
||||
# add_index :<%= table_name %>, :confirmation_token, unique: true
|
||||
# add_index :<%= table_name %>, :unlock_token, unique: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,10 +11,10 @@ class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration
|
||||
# t.timestamps
|
||||
end
|
||||
|
||||
add_index :<%= table_name %>, :email, :unique => true
|
||||
add_index :<%= table_name %>, :reset_password_token, :unique => true
|
||||
# add_index :<%= table_name %>, :confirmation_token, :unique => true
|
||||
# add_index :<%= table_name %>, :unlock_token, :unique => true
|
||||
add_index :<%= table_name %>, :email, unique: true
|
||||
add_index :<%= table_name %>, :reset_password_token, unique: true
|
||||
# add_index :<%= table_name %>, :confirmation_token, unique: true
|
||||
# add_index :<%= table_name %>, :unlock_token, unique: true
|
||||
end
|
||||
|
||||
def self.down
|
||||
|
||||
@@ -13,12 +13,12 @@ module Devise
|
||||
|
||||
hook_for :orm
|
||||
|
||||
class_option :routes, :desc => "Generate routes", :type => :boolean, :default => true
|
||||
class_option :routes, desc: "Generate routes", type: :boolean, default: true
|
||||
|
||||
def add_devise_routes
|
||||
devise_route = "devise_for :#{plural_name}"
|
||||
devise_route << %Q(, :class_name => "#{class_name}") if class_name.include?("::")
|
||||
devise_route << %Q(, :skip => :all) unless options.routes?
|
||||
devise_route << %Q(, class_name: "#{class_name}") if class_name.include?("::")
|
||||
devise_route << %Q(, skip: :all) unless options.routes?
|
||||
route devise_route
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,13 +9,14 @@ module Devise
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
argument :scope, :required => false, :default => nil,
|
||||
:desc => "The scope to copy views to"
|
||||
argument :scope, required: false, default: nil,
|
||||
desc: "The scope to copy views to"
|
||||
|
||||
# Le sigh, ensure Thor won't handle opts as args
|
||||
# It should be fixed in future Rails releases
|
||||
class_option :form_builder, :aliases => "-b"
|
||||
class_option :form_builder, aliases: "-b"
|
||||
class_option :markerb
|
||||
class_option :views, aliases: "-v", type: :array, desc: "Select specific view directories to generate (confirmations, passwords, registrations, sessions, unlocks, mailer)"
|
||||
|
||||
public_task :copy_views
|
||||
end
|
||||
@@ -28,11 +29,17 @@ module Devise
|
||||
end
|
||||
|
||||
def copy_views
|
||||
view_directory :confirmations
|
||||
view_directory :passwords
|
||||
view_directory :registrations
|
||||
view_directory :sessions
|
||||
view_directory :unlocks
|
||||
if options[:views]
|
||||
options[:views].each do |directory|
|
||||
view_directory directory.to_sym
|
||||
end
|
||||
else
|
||||
view_directory :confirmations
|
||||
view_directory :passwords
|
||||
view_directory :registrations
|
||||
view_directory :sessions
|
||||
view_directory :unlocks
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
@@ -85,7 +92,9 @@ module Devise
|
||||
hide!
|
||||
|
||||
def copy_views
|
||||
view_directory :mailer
|
||||
if !options[:views] || options[:views].include?('mailer')
|
||||
view_directory :mailer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -96,7 +105,9 @@ module Devise
|
||||
hide!
|
||||
|
||||
def copy_views
|
||||
view_directory :markerb, target_path
|
||||
if !options[:views] || options[:views].include?('mailer')
|
||||
view_directory :markerb, target_path
|
||||
end
|
||||
end
|
||||
|
||||
def target_path
|
||||
@@ -107,18 +118,18 @@ module Devise
|
||||
class ViewsGenerator < Rails::Generators::Base
|
||||
desc "Copies Devise views to your application."
|
||||
|
||||
argument :scope, :required => false, :default => nil,
|
||||
:desc => "The scope to copy views to"
|
||||
argument :scope, required: false, default: nil,
|
||||
desc: "The scope to copy views to"
|
||||
|
||||
invoke SharedViewsGenerator
|
||||
|
||||
hook_for :form_builder, :aliases => "-b",
|
||||
:desc => "Form builder to be used",
|
||||
:default => defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
||||
hook_for :form_builder, aliases: "-b",
|
||||
desc: "Form builder to be used",
|
||||
default: defined?(SimpleForm) ? "simple_form_for" : "form_for"
|
||||
|
||||
hook_for :markerb, :desc => "Generate markerb instead of erb mail views",
|
||||
:default => defined?(Markerb) ? :markerb : :erb,
|
||||
:type => :boolean
|
||||
hook_for :markerb, desc: "Generate markerb instead of erb mail views",
|
||||
default: defined?(Markerb) ? :markerb : :erb,
|
||||
type: :boolean
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,43 +11,43 @@ module Mongoid
|
||||
end
|
||||
|
||||
def inject_field_types
|
||||
inject_into_file model_path, migration_data, :after => "include Mongoid::Document\n" if model_exists?
|
||||
inject_into_file model_path, migration_data, after: "include Mongoid::Document\n" if model_exists?
|
||||
end
|
||||
|
||||
def inject_devise_content
|
||||
inject_into_file model_path, model_contents, :after => "include Mongoid::Document\n" if model_exists?
|
||||
inject_into_file model_path, model_contents, after: "include Mongoid::Document\n" if model_exists?
|
||||
end
|
||||
|
||||
def migration_data
|
||||
<<RUBY
|
||||
## Database authenticatable
|
||||
field :email, :type => String, :default => ""
|
||||
field :encrypted_password, :type => String, :default => ""
|
||||
field :email, type: String, default: ""
|
||||
field :encrypted_password, type: String, default: ""
|
||||
|
||||
## Recoverable
|
||||
field :reset_password_token, :type => String
|
||||
field :reset_password_sent_at, :type => Time
|
||||
field :reset_password_token, type: String
|
||||
field :reset_password_sent_at, type: Time
|
||||
|
||||
## Rememberable
|
||||
field :remember_created_at, :type => Time
|
||||
field :remember_created_at, type: Time
|
||||
|
||||
## Trackable
|
||||
field :sign_in_count, :type => Integer, :default => 0
|
||||
field :current_sign_in_at, :type => Time
|
||||
field :last_sign_in_at, :type => Time
|
||||
field :current_sign_in_ip, :type => String
|
||||
field :last_sign_in_ip, :type => String
|
||||
field :sign_in_count, type: Integer, default: 0
|
||||
field :current_sign_in_at, type: Time
|
||||
field :last_sign_in_at, type: Time
|
||||
field :current_sign_in_ip, type: String
|
||||
field :last_sign_in_ip, type: String
|
||||
|
||||
## Confirmable
|
||||
# field :confirmation_token, :type => String
|
||||
# field :confirmed_at, :type => Time
|
||||
# field :confirmation_sent_at, :type => Time
|
||||
# field :unconfirmed_email, :type => String # Only if using reconfirmable
|
||||
# field :confirmation_token, type: String
|
||||
# field :confirmed_at, type: Time
|
||||
# field :confirmation_sent_at, type: Time
|
||||
# field :unconfirmed_email, type: String # Only if using reconfirmable
|
||||
|
||||
## Lockable
|
||||
# field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
|
||||
# field :unlock_token, :type => String # Only if unlock strategy is :email or :both
|
||||
# field :locked_at, :type => Time
|
||||
# field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
|
||||
# field :unlock_token, type: String # Only if unlock strategy is :email or :both
|
||||
# field :locked_at, type: Time
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,14 +6,14 @@ Some setup you must do manually if you haven't yet:
|
||||
is an example of default_url_options appropriate for a development environment
|
||||
in config/environments/development.rb:
|
||||
|
||||
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
||||
config.action_mailer.default_url_options = { host: 'localhost:3000' }
|
||||
|
||||
In production, :host should be set to the actual host of your application.
|
||||
|
||||
2. Ensure you have defined root_url to *something* in your config/routes.rb.
|
||||
For example:
|
||||
|
||||
root :to => "home#index"
|
||||
root to: "home#index"
|
||||
|
||||
3. Ensure you have flash messages in app/views/layouts/application.html.erb.
|
||||
For example:
|
||||
|
||||
@@ -80,7 +80,7 @@ Devise.setup do |config|
|
||||
# particular strategies by setting this option.
|
||||
# Notice that if you are skipping storage for all authentication paths, you
|
||||
# may want to disable generating routes to Devise's sessions controller by
|
||||
# passing :skip => :sessions to `devise_for` in your config/routes.rb
|
||||
# passing skip: :sessions to `devise_for` in your config/routes.rb
|
||||
config.skip_session_storage = [:http_auth]
|
||||
|
||||
# By default, Devise cleans up the CSRF token on authentication to
|
||||
@@ -95,7 +95,9 @@ Devise.setup do |config|
|
||||
#
|
||||
# Limiting the stretches to just one in testing will increase the performance of
|
||||
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
|
||||
# a value less than 10 in other environments.
|
||||
# a value less than 10 in other environments. Note that, for bcrypt (the default
|
||||
# encryptor), the cost increases exponentially with the number of stretches (e.g.
|
||||
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
|
||||
config.stretches = Rails.env.test? ? 1 : 10
|
||||
|
||||
# Setup a pepper to generate the encrypted password.
|
||||
@@ -119,8 +121,8 @@ Devise.setup do |config|
|
||||
|
||||
# If true, requires any email changes to be confirmed (exactly the same way as
|
||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||
# db field (see migrations). Until confirmed new email is stored in
|
||||
# unconfirmed email column, and copied to email column on successful confirmation.
|
||||
# db field (see migrations). Until confirmed, new email is stored in
|
||||
# unconfirmed_email column, and copied to email column on successful confirmation.
|
||||
config.reconfirmable = true
|
||||
|
||||
# Defines which key will be used when confirming an account
|
||||
@@ -134,7 +136,7 @@ Devise.setup do |config|
|
||||
# config.extend_remember_period = false
|
||||
|
||||
# Options to be passed to the created cookie. For instance, you can set
|
||||
# :secure => true in order to force SSL only cookies.
|
||||
# secure: true in order to force SSL only cookies.
|
||||
# config.rememberable_options = {}
|
||||
|
||||
# ==> Configuration for :validatable
|
||||
@@ -231,7 +233,7 @@ Devise.setup do |config|
|
||||
# ==> OmniAuth
|
||||
# Add a new OmniAuth provider. Check the wiki for more information on setting
|
||||
# up on your models and hooks.
|
||||
# config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
|
||||
# config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'
|
||||
|
||||
# ==> Warden configuration
|
||||
# If you want to use other strategies, that are not supported by Devise, or
|
||||
@@ -239,7 +241,7 @@ Devise.setup do |config|
|
||||
#
|
||||
# config.warden do |manager|
|
||||
# manager.intercept_401 = false
|
||||
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
|
||||
# manager.default_strategies(scope: :user).unshift :some_external_strategy
|
||||
# end
|
||||
|
||||
# ==> Mountable engine configurations
|
||||
|
||||
@@ -2,4 +2,4 @@ Welcome <%= @email %>!
|
||||
|
||||
You can confirm your account through the link below:
|
||||
|
||||
<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @token) %>
|
||||
<%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %>
|
||||
|
||||
@@ -2,7 +2,7 @@ Hello <%= @resource.email %>!
|
||||
|
||||
Someone has requested a link to change your password, and you can do this through the link below.
|
||||
|
||||
<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token) %>
|
||||
<%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %>
|
||||
|
||||
If you didn't request this, please ignore this email.
|
||||
Your password won't change until you access the link above and create a new one.
|
||||
|
||||
@@ -4,4 +4,4 @@ Your account has been locked due to an excessive number of unsuccessful sign in
|
||||
|
||||
Click the link below to unlock your account:
|
||||
|
||||
<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @token) %>
|
||||
<%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<h2>Resend confirmation instructions</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
<%= f.full_error :confirmation_token %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :email, :required => true, :autofocus => true %>
|
||||
<%= f.input :email, required: true, autofocus: true %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<h2>Change your password</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<%= f.input :reset_password_token, :as => :hidden %>
|
||||
<%= f.input :reset_password_token, as: :hidden %>
|
||||
<%= f.full_error :reset_password_token %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :password, :label => "New password", :required => true, :autofocus => true %>
|
||||
<%= f.input :password_confirmation, :label => "Confirm your new password", :required => true %>
|
||||
<%= f.input :password, label: "New password", required: true, autofocus: true %>
|
||||
<%= f.input :password_confirmation, label: "Confirm your new password", required: true %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<h2>Forgot your password?</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :email, :required => true, :autofocus => true %>
|
||||
<%= f.input :email, required: true, autofocus: true %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
<h2>Edit <%= resource_name.to_s.humanize %></h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
|
||||
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :email, :required => true, :autofocus => true %>
|
||||
<%= f.input :email, required: true, autofocus: true %>
|
||||
|
||||
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
|
||||
<p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>
|
||||
<% end %>
|
||||
|
||||
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
|
||||
<%= f.input :password_confirmation, :required => false %>
|
||||
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
|
||||
<%= f.input :password, autocomplete: "off", hint: "leave it blank if you don't want to change it", required: false %>
|
||||
<%= f.input :password_confirmation, required: false %>
|
||||
<%= f.input :current_password, hint: "we need your current password to confirm your changes", required: true %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
@@ -22,6 +22,6 @@
|
||||
|
||||
<h3>Cancel my account</h3>
|
||||
|
||||
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %></p>
|
||||
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
|
||||
|
||||
<%= link_to "Back", :back %>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<h2>Sign up</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
|
||||
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :email, :required => true, :autofocus => true %>
|
||||
<%= f.input :password, :required => true %>
|
||||
<%= f.input :password_confirmation, :required => true %>
|
||||
<%= f.input :email, required: true, autofocus: true %>
|
||||
<%= f.input :password, required: true %>
|
||||
<%= f.input :password_confirmation, required: true %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<h2>Sign in</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
||||
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
|
||||
<div class="form-inputs">
|
||||
<%= f.input :email, :required => false, :autofocus => true %>
|
||||
<%= f.input :password, :required => false %>
|
||||
<%= f.input :remember_me, :as => :boolean if devise_mapping.rememberable? %>
|
||||
<%= f.input :email, required: false, autofocus: true %>
|
||||
<%= f.input :password, required: false %>
|
||||
<%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<h2>Resend unlock instructions</h2>
|
||||
|
||||
<%= simple_form_for(resource, :as => resource_name, :url => unlock_path(resource_name), :html => { :method => :post }) do |f| %>
|
||||
<%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
<%= f.full_error :unlock_token %>
|
||||
|
||||
<div class="form-inputs">
|
||||
<%= f.input :email, :required => true, :autofocus => true %>
|
||||
<%= f.input :email, required: true, autofocus: true %>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
|
||||
@@ -14,81 +14,81 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'proxy signed_in?(scope) to authenticate?' do
|
||||
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
|
||||
@mock_warden.expects(:authenticate?).with(scope: :my_scope)
|
||||
@controller.signed_in?(:my_scope)
|
||||
end
|
||||
|
||||
test 'proxy signed_in?(nil) to authenticate?' do
|
||||
Devise.mappings.keys.each do |scope| # :user, :admin, :manager
|
||||
@mock_warden.expects(:authenticate?).with(:scope => scope)
|
||||
@mock_warden.expects(:authenticate?).with(scope: scope)
|
||||
end
|
||||
@controller.signed_in?
|
||||
end
|
||||
|
||||
test 'proxy current_user to authenticate with user scope' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :user)
|
||||
@mock_warden.expects(:authenticate).with(scope: :user)
|
||||
@controller.current_user
|
||||
end
|
||||
|
||||
test 'proxy current_admin to authenticate with admin scope' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
||||
@mock_warden.expects(:authenticate).with(scope: :admin)
|
||||
@controller.current_admin
|
||||
end
|
||||
|
||||
test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
||||
@mock_warden.expects(:authenticate).with(scope: :publisher_account)
|
||||
@controller.current_publisher_account
|
||||
end
|
||||
|
||||
test 'proxy authenticate_user! to authenticate with user scope' do
|
||||
@mock_warden.expects(:authenticate!).with(:scope => :user)
|
||||
@mock_warden.expects(:authenticate!).with(scope: :user)
|
||||
@controller.authenticate_user!
|
||||
end
|
||||
|
||||
test 'proxy authenticate_user! options to authenticate with user scope' do
|
||||
@mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo")
|
||||
@controller.authenticate_user!(:recall => "foo")
|
||||
@mock_warden.expects(:authenticate!).with(scope: :user, recall: "foo")
|
||||
@controller.authenticate_user!(recall: "foo")
|
||||
end
|
||||
|
||||
test 'proxy authenticate_admin! to authenticate with admin scope' do
|
||||
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
||||
@mock_warden.expects(:authenticate!).with(scope: :admin)
|
||||
@controller.authenticate_admin!
|
||||
end
|
||||
|
||||
test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
|
||||
@mock_warden.expects(:authenticate!).with(:scope => :publisher_account)
|
||||
@mock_warden.expects(:authenticate!).with(scope: :publisher_account)
|
||||
@controller.authenticate_publisher_account!
|
||||
end
|
||||
|
||||
test 'proxy user_signed_in? to authenticate with user scope' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :user).returns("user")
|
||||
@mock_warden.expects(:authenticate).with(scope: :user).returns("user")
|
||||
assert @controller.user_signed_in?
|
||||
end
|
||||
|
||||
test 'proxy admin_signed_in? to authenticatewith admin scope' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
||||
@mock_warden.expects(:authenticate).with(scope: :admin)
|
||||
assert_not @controller.admin_signed_in?
|
||||
end
|
||||
|
||||
test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
||||
@mock_warden.expects(:authenticate).with(scope: :publisher_account)
|
||||
@controller.publisher_account_signed_in?
|
||||
end
|
||||
|
||||
test 'proxy user_session to session scope in warden' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :user).returns(true)
|
||||
@mock_warden.expects(:authenticate).with(scope: :user).returns(true)
|
||||
@mock_warden.expects(:session).with(:user).returns({})
|
||||
@controller.user_session
|
||||
end
|
||||
|
||||
test 'proxy admin_session to session scope in warden' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :admin).returns(true)
|
||||
@mock_warden.expects(:authenticate).with(scope: :admin).returns(true)
|
||||
@mock_warden.expects(:session).with(:admin).returns({})
|
||||
@controller.admin_session
|
||||
end
|
||||
|
||||
test 'proxy publisher_account_session from namespaced scope to session scope in warden' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :publisher_account).returns(true)
|
||||
@mock_warden.expects(:authenticate).with(scope: :publisher_account).returns(true)
|
||||
@mock_warden.expects(:session).with(:publisher_account).returns({})
|
||||
@controller.publisher_account_session
|
||||
end
|
||||
@@ -96,14 +96,14 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
test 'sign in proxy to set_user on warden' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).returns(nil)
|
||||
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
||||
@mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
|
||||
@controller.sign_in(:user, user)
|
||||
end
|
||||
|
||||
test 'sign in accepts a resource as argument' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).returns(nil)
|
||||
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
||||
@mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
|
||||
@controller.sign_in(user)
|
||||
end
|
||||
|
||||
@@ -117,15 +117,15 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
test 'sign in again when the user is already in only if force is given' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).returns(user)
|
||||
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
||||
@controller.sign_in(user, :force => true)
|
||||
@mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
|
||||
@controller.sign_in(user, force: true)
|
||||
end
|
||||
|
||||
test 'sign in accepts bypass as option' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:session_serializer).returns(serializer = mock())
|
||||
serializer.expects(:store).with(user, :user)
|
||||
@controller.sign_in(user, :bypass => true)
|
||||
@controller.sign_in(user, bypass: true)
|
||||
end
|
||||
|
||||
test 'sign out clears up any signed in user from all scopes' do
|
||||
@@ -141,18 +141,18 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
|
||||
test 'sign out logs out and clears up any signed in user by scope' do
|
||||
user = User.new
|
||||
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(user)
|
||||
@mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(user)
|
||||
@mock_warden.expects(:logout).with(:user).returns(true)
|
||||
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true)
|
||||
@mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)
|
||||
@controller.instance_variable_set(:@current_user, user)
|
||||
@controller.sign_out(:user)
|
||||
assert_equal nil, @controller.instance_variable_get(:@current_user)
|
||||
end
|
||||
|
||||
test 'sign out accepts a resource as argument' do
|
||||
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
|
||||
@mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(true)
|
||||
@mock_warden.expects(:logout).with(:user).returns(true)
|
||||
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true)
|
||||
@mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)
|
||||
@controller.sign_out(User.new)
|
||||
end
|
||||
|
||||
@@ -227,7 +227,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
user = User.new
|
||||
@controller.session[:user_return_to] = "/foo.bar"
|
||||
@mock_warden.expects(:user).with(:user).returns(nil)
|
||||
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
||||
@mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
|
||||
@controller.expects(:redirect_to).with("/foo.bar")
|
||||
@controller.sign_in_and_redirect(user)
|
||||
end
|
||||
@@ -235,7 +235,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
test 'sign in and redirect uses the configured after sign in path' do
|
||||
admin = Admin.new
|
||||
@mock_warden.expects(:user).with(:admin).returns(nil)
|
||||
@mock_warden.expects(:set_user).with(admin, :scope => :admin).returns(true)
|
||||
@mock_warden.expects(:set_user).with(admin, scope: :admin).returns(true)
|
||||
@controller.expects(:redirect_to).with(admin_root_path)
|
||||
@controller.sign_in_and_redirect(admin)
|
||||
end
|
||||
@@ -249,10 +249,10 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
|
||||
swap Devise, :sign_out_all_scopes => false do
|
||||
@mock_warden.expects(:user).with(:scope => :admin, :run_callbacks => false).returns(true)
|
||||
swap Devise, sign_out_all_scopes: false do
|
||||
@mock_warden.expects(:user).with(scope: :admin, run_callbacks: false).returns(true)
|
||||
@mock_warden.expects(:logout).with(:admin).returns(true)
|
||||
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :admin).returns(true)
|
||||
@mock_warden.expects(:clear_strategies_cache!).with(scope: :admin).returns(true)
|
||||
@controller.expects(:redirect_to).with(admin_root_path)
|
||||
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
||||
@controller.sign_out_and_redirect(:admin)
|
||||
@@ -260,7 +260,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
|
||||
swap Devise, :sign_out_all_scopes => true do
|
||||
swap Devise, sign_out_all_scopes: true do
|
||||
@mock_warden.expects(:user).times(Devise.mappings.size)
|
||||
@mock_warden.expects(:logout).with().returns(true)
|
||||
@mock_warden.expects(:clear_strategies_cache!).with().returns(true)
|
||||
|
||||
@@ -55,7 +55,7 @@ class HelpersTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'require no authentication tests current mapping' do
|
||||
@mock_warden.expects(:authenticate?).with(:rememberable, :scope => :user).returns(true)
|
||||
@mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
|
||||
@mock_warden.expects(:user).with(:user).returns(User.new)
|
||||
@controller.expects(:redirect_to).with(root_path)
|
||||
@controller.send :require_no_authentication
|
||||
@@ -71,7 +71,7 @@ class HelpersTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'require no authentication sets a flash message' do
|
||||
@mock_warden.expects(:authenticate?).with(:rememberable, :scope => :user).returns(true)
|
||||
@mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
|
||||
@mock_warden.expects(:user).with(:user).returns(User.new)
|
||||
@controller.expects(:redirect_to).with(root_path)
|
||||
@controller.send :require_no_authentication
|
||||
@@ -79,7 +79,7 @@ class HelpersTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'signed in resource returns signed in resource for current scope' do
|
||||
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
|
||||
@mock_warden.expects(:authenticate).with(scope: :user).returns(User.new)
|
||||
assert_kind_of User, @controller.signed_in_resource
|
||||
end
|
||||
|
||||
@@ -100,21 +100,21 @@ class HelpersTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'uses custom i18n options' do
|
||||
@controller.stubs(:devise_i18n_options).returns(:default => "devise custom options")
|
||||
@controller.stubs(:devise_i18n_options).returns(default: "devise custom options")
|
||||
@controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions
|
||||
assert_equal 'devise custom options', flash[:notice]
|
||||
end
|
||||
|
||||
test 'allows custom i18n options to override resource_name' do
|
||||
I18n.expects(:t).with("custom_resource_name.confirmed", anything)
|
||||
@controller.stubs(:devise_i18n_options).returns(:resource_name => "custom_resource_name")
|
||||
@controller.stubs(:devise_i18n_options).returns(resource_name: "custom_resource_name")
|
||||
@controller.send :set_flash_message, :notice, :confirmed
|
||||
end
|
||||
|
||||
test 'navigational_formats not returning a wild card' do
|
||||
MyController.send(:public, :navigational_formats)
|
||||
|
||||
swap Devise, :navigational_formats => ['*/*', :html] do
|
||||
swap Devise, navigational_formats: ['*/*', :html] do
|
||||
assert_not @controller.navigational_formats.include?("*/*")
|
||||
end
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
request.session["user_return_to"] = 'foo.bar'
|
||||
create_user
|
||||
post :create, :user => {
|
||||
:email => "wrong@email.com",
|
||||
:password => "wrongpassword"
|
||||
post :create, user: {
|
||||
email: "wrong@email.com",
|
||||
password: "wrongpassword"
|
||||
}
|
||||
assert_equal 200, @response.status
|
||||
ensure
|
||||
@@ -23,7 +23,7 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test "#create works even with scoped views" do
|
||||
swap Devise, :scoped_views => true do
|
||||
swap Devise, scoped_views: true do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
post :create
|
||||
assert_equal 200, @response.status
|
||||
@@ -37,9 +37,9 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
|
||||
user = create_user
|
||||
user.confirm!
|
||||
post :create, :user => {
|
||||
:email => user.email,
|
||||
:password => user.password
|
||||
post :create, user: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
}
|
||||
|
||||
assert_nil request.session["user_return_to"]
|
||||
@@ -51,9 +51,9 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
|
||||
user = create_user
|
||||
user.confirm!
|
||||
post :create, :format => 'json', :user => {
|
||||
:email => user.email,
|
||||
:password => user.password
|
||||
post :create, format: 'json', user: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
}
|
||||
|
||||
assert_equal 'foo.bar', request.session["user_return_to"]
|
||||
@@ -61,9 +61,9 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
|
||||
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
post :create, :user => {
|
||||
:email => "nosuchuser@example.com",
|
||||
:password => "wevdude"
|
||||
post :create, user: {
|
||||
email: "nosuchuser@example.com",
|
||||
password: "wevdude"
|
||||
}
|
||||
assert_equal 200, @response.status
|
||||
assert_template "devise/sessions/new"
|
||||
@@ -73,12 +73,12 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
user = create_user
|
||||
user.confirm!
|
||||
post :create, :format => 'json', :user => {
|
||||
:email => user.email,
|
||||
:password => user.password
|
||||
post :create, format: 'json', user: {
|
||||
email: user.email,
|
||||
password: user.password
|
||||
}
|
||||
|
||||
delete :destroy, :format => 'json'
|
||||
delete :destroy, format: 'json'
|
||||
assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
|
||||
assert_equal 204, @response.status
|
||||
end
|
||||
@@ -92,7 +92,7 @@ class SessionsControllerTest < ActionController::TestCase
|
||||
|
||||
begin
|
||||
assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do
|
||||
get :new, :user => { :email => "allez viens!" }
|
||||
get :new, user: { email: "allez viens!" }
|
||||
end
|
||||
ensure
|
||||
ActiveRecord::Base.mass_assignment_sanitizer = :logger
|
||||
|
||||
@@ -14,10 +14,10 @@ class RoutesTest < ActionController::TestCase
|
||||
send(:"#{prepend_path}user_#{name}_url")
|
||||
|
||||
# Default url params
|
||||
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, :param => 123),
|
||||
send(:"#{prepend_path}user_#{name}_path", :param => 123)
|
||||
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, :param => 123),
|
||||
send(:"#{prepend_path}user_#{name}_url", :param => 123)
|
||||
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123),
|
||||
send(:"#{prepend_path}user_#{name}_path", param: 123)
|
||||
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, param: 123),
|
||||
send(:"#{prepend_path}user_#{name}_url", param: 123)
|
||||
|
||||
@request.path = nil
|
||||
# With an object
|
||||
|
||||
@@ -14,6 +14,6 @@ class DelegatorTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'failure_app returns associated failure app by scope in the given environment' do
|
||||
assert_kind_of Proc, delegator.failure_app({"warden.options" => {:scope => "manager"}})
|
||||
assert_kind_of Proc, delegator.failure_app({"warden.options" => {scope: "manager"}})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,7 +23,7 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'model options can be configured through Devise' do
|
||||
swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do
|
||||
swap Devise, allow_unconfirmed_access_for: 113, pepper: "foo" do
|
||||
assert_equal 113, Devise.allow_unconfirmed_access_for
|
||||
assert_equal "foo", Devise.pepper
|
||||
end
|
||||
@@ -60,12 +60,12 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
assert_not defined?(Devise::Models::Coconut)
|
||||
Devise::ALL.delete(:coconut)
|
||||
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => :fruits) }
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) }
|
||||
assert_equal :fruits, Devise::STRATEGIES[:banana]
|
||||
Devise::ALL.delete(:banana)
|
||||
Devise::STRATEGIES.delete(:banana)
|
||||
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) }
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:kivi, controller: :fruits) }
|
||||
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
||||
Devise::ALL.delete(:kivi)
|
||||
Devise::CONTROLLERS.delete(:kivi)
|
||||
|
||||
@@ -10,7 +10,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
|
||||
class FailureWithI18nOptions < Devise::FailureApp
|
||||
def i18n_options(options)
|
||||
options.merge(:name => 'Steve')
|
||||
options.merge(name: 'Steve')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -23,11 +23,11 @@ class FailureTest < ActiveSupport::TestCase
|
||||
'REQUEST_URI' => 'http://test.host/',
|
||||
'HTTP_HOST' => 'test.host',
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
'warden.options' => { :scope => :user },
|
||||
'warden.options' => { scope: :user },
|
||||
'rack.session' => {},
|
||||
'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime::HTML),
|
||||
'rack.input' => "",
|
||||
'warden' => OpenStruct.new(:message => nil)
|
||||
'warden' => OpenStruct.new(message: nil)
|
||||
}.merge!(env_params)
|
||||
|
||||
@response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
|
||||
@@ -49,8 +49,8 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'returns to the root path if no session path is available' do
|
||||
swap Devise, :router_name => :fake_app do
|
||||
call_failure :app => RootFailureApp
|
||||
swap Devise, router_name: :fake_app do
|
||||
call_failure app: RootFailureApp
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
||||
assert_equal 'http://test.host/', @response.second['Location']
|
||||
@@ -59,7 +59,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
|
||||
if Rails.application.config.respond_to?(:relative_url_root)
|
||||
test 'returns to the default redirect location considering the relative url root' do
|
||||
swap Rails.application.config, :relative_url_root => "/sample" do
|
||||
swap Rails.application.config, relative_url_root: "/sample" do
|
||||
call_failure
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
|
||||
@@ -68,18 +68,18 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'uses the proxy failure message as symbol' do
|
||||
call_failure('warden' => OpenStruct.new(:message => :invalid))
|
||||
call_failure('warden' => OpenStruct.new(message: :invalid))
|
||||
assert_equal 'Invalid email or password.', @request.flash[:alert]
|
||||
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
||||
end
|
||||
|
||||
test 'uses custom i18n options' do
|
||||
call_failure('warden' => OpenStruct.new(:message => :does_not_exist), :app => FailureWithI18nOptions)
|
||||
call_failure('warden' => OpenStruct.new(message: :does_not_exist), app: FailureWithI18nOptions)
|
||||
assert_equal 'User Steve does not exist', @request.flash[:alert]
|
||||
end
|
||||
|
||||
test 'uses the proxy failure message as string' do
|
||||
call_failure('warden' => OpenStruct.new(:message => 'Hello world'))
|
||||
call_failure('warden' => OpenStruct.new(message: 'Hello world'))
|
||||
assert_equal 'Hello world', @request.flash[:alert]
|
||||
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
||||
end
|
||||
@@ -97,14 +97,14 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'works for any navigational format' do
|
||||
swap Devise, :navigational_formats => [:xml] do
|
||||
swap Devise, navigational_formats: [:xml] do
|
||||
call_failure('formats' => Mime::XML)
|
||||
assert_equal 302, @response.first
|
||||
end
|
||||
end
|
||||
|
||||
test 'redirects the correct format if it is a non-html format request' do
|
||||
swap Devise, :navigational_formats => [:js] do
|
||||
swap Devise, navigational_formats: [:js] do
|
||||
call_failure('formats' => Mime::JS)
|
||||
assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
|
||||
end
|
||||
@@ -140,28 +140,28 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'does not return WWW-authenticate headers if model does not allow' do
|
||||
swap Devise, :http_authenticatable => false do
|
||||
swap Devise, http_authenticatable: false do
|
||||
call_failure('formats' => Mime::XML)
|
||||
assert_nil @response.second["WWW-Authenticate"]
|
||||
end
|
||||
end
|
||||
|
||||
test 'works for any non navigational format' do
|
||||
swap Devise, :navigational_formats => [] do
|
||||
swap Devise, navigational_formats: [] do
|
||||
call_failure('formats' => Mime::HTML)
|
||||
assert_equal 401, @response.first
|
||||
end
|
||||
end
|
||||
|
||||
test 'uses the failure message as response body' do
|
||||
call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(:message => :invalid))
|
||||
call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(message: :invalid))
|
||||
assert_match '<error>Invalid email or password.</error>', @response.third.body
|
||||
end
|
||||
|
||||
context 'on ajax call' do
|
||||
context 'when http_authenticatable_on_xhr is false' do
|
||||
test 'dont return 401 with navigational formats' do
|
||||
swap Devise, :http_authenticatable_on_xhr => false do
|
||||
swap Devise, http_authenticatable_on_xhr: false do
|
||||
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
||||
@@ -169,7 +169,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'dont return 401 with non navigational formats' do
|
||||
swap Devise, :http_authenticatable_on_xhr => false do
|
||||
swap Devise, http_authenticatable_on_xhr: false do
|
||||
call_failure('formats' => Mime::JSON, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
|
||||
@@ -179,14 +179,14 @@ class FailureTest < ActiveSupport::TestCase
|
||||
|
||||
context 'when http_authenticatable_on_xhr is true' do
|
||||
test 'return 401' do
|
||||
swap Devise, :http_authenticatable_on_xhr => true do
|
||||
swap Devise, http_authenticatable_on_xhr: true do
|
||||
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
assert_equal 401, @response.first
|
||||
end
|
||||
end
|
||||
|
||||
test 'skip WWW-Authenticate header' do
|
||||
swap Devise, :http_authenticatable_on_xhr => true do
|
||||
swap Devise, http_authenticatable_on_xhr: true do
|
||||
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
||||
assert_nil @response.second['WWW-Authenticate']
|
||||
end
|
||||
@@ -198,7 +198,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
context 'With recall' do
|
||||
test 'calls the original controller if invalid email or password' do
|
||||
env = {
|
||||
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in" },
|
||||
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in" },
|
||||
"devise.mapping" => Devise.mappings[:user],
|
||||
"warden" => stub_everything
|
||||
}
|
||||
@@ -209,7 +209,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
|
||||
test 'calls the original controller if not confirmed email' do
|
||||
env = {
|
||||
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :unconfirmed },
|
||||
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :unconfirmed },
|
||||
"devise.mapping" => Devise.mappings[:user],
|
||||
"warden" => stub_everything
|
||||
}
|
||||
@@ -220,7 +220,7 @@ class FailureTest < ActiveSupport::TestCase
|
||||
|
||||
test 'calls the original controller if inactive account' do
|
||||
env = {
|
||||
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :inactive },
|
||||
"warden.options" => { recall: "devise/sessions#new", attempted_path: "/users/sign_in", message: :inactive },
|
||||
"devise.mapping" => Devise.mappings[:user],
|
||||
"warden" => stub_everything
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ if DEVISE_ORM == :active_record
|
||||
run_generator %w(monster)
|
||||
assert_migration "db/migrate/devise_create_monsters.rb"
|
||||
assert_migration "db/migrate/add_devise_to_monsters.rb"
|
||||
run_generator %w(monster), :behavior => :revoke
|
||||
run_generator %w(monster), behavior: :revoke
|
||||
assert_no_migration "db/migrate/add_devise_to_monsters.rb"
|
||||
assert_migration "db/migrate/devise_create_monsters.rb"
|
||||
run_generator %w(monster), :behavior => :revoke
|
||||
run_generator %w(monster), behavior: :revoke
|
||||
assert_no_file "app/models/monster.rb"
|
||||
assert_no_migration "db/migrate/devise_create_monsters.rb"
|
||||
end
|
||||
@@ -47,11 +47,11 @@ if DEVISE_ORM == :active_record
|
||||
|
||||
def simulate_inside_engine(engine, namespace)
|
||||
if Rails::Generators.respond_to?(:namespace=)
|
||||
swap Rails::Generators, :namespace => namespace do
|
||||
swap Rails::Generators, namespace: namespace do
|
||||
yield
|
||||
end
|
||||
else
|
||||
swap Rails, :application => engine.instance do
|
||||
swap Rails, application: engine.instance do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,13 +18,13 @@ class DeviseGeneratorTest < Rails::Generators::TestCase
|
||||
|
||||
test "route generation for namespaced model names" do
|
||||
run_generator %w(monster/goblin name:string)
|
||||
match = /devise_for :goblins, :class_name => "Monster::Goblin"/
|
||||
match = /devise_for :goblins, class_name: "Monster::Goblin"/
|
||||
assert_file "config/routes.rb", match
|
||||
end
|
||||
|
||||
test "route generation with skip routes" do
|
||||
run_generator %w(monster name:string --skip-routes)
|
||||
match = /devise_for :monsters, :skip => :all/
|
||||
match = /devise_for :monsters, skip: :all/
|
||||
assert_file "config/routes.rb", match
|
||||
end
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ if DEVISE_ORM == :mongoid
|
||||
|
||||
test "all files are properly deleted" do
|
||||
run_generator %w(monster)
|
||||
run_generator %w(monster), :behavior => :revoke
|
||||
run_generator %w(monster), behavior: :revoke
|
||||
assert_no_file "app/models/monster.rb"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,36 @@ class ViewsGeneratorTest < Rails::Generators::TestCase
|
||||
|
||||
test "Assert views with markerb" do
|
||||
run_generator %w(--markerb)
|
||||
assert_files nil, :mail_template_engine => "markerb"
|
||||
assert_files nil, mail_template_engine: "markerb"
|
||||
end
|
||||
|
||||
|
||||
test "Assert only views within specified directories" do
|
||||
run_generator %w(-v sessions registrations)
|
||||
assert_file "app/views/devise/sessions/new.html.erb"
|
||||
assert_file "app/views/devise/registrations/new.html.erb"
|
||||
assert_file "app/views/devise/registrations/edit.html.erb"
|
||||
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
||||
assert_no_file "app/views/devise/mailer/confirmation_instructions.html.erb"
|
||||
end
|
||||
|
||||
test "Assert specified directories with scope" do
|
||||
run_generator %w(users -v sessions)
|
||||
assert_file "app/views/users/sessions/new.html.erb"
|
||||
assert_no_file "app/views/users/confirmations/new.html.erb"
|
||||
end
|
||||
|
||||
test "Assert specified directories with simple form" do
|
||||
run_generator %w(-v registrations -b simple_form_for)
|
||||
assert_file "app/views/devise/registrations/new.html.erb", /simple_form_for/
|
||||
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
||||
end
|
||||
|
||||
test "Assert specified directories with markerb" do
|
||||
run_generator %w(--markerb -v passwords mailer)
|
||||
assert_file "app/views/devise/passwords/new.html.erb"
|
||||
assert_no_file "app/views/devise/confirmations/new.html.erb"
|
||||
assert_file "app/views/devise/mailer/reset_password_instructions.markerb"
|
||||
end
|
||||
|
||||
def assert_files(scope = nil, options={})
|
||||
|
||||
@@ -2,16 +2,16 @@ require 'test_helper'
|
||||
|
||||
class DeviseHelperTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
model_labels = { :models => { :user => "utilisateur" } }
|
||||
model_labels = { models: { user: "utilisateur" } }
|
||||
|
||||
I18n.backend.store_translations :fr,
|
||||
{
|
||||
:errors => { :messages => { :not_saved => {
|
||||
:one => "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.",
|
||||
:other => "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs."
|
||||
errors: { messages: { not_saved: {
|
||||
one: "Erreur lors de l'enregistrement de '%{resource}': 1 erreur.",
|
||||
other: "Erreur lors de l'enregistrement de '%{resource}': %{count} erreurs."
|
||||
} } },
|
||||
:activerecord => model_labels,
|
||||
:mongoid => model_labels
|
||||
activerecord: model_labels,
|
||||
mongoid: model_labels
|
||||
}
|
||||
|
||||
I18n.locale = 'fr'
|
||||
@@ -24,8 +24,8 @@ class DeviseHelperTest < ActionDispatch::IntegrationTest
|
||||
test 'test errors.messages.not_saved with single error from i18n' do
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'password', :with => 'new_user123'
|
||||
fill_in 'password confirmation', :with => 'new_user123'
|
||||
fill_in 'password', with: 'new_user123'
|
||||
fill_in 'password confirmation', with: 'new_user123'
|
||||
click_button 'Sign up'
|
||||
|
||||
assert_have_selector '#error_explanation'
|
||||
@@ -39,9 +39,9 @@ class DeviseHelperTest < ActionDispatch::IntegrationTest
|
||||
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'invalid_email'
|
||||
fill_in 'password', :with => 'new_user123'
|
||||
fill_in 'password confirmation', :with => 'new_user321'
|
||||
fill_in 'email', with: 'invalid_email'
|
||||
fill_in 'password', with: 'new_user123'
|
||||
fill_in 'password confirmation', with: 'new_user321'
|
||||
click_button 'Sign up'
|
||||
|
||||
assert_have_selector '#error_explanation'
|
||||
|
||||
@@ -27,7 +27,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do
|
||||
swap Devise, :sign_out_all_scopes => false do
|
||||
swap Devise, sign_out_all_scopes: false do
|
||||
sign_in_as_user
|
||||
sign_in_as_admin
|
||||
get destroy_user_session_path
|
||||
@@ -37,7 +37,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do
|
||||
swap Devise, :sign_out_all_scopes => false do
|
||||
swap Devise, sign_out_all_scopes: false do
|
||||
sign_in_as_user
|
||||
sign_in_as_admin
|
||||
|
||||
@@ -48,7 +48,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do
|
||||
swap Devise, :sign_out_all_scopes => true do
|
||||
swap Devise, sign_out_all_scopes: true do
|
||||
sign_in_as_user
|
||||
sign_in_as_admin
|
||||
|
||||
@@ -59,7 +59,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do
|
||||
swap Devise, :sign_out_all_scopes => true do
|
||||
swap Devise, sign_out_all_scopes: true do
|
||||
sign_in_as_user
|
||||
sign_in_as_admin
|
||||
|
||||
@@ -162,7 +162,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do
|
||||
sign_in_as_admin(:active => false)
|
||||
sign_in_as_admin(active: false)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
@@ -172,7 +172,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do
|
||||
sign_in_as_admin(:active => true)
|
||||
sign_in_as_admin(active: true)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
@@ -214,7 +214,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do
|
||||
sign_in_as_admin(:active => false)
|
||||
sign_in_as_admin(active: false)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
@@ -224,7 +224,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do
|
||||
sign_in_as_admin(:active => true)
|
||||
sign_in_as_admin(active: true)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
@@ -277,7 +277,7 @@ class AuthenticationRedirectTest < ActionDispatch::IntegrationTest
|
||||
assert_equal users_path, session[:"user_return_to"]
|
||||
|
||||
follow_redirect!
|
||||
sign_in_as_user :visit => false
|
||||
sign_in_as_user visit: false
|
||||
|
||||
assert_current_url '/users'
|
||||
assert_nil session[:"user_return_to"]
|
||||
@@ -293,7 +293,7 @@ class AuthenticationRedirectTest < ActionDispatch::IntegrationTest
|
||||
assert_equal users_path, session[:"user_return_to"]
|
||||
|
||||
follow_redirect!
|
||||
sign_in_as_user :visit => false
|
||||
sign_in_as_user visit: false
|
||||
|
||||
assert_current_url '/users'
|
||||
assert_nil session[:"user_return_to"]
|
||||
@@ -392,7 +392,7 @@ end
|
||||
|
||||
class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
|
||||
test 'renders the scoped view if turned on and view is available' do
|
||||
swap Devise, :scoped_views => true do
|
||||
swap Devise, scoped_views: true do
|
||||
assert_raise Webrat::NotFoundError do
|
||||
sign_in_as_user
|
||||
end
|
||||
@@ -415,7 +415,7 @@ class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'does not render the scoped view if turned off' do
|
||||
swap Devise, :scoped_views => false do
|
||||
swap Devise, scoped_views: false do
|
||||
assert_nothing_raised do
|
||||
sign_in_as_user
|
||||
end
|
||||
@@ -423,7 +423,7 @@ class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'does not render the scoped view if not available' do
|
||||
swap Devise, :scoped_views => true do
|
||||
swap Devise, scoped_views: true do
|
||||
assert_nothing_raised do
|
||||
sign_in_as_admin
|
||||
end
|
||||
@@ -433,7 +433,7 @@ end
|
||||
|
||||
class AuthenticationOthersTest < ActionDispatch::IntegrationTest
|
||||
test 'handles unverified requests gets rid of caches' do
|
||||
swap ApplicationController, :allow_forgery_protection => true do
|
||||
swap ApplicationController, allow_forgery_protection: true do
|
||||
post exhibit_user_url(1)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
@@ -473,12 +473,12 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
|
||||
test 'sign in with script name' do
|
||||
assert_nothing_raised do
|
||||
get new_user_session_path, {}, "SCRIPT_NAME" => "/omg"
|
||||
fill_in "email", :with => "user@test.com"
|
||||
fill_in "email", with: "user@test.com"
|
||||
end
|
||||
end
|
||||
|
||||
test 'sign in stub in xml format' do
|
||||
get new_user_session_path(:format => 'xml')
|
||||
get new_user_session_path(format: 'xml')
|
||||
assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body
|
||||
assert_match /<user>.*<\/user>/m, response.body
|
||||
assert_match '<email></email>', response.body
|
||||
@@ -486,15 +486,15 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'sign in stub in json format' do
|
||||
get new_user_session_path(:format => 'json')
|
||||
get new_user_session_path(format: 'json')
|
||||
assert_match '{"user":{', response.body
|
||||
assert_match '"email":""', response.body
|
||||
assert_match '"password":null', response.body
|
||||
end
|
||||
|
||||
test 'sign in stub in json with non attribute key' do
|
||||
swap Devise, :authentication_keys => [:other_key] do
|
||||
get new_user_session_path(:format => 'json')
|
||||
swap Devise, authentication_keys: [:other_key] do
|
||||
get new_user_session_path(format: 'json')
|
||||
assert_match '{"user":{', response.body
|
||||
assert_match '"other_key":null', response.body
|
||||
assert_match '"password":null', response.body
|
||||
@@ -502,30 +502,30 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'uses the mapping from router' do
|
||||
sign_in_as_user :visit => "/as/sign_in"
|
||||
sign_in_as_user visit: "/as/sign_in"
|
||||
assert warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'sign in with xml format returns xml response' do
|
||||
create_user
|
||||
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
|
||||
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
|
||||
assert_response :success
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
||||
end
|
||||
|
||||
test 'sign in with xml format is idempotent' do
|
||||
get new_user_session_path(:format => 'xml')
|
||||
get new_user_session_path(format: 'xml')
|
||||
assert_response :success
|
||||
|
||||
create_user
|
||||
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
|
||||
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
|
||||
assert_response :success
|
||||
|
||||
get new_user_session_path(:format => 'xml')
|
||||
get new_user_session_path(format: 'xml')
|
||||
assert_response :success
|
||||
|
||||
post user_session_path(:format => 'xml'), :user => {:email => "user@test.com", :password => '12345678'}
|
||||
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'}
|
||||
assert_response :success
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
||||
end
|
||||
@@ -537,27 +537,27 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
|
||||
assert_current_url '/'
|
||||
|
||||
sign_in_as_user
|
||||
get destroy_user_session_path(:format => 'html')
|
||||
get destroy_user_session_path(format: 'html')
|
||||
assert_response :redirect
|
||||
assert_current_url '/'
|
||||
end
|
||||
|
||||
test 'sign out with xml format returns no content' do
|
||||
sign_in_as_user
|
||||
get destroy_user_session_path(:format => 'xml')
|
||||
get destroy_user_session_path(format: 'xml')
|
||||
assert_response :no_content
|
||||
assert_not warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'sign out with json format returns no content' do
|
||||
sign_in_as_user
|
||||
get destroy_user_session_path(:format => 'json')
|
||||
get destroy_user_session_path(format: 'json')
|
||||
assert_response :no_content
|
||||
assert_not warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'sign out with non-navigational format via XHR does not redirect' do
|
||||
swap Devise, :navigational_formats => ['*/*', :html] do
|
||||
swap Devise, navigational_formats: ['*/*', :html] do
|
||||
sign_in_as_user
|
||||
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
|
||||
assert_response :no_content
|
||||
@@ -567,7 +567,7 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
|
||||
|
||||
# Belt and braces ... Perhaps this test is not necessary?
|
||||
test 'sign out with navigational format via XHR does redirect' do
|
||||
swap Devise, :navigational_formats => ['*/*', :html] do
|
||||
swap Devise, navigational_formats: ['*/*', :html] do
|
||||
sign_in_as_user
|
||||
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "text/html,*/*" }
|
||||
assert_response :redirect
|
||||
@@ -578,7 +578,7 @@ end
|
||||
|
||||
class AuthenticationKeysTest < ActionDispatch::IntegrationTest
|
||||
test 'missing authentication keys cause authentication to abort' do
|
||||
swap Devise, :authentication_keys => [:subdomain] do
|
||||
swap Devise, authentication_keys: [:subdomain] do
|
||||
sign_in_as_user
|
||||
assert_contain "Invalid email or password."
|
||||
assert_not warden.authenticated?(:user)
|
||||
@@ -586,7 +586,7 @@ class AuthenticationKeysTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'missing authentication keys cause authentication to abort unless marked as not required' do
|
||||
swap Devise, :authentication_keys => { :email => true, :subdomain => false } do
|
||||
swap Devise, authentication_keys: { email: true, subdomain: false } do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
end
|
||||
@@ -597,15 +597,15 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
|
||||
test 'request keys are used on authentication' do
|
||||
host! 'foo.bar.baz'
|
||||
|
||||
swap Devise, :request_keys => [:subdomain] do
|
||||
User.expects(:find_for_authentication).with(:subdomain => 'foo', :email => 'user@test.com').returns(create_user)
|
||||
swap Devise, request_keys: [:subdomain] do
|
||||
User.expects(:find_for_authentication).with(subdomain: 'foo', email: 'user@test.com').returns(create_user)
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
test 'invalid request keys raises NoMethodError' do
|
||||
swap Devise, :request_keys => [:unknown_method] do
|
||||
swap Devise, request_keys: [:unknown_method] do
|
||||
assert_raise NoMethodError do
|
||||
sign_in_as_user
|
||||
end
|
||||
@@ -617,7 +617,7 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
|
||||
test 'blank request keys cause authentication to abort' do
|
||||
host! 'test.com'
|
||||
|
||||
swap Devise, :request_keys => [:subdomain] do
|
||||
swap Devise, request_keys: [:subdomain] do
|
||||
sign_in_as_user
|
||||
assert_contain "Invalid email or password."
|
||||
assert_not warden.authenticated?(:user)
|
||||
@@ -627,7 +627,7 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
|
||||
test 'blank request keys cause authentication to abort unless if marked as not required' do
|
||||
host! 'test.com'
|
||||
|
||||
swap Devise, :request_keys => { :subdomain => false } do
|
||||
swap Devise, request_keys: { subdomain: false } do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
end
|
||||
@@ -636,7 +636,7 @@ end
|
||||
|
||||
class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
|
||||
def sign_in!(scope)
|
||||
sign_in_as_admin(:visit => send("new_#{scope}_session_path"))
|
||||
sign_in_as_admin(visit: send("new_#{scope}_session_path"))
|
||||
assert warden.authenticated?(scope)
|
||||
end
|
||||
|
||||
@@ -692,22 +692,22 @@ end
|
||||
class DoubleAuthenticationRedirectTest < ActionDispatch::IntegrationTest
|
||||
test 'signed in as user redirects when visiting user sign in page' do
|
||||
sign_in_as_user
|
||||
get new_user_session_path(:format => :html)
|
||||
get new_user_session_path(format: :html)
|
||||
assert_redirected_to '/'
|
||||
end
|
||||
|
||||
test 'signed in as admin redirects when visiting admin sign in page' do
|
||||
sign_in_as_admin
|
||||
get new_admin_session_path(:format => :html)
|
||||
get new_admin_session_path(format: :html)
|
||||
assert_redirected_to '/admin_area/home'
|
||||
end
|
||||
|
||||
test 'signed in as both user and admin redirects when visiting admin sign in page' do
|
||||
sign_in_as_user
|
||||
sign_in_as_admin
|
||||
get new_user_session_path(:format => :html)
|
||||
get new_user_session_path(format: :html)
|
||||
assert_redirected_to '/'
|
||||
get new_admin_session_path(:format => :html)
|
||||
get new_admin_session_path(format: :html)
|
||||
assert_redirected_to '/admin_area/home'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,17 +3,17 @@ require 'test_helper'
|
||||
class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
|
||||
def visit_user_confirmation_with_token(confirmation_token)
|
||||
visit user_confirmation_path(:confirmation_token => confirmation_token)
|
||||
visit user_confirmation_path(confirmation_token: confirmation_token)
|
||||
end
|
||||
|
||||
def resend_confirmation
|
||||
user = create_user(:confirm => false)
|
||||
user = create_user(confirm: false)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
visit new_user_session_path
|
||||
click_link "Didn't receive confirmation instructions?"
|
||||
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'email', with: user.email
|
||||
click_button 'Resend confirmation instructions'
|
||||
end
|
||||
|
||||
@@ -39,8 +39,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do
|
||||
swap Devise, :confirm_within => 3.days do
|
||||
user = create_user(:confirm => false, :confirmation_sent_at => 4.days.ago)
|
||||
swap Devise, confirm_within: 3.days do
|
||||
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)
|
||||
assert_not user.confirmed?
|
||||
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
||||
|
||||
@@ -51,8 +51,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'user with valid confirmation token should be able to confirm an account before the token has expired' do
|
||||
swap Devise, :confirm_within => 3.days do
|
||||
user = create_user(:confirm => false, :confirmation_sent_at => 2.days.ago)
|
||||
swap Devise, confirm_within: 3.days do
|
||||
user = create_user(confirm: false, confirmation_sent_at: 2.days.ago)
|
||||
assert_not user.confirmed?
|
||||
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
||||
|
||||
@@ -65,14 +65,14 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
test 'user should be redirected to a custom path after confirmation' do
|
||||
Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns("/?custom=1")
|
||||
|
||||
user = create_user(:confirm => false)
|
||||
user = create_user(confirm: false)
|
||||
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
||||
|
||||
assert_current_url "/?custom=1"
|
||||
end
|
||||
|
||||
test 'already confirmed user should not be able to confirm the account again' do
|
||||
user = create_user(:confirm => false)
|
||||
user = create_user(confirm: false)
|
||||
user.confirmed_at = Time.now
|
||||
user.save
|
||||
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
||||
@@ -82,21 +82,21 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'already confirmed user should not be able to confirm the account again neither request confirmation' do
|
||||
user = create_user(:confirm => false)
|
||||
user = create_user(confirm: false)
|
||||
user.confirmed_at = Time.now
|
||||
user.save
|
||||
|
||||
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
||||
assert_contain 'already confirmed'
|
||||
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'email', with: user.email
|
||||
click_button 'Resend confirmation instructions'
|
||||
assert_contain 'already confirmed'
|
||||
end
|
||||
|
||||
test 'not confirmed user with setup to block without confirmation should not be able to sign in' do
|
||||
swap Devise, :allow_unconfirmed_access_for => 0.days do
|
||||
sign_in_as_user(:confirm => false)
|
||||
swap Devise, allow_unconfirmed_access_for: 0.days do
|
||||
sign_in_as_user(confirm: false)
|
||||
|
||||
assert_contain 'You have to confirm your account before continuing'
|
||||
assert_not warden.authenticated?(:user)
|
||||
@@ -104,9 +104,9 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'not confirmed user should not see confirmation message if invalid credentials are given' do
|
||||
swap Devise, :allow_unconfirmed_access_for => 0.days do
|
||||
sign_in_as_user(:confirm => false) do
|
||||
fill_in 'password', :with => 'invalid'
|
||||
swap Devise, allow_unconfirmed_access_for: 0.days do
|
||||
sign_in_as_user(confirm: false) do
|
||||
fill_in 'password', with: 'invalid'
|
||||
end
|
||||
|
||||
assert_contain 'Invalid email or password'
|
||||
@@ -115,8 +115,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'not confirmed user but configured with some days to confirm should be able to sign in' do
|
||||
swap Devise, :allow_unconfirmed_access_for => 1.day do
|
||||
sign_in_as_user(:confirm => false)
|
||||
swap Devise, allow_unconfirmed_access_for: 1.day do
|
||||
sign_in_as_user(confirm: false)
|
||||
|
||||
assert_response :success
|
||||
assert warden.authenticated?(:user)
|
||||
@@ -124,8 +124,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'unconfirmed but signed in user should be redirected to their root path' do
|
||||
swap Devise, :allow_unconfirmed_access_for => 1.day do
|
||||
user = sign_in_as_user(:confirm => false)
|
||||
swap Devise, allow_unconfirmed_access_for: 1.day do
|
||||
user = sign_in_as_user(confirm: false)
|
||||
|
||||
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
||||
assert_contain 'Your account was successfully confirmed.'
|
||||
@@ -134,57 +134,57 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'error message is configurable by resource name' do
|
||||
store_translations :en, :devise => {
|
||||
:failure => { :user => { :unconfirmed => "Not confirmed user" } }
|
||||
store_translations :en, devise: {
|
||||
failure: { user: { unconfirmed: "Not confirmed user" } }
|
||||
} do
|
||||
sign_in_as_user(:confirm => false)
|
||||
sign_in_as_user(confirm: false)
|
||||
assert_contain 'Not confirmed user'
|
||||
end
|
||||
end
|
||||
|
||||
test 'resent confirmation token with valid E-Mail in XML format should return valid response' do
|
||||
user = create_user(:confirm => false)
|
||||
post user_confirmation_path(:format => 'xml'), :user => { :email => user.email }
|
||||
user = create_user(confirm: false)
|
||||
post user_confirmation_path(format: 'xml'), user: { email: user.email }
|
||||
assert_response :success
|
||||
assert_equal response.body, {}.to_xml
|
||||
end
|
||||
|
||||
test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do
|
||||
create_user(:confirm => false)
|
||||
post user_confirmation_path(:format => 'xml'), :user => { :email => 'invalid.test@test.com' }
|
||||
create_user(confirm: false)
|
||||
post user_confirmation_path(format: 'xml'), user: { email: 'invalid.test@test.com' }
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
|
||||
test 'confirm account with valid confirmation token in XML format should return valid response' do
|
||||
user = create_user(:confirm => false)
|
||||
get user_confirmation_path(:confirmation_token => user.raw_confirmation_token, :format => 'xml')
|
||||
user = create_user(confirm: false)
|
||||
get user_confirmation_path(confirmation_token: user.raw_confirmation_token, format: 'xml')
|
||||
assert_response :success
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
||||
end
|
||||
|
||||
test 'confirm account with invalid confirmation token in XML format should return invalid response' do
|
||||
create_user(:confirm => false)
|
||||
get user_confirmation_path(:confirmation_token => 'invalid_confirmation', :format => 'xml')
|
||||
create_user(confirm: false)
|
||||
get user_confirmation_path(confirmation_token: 'invalid_confirmation', format: 'xml')
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
|
||||
test 'request an account confirmation account with JSON, should return an empty JSON' do
|
||||
user = create_user(:confirm => false)
|
||||
user = create_user(confirm: false)
|
||||
|
||||
post user_confirmation_path, :user => { :email => user.email }, :format => :json
|
||||
post user_confirmation_path, user: { email: user.email }, format: :json
|
||||
assert_response :success
|
||||
assert_equal response.body, {}.to_json
|
||||
end
|
||||
|
||||
test "when in paranoid mode and with a valid e-mail, should not say that the e-mail is valid" do
|
||||
swap Devise, :paranoid => true do
|
||||
user = create_user(:confirm => false)
|
||||
swap Devise, paranoid: true do
|
||||
user = create_user(confirm: false)
|
||||
visit new_user_session_path
|
||||
|
||||
click_link "Didn't receive confirmation instructions?"
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'email', with: user.email
|
||||
click_button 'Resend confirmation instructions'
|
||||
|
||||
assert_contain "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
|
||||
@@ -193,11 +193,11 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "when in paranoid mode and with a invalid e-mail, should not say that the e-mail is invalid" do
|
||||
swap Devise, :paranoid => true do
|
||||
swap Devise, paranoid: true do
|
||||
visit new_user_session_path
|
||||
|
||||
click_link "Didn't receive confirmation instructions?"
|
||||
fill_in 'email', :with => "idonthavethisemail@gmail.com"
|
||||
fill_in 'email', with: "idonthavethisemail@gmail.com"
|
||||
click_button 'Resend confirmation instructions'
|
||||
|
||||
assert_not_contain "1 error prohibited this user from being saved:"
|
||||
@@ -216,17 +216,17 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
def visit_admin_confirmation_with_token(confirmation_token)
|
||||
visit admin_confirmation_path(:confirmation_token => confirmation_token)
|
||||
visit admin_confirmation_path(confirmation_token: confirmation_token)
|
||||
end
|
||||
|
||||
test 'admin should be able to request a new confirmation after email changed' do
|
||||
admin = create_admin
|
||||
admin.update_attributes(:email => 'new_test@example.com')
|
||||
admin.update_attributes(email: 'new_test@example.com')
|
||||
|
||||
visit new_admin_session_path
|
||||
click_link "Didn't receive confirmation instructions?"
|
||||
|
||||
fill_in 'email', :with => admin.unconfirmed_email
|
||||
fill_in 'email', with: admin.unconfirmed_email
|
||||
assert_difference "ActionMailer::Base.deliveries.size" do
|
||||
click_button 'Resend confirmation instructions'
|
||||
end
|
||||
@@ -237,7 +237,7 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'admin with valid confirmation token should be able to confirm email after email changed' do
|
||||
admin = create_admin
|
||||
admin.update_attributes(:email => 'new_test@example.com')
|
||||
admin.update_attributes(email: 'new_test@example.com')
|
||||
assert_equal 'new_test@example.com', admin.unconfirmed_email
|
||||
visit_admin_confirmation_with_token(admin.raw_confirmation_token)
|
||||
|
||||
@@ -249,13 +249,13 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do
|
||||
admin = create_admin
|
||||
admin.update_attributes(:email => 'first_test@example.com')
|
||||
admin.update_attributes(email: 'first_test@example.com')
|
||||
assert_equal 'first_test@example.com', admin.unconfirmed_email
|
||||
|
||||
raw_confirmation_token = admin.raw_confirmation_token
|
||||
admin = Admin.find(admin.id)
|
||||
|
||||
admin.update_attributes(:email => 'second_test@example.com')
|
||||
admin.update_attributes(email: 'second_test@example.com')
|
||||
assert_equal 'second_test@example.com', admin.unconfirmed_email
|
||||
|
||||
visit_admin_confirmation_with_token(raw_confirmation_token)
|
||||
@@ -271,10 +271,10 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'admin email should be unique also within unconfirmed_email' do
|
||||
admin = create_admin
|
||||
admin.update_attributes(:email => 'new_admin_test@example.com')
|
||||
admin.update_attributes(email: 'new_admin_test@example.com')
|
||||
assert_equal 'new_admin_test@example.com', admin.unconfirmed_email
|
||||
|
||||
create_second_admin(:email => "new_admin_test@example.com")
|
||||
create_second_admin(email: "new_admin_test@example.com")
|
||||
|
||||
visit_admin_confirmation_with_token(admin.raw_confirmation_token)
|
||||
assert_have_selector '#error_explanation'
|
||||
|
||||
@@ -2,21 +2,21 @@ require 'test_helper'
|
||||
|
||||
class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do
|
||||
create_user(:email => 'Foo@Bar.com')
|
||||
create_user(email: 'Foo@Bar.com')
|
||||
|
||||
sign_in_as_user do
|
||||
fill_in 'email', :with => 'foo@bar.com'
|
||||
fill_in 'email', with: 'foo@bar.com'
|
||||
end
|
||||
|
||||
assert warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'sign in with email of different case should fail when email is NOT the list of case insensitive keys' do
|
||||
swap Devise, :case_insensitive_keys => [] do
|
||||
create_user(:email => 'Foo@Bar.com')
|
||||
swap Devise, case_insensitive_keys: [] do
|
||||
create_user(email: 'Foo@Bar.com')
|
||||
|
||||
sign_in_as_user do
|
||||
fill_in 'email', :with => 'foo@bar.com'
|
||||
fill_in 'email', with: 'foo@bar.com'
|
||||
end
|
||||
|
||||
assert_not warden.authenticated?(:user)
|
||||
@@ -24,21 +24,21 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'sign in with email including extra spaces should succeed when email is in the list of strip whitespace keys' do
|
||||
create_user(:email => ' foo@bar.com ')
|
||||
create_user(email: ' foo@bar.com ')
|
||||
|
||||
sign_in_as_user do
|
||||
fill_in 'email', :with => 'foo@bar.com'
|
||||
fill_in 'email', with: 'foo@bar.com'
|
||||
end
|
||||
|
||||
assert warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'sign in with email including extra spaces should fail when email is NOT the list of strip whitespace keys' do
|
||||
swap Devise, :strip_whitespace_keys => [] do
|
||||
create_user(:email => 'foo@bar.com')
|
||||
swap Devise, strip_whitespace_keys: [] do
|
||||
create_user(email: 'foo@bar.com')
|
||||
|
||||
sign_in_as_user do
|
||||
fill_in 'email', :with => ' foo@bar.com '
|
||||
fill_in 'email', with: ' foo@bar.com '
|
||||
end
|
||||
|
||||
assert_not warden.authenticated?(:user)
|
||||
@@ -46,16 +46,16 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'sign in should not authenticate if not using proper authentication keys' do
|
||||
swap Devise, :authentication_keys => [:username] do
|
||||
swap Devise, authentication_keys: [:username] do
|
||||
sign_in_as_user
|
||||
assert_not warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
test 'sign in with invalid email should return to sign in form with error message' do
|
||||
store_translations :en, :devise => { :failure => { :admin => { :not_found_in_database => 'Invalid email address' } } } do
|
||||
store_translations :en, devise: { failure: { admin: { not_found_in_database: 'Invalid email address' } } } do
|
||||
sign_in_as_admin do
|
||||
fill_in 'email', :with => 'wrongemail@test.com'
|
||||
fill_in 'email', with: 'wrongemail@test.com'
|
||||
end
|
||||
|
||||
assert_contain 'Invalid email address'
|
||||
@@ -65,7 +65,7 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'sign in with invalid pasword should return to sign in form with error message' do
|
||||
sign_in_as_admin do
|
||||
fill_in 'password', :with => 'abcdef'
|
||||
fill_in 'password', with: 'abcdef'
|
||||
end
|
||||
|
||||
assert_contain 'Invalid email or password'
|
||||
@@ -73,9 +73,9 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'error message is configurable by resource name' do
|
||||
store_translations :en, :devise => { :failure => { :admin => { :invalid => "Invalid credentials" } } } do
|
||||
store_translations :en, devise: { failure: { admin: { invalid: "Invalid credentials" } } } do
|
||||
sign_in_as_admin do
|
||||
fill_in 'password', :with => 'abcdef'
|
||||
fill_in 'password', with: 'abcdef'
|
||||
end
|
||||
|
||||
assert_contain 'Invalid credentials'
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
test 'handles unverified requests gets rid of caches but continues signed in' do
|
||||
swap ApplicationController, :allow_forgery_protection => true do
|
||||
swap ApplicationController, allow_forgery_protection: true do
|
||||
create_user
|
||||
post exhibit_user_url(1), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("user@test.com:12345678")}"
|
||||
assert warden.authenticated?(:user)
|
||||
@@ -16,18 +16,18 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
assert_match '<email>user@test.com</email>', response.body
|
||||
assert warden.authenticated?(:user)
|
||||
|
||||
get users_path(:format => :xml)
|
||||
get users_path(format: :xml)
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
test 'sign in should authenticate with http but not emit a cookie if skipping session storage' do
|
||||
swap Devise, :skip_session_storage => [:http_auth] do
|
||||
swap Devise, skip_session_storage: [:http_auth] do
|
||||
sign_in_as_new_user_with_http
|
||||
assert_response 200
|
||||
assert_match '<email>user@test.com</email>', response.body
|
||||
assert warden.authenticated?(:user)
|
||||
|
||||
get users_path(:format => :xml)
|
||||
get users_path(format: :xml)
|
||||
assert_response 401
|
||||
end
|
||||
end
|
||||
@@ -46,7 +46,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'returns a custom response with www-authenticate and chosen realm' do
|
||||
swap Devise, :http_authentication_realm => "MyApp" do
|
||||
swap Devise, http_authentication_realm: "MyApp" do
|
||||
sign_in_as_new_user_with_http("unknown")
|
||||
assert_equal 401, status
|
||||
assert_equal 'Basic realm="MyApp"', headers["WWW-Authenticate"]
|
||||
@@ -54,7 +54,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'sign in should authenticate with http even with specific authentication keys' do
|
||||
swap Devise, :authentication_keys => [:username] do
|
||||
swap Devise, authentication_keys: [:username] do
|
||||
sign_in_as_new_user_with_http("usertest")
|
||||
assert_response :success
|
||||
assert_match '<email>user@test.com</email>', response.body
|
||||
@@ -63,7 +63,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'it uses appropriate authentication_keys when configured with hash' do
|
||||
swap Devise, :authentication_keys => ActiveSupport::OrderedHash[:username, false, :email, false] do
|
||||
swap Devise, authentication_keys: ActiveSupport::OrderedHash[:username, false, :email, false] do
|
||||
sign_in_as_new_user_with_http("usertest")
|
||||
assert_response :success
|
||||
assert_match '<email>user@test.com</email>', response.body
|
||||
@@ -72,7 +72,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'it uses the appropriate key when configured explicitly' do
|
||||
swap Devise, :authentication_keys => ActiveSupport::OrderedHash[:email, false, :username, false], :http_authentication_key => :username do
|
||||
swap Devise, authentication_keys: ActiveSupport::OrderedHash[:email, false, :username, false], http_authentication_key: :username do
|
||||
sign_in_as_new_user_with_http("usertest")
|
||||
assert_response :success
|
||||
assert_match '<email>user@test.com</email>', response.body
|
||||
@@ -81,7 +81,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'test request with oauth2 header doesnt get mistaken for basic authentication' do
|
||||
swap Devise, :http_authenticatable => true do
|
||||
swap Devise, http_authenticatable: true do
|
||||
add_oauth2_header
|
||||
assert_equal 401, status
|
||||
assert_equal 'Basic realm="Application"', headers["WWW-Authenticate"]
|
||||
@@ -92,14 +92,14 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
|
||||
|
||||
def sign_in_as_new_user_with_http(username="user@test.com", password="12345678")
|
||||
user = create_user
|
||||
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}"
|
||||
get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}"
|
||||
user
|
||||
end
|
||||
|
||||
# Sign in with oauth2 token. This is just to test that it isn't misinterpreted as basic authentication
|
||||
def add_oauth2_header
|
||||
user = create_user
|
||||
get users_path(:format => :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:12345678")}"
|
||||
get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:12345678")}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3,18 +3,18 @@ require 'test_helper'
|
||||
class LockTest < ActionDispatch::IntegrationTest
|
||||
|
||||
def visit_user_unlock_with_token(unlock_token)
|
||||
visit user_unlock_path(:unlock_token => unlock_token)
|
||||
visit user_unlock_path(unlock_token: unlock_token)
|
||||
end
|
||||
|
||||
def send_unlock_request
|
||||
user = create_user(:locked => true)
|
||||
user = create_user(locked: true)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
visit new_user_session_path
|
||||
click_link "Didn't receive unlock instructions?"
|
||||
|
||||
Devise.stubs(:friendly_token).returns("abcdef")
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'email', with: user.email
|
||||
click_button 'Resend unlock instructions'
|
||||
end
|
||||
|
||||
@@ -39,13 +39,13 @@ class LockTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'unlocked user should not be able to request a unlock token' do
|
||||
user = create_user(:locked => false)
|
||||
user = create_user(locked: false)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
visit new_user_session_path
|
||||
click_link "Didn't receive unlock instructions?"
|
||||
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'email', with: user.email
|
||||
click_button 'Resend unlock instructions'
|
||||
|
||||
assert_template 'unlocks/new'
|
||||
@@ -89,60 +89,60 @@ class LockTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "user should not send a new e-mail if already locked" do
|
||||
user = create_user(:locked => true)
|
||||
user = create_user(locked: true)
|
||||
user.failed_attempts = User.maximum_attempts + 1
|
||||
user.save!
|
||||
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
sign_in_as_user(:password => "invalid")
|
||||
sign_in_as_user(password: "invalid")
|
||||
assert_contain 'Your account is locked.'
|
||||
assert ActionMailer::Base.deliveries.empty?
|
||||
end
|
||||
|
||||
test 'error message is configurable by resource name' do
|
||||
store_translations :en, :devise => {
|
||||
:failure => {:user => {:locked => "You are locked!"}}
|
||||
store_translations :en, devise: {
|
||||
failure: {user: {locked: "You are locked!"}}
|
||||
} do
|
||||
|
||||
user = create_user(:locked => true)
|
||||
user = create_user(locked: true)
|
||||
user.failed_attempts = User.maximum_attempts + 1
|
||||
user.save!
|
||||
|
||||
sign_in_as_user(:password => "invalid")
|
||||
sign_in_as_user(password: "invalid")
|
||||
assert_contain "You are locked!"
|
||||
end
|
||||
end
|
||||
|
||||
test "user should not be able to sign in when locked" do
|
||||
store_translations :en, :devise => {
|
||||
:failure => {:user => {:locked => "You are locked!"}}
|
||||
store_translations :en, devise: {
|
||||
failure: {user: {locked: "You are locked!"}}
|
||||
} do
|
||||
|
||||
user = create_user(:locked => true)
|
||||
user = create_user(locked: true)
|
||||
user.failed_attempts = User.maximum_attempts + 1
|
||||
user.save!
|
||||
|
||||
sign_in_as_user(:password => "123456")
|
||||
sign_in_as_user(password: "123456")
|
||||
assert_contain "You are locked!"
|
||||
end
|
||||
end
|
||||
|
||||
test 'user should be able to request a new unlock token via XML request' do
|
||||
user = create_user(:locked => true)
|
||||
user = create_user(locked: true)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
post user_unlock_path(:format => 'xml'), :user => {:email => user.email}
|
||||
post user_unlock_path(format: 'xml'), user: {email: user.email}
|
||||
assert_response :success
|
||||
assert_equal response.body, {}.to_xml
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
end
|
||||
|
||||
test 'unlocked user should not be able to request a unlock token via XML request' do
|
||||
user = create_user(:locked => false)
|
||||
user = create_user(locked: false)
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
post user_unlock_path(:format => 'xml'), :user => {:email => user.email}
|
||||
post user_unlock_path(format: 'xml'), user: {email: user.email}
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
assert_equal 0, ActionMailer::Base.deliveries.size
|
||||
@@ -152,33 +152,33 @@ class LockTest < ActionDispatch::IntegrationTest
|
||||
user = create_user()
|
||||
raw = user.lock_access!
|
||||
assert user.access_locked?
|
||||
get user_unlock_path(:format => 'xml', :unlock_token => raw)
|
||||
get user_unlock_path(format: 'xml', unlock_token: raw)
|
||||
assert_response :success
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
||||
end
|
||||
|
||||
|
||||
test 'user with invalid unlock token should not be able to unlock the account via XML request' do
|
||||
get user_unlock_path(:format => 'xml', :unlock_token => 'invalid_token')
|
||||
get user_unlock_path(format: 'xml', unlock_token: 'invalid_token')
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
|
||||
test "when using json to ask a unlock request, should not return the user" do
|
||||
user = create_user(:locked => true)
|
||||
post user_unlock_path(:format => "json", :user => {:email => user.email})
|
||||
user = create_user(locked: true)
|
||||
post user_unlock_path(format: "json", user: {email: user.email})
|
||||
assert_response :success
|
||||
assert_equal response.body, {}.to_json
|
||||
end
|
||||
|
||||
test "in paranoid mode, when trying to unlock an user that exists it should not say that it exists if it is locked" do
|
||||
swap Devise, :paranoid => true do
|
||||
user = create_user(:locked => true)
|
||||
swap Devise, paranoid: true do
|
||||
user = create_user(locked: true)
|
||||
|
||||
visit new_user_session_path
|
||||
click_link "Didn't receive unlock instructions?"
|
||||
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'email', with: user.email
|
||||
click_button 'Resend unlock instructions'
|
||||
|
||||
assert_current_url "/users/sign_in"
|
||||
@@ -187,13 +187,13 @@ class LockTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "in paranoid mode, when trying to unlock an user that exists it should not say that it exists if it is not locked" do
|
||||
swap Devise, :paranoid => true do
|
||||
user = create_user(:locked => false)
|
||||
swap Devise, paranoid: true do
|
||||
user = create_user(locked: false)
|
||||
|
||||
visit new_user_session_path
|
||||
click_link "Didn't receive unlock instructions?"
|
||||
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'email', with: user.email
|
||||
click_button 'Resend unlock instructions'
|
||||
|
||||
assert_current_url "/users/sign_in"
|
||||
@@ -202,11 +202,11 @@ class LockTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "in paranoid mode, when trying to unlock an user that does not exists it should not say that it does not exists" do
|
||||
swap Devise, :paranoid => true do
|
||||
swap Devise, paranoid: true do
|
||||
visit new_user_session_path
|
||||
click_link "Didn't receive unlock instructions?"
|
||||
|
||||
fill_in 'email', :with => "arandomemail@hotmail.com"
|
||||
fill_in 'email', with: "arandomemail@hotmail.com"
|
||||
click_button 'Resend unlock instructions'
|
||||
|
||||
assert_not_contain "1 error prohibited this user from being saved:"
|
||||
@@ -219,16 +219,16 @@ class LockTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "in paranoid mode, when locking a user that exists it should not say that the user was locked" do
|
||||
swap Devise, :paranoid => true, :maximum_attempts => 1 do
|
||||
user = create_user(:locked => false)
|
||||
swap Devise, paranoid: true, maximum_attempts: 1 do
|
||||
user = create_user(locked: false)
|
||||
|
||||
visit new_user_session_path
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'password', :with => "abadpassword"
|
||||
fill_in 'email', with: user.email
|
||||
fill_in 'password', with: "abadpassword"
|
||||
click_button 'Sign in'
|
||||
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'password', :with => "abadpassword"
|
||||
fill_in 'email', with: user.email
|
||||
fill_in 'password', with: "abadpassword"
|
||||
click_button 'Sign in'
|
||||
|
||||
assert_current_url "/users/sign_in"
|
||||
|
||||
@@ -61,8 +61,8 @@ class OmniauthableIntegrationTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_difference "User.count" do
|
||||
visit "/users/sign_up"
|
||||
fill_in "Password", :with => "12345678"
|
||||
fill_in "Password confirmation", :with => "12345678"
|
||||
fill_in "Password", with: "12345678"
|
||||
fill_in "Password confirmation", with: "12345678"
|
||||
click_button "Sign up"
|
||||
end
|
||||
|
||||
@@ -111,7 +111,7 @@ class OmniauthableIntegrationTest < ActionDispatch::IntegrationTest
|
||||
test "generates a proper link when SCRIPT_NAME is set" do
|
||||
header 'SCRIPT_NAME', '/q'
|
||||
visit "/users/sign_in"
|
||||
assert_select "a", :href => "/q/users/auth/facebook"
|
||||
assert_select "a", href: "/q/users/auth/facebook"
|
||||
end
|
||||
|
||||
test "handles callback error parameter according to the specification" do
|
||||
|
||||
@@ -12,7 +12,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
fill_in 'email', :with => 'user@test.com'
|
||||
fill_in 'email', with: 'user@test.com'
|
||||
yield if block_given?
|
||||
|
||||
Devise.stubs(:friendly_token).returns("abcdef")
|
||||
@@ -21,21 +21,21 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
|
||||
def reset_password(options={}, &block)
|
||||
unless options[:visit] == false
|
||||
visit edit_user_password_path(:reset_password_token => options[:reset_password_token] || "abcdef")
|
||||
visit edit_user_password_path(reset_password_token: options[:reset_password_token] || "abcdef")
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
fill_in 'New password', :with => '987654321'
|
||||
fill_in 'Confirm new password', :with => '987654321'
|
||||
fill_in 'New password', with: '987654321'
|
||||
fill_in 'Confirm new password', with: '987654321'
|
||||
yield if block_given?
|
||||
click_button 'Change my password'
|
||||
end
|
||||
|
||||
test 'reset password with email of different case should succeed when email is in the list of case insensitive keys' do
|
||||
create_user(:email => 'Foo@Bar.com')
|
||||
create_user(email: 'Foo@Bar.com')
|
||||
|
||||
request_forgot_password do
|
||||
fill_in 'email', :with => 'foo@bar.com'
|
||||
fill_in 'email', with: 'foo@bar.com'
|
||||
end
|
||||
|
||||
assert_current_url '/users/sign_in'
|
||||
@@ -43,11 +43,11 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'reset password with email should send an email from a custom mailer' do
|
||||
create_user(:email => 'Foo@Bar.com')
|
||||
create_user(email: 'Foo@Bar.com')
|
||||
|
||||
User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)
|
||||
request_forgot_password do
|
||||
fill_in 'email', :with => 'foo@bar.com'
|
||||
fill_in 'email', with: 'foo@bar.com'
|
||||
end
|
||||
|
||||
mail = ActionMailer::Base.deliveries.last
|
||||
@@ -56,11 +56,11 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do
|
||||
swap Devise, :case_insensitive_keys => [] do
|
||||
create_user(:email => 'Foo@Bar.com')
|
||||
swap Devise, case_insensitive_keys: [] do
|
||||
create_user(email: 'Foo@Bar.com')
|
||||
|
||||
request_forgot_password do
|
||||
fill_in 'email', :with => 'foo@bar.com'
|
||||
fill_in 'email', with: 'foo@bar.com'
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
@@ -71,10 +71,10 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'reset password with email with extra whitespace should succeed when email is in the list of strip whitespace keys' do
|
||||
create_user(:email => 'foo@bar.com')
|
||||
create_user(email: 'foo@bar.com')
|
||||
|
||||
request_forgot_password do
|
||||
fill_in 'email', :with => ' foo@bar.com '
|
||||
fill_in 'email', with: ' foo@bar.com '
|
||||
end
|
||||
|
||||
assert_current_url '/users/sign_in'
|
||||
@@ -82,11 +82,11 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'reset password with email with extra whitespace should fail when email is NOT the list of strip whitespace keys' do
|
||||
swap Devise, :strip_whitespace_keys => [] do
|
||||
create_user(:email => 'foo@bar.com')
|
||||
swap Devise, strip_whitespace_keys: [] do
|
||||
create_user(email: 'foo@bar.com')
|
||||
|
||||
request_forgot_password do
|
||||
fill_in 'email', :with => ' foo@bar.com '
|
||||
fill_in 'email', with: ' foo@bar.com '
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
@@ -116,7 +116,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'not authenticated user with invalid email should receive an error message' do
|
||||
request_forgot_password do
|
||||
fill_in 'email', :with => 'invalid.test@test.com'
|
||||
fill_in 'email', with: 'invalid.test@test.com'
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
@@ -141,7 +141,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'not authenticated user with invalid reset password token should not be able to change their password' do
|
||||
user = create_user
|
||||
reset_password :reset_password_token => 'invalid_reset_password'
|
||||
reset_password reset_password_token: 'invalid_reset_password'
|
||||
|
||||
assert_response :success
|
||||
assert_current_url '/users/password'
|
||||
@@ -154,7 +154,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
user = create_user
|
||||
request_forgot_password
|
||||
reset_password do
|
||||
fill_in 'Confirm new password', :with => 'other_password'
|
||||
fill_in 'Confirm new password', with: 'other_password'
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
@@ -179,12 +179,12 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
user = create_user
|
||||
request_forgot_password
|
||||
|
||||
reset_password { fill_in 'Confirm new password', :with => 'other_password' }
|
||||
reset_password { fill_in 'Confirm new password', with: 'other_password' }
|
||||
assert_response :success
|
||||
assert_have_selector '#error_explanation'
|
||||
assert_not user.reload.valid_password?('987654321')
|
||||
|
||||
reset_password :visit => false
|
||||
reset_password visit: false
|
||||
assert_contain 'Your password was changed successfully.'
|
||||
assert user.reload.valid_password?('987654321')
|
||||
end
|
||||
@@ -199,8 +199,8 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
|
||||
[:none, :time].each do |strategy|
|
||||
swap Devise, :unlock_strategy => strategy do
|
||||
user = create_user(:locked => true)
|
||||
swap Devise, unlock_strategy: strategy do
|
||||
user = create_user(locked: true)
|
||||
request_forgot_password
|
||||
reset_password
|
||||
|
||||
@@ -213,8 +213,8 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :email' do
|
||||
swap Devise, :unlock_strategy => :email do
|
||||
user = create_user(:locked => true)
|
||||
swap Devise, unlock_strategy: :email do
|
||||
user = create_user(locked: true)
|
||||
request_forgot_password
|
||||
reset_password
|
||||
|
||||
@@ -225,8 +225,8 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'unlocks and signs in locked user automatically after changing it\'s password if unlock strategy is :both' do
|
||||
swap Devise, :unlock_strategy => :both do
|
||||
user = create_user(:locked => true)
|
||||
swap Devise, unlock_strategy: :both do
|
||||
user = create_user(locked: true)
|
||||
request_forgot_password
|
||||
reset_password
|
||||
|
||||
@@ -238,22 +238,22 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'reset password request with valid E-Mail in XML format should return valid response' do
|
||||
create_user
|
||||
post user_password_path(:format => 'xml'), :user => {:email => "user@test.com"}
|
||||
post user_password_path(format: 'xml'), user: {email: "user@test.com"}
|
||||
assert_response :success
|
||||
assert_equal response.body, { }.to_xml
|
||||
end
|
||||
|
||||
test 'reset password request with invalid E-Mail in XML format should return valid response' do
|
||||
create_user
|
||||
post user_password_path(:format => 'xml'), :user => {:email => "invalid.test@test.com"}
|
||||
post user_password_path(format: 'xml'), user: {email: "invalid.test@test.com"}
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
|
||||
test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do
|
||||
swap Devise, :paranoid => true do
|
||||
swap Devise, paranoid: true do
|
||||
create_user
|
||||
post user_password_path(:format => 'xml'), :user => {:email => "invalid@test.com"}
|
||||
post user_password_path(format: 'xml'), user: {email: "invalid@test.com"}
|
||||
assert_response :success
|
||||
assert_equal response.body, { }.to_xml
|
||||
end
|
||||
@@ -262,8 +262,8 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
test 'change password with valid parameters in XML format should return valid response' do
|
||||
create_user
|
||||
request_forgot_password
|
||||
put user_password_path(:format => 'xml'), :user => {
|
||||
:reset_password_token => 'abcdef', :password => '987654321', :password_confirmation => '987654321'
|
||||
put user_password_path(format: 'xml'), user: {
|
||||
reset_password_token: 'abcdef', password: '987654321', password_confirmation: '987654321'
|
||||
}
|
||||
assert_response :success
|
||||
assert warden.authenticated?(:user)
|
||||
@@ -272,7 +272,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
test 'change password with invalid token in XML format should return invalid response' do
|
||||
create_user
|
||||
request_forgot_password
|
||||
put user_password_path(:format => 'xml'), :user => {:reset_password_token => 'invalid.token', :password => '987654321', :password_confirmation => '987654321'}
|
||||
put user_password_path(format: 'xml'), user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'}
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
@@ -280,24 +280,24 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
test 'change password with invalid new password in XML format should return invalid response' do
|
||||
user = create_user
|
||||
request_forgot_password
|
||||
put user_password_path(:format => 'xml'), :user => {:reset_password_token => user.reload.reset_password_token, :password => '', :password_confirmation => '987654321'}
|
||||
put user_password_path(format: 'xml'), user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'}
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
|
||||
test "when using json requests to ask a confirmable request, should not return the object" do
|
||||
user = create_user(:confirm => false)
|
||||
user = create_user(confirm: false)
|
||||
|
||||
post user_password_path(:format => :json), :user => { :email => user.email }
|
||||
post user_password_path(format: :json), user: { email: user.email }
|
||||
|
||||
assert_response :success
|
||||
assert_equal response.body, "{}"
|
||||
end
|
||||
|
||||
test "when in paranoid mode and with an invalid e-mail, asking to reset a password should display a message that does not indicates that the e-mail does not exists in the database" do
|
||||
swap Devise, :paranoid => true do
|
||||
swap Devise, paranoid: true do
|
||||
visit_new_password_path
|
||||
fill_in "email", :with => "arandomemail@test.com"
|
||||
fill_in "email", with: "arandomemail@test.com"
|
||||
click_button 'Send me reset password instructions'
|
||||
|
||||
assert_not_contain "1 error prohibited this user from being saved:"
|
||||
@@ -308,10 +308,10 @@ class PasswordTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "when in paranoid mode and with a valid e-mail, asking to reset password should display a message that does not indicates that the email exists in the database and redirect to the failure route" do
|
||||
swap Devise, :paranoid => true do
|
||||
swap Devise, paranoid: true do
|
||||
user = create_user
|
||||
visit_new_password_path
|
||||
fill_in 'email', :with => user.email
|
||||
fill_in 'email', with: user.email
|
||||
click_button 'Send me reset password instructions'
|
||||
|
||||
assert_contain "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
|
||||
|
||||
@@ -8,9 +8,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
|
||||
assert_template 'registrations/new'
|
||||
|
||||
fill_in 'email', :with => 'new_user@test.com'
|
||||
fill_in 'password', :with => 'new_user123'
|
||||
fill_in 'password confirmation', :with => 'new_user123'
|
||||
fill_in 'email', with: 'new_user@test.com'
|
||||
fill_in 'password', with: 'new_user123'
|
||||
fill_in 'password confirmation', with: 'new_user123'
|
||||
click_button 'Sign up'
|
||||
|
||||
assert_contain 'You have signed up successfully'
|
||||
@@ -26,9 +26,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
get new_admin_session_path
|
||||
click_link 'Sign up'
|
||||
|
||||
fill_in 'email', :with => 'new_user@test.com'
|
||||
fill_in 'password', :with => 'new_user123'
|
||||
fill_in 'password confirmation', :with => 'new_user123'
|
||||
fill_in 'email', with: 'new_user@test.com'
|
||||
fill_in 'password', with: 'new_user123'
|
||||
fill_in 'password confirmation', with: 'new_user123'
|
||||
click_button 'Sign up'
|
||||
|
||||
assert_contain 'Welcome! You have signed up successfully.'
|
||||
@@ -41,9 +41,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'new_user@test.com'
|
||||
fill_in 'password', :with => 'new_user123'
|
||||
fill_in 'password confirmation', :with => 'new_user123'
|
||||
fill_in 'email', with: 'new_user@test.com'
|
||||
fill_in 'password', with: 'new_user123'
|
||||
fill_in 'password confirmation', with: 'new_user123'
|
||||
click_button 'Sign up'
|
||||
end
|
||||
|
||||
@@ -76,9 +76,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
Devise::RegistrationsController.any_instance.stubs(:after_inactive_sign_up_path_for).returns("/?custom=1")
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'new_user@test.com'
|
||||
fill_in 'password', :with => 'new_user123'
|
||||
fill_in 'password confirmation', :with => 'new_user123'
|
||||
fill_in 'email', with: 'new_user@test.com'
|
||||
fill_in 'password', with: 'new_user123'
|
||||
fill_in 'password confirmation', with: 'new_user123'
|
||||
click_button 'Sign up'
|
||||
|
||||
assert_current_url "/?custom=1"
|
||||
@@ -92,9 +92,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'invalid_email'
|
||||
fill_in 'password', :with => 'new_user123'
|
||||
fill_in 'password confirmation', :with => 'new_user321'
|
||||
fill_in 'email', with: 'invalid_email'
|
||||
fill_in 'password', with: 'new_user123'
|
||||
fill_in 'password confirmation', with: 'new_user321'
|
||||
click_button 'Sign up'
|
||||
|
||||
assert_template 'registrations/new'
|
||||
@@ -116,9 +116,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
create_user
|
||||
get new_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'user@test.com'
|
||||
fill_in 'password', :with => '123456'
|
||||
fill_in 'password confirmation', :with => '123456'
|
||||
fill_in 'email', with: 'user@test.com'
|
||||
fill_in 'password', with: '123456'
|
||||
fill_in 'password confirmation', with: '123456'
|
||||
click_button 'Sign up'
|
||||
|
||||
assert_current_url '/users'
|
||||
@@ -144,8 +144,8 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as_user
|
||||
get edit_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'user.new@example.com'
|
||||
fill_in 'current password', :with => '12345678'
|
||||
fill_in 'email', with: 'user.new@example.com'
|
||||
fill_in 'current password', with: '12345678'
|
||||
click_button 'Update'
|
||||
|
||||
assert_current_url '/'
|
||||
@@ -158,9 +158,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as_user
|
||||
get edit_user_registration_path
|
||||
|
||||
fill_in 'password', :with => '1234567890'
|
||||
fill_in 'password confirmation', :with => '1234567890'
|
||||
fill_in 'current password', :with => '12345678'
|
||||
fill_in 'password', with: '1234567890'
|
||||
fill_in 'password confirmation', with: '1234567890'
|
||||
fill_in 'current password', with: '12345678'
|
||||
click_button 'Update'
|
||||
|
||||
assert_contain 'You updated your account successfully.'
|
||||
@@ -172,8 +172,8 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as_user
|
||||
get edit_user_registration_path
|
||||
|
||||
fill_in 'email', :with => 'user.new@example.com'
|
||||
fill_in 'current password', :with => 'invalid'
|
||||
fill_in 'email', with: 'user.new@example.com'
|
||||
fill_in 'current password', with: 'invalid'
|
||||
click_button 'Update'
|
||||
|
||||
assert_template 'registrations/edit'
|
||||
@@ -187,9 +187,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as_user
|
||||
get edit_user_registration_path
|
||||
|
||||
fill_in 'password', :with => 'pass1234'
|
||||
fill_in 'password confirmation', :with => 'pass1234'
|
||||
fill_in 'current password', :with => '12345678'
|
||||
fill_in 'password', with: 'pass1234'
|
||||
fill_in 'password confirmation', with: 'pass1234'
|
||||
fill_in 'current password', with: '12345678'
|
||||
click_button 'Update'
|
||||
|
||||
assert_current_url '/'
|
||||
@@ -202,9 +202,9 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as_user
|
||||
get edit_user_registration_path
|
||||
|
||||
fill_in 'password', :with => 'pas123'
|
||||
fill_in 'password confirmation', :with => ''
|
||||
fill_in 'current password', :with => '12345678'
|
||||
fill_in 'password', with: 'pas123'
|
||||
fill_in 'password confirmation', with: ''
|
||||
fill_in 'current password', with: '12345678'
|
||||
click_button 'Update'
|
||||
|
||||
assert_contain Devise.rails4? ?
|
||||
@@ -235,21 +235,21 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'a user with XML sign up stub' do
|
||||
get new_user_registration_path(:format => 'xml')
|
||||
get new_user_registration_path(format: 'xml')
|
||||
assert_response :success
|
||||
assert_match %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>), response.body
|
||||
assert_no_match(/<confirmation-token/, response.body)
|
||||
end
|
||||
|
||||
test 'a user with JSON sign up stub' do
|
||||
get new_user_registration_path(:format => 'json')
|
||||
get new_user_registration_path(format: 'json')
|
||||
assert_response :success
|
||||
assert_match %({"user":), response.body
|
||||
assert_no_match(/"confirmation_token"/, response.body)
|
||||
end
|
||||
|
||||
test 'an admin sign up with valid information in XML format should return valid response' do
|
||||
post admin_registration_path(:format => 'xml'), :admin => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' }
|
||||
post admin_registration_path(format: 'xml'), admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' }
|
||||
assert_response :success
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
|
||||
|
||||
@@ -258,7 +258,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'a user sign up with valid information in XML format should return valid response' do
|
||||
post user_registration_path(:format => 'xml'), :user => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' }
|
||||
post user_registration_path(format: 'xml'), user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' }
|
||||
assert_response :success
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
|
||||
|
||||
@@ -267,28 +267,28 @@ class RegistrationTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'a user sign up with invalid information in XML format should return invalid response' do
|
||||
post user_registration_path(:format => 'xml'), :user => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'invalid' }
|
||||
post user_registration_path(format: 'xml'), user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' }
|
||||
assert_response :unprocessable_entity
|
||||
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
|
||||
end
|
||||
|
||||
test 'a user update information with valid data in XML format should return valid response' do
|
||||
user = sign_in_as_user
|
||||
put user_registration_path(:format => 'xml'), :user => { :current_password => '12345678', :email => 'user.new@test.com' }
|
||||
put user_registration_path(format: 'xml'), user: { current_password: '12345678', email: 'user.new@test.com' }
|
||||
assert_response :success
|
||||
assert_equal user.reload.email, 'user.new@test.com'
|
||||
end
|
||||
|
||||
test 'a user update information with invalid data in XML format should return invalid response' do
|
||||
user = sign_in_as_user
|
||||
put user_registration_path(:format => 'xml'), :user => { :current_password => 'invalid', :email => 'user.new@test.com' }
|
||||
put user_registration_path(format: 'xml'), user: { current_password: 'invalid', email: 'user.new@test.com' }
|
||||
assert_response :unprocessable_entity
|
||||
assert_equal user.reload.email, 'user@test.com'
|
||||
end
|
||||
|
||||
test 'a user cancel their account in XML format should return valid response' do
|
||||
sign_in_as_user
|
||||
delete user_registration_path(:format => 'xml')
|
||||
delete user_registration_path(format: 'xml')
|
||||
assert_response :success
|
||||
assert_equal User.count, 0
|
||||
end
|
||||
@@ -299,8 +299,8 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as_admin
|
||||
get edit_admin_registration_path
|
||||
|
||||
fill_in 'email', :with => 'admin.new@example.com'
|
||||
fill_in 'current password', :with => '123456'
|
||||
fill_in 'email', with: 'admin.new@example.com'
|
||||
fill_in 'current password', with: '123456'
|
||||
click_button 'Update'
|
||||
|
||||
assert_current_url '/admin_area/home'
|
||||
@@ -315,9 +315,9 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as_admin
|
||||
get edit_admin_registration_path
|
||||
|
||||
fill_in 'password', :with => 'pas123'
|
||||
fill_in 'password confirmation', :with => 'pas123'
|
||||
fill_in 'current password', :with => '123456'
|
||||
fill_in 'password', with: 'pas123'
|
||||
fill_in 'password confirmation', with: 'pas123'
|
||||
fill_in 'current password', with: '123456'
|
||||
click_button 'Update'
|
||||
|
||||
assert_current_url '/admin_area/home'
|
||||
@@ -330,14 +330,14 @@ class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as_admin
|
||||
|
||||
get edit_admin_registration_path
|
||||
fill_in 'email', :with => 'admin.new@example.com'
|
||||
fill_in 'current password', :with => '123456'
|
||||
fill_in 'email', with: 'admin.new@example.com'
|
||||
fill_in 'current password', with: '123456'
|
||||
click_button 'Update'
|
||||
|
||||
get edit_admin_registration_path
|
||||
fill_in 'password', :with => 'pas123'
|
||||
fill_in 'password confirmation', :with => 'pas123'
|
||||
fill_in 'current password', :with => '123456'
|
||||
fill_in 'password', with: 'pas123'
|
||||
fill_in 'password confirmation', with: 'pas123'
|
||||
fill_in 'current password', with: '123456'
|
||||
click_button 'Update'
|
||||
|
||||
assert_current_url '/admin_area/home'
|
||||
|
||||
@@ -31,7 +31,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'handle unverified requests gets rid of caches' do
|
||||
swap ApplicationController, :allow_forgery_protection => true do
|
||||
swap ApplicationController, allow_forgery_protection: true do
|
||||
post exhibit_user_url(1)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
@@ -43,19 +43,19 @@ class RememberMeTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'handle unverified requests does not create cookies on sign in' do
|
||||
swap ApplicationController, :allow_forgery_protection => true do
|
||||
swap ApplicationController, allow_forgery_protection: true do
|
||||
get new_user_session_path
|
||||
assert request.session[:_csrf_token]
|
||||
|
||||
post user_session_path, :authenticity_token => "oops", :user =>
|
||||
{ email: "jose.valim@gmail.com", password: "123456", :remember_me => "1" }
|
||||
post user_session_path, authenticity_token: "oops", user:
|
||||
{ email: "jose.valim@gmail.com", password: "123456", remember_me: "1" }
|
||||
assert_not warden.authenticated?(:user)
|
||||
assert_not request.cookies['remember_user_token']
|
||||
end
|
||||
end
|
||||
|
||||
test 'generate remember token after sign in' do
|
||||
sign_in_as_user :remember_me => true
|
||||
sign_in_as_user remember_me: true
|
||||
assert request.cookies['remember_user_token']
|
||||
end
|
||||
|
||||
@@ -63,15 +63,15 @@ class RememberMeTest < ActionDispatch::IntegrationTest
|
||||
# We test this by asserting the cookie is not sent after the redirect
|
||||
# since we changed the domain. This is the only difference with the
|
||||
# previous test.
|
||||
swap Devise, :rememberable_options => { :domain => "omg.somewhere.com" } do
|
||||
sign_in_as_user :remember_me => true
|
||||
swap Devise, rememberable_options: { domain: "omg.somewhere.com" } do
|
||||
sign_in_as_user remember_me: true
|
||||
assert_nil request.cookies["remember_user_token"]
|
||||
end
|
||||
end
|
||||
|
||||
test 'generate remember token with a custom key' do
|
||||
swap Devise, :rememberable_options => { :key => "v1lat_token" } do
|
||||
sign_in_as_user :remember_me => true
|
||||
swap Devise, rememberable_options: { key: "v1lat_token" } do
|
||||
sign_in_as_user remember_me: true
|
||||
assert request.cookies["v1lat_token"]
|
||||
end
|
||||
end
|
||||
@@ -79,7 +79,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest
|
||||
test 'generate remember token after sign in setting session options' do
|
||||
begin
|
||||
Rails.configuration.session_options[:domain] = "omg.somewhere.com"
|
||||
sign_in_as_user :remember_me => true
|
||||
sign_in_as_user remember_me: true
|
||||
assert_nil request.cookies["remember_user_token"]
|
||||
ensure
|
||||
Rails.configuration.session_options.delete(:domain)
|
||||
@@ -103,14 +103,14 @@ class RememberMeTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'does not extend remember period through sign in' do
|
||||
swap Devise, :extend_remember_period => true, :remember_for => 1.year do
|
||||
swap Devise, extend_remember_period: true, remember_for: 1.year do
|
||||
user = create_user
|
||||
user.remember_me!
|
||||
|
||||
user.remember_created_at = old = 10.days.ago
|
||||
user.save
|
||||
|
||||
sign_in_as_user :remember_me => true
|
||||
sign_in_as_user remember_me: true
|
||||
user.reload
|
||||
|
||||
assert warden.user(:user) == user
|
||||
@@ -135,7 +135,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest
|
||||
|
||||
test 'do not remember with expired token' do
|
||||
create_user_and_remember
|
||||
swap Devise, :remember_for => 0 do
|
||||
swap Devise, remember_for: 0 do
|
||||
get users_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
assert_redirected_to new_user_session_path
|
||||
|
||||
@@ -104,7 +104,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
|
||||
user = sign_in_as_user
|
||||
get expire_user_path(user)
|
||||
|
||||
post "/users/sign_in", :email => user.email, :password => "123456"
|
||||
post "/users/sign_in", email: user.email, password: "123456"
|
||||
|
||||
assert_response :redirect
|
||||
follow_redirect!
|
||||
@@ -129,7 +129,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'user configured timeout limit' do
|
||||
swap Devise, :timeout_in => 8.minutes do
|
||||
swap Devise, timeout_in: 8.minutes do
|
||||
user = sign_in_as_user
|
||||
|
||||
get users_path
|
||||
@@ -145,8 +145,8 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'error message with i18n' do
|
||||
store_translations :en, :devise => {
|
||||
:failure => { :user => { :timeout => 'Session expired!' } }
|
||||
store_translations :en, devise: {
|
||||
failure: { user: { timeout: 'Session expired!' } }
|
||||
} do
|
||||
user = sign_in_as_user
|
||||
|
||||
@@ -158,8 +158,8 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'error message with i18n with double redirect' do
|
||||
store_translations :en, :devise => {
|
||||
:failure => { :user => { :timeout => 'Session expired!' } }
|
||||
store_translations :en, devise: {
|
||||
failure: { user: { timeout: 'Session expired!' } }
|
||||
} do
|
||||
user = sign_in_as_user
|
||||
|
||||
@@ -172,7 +172,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test 'time out not triggered if remembered' do
|
||||
user = sign_in_as_user :remember_me => true
|
||||
user = sign_in_as_user remember_me: true
|
||||
get expire_user_path(user)
|
||||
assert_not_nil last_request_at
|
||||
|
||||
|
||||
@@ -63,8 +63,8 @@ class TrackableHooksTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
test "does not update anything if user has signed out along the way" do
|
||||
swap Devise, :allow_unconfirmed_access_for => 0.days do
|
||||
user = create_user(:confirm => false)
|
||||
swap Devise, allow_unconfirmed_access_for: 0.days do
|
||||
user = create_user(confirm: false)
|
||||
sign_in_as_user
|
||||
|
||||
user.reload
|
||||
|
||||
@@ -67,13 +67,13 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
||||
end
|
||||
|
||||
test 'setup subject from I18n' do
|
||||
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :subject => 'Account Confirmation' } } } do
|
||||
store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do
|
||||
assert_equal 'Account Confirmation', mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
test 'subject namespaced by model' do
|
||||
store_translations :en, :devise => { :mailer => { :confirmation_instructions => { :user_subject => 'User Account Confirmation' } } } do
|
||||
store_translations :en, devise: { mailer: { confirmation_instructions: { user_subject: 'User Account Confirmation' } } } do
|
||||
assert_equal 'User Account Confirmation', mail.subject
|
||||
end
|
||||
end
|
||||
@@ -93,7 +93,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
||||
end
|
||||
|
||||
test 'renders a scoped if scoped_views is set to true' do
|
||||
swap Devise, :scoped_views => true do
|
||||
swap Devise, scoped_views: true do
|
||||
assert_equal user.email, mail.body.decoded
|
||||
end
|
||||
end
|
||||
@@ -108,7 +108,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
|
||||
end
|
||||
|
||||
test 'mailer sender accepts a proc' do
|
||||
swap Devise, :mailer_sender => proc { "another@example.com" } do
|
||||
swap Devise, mailer_sender: proc { "another@example.com" } do
|
||||
assert_equal ['another@example.com'], mail.from
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,13 +63,13 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
||||
end
|
||||
|
||||
test 'setup subject from I18n' do
|
||||
store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :subject => 'Reset instructions' } } } do
|
||||
store_translations :en, devise: { mailer: { reset_password_instructions: { subject: 'Reset instructions' } } } do
|
||||
assert_equal 'Reset instructions', mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
test 'subject namespaced by model' do
|
||||
store_translations :en, :devise => { :mailer => { :reset_password_instructions => { :user_subject => 'User Reset Instructions' } } } do
|
||||
store_translations :en, devise: { mailer: { reset_password_instructions: { user_subject: 'User Reset Instructions' } } } do
|
||||
assert_equal 'User Reset Instructions', mail.subject
|
||||
end
|
||||
end
|
||||
@@ -89,7 +89,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
|
||||
end
|
||||
|
||||
test 'mailer sender accepts a proc' do
|
||||
swap Devise, :mailer_sender => proc { "another@example.com" } do
|
||||
swap Devise, mailer_sender: proc { "another@example.com" } do
|
||||
assert_equal ['another@example.com'], mail.from
|
||||
end
|
||||
end
|
||||
|
||||
@@ -64,13 +64,13 @@ class UnlockInstructionsTest < ActionMailer::TestCase
|
||||
end
|
||||
|
||||
test 'setup subject from I18n' do
|
||||
store_translations :en, :devise => { :mailer => { :unlock_instructions => { :subject => 'Yo unlock instructions' } } } do
|
||||
store_translations :en, devise: { mailer: { unlock_instructions: { subject: 'Yo unlock instructions' } } } do
|
||||
assert_equal 'Yo unlock instructions', mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
test 'subject namespaced by model' do
|
||||
store_translations :en, :devise => { :mailer => { :unlock_instructions => { :user_subject => 'User Unlock Instructions' } } } do
|
||||
store_translations :en, devise: { mailer: { unlock_instructions: { user_subject: 'User Unlock Instructions' } } } do
|
||||
assert_equal 'User Unlock Instructions', mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,8 +6,8 @@ class AuthenticatableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'find_first_by_auth_conditions allows custom filtering parameters' do
|
||||
user = User.create!(:email => "example@example.com", :password => "123456")
|
||||
assert_equal User.find_first_by_auth_conditions({ :email => "example@example.com" }), user
|
||||
assert_nil User.find_first_by_auth_conditions({ :email => "example@example.com" }, :id => user.id.to_s.next)
|
||||
user = User.create!(email: "example@example.com", password: "123456")
|
||||
assert_equal User.find_first_by_auth_conditions({ email: "example@example.com" }), user
|
||||
assert_nil User.find_first_by_auth_conditions({ email: "example@example.com" }, id: user.id.to_s.next)
|
||||
end
|
||||
end
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user