mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:58:06 -05:00
Compare commits
166 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
079ed3b6f8 | ||
|
|
5e014ab607 | ||
|
|
0f6014b84d | ||
|
|
b5629ebf1d | ||
|
|
ee01bac8b0 | ||
|
|
3e1c9e343c | ||
|
|
399774af69 | ||
|
|
a62faa2c82 | ||
|
|
059dfc8cce | ||
|
|
cc6a582408 | ||
|
|
ce08d7abb8 | ||
|
|
83213569dd | ||
|
|
be2e17841e | ||
|
|
0591d92f53 | ||
|
|
244cc60d35 | ||
|
|
94c6d5f5cc | ||
|
|
0fe308e7a7 | ||
|
|
801cf00146 | ||
|
|
83002017ea | ||
|
|
0263b8dbfc | ||
|
|
4beeca46c4 | ||
|
|
7c4e8c8d17 | ||
|
|
36613b09d7 | ||
|
|
31774452e8 | ||
|
|
244c22a6a2 | ||
|
|
7d3d6fb3f0 | ||
|
|
ce071502ee | ||
|
|
32f63b2fb9 | ||
|
|
bacd9d244c | ||
|
|
a665aada25 | ||
|
|
0c5d78e31c | ||
|
|
60dc4be8c1 | ||
|
|
f7b6d78606 | ||
|
|
c605758800 | ||
|
|
2135ae5e5e | ||
|
|
a3d31778c2 | ||
|
|
d7f6855ad8 | ||
|
|
0a9e2c961f | ||
|
|
8387cc9474 | ||
|
|
70eb18d766 | ||
|
|
bf4641c8cf | ||
|
|
c76f0e59b7 | ||
|
|
fa2d333bde | ||
|
|
15a50dc8d7 | ||
|
|
a47928090a | ||
|
|
6fc6a28e3b | ||
|
|
6bc2db4567 | ||
|
|
5abdb65e56 | ||
|
|
25a3eeb30a | ||
|
|
33d5335f53 | ||
|
|
8a4d610c58 | ||
|
|
3d2a908f64 | ||
|
|
d2ea28b3db | ||
|
|
7a44233fb9 | ||
|
|
a9bb7d0318 | ||
|
|
ebe65b516b | ||
|
|
ebf79be163 | ||
|
|
88724e10ad | ||
|
|
30405943b5 | ||
|
|
9c0dccfec1 | ||
|
|
9fe7040db9 | ||
|
|
4c3838bb75 | ||
|
|
48aa20897f | ||
|
|
2a5f8b6688 | ||
|
|
8ee01fc10b | ||
|
|
d7985e7ddb | ||
|
|
ae8b0914a9 | ||
|
|
6720f93d2c | ||
|
|
13d4fd4088 | ||
|
|
bbd614a725 | ||
|
|
eb0540e028 | ||
|
|
08374f1d33 | ||
|
|
a5f8cd9d32 | ||
|
|
54e7a3b9d9 | ||
|
|
e761a8df2b | ||
|
|
65d8e94ed9 | ||
|
|
83b88353b5 | ||
|
|
39227bd494 | ||
|
|
e841c4c5ef | ||
|
|
e90ba2fbcb | ||
|
|
e6b5f5f31a | ||
|
|
245b1f9de0 | ||
|
|
e05523f767 | ||
|
|
2c8727ad42 | ||
|
|
b1508e93e1 | ||
|
|
5b57aa0b85 | ||
|
|
768656deb9 | ||
|
|
fe10a5b17a | ||
|
|
22784cb55a | ||
|
|
656720583f | ||
|
|
a20cca6873 | ||
|
|
8d78dc072f | ||
|
|
b2a2e85412 | ||
|
|
c2c74b0a39 | ||
|
|
92bb772d36 | ||
|
|
783234c72a | ||
|
|
2671f19cb1 | ||
|
|
72ea8392a8 | ||
|
|
bb44d422d6 | ||
|
|
5d304ae63a | ||
|
|
0c991af985 | ||
|
|
ac702843dd | ||
|
|
4015488b90 | ||
|
|
cccc137714 | ||
|
|
3fa0afad67 | ||
|
|
29142418ba | ||
|
|
c3b54dc0c2 | ||
|
|
a0232cf763 | ||
|
|
57980ba82a | ||
|
|
bcdd54cc5e | ||
|
|
83d5d3142d | ||
|
|
cbbe932ee2 | ||
|
|
593ae41f9d | ||
|
|
e9770fd434 | ||
|
|
53f6785e11 | ||
|
|
1b48fd0abe | ||
|
|
b835059baf | ||
|
|
f7359d6d96 | ||
|
|
4924dd68ae | ||
|
|
02ed166f51 | ||
|
|
9a11586a72 | ||
|
|
b5a5bae09c | ||
|
|
e757543323 | ||
|
|
7b000390a0 | ||
|
|
3f3ec236bb | ||
|
|
22dd3b489d | ||
|
|
0d45142845 | ||
|
|
62d6b5afb7 | ||
|
|
934fe45cfe | ||
|
|
675ae4d802 | ||
|
|
48251f236f | ||
|
|
8e6e70eaa7 | ||
|
|
4925ffda31 | ||
|
|
f89921e153 | ||
|
|
863b811167 | ||
|
|
d1f8884ee6 | ||
|
|
9caf07dd4f | ||
|
|
2044fffa25 | ||
|
|
2e442d81f7 | ||
|
|
28f0e3281a | ||
|
|
6a0d881554 | ||
|
|
4a9eee5a1c | ||
|
|
a4d3b9f14a | ||
|
|
1beac93961 | ||
|
|
8286325fd0 | ||
|
|
228f24c491 | ||
|
|
cff78eec23 | ||
|
|
20d786d7ca | ||
|
|
0c1b1a896f | ||
|
|
db8e247aa5 | ||
|
|
e01fdba557 | ||
|
|
0a1e55f11c | ||
|
|
85bcbdf18b | ||
|
|
a45c4c0ac4 | ||
|
|
d293e00ef5 | ||
|
|
201a4f92c2 | ||
|
|
71f90c0d6e | ||
|
|
26e22d8e95 | ||
|
|
9805728964 | ||
|
|
f64022a57b | ||
|
|
e79201aef8 | ||
|
|
a2498074f1 | ||
|
|
536279b05b | ||
|
|
031351224a | ||
|
|
74ab3e9a05 | ||
|
|
eba2527b8e |
28
.travis.yml
28
.travis.yml
@@ -1,22 +1,36 @@
|
||||
language: ruby
|
||||
|
||||
rvm:
|
||||
- 2.3.0
|
||||
- 2.2.4
|
||||
- 2.1.8
|
||||
- 2.1.10
|
||||
- 2.2.7
|
||||
- 2.3.4
|
||||
- 2.4.1
|
||||
- ruby-head
|
||||
|
||||
gemfile:
|
||||
- Gemfile
|
||||
- gemfiles/Gemfile.rails-5.0-beta
|
||||
- gemfiles/Gemfile.rails-5.0-stable
|
||||
- gemfiles/Gemfile.rails-4.2-stable
|
||||
- gemfiles/Gemfile.rails-4.1-stable
|
||||
|
||||
matrix:
|
||||
exclude:
|
||||
- rvm: 2.1.8
|
||||
gemfile: gemfiles/Gemfile.rails-5.0-beta
|
||||
- rvm: 2.1.10
|
||||
gemfile: Gemfile
|
||||
- rvm: 2.4.1
|
||||
gemfile: gemfiles/Gemfile.rails-4.1-stable
|
||||
- rvm: ruby-head
|
||||
gemfile: gemfiles/Gemfile.rails-4.1-stable
|
||||
- rvm: 2.1.10
|
||||
gemfile: gemfiles/Gemfile.rails-5.0-stable
|
||||
- rvm: 2.1.10
|
||||
gemfile: Gemfile
|
||||
- env: DEVISE_ORM=mongoid
|
||||
gemfile: gemfiles/Gemfile.rails-5.0-beta
|
||||
gemfile: Gemfile
|
||||
- env: DEVISE_ORM=mongoid
|
||||
gemfile: gemfiles/Gemfile.rails-5.0-stable
|
||||
allow_failures:
|
||||
- rvm: ruby-head
|
||||
services:
|
||||
- mongodb
|
||||
|
||||
|
||||
71
CHANGELOG.md
71
CHANGELOG.md
@@ -1,3 +1,65 @@
|
||||
### 4.3.0 - 2017-05-14
|
||||
|
||||
* Enhancements
|
||||
* Dependency support added for Rails 5.1.x.
|
||||
|
||||
### 4.2.1 - 2017-03-15
|
||||
|
||||
* removals
|
||||
* `Devise::Mailer#scope_name` and `Devise::Mailer#resource` are now protected
|
||||
methods instead of public.
|
||||
* bug fixes
|
||||
* Attempt to reset password without the password field in the request now results in a `:blank` validation error.
|
||||
Before this change, Devise would accept the reset password request and log the user in, without validating/changing
|
||||
the password. (by @victor-am)
|
||||
* Confirmation links now expire based on UTC time, working properly when using different timezones. (by @jjuliano)
|
||||
* enhancements
|
||||
* Notify the original email when it is changed with a new `Devise.send_email_changed_notification` setting.
|
||||
When using `reconfirmable`, the notification will be sent right away instead of when the unconfirmed email is confirmed.
|
||||
(original change by @ethirajsrinivasan)
|
||||
|
||||
### 4.2.0 - 2016-07-01
|
||||
|
||||
* removals
|
||||
* Remove the deprecated `Devise::ParameterSanitizer` API from Devise 3.
|
||||
Please use the `#permit` and `#sanitize` methods over `#for`.
|
||||
* Remove the deprecated OmniAuth URL helpers. Use the fully qualified helpers
|
||||
(`user_facebook_omniauth_authorize_path`) over the scope based helpers
|
||||
( `user_omniauth_authorize_path(:facebook)`).
|
||||
* Remove the `Devise.bcrypt` method, use `Devise::Encryptor.digest` instead.
|
||||
* Remove the `Devise::Models::Confirmable#confirm!` method, use `confirm` instead.
|
||||
* Remove the `Devise::Models::Recoverable#reset_password!` method, use `reset_password` instead.
|
||||
* Remove the `Devise::Models::Recoverable#after_password_reset` method.
|
||||
* bug fixes
|
||||
* Fix an `ActionDispatch::IllegalStateError` when testing controllers with Rails 5 rc 2(by @hamadata).
|
||||
* Use `ActiveSupport.on_load` hooks to include Devise on `ActiveRecord` and `Mongoid`,
|
||||
avoiding autoloading these constants too soon (by @lucasmazza, @rafaelfranca).
|
||||
* enhancements
|
||||
* Display the minimum password length on `registrations/edit` view (by @Yanchek99).
|
||||
* You can disable Devise's routes reloading on boot by through the `reload_routes = false` config.
|
||||
This can reduce the time taken to boot the application but it might trigger
|
||||
some errors if you application (mostly your controllers) requires that
|
||||
Devise mappings be loaded during boot time (by @sidonath).
|
||||
* Added `Devise::Test::IntegrationHelpers` to bypass the sign in process using
|
||||
Warden test API (by @lucasmazza).
|
||||
* Define `inspect` in `Devise::Models::Authenticatable` to help ensure password hashes
|
||||
aren't included in exceptions or otherwise accidentally serialized (by @tkrajcar).
|
||||
* Add missing support of `Rails.application.config.action_controller.relative_url_root` (by @kosdiamantis).
|
||||
* deprecations
|
||||
* `Devise::TestHelpers` is deprecated in favor of `Devise::Test::ControllerHelpers`
|
||||
(by @lucasmazza).
|
||||
* The `sign_in` test helper has changed to use keyword arguments when passing
|
||||
a scope. `sign_in :admin, users(:alice)` should be rewritten as
|
||||
`sign_in users(:alice), scope: :admin` (by @lucasmazza).
|
||||
* The option `bypass` of `Devise::Controllers::SignInOut#sign_in` method is
|
||||
deprecated in favor of `Devise::Controllers::SignInOut#bypass_sign_in`
|
||||
method (by @ulissesalmeida).
|
||||
|
||||
### 4.1.1 - 2016-05-15
|
||||
|
||||
* bug fixes
|
||||
* Fix overwriting the remember_token when a valid one already exists (by @ralinchimev).
|
||||
|
||||
### 4.1.0
|
||||
|
||||
* bug fixes
|
||||
@@ -34,6 +96,11 @@
|
||||
* improvements
|
||||
* Avoids extra computation of friendly token for confirmation token (by @sbc100)
|
||||
|
||||
### 4.0.3 - 2016-05-15
|
||||
|
||||
* bug fixes
|
||||
* Fix overwriting the remember_token when a valid one already exists (by @ralinchimev).
|
||||
|
||||
### 4.0.2 - 2016-05-02
|
||||
|
||||
* bug fixes
|
||||
@@ -77,11 +144,11 @@
|
||||
|
||||
* deprecations
|
||||
* omniauth routes are no longer defined with a wildcard `:provider` parameter,
|
||||
and provider specific routes are defined instead, so route helpers like `user_omniauth_authorize_path(:github)` are deprecated in favor of `user_github_authorize_path`.
|
||||
and provider specific routes are defined instead, so route helpers like `user_omniauth_authorize_path(:github)` are deprecated in favor of `user_github_omniauth_authorize_path`.
|
||||
You can still use `omniauth_authorize_path(:user, :github)` if you need to
|
||||
call the helpers dynamically.
|
||||
|
||||
### 4.0.0.rc1 - 2016-01-02
|
||||
### 4.0.0.rc1 - 2016-02-01
|
||||
|
||||
* Support added to Rails 5 (by @twalpole).
|
||||
* Devise no longer supports Rails 3.2 and 4.0.
|
||||
|
||||
@@ -1,16 +1,79 @@
|
||||
### Please read before contributing
|
||||
# How to contribute to Devise
|
||||
|
||||
1) Do not post questions in the issues tracker. If you have any questions about Devise, search the [Wiki](https://github.com/plataformatec/devise/wiki) or use the [Mailing List](https://groups.google.com/group/plataformatec-devise) or [Stack Overflow](http://stackoverflow.com/questions/tagged/devise).
|
||||
Thanks for your interest on contributing to Devise! Here are a few general
|
||||
guidelines on contributing and reporting bugs to Devise that we ask you to
|
||||
take a look first. Notice that all of your interactions in the project are
|
||||
expected to follow our [Code of Conduct](CODE_OF_CONDUCT.md).
|
||||
|
||||
2) If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to [opensource@plataformatec.com.br](mailto:opensource@plataformatec.com.br) instead.
|
||||
## Reporting Issues
|
||||
|
||||
3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed.
|
||||
Before reporting a new issue, please be sure that the issue wasn't already
|
||||
reported or fixed by searching on GitHub through our [issues](https://github.com/plataformatec/devise/issues).
|
||||
|
||||
4) When reporting an issue, include Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace.
|
||||
When creating a new issue, be sure to include a **title and clear description**,
|
||||
as much relevant information as possible, and either a test case example or
|
||||
even better a **sample Rails app that replicates the issue** - Devise has a lot
|
||||
of moving parts and it's functionality can be affected by third party gems, so
|
||||
we need as much context and details as possible to identify what might be broken
|
||||
for you. We have a [test case template](guides/bug_report_templates/integration_test.rb)
|
||||
that can be used to replicate issues with minimal setup.
|
||||
|
||||
5) Notice that all of your interactions in the project are expected to follow our [Code of Conduct](CODE_OF_CONDUCT.md)
|
||||
Please do not attempt to translate Devise built in views. The views are meant
|
||||
to be a starting point for fresh apps and not production material - eventually
|
||||
all applications will require custom views where you can write your own copy and
|
||||
translate it if the application requires it . For historical references, please look into closed
|
||||
[Issues/Pull Requests](https://github.com/plataformatec/devise/issues?q=i18n) regarding
|
||||
internationalization.
|
||||
|
||||
That's it! The more information you give, the easier it becomes for us to track it down and fix it.
|
||||
Ideally, you should provide an application that reproduces the error or a test case to Devise's suite.
|
||||
Avoid opening new issues to ask questions in our issues tracker. Please go through
|
||||
the project wiki, documentation and source code first, or try to ask your question
|
||||
on [Stack Overflow](http://stackoverflow.com/questions/tagged/devise).
|
||||
|
||||
Thanks!
|
||||
**If you find a security bug, do not report it through GitHub. Please send an
|
||||
e-mail to [opensource@plataformatec.com.br](mailto:opensource@plataformatec.com.br)
|
||||
instead.**
|
||||
|
||||
## Sending Pull Requests
|
||||
|
||||
Before sending a new Pull Request, take a look on existing Pull Requests and Issues
|
||||
to see if the proposed change or fix has been discussed in the past, or if the
|
||||
change was already implemented but not yet released.
|
||||
|
||||
We expect new Pull Requests to include enough tests for new or changed behavior,
|
||||
and we aim to maintain everything as most backwards compatible as possible,
|
||||
reserving breaking changes to be ship in major releases when necessary - you
|
||||
can wrap the new code path with a setting toggle from the `Devise` module defined
|
||||
as `false` by default to require developers to opt-in for the new behavior.
|
||||
|
||||
If your Pull Request includes new or changed behavior, be sure that the changes
|
||||
are beneficial to a wide range of use cases or it's an application specific change
|
||||
that might not be so valuable to other applications. Some changes can be introduced
|
||||
as a new `devise-something` gem instead of belonging to the main codebase.
|
||||
|
||||
When adding new settings, you can take advantage of the [`Devise::Models.config`](https://github.com/plataformatec/devise/blob/245b1f9de0b3386b7913e14b60ea24f43b77feb0/lib/devise/models.rb#L13-L50) method to add class and instance level fallbacks
|
||||
to the new setting.
|
||||
|
||||
We also welcome Pull Requests that improve our existing documentation (both our
|
||||
`README.md` and the RDoc sections in the source code) or improve existing rough
|
||||
edges in our API that might be blocking existing integrations or 3rd party gems.
|
||||
|
||||
## Other ways to contribute
|
||||
|
||||
We welcome anyone that wants to contribute to Devise to triage and reply to
|
||||
open issues to help troubleshoot and fix existing bugs on Devise. Here is what
|
||||
you can do:
|
||||
|
||||
* Help ensure that existing issues follows the recommendations from the
|
||||
_[Reporting Issues](#reporting-issues)_ section, providing feeback to the issue's
|
||||
author on what might be missing.
|
||||
* Review and update the existing content of our [Wiki](https://github.com/plataformatec/devise/wiki)
|
||||
with up to date instructions and code samples - the wiki was grown with several
|
||||
different tutorials and references that we can't keep track of everything, so if
|
||||
there is a page that showcases an integration or customization that you are
|
||||
familiar with feel free to update it as necessary.
|
||||
* Review existing Pull Requests, and testing patches against real existing
|
||||
applications that use Devise.
|
||||
|
||||
Thanks again for your interest on contributing to the project!
|
||||
|
||||
:heart:
|
||||
|
||||
24
Gemfile
24
Gemfile
@@ -2,17 +2,26 @@ source "https://rubygems.org"
|
||||
|
||||
gemspec
|
||||
|
||||
gem "rails", "~> 4.2.6"
|
||||
gem "rails", "~> 5.1"
|
||||
gem "omniauth", "~> 1.3"
|
||||
gem "omniauth-oauth2", "~> 1.4"
|
||||
gem "oauth2"
|
||||
gem "omniauth-oauth2"
|
||||
gem "rdoc"
|
||||
|
||||
gem "activemodel-serializers-xml", github: "rails/activemodel-serializers-xml"
|
||||
|
||||
gem "rails-controller-testing"
|
||||
|
||||
gem "responders", "~> 2.1"
|
||||
|
||||
# TODO: Remove this line when Rails 5.1.1 is released
|
||||
gem "minitest", "< 5.10.2"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "omniauth-openid"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
gem 'test_after_commit', require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
@@ -25,6 +34,7 @@ platforms :ruby do
|
||||
gem "sqlite3"
|
||||
end
|
||||
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 5.0"
|
||||
end
|
||||
# TODO:
|
||||
# group :mongoid do
|
||||
# gem "mongoid", "~> 4.0.0"
|
||||
# end
|
||||
|
||||
228
Gemfile.lock
228
Gemfile.lock
@@ -1,97 +1,103 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/activemodel-serializers-xml.git
|
||||
revision: dd9c0acf26aab111ebc647cd8deb99ebc6946531
|
||||
specs:
|
||||
activemodel-serializers-xml (1.0.1)
|
||||
activemodel (> 5.x)
|
||||
activesupport (> 5.x)
|
||||
builder (~> 3.1)
|
||||
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
devise (4.1.0)
|
||||
devise (4.3.0)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 4.1.0, < 5.1)
|
||||
railties (>= 4.1.0, < 5.2)
|
||||
responders
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actionmailer (4.2.6)
|
||||
actionpack (= 4.2.6)
|
||||
actionview (= 4.2.6)
|
||||
activejob (= 4.2.6)
|
||||
actioncable (5.1.0)
|
||||
actionpack (= 5.1.0)
|
||||
nio4r (~> 2.0)
|
||||
websocket-driver (~> 0.6.1)
|
||||
actionmailer (5.1.0)
|
||||
actionpack (= 5.1.0)
|
||||
actionview (= 5.1.0)
|
||||
activejob (= 5.1.0)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
actionpack (4.2.6)
|
||||
actionview (= 4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
rack (~> 1.6)
|
||||
rack-test (~> 0.6.2)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-dom-testing (~> 2.0)
|
||||
actionpack (5.1.0)
|
||||
actionview (= 5.1.0)
|
||||
activesupport (= 5.1.0)
|
||||
rack (~> 2.0)
|
||||
rack-test (~> 0.6.3)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
actionview (4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
actionview (5.1.0)
|
||||
activesupport (= 5.1.0)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
activejob (4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
globalid (>= 0.3.0)
|
||||
activemodel (4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
builder (~> 3.1)
|
||||
activerecord (4.2.6)
|
||||
activemodel (= 4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
arel (~> 6.0)
|
||||
activesupport (4.2.6)
|
||||
erubi (~> 1.4)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
||||
activejob (5.1.0)
|
||||
activesupport (= 5.1.0)
|
||||
globalid (>= 0.3.6)
|
||||
activemodel (5.1.0)
|
||||
activesupport (= 5.1.0)
|
||||
activerecord (5.1.0)
|
||||
activemodel (= 5.1.0)
|
||||
activesupport (= 5.1.0)
|
||||
arel (~> 8.0)
|
||||
activesupport (5.1.0)
|
||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||
i18n (~> 0.7)
|
||||
json (~> 1.7, >= 1.7.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
arel (6.0.3)
|
||||
arel (8.0.0)
|
||||
bcrypt (3.1.11)
|
||||
bson (4.0.0)
|
||||
builder (3.2.2)
|
||||
concurrent-ruby (1.0.1)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.2)
|
||||
builder (3.2.3)
|
||||
concurrent-ruby (1.0.5)
|
||||
erubi (1.6.0)
|
||||
faraday (0.11.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
globalid (0.3.6)
|
||||
activesupport (>= 4.1.0)
|
||||
hashie (3.4.3)
|
||||
i18n (0.7.0)
|
||||
json (1.8.3)
|
||||
jwt (1.5.1)
|
||||
globalid (0.4.0)
|
||||
activesupport (>= 4.2.0)
|
||||
hashie (3.5.5)
|
||||
i18n (0.8.1)
|
||||
jwt (1.5.6)
|
||||
loofah (2.0.3)
|
||||
nokogiri (>= 1.5.9)
|
||||
mail (2.6.3)
|
||||
mime-types (>= 1.16, < 3)
|
||||
mail (2.6.5)
|
||||
mime-types (>= 1.16, < 4)
|
||||
metaclass (0.0.4)
|
||||
mime-types (2.99.1)
|
||||
mini_portile2 (2.0.0)
|
||||
minitest (5.8.4)
|
||||
mocha (1.1.0)
|
||||
method_source (0.8.2)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.10.1)
|
||||
mocha (1.2.1)
|
||||
metaclass (~> 0.0.1)
|
||||
mongo (2.2.0)
|
||||
bson (~> 4.0)
|
||||
mongoid (5.0.1)
|
||||
activemodel (~> 4.0)
|
||||
mongo (~> 2.1)
|
||||
origin (~> 2.1)
|
||||
tzinfo (>= 0.3.37)
|
||||
multi_json (1.11.2)
|
||||
multi_xml (0.5.5)
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.6.0)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.6.7.2)
|
||||
mini_portile2 (~> 2.0.0.rc2)
|
||||
oauth2 (1.1.0)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0, < 1.5.2)
|
||||
nio4r (2.0.0)
|
||||
nokogiri (1.7.1)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
oauth2 (1.3.1)
|
||||
faraday (>= 0.8, < 0.12)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (>= 1.2, < 3)
|
||||
omniauth (1.3.1)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (>= 1.0, < 3)
|
||||
omniauth-facebook (3.0.0)
|
||||
omniauth (1.6.1)
|
||||
hashie (>= 3.4.6, < 3.6.0)
|
||||
rack (>= 1.6.2, < 3)
|
||||
omniauth-facebook (4.0.0)
|
||||
omniauth-oauth2 (~> 1.2)
|
||||
omniauth-oauth2 (1.4.0)
|
||||
oauth2 (~> 1.0)
|
||||
@@ -99,84 +105,90 @@ GEM
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
origin (2.2.0)
|
||||
orm_adapter (0.5.0)
|
||||
rack (1.6.4)
|
||||
rack (2.0.1)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rails (4.2.6)
|
||||
actionmailer (= 4.2.6)
|
||||
actionpack (= 4.2.6)
|
||||
actionview (= 4.2.6)
|
||||
activejob (= 4.2.6)
|
||||
activemodel (= 4.2.6)
|
||||
activerecord (= 4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
rails (5.1.0)
|
||||
actioncable (= 5.1.0)
|
||||
actionmailer (= 5.1.0)
|
||||
actionpack (= 5.1.0)
|
||||
actionview (= 5.1.0)
|
||||
activejob (= 5.1.0)
|
||||
activemodel (= 5.1.0)
|
||||
activerecord (= 5.1.0)
|
||||
activesupport (= 5.1.0)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.2.6)
|
||||
sprockets-rails
|
||||
rails-deprecated_sanitizer (1.0.3)
|
||||
activesupport (>= 4.2.0.alpha)
|
||||
rails-dom-testing (1.0.7)
|
||||
activesupport (>= 4.2.0.beta, < 5.0)
|
||||
nokogiri (~> 1.6.0)
|
||||
rails-deprecated_sanitizer (>= 1.0.1)
|
||||
railties (= 5.1.0)
|
||||
sprockets-rails (>= 2.0.0)
|
||||
rails-controller-testing (1.0.1)
|
||||
actionpack (~> 5.x)
|
||||
actionview (~> 5.x)
|
||||
activesupport (~> 5.x)
|
||||
rails-dom-testing (2.0.2)
|
||||
activesupport (>= 4.2.0, < 6.0)
|
||||
nokogiri (~> 1.6)
|
||||
rails-html-sanitizer (1.0.3)
|
||||
loofah (~> 2.0)
|
||||
railties (4.2.6)
|
||||
actionpack (= 4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
railties (5.1.0)
|
||||
actionpack (= 5.1.0)
|
||||
activesupport (= 5.1.0)
|
||||
method_source
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rake (11.0.1)
|
||||
rdoc (4.2.2)
|
||||
json (~> 1.4)
|
||||
responders (2.2.0)
|
||||
railties (>= 4.2.0, < 5.1)
|
||||
rake (12.0.0)
|
||||
rdoc (5.1.0)
|
||||
responders (2.4.0)
|
||||
actionpack (>= 4.2.0, < 5.3)
|
||||
railties (>= 4.2.0, < 5.3)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (3.5.2)
|
||||
sprockets (3.7.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (3.0.4)
|
||||
sprockets-rails (3.2.0)
|
||||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
sqlite3 (1.3.11)
|
||||
test_after_commit (1.0.0)
|
||||
activerecord (>= 3.2)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tzinfo (1.2.2)
|
||||
sqlite3 (1.3.13)
|
||||
thor (0.19.4)
|
||||
thread_safe (0.3.6)
|
||||
tzinfo (1.2.3)
|
||||
thread_safe (~> 0.1)
|
||||
warden (1.2.6)
|
||||
warden (1.2.7)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
websocket-driver (0.6.5)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activemodel-serializers-xml!
|
||||
activerecord-jdbc-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
devise!
|
||||
jruby-openssl
|
||||
minitest (< 5.10.2)
|
||||
mocha (~> 1.1)
|
||||
mongoid (~> 5.0)
|
||||
oauth2
|
||||
omniauth (~> 1.3)
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.4)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
rails (~> 4.2.6)
|
||||
omniauth-oauth2
|
||||
omniauth-openid
|
||||
rails (~> 5.1)
|
||||
rails-controller-testing
|
||||
rdoc
|
||||
responders (~> 2.1)
|
||||
sqlite3
|
||||
test_after_commit
|
||||
webrat (= 0.7.3)
|
||||
|
||||
BUNDLED WITH
|
||||
1.11.2
|
||||
1.14.6
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
|
||||
Copyright 2009-2017 Plataformatec. http://plataformatec.com.br
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
150
README.md
150
README.md
@@ -17,7 +17,7 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
|
||||
It's composed of 10 modules:
|
||||
|
||||
* [Database Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): hashes and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.
|
||||
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/intridea/omniauth) support.
|
||||
* [Omniauthable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.
|
||||
* [Confirmable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.
|
||||
* [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
|
||||
* [Registerable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.
|
||||
@@ -43,9 +43,13 @@ https://github.com/plataformatec/devise/wiki/Bug-reports
|
||||
|
||||
If you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to opensource@plataformatec.com.br.
|
||||
|
||||
### Mailing list
|
||||
### StackOverflow and Mailing List
|
||||
|
||||
If you have any questions, comments, or concerns, please use the Google Group instead of the GitHub issue tracker:
|
||||
If you have any questions, comments, or concerns, please use StackOverflow instead of the GitHub issue tracker:
|
||||
|
||||
http://stackoverflow.com/questions/tagged/devise
|
||||
|
||||
The deprecated mailing list can still be read on
|
||||
|
||||
https://groups.google.com/group/plataformatec-devise
|
||||
|
||||
@@ -89,36 +93,39 @@ Once you have solidified your understanding of Rails and authentication mechanis
|
||||
|
||||
## Getting started
|
||||
|
||||
Devise 4.0 works with Rails 4.2 onwards. You can add it to your Gemfile with:
|
||||
Devise 4.0 works with Rails 4.1 onwards. You can add it to your Gemfile with:
|
||||
|
||||
```ruby
|
||||
gem 'devise'
|
||||
```
|
||||
|
||||
Run the bundle command to install it.
|
||||
Then run `bundle install`
|
||||
|
||||
After you install Devise and add it to your Gemfile, you need to run the generator:
|
||||
Next, you need to run the generator:
|
||||
|
||||
```console
|
||||
rails generate devise:install
|
||||
$ rails generate devise:install
|
||||
```
|
||||
|
||||
The generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator:
|
||||
|
||||
```console
|
||||
rails generate devise MODEL
|
||||
```
|
||||
|
||||
Replace MODEL with the class name used for the application’s users (it’s frequently `User` but could also be `Admin`). This will create a model (if one does not exist) and configure it with the default Devise modules. The generator also configures your `config/routes.rb` file to point to the Devise controller.
|
||||
|
||||
Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration. Then run `rake db:migrate`
|
||||
|
||||
Next, you need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
|
||||
At this point, a number of instructions will appear in the console. Among these instructions, you'll need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:
|
||||
|
||||
```ruby
|
||||
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
|
||||
```
|
||||
|
||||
The generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator.
|
||||
|
||||
|
||||
In the following command you will replace `MODEL` with the class name used for the application’s users (it’s frequently `User` but could also be `Admin`). This will create a model (if one does not exist) and configure it with the default Devise modules. The generator also configures your `config/routes.rb` file to point to the Devise controller.
|
||||
|
||||
```console
|
||||
$ rails generate devise MODEL
|
||||
```
|
||||
|
||||
Next, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section. For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration.
|
||||
|
||||
Then run `rails db:migrate`
|
||||
|
||||
You should restart your application after changing Devise's configuration options. Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.
|
||||
|
||||
### Controller filters and helpers
|
||||
@@ -154,7 +161,7 @@ user_session
|
||||
After signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect to. For instance, when using a `:user` resource, the `user_root_path` will be used if it exists; otherwise, the default `root_path` will be used. This means that you need to set the root inside your routes:
|
||||
|
||||
```ruby
|
||||
root to: "home#index"
|
||||
root to: 'home#index'
|
||||
```
|
||||
|
||||
You can also override `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
|
||||
@@ -176,7 +183,7 @@ member_session
|
||||
The Devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the hashing algorithm with:
|
||||
|
||||
```ruby
|
||||
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
|
||||
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 12
|
||||
```
|
||||
|
||||
Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`, `:remember_for`, `:timeout_in`, `:unlock_in` among other options. For more details, see the initializer file that was created when you invoked the "devise:install" generator described above. This file is usually located at `/config/initializers/devise.rb`.
|
||||
@@ -270,7 +277,7 @@ We built Devise to help you quickly develop an application that uses authenticat
|
||||
Since Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:
|
||||
|
||||
```console
|
||||
rails generate devise:views
|
||||
$ rails generate devise:views
|
||||
```
|
||||
|
||||
If you have more than one Devise model in your application (such as `User` and `Admin`), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set `config.scoped_views = true` inside the `config/initializers/devise.rb` file.
|
||||
@@ -278,14 +285,14 @@ If you have more than one Devise model in your application (such as `User` and `
|
||||
After doing so, you will be able to have views based on the role like `users/sessions/new` and `admins/sessions/new`. If no view is found within the scope, Devise will use the default view at `devise/sessions/new`. You can also use the generator to generate scoped views:
|
||||
|
||||
```console
|
||||
rails generate devise:views users
|
||||
$ rails generate devise:views users
|
||||
```
|
||||
|
||||
If you would like to generate only a few sets of views, like the ones for the `registerable` 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
|
||||
$ rails generate devise:views -v registrations confirmations
|
||||
```
|
||||
|
||||
### Configuring controllers
|
||||
@@ -295,7 +302,7 @@ If the customization at the views level is not enough, you can customize each co
|
||||
1. Create your custom controllers using the generator which requires a scope:
|
||||
|
||||
```console
|
||||
rails generate devise:controllers [scope]
|
||||
$ rails generate devise:controllers [scope]
|
||||
```
|
||||
|
||||
If you specify `users` as the scope, controllers will be created in `app/controllers/users/`.
|
||||
@@ -314,7 +321,7 @@ If the customization at the views level is not enough, you can customize each co
|
||||
2. Tell the router to use this controller:
|
||||
|
||||
```ruby
|
||||
devise_for :users, controllers: { sessions: "users/sessions" }
|
||||
devise_for :users, controllers: { sessions: 'users/sessions' }
|
||||
```
|
||||
|
||||
3. Copy the views from `devise/sessions` to `users/sessions`. Since the controller was changed, it won't use the default views located in `devise/sessions`.
|
||||
@@ -352,7 +359,7 @@ Remember that Devise uses flash messages to let users know if sign in was succes
|
||||
Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
|
||||
|
||||
```ruby
|
||||
devise_for :users, path: "auth", path_names: { sign_in: 'login', sign_out: 'logout', password: 'secret', confirmation: 'verification', unlock: 'unblock', registration: 'register', sign_up: 'cmon_let_me_in' }
|
||||
devise_for :users, path: 'auth', path_names: { sign_in: 'login', sign_out: 'logout', password: 'secret', confirmation: 'verification', unlock: 'unblock', registration: 'register', sign_up: 'cmon_let_me_in' }
|
||||
```
|
||||
|
||||
Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/plataformatec/devise/master/ActionDispatch/Routing/Mapper%3Adevise_for) for details.
|
||||
@@ -361,7 +368,7 @@ If you have the need for more deep customization, for instance to also allow "/s
|
||||
|
||||
```ruby
|
||||
devise_scope :user do
|
||||
get "sign_in", to: "devise/sessions#new"
|
||||
get 'sign_in', to: 'devise/sessions#new'
|
||||
end
|
||||
```
|
||||
|
||||
@@ -411,45 +418,94 @@ Caution: Devise Controllers inherit from ApplicationController. If your app uses
|
||||
|
||||
### Test helpers
|
||||
|
||||
Devise includes some test helpers for functional specs. In order to use them, you need to include Devise in your functional tests by adding the following to the bottom of your `test/test_helper.rb` file (make sure you place it out of scope of `ActiveSupport::TestCase` which is the default class inside of `test/test_helper.rb`):
|
||||
Devise includes some test helpers for controller and integration tests.
|
||||
In order to use them, you need to include the respective module in your test
|
||||
cases/specs.
|
||||
|
||||
### Controller tests
|
||||
|
||||
Controller tests require that you include `Devise::Test::ControllerHelpers` on
|
||||
your test case or its parent `ActionController::TestCase` superclass.
|
||||
|
||||
```ruby
|
||||
class ActionController::TestCase
|
||||
include Devise::TestHelpers
|
||||
class PostsControllerTest < ActionController::TestCase
|
||||
include Devise::Test::ControllerHelpers
|
||||
end
|
||||
```
|
||||
|
||||
If you're using RSpec, you can put the following inside a file named `spec/support/devise.rb` or in your `spec/spec_helper.rb` (or `spec/rails_helper.rb` if you are using rspec-rails):
|
||||
If you're using RSpec, you can put the following inside a file named
|
||||
`spec/support/devise.rb` or in your `spec/spec_helper.rb` (or
|
||||
`spec/rails_helper.rb` if you are using `rspec-rails`):
|
||||
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.include Devise::TestHelpers, type: :controller
|
||||
config.include Devise::TestHelpers, type: :view
|
||||
config.include Devise::Test::ControllerHelpers, type: :controller
|
||||
config.include Devise::Test::ControllerHelpers, type: :view
|
||||
end
|
||||
```
|
||||
|
||||
Just be sure that this inclusion is made *after* the `require 'rspec/rails'` directive.
|
||||
|
||||
Now you are ready to use the `sign_in` and `sign_out` methods. Such methods have the same signature as in controllers:
|
||||
Now you are ready to use the `sign_in` and `sign_out` methods on your controller
|
||||
tests:
|
||||
|
||||
```ruby
|
||||
sign_in :user, @user # sign_in(scope, resource)
|
||||
sign_in @user # sign_in(resource)
|
||||
|
||||
sign_out :user # sign_out(scope)
|
||||
sign_out @user # sign_out(resource)
|
||||
sign_in @user
|
||||
sign_in @user, scope: :admin
|
||||
```
|
||||
|
||||
There are two things that are important to keep in mind:
|
||||
If you are testing Devise internal controllers or a controller that inherits
|
||||
from Devise's, you need to tell Devise which mapping should be used before a
|
||||
request. This is necessary because Devise gets this information from the router,
|
||||
but since controller tests do not pass through the router, it needs to be stated
|
||||
explicitly. For example, if you are testing the user scope, simply use:
|
||||
|
||||
1. These helpers are not going to work for integration tests driven by Capybara or Webrat. They are meant to be used with functional tests only. It is undesirable even to include `Devise::TestHelpers` during integration tests. Instead, fill in the form or explicitly set the user in session;
|
||||
```ruby
|
||||
test 'GET new' do
|
||||
# Mimic the router behavior of setting the Devise scope through the env.
|
||||
@request.env['devise.mapping'] = Devise.mappings[:user]
|
||||
|
||||
2. If you are testing Devise internal controllers or a controller that inherits from Devise's, you need to tell Devise which mapping should be used before a request. This is necessary because Devise gets this information from the router, but since functional tests do not pass through the router, it needs to be stated explicitly. For example, if you are testing the user scope, simply use:
|
||||
# Use the sign_in helper to sign in a fixture `User` record.
|
||||
sign_in users(:alice)
|
||||
|
||||
```ruby
|
||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
get :new
|
||||
```
|
||||
get :new
|
||||
|
||||
# assert something
|
||||
end
|
||||
```
|
||||
|
||||
### Integration tests
|
||||
|
||||
Integration test helpers are available by including the
|
||||
`Devise::Test::IntegrationHelpers` module.
|
||||
|
||||
```ruby
|
||||
class PostsTests < ActionDispatch::IntegrationTest
|
||||
include Devise::Test::IntegrationHelpers
|
||||
end
|
||||
```
|
||||
|
||||
Now you can use the following `sign_in` and `sign_out` methods in your integration
|
||||
tests:
|
||||
|
||||
```ruby
|
||||
sign_in users(:bob)
|
||||
sign_in users(:bob), scope: :admin
|
||||
|
||||
sign_out :user
|
||||
```
|
||||
|
||||
RSpec users can include the `IntegrationHelpers` module on their `:feature` specs.
|
||||
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.include Devise::Test::IntegrationHelpers, type: :feature
|
||||
end
|
||||
```
|
||||
|
||||
Unlike controller tests, integration tests do not need to supply the
|
||||
`devise.mapping` `env` value, as the mapping can be inferred by the routes that
|
||||
are executed in your tests.
|
||||
|
||||
You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
|
||||
|
||||
@@ -554,6 +610,6 @@ https://github.com/plataformatec/devise/graphs/contributors
|
||||
|
||||
## License
|
||||
|
||||
MIT License. Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
|
||||
MIT License. Copyright 2009-2017 Plataformatec. http://plataformatec.com.br
|
||||
|
||||
You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.
|
||||
|
||||
@@ -2,7 +2,7 @@ class Devise::OmniauthCallbacksController < DeviseController
|
||||
prepend_before_action { request.env["devise.skip_timeout"] = true }
|
||||
|
||||
def passthru
|
||||
render status: 404, text: "Not found. Authentication passthru."
|
||||
render status: 404, plain: "Not found. Authentication passthru."
|
||||
end
|
||||
|
||||
def failure
|
||||
@@ -13,14 +13,14 @@ class Devise::OmniauthCallbacksController < DeviseController
|
||||
protected
|
||||
|
||||
def failed_strategy
|
||||
request.respond_to?(:get_header) ? request.get_header("omniauth.error.strategy") : env["omniauth.error.strategy"]
|
||||
request.respond_to?(:get_header) ? request.get_header("omniauth.error.strategy") : request.env["omniauth.error.strategy"]
|
||||
end
|
||||
|
||||
def failure_message
|
||||
exception = request.respond_to?(:get_header) ? request.get_header("omniauth.error") : env["omniauth.error"]
|
||||
exception = request.respond_to?(:get_header) ? request.get_header("omniauth.error") : request.env["omniauth.error"]
|
||||
error = exception.error_reason if exception.respond_to?(:error_reason)
|
||||
error ||= exception.error if exception.respond_to?(:error)
|
||||
error ||= (request.respond_to?(:get_header) ? request.get_header("omniauth.error.type") : env["omniauth.error.type"]).to_s
|
||||
error ||= (request.respond_to?(:get_header) ? request.get_header("omniauth.error.type") : request.env["omniauth.error.type"]).to_s
|
||||
error.to_s.humanize if error
|
||||
end
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
class Devise::RegistrationsController < DeviseController
|
||||
prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
|
||||
prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
|
||||
prepend_before_action :set_minimum_password_length, only: [:new, :edit]
|
||||
|
||||
# GET /resource/sign_up
|
||||
def new
|
||||
build_resource({})
|
||||
set_minimum_password_length
|
||||
yield resource if block_given?
|
||||
respond_with self.resource
|
||||
respond_with resource
|
||||
end
|
||||
|
||||
# POST /resource
|
||||
@@ -53,10 +53,11 @@ class Devise::RegistrationsController < DeviseController
|
||||
:update_needs_confirmation : :updated
|
||||
set_flash_message :notice, flash_key
|
||||
end
|
||||
sign_in resource_name, resource, bypass: true
|
||||
bypass_sign_in resource, scope: resource_name
|
||||
respond_with resource, location: after_update_path_for(resource)
|
||||
else
|
||||
clean_up_passwords resource
|
||||
set_minimum_password_length
|
||||
respond_with resource
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,6 +17,10 @@ if defined?(ActionMailer)
|
||||
devise_mail(record, :unlock_instructions, opts)
|
||||
end
|
||||
|
||||
def email_changed(record, opts={})
|
||||
devise_mail(record, :email_changed, opts)
|
||||
end
|
||||
|
||||
def password_change(record, opts={})
|
||||
devise_mail(record, :password_change, opts)
|
||||
end
|
||||
|
||||
7
app/views/devise/mailer/email_changed.html.erb
Normal file
7
app/views/devise/mailer/email_changed.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<p>Hello <%= @email %>!</p>
|
||||
|
||||
<% if @resource.try(:unconfirmed_email?) %>
|
||||
<p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>
|
||||
<% else %>
|
||||
<p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>
|
||||
<% end %>
|
||||
@@ -15,6 +15,10 @@
|
||||
<div class="field">
|
||||
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
||||
<%= f.password_field :password, autocomplete: "off" %>
|
||||
<% if @minimum_password_length %>
|
||||
<br />
|
||||
<em><%= @minimum_password_length %> characters minimum</em>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
||||
@@ -23,6 +23,8 @@ en:
|
||||
subject: "Reset password instructions"
|
||||
unlock_instructions:
|
||||
subject: "Unlock instructions"
|
||||
email_changed:
|
||||
subject: "Email Changed"
|
||||
password_change:
|
||||
subject: "Password Changed"
|
||||
omniauth_callbacks:
|
||||
|
||||
@@ -21,6 +21,6 @@ Gem::Specification.new do |s|
|
||||
s.add_dependency("warden", "~> 1.2.3")
|
||||
s.add_dependency("orm_adapter", "~> 0.1")
|
||||
s.add_dependency("bcrypt", "~> 3.0")
|
||||
s.add_dependency("railties", ">= 4.1.0", "< 5.1")
|
||||
s.add_dependency("railties", ">= 4.1.0", "< 5.2")
|
||||
s.add_dependency("responders")
|
||||
end
|
||||
|
||||
@@ -3,13 +3,13 @@ source "https://rubygems.org"
|
||||
gemspec path: ".."
|
||||
|
||||
gem "rails", github: "rails/rails", branch: "4-1-stable"
|
||||
gem "omniauth", "~> 1.3"
|
||||
gem "omniauth-oauth2", "~> 1.4"
|
||||
gem "omniauth"
|
||||
gem "omniauth-oauth2"
|
||||
gem "rdoc"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "omniauth-openid"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
gem 'test_after_commit', require: false
|
||||
@@ -26,5 +26,5 @@ platforms :ruby do
|
||||
end
|
||||
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 4.0.0"
|
||||
gem "mongoid", "~> 4.0"
|
||||
end
|
||||
|
||||
@@ -1,83 +1,80 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/rails.git
|
||||
revision: 41b4d81b4fd14cbf43060c223bea0f461256d099
|
||||
revision: 0cad778c2605a5204a05a9f1dbd3344e39f248d8
|
||||
branch: 4-1-stable
|
||||
specs:
|
||||
actionmailer (4.1.15)
|
||||
actionpack (= 4.1.15)
|
||||
actionview (= 4.1.15)
|
||||
actionmailer (4.1.16)
|
||||
actionpack (= 4.1.16)
|
||||
actionview (= 4.1.16)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
actionpack (4.1.15)
|
||||
actionview (= 4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
rack (~> 1.5.2)
|
||||
rack-test (~> 0.6.2)
|
||||
actionview (4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
activemodel (4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
builder (~> 3.1)
|
||||
activerecord (4.1.15)
|
||||
activemodel (= 4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
arel (~> 5.0.0)
|
||||
activesupport (4.1.15)
|
||||
i18n (~> 0.6, >= 0.6.9)
|
||||
json (~> 1.7, >= 1.7.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.1)
|
||||
tzinfo (~> 1.1)
|
||||
rails (4.1.15)
|
||||
actionmailer (= 4.1.15)
|
||||
actionpack (= 4.1.15)
|
||||
actionview (= 4.1.15)
|
||||
activemodel (= 4.1.15)
|
||||
activerecord (= 4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
rails (4.1.16)
|
||||
actionmailer (= 4.1.16)
|
||||
actionpack (= 4.1.16)
|
||||
actionview (= 4.1.16)
|
||||
activemodel (= 4.1.16)
|
||||
activerecord (= 4.1.16)
|
||||
activesupport (= 4.1.16)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.1.15)
|
||||
railties (= 4.1.16)
|
||||
sprockets-rails (~> 2.0)
|
||||
railties (4.1.15)
|
||||
actionpack (= 4.1.15)
|
||||
activesupport (= 4.1.15)
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (4.0.1)
|
||||
devise (4.3.0)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 4.1.0, < 5.1)
|
||||
railties (>= 4.1.0, < 5.2)
|
||||
responders
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actionpack (4.1.16)
|
||||
actionview (= 4.1.16)
|
||||
activesupport (= 4.1.16)
|
||||
rack (~> 1.5.2)
|
||||
rack-test (~> 0.6.2)
|
||||
actionview (4.1.16)
|
||||
activesupport (= 4.1.16)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
activemodel (4.1.16)
|
||||
activesupport (= 4.1.16)
|
||||
builder (~> 3.1)
|
||||
activerecord (4.1.16)
|
||||
activemodel (= 4.1.16)
|
||||
activesupport (= 4.1.16)
|
||||
arel (~> 5.0.0)
|
||||
activesupport (4.1.16)
|
||||
i18n (~> 0.6, >= 0.6.9)
|
||||
json (~> 1.7, >= 1.7.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.1)
|
||||
tzinfo (~> 1.1)
|
||||
arel (5.0.1.20140414130214)
|
||||
bcrypt (3.1.11)
|
||||
bson (3.2.6)
|
||||
builder (3.2.2)
|
||||
concurrent-ruby (1.0.1)
|
||||
connection_pool (2.2.0)
|
||||
builder (3.2.3)
|
||||
concurrent-ruby (1.0.5)
|
||||
connection_pool (2.2.1)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.2)
|
||||
faraday (0.11.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
hashie (3.4.3)
|
||||
i18n (0.7.0)
|
||||
json (1.8.3)
|
||||
jwt (1.5.1)
|
||||
mail (2.6.3)
|
||||
mime-types (>= 1.16, < 3)
|
||||
hashie (3.5.5)
|
||||
i18n (0.8.1)
|
||||
json (1.8.6)
|
||||
jwt (1.5.6)
|
||||
mail (2.6.4)
|
||||
mime-types (>= 1.16, < 4)
|
||||
metaclass (0.0.4)
|
||||
mime-types (2.99.1)
|
||||
mini_portile2 (2.0.0)
|
||||
minitest (5.8.4)
|
||||
mocha (1.1.0)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.10.1)
|
||||
mocha (1.2.1)
|
||||
metaclass (~> 0.0.1)
|
||||
mongoid (4.0.2)
|
||||
activemodel (~> 4.0)
|
||||
@@ -88,21 +85,21 @@ GEM
|
||||
bson (~> 3.0)
|
||||
connection_pool (~> 2.0)
|
||||
optionable (~> 0.2.0)
|
||||
multi_json (1.11.2)
|
||||
multi_xml (0.5.5)
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.6.0)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.6.7.2)
|
||||
mini_portile2 (~> 2.0.0.rc2)
|
||||
oauth2 (1.1.0)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0, < 1.5.2)
|
||||
nokogiri (1.7.0.1)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
oauth2 (1.3.1)
|
||||
faraday (>= 0.8, < 0.12)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (>= 1.2, < 3)
|
||||
omniauth (1.3.1)
|
||||
omniauth (1.4.2)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (>= 1.0, < 3)
|
||||
omniauth-facebook (3.0.0)
|
||||
omniauth-facebook (4.0.0)
|
||||
omniauth-oauth2 (~> 1.2)
|
||||
omniauth-oauth2 (1.4.0)
|
||||
oauth2 (~> 1.0)
|
||||
@@ -111,7 +108,7 @@ GEM
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
optionable (0.2.0)
|
||||
origin (2.2.0)
|
||||
origin (2.3.0)
|
||||
orm_adapter (0.5.0)
|
||||
rack (1.5.5)
|
||||
rack-openid (1.3.1)
|
||||
@@ -119,27 +116,31 @@ GEM
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rake (11.0.1)
|
||||
rdoc (4.2.2)
|
||||
json (~> 1.4)
|
||||
railties (4.1.16)
|
||||
actionpack (= 4.1.16)
|
||||
activesupport (= 4.1.16)
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rake (12.0.0)
|
||||
rdoc (5.1.0)
|
||||
responders (1.1.2)
|
||||
railties (>= 3.2, < 4.2)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (3.5.2)
|
||||
sprockets (3.7.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (2.3.3)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
sprockets (>= 2.8, < 4.0)
|
||||
sqlite3 (1.3.11)
|
||||
test_after_commit (1.0.0)
|
||||
sqlite3 (1.3.13)
|
||||
test_after_commit (1.1.0)
|
||||
activerecord (>= 3.2)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
thor (0.19.4)
|
||||
thread_safe (0.3.6)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
warden (1.2.6)
|
||||
warden (1.2.7)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
@@ -155,11 +156,11 @@ DEPENDENCIES
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 1.1)
|
||||
mongoid (~> 4.0.0)
|
||||
omniauth (~> 1.3)
|
||||
mongoid (~> 4.0)
|
||||
omniauth
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.4)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
omniauth-oauth2
|
||||
omniauth-openid
|
||||
rails!
|
||||
rdoc
|
||||
sqlite3
|
||||
@@ -167,4 +168,4 @@ DEPENDENCIES
|
||||
webrat (= 0.7.3)
|
||||
|
||||
BUNDLED WITH
|
||||
1.11.2
|
||||
1.14.6
|
||||
|
||||
@@ -3,13 +3,13 @@ source "https://rubygems.org"
|
||||
gemspec path: ".."
|
||||
|
||||
gem "rails", github: "rails/rails", branch: "4-2-stable"
|
||||
gem "omniauth", "~> 1.3"
|
||||
gem "omniauth-oauth2", "~> 1.4"
|
||||
gem "omniauth"
|
||||
gem "omniauth-oauth2"
|
||||
gem "rdoc"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "omniauth-openid"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
gem 'test_after_commit', require: false
|
||||
@@ -26,5 +26,5 @@ platforms :ruby do
|
||||
end
|
||||
|
||||
group :mongoid do
|
||||
gem "mongoid", "~> 4.0.0"
|
||||
gem "mongoid", "~> 4.0"
|
||||
end
|
||||
|
||||
@@ -1,97 +1,97 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/rails.git
|
||||
revision: 2aa27582c202148296bb169159b0bf9a47a7bd80
|
||||
revision: dc3ae21802c316e1639239d28202db7aa7fb7cac
|
||||
branch: 4-2-stable
|
||||
specs:
|
||||
actionmailer (4.2.6)
|
||||
actionpack (= 4.2.6)
|
||||
actionview (= 4.2.6)
|
||||
activejob (= 4.2.6)
|
||||
actionmailer (4.2.8)
|
||||
actionpack (= 4.2.8)
|
||||
actionview (= 4.2.8)
|
||||
activejob (= 4.2.8)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
actionpack (4.2.6)
|
||||
actionview (= 4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
actionpack (4.2.8)
|
||||
actionview (= 4.2.8)
|
||||
activesupport (= 4.2.8)
|
||||
rack (~> 1.6)
|
||||
rack-test (~> 0.6.2)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
actionview (4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
actionview (4.2.8)
|
||||
activesupport (= 4.2.8)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
activejob (4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
||||
activejob (4.2.8)
|
||||
activesupport (= 4.2.8)
|
||||
globalid (>= 0.3.0)
|
||||
activemodel (4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
activemodel (4.2.8)
|
||||
activesupport (= 4.2.8)
|
||||
builder (~> 3.1)
|
||||
activerecord (4.2.6)
|
||||
activemodel (= 4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
activerecord (4.2.8)
|
||||
activemodel (= 4.2.8)
|
||||
activesupport (= 4.2.8)
|
||||
arel (~> 6.0)
|
||||
activesupport (4.2.6)
|
||||
activesupport (4.2.8)
|
||||
i18n (~> 0.7)
|
||||
json (~> 1.7, >= 1.7.7)
|
||||
minitest (~> 5.1)
|
||||
thread_safe (~> 0.3, >= 0.3.4)
|
||||
tzinfo (~> 1.1)
|
||||
rails (4.2.6)
|
||||
actionmailer (= 4.2.6)
|
||||
actionpack (= 4.2.6)
|
||||
actionview (= 4.2.6)
|
||||
activejob (= 4.2.6)
|
||||
activemodel (= 4.2.6)
|
||||
activerecord (= 4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
rails (4.2.8)
|
||||
actionmailer (= 4.2.8)
|
||||
actionpack (= 4.2.8)
|
||||
actionview (= 4.2.8)
|
||||
activejob (= 4.2.8)
|
||||
activemodel (= 4.2.8)
|
||||
activerecord (= 4.2.8)
|
||||
activesupport (= 4.2.8)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 4.2.6)
|
||||
railties (= 4.2.8)
|
||||
sprockets-rails
|
||||
railties (4.2.6)
|
||||
actionpack (= 4.2.6)
|
||||
activesupport (= 4.2.6)
|
||||
railties (4.2.8)
|
||||
actionpack (= 4.2.8)
|
||||
activesupport (= 4.2.8)
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (4.0.1)
|
||||
devise (4.3.0)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 4.1.0, < 5.1)
|
||||
railties (>= 4.1.0, < 5.2)
|
||||
responders
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
arel (6.0.3)
|
||||
arel (6.0.4)
|
||||
bcrypt (3.1.11)
|
||||
bson (3.2.6)
|
||||
builder (3.2.2)
|
||||
concurrent-ruby (1.0.1)
|
||||
connection_pool (2.2.0)
|
||||
builder (3.2.3)
|
||||
concurrent-ruby (1.0.5)
|
||||
connection_pool (2.2.1)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.2)
|
||||
faraday (0.11.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
globalid (0.3.6)
|
||||
globalid (0.3.7)
|
||||
activesupport (>= 4.1.0)
|
||||
hashie (3.4.3)
|
||||
i18n (0.7.0)
|
||||
json (1.8.3)
|
||||
jwt (1.5.1)
|
||||
hashie (3.5.5)
|
||||
i18n (0.8.1)
|
||||
jwt (1.5.6)
|
||||
loofah (2.0.3)
|
||||
nokogiri (>= 1.5.9)
|
||||
mail (2.6.3)
|
||||
mime-types (>= 1.16, < 3)
|
||||
mail (2.6.4)
|
||||
mime-types (>= 1.16, < 4)
|
||||
metaclass (0.0.4)
|
||||
mime-types (2.99.1)
|
||||
mini_portile2 (2.0.0)
|
||||
minitest (5.8.4)
|
||||
mocha (1.1.0)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.10.1)
|
||||
mocha (1.2.1)
|
||||
metaclass (~> 0.0.1)
|
||||
mongoid (4.0.2)
|
||||
activemodel (~> 4.0)
|
||||
@@ -102,21 +102,21 @@ GEM
|
||||
bson (~> 3.0)
|
||||
connection_pool (~> 2.0)
|
||||
optionable (~> 0.2.0)
|
||||
multi_json (1.11.2)
|
||||
multi_xml (0.5.5)
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.6.0)
|
||||
multipart-post (2.0.0)
|
||||
nokogiri (1.6.7.2)
|
||||
mini_portile2 (~> 2.0.0.rc2)
|
||||
oauth2 (1.1.0)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0, < 1.5.2)
|
||||
nokogiri (1.7.0.1)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
oauth2 (1.3.1)
|
||||
faraday (>= 0.8, < 0.12)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (>= 1.2, < 3)
|
||||
omniauth (1.3.1)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (>= 1.0, < 3)
|
||||
omniauth-facebook (3.0.0)
|
||||
omniauth (1.6.1)
|
||||
hashie (>= 3.4.6, < 3.6.0)
|
||||
rack (>= 1.6.2, < 3)
|
||||
omniauth-facebook (4.0.0)
|
||||
omniauth-oauth2 (~> 1.2)
|
||||
omniauth-oauth2 (1.4.0)
|
||||
oauth2 (~> 1.0)
|
||||
@@ -125,9 +125,9 @@ GEM
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
optionable (0.2.0)
|
||||
origin (2.2.0)
|
||||
origin (2.3.0)
|
||||
orm_adapter (0.5.0)
|
||||
rack (1.6.4)
|
||||
rack (1.6.5)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
@@ -135,33 +135,33 @@ GEM
|
||||
rack (>= 1.0)
|
||||
rails-deprecated_sanitizer (1.0.3)
|
||||
activesupport (>= 4.2.0.alpha)
|
||||
rails-dom-testing (1.0.7)
|
||||
rails-dom-testing (1.0.8)
|
||||
activesupport (>= 4.2.0.beta, < 5.0)
|
||||
nokogiri (~> 1.6.0)
|
||||
nokogiri (~> 1.6)
|
||||
rails-deprecated_sanitizer (>= 1.0.1)
|
||||
rails-html-sanitizer (1.0.3)
|
||||
loofah (~> 2.0)
|
||||
rake (11.0.1)
|
||||
rdoc (4.2.2)
|
||||
json (~> 1.4)
|
||||
responders (2.1.2)
|
||||
railties (>= 4.2.0, < 5.1)
|
||||
rake (12.0.0)
|
||||
rdoc (5.1.0)
|
||||
responders (2.4.0)
|
||||
actionpack (>= 4.2.0, < 5.3)
|
||||
railties (>= 4.2.0, < 5.3)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (3.5.2)
|
||||
sprockets (3.7.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (3.0.4)
|
||||
sprockets-rails (3.2.0)
|
||||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
sqlite3 (1.3.11)
|
||||
test_after_commit (1.0.0)
|
||||
sqlite3 (1.3.13)
|
||||
test_after_commit (1.1.0)
|
||||
activerecord (>= 3.2)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
thor (0.19.4)
|
||||
thread_safe (0.3.6)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
warden (1.2.6)
|
||||
warden (1.2.7)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
@@ -177,11 +177,11 @@ DEPENDENCIES
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 1.1)
|
||||
mongoid (~> 4.0.0)
|
||||
omniauth (~> 1.3)
|
||||
mongoid (~> 4.0)
|
||||
omniauth
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (~> 1.4)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
omniauth-oauth2
|
||||
omniauth-openid
|
||||
rails!
|
||||
rdoc
|
||||
sqlite3
|
||||
@@ -189,4 +189,4 @@ DEPENDENCIES
|
||||
webrat (= 0.7.3)
|
||||
|
||||
BUNDLED WITH
|
||||
1.11.2
|
||||
1.14.6
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/activemodel-serializers-xml.git
|
||||
revision: f380ea5ddefcb9a37f4fbc47606ed6fbecdb2b2a
|
||||
specs:
|
||||
activemodel-serializers-xml (1.0.0)
|
||||
activemodel (> 5.x)
|
||||
activerecord (> 5.x)
|
||||
activesupport (> 5.x)
|
||||
builder (~> 3.1)
|
||||
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (4.0.0.rc2)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 4.1.0, < 5.1)
|
||||
responders
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actioncable (5.0.0.beta3)
|
||||
actionpack (= 5.0.0.beta3)
|
||||
nio4r (~> 1.2)
|
||||
websocket-driver (~> 0.6.1)
|
||||
actionmailer (5.0.0.beta3)
|
||||
actionpack (= 5.0.0.beta3)
|
||||
actionview (= 5.0.0.beta3)
|
||||
activejob (= 5.0.0.beta3)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
actionpack (5.0.0.beta3)
|
||||
actionview (= 5.0.0.beta3)
|
||||
activesupport (= 5.0.0.beta3)
|
||||
rack (~> 2.x)
|
||||
rack-test (~> 0.6.3)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
actionview (5.0.0.beta3)
|
||||
activesupport (= 5.0.0.beta3)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
activejob (5.0.0.beta3)
|
||||
activesupport (= 5.0.0.beta3)
|
||||
globalid (>= 0.3.6)
|
||||
activemodel (5.0.0.beta3)
|
||||
activesupport (= 5.0.0.beta3)
|
||||
activerecord (5.0.0.beta3)
|
||||
activemodel (= 5.0.0.beta3)
|
||||
activesupport (= 5.0.0.beta3)
|
||||
arel (~> 7.0)
|
||||
activesupport (5.0.0.beta3)
|
||||
concurrent-ruby (~> 1.0)
|
||||
i18n (~> 0.7)
|
||||
minitest (~> 5.1)
|
||||
tzinfo (~> 1.1)
|
||||
arel (7.0.0)
|
||||
bcrypt (3.1.11)
|
||||
builder (3.2.2)
|
||||
concurrent-ruby (1.0.1)
|
||||
erubis (2.7.0)
|
||||
faraday (0.9.2)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
globalid (0.3.6)
|
||||
activesupport (>= 4.1.0)
|
||||
hashie (3.4.3)
|
||||
i18n (0.7.0)
|
||||
json (1.8.3)
|
||||
jwt (1.5.1)
|
||||
loofah (2.0.3)
|
||||
nokogiri (>= 1.5.9)
|
||||
mail (2.6.4)
|
||||
mime-types (>= 1.16, < 4)
|
||||
metaclass (0.0.4)
|
||||
method_source (0.8.2)
|
||||
mime-types (3.0)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0221)
|
||||
mini_portile2 (2.0.0)
|
||||
minitest (5.8.4)
|
||||
mocha (1.1.0)
|
||||
metaclass (~> 0.0.1)
|
||||
multi_json (1.11.2)
|
||||
multi_xml (0.5.5)
|
||||
multipart-post (2.0.0)
|
||||
nio4r (1.2.1)
|
||||
nokogiri (1.6.7.2)
|
||||
mini_portile2 (~> 2.0.0.rc2)
|
||||
oauth2 (1.1.0)
|
||||
faraday (>= 0.8, < 0.10)
|
||||
jwt (~> 1.0, < 1.5.2)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (>= 1.2, < 3)
|
||||
omniauth (1.3.1)
|
||||
hashie (>= 1.2, < 4)
|
||||
rack (>= 1.0, < 3)
|
||||
omniauth-facebook (3.0.0)
|
||||
omniauth-oauth2 (~> 1.2)
|
||||
omniauth-oauth2 (1.4.0)
|
||||
oauth2 (~> 1.0)
|
||||
omniauth (~> 1.2)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
orm_adapter (0.5.0)
|
||||
rack (2.0.0.alpha)
|
||||
json
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rails (5.0.0.beta3)
|
||||
actioncable (= 5.0.0.beta3)
|
||||
actionmailer (= 5.0.0.beta3)
|
||||
actionpack (= 5.0.0.beta3)
|
||||
actionview (= 5.0.0.beta3)
|
||||
activejob (= 5.0.0.beta3)
|
||||
activemodel (= 5.0.0.beta3)
|
||||
activerecord (= 5.0.0.beta3)
|
||||
activesupport (= 5.0.0.beta3)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 5.0.0.beta3)
|
||||
sprockets-rails (>= 2.0.0)
|
||||
rails-controller-testing (0.1.1)
|
||||
actionpack (~> 5.x)
|
||||
actionview (~> 5.x)
|
||||
activesupport (~> 5.x)
|
||||
rails-deprecated_sanitizer (1.0.3)
|
||||
activesupport (>= 4.2.0.alpha)
|
||||
rails-dom-testing (1.0.7)
|
||||
activesupport (>= 4.2.0.beta, < 5.0)
|
||||
nokogiri (~> 1.6.0)
|
||||
rails-deprecated_sanitizer (>= 1.0.1)
|
||||
rails-html-sanitizer (1.0.3)
|
||||
loofah (~> 2.0)
|
||||
railties (5.0.0.beta3)
|
||||
actionpack (= 5.0.0.beta3)
|
||||
activesupport (= 5.0.0.beta3)
|
||||
method_source
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rake (11.1.2)
|
||||
rdoc (4.2.2)
|
||||
json (~> 1.4)
|
||||
responders (2.1.2)
|
||||
railties (>= 4.2.0, < 5.1)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (3.6.0)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (3.0.4)
|
||||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
sqlite3 (1.3.11)
|
||||
thor (0.19.1)
|
||||
thread_safe (0.3.5)
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
warden (1.2.6)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
websocket-driver (0.6.3)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activemodel-serializers-xml!
|
||||
activerecord-jdbc-adapter
|
||||
activerecord-jdbcsqlite3-adapter
|
||||
devise!
|
||||
jruby-openssl
|
||||
mocha (~> 1.1)
|
||||
oauth2
|
||||
omniauth (~> 1.3)
|
||||
omniauth-facebook
|
||||
omniauth-oauth2 (>= 1.2.0, < 1.5.0)
|
||||
omniauth-openid (~> 1.0.1)
|
||||
rails (= 5.0.0.beta3)
|
||||
rails-controller-testing
|
||||
rdoc
|
||||
responders (~> 2.1.1)
|
||||
sqlite3
|
||||
webrat (= 0.7.3)
|
||||
|
||||
BUNDLED WITH
|
||||
1.11.2
|
||||
@@ -2,29 +2,26 @@ source "https://rubygems.org"
|
||||
|
||||
gemspec path: ".."
|
||||
|
||||
gem "rails", "5.0.0.beta3"
|
||||
gem "omniauth", " ~>1.3"
|
||||
gem "oauth2"
|
||||
gem "omniauth-oauth2", ">= 1.2.0", "< 1.5.0"
|
||||
gem "rails", '~> 5.0.0'
|
||||
gem "omniauth"
|
||||
gem "omniauth-oauth2"
|
||||
gem "rdoc"
|
||||
|
||||
gem "activemodel-serializers-xml", github: "rails/activemodel-serializers-xml"
|
||||
|
||||
gem "rails-controller-testing"
|
||||
|
||||
gem "responders", "~> 2.1.1"
|
||||
gem "responders", "~> 2.1"
|
||||
|
||||
# TODO: Remove this line when Rails 5.0.3 is released
|
||||
gem "minitest", "< 5.10.2"
|
||||
|
||||
group :test do
|
||||
gem "omniauth-facebook"
|
||||
gem "omniauth-openid", "~> 1.0.1"
|
||||
gem "omniauth-openid"
|
||||
gem "webrat", "0.7.3", require: false
|
||||
gem "mocha", "~> 1.1", require: false
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
gem "activerecord-jdbc-adapter"
|
||||
gem "activerecord-jdbcsqlite3-adapter"
|
||||
gem "jruby-openssl"
|
||||
gem 'test_after_commit', require: false
|
||||
end
|
||||
|
||||
platforms :ruby do
|
||||
193
gemfiles/Gemfile.rails-5.0-stable.lock
Normal file
193
gemfiles/Gemfile.rails-5.0-stable.lock
Normal file
@@ -0,0 +1,193 @@
|
||||
GIT
|
||||
remote: git://github.com/rails/activemodel-serializers-xml.git
|
||||
revision: dd9c0acf26aab111ebc647cd8deb99ebc6946531
|
||||
specs:
|
||||
activemodel-serializers-xml (1.0.1)
|
||||
activemodel (> 5.x)
|
||||
activesupport (> 5.x)
|
||||
builder (~> 3.1)
|
||||
|
||||
PATH
|
||||
remote: ..
|
||||
specs:
|
||||
devise (4.3.0)
|
||||
bcrypt (~> 3.0)
|
||||
orm_adapter (~> 0.1)
|
||||
railties (>= 4.1.0, < 5.2)
|
||||
responders
|
||||
warden (~> 1.2.3)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actioncable (5.0.2)
|
||||
actionpack (= 5.0.2)
|
||||
nio4r (>= 1.2, < 3.0)
|
||||
websocket-driver (~> 0.6.1)
|
||||
actionmailer (5.0.2)
|
||||
actionpack (= 5.0.2)
|
||||
actionview (= 5.0.2)
|
||||
activejob (= 5.0.2)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
rails-dom-testing (~> 2.0)
|
||||
actionpack (5.0.2)
|
||||
actionview (= 5.0.2)
|
||||
activesupport (= 5.0.2)
|
||||
rack (~> 2.0)
|
||||
rack-test (~> 0.6.3)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
actionview (5.0.2)
|
||||
activesupport (= 5.0.2)
|
||||
builder (~> 3.1)
|
||||
erubis (~> 2.7.0)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
||||
activejob (5.0.2)
|
||||
activesupport (= 5.0.2)
|
||||
globalid (>= 0.3.6)
|
||||
activemodel (5.0.2)
|
||||
activesupport (= 5.0.2)
|
||||
activerecord (5.0.2)
|
||||
activemodel (= 5.0.2)
|
||||
activesupport (= 5.0.2)
|
||||
arel (~> 7.0)
|
||||
activesupport (5.0.2)
|
||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||
i18n (~> 0.7)
|
||||
minitest (~> 5.1)
|
||||
tzinfo (~> 1.1)
|
||||
arel (7.1.4)
|
||||
bcrypt (3.1.11)
|
||||
builder (3.2.3)
|
||||
concurrent-ruby (1.0.5)
|
||||
erubis (2.7.0)
|
||||
faraday (0.11.0)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
globalid (0.4.0)
|
||||
activesupport (>= 4.2.0)
|
||||
hashie (3.5.5)
|
||||
i18n (0.8.1)
|
||||
jwt (1.5.6)
|
||||
loofah (2.0.3)
|
||||
nokogiri (>= 1.5.9)
|
||||
mail (2.6.5)
|
||||
mime-types (>= 1.16, < 4)
|
||||
metaclass (0.0.4)
|
||||
method_source (0.8.2)
|
||||
mime-types (3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2016.0521)
|
||||
mini_portile2 (2.1.0)
|
||||
minitest (5.10.1)
|
||||
mocha (1.2.1)
|
||||
metaclass (~> 0.0.1)
|
||||
multi_json (1.12.1)
|
||||
multi_xml (0.6.0)
|
||||
multipart-post (2.0.0)
|
||||
nio4r (2.0.0)
|
||||
nokogiri (1.7.2)
|
||||
mini_portile2 (~> 2.1.0)
|
||||
oauth2 (1.3.1)
|
||||
faraday (>= 0.8, < 0.12)
|
||||
jwt (~> 1.0)
|
||||
multi_json (~> 1.3)
|
||||
multi_xml (~> 0.5)
|
||||
rack (>= 1.2, < 3)
|
||||
omniauth (1.6.1)
|
||||
hashie (>= 3.4.6, < 3.6.0)
|
||||
rack (>= 1.6.2, < 3)
|
||||
omniauth-facebook (4.0.0)
|
||||
omniauth-oauth2 (~> 1.2)
|
||||
omniauth-oauth2 (1.4.0)
|
||||
oauth2 (~> 1.0)
|
||||
omniauth (~> 1.2)
|
||||
omniauth-openid (1.0.1)
|
||||
omniauth (~> 1.0)
|
||||
rack-openid (~> 1.3.1)
|
||||
orm_adapter (0.5.0)
|
||||
rack (2.0.2)
|
||||
rack-openid (1.3.1)
|
||||
rack (>= 1.1.0)
|
||||
ruby-openid (>= 2.1.8)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
rails (5.0.2)
|
||||
actioncable (= 5.0.2)
|
||||
actionmailer (= 5.0.2)
|
||||
actionpack (= 5.0.2)
|
||||
actionview (= 5.0.2)
|
||||
activejob (= 5.0.2)
|
||||
activemodel (= 5.0.2)
|
||||
activerecord (= 5.0.2)
|
||||
activesupport (= 5.0.2)
|
||||
bundler (>= 1.3.0, < 2.0)
|
||||
railties (= 5.0.2)
|
||||
sprockets-rails (>= 2.0.0)
|
||||
rails-controller-testing (1.0.1)
|
||||
actionpack (~> 5.x)
|
||||
actionview (~> 5.x)
|
||||
activesupport (~> 5.x)
|
||||
rails-dom-testing (2.0.3)
|
||||
activesupport (>= 4.2.0)
|
||||
nokogiri (>= 1.6)
|
||||
rails-html-sanitizer (1.0.3)
|
||||
loofah (~> 2.0)
|
||||
railties (5.0.2)
|
||||
actionpack (= 5.0.2)
|
||||
activesupport (= 5.0.2)
|
||||
method_source
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rake (12.0.0)
|
||||
rdoc (5.1.0)
|
||||
responders (2.4.0)
|
||||
actionpack (>= 4.2.0, < 5.3)
|
||||
railties (>= 4.2.0, < 5.3)
|
||||
ruby-openid (2.7.0)
|
||||
sprockets (3.7.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (3.2.0)
|
||||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
sqlite3 (1.3.13)
|
||||
test_after_commit (1.1.0)
|
||||
activerecord (>= 3.2)
|
||||
thor (0.19.4)
|
||||
thread_safe (0.3.6)
|
||||
tzinfo (1.2.3)
|
||||
thread_safe (~> 0.1)
|
||||
warden (1.2.7)
|
||||
rack (>= 1.0)
|
||||
webrat (0.7.3)
|
||||
nokogiri (>= 1.2.0)
|
||||
rack (>= 1.0)
|
||||
rack-test (>= 0.5.3)
|
||||
websocket-driver (0.6.5)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
activemodel-serializers-xml!
|
||||
devise!
|
||||
minitest (< 5.10.2)
|
||||
mocha (~> 1.1)
|
||||
omniauth
|
||||
omniauth-facebook
|
||||
omniauth-oauth2
|
||||
omniauth-openid
|
||||
rails (~> 5.0.0)
|
||||
rails-controller-testing
|
||||
rdoc
|
||||
responders (~> 2.1)
|
||||
sqlite3
|
||||
test_after_commit
|
||||
webrat (= 0.7.3)
|
||||
|
||||
BUNDLED WITH
|
||||
1.14.6
|
||||
104
guides/bug_report_templates/integration_test.rb
Normal file
104
guides/bug_report_templates/integration_test.rb
Normal file
@@ -0,0 +1,104 @@
|
||||
begin
|
||||
require 'bundler/inline'
|
||||
rescue LoadError => e
|
||||
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
|
||||
raise e
|
||||
end
|
||||
|
||||
gemfile(true) do
|
||||
source 'https://rubygems.org'
|
||||
# Activate the gem you are reporting the issue against.
|
||||
gem 'rails', '~> 4.2.0'
|
||||
gem 'devise', '~> 4.0'
|
||||
gem 'sqlite3'
|
||||
gem 'byebug'
|
||||
end
|
||||
|
||||
require 'rack/test'
|
||||
require 'action_controller/railtie'
|
||||
require 'active_record'
|
||||
require 'devise/rails/routes'
|
||||
require 'devise/rails/warden_compat'
|
||||
|
||||
ActiveRecord::Base.establish_connection( adapter: :sqlite3, database: ':memory:')
|
||||
|
||||
class DeviseCreateUsers < ActiveRecord::Migration
|
||||
def change
|
||||
create_table(:users) do |t|
|
||||
t.string :email, null: false
|
||||
t.string :encrypted_password, null: true
|
||||
t.timestamps null: false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Devise.setup do |config|
|
||||
require 'devise/orm/active_record'
|
||||
config.secret_key = 'secret_key_base'
|
||||
end
|
||||
|
||||
class TestApp < Rails::Application
|
||||
config.root = File.dirname(__FILE__)
|
||||
config.session_store :cookie_store, key: 'cookie_store_key'
|
||||
secrets.secret_token = 'secret_token'
|
||||
secrets.secret_key_base = 'secret_key_base'
|
||||
config.eager_load = false
|
||||
|
||||
config.middleware.use Warden::Manager do |config|
|
||||
Devise.warden_config = config
|
||||
end
|
||||
|
||||
config.logger = Logger.new($stdout)
|
||||
Rails.logger = config.logger
|
||||
|
||||
end
|
||||
|
||||
Rails.application.initialize!
|
||||
|
||||
DeviseCreateUsers.migrate(:up)
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
devise :database_authenticatable
|
||||
end
|
||||
|
||||
Rails.application.routes.draw do
|
||||
devise_for :users
|
||||
|
||||
get '/' => 'test#index'
|
||||
end
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
class TestController < ApplicationController
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def index
|
||||
render plain: 'Home'
|
||||
end
|
||||
end
|
||||
|
||||
require 'minitest/autorun'
|
||||
|
||||
class BugTest < ActionDispatch::IntegrationTest
|
||||
include Rack::Test::Methods
|
||||
include Warden::Test::Helpers
|
||||
|
||||
def test_returns_success
|
||||
Warden.test_mode!
|
||||
|
||||
login_as User.create!(email: 'test@test.com', password: 'test123456', password_confirmation: 'test123456')
|
||||
|
||||
get '/'
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def app
|
||||
Rails.application
|
||||
end
|
||||
end
|
||||
@@ -39,13 +39,18 @@ module Devise
|
||||
autoload :Authenticatable, 'devise/strategies/authenticatable'
|
||||
end
|
||||
|
||||
module Test
|
||||
autoload :ControllerHelpers, 'devise/test/controller_helpers'
|
||||
autoload :IntegrationHelpers, 'devise/test/integration_helpers'
|
||||
end
|
||||
|
||||
# Constants which holds devise configuration for extensions. Those should
|
||||
# not be modified by the "end user" (this is why they are constants).
|
||||
ALL = []
|
||||
CONTROLLERS = ActiveSupport::OrderedHash.new
|
||||
ROUTES = ActiveSupport::OrderedHash.new
|
||||
STRATEGIES = ActiveSupport::OrderedHash.new
|
||||
URL_HELPERS = ActiveSupport::OrderedHash.new
|
||||
CONTROLLERS = {}
|
||||
ROUTES = {}
|
||||
STRATEGIES = {}
|
||||
URL_HELPERS = {}
|
||||
|
||||
# Strategies that do not require user input.
|
||||
NO_INPUT = []
|
||||
@@ -148,7 +153,11 @@ module Devise
|
||||
mattr_accessor :pepper
|
||||
@@pepper = nil
|
||||
|
||||
# Used to enable sending notification to user when their password is changed
|
||||
# Used to send notification to the original user email when their email is changed.
|
||||
mattr_accessor :send_email_changed_notification
|
||||
@@send_email_changed_notification = false
|
||||
|
||||
# Used to enable sending notification to user when their password is changed.
|
||||
mattr_accessor :send_password_change_notification
|
||||
@@send_password_change_notification = false
|
||||
|
||||
@@ -242,15 +251,22 @@ module Devise
|
||||
mattr_accessor :clean_up_csrf_token_on_authentication
|
||||
@@clean_up_csrf_token_on_authentication = true
|
||||
|
||||
# When false, Devise will not attempt to reload routes on eager load.
|
||||
# This can reduce the time taken to boot the app but if your application
|
||||
# requires the Devise mappings to be loaded during boot time the application
|
||||
# won't boot properly.
|
||||
mattr_accessor :reload_routes
|
||||
@@reload_routes = true
|
||||
|
||||
# PRIVATE CONFIGURATION
|
||||
|
||||
# Store scopes mappings.
|
||||
mattr_reader :mappings
|
||||
@@mappings = ActiveSupport::OrderedHash.new
|
||||
@@mappings = {}
|
||||
|
||||
# OmniAuth configurations.
|
||||
mattr_reader :omniauth_configs
|
||||
@@omniauth_configs = ActiveSupport::OrderedHash.new
|
||||
@@omniauth_configs = {}
|
||||
|
||||
# Define a set of modules that are called when a mapping is added.
|
||||
mattr_reader :helpers
|
||||
@@ -274,6 +290,14 @@ module Devise
|
||||
mattr_accessor :token_generator
|
||||
@@token_generator = nil
|
||||
|
||||
def self.rails51? # :nodoc:
|
||||
Rails.gem_version >= Gem::Version.new("5.1.x")
|
||||
end
|
||||
|
||||
def self.activerecord51? # :nodoc:
|
||||
defined?(ActiveRecord) && ActiveRecord.gem_version >= Gem::Version.new("5.1.x")
|
||||
end
|
||||
|
||||
# Default way to set up Devise. Run rails generate devise_install to create
|
||||
# a fresh initializer with all configuration values.
|
||||
def self.setup
|
||||
@@ -281,7 +305,7 @@ module Devise
|
||||
end
|
||||
|
||||
class Getter
|
||||
def initialize name
|
||||
def initialize(name)
|
||||
@name = name
|
||||
end
|
||||
|
||||
@@ -291,12 +315,8 @@ module Devise
|
||||
end
|
||||
|
||||
def self.ref(arg)
|
||||
if defined?(ActiveSupport::Dependencies::ClassCache)
|
||||
ActiveSupport::Dependencies::reference(arg)
|
||||
Getter.new(arg)
|
||||
else
|
||||
ActiveSupport::Dependencies.ref(arg)
|
||||
end
|
||||
ActiveSupport::Dependencies.reference(arg)
|
||||
Getter.new(arg)
|
||||
end
|
||||
|
||||
def self.available_router_name
|
||||
@@ -417,7 +437,6 @@ module Devise
|
||||
# config.omniauth :github, APP_ID, APP_SECRET
|
||||
#
|
||||
def self.omniauth(provider, *args)
|
||||
@@helpers << Devise::OmniAuth::UrlHelpers
|
||||
config = Devise::OmniAuth::Config.new(provider, args)
|
||||
@@omniauth_configs[config.strategy_name.to_sym] = config
|
||||
end
|
||||
|
||||
@@ -138,7 +138,7 @@ module Devise
|
||||
|
||||
# The main accessor for the warden proxy instance
|
||||
def warden
|
||||
request.env['warden']
|
||||
request.env['warden'] or raise MissingWarden
|
||||
end
|
||||
|
||||
# Return true if it's a devise_controller. false to all controllers unless
|
||||
@@ -277,4 +277,15 @@ module Devise
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class MissingWarden < StandardError
|
||||
def initialize
|
||||
super "Devise could not find the `Warden::Proxy` instance on your request environment.\n" + \
|
||||
"Make sure that your application is loading Devise and Warden as expected and that " + \
|
||||
"the `Warden::Manager` middleware is present in your middleware stack.\n" + \
|
||||
"If you are seeing this on one of your tests, ensure that your tests are either " + \
|
||||
"executing the Rails middleware stack or that your tests are using the `Devise::Test::ControllerHelpers` " + \
|
||||
"module to inject the `request.env['warden']` object for you."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ module Devise
|
||||
|
||||
# Remembers the given resource by setting up a cookie
|
||||
def remember_me(resource)
|
||||
return if env["devise.skip_storage"]
|
||||
return if request.env["devise.skip_storage"]
|
||||
scope = Devise::Mapping.find_scope!(resource)
|
||||
resource.remember_me!
|
||||
cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource)
|
||||
|
||||
@@ -12,20 +12,15 @@ module Devise
|
||||
end
|
||||
|
||||
# Sign in a user that already was authenticated. This helper is useful for logging
|
||||
# users in after sign up.
|
||||
#
|
||||
# All options given to sign_in is passed forward to the set_user method in warden.
|
||||
# The only exception is the :bypass option, which bypass warden callbacks and stores
|
||||
# the user straight in session. This option is useful in cases the user is already
|
||||
# signed in, but we want to refresh the credentials in session.
|
||||
# users in after sign up. All options given to sign_in is passed forward
|
||||
# to the set_user method in warden.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# 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)
|
||||
#
|
||||
def sign_in(resource_or_scope, *args)
|
||||
options = args.extract_options!
|
||||
@@ -35,6 +30,13 @@ module Devise
|
||||
expire_data_after_sign_in!
|
||||
|
||||
if options[:bypass]
|
||||
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc, caller)
|
||||
[Devise] bypass option is deprecated and it will be removed in future version of Devise.
|
||||
Please use bypass_sign_in method instead.
|
||||
Example:
|
||||
|
||||
bypass_sign_in(user)
|
||||
DEPRECATION
|
||||
warden.session_serializer.store(resource, scope)
|
||||
elsif warden.user(scope) == resource && !options.delete(:force)
|
||||
# Do nothing. User already signed in and we are not forcing it.
|
||||
@@ -44,6 +46,20 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
# Sign in a user bypassing the warden callbacks and stores the user
|
||||
# straight in session. This option is useful in cases the user is already
|
||||
# signed in, but we want to refresh the credentials in session.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# bypass_sign_in @user, scope: :user
|
||||
# bypass_sign_in @user
|
||||
def bypass_sign_in(resource, scope: nil)
|
||||
scope ||= Devise::Mapping.find_scope!(resource)
|
||||
expire_data_after_sign_in!
|
||||
warden.session_serializer.store(resource, scope)
|
||||
end
|
||||
|
||||
# Sign out a given user or scope. This helper is useful for signing out a user
|
||||
# after deleting accounts. Returns true if there was a logout and false if there
|
||||
# is no user logged in on the referred scope
|
||||
@@ -58,7 +74,6 @@ module Devise
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
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)
|
||||
instance_variable_set(:"@current_#{scope}", nil)
|
||||
|
||||
@@ -29,7 +29,7 @@ module Devise
|
||||
# Example:
|
||||
#
|
||||
# store_location_for(:user, dashboard_path)
|
||||
# redirect_to user_omniauth_authorize_path(:facebook)
|
||||
# redirect_to user_facebook_omniauth_authorize_path
|
||||
#
|
||||
def store_location_for(resource_or_scope, location)
|
||||
session_key = stored_location_key_for(resource_or_scope)
|
||||
|
||||
@@ -2,9 +2,9 @@ require "action_controller/metal"
|
||||
|
||||
module Devise
|
||||
# Failure application that will be called every time :warden is thrown from
|
||||
# any strategy or hook. Responsible for redirect the user to the sign in
|
||||
# page based on current scope and mapping. If no scope is given, redirect
|
||||
# to the default_url.
|
||||
# any strategy or hook. It is responsible for redirecting the user to the sign
|
||||
# in page based on current scope and mapping. If no scope is given, it
|
||||
# redirects to the default_url.
|
||||
class FailureApp < ActionController::Metal
|
||||
include ActionController::UrlFor
|
||||
include ActionController::Redirecting
|
||||
@@ -50,13 +50,11 @@ module Devise
|
||||
end
|
||||
|
||||
def recall
|
||||
config = Rails.application.config
|
||||
|
||||
header_info = if config.try(:relative_url_root)
|
||||
base_path = Pathname.new(config.relative_url_root)
|
||||
header_info = if relative_url_root?
|
||||
base_path = Pathname.new(relative_url_root)
|
||||
full_path = Pathname.new(attempted_path)
|
||||
|
||||
{ "SCRIPT_NAME" => config.relative_url_root,
|
||||
{ "SCRIPT_NAME" => relative_url_root,
|
||||
"PATH_INFO" => '/' + full_path.relative_path_from(base_path).to_s }
|
||||
else
|
||||
{ "PATH_INFO" => attempted_path }
|
||||
@@ -66,7 +64,7 @@ module Devise
|
||||
if request.respond_to?(:set_header)
|
||||
request.set_header(var, value)
|
||||
else
|
||||
env[var] = value
|
||||
request.env[var] = value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -135,18 +133,16 @@ module Devise
|
||||
|
||||
def scope_url
|
||||
opts = {}
|
||||
|
||||
# Initialize script_name with nil to prevent infinite loops in
|
||||
# authenticated mounted engines in rails 4.2 and 5.0
|
||||
opts[:script_name] = nil
|
||||
|
||||
route = route(scope)
|
||||
|
||||
opts[:format] = request_format unless skip_format?
|
||||
|
||||
config = Rails.application.config
|
||||
|
||||
if config.respond_to?(:relative_url_root)
|
||||
# Rails 4.2 goes into an infinite loop if opts[:script_name] is unset
|
||||
rails_4_2 = (Rails::VERSION::MAJOR >= 4) && (Rails::VERSION::MINOR >= 2)
|
||||
if config.relative_url_root.present? || rails_4_2
|
||||
opts[:script_name] = config.relative_url_root
|
||||
end
|
||||
end
|
||||
opts[:script_name] = relative_url_root if relative_url_root?
|
||||
|
||||
router_name = Devise.mappings[scope].router_name || Devise.available_router_name
|
||||
context = send(router_name)
|
||||
@@ -164,12 +160,12 @@ module Devise
|
||||
%w(html */*).include? request_format.to_s
|
||||
end
|
||||
|
||||
# Choose whether we should respond in a http authentication fashion,
|
||||
# Choose whether we should respond in an HTTP authentication fashion,
|
||||
# including 401 and optional headers.
|
||||
#
|
||||
# This method allows the user to explicitly disable http authentication
|
||||
# on ajax requests in case they want to redirect on failures instead of
|
||||
# handling the errors on their own. This is useful in case your ajax API
|
||||
# This method allows the user to explicitly disable HTTP authentication
|
||||
# on AJAX requests in case they want to redirect on failures instead of
|
||||
# handling the errors on their own. This is useful in case your AJAX API
|
||||
# is the same as your public API and uses a format like JSON (so you
|
||||
# cannot mark JSON as a navigational format).
|
||||
def http_auth?
|
||||
@@ -180,7 +176,7 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
# It does not make sense to send authenticate headers in ajax requests
|
||||
# It doesn't make sense to send authenticate headers in AJAX requests
|
||||
# or if the user disabled them.
|
||||
def http_auth_header?
|
||||
scope_class.http_authenticatable && !request.xhr?
|
||||
@@ -206,11 +202,11 @@ module Devise
|
||||
end
|
||||
|
||||
def warden
|
||||
request.respond_to?(:get_header) ? request.get_header("warden") : env["warden"]
|
||||
request.respond_to?(:get_header) ? request.get_header("warden") : request.env["warden"]
|
||||
end
|
||||
|
||||
def warden_options
|
||||
request.respond_to?(:get_header) ? request.get_header("warden.options") : env["warden.options"]
|
||||
request.respond_to?(:get_header) ? request.get_header("warden.options") : request.env["warden.options"]
|
||||
end
|
||||
|
||||
def warden_message
|
||||
@@ -229,10 +225,10 @@ module Devise
|
||||
warden_options[:attempted_path]
|
||||
end
|
||||
|
||||
# Stores requested uri to redirect the user after signing in. We cannot use
|
||||
# scoped session provided by warden here, since the user is not authenticated
|
||||
# yet, but we still need to store the uri based on scope, so different scopes
|
||||
# would never use the same uri to redirect.
|
||||
# Stores requested URI to redirect the user after signing in. We can't use
|
||||
# the scoped session provided by warden here, since the user is not
|
||||
# authenticated yet, but we still need to store the URI based on scope, so
|
||||
# different scopes would never use the same URI to redirect.
|
||||
def store_location!
|
||||
store_location_for(scope, attempted_path) if request.get? && !http_auth?
|
||||
end
|
||||
@@ -250,5 +246,17 @@ module Devise
|
||||
def request_format
|
||||
@request_format ||= request.format.try(:ref)
|
||||
end
|
||||
|
||||
def relative_url_root
|
||||
@relative_url_root ||= begin
|
||||
config = Rails.application.config
|
||||
|
||||
config.try(:relative_url_root) || config.action_controller.try(:relative_url_root)
|
||||
end
|
||||
end
|
||||
|
||||
def relative_url_root?
|
||||
relative_url_root.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
# This is only triggered when the user is explicitly set (with set_user)
|
||||
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?
|
||||
unless record.failed_attempts.to_i.zero?
|
||||
record.failed_attempts = 0
|
||||
record.save(validate: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ module Devise
|
||||
include Devise::Controllers::SignInOut
|
||||
|
||||
attr_reader :warden
|
||||
delegate :cookies, :env, to: :warden
|
||||
delegate :cookies, :request, to: :warden
|
||||
|
||||
def initialize(warden)
|
||||
@warden = warden
|
||||
|
||||
@@ -5,15 +5,16 @@ module Devise
|
||||
|
||||
included do
|
||||
include Devise::Controllers::ScopedViews
|
||||
attr_reader :scope_name, :resource
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
attr_reader :scope_name, :resource
|
||||
|
||||
# Configure default email options
|
||||
def devise_mail(record, action, opts={})
|
||||
def devise_mail(record, action, opts = {}, &block)
|
||||
initialize_from_record(record)
|
||||
mail headers_for(action, opts)
|
||||
mail headers_for(action, opts), &block
|
||||
end
|
||||
|
||||
def initialize_from_record(record)
|
||||
|
||||
@@ -12,7 +12,7 @@ module Devise
|
||||
|
||||
# Creates configuration values for Devise and for the given module.
|
||||
#
|
||||
# Devise::Models.config(Devise::DatabaseAuthenticatable, :stretches)
|
||||
# Devise::Models.config(Devise::Models::DatabaseAuthenticatable, :stretches)
|
||||
#
|
||||
# The line above creates:
|
||||
#
|
||||
|
||||
@@ -114,6 +114,15 @@ module Devise
|
||||
super(options)
|
||||
end
|
||||
|
||||
# Redefine inspect using serializable_hash, to ensure we don't accidentally
|
||||
# leak passwords into exceptions.
|
||||
def inspect
|
||||
inspection = serializable_hash.collect do |k,v|
|
||||
"#{k}: #{respond_to?(:attribute_for_inspect) ? attribute_for_inspect(k) : v.inspect}"
|
||||
end
|
||||
"#<#{self.class} #{inspection.join(", ")}>"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def devise_mailer
|
||||
@@ -143,13 +152,25 @@ module Devise
|
||||
# if new_record? || changed?
|
||||
# pending_notifications << [notification, args]
|
||||
# else
|
||||
# devise_mailer.send(notification, self, *args).deliver
|
||||
# message = devise_mailer.send(notification, self, *args)
|
||||
# Remove once we move to Rails 4.2+ only.
|
||||
# if message.respond_to?(:deliver_now)
|
||||
# message.deliver_now
|
||||
# else
|
||||
# message.deliver
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def send_pending_notifications
|
||||
# pending_notifications.each do |notification, args|
|
||||
# devise_mailer.send(notification, self, *args).deliver
|
||||
# message = devise_mailer.send(notification, self, *args)
|
||||
# Remove once we move to Rails 4.2+ only.
|
||||
# if message.respond_to?(:deliver_now)
|
||||
# message.deliver_now
|
||||
# else
|
||||
# message.deliver
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# # Empty the pending notifications array because the
|
||||
|
||||
@@ -26,7 +26,9 @@ module Devise
|
||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||
# db field to be set up (t.reconfirmable in migrations). Until confirmed, new email is
|
||||
# stored in unconfirmed email column, and copied to email column on successful
|
||||
# confirmation.
|
||||
# confirmation. Also, when used in conjunction with `send_email_changed_notification`,
|
||||
# the notification is sent to the original email when the change is requested,
|
||||
# not when the unconfirmed email is confirmed.
|
||||
# * +confirm_within+: the time before a sent confirmation token becomes invalid.
|
||||
# You can use this to force the user to confirm within a set period of time.
|
||||
# Confirmable will not generate a new token if a repeat confirmation is requested
|
||||
@@ -43,7 +45,7 @@ module Devise
|
||||
|
||||
included do
|
||||
before_create :generate_confirmation_token, if: :confirmation_required?
|
||||
after_create :skip_reconfirmation!, if: :send_confirmation_notification?
|
||||
after_create :skip_reconfirmation_in_callback!, if: :send_confirmation_notification?
|
||||
if respond_to?(:after_commit) # ActiveRecord
|
||||
after_commit :send_on_create_confirmation_instructions, on: :create, if: :send_confirmation_notification?
|
||||
after_commit :send_reconfirmation_instructions, on: :update, if: :reconfirmation_required?
|
||||
@@ -56,6 +58,7 @@ module Devise
|
||||
|
||||
def initialize(*args, &block)
|
||||
@bypass_confirmation_postpone = false
|
||||
@skip_reconfirmation_in_callback = false
|
||||
@reconfirmation_required = false
|
||||
@skip_confirmation_notification = false
|
||||
@raw_confirmation_token = nil
|
||||
@@ -97,11 +100,6 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
def confirm!(args={})
|
||||
ActiveSupport::Deprecation.warn "confirm! is deprecated in favor of confirm"
|
||||
confirm(args)
|
||||
end
|
||||
|
||||
# Verifies whether a user is confirmed or not
|
||||
def confirmed?
|
||||
!!confirmed_at
|
||||
@@ -170,6 +168,12 @@ module Devise
|
||||
|
||||
protected
|
||||
|
||||
# To not require reconfirmation after creating with #save called in a
|
||||
# callback call skip_create_confirmation!
|
||||
def skip_reconfirmation_in_callback!
|
||||
@skip_reconfirmation_in_callback = true
|
||||
end
|
||||
|
||||
# A callback method used to deliver confirmation
|
||||
# instructions on creation. This can be overridden
|
||||
# in models to map to a nice sign up e-mail.
|
||||
@@ -221,7 +225,7 @@ module Devise
|
||||
# confirmation_period_expired? # will always return false
|
||||
#
|
||||
def confirmation_period_expired?
|
||||
self.class.confirm_within && self.confirmation_sent_at && (Time.now > self.confirmation_sent_at + self.class.confirm_within)
|
||||
self.class.confirm_within && self.confirmation_sent_at && (Time.now.utc > self.confirmation_sent_at.utc + self.class.confirm_within)
|
||||
end
|
||||
|
||||
# Checks whether the record requires any confirmation.
|
||||
@@ -249,18 +253,44 @@ module Devise
|
||||
generate_confirmation_token && save(validate: false)
|
||||
end
|
||||
|
||||
def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
|
||||
@reconfirmation_required = true
|
||||
self.unconfirmed_email = self.email
|
||||
self.email = self.email_was
|
||||
self.confirmation_token = nil
|
||||
generate_confirmation_token
|
||||
if Devise.activerecord51?
|
||||
def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
|
||||
@reconfirmation_required = true
|
||||
self.unconfirmed_email = self.email
|
||||
self.email = self.email_in_database
|
||||
self.confirmation_token = nil
|
||||
generate_confirmation_token
|
||||
end
|
||||
else
|
||||
def postpone_email_change_until_confirmation_and_regenerate_confirmation_token
|
||||
@reconfirmation_required = true
|
||||
self.unconfirmed_email = self.email
|
||||
self.email = self.email_was
|
||||
self.confirmation_token = nil
|
||||
generate_confirmation_token
|
||||
end
|
||||
end
|
||||
|
||||
def postpone_email_change?
|
||||
postpone = self.class.reconfirmable && email_changed? && !@bypass_confirmation_postpone && self.email.present?
|
||||
@bypass_confirmation_postpone = false
|
||||
postpone
|
||||
if Devise.activerecord51?
|
||||
def postpone_email_change?
|
||||
postpone = self.class.reconfirmable &&
|
||||
will_save_change_to_email? &&
|
||||
!@bypass_confirmation_postpone &&
|
||||
self.email.present? &&
|
||||
(!@skip_reconfirmation_in_callback || !self.email_in_database.nil?)
|
||||
@bypass_confirmation_postpone = false
|
||||
postpone
|
||||
end
|
||||
else
|
||||
def postpone_email_change?
|
||||
postpone = self.class.reconfirmable &&
|
||||
email_changed? &&
|
||||
!@bypass_confirmation_postpone &&
|
||||
self.email.present? &&
|
||||
(!@skip_reconfirmation_in_callback || !self.email_was.nil?)
|
||||
@bypass_confirmation_postpone = false
|
||||
postpone
|
||||
end
|
||||
end
|
||||
|
||||
def reconfirmation_required?
|
||||
@@ -271,6 +301,16 @@ module Devise
|
||||
confirmation_required? && !@skip_confirmation_notification && self.email.present?
|
||||
end
|
||||
|
||||
# With reconfirmable, notify the original email when the user first
|
||||
# requests the email change, instead of when the change is confirmed.
|
||||
def send_email_changed_notification?
|
||||
if self.class.reconfirmable
|
||||
self.class.send_email_changed_notification && reconfirmation_required?
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# A callback initiated after successfully confirming. This can be
|
||||
# used to insert your own logic that is only run after the user successfully
|
||||
# confirms.
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
require 'devise/strategies/database_authenticatable'
|
||||
|
||||
module Devise
|
||||
def self.bcrypt(klass, password)
|
||||
ActiveSupport::Deprecation.warn "Devise.bcrypt is deprecated; use Devise::Encryptor.digest instead"
|
||||
Devise::Encryptor.digest(klass, password)
|
||||
end
|
||||
|
||||
module Models
|
||||
# Authenticatable Module, responsible for hashing the password and
|
||||
# validating the authenticity of a user while signing in.
|
||||
@@ -19,6 +14,10 @@ module Devise
|
||||
#
|
||||
# * +stretches+: the cost given to bcrypt.
|
||||
#
|
||||
# * +send_email_changed_notification+: notify original email when it changes.
|
||||
#
|
||||
# * +send_password_change_notification+: notify email when password changes.
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# User.find(1).valid_password?('password123') # returns true/false
|
||||
@@ -27,6 +26,7 @@ module Devise
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
after_update :send_email_changed_notification, if: :send_email_changed_notification?
|
||||
after_update :send_password_change_notification, if: :send_password_change_notification?
|
||||
|
||||
attr_reader :password, :current_password
|
||||
@@ -137,6 +137,19 @@ module Devise
|
||||
encrypted_password[0,29] if encrypted_password
|
||||
end
|
||||
|
||||
if Devise.activerecord51?
|
||||
# Send notification to user when email changes.
|
||||
def send_email_changed_notification
|
||||
send_devise_notification(:email_changed, to: email_before_last_save)
|
||||
end
|
||||
else
|
||||
# Send notification to user when email changes.
|
||||
def send_email_changed_notification
|
||||
send_devise_notification(:email_changed, to: email_was)
|
||||
end
|
||||
end
|
||||
|
||||
# Send notification to user when password changes.
|
||||
def send_password_change_notification
|
||||
send_devise_notification(:password_change)
|
||||
end
|
||||
@@ -152,12 +165,28 @@ module Devise
|
||||
Devise::Encryptor.digest(self.class, password)
|
||||
end
|
||||
|
||||
def send_password_change_notification?
|
||||
self.class.send_password_change_notification && encrypted_password_changed?
|
||||
if Devise.activerecord51?
|
||||
def send_email_changed_notification?
|
||||
self.class.send_email_changed_notification && saved_change_to_email?
|
||||
end
|
||||
else
|
||||
def send_email_changed_notification?
|
||||
self.class.send_email_changed_notification && email_changed?
|
||||
end
|
||||
end
|
||||
|
||||
if Devise.activerecord51?
|
||||
def send_password_change_notification?
|
||||
self.class.send_password_change_notification && saved_change_to_encrypted_password?
|
||||
end
|
||||
else
|
||||
def send_password_change_notification?
|
||||
self.class.send_password_change_notification && encrypted_password_changed?
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
Devise::Models.config(self, :pepper, :stretches, :send_password_change_notification)
|
||||
Devise::Models.config(self, :pepper, :stretches, :send_email_changed_notification, :send_password_change_notification)
|
||||
|
||||
# We assume this method already gets the sanitized values from the
|
||||
# DatabaseAuthenticatable strategy. If you are using this method on
|
||||
|
||||
@@ -27,30 +27,20 @@ module Devise
|
||||
end
|
||||
|
||||
included do
|
||||
before_update do
|
||||
if (respond_to?(:email_changed?) && email_changed?) || encrypted_password_changed?
|
||||
clear_reset_password_token
|
||||
end
|
||||
end
|
||||
before_update :clear_reset_password_token, if: :clear_reset_password_token?
|
||||
end
|
||||
|
||||
# Update password saving the record and clearing token. Returns true if
|
||||
# the passwords are valid and the record was saved, false otherwise.
|
||||
def reset_password(new_password, new_password_confirmation)
|
||||
self.password = new_password
|
||||
self.password_confirmation = new_password_confirmation
|
||||
|
||||
if respond_to?(:after_password_reset) && valid?
|
||||
ActiveSupport::Deprecation.warn "after_password_reset is deprecated"
|
||||
after_password_reset
|
||||
if new_password.present?
|
||||
self.password = new_password
|
||||
self.password_confirmation = new_password_confirmation
|
||||
save
|
||||
else
|
||||
errors.add(:password, :blank)
|
||||
false
|
||||
end
|
||||
|
||||
save
|
||||
end
|
||||
|
||||
def reset_password!(new_password, new_password_confirmation)
|
||||
ActiveSupport::Deprecation.warn "reset_password! is deprecated in favor of reset_password"
|
||||
reset_password(new_password, new_password_confirmation)
|
||||
end
|
||||
|
||||
# Resets reset password token and send reset password instructions by email.
|
||||
@@ -107,6 +97,26 @@ module Devise
|
||||
send_devise_notification(:reset_password_instructions, token, {})
|
||||
end
|
||||
|
||||
if Devise.activerecord51?
|
||||
def clear_reset_password_token?
|
||||
encrypted_password_changed = respond_to?(:will_save_change_to_encrypted_password?) && will_save_change_to_encrypted_password?
|
||||
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
|
||||
respond_to?("will_save_change_to_#{attribute}?") && send("will_save_change_to_#{attribute}?")
|
||||
end
|
||||
|
||||
authentication_keys_changed || encrypted_password_changed
|
||||
end
|
||||
else
|
||||
def clear_reset_password_token?
|
||||
encrypted_password_changed = respond_to?(:encrypted_password_changed?) && encrypted_password_changed?
|
||||
authentication_keys_changed = self.class.authentication_keys.any? do |attribute|
|
||||
respond_to?("#{attribute}_changed?") && send("#{attribute}_changed?")
|
||||
end
|
||||
|
||||
authentication_keys_changed || encrypted_password_changed
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
# Attempt to find a user by password reset token. If a user is found, return it
|
||||
# If a user is not found, return nil
|
||||
|
||||
@@ -46,7 +46,7 @@ module Devise
|
||||
end
|
||||
|
||||
def remember_me!
|
||||
self.remember_token = self.class.remember_token if respond_to?(:remember_token)
|
||||
self.remember_token ||= self.class.remember_token if respond_to?(:remember_token)
|
||||
self.remember_created_at ||= Time.now.utc
|
||||
save(validate: false) if self.changed?
|
||||
end
|
||||
@@ -74,7 +74,7 @@ module Devise
|
||||
elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt.presence)
|
||||
salt
|
||||
else
|
||||
raise "authenticable_salt returned nil for the #{self.class.name} model. " \
|
||||
raise "authenticatable_salt returned nil for the #{self.class.name} model. " \
|
||||
"In order to use rememberable, you must ensure a password is always set " \
|
||||
"or have a remember_token column in your model or implement your own " \
|
||||
"rememberable_value in the model with custom logic."
|
||||
|
||||
@@ -27,8 +27,13 @@ module Devise
|
||||
|
||||
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?
|
||||
if Devise.activerecord51?
|
||||
validates_uniqueness_of :email, allow_blank: true, if: :will_save_change_to_email?
|
||||
validates_format_of :email, with: email_regexp, allow_blank: true, if: :will_save_change_to_email?
|
||||
else
|
||||
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
|
||||
validates_format_of :email, with: email_regexp, allow_blank: true, if: :email_changed?
|
||||
end
|
||||
|
||||
validates_presence_of :password, if: :password_required?
|
||||
validates_confirmation_of :password, if: :password_required?
|
||||
|
||||
@@ -1,57 +1,6 @@
|
||||
module Devise
|
||||
module OmniAuth
|
||||
module UrlHelpers
|
||||
def self.define_helpers(mapping)
|
||||
return unless mapping.omniauthable?
|
||||
|
||||
mapping = mapping.name
|
||||
|
||||
class_eval do
|
||||
define_method("#{mapping}_omniauth_authorize_path") do |provider, *args|
|
||||
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc)
|
||||
[Devise] #{mapping}_omniauth_authorize_path(#{provider.inspect}) is deprecated and it will be removed from Devise 4.2.
|
||||
|
||||
Please use #{mapping}_#{provider}_omniauth_authorize_path instead.
|
||||
DEPRECATION
|
||||
send("#{mapping}_#{provider}_omniauth_authorize_path", *args)
|
||||
end
|
||||
|
||||
define_method("#{mapping}_omniauth_authorize_url") do |provider, *args|
|
||||
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc)
|
||||
[Devise] #{mapping}_omniauth_authorize_url(#{provider.inspect}) is deprecated and it will be removed from Devise 4.2.
|
||||
|
||||
Please use #{mapping}_#{provider}_omniauth_authorize_url instead.
|
||||
DEPRECATION
|
||||
send("#{mapping}_#{provider}_omniauth_authorize_url", *args)
|
||||
end
|
||||
|
||||
define_method("#{mapping}_omniauth_callback_path") do |provider, *args|
|
||||
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc)
|
||||
[Devise] #{mapping}_omniauth_callback_path(#{provider.inspect}) is deprecated and it will be removed from Devise 4.2.
|
||||
|
||||
Please use #{mapping}_#{provider}_omniauth_callback_path instead.
|
||||
DEPRECATION
|
||||
send("#{mapping}_#{provider}_omniauth_callback_path", *args)
|
||||
end
|
||||
|
||||
define_method("#{mapping}_omniauth_callback_url") do |provider, *args|
|
||||
ActiveSupport::Deprecation.warn(<<-DEPRECATION.strip_heredoc)
|
||||
[Devise] #{mapping}_omniauth_callback_url(#{provider.inspect}) is deprecated and it will be removed from Devise 4.2.
|
||||
|
||||
Please use #{mapping}_#{provider}_omniauth_callback_url instead.
|
||||
DEPRECATION
|
||||
send("#{mapping}_#{provider}_omniauth_callback_url", *args)
|
||||
end
|
||||
end
|
||||
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
if respond_to?(:helper_method)
|
||||
helper_method "#{mapping}_omniauth_authorize_path", "#{mapping}_omniauth_authorize_url"
|
||||
helper_method "#{mapping}_omniauth_callback_path", "#{mapping}_omniauth_callback_url"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def omniauth_authorize_path(resource_or_scope, provider, *args)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
_devise_route_context.send("#{scope}_#{provider}_omniauth_authorize_path", *args)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require 'orm_adapter/adapters/active_record'
|
||||
|
||||
ActiveRecord::Base.extend Devise::Models
|
||||
ActiveSupport.on_load(:active_record) do
|
||||
extend Devise::Models
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require 'orm_adapter/adapters/mongoid'
|
||||
ActiveSupport.on_load(:mongoid) do
|
||||
require 'orm_adapter/adapters/mongoid'
|
||||
|
||||
Mongoid::Document::ClassMethods.send :include, Devise::Models
|
||||
Mongoid::Document::ClassMethods.send :include, Devise::Models
|
||||
end
|
||||
|
||||
@@ -68,12 +68,6 @@ module Devise
|
||||
def sanitize(action)
|
||||
permissions = @permitted[action]
|
||||
|
||||
# DEPRECATED: Remove this branch on Devise 4.2.
|
||||
if respond_to?(action, true)
|
||||
deprecate_instance_method_sanitization(action)
|
||||
return cast_to_hash send(action)
|
||||
end
|
||||
|
||||
if permissions.respond_to?(:call)
|
||||
cast_to_hash permissions.call(default_params)
|
||||
elsif permissions.present?
|
||||
@@ -127,17 +121,6 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
# DEPRECATED: Remove this method on Devise 4.2.
|
||||
def for(action, &block) # :nodoc:
|
||||
if block_given?
|
||||
deprecate_for_with_block(action)
|
||||
permit(action, &block)
|
||||
else
|
||||
deprecate_for_without_block(action)
|
||||
@permitted[action] or unknown_action!(action)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Cast a sanitized +ActionController::Parameters+ to a +HashWithIndifferentAccess+
|
||||
@@ -172,43 +155,5 @@ module Devise
|
||||
devise_parameter_sanitizer.permit(:#{action}, keys: [:param1, :param2, :param3])
|
||||
MESSAGE
|
||||
end
|
||||
|
||||
def deprecate_for_with_block(action)
|
||||
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
|
||||
[Devise] Changing the sanitized parameters through "#{self.class.name}#for(#{action}) is deprecated and it will be removed from Devise 4.2.
|
||||
Please use the `permit` method:
|
||||
|
||||
devise_parameter_sanitizer.permit(:#{action}) do |user|
|
||||
# Your block here.
|
||||
end
|
||||
MESSAGE
|
||||
end
|
||||
|
||||
def deprecate_for_without_block(action)
|
||||
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
|
||||
[Devise] Changing the sanitized parameters through "#{self.class.name}#for(#{action}) is deprecated and it will be removed from Devise 4.2.
|
||||
Please use the `permit` method to add or remove any key:
|
||||
|
||||
To add any new key, use the `keys` keyword argument:
|
||||
devise_parameter_sanitizer.permit(:#{action}, keys: [:param1, :param2, :param3])
|
||||
|
||||
To remove any existing key, use the `except` keyword argument:
|
||||
devise_parameter_sanitizer.permit(:#{action}, except: [:email])
|
||||
MESSAGE
|
||||
end
|
||||
|
||||
def deprecate_instance_method_sanitization(action)
|
||||
ActiveSupport::Deprecation.warn(<<-MESSAGE.strip_heredoc)
|
||||
[Devise] Parameter sanitization through a "#{self.class.name}##{action}" method is deprecated and it will be removed from Devise 4.2.
|
||||
Please use the `permit` method on your sanitizer `initialize` method.
|
||||
|
||||
class #{self.class.name} < Devise::ParameterSanitizer
|
||||
def initialize(*)
|
||||
super
|
||||
permit(:#{action}, keys: [:param1, :param2, :param3])
|
||||
end
|
||||
end
|
||||
MESSAGE
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,9 @@ module Devise
|
||||
end
|
||||
|
||||
# Force routes to be loaded if we are doing any eager load.
|
||||
config.before_eager_load { |app| app.reload_routes! }
|
||||
config.before_eager_load do |app|
|
||||
app.reload_routes! if Devise.reload_routes
|
||||
end
|
||||
|
||||
initializer "devise.url_helpers" do
|
||||
Devise.include_helpers(Devise::Controllers)
|
||||
|
||||
@@ -338,7 +338,7 @@ module ActionDispatch::Routing
|
||||
|
||||
# Sets the devise scope to be used in the controller. If you have custom routes,
|
||||
# you are required to call this method (also aliased as :as) in order to specify
|
||||
# to which controller it is targetted.
|
||||
# to which controller it is targeted.
|
||||
#
|
||||
# as :user do
|
||||
# get "sign_in", to: "devise/sessions#new"
|
||||
|
||||
162
lib/devise/test/controller_helpers.rb
Normal file
162
lib/devise/test/controller_helpers.rb
Normal file
@@ -0,0 +1,162 @@
|
||||
module Devise
|
||||
module Test
|
||||
# `Devise::Test::ControllerHelpers` provides a facility to test controllers
|
||||
# in isolation when using `ActionController::TestCase` allowing you to
|
||||
# quickly sign_in or sign_out a user. Do not use
|
||||
# `Devise::Test::ControllerHelpers` in integration tests.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# class PostsTest < ActionController::TestCase
|
||||
# include Devise::Test::ControllerHelpers
|
||||
#
|
||||
# test 'authenticated users can GET index' do
|
||||
# sign_in users(:bob)
|
||||
#
|
||||
# get :index
|
||||
# assert_response :success
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Important: you should not test Warden specific behavior (like callbacks)
|
||||
# using `Devise::Test::ControllerHelpers` since it is a stub of the actual
|
||||
# behavior. Such callbacks should be tested in your integration suite instead.
|
||||
module ControllerHelpers
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
setup :setup_controller_for_warden, :warden
|
||||
end
|
||||
|
||||
# Override process to consider warden.
|
||||
def process(*)
|
||||
_catch_warden { super }
|
||||
|
||||
@response
|
||||
end
|
||||
|
||||
# We need to set up the environment variables and the response in the controller.
|
||||
def setup_controller_for_warden #:nodoc:
|
||||
@request.env['action_controller.instance'] = @controller
|
||||
end
|
||||
|
||||
# Quick access to Warden::Proxy.
|
||||
def warden #:nodoc:
|
||||
@request.env['warden'] ||= begin
|
||||
manager = Warden::Manager.new(nil) do |config|
|
||||
config.merge! Devise.warden_config
|
||||
end
|
||||
Warden::Proxy.new(@request.env, manager)
|
||||
end
|
||||
end
|
||||
|
||||
# sign_in a given resource by storing its keys in the session.
|
||||
# This method bypass any warden authentication callback.
|
||||
#
|
||||
# * +resource+ - The resource that should be authenticated
|
||||
# * +scope+ - An optional +Symbol+ with the scope where the resource
|
||||
# should be signed in with.
|
||||
# Examples:
|
||||
#
|
||||
# sign_in users(:alice)
|
||||
# sign_in users(:alice), scope: :admin
|
||||
def sign_in(resource, deprecated = nil, scope: nil)
|
||||
if deprecated.present?
|
||||
scope = resource
|
||||
resource = deprecated
|
||||
|
||||
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
|
||||
[Devise] sign_in(:#{scope}, resource) on controller tests is deprecated and will be removed from Devise.
|
||||
Please use sign_in(resource, scope: :#{scope}) instead.
|
||||
DEPRECATION
|
||||
end
|
||||
|
||||
scope ||= Devise::Mapping.find_scope!(resource)
|
||||
|
||||
warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.store(resource, scope)
|
||||
end
|
||||
|
||||
# Sign out a given resource or scope by calling logout on Warden.
|
||||
# This method bypass any warden logout callback.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_out :user # sign_out(scope)
|
||||
# sign_out @user # sign_out(resource)
|
||||
#
|
||||
def sign_out(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
@controller.instance_variable_set(:"@current_#{scope}", nil)
|
||||
user = warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.delete(scope, user)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Catch warden continuations and handle like the middleware would.
|
||||
# Returns nil when interrupted, otherwise the normal result of the block.
|
||||
def _catch_warden(&block)
|
||||
result = catch(:warden, &block)
|
||||
|
||||
env = @controller.request.env
|
||||
|
||||
result ||= {}
|
||||
|
||||
# Set the response. In production, the rack result is returned
|
||||
# from Warden::Manager#call, which the following is modelled on.
|
||||
case result
|
||||
when Array
|
||||
if result.first == 401 && intercept_401?(env) # does this happen during testing?
|
||||
_process_unauthenticated(env)
|
||||
else
|
||||
result
|
||||
end
|
||||
when Hash
|
||||
_process_unauthenticated(env, result)
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def _process_unauthenticated(env, options = {})
|
||||
options[:action] ||= :unauthenticated
|
||||
proxy = request.env['warden']
|
||||
result = options[:result] || proxy.result
|
||||
|
||||
ret = case result
|
||||
when :redirect
|
||||
body = proxy.message || "You are being redirected to #{proxy.headers['Location']}"
|
||||
[proxy.status, proxy.headers, [body]]
|
||||
when :custom
|
||||
proxy.custom_response
|
||||
else
|
||||
request.env["PATH_INFO"] = "/#{options[:action]}"
|
||||
request.env["warden.options"] = options
|
||||
Warden::Manager._run_callbacks(:before_failure, env, options)
|
||||
|
||||
status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
|
||||
@controller.response.headers.merge!(headers)
|
||||
@controller.status = status
|
||||
@controller.response.body = response.body
|
||||
nil # causes process return @response
|
||||
end
|
||||
|
||||
# ensure that the controller response is set up. In production, this is
|
||||
# not necessary since warden returns the results to rack. However, at
|
||||
# testing time, we want the response to be available to the testing
|
||||
# framework to verify what would be returned to rack.
|
||||
if ret.is_a?(Array)
|
||||
status, headers, body = *ret
|
||||
# ensure the controller response is set to our response.
|
||||
@controller.response ||= @response
|
||||
@response.status = status
|
||||
@response.headers.merge!(headers)
|
||||
@response.body = body
|
||||
end
|
||||
|
||||
ret
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
61
lib/devise/test/integration_helpers.rb
Normal file
61
lib/devise/test/integration_helpers.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
module Devise
|
||||
# Devise::Test::IntegrationHelpers is a helper module for facilitating
|
||||
# authentication on Rails integration tests to bypass the required steps for
|
||||
# signin in or signin out a record.
|
||||
#
|
||||
# Examples
|
||||
#
|
||||
# class PostsTest < ActionDispatch::IntegrationTest
|
||||
# include Devise::Test::IntegrationHelpers
|
||||
#
|
||||
# test 'authenticated users can see posts' do
|
||||
# sign_in users(:bob)
|
||||
#
|
||||
# get '/posts'
|
||||
# assert_response :success
|
||||
# end
|
||||
# end
|
||||
module Test
|
||||
module IntegrationHelpers
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
include Warden::Test::Helpers
|
||||
|
||||
setup :setup_integration_for_devise
|
||||
teardown :teardown_integration_for_devise
|
||||
end
|
||||
end
|
||||
|
||||
# Signs in a specific resource, mimicking a successfull sign in
|
||||
# operation through +Devise::SessionsController#create+.
|
||||
#
|
||||
# * +resource+ - The resource that should be authenticated
|
||||
# * +scope+ - An optional +Symbol+ with the scope where the resource
|
||||
# should be signed in with.
|
||||
def sign_in(resource, scope: nil)
|
||||
scope ||= Devise::Mapping.find_scope!(resource)
|
||||
|
||||
login_as(resource, scope: scope)
|
||||
end
|
||||
|
||||
# Signs out a specific scope from the session.
|
||||
#
|
||||
# * +resource_or_scope+ - The resource or scope that should be signed out.
|
||||
def sign_out(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
|
||||
logout scope
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def setup_integration_for_devise
|
||||
Warden.test_mode!
|
||||
end
|
||||
|
||||
def teardown_integration_for_devise
|
||||
Warden.test_reset!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,137 +1,13 @@
|
||||
module Devise
|
||||
# Devise::TestHelpers provides a facility to test controllers in isolation
|
||||
# when using ActionController::TestCase allowing you to quickly sign_in or
|
||||
# sign_out a user. Do not use Devise::TestHelpers in integration tests.
|
||||
#
|
||||
# Notice you should not test Warden specific behavior (like Warden callbacks)
|
||||
# using Devise::TestHelpers since it is a stub of the actual behavior. Such
|
||||
# callbacks should be tested in your integration suite instead.
|
||||
module TestHelpers
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
setup :setup_controller_for_warden, :warden if respond_to?(:setup)
|
||||
ActiveSupport::Deprecation.warn <<-DEPRECATION.strip_heredoc
|
||||
[Devise] including `Devise::TestHelpers` is deprecated and will be removed from Devise.
|
||||
For controller tests, please include `Devise::Test::ControllerHelpers` instead.
|
||||
DEPRECATION
|
||||
include Devise::Test::ControllerHelpers
|
||||
end
|
||||
end
|
||||
|
||||
# Override process to consider warden.
|
||||
def process(*)
|
||||
# Make sure we always return @response, a la ActionController::TestCase::Behaviour#process, even if warden interrupts
|
||||
_catch_warden { super } # || @response # _catch_warden will setup the @response object
|
||||
|
||||
# process needs to return the ActionDispath::TestResponse object
|
||||
@response
|
||||
end
|
||||
|
||||
# We need to set up the environment variables and the response in the controller.
|
||||
def setup_controller_for_warden #:nodoc:
|
||||
@request.env['action_controller.instance'] = @controller
|
||||
end
|
||||
|
||||
# Quick access to Warden::Proxy.
|
||||
def warden #:nodoc:
|
||||
@request.env['warden'] ||= begin
|
||||
manager = Warden::Manager.new(nil) do |config|
|
||||
config.merge! Devise.warden_config
|
||||
end
|
||||
Warden::Proxy.new(@request.env, manager)
|
||||
end
|
||||
end
|
||||
|
||||
# sign_in a given resource by storing its keys in the session.
|
||||
# This method bypass any warden authentication callback.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_in :user, @user # sign_in(scope, resource)
|
||||
# sign_in @user # sign_in(resource)
|
||||
#
|
||||
def sign_in(resource_or_scope, resource=nil)
|
||||
scope ||= Devise::Mapping.find_scope!(resource_or_scope)
|
||||
resource ||= resource_or_scope
|
||||
warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.store(resource, scope)
|
||||
end
|
||||
|
||||
# Sign out a given resource or scope by calling logout on Warden.
|
||||
# This method bypass any warden logout callback.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# sign_out :user # sign_out(scope)
|
||||
# sign_out @user # sign_out(resource)
|
||||
#
|
||||
def sign_out(resource_or_scope)
|
||||
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
||||
@controller.instance_variable_set(:"@current_#{scope}", nil)
|
||||
user = warden.instance_variable_get(:@users).delete(scope)
|
||||
warden.session_serializer.delete(scope, user)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Catch warden continuations and handle like the middleware would.
|
||||
# Returns nil when interrupted, otherwise the normal result of the block.
|
||||
def _catch_warden(&block)
|
||||
result = catch(:warden, &block)
|
||||
|
||||
env = @controller.request.env
|
||||
|
||||
result ||= {}
|
||||
|
||||
# Set the response. In production, the rack result is returned
|
||||
# from Warden::Manager#call, which the following is modelled on.
|
||||
case result
|
||||
when Array
|
||||
if result.first == 401 && intercept_401?(env) # does this happen during testing?
|
||||
_process_unauthenticated(env)
|
||||
else
|
||||
result
|
||||
end
|
||||
when Hash
|
||||
_process_unauthenticated(env, result)
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def _process_unauthenticated(env, options = {})
|
||||
options[:action] ||= :unauthenticated
|
||||
proxy = env['warden']
|
||||
result = options[:result] || proxy.result
|
||||
|
||||
ret = case result
|
||||
when :redirect
|
||||
body = proxy.message || "You are being redirected to #{proxy.headers['Location']}"
|
||||
[proxy.status, proxy.headers, [body]]
|
||||
when :custom
|
||||
proxy.custom_response
|
||||
else
|
||||
env["PATH_INFO"] = "/#{options[:action]}"
|
||||
env["warden.options"] = options
|
||||
Warden::Manager._run_callbacks(:before_failure, env, options)
|
||||
|
||||
status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
|
||||
@controller.response.headers.merge!(headers)
|
||||
r_opts = { status: status, content_type: headers["Content-Type"], location: headers["Location"] }
|
||||
r_opts[Rails.version.start_with?('5') ? :body : :text] = response.body
|
||||
@controller.send :render, r_opts
|
||||
nil # causes process return @response
|
||||
end
|
||||
|
||||
# ensure that the controller response is set up. In production, this is
|
||||
# not necessary since warden returns the results to rack. However, at
|
||||
# testing time, we want the response to be available to the testing
|
||||
# framework to verify what would be returned to rack.
|
||||
if ret.is_a?(Array)
|
||||
# ensure the controller response is set to our response.
|
||||
@controller.response ||= @response
|
||||
@response.status = ret.first
|
||||
@response.headers.clear
|
||||
ret.second.each { |k,v| @response[k] = v }
|
||||
@response.body = ret.third
|
||||
end
|
||||
|
||||
ret
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Devise
|
||||
VERSION = "4.1.0".freeze
|
||||
VERSION = "4.3.0".freeze
|
||||
end
|
||||
|
||||
@@ -21,14 +21,7 @@ Some setup you must do manually if you haven't yet:
|
||||
<p class="notice"><%= notice %></p>
|
||||
<p class="alert"><%= alert %></p>
|
||||
|
||||
4. If you are deploying on Heroku with Rails 3.2 only, you may want to set:
|
||||
|
||||
config.assets.initialize_on_precompile = false
|
||||
|
||||
On config/application.rb forcing your application to not access the DB
|
||||
or load models when precompiling your assets.
|
||||
|
||||
5. You can copy Devise views (for customization) to your app by running:
|
||||
4. You can copy Devise views (for customization) to your app by running:
|
||||
|
||||
rails g devise:views
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsController
|
||||
# before_action :configure_sign_up_params, only: [:create]
|
||||
# before_action :configure_account_update_params, only: [:update]
|
||||
# before_action :configure_sign_up_params, only: [:create]
|
||||
# before_action :configure_account_update_params, only: [:update]
|
||||
|
||||
# GET /resource/sign_up
|
||||
# def new
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class <%= @scope_prefix %>SessionsController < Devise::SessionsController
|
||||
# before_action :configure_sign_in_params, only: [:create]
|
||||
# before_action :configure_sign_in_params, only: [:create]
|
||||
|
||||
# GET /resource/sign_in
|
||||
# def new
|
||||
|
||||
@@ -90,6 +90,12 @@ Devise.setup do |config|
|
||||
# from the server. You can disable this option at your own risk.
|
||||
# config.clean_up_csrf_token_on_authentication = true
|
||||
|
||||
# When false, Devise will not attempt to reload routes on eager load.
|
||||
# This can reduce the time taken to boot the app but if your application
|
||||
# requires the Devise mappings to be loaded during boot time the application
|
||||
# won't boot properly.
|
||||
# config.reload_routes = true
|
||||
|
||||
# ==> Configuration for :database_authenticatable
|
||||
# For bcrypt, this is the cost for hashing the password and defaults to 11. If
|
||||
# using other algorithms, it sets how many times you want the password to be hashed.
|
||||
@@ -104,7 +110,10 @@ Devise.setup do |config|
|
||||
# Set up a pepper to generate the hashed password.
|
||||
# config.pepper = '<%= SecureRandom.hex(64) %>'
|
||||
|
||||
# Send a notification email when the user's password is changed
|
||||
# Send a notification to the original email when the user's email is changed.
|
||||
# config.send_email_changed_notification = false
|
||||
|
||||
# Send a notification email when the user's password is changed.
|
||||
# config.send_password_change_notification = false
|
||||
|
||||
# ==> Configuration for :confirmable
|
||||
|
||||
7
lib/generators/templates/markerb/email_changed.markerb
Normal file
7
lib/generators/templates/markerb/email_changed.markerb
Normal file
@@ -0,0 +1,7 @@
|
||||
Hello <%= @email %>!
|
||||
|
||||
<% if @resource.try(:unconfirmed_email?) %>
|
||||
We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.
|
||||
<% else %>
|
||||
We're contacting you to notify you that your email has been changed to <%= @resource.email %>.
|
||||
<% end %>
|
||||
@@ -1,3 +1,3 @@
|
||||
<p>Hello <%= @resource.email %>!</p>
|
||||
Hello <%= @resource.email %>!
|
||||
|
||||
<p>We're contacting you to notify you that your password has been changed.</p>
|
||||
We're contacting you to notify you that your password has been changed.
|
||||
|
||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
||||
class CustomRegistrationsControllerTest < Devise::ControllerTestCase
|
||||
tests Custom::RegistrationsController
|
||||
|
||||
include Devise::TestHelpers
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
||||
setup do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
|
||||
@@ -27,7 +27,7 @@ end
|
||||
class CustomStrategyTest < Devise::ControllerTestCase
|
||||
tests CustomStrategyController
|
||||
|
||||
include Devise::TestHelpers
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
||||
setup do
|
||||
Warden::Strategies.add(:custom_strategy, CustomStrategy)
|
||||
|
||||
@@ -96,7 +96,7 @@ class ControllerAuthenticatableTest < Devise::ControllerTestCase
|
||||
|
||||
test 'proxy admin_signed_in? to authenticatewith admin scope' do
|
||||
@mock_warden.expects(:authenticate).with(scope: :admin)
|
||||
assert_not @controller.admin_signed_in?
|
||||
refute @controller.admin_signed_in?
|
||||
end
|
||||
|
||||
test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
|
||||
@@ -150,11 +150,11 @@ class ControllerAuthenticatableTest < Devise::ControllerTestCase
|
||||
@controller.sign_in(user, force: true)
|
||||
end
|
||||
|
||||
test 'sign in accepts bypass as option' do
|
||||
test 'bypass the sign in' 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.bypass_sign_in(user)
|
||||
end
|
||||
|
||||
test 'sign out clears up any signed in user from all scopes' do
|
||||
@@ -164,8 +164,8 @@ class ControllerAuthenticatableTest < Devise::ControllerTestCase
|
||||
@controller.instance_variable_set(:@current_user, user)
|
||||
@controller.instance_variable_set(:@current_admin, user)
|
||||
@controller.sign_out
|
||||
assert_equal nil, @controller.instance_variable_get(:@current_user)
|
||||
assert_equal nil, @controller.instance_variable_get(:@current_admin)
|
||||
assert_nil @controller.instance_variable_get(:@current_user)
|
||||
assert_nil @controller.instance_variable_get(:@current_admin)
|
||||
end
|
||||
|
||||
test 'sign out logs out and clears up any signed in user by scope' do
|
||||
@@ -175,7 +175,7 @@ class ControllerAuthenticatableTest < Devise::ControllerTestCase
|
||||
@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)
|
||||
assert_nil @controller.instance_variable_get(:@current_user)
|
||||
end
|
||||
|
||||
test 'sign out accepts a resource as argument' do
|
||||
@@ -311,6 +311,6 @@ class ControllerAuthenticatableTest < Devise::ControllerTestCase
|
||||
end
|
||||
|
||||
test 'is not a devise controller' do
|
||||
assert_not @controller.devise_controller?
|
||||
refute @controller.devise_controller?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -119,7 +119,7 @@ class HelpersTest < Devise::ControllerTestCase
|
||||
MyController.send(:public, :navigational_formats)
|
||||
|
||||
swap Devise, navigational_formats: ['*/*', :html] do
|
||||
assert_not @controller.navigational_formats.include?("*/*")
|
||||
refute @controller.navigational_formats.include?("*/*")
|
||||
end
|
||||
|
||||
MyController.send(:protected, :navigational_formats)
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class PasswordsControllerTest < Devise::ControllerTestCase
|
||||
tests Devise::PasswordsController
|
||||
include Devise::TestHelpers
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
||||
setup do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class SessionsControllerTest < Devise::ControllerTestCase
|
||||
tests Devise::SessionsController
|
||||
include Devise::TestHelpers
|
||||
include Devise::Test::ControllerHelpers
|
||||
|
||||
test "#create doesn't raise unpermitted params when sign in fails" do
|
||||
begin
|
||||
@@ -94,7 +94,7 @@ class SessionsControllerTest < Devise::ControllerTestCase
|
||||
User.class_eval { attr_protected :email }
|
||||
|
||||
begin
|
||||
assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do
|
||||
assert_nothing_raised do
|
||||
get :new, user: { email: "allez viens!" }
|
||||
end
|
||||
ensure
|
||||
|
||||
@@ -67,18 +67,18 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'add new module using the helper method' do
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
||||
Devise.add_module(:coconut)
|
||||
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
||||
assert_not Devise::STRATEGIES.include?(:coconut)
|
||||
assert_not defined?(Devise::Models::Coconut)
|
||||
refute Devise::STRATEGIES.include?(:coconut)
|
||||
refute defined?(Devise::Models::Coconut)
|
||||
Devise::ALL.delete(:coconut)
|
||||
|
||||
assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) }
|
||||
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) }
|
||||
Devise.add_module(:kivi, controller: :fruits)
|
||||
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
||||
Devise::ALL.delete(:kivi)
|
||||
Devise::CONTROLLERS.delete(:kivi)
|
||||
@@ -86,11 +86,11 @@ class DeviseTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should complain when comparing empty or different sized passes' do
|
||||
[nil, ""].each do |empty|
|
||||
assert_not Devise.secure_compare(empty, "something")
|
||||
assert_not Devise.secure_compare("something", empty)
|
||||
assert_not Devise.secure_compare(empty, empty)
|
||||
refute Devise.secure_compare(empty, "something")
|
||||
refute Devise.secure_compare("something", empty)
|
||||
refute Devise.secure_compare(empty, empty)
|
||||
end
|
||||
assert_not Devise.secure_compare("size_1", "size_four")
|
||||
refute Devise.secure_compare("size_1", "size_four")
|
||||
end
|
||||
|
||||
test 'Devise.email_regexp should match valid email addresses' do
|
||||
|
||||
@@ -131,6 +131,24 @@ class FailureTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
if Rails.application.config.action_controller.respond_to?(:relative_url_root)
|
||||
test "returns to the default redirect location considering action_controller's relative url root" do
|
||||
swap Rails.application.config.action_controller, relative_url_root: "/sample" do
|
||||
call_failure
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']
|
||||
end
|
||||
end
|
||||
|
||||
test "returns to the default redirect location considering action_controller's relative url root and subdomain" do
|
||||
swap Rails.application.config.action_controller, relative_url_root: "/sample" do
|
||||
call_failure('warden.options' => { scope: :subdomain_user })
|
||||
assert_equal 302, @response.first
|
||||
assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test 'uses the proxy failure message as symbol' do
|
||||
call_failure('warden' => OpenStruct.new(message: :invalid))
|
||||
assert_equal 'Invalid Email or password.', @request.flash[:alert]
|
||||
|
||||
@@ -10,13 +10,13 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||
test 'sign in as user should not authenticate admin scope' do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'sign in as admin should not authenticate user scope' do
|
||||
sign_in_as_admin
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'sign in as both user and admin at same time' do
|
||||
@@ -31,7 +31,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||
sign_in_as_user
|
||||
sign_in_as_admin
|
||||
delete destroy_user_session_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
assert warden.authenticated?(:admin)
|
||||
end
|
||||
end
|
||||
@@ -42,7 +42,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||
sign_in_as_admin
|
||||
|
||||
delete destroy_admin_session_path
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
assert warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
@@ -53,8 +53,8 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||
sign_in_as_admin
|
||||
|
||||
delete destroy_user_session_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -64,21 +64,21 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||
sign_in_as_admin
|
||||
|
||||
delete destroy_admin_session_path
|
||||
assert_not warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
test 'not signed in as admin should not be able to access admins actions' do
|
||||
get admins_path
|
||||
assert_redirected_to new_admin_session_path
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'signed in as user should not be able to access admins actions' do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
|
||||
get admins_path
|
||||
assert_redirected_to new_admin_session_path
|
||||
@@ -87,7 +87,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||
test 'signed in as admin should be able to access admin actions' do
|
||||
sign_in_as_admin
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
get admins_path
|
||||
|
||||
@@ -115,7 +115,7 @@ class AuthenticationSanityTest < Devise::IntegrationTest
|
||||
|
||||
get root_path
|
||||
assert_contain 'Signed out successfully'
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'unauthenticated admin set message on sign out' do
|
||||
@@ -138,13 +138,13 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
test 'not signed in should not be able to access private route (authenticate denied)' do
|
||||
get private_path
|
||||
assert_redirected_to new_admin_session_path
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'signed in as user should not be able to access private route restricted to admins (authenticate denied)' do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
get private_path
|
||||
assert_redirected_to new_admin_session_path
|
||||
end
|
||||
@@ -152,7 +152,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
test 'signed in as admin should be able to access private route restricted to admins (authenticate accepted)' do
|
||||
sign_in_as_admin
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
get private_path
|
||||
|
||||
@@ -164,7 +164,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
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)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
assert_raises ActionController::RoutingError do
|
||||
get "/private/active"
|
||||
@@ -174,7 +174,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
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)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
get private_active_path
|
||||
|
||||
@@ -186,7 +186,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
test 'signed in as admin should get admin dashboard (authenticated accepted)' do
|
||||
sign_in_as_admin
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
get dashboard_path
|
||||
|
||||
@@ -198,7 +198,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
test 'signed in as user should get user dashboard (authenticated accepted)' do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
|
||||
get dashboard_path
|
||||
|
||||
@@ -216,7 +216,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
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)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
assert_raises ActionController::RoutingError do
|
||||
get "/dashboard/active"
|
||||
@@ -226,7 +226,7 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
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)
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
get dashboard_active_path
|
||||
|
||||
@@ -238,14 +238,14 @@ class AuthenticationRoutesRestrictions < Devise::IntegrationTest
|
||||
test 'signed in user should not see unauthenticated page (unauthenticated denied)' do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
|
||||
assert_raises ActionController::RoutingError do
|
||||
get join_path
|
||||
end
|
||||
end
|
||||
|
||||
test 'not signed in users should see unautheticated page (unauthenticated accepted)' do
|
||||
test 'not signed in users should see unauthenticated page (unauthenticated accepted)' do
|
||||
get join_path
|
||||
|
||||
assert_response :success
|
||||
@@ -404,13 +404,13 @@ class AuthenticationOthersTest < Devise::IntegrationTest
|
||||
test 'handles unverified requests gets rid of caches' do
|
||||
swap ApplicationController, allow_forgery_protection: true do
|
||||
post exhibit_user_url(1)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
|
||||
post exhibit_user_url(1)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
assert_equal "User is not authenticated", response.body
|
||||
end
|
||||
end
|
||||
@@ -473,7 +473,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
|
||||
test 'uses the mapping from router' do
|
||||
sign_in_as_user visit: "/as/sign_in"
|
||||
assert warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'sign in with xml format returns xml response' do
|
||||
@@ -515,14 +515,14 @@ class AuthenticationOthersTest < Devise::IntegrationTest
|
||||
sign_in_as_user
|
||||
delete destroy_user_session_path(format: 'xml')
|
||||
assert_response :no_content
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'sign out with json format returns no content' do
|
||||
sign_in_as_user
|
||||
delete destroy_user_session_path(format: 'json')
|
||||
assert_response :no_content
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'sign out with non-navigational format via XHR does not redirect' do
|
||||
@@ -530,7 +530,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
|
||||
sign_in_as_admin
|
||||
get destroy_sign_out_via_get_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*.
|
||||
assert_response :no_content
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -540,7 +540,7 @@ class AuthenticationOthersTest < Devise::IntegrationTest
|
||||
sign_in_as_user
|
||||
delete destroy_user_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "text/html,*/*" }
|
||||
assert_response :redirect
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -550,7 +550,7 @@ class AuthenticationKeysTest < Devise::IntegrationTest
|
||||
swap Devise, authentication_keys: [:subdomain] do
|
||||
sign_in_as_user
|
||||
assert_contain "Invalid Subdomain or password."
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -579,7 +579,7 @@ class AuthenticationRequestKeysTest < Devise::IntegrationTest
|
||||
sign_in_as_user
|
||||
end
|
||||
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -589,7 +589,7 @@ class AuthenticationRequestKeysTest < Devise::IntegrationTest
|
||||
swap Devise, request_keys: [:subdomain] do
|
||||
sign_in_as_user
|
||||
assert_contain "Invalid Email or password."
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -612,7 +612,7 @@ class AuthenticationSignOutViaTest < Devise::IntegrationTest
|
||||
test 'allow sign out via delete when sign_out_via provides only delete' do
|
||||
sign_in!(:sign_out_via_delete)
|
||||
delete destroy_sign_out_via_delete_session_path
|
||||
assert_not warden.authenticated?(:sign_out_via_delete)
|
||||
refute warden.authenticated?(:sign_out_via_delete)
|
||||
end
|
||||
|
||||
test 'do not allow sign out via get when sign_out_via provides only delete' do
|
||||
@@ -626,7 +626,7 @@ class AuthenticationSignOutViaTest < Devise::IntegrationTest
|
||||
test 'allow sign out via post when sign_out_via provides only post' do
|
||||
sign_in!(:sign_out_via_post)
|
||||
post destroy_sign_out_via_post_session_path
|
||||
assert_not warden.authenticated?(:sign_out_via_post)
|
||||
refute warden.authenticated?(:sign_out_via_post)
|
||||
end
|
||||
|
||||
test 'do not allow sign out via get when sign_out_via provides only post' do
|
||||
@@ -640,13 +640,13 @@ class AuthenticationSignOutViaTest < Devise::IntegrationTest
|
||||
test 'allow sign out via delete when sign_out_via provides delete and post' do
|
||||
sign_in!(:sign_out_via_delete_or_post)
|
||||
delete destroy_sign_out_via_delete_or_post_session_path
|
||||
assert_not warden.authenticated?(:sign_out_via_delete_or_post)
|
||||
refute warden.authenticated?(:sign_out_via_delete_or_post)
|
||||
end
|
||||
|
||||
test 'allow sign out via post when sign_out_via provides delete and post' do
|
||||
sign_in!(:sign_out_via_delete_or_post)
|
||||
post destroy_sign_out_via_delete_or_post_session_path
|
||||
assert_not warden.authenticated?(:sign_out_via_delete_or_post)
|
||||
refute warden.authenticated?(:sign_out_via_delete_or_post)
|
||||
end
|
||||
|
||||
test 'do not allow sign out via get when sign_out_via provides delete and post' do
|
||||
|
||||
@@ -41,12 +41,12 @@ class ConfirmationTest < Devise::IntegrationTest
|
||||
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)
|
||||
assert_not user.confirmed?
|
||||
refute user.confirmed?
|
||||
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
||||
|
||||
assert_have_selector '#error_explanation'
|
||||
assert_contain %r{needs to be confirmed within 3 days}
|
||||
assert_not user.reload.confirmed?
|
||||
refute user.reload.confirmed?
|
||||
assert_current_url "/users/confirmation?confirmation_token=#{user.raw_confirmation_token}"
|
||||
end
|
||||
end
|
||||
@@ -84,7 +84,7 @@ class ConfirmationTest < Devise::IntegrationTest
|
||||
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)
|
||||
assert_not user.confirmed?
|
||||
refute user.confirmed?
|
||||
visit_user_confirmation_with_token(user.raw_confirmation_token)
|
||||
|
||||
assert_contain 'Your email address has been successfully confirmed.'
|
||||
@@ -130,7 +130,7 @@ class ConfirmationTest < Devise::IntegrationTest
|
||||
sign_in_as_user(confirm: false)
|
||||
|
||||
assert_contain 'You have to confirm your email address before continuing'
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -141,7 +141,7 @@ class ConfirmationTest < Devise::IntegrationTest
|
||||
end
|
||||
|
||||
assert_contain 'Invalid Email or password'
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -284,7 +284,7 @@ class ConfirmationOnChangeTest < Devise::IntegrationTest
|
||||
assert_contain 'Your email address has been successfully confirmed.'
|
||||
assert_current_url '/admin_area/sign_in'
|
||||
assert admin.reload.confirmed?
|
||||
assert_not admin.reload.pending_reconfirmation?
|
||||
refute admin.reload.pending_reconfirmation?
|
||||
end
|
||||
|
||||
test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do
|
||||
@@ -306,7 +306,7 @@ class ConfirmationOnChangeTest < Devise::IntegrationTest
|
||||
assert_contain 'Your email address has been successfully confirmed.'
|
||||
assert_current_url '/admin_area/sign_in'
|
||||
assert admin.reload.confirmed?
|
||||
assert_not admin.reload.pending_reconfirmation?
|
||||
refute admin.reload.pending_reconfirmation?
|
||||
end
|
||||
|
||||
test 'admin email should be unique also within unconfirmed_email' do
|
||||
|
||||
@@ -19,7 +19,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
|
||||
fill_in 'email', with: 'foo@bar.com'
|
||||
end
|
||||
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,14 +41,14 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
|
||||
fill_in 'email', with: ' foo@bar.com '
|
||||
end
|
||||
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
test 'sign in should not authenticate if not using proper authentication keys' do
|
||||
swap Devise, authentication_keys: [:username] do
|
||||
sign_in_as_user
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -59,7 +59,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
|
||||
end
|
||||
|
||||
assert_contain 'Invalid email address'
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -69,7 +69,7 @@ class DatabaseAuthenticationTest < Devise::IntegrationTest
|
||||
end
|
||||
|
||||
assert_contain 'Invalid Email or password'
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'error message is configurable by resource name' do
|
||||
|
||||
@@ -65,7 +65,7 @@ class HttpAuthenticationTest < Devise::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: { 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
|
||||
@@ -74,7 +74,7 @@ class HttpAuthenticationTest < Devise::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: { 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
|
||||
|
||||
@@ -85,7 +85,7 @@ class LockTest < Devise::IntegrationTest
|
||||
|
||||
assert_current_url "/users/sign_in"
|
||||
assert_contain 'Your account has been unlocked successfully. Please sign in to continue.'
|
||||
assert_not user.reload.access_locked?
|
||||
refute user.reload.access_locked?
|
||||
end
|
||||
|
||||
test "user should not send a new e-mail if already locked" do
|
||||
|
||||
36
test/integration/mounted_engine_test.rb
Normal file
36
test/integration/mounted_engine_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MyMountableEngine
|
||||
def self.call(env)
|
||||
['200', { 'Content-Type' => 'text/html' }, ['Rendered content of MyMountableEngine']]
|
||||
end
|
||||
end
|
||||
|
||||
# If disable_clear_and_finalize is set to true, Rails will not clear other routes when calling
|
||||
# again the draw method. Look at the source code at:
|
||||
# http://www.rubydoc.info/docs/rails/ActionDispatch/Routing/RouteSet:draw
|
||||
Rails.application.routes.disable_clear_and_finalize = true
|
||||
|
||||
Rails.application.routes.draw do
|
||||
authenticate(:user) do
|
||||
mount MyMountableEngine, at: '/mountable_engine'
|
||||
end
|
||||
end
|
||||
|
||||
class AuthenticatedMountedEngineTest < Devise::IntegrationTest
|
||||
test 'redirects to the sign in page when not authenticated' do
|
||||
get '/mountable_engine'
|
||||
follow_redirect!
|
||||
|
||||
assert_response :ok
|
||||
assert_contain 'You need to sign in or sign up before continuing.'
|
||||
end
|
||||
|
||||
test 'renders the mounted engine when authenticated' do
|
||||
sign_in_as_user
|
||||
get '/mountable_engine'
|
||||
|
||||
assert_response :success
|
||||
assert_contain 'Rendered content of MyMountableEngine'
|
||||
end
|
||||
end
|
||||
@@ -71,7 +71,7 @@ class OmniauthableIntegrationTest < Devise::IntegrationTest
|
||||
assert_current_url "/"
|
||||
assert_contain "You have signed up successfully."
|
||||
assert_contain "Hello User user@example.com"
|
||||
assert_not session["devise.facebook_data"]
|
||||
refute session["devise.facebook_data"]
|
||||
end
|
||||
|
||||
test "cleans up session on cancel" do
|
||||
|
||||
@@ -10,7 +10,7 @@ class PasswordTest < Devise::IntegrationTest
|
||||
def request_forgot_password(&block)
|
||||
visit_new_password_path
|
||||
assert_response :success
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
fill_in 'email', with: 'user@test.com'
|
||||
yield if block_given?
|
||||
@@ -147,7 +147,7 @@ class PasswordTest < Devise::IntegrationTest
|
||||
assert_current_url '/users/password'
|
||||
assert_have_selector '#error_explanation'
|
||||
assert_contain %r{Reset password token(.*)invalid}
|
||||
assert_not user.reload.valid_password?('987654321')
|
||||
refute user.reload.valid_password?('987654321')
|
||||
end
|
||||
|
||||
test 'not authenticated user with valid reset password token but invalid password should not be able to change their password' do
|
||||
@@ -161,7 +161,7 @@ class PasswordTest < Devise::IntegrationTest
|
||||
assert_current_url '/users/password'
|
||||
assert_have_selector '#error_explanation'
|
||||
assert_contain "Password confirmation doesn't match Password"
|
||||
assert_not user.reload.valid_password?('987654321')
|
||||
refute user.reload.valid_password?('987654321')
|
||||
end
|
||||
|
||||
test 'not authenticated user with valid data should be able to change their password' do
|
||||
@@ -181,7 +181,7 @@ class PasswordTest < Devise::IntegrationTest
|
||||
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')
|
||||
refute user.reload.valid_password?('987654321')
|
||||
|
||||
reset_password visit: false
|
||||
assert_contain 'Your password has been changed successfully.'
|
||||
|
||||
@@ -64,11 +64,11 @@ class RegistrationTest < Devise::IntegrationTest
|
||||
assert_not_contain 'You have to confirm your account before continuing'
|
||||
assert_current_url "/"
|
||||
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
user = User.to_adapter.find_first(order: [:id, :desc])
|
||||
assert_equal user.email, 'new_user@test.com'
|
||||
assert_not user.confirmed?
|
||||
refute user.confirmed?
|
||||
end
|
||||
|
||||
test 'a guest user should receive the confirmation instructions from the default mailer' do
|
||||
@@ -92,7 +92,7 @@ class RegistrationTest < Devise::IntegrationTest
|
||||
click_button 'Sign up'
|
||||
|
||||
assert_current_url "/?custom=1"
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'a guest user cannot sign up with invalid information' do
|
||||
@@ -114,7 +114,7 @@ class RegistrationTest < Devise::IntegrationTest
|
||||
assert_contain "2 errors prohibited"
|
||||
assert_nil User.to_adapter.find_first
|
||||
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'a guest should not sign up with email/password that already exists' do
|
||||
@@ -133,7 +133,7 @@ class RegistrationTest < Devise::IntegrationTest
|
||||
assert_current_url '/users'
|
||||
assert_contain(/Email.*already.*taken/)
|
||||
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'a guest should not be able to change account' do
|
||||
@@ -217,7 +217,13 @@ class RegistrationTest < Devise::IntegrationTest
|
||||
click_button 'Update'
|
||||
|
||||
assert_contain "Password confirmation doesn't match Password"
|
||||
assert_not User.to_adapter.find_first.valid_password?('pas123')
|
||||
refute User.to_adapter.find_first.valid_password?('pas123')
|
||||
end
|
||||
|
||||
test 'a signed in user should see a warning about minimum password length' do
|
||||
sign_in_as_user
|
||||
get edit_user_registration_path
|
||||
assert_contain 'characters minimum'
|
||||
end
|
||||
|
||||
test 'a signed in user should be able to cancel their account' do
|
||||
|
||||
@@ -10,7 +10,13 @@ class RememberMeTest < Devise::IntegrationTest
|
||||
end
|
||||
|
||||
def generate_signed_cookie(raw_cookie)
|
||||
request = Devise.rails5? ? ActionDispatch::TestRequest.create : ActionDispatch::TestRequest.new
|
||||
request = if Devise::Test.rails51?
|
||||
ActionController::TestRequest.create(Class.new) # needs a "controller class"
|
||||
elsif Devise::Test.rails5?
|
||||
ActionController::TestRequest.create
|
||||
else
|
||||
ActionController::TestRequest.new
|
||||
end
|
||||
request.cookie_jar.signed['raw_cookie'] = raw_cookie
|
||||
request.cookie_jar['raw_cookie']
|
||||
end
|
||||
@@ -33,12 +39,12 @@ class RememberMeTest < Devise::IntegrationTest
|
||||
test 'handle unverified requests gets rid of caches' do
|
||||
swap ApplicationController, allow_forgery_protection: true do
|
||||
post exhibit_user_url(1)
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
|
||||
create_user_and_remember
|
||||
post exhibit_user_url(1)
|
||||
assert_equal "User is not authenticated", response.body
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,8 +57,8 @@ class RememberMeTest < Devise::IntegrationTest
|
||||
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']
|
||||
refute warden.authenticated?(:user)
|
||||
refute request.cookies['remember_user_token']
|
||||
end
|
||||
end
|
||||
|
||||
@@ -158,13 +164,13 @@ class RememberMeTest < Devise::IntegrationTest
|
||||
get root_path
|
||||
assert_response :success
|
||||
assert warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'do not remember with invalid token' do
|
||||
create_user_and_remember('add')
|
||||
get users_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
|
||||
@@ -172,7 +178,7 @@ class RememberMeTest < Devise::IntegrationTest
|
||||
create_user_and_remember
|
||||
swap Devise, remember_for: 0.days do
|
||||
get users_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
assert_redirected_to new_user_session_path
|
||||
end
|
||||
end
|
||||
@@ -183,11 +189,11 @@ class RememberMeTest < Devise::IntegrationTest
|
||||
assert warden.authenticated?(:user)
|
||||
|
||||
delete destroy_user_session_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
assert_nil warden.cookies['remember_user_token']
|
||||
|
||||
get users_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'changing user password expires remember me token' do
|
||||
@@ -197,7 +203,7 @@ class RememberMeTest < Devise::IntegrationTest
|
||||
user.save!
|
||||
|
||||
get users_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'valid sign in calls after_remembered callback' do
|
||||
|
||||
@@ -56,7 +56,7 @@ class SessionTimeoutTest < Devise::IntegrationTest
|
||||
|
||||
get users_path
|
||||
assert_redirected_to users_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
assert warden.authenticated?(:admin)
|
||||
end
|
||||
end
|
||||
@@ -70,8 +70,8 @@ class SessionTimeoutTest < Devise::IntegrationTest
|
||||
assert_not_nil last_request_at
|
||||
|
||||
get root_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
assert_not warden.authenticated?(:admin)
|
||||
refute warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:admin)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -108,7 +108,7 @@ class SessionTimeoutTest < Devise::IntegrationTest
|
||||
|
||||
assert_response :success
|
||||
assert_contain 'Sign in'
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'time out is not triggered on sign in' do
|
||||
@@ -134,7 +134,7 @@ class SessionTimeoutTest < Devise::IntegrationTest
|
||||
get expire_user_path(user)
|
||||
get users_path
|
||||
assert_redirected_to users_path
|
||||
assert_not warden.authenticated?(:user)
|
||||
refute warden.authenticated?(:user)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
130
test/mailers/email_changed_test.rb
Normal file
130
test/mailers/email_changed_test.rb
Normal file
@@ -0,0 +1,130 @@
|
||||
require 'test_helper'
|
||||
|
||||
class EmailChangedTest < ActionMailer::TestCase
|
||||
def setup
|
||||
setup_mailer
|
||||
Devise.mailer = 'Devise::Mailer'
|
||||
Devise.mailer_sender = 'test@example.com'
|
||||
Devise.send_email_changed_notification = true
|
||||
end
|
||||
|
||||
def teardown
|
||||
Devise.mailer = 'Devise::Mailer'
|
||||
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
||||
Devise.send_email_changed_notification = false
|
||||
end
|
||||
|
||||
def user
|
||||
@user ||= create_user.tap { |u|
|
||||
@original_user_email = u.email
|
||||
u.update_attributes!(email: 'new-email@example.com')
|
||||
}
|
||||
end
|
||||
|
||||
def mail
|
||||
@mail ||= begin
|
||||
user
|
||||
ActionMailer::Base.deliveries.last
|
||||
end
|
||||
end
|
||||
|
||||
test 'email sent after changing the user email' do
|
||||
assert_not_nil mail
|
||||
end
|
||||
|
||||
test 'content type should be set to html' do
|
||||
assert mail.content_type.include?('text/html')
|
||||
end
|
||||
|
||||
test 'send email changed to the original user email' do
|
||||
mail
|
||||
assert_equal [@original_user_email], mail.to
|
||||
end
|
||||
|
||||
test 'set up sender from configuration' do
|
||||
assert_equal ['test@example.com'], mail.from
|
||||
end
|
||||
|
||||
test 'set up sender from custom mailer defaults' do
|
||||
Devise.mailer = 'Users::Mailer'
|
||||
assert_equal ['custom@example.com'], mail.from
|
||||
end
|
||||
|
||||
test 'set up sender from custom mailer defaults with proc' do
|
||||
Devise.mailer = 'Users::FromProcMailer'
|
||||
assert_equal ['custom@example.com'], mail.from
|
||||
end
|
||||
|
||||
test 'custom mailer renders parent mailer template' do
|
||||
Devise.mailer = 'Users::Mailer'
|
||||
assert_present mail.body.encoded
|
||||
end
|
||||
|
||||
test 'set up reply to as copy from sender' do
|
||||
assert_equal ['test@example.com'], mail.reply_to
|
||||
end
|
||||
|
||||
test 'set up reply to as different if set in defaults' do
|
||||
Devise.mailer = 'Users::ReplyToMailer'
|
||||
assert_equal ['custom@example.com'], mail.from
|
||||
assert_equal ['custom_reply_to@example.com'], mail.reply_to
|
||||
end
|
||||
|
||||
test 'set up subject from I18n' do
|
||||
store_translations :en, devise: { mailer: { email_changed: { subject: 'Email Has Changed' } } } do
|
||||
assert_equal 'Email Has Changed', mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
test 'subject namespaced by model' do
|
||||
store_translations :en, devise: { mailer: { email_changed: { user_subject: 'User Email Has Changed' } } } do
|
||||
assert_equal 'User Email Has Changed', mail.subject
|
||||
end
|
||||
end
|
||||
|
||||
test 'body should have user info' do
|
||||
body = mail.body.encoded
|
||||
assert_match "Hello #{@original_user_email}", body
|
||||
assert_match "has been changed to #{user.email}", body
|
||||
end
|
||||
end
|
||||
|
||||
class EmailChangedReconfirmationTest < ActionMailer::TestCase
|
||||
def setup
|
||||
setup_mailer
|
||||
Devise.mailer = 'Devise::Mailer'
|
||||
Devise.mailer_sender = 'test@example.com'
|
||||
Devise.send_email_changed_notification = true
|
||||
end
|
||||
|
||||
def teardown
|
||||
Devise.mailer = 'Devise::Mailer'
|
||||
Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
|
||||
Devise.send_email_changed_notification = false
|
||||
end
|
||||
|
||||
def admin
|
||||
@admin ||= create_admin.tap { |u|
|
||||
@original_admin_email = u.email
|
||||
u.update_attributes!(email: 'new-email@example.com')
|
||||
}
|
||||
end
|
||||
|
||||
def mail
|
||||
@mail ||= begin
|
||||
admin
|
||||
ActionMailer::Base.deliveries[-2]
|
||||
end
|
||||
end
|
||||
|
||||
test 'send email changed to the original user email' do
|
||||
mail
|
||||
assert_equal [@original_admin_email], mail.to
|
||||
end
|
||||
|
||||
test 'body should have unconfirmed user info' do
|
||||
body = mail.body.encoded
|
||||
assert_match admin.email, body
|
||||
assert_match "is being changed to #{admin.unconfirmed_email}", body
|
||||
end
|
||||
end
|
||||
18
test/mailers/mailer_test.rb
Normal file
18
test/mailers/mailer_test.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
require "test_helper"
|
||||
|
||||
class MailerTest < ActionMailer::TestCase
|
||||
test "pass given block to #mail call" do
|
||||
class TestMailer < Devise::Mailer
|
||||
def confirmation_instructions(record, token, opts = {})
|
||||
@token = token
|
||||
devise_mail(record, :confirmation_instructions, opts) do |format|
|
||||
format.html(content_transfer_encoding: "7bit")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
mail = TestMailer.confirmation_instructions(create_user, "confirmation-token")
|
||||
|
||||
assert mail.content_transfer_encoding, "7bit"
|
||||
end
|
||||
end
|
||||
@@ -115,7 +115,7 @@ class MappingTest < ActiveSupport::TestCase
|
||||
assert mapping.authenticatable?
|
||||
assert mapping.recoverable?
|
||||
assert mapping.lockable?
|
||||
assert_not mapping.omniauthable?
|
||||
refute mapping.omniauthable?
|
||||
end
|
||||
|
||||
test 'find mapping by path' do
|
||||
|
||||
@@ -28,9 +28,9 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'should verify whether a user is confirmed or not' do
|
||||
assert_not new_user.confirmed?
|
||||
refute new_user.confirmed?
|
||||
user = create_user
|
||||
assert_not user.confirmed?
|
||||
refute user.confirmed?
|
||||
user.confirm
|
||||
assert user.confirmed?
|
||||
end
|
||||
@@ -40,7 +40,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
assert user.confirm
|
||||
assert_blank user.errors[:email]
|
||||
|
||||
assert_not user.confirm
|
||||
refute user.confirm
|
||||
assert_equal "was already confirmed, please try signing in", user.errors[:email].join
|
||||
end
|
||||
|
||||
@@ -54,13 +54,13 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should return a new record with errors when a invalid token is given' do
|
||||
confirmed_user = User.confirm_by_token('invalid_confirmation_token')
|
||||
assert_not confirmed_user.persisted?
|
||||
refute confirmed_user.persisted?
|
||||
assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
|
||||
end
|
||||
|
||||
test 'should return a new record with errors when a blank token is given' do
|
||||
confirmed_user = User.confirm_by_token('')
|
||||
assert_not confirmed_user.persisted?
|
||||
refute confirmed_user.persisted?
|
||||
assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
|
||||
end
|
||||
|
||||
@@ -114,7 +114,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
|
||||
assert_email_not_sent do
|
||||
user.save!
|
||||
assert_not user.confirmed?
|
||||
refute user.confirmed?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -134,7 +134,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should return a new user if no email was found' do
|
||||
confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com")
|
||||
assert_not confirmation_user.persisted?
|
||||
refute confirmation_user.persisted?
|
||||
end
|
||||
|
||||
test 'should add error to new user email if no email was found' do
|
||||
@@ -181,7 +181,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
test 'should not be able to send instructions if the user is already confirmed' do
|
||||
user = create_user
|
||||
user.confirm
|
||||
assert_not user.resend_confirmation_instructions
|
||||
refute user.resend_confirmation_instructions
|
||||
assert user.confirmed?
|
||||
assert_equal 'was already confirmed, please try signing in', user.errors[:email].join
|
||||
end
|
||||
@@ -190,7 +190,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
swap Devise, allow_unconfirmed_access_for: 1.day do
|
||||
user = create_user
|
||||
user.confirmation_sent_at = 2.days.ago
|
||||
assert_not user.active_for_authentication?
|
||||
refute user.active_for_authentication?
|
||||
|
||||
Devise.allow_unconfirmed_access_for = 3.days
|
||||
assert user.active_for_authentication?
|
||||
@@ -206,14 +206,14 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
assert user.active_for_authentication?
|
||||
|
||||
user.confirmation_sent_at = 5.days.ago
|
||||
assert_not user.active_for_authentication?
|
||||
refute user.active_for_authentication?
|
||||
end
|
||||
end
|
||||
|
||||
test 'should be active when already confirmed' do
|
||||
user = create_user
|
||||
assert_not user.confirmed?
|
||||
assert_not user.active_for_authentication?
|
||||
refute user.confirmed?
|
||||
refute user.active_for_authentication?
|
||||
|
||||
user.confirm
|
||||
assert user.confirmed?
|
||||
@@ -224,7 +224,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
Devise.allow_unconfirmed_access_for = 0.days
|
||||
user = create_user
|
||||
user.confirmation_sent_at = Time.zone.today
|
||||
assert_not user.active_for_authentication?
|
||||
refute user.active_for_authentication?
|
||||
end
|
||||
|
||||
test 'should be active when we set allow_unconfirmed_access_for to nil' do
|
||||
@@ -239,7 +239,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
user = create_user
|
||||
user.confirmation_sent_at = nil
|
||||
user.save
|
||||
assert_not user.reload.active_for_authentication?
|
||||
refute user.reload.active_for_authentication?
|
||||
end
|
||||
|
||||
test 'should be active without confirmation when confirmation is not required' do
|
||||
@@ -272,7 +272,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
swap Devise, confirmation_keys: [:username, :email] do
|
||||
user = create_user
|
||||
confirm_user = User.send_confirmation_instructions(email: user.email)
|
||||
assert_not confirm_user.persisted?
|
||||
refute confirm_user.persisted?
|
||||
assert_equal "can't be blank", confirm_user.errors[:username].join
|
||||
end
|
||||
end
|
||||
@@ -297,7 +297,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
|
||||
swap Devise, confirm_within: 3.days do
|
||||
assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
|
||||
refute confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -337,14 +337,14 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||
self.username = self.username.to_s + 'updated'
|
||||
end
|
||||
old = user.username
|
||||
assert_not user.confirm
|
||||
refute user.confirm
|
||||
assert_equal user.username, old
|
||||
end
|
||||
|
||||
test 'should always perform validations upon confirm when ensure valid true' do
|
||||
admin = create_admin
|
||||
admin.stubs(:valid?).returns(false)
|
||||
assert_not admin.confirm(ensure_valid: true)
|
||||
refute admin.confirm(ensure_valid: true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -370,7 +370,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
||||
admin.skip_reconfirmation!
|
||||
assert admin.update_attributes(email: 'new_test@example.com')
|
||||
assert admin.confirmed?
|
||||
assert_not admin.pending_reconfirmation?
|
||||
refute admin.pending_reconfirmation?
|
||||
assert_equal original_token, admin.confirmation_token
|
||||
end
|
||||
|
||||
@@ -461,7 +461,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should return a new admin if no email or unconfirmed_email was found' do
|
||||
confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com")
|
||||
assert_not confirmation_admin.persisted?
|
||||
refute confirmation_admin.persisted?
|
||||
end
|
||||
|
||||
test 'should add error to new admin email if no email or unconfirmed_email was found' do
|
||||
@@ -479,18 +479,18 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'required_fields should contain the fields that Devise uses' do
|
||||
assert_same_content Devise::Models::Confirmable.required_fields(User), [
|
||||
:confirmation_sent_at,
|
||||
assert_equal Devise::Models::Confirmable.required_fields(User), [
|
||||
:confirmation_token,
|
||||
:confirmed_at
|
||||
:confirmed_at,
|
||||
:confirmation_sent_at
|
||||
]
|
||||
end
|
||||
|
||||
test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do
|
||||
assert_same_content Devise::Models::Confirmable.required_fields(Admin), [
|
||||
:confirmation_sent_at,
|
||||
assert_equal Devise::Models::Confirmable.required_fields(Admin), [
|
||||
:confirmation_token,
|
||||
:confirmed_at,
|
||||
:confirmation_sent_at,
|
||||
:unconfirmed_email
|
||||
]
|
||||
end
|
||||
@@ -508,4 +508,29 @@ class ReconfirmableTest < ActiveSupport::TestCase
|
||||
admin = Admin::WithSaveInCallback.create(valid_attributes.except(:username))
|
||||
assert !admin.pending_reconfirmation?
|
||||
end
|
||||
|
||||
test 'should require reconfirmation after creating a record and updating the email' do
|
||||
admin = create_admin
|
||||
assert !admin.instance_variable_get(:@bypass_confirmation_postpone)
|
||||
admin.email = "new_test@email.com"
|
||||
admin.save
|
||||
assert admin.pending_reconfirmation?
|
||||
end
|
||||
|
||||
test 'should notify previous email on email change when configured' do
|
||||
swap Devise, send_email_changed_notification: true do
|
||||
admin = create_admin
|
||||
original_email = admin.email
|
||||
|
||||
assert_difference 'ActionMailer::Base.deliveries.size', 2 do
|
||||
assert admin.update_attributes(email: 'new-email@example.com')
|
||||
end
|
||||
assert_equal original_email, ActionMailer::Base.deliveries[-2]['to'].to_s
|
||||
assert_equal 'new-email@example.com', ActionMailer::Base.deliveries[-1]['to'].to_s
|
||||
|
||||
assert_email_not_sent do
|
||||
assert admin.confirm
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -124,7 +124,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
test 'should test for a valid password' do
|
||||
user = create_user
|
||||
assert user.valid_password?('12345678')
|
||||
assert_not user.valid_password?('654321')
|
||||
refute user.valid_password?('654321')
|
||||
end
|
||||
|
||||
test 'should not raise error with an empty password' do
|
||||
@@ -136,7 +136,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
test 'should be an invalid password if the user has an empty password' do
|
||||
user = create_user
|
||||
user.encrypted_password = ''
|
||||
assert_not user.valid_password?('654321')
|
||||
refute user.valid_password?('654321')
|
||||
end
|
||||
|
||||
test 'should respond to current password' do
|
||||
@@ -152,7 +152,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should add an error to current password when it is invalid' do
|
||||
user = create_user
|
||||
assert_not user.update_with_password(current_password: 'other',
|
||||
refute user.update_with_password(current_password: 'other',
|
||||
password: 'pass4321', password_confirmation: 'pass4321')
|
||||
assert user.reload.valid_password?('12345678')
|
||||
assert_match "is invalid", user.errors[:current_password].join
|
||||
@@ -160,7 +160,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should add an error to current password when it is blank' do
|
||||
user = create_user
|
||||
assert_not user.update_with_password(password: 'pass4321',
|
||||
refute user.update_with_password(password: 'pass4321',
|
||||
password_confirmation: 'pass4321')
|
||||
assert user.reload.valid_password?('12345678')
|
||||
assert_match "can't be blank", user.errors[:current_password].join
|
||||
@@ -170,7 +170,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
user = UserWithValidation.create!(valid_attributes)
|
||||
user.save
|
||||
assert user.persisted?
|
||||
assert_not user.update_with_password(username: "")
|
||||
refute user.update_with_password(username: "")
|
||||
assert_match "usertest", user.reload.username
|
||||
assert_match "can't be blank", user.errors[:username].join
|
||||
end
|
||||
@@ -183,14 +183,14 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should not update password with invalid confirmation' do
|
||||
user = create_user
|
||||
assert_not user.update_with_password(current_password: '12345678',
|
||||
refute user.update_with_password(current_password: '12345678',
|
||||
password: 'pass4321', password_confirmation: 'other')
|
||||
assert user.reload.valid_password?('12345678')
|
||||
end
|
||||
|
||||
test 'should clean up password fields on failure' do
|
||||
user = create_user
|
||||
assert_not user.update_with_password(current_password: '12345678',
|
||||
refute user.update_with_password(current_password: '12345678',
|
||||
password: 'pass4321', password_confirmation: 'other')
|
||||
assert user.password.blank?
|
||||
assert user.password_confirmation.blank?
|
||||
@@ -217,14 +217,14 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should not destroy user with invalid password' do
|
||||
user = create_user
|
||||
assert_not user.destroy_with_password('other')
|
||||
refute user.destroy_with_password('other')
|
||||
assert user.persisted?
|
||||
assert_match "is invalid", user.errors[:current_password].join
|
||||
end
|
||||
|
||||
test 'should not destroy user with blank password' do
|
||||
user = create_user
|
||||
assert_not user.destroy_with_password(nil)
|
||||
refute user.destroy_with_password(nil)
|
||||
assert user.persisted?
|
||||
assert_match "can't be blank", user.errors[:current_password].join
|
||||
end
|
||||
@@ -236,12 +236,24 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
test 'should email on password change when configured' do
|
||||
test 'should notify previous email on email change when configured' do
|
||||
swap Devise, send_email_changed_notification: true do
|
||||
user = create_user
|
||||
original_email = user.email
|
||||
assert_email_sent original_email do
|
||||
assert user.update_attributes(email: 'new-email@example.com')
|
||||
end
|
||||
assert_match original_email, ActionMailer::Base.deliveries.last.body.encoded
|
||||
end
|
||||
end
|
||||
|
||||
test 'should notify email on password change when configured' do
|
||||
swap Devise, send_password_change_notification: true do
|
||||
user = create_user
|
||||
assert_email_sent user.email do
|
||||
assert user.update_attributes(password: 'newpass', password_confirmation: 'newpass')
|
||||
end
|
||||
assert_match user.email, ActionMailer::Base.deliveries.last.body.encoded
|
||||
end
|
||||
end
|
||||
|
||||
@@ -252,15 +264,15 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'required_fields should be encryptable_password and the email field by default' do
|
||||
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
||||
:email,
|
||||
:encrypted_password
|
||||
assert_equal Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
||||
:encrypted_password,
|
||||
:email
|
||||
]
|
||||
end
|
||||
|
||||
test 'required_fields should be encryptable_password and the login when the login is on authentication_keys' do
|
||||
swap Devise, authentication_keys: [:login] do
|
||||
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
||||
assert_equal Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
||||
:encrypted_password,
|
||||
:login
|
||||
]
|
||||
|
||||
@@ -46,7 +46,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
|
||||
test "should verify whether a user is locked or not" do
|
||||
user = create_user
|
||||
assert_not user.access_locked?
|
||||
refute user.access_locked?
|
||||
user.lock_access!
|
||||
assert user.access_locked?
|
||||
end
|
||||
@@ -56,7 +56,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
user.confirm
|
||||
assert user.active_for_authentication?
|
||||
user.lock_access!
|
||||
assert_not user.active_for_authentication?
|
||||
refute user.active_for_authentication?
|
||||
end
|
||||
|
||||
test "should unlock a user by cleaning locked_at, failed_attempts and unlock_token" do
|
||||
@@ -72,7 +72,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "new user should not be locked and should have zero failed_attempts" do
|
||||
assert_not new_user.access_locked?
|
||||
refute new_user.access_locked?
|
||||
assert_equal 0, create_user.failed_attempts
|
||||
end
|
||||
|
||||
@@ -83,7 +83,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
assert user.access_locked?
|
||||
|
||||
Devise.unlock_in = 1.hour
|
||||
assert_not user.access_locked?
|
||||
refute user.access_locked?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -162,18 +162,18 @@ class LockableTest < ActiveSupport::TestCase
|
||||
raw = user.send_unlock_instructions
|
||||
locked_user = User.unlock_access_by_token(raw)
|
||||
assert_equal locked_user, user
|
||||
assert_not user.reload.access_locked?
|
||||
refute user.reload.access_locked?
|
||||
end
|
||||
|
||||
test 'should return a new record with errors when a invalid token is given' do
|
||||
locked_user = User.unlock_access_by_token('invalid_token')
|
||||
assert_not locked_user.persisted?
|
||||
refute locked_user.persisted?
|
||||
assert_equal "is invalid", locked_user.errors[:unlock_token].join
|
||||
end
|
||||
|
||||
test 'should return a new record with errors when a blank token is given' do
|
||||
locked_user = User.unlock_access_by_token('')
|
||||
assert_not locked_user.persisted?
|
||||
refute locked_user.persisted?
|
||||
assert_equal "can't be blank", locked_user.errors[:unlock_token].join
|
||||
end
|
||||
|
||||
@@ -186,7 +186,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should return a new user if no email was found' do
|
||||
unlock_user = User.send_unlock_instructions(email: "invalid@example.com")
|
||||
assert_not unlock_user.persisted?
|
||||
refute unlock_user.persisted?
|
||||
end
|
||||
|
||||
test 'should add error to new user email if no email was found' do
|
||||
@@ -206,23 +206,23 @@ class LockableTest < ActiveSupport::TestCase
|
||||
swap Devise, unlock_keys: [:username, :email] do
|
||||
user = create_user
|
||||
unlock_user = User.send_unlock_instructions(email: user.email)
|
||||
assert_not unlock_user.persisted?
|
||||
refute unlock_user.persisted?
|
||||
assert_equal "can't be blank", unlock_user.errors[:username].join
|
||||
end
|
||||
end
|
||||
|
||||
test 'should not be able to send instructions if the user is not locked' do
|
||||
user = create_user
|
||||
assert_not user.resend_unlock_instructions
|
||||
assert_not user.access_locked?
|
||||
refute user.resend_unlock_instructions
|
||||
refute user.access_locked?
|
||||
assert_equal 'was not locked', user.errors[:email].join
|
||||
end
|
||||
|
||||
test 'should not be able to send instructions if the user if not locked and have username as unlock key' do
|
||||
swap Devise, unlock_keys: [:username] do
|
||||
user = create_user
|
||||
assert_not user.resend_unlock_instructions
|
||||
assert_not user.access_locked?
|
||||
refute user.resend_unlock_instructions
|
||||
refute user.access_locked?
|
||||
assert_equal 'was not locked', user.errors[:username].join
|
||||
end
|
||||
end
|
||||
@@ -257,7 +257,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
test 'required_fields should contain the all the fields when all the strategies are enabled' do
|
||||
swap Devise, unlock_strategy: :both do
|
||||
swap Devise, lock_strategy: :failed_attempts do
|
||||
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
||||
assert_equal Devise::Models::Lockable.required_fields(User), [
|
||||
:failed_attempts,
|
||||
:locked_at,
|
||||
:unlock_token
|
||||
@@ -269,7 +269,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
test 'required_fields should contain only failed_attempts and locked_at when the strategies are time and failed_attempts are enabled' do
|
||||
swap Devise, unlock_strategy: :time do
|
||||
swap Devise, lock_strategy: :failed_attempts do
|
||||
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
||||
assert_equal Devise::Models::Lockable.required_fields(User), [
|
||||
:failed_attempts,
|
||||
:locked_at
|
||||
]
|
||||
@@ -280,7 +280,7 @@ class LockableTest < ActiveSupport::TestCase
|
||||
test 'required_fields should contain only failed_attempts and unlock_token when the strategies are token and failed_attempts are enabled' do
|
||||
swap Devise, unlock_strategy: :email do
|
||||
swap Devise, lock_strategy: :failed_attempts do
|
||||
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
||||
assert_equal Devise::Models::Lockable.required_fields(User), [
|
||||
:failed_attempts,
|
||||
:unlock_token
|
||||
]
|
||||
|
||||
@@ -2,6 +2,6 @@ require 'test_helper'
|
||||
|
||||
class OmniauthableTest < ActiveSupport::TestCase
|
||||
test 'required_fields should contain the fields that Devise uses' do
|
||||
assert_same_content Devise::Models::Omniauthable.required_fields(User), []
|
||||
assert_equal Devise::Models::Omniauthable.required_fields(User), []
|
||||
end
|
||||
end
|
||||
|
||||
@@ -92,14 +92,14 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
user = create_user
|
||||
user.send_reset_password_instructions
|
||||
assert_present user.reset_password_token
|
||||
assert_not user.reset_password('123456789', '987654321')
|
||||
refute user.reset_password('123456789', '987654321')
|
||||
assert_present user.reset_password_token
|
||||
end
|
||||
|
||||
test 'should not reset password with invalid data' do
|
||||
user = create_user
|
||||
user.stubs(:valid?).returns(false)
|
||||
assert_not user.reset_password('123456789', '987654321')
|
||||
refute user.reset_password('123456789', '987654321')
|
||||
end
|
||||
|
||||
test 'should reset reset password token and send instructions by email' do
|
||||
@@ -119,7 +119,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should return a new record with errors if user was not found by e-mail' do
|
||||
reset_password_user = User.send_reset_password_instructions(email: "invalid@example.com")
|
||||
assert_not reset_password_user.persisted?
|
||||
refute reset_password_user.persisted?
|
||||
assert_equal "not found", reset_password_user.errors[:email].join
|
||||
end
|
||||
|
||||
@@ -135,7 +135,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
swap Devise, reset_password_keys: [:username, :email] do
|
||||
user = create_user
|
||||
reset_password_user = User.send_reset_password_instructions(email: user.email)
|
||||
assert_not reset_password_user.persisted?
|
||||
refute reset_password_user.persisted?
|
||||
assert_equal "can't be blank", reset_password_user.errors[:username].join
|
||||
end
|
||||
end
|
||||
@@ -164,13 +164,13 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
|
||||
test 'should return a new record with errors if no reset_password_token is found' do
|
||||
reset_password_user = User.reset_password_by_token(reset_password_token: 'invalid_token')
|
||||
assert_not reset_password_user.persisted?
|
||||
refute reset_password_user.persisted?
|
||||
assert_equal "is invalid", reset_password_user.errors[:reset_password_token].join
|
||||
end
|
||||
|
||||
test 'should return a new record with errors if reset_password_token is blank' do
|
||||
reset_password_user = User.reset_password_by_token(reset_password_token: '')
|
||||
assert_not reset_password_user.persisted?
|
||||
refute reset_password_user.persisted?
|
||||
assert_match "can't be blank", reset_password_user.errors[:reset_password_token].join
|
||||
end
|
||||
|
||||
@@ -179,7 +179,17 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
raw = user.send_reset_password_instructions
|
||||
|
||||
reset_password_user = User.reset_password_by_token(reset_password_token: raw, password: '')
|
||||
assert_not reset_password_user.errors.empty?
|
||||
refute reset_password_user.errors.empty?
|
||||
assert_match "can't be blank", reset_password_user.errors[:password].join
|
||||
assert_equal raw, reset_password_user.reset_password_token
|
||||
end
|
||||
|
||||
test 'should return a new record with errors if password is not provided' do
|
||||
user = create_user
|
||||
raw = user.send_reset_password_instructions
|
||||
|
||||
reset_password_user = User.reset_password_by_token(reset_password_token: raw)
|
||||
refute reset_password_user.errors.empty?
|
||||
assert_match "can't be blank", reset_password_user.errors[:password].join
|
||||
assert_equal raw, reset_password_user.reset_password_token
|
||||
end
|
||||
@@ -197,7 +207,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
assert_nil reset_password_user.reset_password_token
|
||||
|
||||
user.reload
|
||||
assert_not user.valid_password?(old_password)
|
||||
refute user.valid_password?(old_password)
|
||||
assert user.valid_password?('new_password')
|
||||
assert_nil user.reset_password_token
|
||||
end
|
||||
@@ -219,13 +229,13 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
user.reload
|
||||
|
||||
assert user.valid_password?(old_password)
|
||||
assert_not user.valid_password?('new_password')
|
||||
refute user.valid_password?('new_password')
|
||||
assert_equal "has expired, please request a new one", reset_password_user.errors[:reset_password_token].join
|
||||
end
|
||||
end
|
||||
|
||||
test 'required_fields should contain the fields that Devise uses' do
|
||||
assert_same_content Devise::Models::Recoverable.required_fields(User), [
|
||||
assert_equal Devise::Models::Recoverable.required_fields(User), [
|
||||
:reset_password_sent_at,
|
||||
:reset_password_token
|
||||
]
|
||||
@@ -245,7 +255,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'should return nil if a user based on the raw token is not found' do
|
||||
assert_equal User.with_reset_password_token('random-token'), nil
|
||||
assert_nil User.with_reset_password_token('random-token')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,6 +2,6 @@ require 'test_helper'
|
||||
|
||||
class RegisterableTest < ActiveSupport::TestCase
|
||||
test 'required_fields should contain the fields that Devise uses' do
|
||||
assert_same_content Devise::Models::Registerable.required_fields(User), []
|
||||
assert_equal Devise::Models::Registerable.required_fields(User), []
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,6 +16,18 @@ class RememberableTest < ActiveSupport::TestCase
|
||||
assert user.remember_created_at
|
||||
end
|
||||
|
||||
test 'remember_me should not generate a new token if valid token exists' do
|
||||
user = create_user
|
||||
user.singleton_class.send(:attr_accessor, :remember_token)
|
||||
User.to_adapter.expects(:find_first).returns(nil)
|
||||
|
||||
user.remember_me!
|
||||
existing_token = user.remember_token
|
||||
|
||||
user.remember_me!
|
||||
assert_equal existing_token, user.remember_token
|
||||
end
|
||||
|
||||
test 'forget_me should not clear remember token if using salt' do
|
||||
user = create_user
|
||||
user.remember_me!
|
||||
@@ -87,15 +99,28 @@ class RememberableTest < ActiveSupport::TestCase
|
||||
assert_nil User.serialize_from_cookie(user.to_key, "123", Time.now.utc)
|
||||
end
|
||||
|
||||
test 'raises a RuntimeError if the user does not implements a rememberable value' do
|
||||
user = User.new
|
||||
assert_raise(RuntimeError) { user.rememberable_value }
|
||||
|
||||
user_with_remember_token = User.new
|
||||
def user_with_remember_token.remember_token; '123-token'; end
|
||||
assert_equal '123-token', user_with_remember_token.rememberable_value
|
||||
|
||||
user_with_salt = User.new
|
||||
def user_with_salt.authenticatable_salt; '123-salt'; end
|
||||
assert_equal '123-salt', user_with_salt.rememberable_value
|
||||
end
|
||||
|
||||
test 'raises a RuntimeError if authenticatable_salt is nil or empty' do
|
||||
user = User.new
|
||||
def user.authenticable_salt; nil; end
|
||||
def user.authenticatable_salt; nil; end
|
||||
assert_raise RuntimeError do
|
||||
user.rememberable_value
|
||||
end
|
||||
|
||||
user = User.new
|
||||
def user.authenticable_salt; ""; end
|
||||
def user.authenticatable_salt; ""; end
|
||||
assert_raise RuntimeError do
|
||||
user.rememberable_value
|
||||
end
|
||||
@@ -150,7 +175,7 @@ class RememberableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'should have the required_fields array' do
|
||||
assert_same_content Devise::Models::Rememberable.required_fields(User), [
|
||||
assert_equal Devise::Models::Rememberable.required_fields(User), [
|
||||
:remember_created_at
|
||||
]
|
||||
end
|
||||
|
||||
@@ -35,6 +35,11 @@ class SerializableTest < ActiveSupport::TestCase
|
||||
assert_key "confirmation_token", from_json(force_except: :email)
|
||||
end
|
||||
|
||||
test 'should not include unsafe keys in inspect' do
|
||||
assert_match(/email/, @user.inspect)
|
||||
assert_no_match(/confirmation_token/, @user.inspect)
|
||||
end
|
||||
|
||||
def assert_key(key, subject)
|
||||
assert subject.key?(key), "Expected #{subject.inspect} to have key #{key.inspect}"
|
||||
end
|
||||
|
||||
@@ -7,11 +7,11 @@ class TimeoutableTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test 'should not be expired' do
|
||||
assert_not new_user.timedout?(29.minutes.ago)
|
||||
refute new_user.timedout?(29.minutes.ago)
|
||||
end
|
||||
|
||||
test 'should not be expired when params is nil' do
|
||||
assert_not new_user.timedout?(nil)
|
||||
refute new_user.timedout?(nil)
|
||||
end
|
||||
|
||||
test 'should use timeout_in method' do
|
||||
@@ -19,29 +19,29 @@ class TimeoutableTest < ActiveSupport::TestCase
|
||||
user.instance_eval { def timeout_in; 10.minutes end }
|
||||
|
||||
assert user.timedout?(12.minutes.ago)
|
||||
assert_not user.timedout?(8.minutes.ago)
|
||||
refute user.timedout?(8.minutes.ago)
|
||||
end
|
||||
|
||||
test 'should not be expired when timeout_in method returns nil' do
|
||||
user = new_user
|
||||
user.instance_eval { def timeout_in; nil end }
|
||||
assert_not user.timedout?(10.hours.ago)
|
||||
refute user.timedout?(10.hours.ago)
|
||||
end
|
||||
|
||||
test 'fallback to Devise config option' do
|
||||
swap Devise, timeout_in: 1.minute do
|
||||
user = new_user
|
||||
assert user.timedout?(2.minutes.ago)
|
||||
assert_not user.timedout?(30.seconds.ago)
|
||||
refute user.timedout?(30.seconds.ago)
|
||||
|
||||
Devise.timeout_in = 5.minutes
|
||||
assert_not user.timedout?(2.minutes.ago)
|
||||
refute user.timedout?(2.minutes.ago)
|
||||
assert user.timedout?(6.minutes.ago)
|
||||
end
|
||||
end
|
||||
|
||||
test 'required_fields should contain the fields that Devise uses' do
|
||||
assert_same_content Devise::Models::Timeoutable.required_fields(User), []
|
||||
assert_equal Devise::Models::Timeoutable.required_fields(User), []
|
||||
end
|
||||
|
||||
test 'should not raise error if remember_created_at is not empty and rememberable is disabled' do
|
||||
|
||||
@@ -2,7 +2,7 @@ require 'test_helper'
|
||||
|
||||
class TrackableTest < ActiveSupport::TestCase
|
||||
test 'required_fields should contain the fields that Devise uses' do
|
||||
assert_same_content Devise::Models::Trackable.required_fields(User), [
|
||||
assert_equal Devise::Models::Trackable.required_fields(User), [
|
||||
:current_sign_in_at,
|
||||
:current_sign_in_ip,
|
||||
:last_sign_in_at,
|
||||
|
||||
@@ -97,7 +97,7 @@ class ValidatableTest < ActiveSupport::TestCase
|
||||
|
||||
user.password_confirmation = 'confirmation'
|
||||
assert user.invalid?
|
||||
assert_not (user.errors[:password].join =~ /is too long/)
|
||||
refute (user.errors[:password].join =~ /is too long/)
|
||||
end
|
||||
|
||||
test 'should complain about length even if password is not required' do
|
||||
|
||||
@@ -13,7 +13,7 @@ class ActiveRecordTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
(Devise::ALL - modules).each do |mod|
|
||||
assert_not include_module?(klass, mod)
|
||||
refute include_module?(klass, mod)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -112,7 +112,7 @@ class CheckFieldsTest < ActiveSupport::TestCase
|
||||
attr_accessor :encrypted_password, :email
|
||||
end
|
||||
|
||||
assert_nothing_raised Devise::Models::MissingAttribute do
|
||||
assert_nothing_raised do
|
||||
Devise::Models.check_fields!(Player)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,19 +25,21 @@ class OmniAuthConfigTest < ActiveSupport::TestCase
|
||||
assert_equal OmniAuth::Strategies::Facebook, config.strategy_class
|
||||
end
|
||||
|
||||
test "finds the strategy in OmniAuth's list by name" do
|
||||
NamedTestStrategy = Class.new
|
||||
NamedTestStrategy.send :include, OmniAuth::Strategy
|
||||
NamedTestStrategy.option :name, :the_one
|
||||
class NamedTestStrategy
|
||||
include OmniAuth::Strategy
|
||||
option :name, :the_one
|
||||
end
|
||||
|
||||
test "finds the strategy in OmniAuth's list by name" do
|
||||
config = Devise::OmniAuth::Config.new :the_one, [{}]
|
||||
assert_equal NamedTestStrategy, config.strategy_class
|
||||
end
|
||||
|
||||
test "finds the strategy in OmniAuth's list by class name" do
|
||||
UnNamedTestStrategy = Class.new
|
||||
UnNamedTestStrategy.send :include, OmniAuth::Strategy
|
||||
class UnNamedTestStrategy
|
||||
include OmniAuth::Strategy
|
||||
end
|
||||
|
||||
test "finds the strategy in OmniAuth's list by class name" do
|
||||
config = Devise::OmniAuth::Config.new :un_named_test_strategy, [{}]
|
||||
assert_equal UnNamedTestStrategy, config.strategy_class
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ ActiveRecord::Base.include_root_in_json = true
|
||||
ActiveRecord::Migrator.migrate(File.expand_path("../../rails_app/db/migrate/", __FILE__))
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
if Devise.rails5?
|
||||
if Devise::Test.rails5?
|
||||
self.use_transactional_tests = true
|
||||
else
|
||||
# Let `after_commit` work with transactional fixtures, however this is not needed for Rails 5.
|
||||
|
||||
@@ -73,59 +73,3 @@ class ParameterSanitizerTest < ActiveSupport::TestCase
|
||||
assert_equal({ 'username' => 'jose' }, sanitized)
|
||||
end
|
||||
end
|
||||
|
||||
class DeprecatedParameterSanitizerAPITest < ActiveSupport::TestCase
|
||||
class CustomSanitizer < Devise::ParameterSanitizer
|
||||
def sign_in
|
||||
default_params.permit(:username)
|
||||
end
|
||||
end
|
||||
|
||||
def sanitizer(params)
|
||||
params = ActionController::Parameters.new(params)
|
||||
Devise::ParameterSanitizer.new(User, :user, params)
|
||||
end
|
||||
|
||||
test 'overriding instance methods have precedence over the default sanitized attributes' do
|
||||
assert_deprecated do
|
||||
params = ActionController::Parameters.new(user: { "username" => "jose", "name" => "Jose" })
|
||||
sanitizer = CustomSanitizer.new(User, :user, params)
|
||||
|
||||
sanitized = sanitizer.sanitize(:sign_in)
|
||||
|
||||
assert_equal({ "username" => "jose" }, sanitized)
|
||||
end
|
||||
end
|
||||
|
||||
test 'adding new parameters by mutating the Array' do
|
||||
assert_deprecated do
|
||||
sanitizer = sanitizer('user' => { 'username' => 'jose' })
|
||||
sanitizer.for(:sign_in) << :username
|
||||
sanitized = sanitizer.sanitize(:sign_in)
|
||||
|
||||
assert_equal({ 'username' => 'jose' }, sanitized)
|
||||
end
|
||||
end
|
||||
|
||||
test 'adding new parameters with a block' do
|
||||
assert_deprecated do
|
||||
sanitizer = sanitizer('user' => { 'username' => 'jose' })
|
||||
sanitizer.for(:sign_in) { |user| user.permit(:username) }
|
||||
|
||||
sanitized = sanitizer.sanitize(:sign_in)
|
||||
|
||||
assert_equal({ 'username' => 'jose' }, sanitized)
|
||||
end
|
||||
end
|
||||
|
||||
test 'removing multiple default parameters' do
|
||||
assert_deprecated do
|
||||
sanitizer = sanitizer('user' => { 'email' => 'jose', 'password' => 'invalid', 'remember_me' => '1' })
|
||||
sanitizer.for(:sign_in).delete(:email)
|
||||
sanitizer.for(:sign_in).delete(:password)
|
||||
sanitized = sanitizer.sanitize(:sign_in)
|
||||
|
||||
assert_equal({ 'remember_me' => '1' }, sanitized)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,5 +3,5 @@ require 'shared_user'
|
||||
class User < ActiveRecord::Base
|
||||
include Shim
|
||||
include SharedUser
|
||||
include ActiveModel::Serializers::Xml if Devise.rails5?
|
||||
include ActiveModel::Serializers::Xml if Devise::Test.rails5?
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ class HomeController < ApplicationController
|
||||
end
|
||||
|
||||
def unauthenticated
|
||||
if Devise.rails5?
|
||||
if Devise::Test.rails5?
|
||||
render body: "unauthenticated", status: :unauthorized
|
||||
else
|
||||
render text: "unauthenticated", status: :unauthorized
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
def facebook
|
||||
data = request.respond_to?(:get_header) ? request.get_header("omniauth.auth") : env["omniauth.auth"]
|
||||
data = request.respond_to?(:get_header) ? request.get_header("omniauth.auth") : request.env["omniauth.auth"]
|
||||
session["devise.facebook_data"] = data["extra"]["user_hash"]
|
||||
render json: data
|
||||
end
|
||||
@@ -9,6 +9,6 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
user = User.to_adapter.find_first(email: 'user@test.com')
|
||||
user.remember_me = true
|
||||
sign_in user
|
||||
render (Devise.rails5? ? :body : :text) => ""
|
||||
render (Devise::Test.rails5? ? :body : :text) => ""
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def update_form
|
||||
render (Devise.rails5? ? :body : :text) => 'Update'
|
||||
render (Devise::Test.rails5? ? :body : :text) => 'Update'
|
||||
end
|
||||
|
||||
def accept
|
||||
@@ -21,11 +21,11 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def exhibit
|
||||
render (Devise.rails5? ? :body : :text) => current_user ? "User is authenticated" : "User is not authenticated"
|
||||
render (Devise::Test.rails5? ? :body : :text) => current_user ? "User is authenticated" : "User is not authenticated"
|
||||
end
|
||||
|
||||
def expire
|
||||
user_session['last_request_at'] = 31.minutes.ago.utc
|
||||
render (Devise.rails5? ? :body : :text) => 'User will be expired on next request'
|
||||
render (Devise::Test.rails5? ? :body : :text) => 'User will be expired on next request'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,9 +3,15 @@ unless defined?(DEVISE_ORM)
|
||||
end
|
||||
|
||||
module Devise
|
||||
# Detection for minor differences between Rails 4 and 5 in tests.
|
||||
def self.rails5?
|
||||
Rails.version.start_with? '5'
|
||||
module Test
|
||||
# Detection for minor differences between Rails 4 and 5, and 5.1 in tests.
|
||||
def self.rails51?
|
||||
Rails.version.start_with? '5.1'
|
||||
end
|
||||
|
||||
def self.rails5?
|
||||
Rails.version.start_with? '5'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ RailsApp::Application.configure do
|
||||
# config.action_dispatch.rack_cache = true
|
||||
|
||||
# Disable Rails's static asset server (Apache or nginx will already do this).
|
||||
if Rails.version >= "4.2.0"
|
||||
if Rails.version >= "5.0.0"
|
||||
config.public_file_server.enabled = false
|
||||
elsif Rails.version >= "4.2.0"
|
||||
config.serve_static_files = false
|
||||
else
|
||||
config.serve_static_assets = false
|
||||
|
||||
@@ -14,15 +14,14 @@ RailsApp::Application.configure do
|
||||
|
||||
# Disable serving static files from the `/public` folder by default since
|
||||
# Apache or NGINX already handles this.
|
||||
if Rails.version >= "4.2.0"
|
||||
if Rails.version >= "5.0.0"
|
||||
config.public_file_server.enabled = true
|
||||
config.public_file_server.headers = {'Cache-Control' => 'public, max-age=3600'}
|
||||
elsif Rails.version >= "4.2.0"
|
||||
config.serve_static_files = true
|
||||
config.static_cache_control = "public, max-age=3600"
|
||||
else
|
||||
config.serve_static_assets = true
|
||||
end
|
||||
|
||||
if Rails.version >= "5.0.0"
|
||||
config.public_file_server.headers = {'Cache-Control' => 'public, max-age=3600'}
|
||||
else
|
||||
config.static_cache_control = "public, max-age=3600"
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
class CreateTables < ActiveRecord::Migration
|
||||
superclass = ActiveRecord::Migration
|
||||
# TODO: Inherit from the 5.0 Migration class directly when we drop support for Rails 4.
|
||||
superclass = ActiveRecord::Migration[5.0] if superclass.respond_to?(:[])
|
||||
|
||||
class CreateTables < superclass
|
||||
def self.up
|
||||
create_table :users do |t|
|
||||
t.string :username
|
||||
|
||||
@@ -8,7 +8,11 @@ module SharedAdmin
|
||||
allow_unconfirmed_access_for: 2.weeks, reconfirmable: true
|
||||
|
||||
validates_length_of :reset_password_token, minimum: 3, allow_blank: true
|
||||
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
|
||||
if Devise::Test.rails51?
|
||||
validates_uniqueness_of :email, allow_blank: true, if: :will_save_change_to_email?
|
||||
else
|
||||
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
|
||||
end
|
||||
end
|
||||
|
||||
def raw_confirmation_token
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user