Compare commits

...

224 Commits

Author SHA1 Message Date
Lucas Mazza
b68b400235 Test against JRuby. 2016-05-21 12:10:30 -03:00
Lucas Mazza
593ae41f9d Update existing Gemfiles. 2016-05-18 13:59:06 -03:00
Lucas Mazza
e9770fd434 Update Rails 5 Gemfile. 2016-05-18 13:50:07 -03:00
Lucas Mazza
53f6785e11 Fix Rails version reference on README.md [ci skip] 2016-05-18 13:42:31 -03:00
Lucas Mazza
1b48fd0abe Fix syntax highlight on README [ci skip] 2016-05-18 09:39:04 -03:00
Lucas Mazza
b835059baf Merge pull request #4118 from kamipo/patch-2
Fix release date in CHANGELOG.md
2016-05-17 10:05:48 -03:00
Ryuta Kamizono
f7359d6d96 Fix release date in CHANGELOG.md 2016-05-17 22:00:22 +09:00
Lucas Mazza
4924dd68ae Raise a more informative error when request.env['warden'] is nil.
Previously, a `NoMethodError` exception would be raised from here when the
middleware stack isn't present and Warden wasn't injected as expected
(like in a controller test). To foolproof ourselves, we now raise a more
informative error when `request.env['warden']` is `nil` so developers can
figure this out on their own instead of reaching to the issue tracker for
guidance.
2016-05-16 15:23:25 -03:00
Lucas Mazza
02ed166f51 Update CHANGELOG [ci skip] 2016-05-16 14:45:30 -03:00
Lucas Mazza
9a11586a72 Merge pull request #4071 from plataformatec/lm-test-helpers
Introduce `IntegrationHelpers` and deprecate `Devise::TestHelpers`.
2016-05-16 14:39:22 -03:00
Lucas Mazza
b5a5bae09c Tidy up ControllerHelpers implementation a bit. 2016-05-15 19:55:24 -03:00
Lucas Mazza
e757543323 Revisit docs on test helpers on README.md 2016-05-15 19:47:42 -03:00
Lucas Mazza
7b000390a0 Add Devise::Test::IntegrationHelpers. 2016-05-15 19:36:41 -03:00
Lucas Mazza
3f3ec236bb Move Devise::TestHelpers to Devise::Test::ControllerHelpers. 2016-05-15 19:36:41 -03:00
Lucas Mazza
22dd3b489d Merge pull request #4115 from wbotelhos/patch-1
removes bugfix, from unreleased, already shipped
2016-05-15 19:35:35 -03:00
Lucas Mazza
0d45142845 CONTRIBUTING.md edits
* Wrap lines to around ~80 characters.
* Suggest reporting issues with fresh apps that replicate the issue.
* Mention our policy regarding internationalizing Devise views.
2016-05-15 19:30:14 -03:00
Lucas Mazza
62d6b5afb7 Mention the bug report test case on CONTRIBUTING.md. 2016-05-15 19:24:59 -03:00
Lucas Mazza
934fe45cfe Drop _master suffix as the bug template doesnt use Rails/Devise master. 2016-05-15 19:21:50 -03:00
Lucas Mazza
675ae4d802 Lock devise version on the bug report template. 2016-05-15 19:20:32 -03:00
Lucas Mazza
48251f236f Use single quotes consistently through the integration test example. 2016-05-15 19:19:27 -03:00
Lucas Mazza
8e6e70eaa7 Merge pull request #4087 from leonardoprg/master
fix #3958 adding helper test to report bugs
2016-05-15 19:16:26 -03:00
Washington Botelho
4925ffda31 removes bugfix, from unreleased, already shipped 2016-05-15 13:51:41 -03:00
Ulisses Almeida
f89921e153 📝 Update with minor patch releases 2016-05-15 12:22:45 -03:00
Ulisses Almeida
863b811167 📝 Update CHANGELOG 2016-05-15 11:58:02 -03:00
Lucas Mazza
d1f8884ee6 Merge pull request #4105 from giedriusr/features/update_example_in_authenticatable
Update example code in authenticatable model
2016-05-15 11:49:02 -03:00
Ralin Chimev
9caf07dd4f Fix overwriting the remember_token when a valid one already exists (#4101)
The remember_token should not get overwritten when a user is
signing in and a valid token already exists.

Fixes #3950.
2016-05-15 11:48:12 -03:00
Ulisses Almeida
2044fffa25 Deprecate the bypass option of sign_in (#4078)
The sign_in method permits the bypass option
that ignore the others options used. This behavior
has lead some users to a misconfusion what the
method really does.

This change deprecate the bypass option in favor
of a method that only does the sign in with bypass.

Closes #3981
2016-05-15 11:46:48 -03:00
Giedrius Rimkus
2e442d81f7 Update example code in authenticatable model 2016-05-12 15:47:04 +03:00
Steven Spiel
28f0e3281a Consistency of quotation marks in README (#4103)
* Change double to single quotes in ruby code blocks

For consistency, I switched some of the double quotes to single quotes in the ruby code blocks.
2016-05-11 23:06:40 -03:00
Lucas Mazza
6a0d881554 Merge pull request #4104 from LucasAU/fix-omniauth-changeog
Fix suggested omniauth path
2016-05-11 22:37:32 -03:00
Lucas Nelson
4a9eee5a1c Fix suggested omniauth path
The suggested omniauth path noted in the CHANGELOG.md under 4.0.0.rc2 
did not work. It was missing an `_omniauth` in the middle of the 
method name.

user_github_authorize_path => user_github_omniauth_authorize_path
2016-05-12 10:24:47 +10:00
Vasiliy Ermolovich
a4d3b9f14a Merge pull request #4100 from shinyaK14/update_readme
Update README.md
2016-05-11 09:19:26 +03:00
Shinya Kitamura
1beac93961 Update README.md 2016-05-10 22:11:12 +08:00
Maarten van Vliet
8286325fd0 Remove reference to Rails 3.2 in post-install text (#4094) 2016-05-08 13:41:46 -03:00
Lucas Mazza
228f24c491 Merge pull request #4092 from bogdanvlviv/patch-5
Update .travis.yml
2016-05-06 22:11:57 -03:00
bogdanvlviv
cff78eec23 Update .travis.yml 2016-05-06 23:05:03 +03:00
Leonardo
20d786d7ca fix #3958 adding helper test to report bugs 2016-05-05 23:13:00 +01:00
Lucas Mazza
0c1b1a896f Update CHANGELOG [ci skip]. 2016-05-05 17:23:19 -03:00
Lucas Mazza
db8e247aa5 Document reload_routes on the app file template. 2016-05-05 17:23:05 -03:00
Lucas Mazza
e01fdba557 Merge pull request #4053 from sidonath/make-route-reloading-configurable
Make reloading of routes optional
2016-05-05 17:18:43 -03:00
Lucas Mazza
0a1e55f11c Update CHANGELOG [ci skip]. 2016-05-05 17:17:48 -03:00
Matt Yanchek
85bcbdf18b Set minimum password length for edit and new views (#4068)
* Set minimum password length for edit and new views

* Update edit.html.erb

* Update registerable_test.rb
2016-05-05 17:16:41 -03:00
Lucas Mazza
a45c4c0ac4 Update CHANGELOG.md. 2016-05-05 17:14:27 -03:00
Lucas Mazza
d293e00ef5 Merge pull request #4083 from plataformatec/lm-rm-deprecations
Remove deprecated APIs
2016-05-05 17:07:53 -03:00
Lucas Mazza
201a4f92c2 Remove deprecated Devise::Models::Recoverable#after_password_reset method. 2016-05-03 18:33:08 -03:00
Lucas Mazza
71f90c0d6e Remove deprecated Devise::Models::Recoverable#reset_password! method. 2016-05-03 18:33:08 -03:00
Lucas Mazza
26e22d8e95 Remove deprecated Devise::Models::Confirmable#confirm! method. 2016-05-03 18:33:08 -03:00
Lucas Mazza
9805728964 Remove deprecated Devise.bcrypt method. 2016-05-03 18:32:56 -03:00
Lucas Mazza
f64022a57b Remove deprecated OmniAuth URL helpers. 2016-05-03 18:32:56 -03:00
Lucas Mazza
e79201aef8 Remove deprecated ParameterSanitizer API. 2016-05-03 18:32:47 -03:00
Lucas Mazza
a2498074f1 Replace custom Array assertion with assert_equal. 2016-05-03 14:18:35 -03:00
Lucas Mazza
536279b05b Replace homemade assert_not matcher in favor of refute. 2016-05-03 13:57:10 -03:00
Lucas Mazza
031351224a Remove usage of ActiveSupport::Dependencies 3.x API. 2016-05-03 13:52:33 -03:00
Lucas Mazza
74ab3e9a05 Remove references to ActiveSupport::OrderedHash.
We no longer support legacy rubies where hashes aren't ordered, so we don't need
to use this class for it.
2016-05-03 13:48:42 -03:00
Ulisses Almeida
1bc9ebd7de Release 4.1.0 2016-05-02 23:51:49 -03:00
Ulisses Almeida
81869de9c5 Only set raise_in_transactional_callbacks for Rails 4.2
* Only set for active record orm.
* Only set for Rails versions that supports the config.
2016-05-02 23:22:51 -03:00
Ulisses Almeida
f6301c08f6 Add raise_in_transactional_callbacks to true
Using a rails app without this config generates a rails
warning, since it will be the new default. Let's udpate it.
2016-05-02 22:41:51 -03:00
Ulisses Almeida
d66d9297fb 📝 Update the CHANGELOG 2016-05-02 22:34:07 -03:00
ALLEN WANG QIANG
78bbf6dcc4 Send on create confirmation email after commit (#4064)
Call send_on_create_confirmation_instructions in after_commit instead of after_create, I think this is no harm in general and it makes things like async job work.

Fix #4062
2016-05-02 21:32:14 -03:00
Ulisses Almeida
1ff64fbbd3 Merge pull request #4076 from f3ndot/issue-4072-unlock-strategy-enabled-bug
Fix strategy checking in #unlock_strategy_enabled? for :none and undefined strategies
2016-05-02 21:28:49 -03:00
Justin Bull
3226ab16c1 Extract list of both strategies into class constant 2016-05-02 14:22:09 -04:00
Lucas Mazza
13285d7ef3 Remove a few Ruby syntax warnings from the test suite. 2016-05-02 10:47:05 -03:00
Justin Bull
7346ce709a 🪲 Fix strategy checking in #unlock_strategy_enabled? for :none and undefined strategies
A bug that if the unlock strategy was set to `:both`, it would return true for all & any inputs

See #4072
2016-05-01 13:56:12 -04:00
Ulisses Almeida
8ac32f14b1 Merge pull request #4061 from plataformatec/ua-remove-config-deprecations
Set the new defaults for Devise 4.1

In our configuration template we explicit set some configurations as recommended defaults.
Now we are enforcing these configurations to be the defaults.
It also removes all warning code about this change.
2016-05-01 13:12:21 -03:00
Ulisses Almeida
91ef42dc0a Remove remaining code of setup deprecation warning
Since all configurations are using the current
recomended defaults. We can remove this deprecation
warning for Devise 4.1.
2016-05-01 12:44:40 -03:00
Ulisses Almeida
1ddca80cee Set the new default of sign_out_via config 2016-05-01 12:44:40 -03:00
Ulisses Almeida
896521be73 Se the new default for skip_session_storage config 2016-05-01 12:44:40 -03:00
Ulisses Almeida
6e419ce821 Set the new default for reconfirmable config 2016-05-01 12:44:40 -03:00
Ulisses Almeida
93df02f601 Set the new default for strip_whitespace_keys config 2016-05-01 12:44:40 -03:00
José Valim
fdd9337b64 Merge pull request #4066 from sbc100/friendly_token
Friendly token
2016-04-30 10:03:04 +02:00
Lucas Mazza
2040b021e1 Extend the deprecation horizon for the ParameterSanitizer and the OmniAuth helpers. 2016-04-29 16:20:01 -03:00
Sam Clegg
d122faf410 Use friendly_token over token_generator when only raw value is needed
The first value returned by token_generator.generate is
simply the return value of friendly_token so this code should
be equivalent.

The use of token_generator here dates back to when the
confirmation_token was stored as a digest, but that is no
longer true.
2016-04-27 10:44:15 -04:00
Sam Clegg
eaa4713e22 Consistent use of save method 2016-04-26 15:16:13 -04:00
Ulisses Almeida
0c1a14e8f2 📝 Update the CHANGELOG 2016-04-26 11:32:15 -03:00
byzg
357ce9c3b5 Humanize authentication keys in failure flash message (#4014)
Humanize and translates the authentication keys in failure flash message.
2016-04-26 11:17:03 -03:00
kimgb
830d3e86ee updated email_regexp and added test cases (#4001)
Add a more permissive default e-mail regex.
2016-04-26 11:13:07 -03:00
Philipe Fatio
209b97d86b Remove upgrade path for old session format (#4032)
This removes an upgrade path that migrated the old serialization format
to the new one introduced. This was introduced in c22d755 (#2300)
3 years ago and should no longer be needed.
2016-04-26 11:10:55 -03:00
Ulisses Almeida
4da955d9cd Release 4.0.1 2016-04-25 17:06:05 -03:00
Ulisses Almeida
bff701758a Merge pull request #4043 from lmduc/master
Send confirmation instructions when a user updates the email address from nil
2016-04-25 16:42:55 -03:00
Ulisses Almeida
90acc6fc23 Change the check for permit! method
We are using the `permit!` method, we should check
for `permit!`.
2016-04-22 20:36:55 -03:00
Damir Zekic
eba2527b8e Make reloading of routes optional
As has been seen in a previous pull request, some applications require
routes to be loaded before the code is eagerly loaded, which implies
that all Rails applications using Devise need to have routes reloaded
twice:
https://github.com/plataformatec/devise/pull/3241

This can incur a very significant slowdown for large apps that have a
lot of routes or a lot of controllers, so reloading should be optional.
2016-04-21 00:10:17 -03:00
Ulisses Almeida
48220f087b Merge pull request #4050 from cadejscroggins/master
Make sure attribute_will_change! method exists before calling it
2016-04-20 23:10:25 -03:00
Cade Scroggins
26b17abb01 Remove attribute_will_change! method as it is unnecessary 2016-04-20 20:23:03 -05:00
Lucas Mazza
22468f3756 Merge pull request #3855 from joshsoftware/mongoid_dep
Upgrade Mongoid to 5.0
2016-04-19 10:14:26 -03:00
Yogesh Khater
9696d83e7d Upgrade Mongoid to 5.0 2016-04-19 17:18:40 +05:30
Lucas Mazza
940ca4f2b8 Release 4.0.0. version. 2016-04-18 11:52:49 -03:00
Ulisses Almeida
f38250245f 📝 Update CHANGELOG 2016-04-18 11:46:29 -03:00
Ulisses Almeida
4c7c27f73e Merge pull request #4044 from plataformatec/ua-remember-me
Remove deprecated argument of `remember_me!`
2016-04-18 11:45:46 -03:00
Ulisses Almeida
7a235849cf Remove deprecated argument of remember_me! 2016-04-18 11:14:01 -03:00
Ulisses Almeida
846ba80480 Merge pull request #4039 from plataformatec/ua-fix-remember-me
Fix extented remember me
2016-04-18 11:07:02 -03:00
Ulisses Almeida
93d98b6450 Merge pull request #4036 from plataformatec/ua-defaults-review
Add warning about default config change
2016-04-18 11:06:32 -03:00
MatBi
7d10019d2a Should check email present 2016-04-18 19:52:31 +08:00
MatBi
274f8f2f87 Should send confirmation instructions after changing email from nil 2016-04-18 19:35:56 +08:00
MatBi
3360b10c2f Skip reconfirmation in case that a record is created with #save called in callback 2016-04-18 19:32:54 +08:00
MatBi
6f9561e64f Refactor a test 2016-04-18 18:30:20 +08:00
MatBi
016b216d95 Change the name of variables to keep the tests consistent 2016-04-18 18:15:32 +08:00
Ulisses Almeida
164134c78a Add warning about default config change
This change add warnings for these configurations:

* strip_whitespace_keys - It is already explicit on config template, now
it will be the same of the template.
* email_regexp - In the new version this regexp will be more
permissive.
* reconfirmable - It is already explicit on config template, now
it will be the same of the template.
* skip_session_storage - It is already explicit on config template, now
it will be the same of the template.
* sign_out_via - It is already explicit on config template, now
it will be the same of the template.

These ones is important to change, since the configuration says current
explicit value are the default. It can lead to misunderstanging if users
remove the explicit configuration.

It also updates the template explicit values:

* Warns the `config.mailer_sender` is nil by default
* Update `config.password_length` to use the current default
* Make the e-mail configuration explicit
2016-04-15 20:31:54 -03:00
Ulisses Almeida
4a4b5ba196 Fix remember me always extending the period
Now the config `extend_remember_period` is used to:

`true` - Every time the user authentication is validated, the
cookie expiration is updated.
`false` - Does not updates the cookie expiration.

Closes #3994
2016-04-15 20:28:46 -03:00
Lucas Mazza
c87d8fda82 Merge pull request #4041 from plataformatec/ua-fix-rails5-build
Fix Rails 5 build
2016-04-15 17:50:04 -03:00
Ulisses Almeida
48af3e8249 Fix Rails 5 build
With this [PR](https://github.com/rails/activemodel-serializers-xml/pull/8)
of activemodel-serializers bundle will require it by default.
2016-04-15 16:57:35 -03:00
Ulisses Almeida
57d150e535 Merge pull request #4031 from tomkadwill/readme_changes
Update README
2016-04-12 11:26:47 -03:00
Carlos Antonio da Silva
d9f97fc9a4 Merge pull request #4035 from bogdanvlviv/deprecated
fix method name for File
2016-04-12 07:40:29 -03:00
Tom Kadwill
9cdf7860d5 Update README 2016-04-12 09:22:16 +01:00
bogdanvlviv
0f11c0f6b3 fix method name for File 2016-04-12 09:03:54 +03:00
Ulisses Almeida
9914ff32ec Merge pull request #4004 from bogdanvlviv/patch-4
removed deprecated private method Devise::Controllers::Helpers#expire_session_data_after_sign_in!
2016-04-11 16:30:36 -03:00
Lucas Mazza
728bf0c956 Merge pull request #4033 from codeodor/patch-2
Note change to Rails 5 that affects Devise example
2016-04-10 18:49:30 -03:00
Sammy Larbi
c520e93733 Note change to Rails 5 that affects Devise example
[A change in Rails 5](3979403781) left me hunting for hours on why I could no longer log in to my application. To save others the trouble, I thought it would be nice to note it in the README.
2016-04-09 17:55:20 -05:00
Ulisses Almeida
b397d33246 Merge pull request #4005 from bogdanvlviv/dependencies
change rails version from 4.2.5 to 4.2.6
2016-04-08 17:04:02 -03:00
Bogdan
aa25e2080e removed deprecated private method Devise::Controllers::Helpers#expire_session_data_after_sign_in! 2016-03-30 18:10:16 +03:00
Carlos Antonio da Silva
2b3799e6ce Merge pull request #4010 from bogdanvlviv/patch-5
Update .travis.yml
2016-03-26 09:22:33 -03:00
Bogdan
2af3a83ef4 Update .travis.yml 2016-03-26 03:48:33 +02:00
bogdanvlviv
c3c2438c9c change rails version from 4.2.5 to 4.2.6 2016-03-23 21:21:58 +02:00
Lucas Mazza
69bee06cee Merge pull request #3993 from totothink/master
unified use pending_reconfirmation? method
2016-03-12 14:34:21 -03:00
aaron
c70eb0a5a8 unified use pending_reconfirmation? method 2016-03-12 07:10:20 +08:00
Lucas Mazza
db901399f2 Fix Symbol syntax no deprecation message. 2016-03-09 15:59:00 -03:00
Lucas Mazza
d0e5a1d252 Update CHANGELOG [ci skip] 2016-03-09 11:34:14 -03:00
Lucas Mazza
ccda4692b4 Add a bin/test executable to use Rails 5 Minitest report. 2016-03-09 11:16:21 -03:00
Lucas Mazza
e6563bc4cb Update Gemfile's dependencies. 2016-03-09 11:13:04 -03:00
Lucas Mazza
1c2328bb90 Prep for 4.0.0.rc2 release. 2016-03-09 11:01:50 -03:00
Lucas Mazza
9ec126bd8b Update CHANGELOG [ci skip] 2016-03-09 11:00:04 -03:00
Lucas Mazza
b3cc3db49e Merge pull request #3991 from plataformatec/lm-deprecate-old-omniauth-helpers
Deprecate legacy OmniAuth URL helpers.
2016-03-09 10:55:33 -03:00
Lucas Mazza
5b1182460c Deprecate legacy OmniAuth URL helpers. 2016-03-09 10:36:39 -03:00
Lucas Mazza
76f76249e7 Merge pull request #3985 from plataformatec/lm-omniauth-route-helpers
Do not use the dynamic `:action` segment on Omniauth routes.
2016-03-07 11:50:35 -03:00
Lucas Mazza
353b14f473 Use versioned migrations when possible
Rails 5 deprecates inheriting directly from `ActiveRecord::Migration` in
favor of inheriting from `ActiveRecord::Migration[5.0]` where `5.0` is
the `major.minor` version of Rails that the migration was originally
written to support.

h/t to b0ce189c69.
2016-03-07 11:38:37 -03:00
Lucas Mazza
ec07bdb315 Do not use the dynamic :action segment on Omniauth routes.
This was deprecated on rails/rails#23980.

We now generate scope and provider specific routes, like `user_facebook_omniauth_callback`
or `user_github_omniauth_callback`.

We could deprecate the `omniauth_authorize_path` in favor of the generated routes, but
the `shared/links.html.erb` depends on it to generate all omniauth links at once.

Closes #3983.
2016-03-07 11:19:27 -03:00
José Valim
9ece7da447 Merge pull request #3984 from jeroenvisser101/remove-trailing-whitespace-from-view
Remove trailing whitespace from confirmation view
2016-03-07 13:08:53 +01:00
Jeroen Visser
b214333760 Remove trailing whitespace from confirmation view
Though not a real issue, it was highlighted as an error by my commit
hooks, so I took the opportunity to fix it.
2016-03-07 10:07:34 +01:00
Vasiliy Ermolovich
3423043759 Merge pull request #3961 from anthonyto/clarify_confirmation_comments
Clarify allow_unconfirmed_access_for comments in confirmation module
2016-02-18 09:54:06 +03:00
Anthony To
8c636ef08a Clarify allow_unconfirmed_access_for comments in confirmation module 2016-02-18 13:35:13 +11:00
Lucas Mazza
a9b94f5eb9 Update CHANGELOG. 2016-02-15 10:19:08 -02:00
Lucas Mazza
c228227bc1 Tweak no ORM check on InstallGenerator.
* Expand the explanation of why it fail.
* Raise a subclass of `Thor::Error` so the Thor doesn't output the exception
  backtrace as it isn't useful for developers facing this error.
2016-02-15 10:16:43 -02:00
José Valim
0c46373c20 Merge pull request #3954 from arjunsharma/master
Raise error if no ORM is found during install generator
2016-02-14 23:11:05 +01:00
Arjun Sharma
648ed3b412 Raise error if no ORM is found during install generator 2016-02-14 14:59:38 -07:00
Lucas Mazza
cecb3ee45b Merge pull request #3921 from oss92/reduce_complexity
Added DeviseController#set_flash_message!
2016-02-11 14:38:03 -02:00
George Guimarães
4585281da4 Devise is already thread-safe and has been working in production on both YARV and JRuby. 2016-02-11 13:29:42 -02:00
George Guimarães
014859ecff Merge branch 'gg-correct-encryption-meaning' 2016-02-11 13:25:49 -02:00
George Guimarães
1f36946f43 Merge pull request #3941 from SimonDKnight/FixDocumentationTestHelpers
Added clarity to documentation regarding where to place test helpers …
2016-02-10 23:42:19 -02:00
George Guimarães
9efc601c73 Merge branch 'jetheredge-patch-2' 2016-02-10 23:28:13 -02:00
Justin Etheredge
dc7e7d66c9 Increase default stretches to 11 2016-02-10 23:27:21 -02:00
oss92
18528650c3 Added DeviseController#set_flash_message! 2016-02-11 02:49:53 +02:00
Simon Knight
a371f03c51 Update README.md
Added formatting to file.
2016-02-10 21:11:57 +00:00
José Valim
f173040222 Merge pull request #3946 from plataformatec/gg-remove-hakiri
Removes Hakiri, since it thinks Devise is a Rails app
2016-02-10 22:06:46 +01:00
George Guimarães
b74235d4a1 Removes Hakiri, since it thinks Devise is a Rails app
I'd like to remove the Hakiri badge from devise's README.

Since we do check in Gemfile and Gemfile.lock for development
and testing purposes (contrary to the popular belief that gems
don't need those files), Hakiri thinks Devise is a Rails app,
instead of a library/gem.

Depending on the Rails version that is locked in Gemfile.lock,
Hakiri will show several CVEs for Rails. But our Travis pipeline
builds against several Rails' branches, all of them updated.

And it is up to the developers using Devise to update
Rails in their apps.

Those warnings (Rails CVEs) don't make sense for devise.
2016-02-10 18:43:33 -02:00
George Guimarães
4b8ea5d0f0 Updates the development/testing dependencies 2016-02-10 18:37:16 -02:00
George Guimarães
79e861b52b Reorder travis builds to prioritize newer ruby and rails versions 2016-02-10 17:20:36 -02:00
George Guimarães
c4b4411513 Change encryption for hashing in the documentation.
Throughout the documentations, we are using 'encrypt' incorrectly.
Encrypt means that someone will eventually decrypt the message,
which is obviously not the case for Devise.

I'm changing the docs to use 'hashing' instead.

However, I left the database field as `encrypted_password` for now.
I'll update the db field in an upcoming PR.
2016-02-10 17:10:52 -02:00
Lucas Mazza
7b33a8ef57 Merge pull request #3931 from giantmonkey/fix-spelling-of-verb-set-up
Spell verb *set up* with a space
2016-02-10 17:06:38 -02:00
Simon Knight
1dd315ce1d Added clarity to documentation regarding where to place test helpers for functional tests 2016-02-09 13:29:42 +00:00
José Valim
7c75ebe672 Merge pull request #3936 from bogdanvlviv/patch-3
Update confirmable_test.rb
2016-02-06 20:11:11 +01:00
bogdanvlviv
d9481ff9b8 Update confirmable_test.rb 2016-02-06 20:37:31 +02:00
Carlos Antonio da Silva
f0c39e08ca Merge pull request #3934 from bogdanvlviv/patch-2
change call deprecated method confirm! to confirm in test
2016-02-03 18:15:39 -02:00
Bogdan
d3fa53151a change call deprecated method confirm! to confirm in test 2016-02-03 22:09:38 +02:00
Paul Menzel
f2d7b8f740 Spell verb *set up* with a space
The verb *set up* is spelled with a space [1].

```
$ git grep -l 'to setup' | xargs sed -i 's/to setup/to set up/g'
$ git grep -l '# Setup' | xargs sed -i 's/# Setup/# Set up/g'
$ git grep -l "test 'setup" | xargs sed -i "s/test 'setup/test 'set up/g"
```

Revert the change for *setup block yields self*.

Change the rest manually.

[1] http://www.merriam-webster.com/dictionary/set%20up
2016-02-02 19:09:19 +01:00
Lucas Mazza
beb8cc8e0b Test against Rails 5 beta 2. 2016-02-02 14:28:34 -02:00
Lucas Mazza
17d6a74909 oauth2 1.1.0 is out. 2016-02-01 10:39:10 -02:00
Lucas Mazza
aab7610808 Release 4.0.0.rc1. 2016-02-01 09:20:42 -02:00
Lucas Mazza
8edee143e8 Prep for 4.0.0.rc1 release. 2016-01-31 17:05:16 -02:00
Lucas Mazza
49cf804c62 Merge pull request #3859 from twalpole/unsafe_h
Explicitly permit rather than using to_unsafe_h
2016-01-31 16:56:10 -02:00
Lucas Mazza
8ab738307e Merge pull request #3927 from plataformatec/lm-cookie-fix
Attempt to coerce the `generated_at` cookie to a `Time` object.
2016-01-31 16:23:31 -02:00
Carlos Antonio da Silva
9d9adc73cd Merge pull request #3928 from gfvcastro/remove-optional-parenthesis
Remove optional parenthesis.
2016-01-30 18:08:50 -02:00
Gustavo Villa
91f93b38ee Remove optional parenthesis. 2016-01-30 14:20:32 -03:00
Lucas Mazza
7bff3be869 Attempt to coerce the generated_at cookie to a Time object.
Time objects aren't properly coerced back when using the JSON cookie serialization,
so we need to do it ourselves.

To avoid any new JSON serialization issues, we now store the `generated_at` as
an String with the timestamp seconds + miliseconds in the cookie but still the
previous JSON encoded format.

Thanks to @boblail at https://github.com/plataformatec/devise/pull/3917 for the
initial patch.
2016-01-29 18:04:16 -02:00
Lucas Mazza
475599d4ab Merge pull request #3926 from schneems/schneems/fix-version
[close 3925] Fix version for older Bundler compat
2016-01-29 14:57:42 -02:00
schneems
7d81731d4f [close 3925] Fix version for older Bundler compat 2016-01-29 10:56:13 -06:00
Lucas Mazza
ffe9d6d406 Fix Symbol syntax on ParameterSanitizer deprecation message. 2016-01-28 11:10:15 -02:00
Lucas Mazza
cf7c9be6b4 Merge pull request #3919 from twalpole/gemfiles
switch to oauth2 home repository
2016-01-27 15:58:57 -02:00
Thomas Walpole
3e80c9a80f switch to oauth2 home repository 2016-01-27 09:03:01 -08:00
Lucas Mazza
c6cf035037 Merge pull request #3918 from plataformatec/lm-serialized_in_cookie
Refactor `Rememberable#serialized_in_cookie?` to split class/instance API
2016-01-27 14:44:12 -02:00
Lucas Mazza
6008885152 Refactor Rememberable.serialized_in_cookie? to split class/instance API.
We now expose a `remember_me?` instance method as internal API for the controller
layer check if the remember me cookie is still valid.
2016-01-27 14:11:26 -02:00
Lucas Mazza
0c7f8764c9 Bump Gemfile dependencies. 2016-01-27 13:52:37 -02:00
José Valim
d1d8c2f03d Ensure generated_at is a Time
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2016-01-25 11:17:18 +01:00
José Valim
b97b3e6e3b Do not timeout if remember me is enabled
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2016-01-22 16:19:10 +01:00
Lucas Mazza
cc02d06c58 Remove Rails 3.2 compatibility fix. 2016-01-18 13:59:27 -02:00
Lucas Mazza
b91bbb1590 Tweak ParameterSanitizer exception/deprecation messages. 2016-01-18 13:51:51 -02:00
José Valim
52b1ca2d80 Bump to dev version 2016-01-18 15:22:00 +01:00
José Valim
4ec7dc0f27 Store creation timestamp on remember cookies
Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2016-01-18 15:17:25 +01:00
Lucas Mazza
0a4da78b22 Add a notice to README regarding the sanitizer API change. 2016-01-17 12:53:31 -02:00
José Valim
aa3f64976f Merge pull request #3898 from kulte/master
Consistent formatting of file arguments to autoload
2016-01-13 23:10:38 +01:00
Zachary Friedman
260fa1a2e2 It would appear that consistency with the indentation used in the top-level Devise module would dictate this formatting change 2016-01-13 14:03:21 -08:00
José Valim
a321282ccc Merge pull request #3893 from retrospective5/updated-readme
Add link to devise_for documentation
2016-01-07 22:37:30 +01:00
araa
6f91baf99c Add link to devise_for documentation 2016-01-07 14:37:02 -05:00
José Valim
1a7f2195a2 Merge pull request #3891 from obduk/parent_mailer
Add parent_mailer to lib/generators/templates/devise.rb
2016-01-06 14:08:26 +01:00
Owen Davies
e5797001a7 Add parent_mailer to lib/generators/templates/devise.rb 2016-01-06 13:00:54 +00:00
Lucas Mazza
f0b937c538 Test against Ruby 2.3.0. 2016-01-05 14:48:10 -02:00
Carlos Antonio da Silva
9639bf8cc1 Merge pull request #3883 from Atul9/master
Update copyright notices to 2016 [ci skip]
2016-01-04 10:42:13 -02:00
José Valim
27e1588685 Merge pull request #3885 from dcmorse/master
Documentation clarification to README.md
2016-01-04 09:59:23 +01:00
Dave Morse
42fac75e8e Clarify previous clarification to README.md 2016-01-03 17:06:34 -05:00
Dave Morse
37b7e9b850 README.md: clarified how to include Devise::TestHelpers for :view tests.
Also clarified that including Devise::TestHelpers during integration tests is a mistake.
source: https://github.com/plataformatec/devise/issues/3881
2016-01-03 16:50:47 -05:00
Atul Bhosale
48e26c5d0a Update copyright notices to 2016 [ci skip] 2016-01-03 15:58:16 +05:30
Lucas Mazza
1d77099861 Merge pull request #3875 from james/master
Update controller generator templates for new ParameterSanitizer syntax
2015-12-27 22:53:01 -02:00
James Darling
924a989f37 Update controller generator templates for new ParameterSanitizer syntax
Devise::ParameterSanitizer has a new syntax for permitting additional
attributes to a model. This commit updates the generated controllers to
reflect that.
2015-12-28 00:45:03 +00:00
Lucas Mazza
6431445846 Cast the result of deperecated sanitization calls to a HWIA as well. 2015-12-21 09:57:20 -02:00
Lucas Mazza
8d57a54b2d ✂️ Remove custom Travis cache scripts. 2015-12-21 09:46:11 -02:00
Lucas Mazza
280d12b81c Merge pull request #3856 from plataformatec/lm-sanitizer-cleanup
Remove `ParametersSanitizer` inheritance.
2015-12-21 09:40:59 -02:00
Lucas Mazza
00a0b8e516 Fix duplicated exclude entry. 2015-12-20 23:02:52 -02:00
Lucas Mazza
238ccb15b5 Test against the beta Rails release. 2015-12-20 22:56:13 -02:00
Lucas Mazza
ace7b55a1a Merge pull request #3868 from twalpole/gemfile_update
update rails 5 gemfile with compatbile gem releases
2015-12-20 21:03:06 -02:00
Thomas Walpole
97ab41728e update rails 5 gemfile with compatbile gem releases 2015-12-20 12:31:51 -08:00
Lucas Mazza
acd9f84802 Merge pull request #3866 from plataformatec/lm-remove-key-generator
Remove `KeyGenerator` implementation ported from Rails 4.x.
2015-12-18 15:18:15 -02:00
Lucas Mazza
a24ecc65f5 Remove KeyGenerator implementation ported from Rails 4.x. 2015-12-18 14:49:50 -02:00
Lucas Mazza
4e45a5fde4 Remove Rails version mention from the initializer template. 2015-12-18 14:47:32 -02:00
Lucas Mazza
9499736593 Remove safeguard against a previously broken NullSessionHash#reset_session.
This behavior was fixed on https://github.com/rails/rails/pull/12279.
2015-12-18 14:47:32 -02:00
Lucas Mazza
df8b48646b Remove ParametersSanitizer inheritance.
We no longer need to support the `BaseSanitizer` implementation for apps without
the Strong Parameters API, and this section is lacking a minimal set of
docs to document the expected behavior besides the `README` section.
2015-12-18 11:39:03 -02:00
Lucas Mazza
b4904a4ba2 Merge pull request #3865 from djsegal/rails5
Add #3732 helper logic to devise controller
2015-12-18 10:53:14 -02:00
djsegal
2006f87b58 Add #3732 helper logic to devise controller: #3864 2015-12-18 04:05:30 -05:00
Thomas Walpole
5d9f6d892f Explicitly permit rather than using to_unsafe_h 2015-12-16 14:14:15 -08:00
Lucas Mazza
1ac4bdd090 Merge pull request #3857 from twalpole/test_fix
Fix Rails 5 test
2015-12-16 10:01:18 -02:00
Thomas Walpole
302c4e43bd fix Rails 5 test 2015-12-15 10:32:24 -08:00
Lucas Mazza
f5926f6514 Do not send Travis notifications of Pull Requests. 2015-12-15 15:26:08 -02:00
Lucas Mazza
330e0f7165 Update lockfile. 2015-12-15 14:55:36 -02:00
Lucas Mazza
42376db763 Update Devise version on README [ci skip] 2015-12-15 11:52:26 -02:00
Lucas Mazza
1147badf7c Update Rails dependency contrainst to support the stable 5.0.0 release. 2015-12-15 11:49:44 -02:00
Lucas Mazza
7b000390ac Update CHANGELOG.md [ci skip] 2015-12-15 11:48:41 -02:00
Lucas Mazza
dd5de829c9 Merge pull request #3714 from twalpole/rails5
Rails 5 Support
2015-12-15 11:44:01 -02:00
Lucas Mazza
2f7834245b Merge pull request #3835 from kv109/master
test for save in after_create hook breaks devise confirmation [3787]
2015-12-15 11:36:47 -02:00
Lucas Mazza
78d2654fb4 Merge pull request #3793 from chrismacias/save_in_after_create_hook_breaks_devise_confirmation
save in after_create hook breaks devise confirmation
2015-12-15 11:36:34 -02:00
José Valim
934dbd1f5a Merge pull request #3854 from joshsoftware/reset_password_token_issue
Comparing times in UTC
2015-12-15 11:55:24 +01:00
Siva Gollapalli
23933d2fb0 FIX# Comparing times in UTC 2015-12-15 15:17:11 +05:30
José Valim
76bbbb8ed5 Merge pull request #3853 from betesh/betesh-patch-1
Removed unnecessary module fixes #3852
2015-12-15 09:35:12 +01:00
betesh
8701a88c94 Removed unnecessary module 2015-12-15 02:52:17 -05:00
Thomas Walpole
2024fca4df Rails 5 compatability. Remove rails < 4.1 and Ruby < 2.1 2015-12-11 09:47:30 -08:00
Kacper Walanus
a0cd4655ba test for save in after_create hook breaks devise confirmation [3787] 2015-11-24 01:54:03 +01:00
Christian Macias
54bb30a1a4 changed email_was !='' to email_was.present? 2015-10-26 08:56:14 -07:00
Christian Macias
5ae6360e75 fix for #3787, save in after_create hook breaks devise confirmation 2015-10-22 13:05:02 -07:00
134 changed files with 2657 additions and 3230 deletions

View File

@@ -1,23 +1,27 @@
language: ruby language: ruby
rvm: rvm:
- 1.9.3 - 2.1.9
- 2.0.0 - 2.2.5
- 2.1 - 2.3.1
- 2.2 - ruby-head
- jruby-9.0.5.0
gemfile: gemfile:
- Gemfile
- gemfiles/Gemfile.rails-5.0
- gemfiles/Gemfile.rails-4.2-stable - gemfiles/Gemfile.rails-4.2-stable
- gemfiles/Gemfile.rails-4.1-stable - gemfiles/Gemfile.rails-4.1-stable
- gemfiles/Gemfile.rails-4.0-stable
- gemfiles/Gemfile.rails-3.2-stable
- Gemfile
matrix: matrix:
exclude: exclude:
- rvm: 2.2 - rvm: 2.1.9
gemfile: gemfiles/Gemfile.rails-3.2-stable gemfile: gemfiles/Gemfile.rails-5.0
- env: DEVISE_ORM=mongoid
gemfile: gemfiles/Gemfile.rails-5.0
allow_failures:
- rvm: ruby-head
fast_finish: true
services: services:
- mongodb - mongodb
@@ -27,18 +31,19 @@ cache: bundler
env: env:
matrix: matrix:
- DEVISE_ORM=mongoid
- DEVISE_ORM=active_record - DEVISE_ORM=active_record
- DEVISE_ORM=mongoid
before_install: "rm ${BUNDLE_GEMFILE}.lock" before_install: "rm ${BUNDLE_GEMFILE}.lock"
before_script: "bundle update" before_script: "bundle update"
script: "bundle exec rake test" script: "bin/test"
notifications: notifications:
email: false email: false
slack: slack:
on_pull_requests: false
on_success: change on_success: change
on_failure: always on_failure: always
secure: Q3M+kmude3FjisibEeeGe0wSMXgvwLH+vL7Zrx9//q4QtkfnrQ/BBMvY9KXxPEsNF+eys4YopYjTkJ8uRmeboUATW/oQ4Jrv3+u3zkIHK2sFn/Q2cQWpK5w+CbgEnHPjKYnUu34b09njXTgDlr/mqtbPqrKeZ1dLlpKXCB/q4GY= secure: Q3M+kmude3FjisibEeeGe0wSMXgvwLH+vL7Zrx9//q4QtkfnrQ/BBMvY9KXxPEsNF+eys4YopYjTkJ8uRmeboUATW/oQ4Jrv3+u3zkIHK2sFn/Q2cQWpK5w+CbgEnHPjKYnUu34b09njXTgDlr/mqtbPqrKeZ1dLlpKXCB/q4GY=

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,39 @@
### Please read before contributing ### Please read before contributing
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). 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).
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. 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.
3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed. 3) If possible, replicate your issue with our
[guides/bug_report_templates/integration_test.rb](test case example), and attach
it to your issue or Pull Request - this way we have an isolated way to replicate
your issue and investigate it further.
4) When reporting an issue, include Rails, Devise and Warden versions. If you are getting exceptions, please include the full backtrace. 4) Otherwise, please provide a fresh new Rails application that replicates your
issue on a public GitHub repository, as some scenarios might not be possible to
replicate using the standalone test case example.
5) Notice that all of your interactions in the project are expected to follow our [Code of Conduct](CODE_OF_CONDUCT.md) 5) Do a small search on the issues tracker before submitting your issue to see
if it was already reported / fixed. Duplicated issues will be closed to avoid
too much noise/duplication in the issue tracker.
That's it! The more information you give, the easier it becomes for us to track it down and fix it. 6) When reporting an issue, include Rails, Devise and Warden versions. If you
Ideally, you should provide an application that reproduces the error or a test case to Devise's suite. are getting exceptions, please include the full backtrace.
7) Please do not attempt to translate Devise built in views. The views are meant
to be a starting point and not a final version. For historical references,
please look into closed issues/Pull regarding i18n.
8) Notice that all of your interactions in the project are expected to follow
our [Code of Conduct](CODE_OF_CONDUCT.md)
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.
Thanks! Thanks!

11
Gemfile
View File

@@ -2,16 +2,17 @@ source "https://rubygems.org"
gemspec gemspec
gem "rails", "4.2.2" gem "rails", "~> 4.2.6"
gem "omniauth", "~> 1.2.0" gem "omniauth"
gem "omniauth-oauth2", "~> 1.1.0" gem "omniauth-oauth2"
gem "rdoc" gem "rdoc"
group :test do group :test do
gem "omniauth-facebook" gem "omniauth-facebook"
gem "omniauth-openid", "~> 1.0.1" gem "omniauth-openid"
gem "webrat", "0.7.3", require: false gem "webrat", "0.7.3", require: false
gem "mocha", "~> 1.1", require: false gem "mocha", "~> 1.1", require: false
gem 'test_after_commit', require: false
end end
platforms :jruby do platforms :jruby do
@@ -25,5 +26,5 @@ platforms :ruby do
end end
group :mongoid do group :mongoid do
gem "mongoid", "~> 4.0" gem "mongoid", "~> 5.0"
end end

View File

@@ -1,159 +1,159 @@
PATH PATH
remote: . remote: .
specs: specs:
devise (3.5.3) devise (4.1.0)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5) railties (>= 4.1.0, < 5.1)
responders responders
thread_safe (~> 0.1)
warden (~> 1.2.3) warden (~> 1.2.3)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actionmailer (4.2.2) actionmailer (4.2.6)
actionpack (= 4.2.2) actionpack (= 4.2.6)
actionview (= 4.2.2) actionview (= 4.2.6)
activejob (= 4.2.2) activejob (= 4.2.6)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.2) actionpack (4.2.6)
actionview (= 4.2.2) actionview (= 4.2.6)
activesupport (= 4.2.2) activesupport (= 4.2.6)
rack (~> 1.6) rack (~> 1.6)
rack-test (~> 0.6.2) rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.2) actionview (4.2.6)
activesupport (= 4.2.2) activesupport (= 4.2.6)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1) rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.2) activejob (4.2.6)
activesupport (= 4.2.2) activesupport (= 4.2.6)
globalid (>= 0.3.0) globalid (>= 0.3.0)
activemodel (4.2.2) activemodel (4.2.6)
activesupport (= 4.2.2) activesupport (= 4.2.6)
builder (~> 3.1) builder (~> 3.1)
activerecord (4.2.2) activerecord (4.2.6)
activemodel (= 4.2.2) activemodel (= 4.2.6)
activesupport (= 4.2.2) activesupport (= 4.2.6)
arel (~> 6.0) arel (~> 6.0)
activesupport (4.2.2) activesupport (4.2.6)
i18n (~> 0.7) i18n (~> 0.7)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (6.0.0) arel (6.0.3)
bcrypt (3.1.10) bcrypt (3.1.11)
bson (3.1.2) bson (4.1.1)
builder (3.2.2) builder (3.2.2)
connection_pool (2.2.0) concurrent-ruby (1.0.2)
erubis (2.7.0) erubis (2.7.0)
faraday (0.9.1) faraday (0.9.2)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
globalid (0.3.5) globalid (0.3.6)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
hashie (3.4.0) hashie (3.4.4)
i18n (0.7.0) i18n (0.7.0)
json (1.8.3) json (1.8.3)
jwt (1.4.1) jwt (1.5.1)
loofah (2.0.2) loofah (2.0.3)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.3) mail (2.6.4)
mime-types (>= 1.16, < 3) mime-types (>= 1.16, < 4)
metaclass (0.0.4) metaclass (0.0.4)
mime-types (2.6.1) mime-types (3.0)
mini_portile (0.6.2) mime-types-data (~> 3.2015)
minitest (5.7.0) mime-types-data (3.2016.0221)
mini_portile2 (2.0.0)
minitest (5.9.0)
mocha (1.1.0) mocha (1.1.0)
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
mongoid (4.0.2) mongo (2.2.5)
bson (~> 4.0)
mongoid (5.1.3)
activemodel (~> 4.0) activemodel (~> 4.0)
moped (~> 2.0.0) mongo (~> 2.1)
origin (~> 2.1) origin (~> 2.2)
tzinfo (>= 0.3.37) tzinfo (>= 0.3.37)
moped (2.0.6) multi_json (1.12.0)
bson (~> 3.0)
connection_pool (~> 2.0)
optionable (~> 0.2.0)
multi_json (1.11.1)
multi_xml (0.5.5) multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
nokogiri (1.6.6.2) nokogiri (1.6.7.2)
mini_portile (~> 0.6.0) mini_portile2 (~> 2.0.0.rc2)
oauth2 (0.9.4) oauth2 (1.1.0)
faraday (>= 0.8, < 0.10) faraday (>= 0.8, < 0.10)
jwt (~> 1.0) jwt (~> 1.0, < 1.5.2)
multi_json (~> 1.3) multi_json (~> 1.3)
multi_xml (~> 0.5) multi_xml (~> 0.5)
rack (~> 1.2) rack (>= 1.2, < 3)
omniauth (1.2.2) omniauth (1.3.1)
hashie (>= 1.2, < 4) hashie (>= 1.2, < 4)
rack (~> 1.0) rack (>= 1.0, < 3)
omniauth-facebook (1.6.0) omniauth-facebook (3.0.0)
omniauth-oauth2 (~> 1.1) omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.1.2) omniauth-oauth2 (1.4.0)
faraday (>= 0.8, < 0.10) oauth2 (~> 1.0)
multi_json (~> 1.3)
oauth2 (~> 0.9.3)
omniauth (~> 1.2) omniauth (~> 1.2)
omniauth-openid (1.0.1) omniauth-openid (1.0.1)
omniauth (~> 1.0) omniauth (~> 1.0)
rack-openid (~> 1.3.1) rack-openid (~> 1.3.1)
optionable (0.2.0) origin (2.2.0)
origin (2.1.1)
orm_adapter (0.5.0) orm_adapter (0.5.0)
rack (1.6.2) rack (1.6.4)
rack-openid (1.3.1) rack-openid (1.3.1)
rack (>= 1.1.0) rack (>= 1.1.0)
ruby-openid (>= 2.1.8) ruby-openid (>= 2.1.8)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rails (4.2.2) rails (4.2.6)
actionmailer (= 4.2.2) actionmailer (= 4.2.6)
actionpack (= 4.2.2) actionpack (= 4.2.6)
actionview (= 4.2.2) actionview (= 4.2.6)
activejob (= 4.2.2) activejob (= 4.2.6)
activemodel (= 4.2.2) activemodel (= 4.2.6)
activerecord (= 4.2.2) activerecord (= 4.2.6)
activesupport (= 4.2.2) activesupport (= 4.2.6)
bundler (>= 1.3.0, < 2.0) bundler (>= 1.3.0, < 2.0)
railties (= 4.2.2) railties (= 4.2.6)
sprockets-rails sprockets-rails
rails-deprecated_sanitizer (1.0.3) rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha) activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.6) rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0) activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0) nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1) rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2) rails-html-sanitizer (1.0.3)
loofah (~> 2.0) loofah (~> 2.0)
railties (4.2.2) railties (4.2.6)
actionpack (= 4.2.2) actionpack (= 4.2.6)
activesupport (= 4.2.2) activesupport (= 4.2.6)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (10.4.2) rake (11.1.2)
rdoc (4.2.0) rdoc (4.2.2)
responders (2.1.0) json (~> 1.4)
railties (>= 4.2.0, < 5) responders (2.2.0)
railties (>= 4.2.0, < 5.1)
ruby-openid (2.7.0) ruby-openid (2.7.0)
sprockets (3.2.0) sprockets (3.6.0)
rack (~> 1.0) concurrent-ruby (~> 1.0)
sprockets-rails (2.3.1) rack (> 1, < 3)
actionpack (>= 3.0) sprockets-rails (3.0.4)
activesupport (>= 3.0) actionpack (>= 4.0)
sprockets (>= 2.8, < 4.0) activesupport (>= 4.0)
sqlite3 (1.3.10) sprockets (>= 3.0.0)
sqlite3 (1.3.11)
test_after_commit (1.0.0)
activerecord (>= 3.2)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
warden (1.2.4) warden (1.2.6)
rack (>= 1.0) rack (>= 1.0)
webrat (0.7.3) webrat (0.7.3)
nokogiri (>= 1.2.0) nokogiri (>= 1.2.0)
@@ -169,15 +169,16 @@ DEPENDENCIES
devise! devise!
jruby-openssl jruby-openssl
mocha (~> 1.1) mocha (~> 1.1)
mongoid (~> 4.0) mongoid (~> 5.0)
omniauth (~> 1.2.0) omniauth
omniauth-facebook omniauth-facebook
omniauth-oauth2 (~> 1.1.0) omniauth-oauth2
omniauth-openid (~> 1.0.1) omniauth-openid
rails (= 4.2.2) rails (~> 4.2.6)
rdoc rdoc
sqlite3 sqlite3
test_after_commit
webrat (= 0.7.3) webrat (= 0.7.3)
BUNDLED WITH BUNDLED WITH
1.10.6 1.11.2

View File

@@ -1,4 +1,4 @@
Copyright 2009-2015 Plataformatec. http://plataformatec.com.br Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the a copy of this software and associated documentation files (the

146
README.md
View File

@@ -4,7 +4,6 @@ By [Plataformatec](http://plataformatec.com.br/).
[![Build Status](https://api.travis-ci.org/plataformatec/devise.svg?branch=master)](http://travis-ci.org/plataformatec/devise) [![Build Status](https://api.travis-ci.org/plataformatec/devise.svg?branch=master)](http://travis-ci.org/plataformatec/devise)
[![Code Climate](https://codeclimate.com/github/plataformatec/devise.svg)](https://codeclimate.com/github/plataformatec/devise) [![Code Climate](https://codeclimate.com/github/plataformatec/devise.svg)](https://codeclimate.com/github/plataformatec/devise)
[![Security](https://hakiri.io/github/plataformatec/devise/master.svg)](https://hakiri.io/github/plataformatec/devise/master)
This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/). This README is [also available in a friendly navigable format](http://devise.plataformatec.com.br/).
@@ -17,7 +16,7 @@ Devise is a flexible authentication solution for Rails based on Warden. It:
It's composed of 10 modules: It's composed of 10 modules:
* [Database Authenticatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/DatabaseAuthenticatable): encrypts 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. * [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/intridea/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. * [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. * [Recoverable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Recoverable): resets the user password and sends reset instructions.
@@ -28,8 +27,6 @@ It's composed of 10 modules:
* [Validatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations. * [Validatable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.
* [Lockable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period. * [Lockable](http://rubydoc.info/github/plataformatec/devise/master/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.
Devise is guaranteed to be thread-safe on YARV. Thread-safety support on JRuby is in progress.
## Information ## Information
### The Devise wiki ### The Devise wiki
@@ -92,7 +89,7 @@ Once you have solidified your understanding of Rails and authentication mechanis
## Getting started ## Getting started
Devise 3.0 works with Rails 3.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 ```ruby
gem 'devise' gem 'devise'
@@ -103,16 +100,16 @@ Run the bundle command to install it.
After you install Devise and add it to your Gemfile, you need to run the generator: After you install Devise and add it to your Gemfile, you need to run the generator:
```console ```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: 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 ```console
rails generate devise MODEL $ rails generate devise MODEL
``` ```
Replace MODEL with the class name used for the applications users (its frequently `User` but could also be `Admin`). This will create a model (if one does not exist) and configure it with default Devise modules. The generator also configures your `config/routes.rb` file to point to the Devise controller. Replace MODEL with the class name used for the applications users (its 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, 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`
@@ -132,6 +129,8 @@ Devise will create some helpers to use inside your controllers and views. To set
before_action :authenticate_user! before_action :authenticate_user!
``` ```
For Rails 5, note that `protect_from_forgery` is no longer prepended to the `before_action` chain, so if you have set `authenticate_user` before `protect_from_forgery`, your request will result in "Can't verify CSRF token authenticity." To resolve this, either change the order in which you call them, or use `protect_from_forgery prepend: true`.
If your devise model is something other than User, replace "_user" with "_yourmodel". The same logic applies to the instructions below. If your devise model is something other than User, replace "_user" with "_yourmodel". The same logic applies to the instructions below.
To verify if a user is signed in, use the following helper: To verify if a user is signed in, use the following helper:
@@ -155,7 +154,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: 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 ```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. You can also override `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.
@@ -174,7 +173,7 @@ member_session
### Configuring Models ### Configuring Models
The Devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the encryption algorithm with: 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 ```ruby
devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20 devise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 20
@@ -184,9 +183,13 @@ Besides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`,
### Strong Parameters ### Strong Parameters
![The Parameter Sanitizer API has changed for Devise 4](http://messages.hellobits.com/warning.svg?message=The%20Parameter%20Sanitizer%20API%20has%20changed%20for%20Devise%204)
*For previous Devise versions see https://github.com/plataformatec/devise/tree/3-stable#strong-parameters*
When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well. When you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.
There are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and the permitted parameters by default are: There are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and default permitted parameters are:
* `sign_in` (`Devise::SessionsController#create`) - Permits only the authentication keys (like `email`) * `sign_in` (`Devise::SessionsController#create`) - Permits only the authentication keys (like `email`)
* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation` * `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`
@@ -201,7 +204,7 @@ class ApplicationController < ActionController::Base
protected protected
def configure_permitted_parameters def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :username devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end end
end end
``` ```
@@ -212,7 +215,9 @@ To permit simple scalar values for username and email, use this
```ruby ```ruby
def configure_permitted_parameters def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email) } devise_parameter_sanitizer.permit(:sign_in) do |user_params|
user_params.permit(:username, :email)
end
end end
``` ```
@@ -220,7 +225,9 @@ If you have some checkboxes that express the roles a user may take on registrati
```ruby ```ruby
def configure_permitted_parameters def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit({ roles: [] }, :email, :password, :password_confirmation) } devise_parameter_sanitizer.permit(:sign_up) do |user_params|
user_params.permit({ roles: [] }, :email, :password, :password_confirmation)
end
end end
``` ```
For the list of permitted scalars, and how to declare permitted keys in nested hashes and arrays, see For the list of permitted scalars, and how to declare permitted keys in nested hashes and arrays, see
@@ -231,8 +238,9 @@ If you have multiple Devise models, you may want to set up a different parameter
```ruby ```ruby
class User::ParameterSanitizer < Devise::ParameterSanitizer class User::ParameterSanitizer < Devise::ParameterSanitizer
def sign_in def initialize(*)
default_params.permit(:username, :email) super
permit(:sign_up, keys: [:username, :email])
end end
end end
``` ```
@@ -262,7 +270,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: 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 ```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. 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.
@@ -270,14 +278,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: 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 ```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, 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. you can pass a list of modules to the generator with the `-v` flag.
```console ```console
rails generate devise:views -v registrations confirmations $ rails generate devise:views -v registrations confirmations
``` ```
### Configuring controllers ### Configuring controllers
@@ -287,7 +295,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: 1. Create your custom controllers using the generator which requires a scope:
```console ```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/`. If you specify `users` as the scope, controllers will be created in `app/controllers/users/`.
@@ -306,7 +314,7 @@ If the customization at the views level is not enough, you can customize each co
2. Tell the router to use this controller: 2. Tell the router to use this controller:
```ruby ```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`. 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`.
@@ -344,16 +352,16 @@ 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: 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 ```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 for details. Be sure to check `devise_for` [documentation](http://www.rubydoc.info/github/plataformatec/devise/master/ActionDispatch/Routing/Mapper%3Adevise_for) for details.
If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is create your routes normally and wrap them in a `devise_scope` block in the router: If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is create your routes normally and wrap them in a `devise_scope` block in the router:
```ruby ```ruby
devise_scope :user do devise_scope :user do
get "sign_in", to: "devise/sessions#new" get 'sign_in', to: 'devise/sessions#new'
end end
``` ```
@@ -403,44 +411,94 @@ Caution: Devise Controllers inherit from ApplicationController. If your app uses
### Test helpers ### 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: 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 ```ruby
class ActionController::TestCase class PostsControllerTest < ActionController::TestCase
include Devise::TestHelpers include Devise::Test::ControllerHelpers
end 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 ```ruby
RSpec.configure do |config| RSpec.configure do |config|
config.include Devise::TestHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view
end end
``` ```
Just be sure that this inclusion is made *after* the `require 'rspec/rails'` directive. 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 ```ruby
sign_in :user, @user # sign_in(scope, resource) sign_in @user
sign_in @user # sign_in(resource) sign_in @user, scope: admin
sign_out :user # sign_out(scope)
sign_out @user # sign_out(resource)
``` ```
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. 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 get :new
@request.env["devise.mapping"] = Devise.mappings[:user]
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: You can read more about testing your Rails 3 - Rails 4 controllers with RSpec in the wiki:
@@ -477,7 +535,7 @@ devise :database_authenticatable, :timeoutable
devise_for :admins devise_for :admins
# Inside your protected controller # Inside your protected controller
before_filter :authenticate_admin! before_action :authenticate_admin!
# Inside your controllers and views # Inside your controllers and views
admin_signed_in? admin_signed_in?
@@ -545,6 +603,6 @@ https://github.com/plataformatec/devise/graphs/contributors
## License ## License
MIT License. Copyright 2009-2015 Plataformatec. http://plataformatec.com.br MIT License. Copyright 2009-2016 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. You are not granted rights or licenses to the trademarks of Plataformatec, including without limitation the Devise name or logo.

View File

@@ -22,7 +22,7 @@ class Devise::ConfirmationsController < DeviseController
yield resource if block_given? yield resource if block_given?
if resource.errors.empty? if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_flashing_format? set_flash_message!(:notice, :confirmed)
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) } respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else else
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new } respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }

View File

@@ -1,5 +1,5 @@
class Devise::OmniauthCallbacksController < DeviseController class Devise::OmniauthCallbacksController < DeviseController
prepend_before_filter { request.env["devise.skip_timeout"] = true } prepend_before_action { request.env["devise.skip_timeout"] = true }
def passthru def passthru
render status: 404, text: "Not found. Authentication passthru." render status: 404, text: "Not found. Authentication passthru."
@@ -13,14 +13,14 @@ class Devise::OmniauthCallbacksController < DeviseController
protected protected
def failed_strategy def failed_strategy
env["omniauth.error.strategy"] request.respond_to?(:get_header) ? request.get_header("omniauth.error.strategy") : env["omniauth.error.strategy"]
end end
def failure_message def failure_message
exception = env["omniauth.error"] exception = request.respond_to?(:get_header) ? request.get_header("omniauth.error") : env["omniauth.error"]
error = exception.error_reason if exception.respond_to?(:error_reason) error = exception.error_reason if exception.respond_to?(:error_reason)
error ||= exception.error if exception.respond_to?(:error) error ||= exception.error if exception.respond_to?(:error)
error ||= env["omniauth.error.type"].to_s error ||= (request.respond_to?(:get_header) ? request.get_header("omniauth.error.type") : env["omniauth.error.type"]).to_s
error.to_s.humanize if error error.to_s.humanize if error
end end

View File

@@ -1,7 +1,7 @@
class Devise::PasswordsController < DeviseController class Devise::PasswordsController < DeviseController
prepend_before_filter :require_no_authentication prepend_before_action :require_no_authentication
# Render the #edit only if coming from a reset password email link # Render the #edit only if coming from a reset password email link
append_before_filter :assert_reset_token_passed, only: :edit append_before_action :assert_reset_token_passed, only: :edit
# GET /resource/password/new # GET /resource/password/new
def new def new
@@ -36,10 +36,10 @@ class Devise::PasswordsController < DeviseController
resource.unlock_access! if unlockable?(resource) resource.unlock_access! if unlockable?(resource)
if Devise.sign_in_after_reset_password if Devise.sign_in_after_reset_password
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_flashing_format? set_flash_message!(:notice, flash_message)
sign_in(resource_name, resource) sign_in(resource_name, resource)
else else
set_flash_message(:notice, :updated_not_active) if is_flashing_format? set_flash_message!(:notice, :updated_not_active)
end end
respond_with resource, location: after_resetting_password_path_for(resource) respond_with resource, location: after_resetting_password_path_for(resource)
else else

View File

@@ -1,11 +1,11 @@
class Devise::RegistrationsController < DeviseController class Devise::RegistrationsController < DeviseController
prepend_before_filter :require_no_authentication, only: [:new, :create, :cancel] prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]
prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy] prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]
prepend_before_action :set_minimum_password_length, only: [:new, :edit]
# GET /resource/sign_up # GET /resource/sign_up
def new def new
build_resource({}) build_resource({})
set_minimum_password_length
yield resource if block_given? yield resource if block_given?
respond_with self.resource respond_with self.resource
end end
@@ -18,11 +18,11 @@ class Devise::RegistrationsController < DeviseController
yield resource if block_given? yield resource if block_given?
if resource.persisted? if resource.persisted?
if resource.active_for_authentication? if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_flashing_format? set_flash_message! :notice, :signed_up
sign_up(resource_name, resource) sign_up(resource_name, resource)
respond_with resource, location: after_sign_up_path_for(resource) respond_with resource, location: after_sign_up_path_for(resource)
else else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in! expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource) respond_with resource, location: after_inactive_sign_up_path_for(resource)
end end
@@ -53,7 +53,7 @@ class Devise::RegistrationsController < DeviseController
:update_needs_confirmation : :updated :update_needs_confirmation : :updated
set_flash_message :notice, flash_key set_flash_message :notice, flash_key
end end
sign_in resource_name, resource, bypass: true bypass_sign_in resource, scope: resource_name
respond_with resource, location: after_update_path_for(resource) respond_with resource, location: after_update_path_for(resource)
else else
clean_up_passwords resource clean_up_passwords resource
@@ -65,7 +65,7 @@ class Devise::RegistrationsController < DeviseController
def destroy def destroy
resource.destroy resource.destroy
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name) Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :destroyed if is_flashing_format? set_flash_message! :notice, :destroyed
yield resource if block_given? yield resource if block_given?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) } respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
end end

View File

@@ -1,8 +1,8 @@
class Devise::SessionsController < DeviseController class Devise::SessionsController < DeviseController
prepend_before_filter :require_no_authentication, only: [:new, :create] prepend_before_action :require_no_authentication, only: [:new, :create]
prepend_before_filter :allow_params_authentication!, only: :create prepend_before_action :allow_params_authentication!, only: :create
prepend_before_filter :verify_signed_out_user, only: :destroy prepend_before_action :verify_signed_out_user, only: :destroy
prepend_before_filter only: [:create, :destroy] { request.env["devise.skip_timeout"] = true } prepend_before_action only: [:create, :destroy] { request.env["devise.skip_timeout"] = true }
# GET /resource/sign_in # GET /resource/sign_in
def new def new
@@ -15,7 +15,7 @@ class Devise::SessionsController < DeviseController
# POST /resource/sign_in # POST /resource/sign_in
def create def create
self.resource = warden.authenticate!(auth_options) self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_flashing_format? set_flash_message!(:notice, :signed_in)
sign_in(resource_name, resource) sign_in(resource_name, resource)
yield resource if block_given? yield resource if block_given?
respond_with resource, location: after_sign_in_path_for(resource) respond_with resource, location: after_sign_in_path_for(resource)
@@ -24,7 +24,7 @@ class Devise::SessionsController < DeviseController
# DELETE /resource/sign_out # DELETE /resource/sign_out
def destroy def destroy
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)) signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
set_flash_message :notice, :signed_out if signed_out && is_flashing_format? set_flash_message! :notice, :signed_out if signed_out
yield if block_given? yield if block_given?
respond_to_on_destroy respond_to_on_destroy
end end
@@ -58,7 +58,7 @@ class Devise::SessionsController < DeviseController
# to the after_sign_out path. # to the after_sign_out path.
def verify_signed_out_user def verify_signed_out_user
if all_signed_out? if all_signed_out?
set_flash_message :notice, :already_signed_out if is_flashing_format? set_flash_message! :notice, :already_signed_out
respond_to_on_destroy respond_to_on_destroy
end end

View File

@@ -1,5 +1,5 @@
class Devise::UnlocksController < DeviseController class Devise::UnlocksController < DeviseController
prepend_before_filter :require_no_authentication prepend_before_action :require_no_authentication
# GET /resource/unlock/new # GET /resource/unlock/new
def new def new
@@ -24,7 +24,7 @@ class Devise::UnlocksController < DeviseController
yield resource if block_given? yield resource if block_given?
if resource.errors.empty? if resource.errors.empty?
set_flash_message :notice, :unlocked if is_flashing_format? set_flash_message! :notice, :unlocked
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) } respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
else else
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new } respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }

View File

@@ -2,13 +2,17 @@
class DeviseController < Devise.parent_controller.constantize class DeviseController < Devise.parent_controller.constantize
include Devise::Controllers::ScopedViews include Devise::Controllers::ScopedViews
helper DeviseHelper if respond_to?(:helper)
helper DeviseHelper
end
helpers = %w(resource scope_name resource_name signed_in_resource if respond_to?(:helper_method)
resource_class resource_params devise_mapping) helpers = %w(resource scope_name resource_name signed_in_resource
helper_method(*helpers) resource_class resource_params devise_mapping)
helper_method(*helpers)
end
prepend_before_filter :assert_is_devise_resource! prepend_before_action :assert_is_devise_resource!
respond_to :html if mimes_for_respond_to.empty? respond_to :html if mimes_for_respond_to.empty?
# Override prefixes to consider the scoped view. # Override prefixes to consider the scoped view.
@@ -89,10 +93,10 @@ MESSAGE
instance_variable_set(:"@#{resource_name}", new_resource) instance_variable_set(:"@#{resource_name}", new_resource)
end end
# Helper for use in before_filters where no authentication is required. # Helper for use in before_actions where no authentication is required.
# #
# Example: # Example:
# before_filter :require_no_authentication, only: :new # before_action :require_no_authentication, only: :new
def require_no_authentication def require_no_authentication
assert_is_devise_resource! assert_is_devise_resource!
return unless is_navigational_format? return unless is_navigational_format?
@@ -123,13 +127,13 @@ MESSAGE
end end
if notice if notice
set_flash_message :notice, notice if is_flashing_format? set_flash_message! :notice, notice
true true
end end
end end
# Sets the flash message with :key, using I18n. By default you are able # Sets the flash message with :key, using I18n. By default you are able
# to setup your messages using specific resource scope, and if no message is # to set up your messages using specific resource scope, and if no message is
# found we look to the default scope. Set the "now" options key to a true # found we look to the default scope. Set the "now" options key to a true
# value to populate the flash.now hash in lieu of the default flash hash (so # value to populate the flash.now hash in lieu of the default flash hash (so
# the flash message will be available to the current action instead of the # the flash message will be available to the current action instead of the
@@ -154,6 +158,13 @@ MESSAGE
end end
end end
# Sets flash message if is_flashing_format? equals true
def set_flash_message!(key, kind, options = {})
if is_flashing_format?
set_flash_message(key, kind, options)
end
end
# Sets minimum password length to show to user # Sets minimum password length to show to user
def set_minimum_password_length def set_minimum_password_length
if devise_mapping.validatable? if devise_mapping.validatable?

View File

@@ -5,7 +5,7 @@
<div class="field"> <div class="field">
<%= f.label :email %><br /> <%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> <%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div> </div>
<div class="actions"> <div class="actions">

View File

@@ -15,6 +15,10 @@
<div class="field"> <div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br /> <%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %> <%= f.password_field :password, autocomplete: "off" %>
<% if @minimum_password_length %>
<br />
<em><%= @minimum_password_length %> characters minimum</em>
<% end %>
</div> </div>
<div class="field"> <div class="field">

13
bin/test Executable file
View File

@@ -0,0 +1,13 @@
#!/usr/bin/env ruby
$: << File.expand_path(File.expand_path('../../test', __FILE__))
require 'bundler/setup'
begin
require 'rails/test_unit/minitest_plugin'
rescue LoadError
exec 'rake'
end
Rails::TestUnitReporter.executable = 'bin/test'
exit Minitest.run(ARGV)

View File

@@ -16,12 +16,11 @@ Gem::Specification.new do |s|
s.files = `git ls-files`.split("\n") s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- test/*`.split("\n") s.test_files = `git ls-files -- test/*`.split("\n")
s.require_paths = ["lib"] s.require_paths = ["lib"]
s.required_ruby_version = '>= 1.9.3' s.required_ruby_version = '>= 2.1.0'
s.add_dependency("warden", "~> 1.2.3") s.add_dependency("warden", "~> 1.2.3")
s.add_dependency("orm_adapter", "~> 0.1") s.add_dependency("orm_adapter", "~> 0.1")
s.add_dependency("bcrypt", "~> 3.0") s.add_dependency("bcrypt", "~> 3.0")
s.add_dependency("thread_safe", "~> 0.1") s.add_dependency("railties", ">= 4.1.0", "< 5.1")
s.add_dependency("railties", ">= 3.2.6", "< 5")
s.add_dependency("responders") s.add_dependency("responders")
end end

View File

@@ -1,29 +0,0 @@
source "https://rubygems.org"
gemspec path: '..'
gem "rails", github: 'rails/rails', branch: '3-2-stable'
gem "omniauth", "~> 1.2.0"
gem "omniauth-oauth2", "~> 1.1.0"
gem "rdoc"
group :test do
gem "omniauth-facebook"
gem "omniauth-openid", "~> 1.0.1"
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"
end
platforms :ruby do
gem "sqlite3"
end
group :mongoid do
gem "mongoid", "~> 3.0"
end

View File

@@ -1,172 +0,0 @@
GIT
remote: git://github.com/rails/rails.git
revision: b344986bc3d94ca7821fc5e0eef1874882ac6cbb
branch: 3-2-stable
specs:
actionmailer (3.2.21)
actionpack (= 3.2.21)
mail (~> 2.5.4)
actionpack (3.2.21)
activemodel (= 3.2.21)
activesupport (= 3.2.21)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.21)
activesupport (= 3.2.21)
builder (~> 3.0.0)
activerecord (3.2.21)
activemodel (= 3.2.21)
activesupport (= 3.2.21)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.21)
activemodel (= 3.2.21)
activesupport (= 3.2.21)
activesupport (3.2.21)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
rails (3.2.21)
actionmailer (= 3.2.21)
actionpack (= 3.2.21)
activerecord (= 3.2.21)
activeresource (= 3.2.21)
activesupport (= 3.2.21)
bundler (~> 1.0)
railties (= 3.2.21)
railties (3.2.21)
actionpack (= 3.2.21)
activesupport (= 3.2.21)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
PATH
remote: ..
specs:
devise (3.5.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
GEM
remote: https://rubygems.org/
specs:
arel (3.0.3)
bcrypt (3.1.10)
builder (3.0.4)
erubis (2.7.0)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
hashie (3.4.0)
hike (1.2.3)
i18n (0.7.0)
journey (1.0.4)
json (1.8.2)
jwt (1.4.1)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metaclass (0.0.4)
mime-types (1.25.1)
mini_portile (0.6.2)
mocha (1.1.0)
metaclass (~> 0.0.1)
mongoid (3.1.6)
activemodel (~> 3.2)
moped (~> 1.4)
origin (~> 1.0)
tzinfo (~> 0.3.29)
moped (1.5.2)
multi_json (1.11.0)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oauth2 (0.9.4)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-facebook (1.6.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.1.2)
faraday (>= 0.8, < 0.10)
multi_json (~> 1.3)
oauth2 (~> 0.9.3)
omniauth (~> 1.2)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
origin (1.1.0)
orm_adapter (0.5.0)
polyglot (0.3.5)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-ssl (1.3.4)
rack
rack-test (0.6.3)
rack (>= 1.0)
rake (10.4.2)
rdoc (3.12.2)
json (~> 1.4)
responders (1.1.2)
railties (>= 3.2, < 4.2)
ruby-openid (2.7.0)
sprockets (2.2.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.10)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.43)
warden (1.2.4)
rack (>= 1.0)
webrat (0.7.3)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
PLATFORMS
ruby
DEPENDENCIES
activerecord-jdbc-adapter
activerecord-jdbcsqlite3-adapter
devise!
jruby-openssl
mocha (~> 1.1)
mongoid (~> 3.0)
omniauth (~> 1.2.0)
omniauth-facebook
omniauth-oauth2 (~> 1.1.0)
omniauth-openid (~> 1.0.1)
rails!
rdoc
sqlite3
webrat (= 0.7.3)
BUNDLED WITH
1.10.6

View File

@@ -1,29 +0,0 @@
source "https://rubygems.org"
gemspec path: '..'
gem "rails", github: 'rails/rails', branch: '4-0-stable'
gem "omniauth", "~> 1.2.0"
gem "omniauth-oauth2", "~> 1.1.0"
gem "rdoc"
group :test do
gem "omniauth-facebook"
gem "omniauth-openid", "~> 1.0.1"
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"
end
platforms :ruby do
gem "sqlite3"
end
group :mongoid do
gem "mongoid", "~> 4.0.0"
end

View File

@@ -1,166 +0,0 @@
GIT
remote: git://github.com/rails/rails.git
revision: 7ec9c9635bf4d57009135ed11e89d8bf32306d73
branch: 4-0-stable
specs:
actionmailer (4.0.13)
actionpack (= 4.0.13)
mail (~> 2.5, >= 2.5.4)
actionpack (4.0.13)
activesupport (= 4.0.13)
builder (~> 3.1.0)
erubis (~> 2.7.0)
rack (~> 1.5.2)
rack-test (~> 0.6.2)
activemodel (4.0.13)
activesupport (= 4.0.13)
builder (~> 3.1.0)
activerecord (4.0.13)
activemodel (= 4.0.13)
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.13)
arel (~> 4.0.0)
activesupport (4.0.13)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
rails (4.0.13)
actionmailer (= 4.0.13)
actionpack (= 4.0.13)
activerecord (= 4.0.13)
activesupport (= 4.0.13)
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.13)
sprockets-rails (~> 2.0)
railties (4.0.13)
actionpack (= 4.0.13)
activesupport (= 4.0.13)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
PATH
remote: ..
specs:
devise (3.5.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
responders
thread_safe (~> 0.1)
warden (~> 1.2.3)
GEM
remote: https://rubygems.org/
specs:
activerecord-deprecated_finders (1.0.3)
arel (4.0.2)
bcrypt (3.1.10)
bson (2.3.0)
builder (3.1.4)
connection_pool (2.1.3)
erubis (2.7.0)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
hashie (3.4.0)
hike (1.2.3)
i18n (0.7.0)
jwt (1.4.1)
mail (2.6.3)
mime-types (>= 1.16, < 3)
metaclass (0.0.4)
mime-types (2.4.3)
mini_portile (0.6.2)
minitest (4.7.5)
mocha (1.1.0)
metaclass (~> 0.0.1)
mongoid (4.0.2)
activemodel (~> 4.0)
moped (~> 2.0.0)
origin (~> 2.1)
tzinfo (>= 0.3.37)
moped (2.0.4)
bson (~> 2.2)
connection_pool (~> 2.0)
optionable (~> 0.2.0)
multi_json (1.11.0)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
oauth2 (0.9.4)
faraday (>= 0.8, < 0.10)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-facebook (1.6.0)
omniauth-oauth2 (~> 1.1)
omniauth-oauth2 (1.1.2)
faraday (>= 0.8, < 0.10)
multi_json (~> 1.3)
oauth2 (~> 0.9.3)
omniauth (~> 1.2)
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
optionable (0.2.0)
origin (2.1.1)
orm_adapter (0.5.0)
rack (1.5.2)
rack-openid (1.3.1)
rack (>= 1.1.0)
ruby-openid (>= 2.1.8)
rack-test (0.6.3)
rack (>= 1.0)
rake (10.4.2)
rdoc (4.2.0)
responders (1.1.2)
railties (>= 3.2, < 4.2)
ruby-openid (2.7.0)
sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.4)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10)
thor (0.19.1)
thread_safe (0.3.5)
tilt (1.4.1)
tzinfo (0.3.43)
warden (1.2.4)
rack (>= 1.0)
webrat (0.7.3)
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
PLATFORMS
ruby
DEPENDENCIES
activerecord-jdbc-adapter
activerecord-jdbcsqlite3-adapter
devise!
jruby-openssl
mocha (~> 1.1)
mongoid (~> 4.0.0)
omniauth (~> 1.2.0)
omniauth-facebook
omniauth-oauth2 (~> 1.1.0)
omniauth-openid (~> 1.0.1)
rails!
rdoc
sqlite3
webrat (= 0.7.3)
BUNDLED WITH
1.10.6

View File

@@ -1,17 +1,18 @@
source "https://rubygems.org" source "https://rubygems.org"
gemspec path: '..' gemspec path: ".."
gem "rails", github: 'rails/rails', branch: '4-1-stable' gem "rails", github: "rails/rails", branch: "4-1-stable"
gem "omniauth", "~> 1.2.0" gem "omniauth"
gem "omniauth-oauth2", "~> 1.1.0" gem "omniauth-oauth2"
gem "rdoc" gem "rdoc"
group :test do group :test do
gem "omniauth-facebook" gem "omniauth-facebook"
gem "omniauth-openid", "~> 1.0.1" gem "omniauth-openid"
gem "webrat", "0.7.3", require: false gem "webrat", "0.7.3", require: false
gem "mocha", "~> 1.1", require: false gem "mocha", "~> 1.1", require: false
gem 'test_after_commit', require: false
end end
platforms :jruby do platforms :jruby do
@@ -25,5 +26,5 @@ platforms :ruby do
end end
group :mongoid do group :mongoid do
gem "mongoid", "~> 4.0.0" gem "mongoid", "~> 4.0"
end end

View File

@@ -1,83 +1,84 @@
GIT GIT
remote: git://github.com/rails/rails.git remote: git://github.com/rails/rails.git
revision: bf32ec7b8611e6b4c7e9398f7d297a1f0221e9b9 revision: 41b4d81b4fd14cbf43060c223bea0f461256d099
branch: 4-1-stable branch: 4-1-stable
specs: specs:
actionmailer (4.1.10) actionmailer (4.1.15)
actionpack (= 4.1.10) actionpack (= 4.1.15)
actionview (= 4.1.10) actionview (= 4.1.15)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
actionpack (4.1.10) actionpack (4.1.15)
actionview (= 4.1.10) actionview (= 4.1.15)
activesupport (= 4.1.10) activesupport (= 4.1.15)
rack (~> 1.5.2) rack (~> 1.5.2)
rack-test (~> 0.6.2) rack-test (~> 0.6.2)
actionview (4.1.10) actionview (4.1.15)
activesupport (= 4.1.10) activesupport (= 4.1.15)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubis (~> 2.7.0)
activemodel (4.1.10) activemodel (4.1.15)
activesupport (= 4.1.10) activesupport (= 4.1.15)
builder (~> 3.1) builder (~> 3.1)
activerecord (4.1.10) activerecord (4.1.15)
activemodel (= 4.1.10) activemodel (= 4.1.15)
activesupport (= 4.1.10) activesupport (= 4.1.15)
arel (~> 5.0.0) arel (~> 5.0.0)
activesupport (4.1.10) activesupport (4.1.15)
i18n (~> 0.6, >= 0.6.9) i18n (~> 0.6, >= 0.6.9)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.1) thread_safe (~> 0.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
rails (4.1.10) rails (4.1.15)
actionmailer (= 4.1.10) actionmailer (= 4.1.15)
actionpack (= 4.1.10) actionpack (= 4.1.15)
actionview (= 4.1.10) actionview (= 4.1.15)
activemodel (= 4.1.10) activemodel (= 4.1.15)
activerecord (= 4.1.10) activerecord (= 4.1.15)
activesupport (= 4.1.10) activesupport (= 4.1.15)
bundler (>= 1.3.0, < 2.0) bundler (>= 1.3.0, < 2.0)
railties (= 4.1.10) railties (= 4.1.15)
sprockets-rails (~> 2.0) sprockets-rails (~> 2.0)
railties (4.1.10) railties (4.1.15)
actionpack (= 4.1.10) actionpack (= 4.1.15)
activesupport (= 4.1.10) activesupport (= 4.1.15)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
PATH PATH
remote: .. remote: ..
specs: specs:
devise (3.5.3) devise (4.1.0)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5) railties (>= 4.1.0, < 5.1)
responders responders
thread_safe (~> 0.1)
warden (~> 1.2.3) warden (~> 1.2.3)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
arel (5.0.1.20140414130214) arel (5.0.1.20140414130214)
bcrypt (3.1.10) bcrypt (3.1.11)
bson (2.3.0) bson (3.2.6)
builder (3.2.2) builder (3.2.2)
connection_pool (2.1.3) concurrent-ruby (1.0.2)
connection_pool (2.2.0)
erubis (2.7.0) erubis (2.7.0)
faraday (0.9.1) faraday (0.9.2)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
hashie (3.4.0) hashie (3.4.4)
hike (1.2.3)
i18n (0.7.0) i18n (0.7.0)
json (1.8.2) json (1.8.3)
jwt (1.4.1) jwt (1.5.1)
mail (2.6.3) mail (2.6.4)
mime-types (>= 1.16, < 3) mime-types (>= 1.16, < 4)
metaclass (0.0.4) metaclass (0.0.4)
mime-types (2.4.3) mime-types (3.0)
mini_portile (0.6.2) mime-types-data (~> 3.2015)
minitest (5.5.1) mime-types-data (3.2016.0221)
mini_portile2 (2.0.0)
minitest (5.9.0)
mocha (1.1.0) mocha (1.1.0)
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
mongoid (4.0.2) mongoid (4.0.2)
@@ -85,64 +86,62 @@ GEM
moped (~> 2.0.0) moped (~> 2.0.0)
origin (~> 2.1) origin (~> 2.1)
tzinfo (>= 0.3.37) tzinfo (>= 0.3.37)
moped (2.0.4) moped (2.0.7)
bson (~> 2.2) bson (~> 3.0)
connection_pool (~> 2.0) connection_pool (~> 2.0)
optionable (~> 0.2.0) optionable (~> 0.2.0)
multi_json (1.11.0) multi_json (1.12.0)
multi_xml (0.5.5) multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
nokogiri (1.6.6.2) nokogiri (1.6.7.2)
mini_portile (~> 0.6.0) mini_portile2 (~> 2.0.0.rc2)
oauth2 (0.9.4) oauth2 (1.1.0)
faraday (>= 0.8, < 0.10) faraday (>= 0.8, < 0.10)
jwt (~> 1.0) jwt (~> 1.0, < 1.5.2)
multi_json (~> 1.3) multi_json (~> 1.3)
multi_xml (~> 0.5) multi_xml (~> 0.5)
rack (~> 1.2) rack (>= 1.2, < 3)
omniauth (1.2.2) omniauth (1.3.1)
hashie (>= 1.2, < 4) hashie (>= 1.2, < 4)
rack (~> 1.0) rack (>= 1.0, < 3)
omniauth-facebook (1.6.0) omniauth-facebook (3.0.0)
omniauth-oauth2 (~> 1.1) omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.1.2) omniauth-oauth2 (1.4.0)
faraday (>= 0.8, < 0.10) oauth2 (~> 1.0)
multi_json (~> 1.3)
oauth2 (~> 0.9.3)
omniauth (~> 1.2) omniauth (~> 1.2)
omniauth-openid (1.0.1) omniauth-openid (1.0.1)
omniauth (~> 1.0) omniauth (~> 1.0)
rack-openid (~> 1.3.1) rack-openid (~> 1.3.1)
optionable (0.2.0) optionable (0.2.0)
origin (2.1.1) origin (2.2.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
rack (1.5.2) rack (1.5.5)
rack-openid (1.3.1) rack-openid (1.3.1)
rack (>= 1.1.0) rack (>= 1.1.0)
ruby-openid (>= 2.1.8) ruby-openid (>= 2.1.8)
rack-test (0.6.3) rack-test (0.6.3)
rack (>= 1.0) rack (>= 1.0)
rake (10.4.2) rake (11.1.2)
rdoc (4.2.0) rdoc (4.2.2)
json (~> 1.4)
responders (1.1.2) responders (1.1.2)
railties (>= 3.2, < 4.2) railties (>= 3.2, < 4.2)
ruby-openid (2.7.0) ruby-openid (2.7.0)
sprockets (2.12.3) sprockets (3.6.0)
hike (~> 1.2) concurrent-ruby (~> 1.0)
multi_json (~> 1.0) rack (> 1, < 3)
rack (~> 1.0) sprockets-rails (2.3.3)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.4)
actionpack (>= 3.0) actionpack (>= 3.0)
activesupport (>= 3.0) activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0) sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10) sqlite3 (1.3.11)
test_after_commit (1.0.0)
activerecord (>= 3.2)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (1.4.1)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
warden (1.2.4) warden (1.2.6)
rack (>= 1.0) rack (>= 1.0)
webrat (0.7.3) webrat (0.7.3)
nokogiri (>= 1.2.0) nokogiri (>= 1.2.0)
@@ -158,15 +157,16 @@ DEPENDENCIES
devise! devise!
jruby-openssl jruby-openssl
mocha (~> 1.1) mocha (~> 1.1)
mongoid (~> 4.0.0) mongoid (~> 4.0)
omniauth (~> 1.2.0) omniauth
omniauth-facebook omniauth-facebook
omniauth-oauth2 (~> 1.1.0) omniauth-oauth2
omniauth-openid (~> 1.0.1) omniauth-openid
rails! rails!
rdoc rdoc
sqlite3 sqlite3
test_after_commit
webrat (= 0.7.3) webrat (= 0.7.3)
BUNDLED WITH BUNDLED WITH
1.10.6 1.11.2

View File

@@ -1,17 +1,18 @@
source "https://rubygems.org" source "https://rubygems.org"
gemspec path: '..' gemspec path: ".."
gem "rails", github: 'rails/rails', branch: '4-2-stable' gem "rails", github: "rails/rails", branch: "4-2-stable"
gem "omniauth", "~> 1.2.2" gem "omniauth"
gem "omniauth-oauth2", "~> 1.2.0" gem "omniauth-oauth2"
gem "rdoc" gem "rdoc"
group :test do group :test do
gem "omniauth-facebook" gem "omniauth-facebook"
gem "omniauth-openid", "~> 1.0.1" gem "omniauth-openid"
gem "webrat", "0.7.3", require: false gem "webrat", "0.7.3", require: false
gem "mocha", "~> 1.1", require: false gem "mocha", "~> 1.1", require: false
gem 'test_after_commit', require: false
end end
platforms :jruby do platforms :jruby do
@@ -25,5 +26,5 @@ platforms :ruby do
end end
group :mongoid do group :mongoid do
gem "mongoid", "~> 4.0.0" gem "mongoid", "~> 4.0"
end end

View File

@@ -1,97 +1,98 @@
GIT GIT
remote: git://github.com/rails/rails.git remote: git://github.com/rails/rails.git
revision: f12ff8ddab7b199707ec36d72bd72f206f142c8b revision: 5be7cfa46e055148c8b74ac5d48982a3435f477c
branch: 4-2-stable branch: 4-2-stable
specs: specs:
actionmailer (4.2.1) actionmailer (4.2.6)
actionpack (= 4.2.1) actionpack (= 4.2.6)
actionview (= 4.2.1) actionview (= 4.2.6)
activejob (= 4.2.1) activejob (= 4.2.6)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.1) actionpack (4.2.6)
actionview (= 4.2.1) actionview (= 4.2.6)
activesupport (= 4.2.1) activesupport (= 4.2.6)
rack (~> 1.6) rack (~> 1.6)
rack-test (~> 0.6.2) rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.1) actionview (4.2.6)
activesupport (= 4.2.1) activesupport (= 4.2.6)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
activejob (4.2.1) activejob (4.2.6)
activesupport (= 4.2.1) activesupport (= 4.2.6)
globalid (>= 0.3.0) globalid (>= 0.3.0)
activemodel (4.2.1) activemodel (4.2.6)
activesupport (= 4.2.1) activesupport (= 4.2.6)
builder (~> 3.1) builder (~> 3.1)
activerecord (4.2.1) activerecord (4.2.6)
activemodel (= 4.2.1) activemodel (= 4.2.6)
activesupport (= 4.2.1) activesupport (= 4.2.6)
arel (~> 6.0) arel (~> 6.0)
activesupport (4.2.1) activesupport (4.2.6)
i18n (~> 0.7) i18n (~> 0.7)
json (~> 1.7, >= 1.7.7) json (~> 1.7, >= 1.7.7)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4) thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
rails (4.2.1) rails (4.2.6)
actionmailer (= 4.2.1) actionmailer (= 4.2.6)
actionpack (= 4.2.1) actionpack (= 4.2.6)
actionview (= 4.2.1) actionview (= 4.2.6)
activejob (= 4.2.1) activejob (= 4.2.6)
activemodel (= 4.2.1) activemodel (= 4.2.6)
activerecord (= 4.2.1) activerecord (= 4.2.6)
activesupport (= 4.2.1) activesupport (= 4.2.6)
bundler (>= 1.3.0, < 2.0) bundler (>= 1.3.0, < 2.0)
railties (= 4.2.1) railties (= 4.2.6)
sprockets-rails sprockets-rails
railties (4.2.1) railties (4.2.6)
actionpack (= 4.2.1) actionpack (= 4.2.6)
activesupport (= 4.2.1) activesupport (= 4.2.6)
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
PATH PATH
remote: .. remote: ..
specs: specs:
devise (3.5.3) devise (4.1.0)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5) railties (>= 4.1.0, < 5.1)
responders responders
thread_safe (~> 0.1)
warden (~> 1.2.3) warden (~> 1.2.3)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
arel (6.0.0) arel (6.0.3)
bcrypt (3.1.10) bcrypt (3.1.11)
bson (2.3.0) bson (3.2.6)
builder (3.2.2) builder (3.2.2)
connection_pool (2.1.3) concurrent-ruby (1.0.2)
connection_pool (2.2.0)
erubis (2.7.0) erubis (2.7.0)
faraday (0.9.1) faraday (0.9.2)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
globalid (0.3.3) globalid (0.3.6)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
hashie (3.4.0) hashie (3.4.4)
hike (1.2.3)
i18n (0.7.0) i18n (0.7.0)
json (1.8.2) json (1.8.3)
jwt (1.4.1) jwt (1.5.1)
loofah (2.0.1) loofah (2.0.3)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.3) mail (2.6.4)
mime-types (>= 1.16, < 3) mime-types (>= 1.16, < 4)
metaclass (0.0.4) metaclass (0.0.4)
mime-types (2.4.3) mime-types (3.0)
mini_portile (0.6.2) mime-types-data (~> 3.2015)
minitest (5.5.1) mime-types-data (3.2016.0221)
mini_portile2 (2.0.0)
minitest (5.9.0)
mocha (1.1.0) mocha (1.1.0)
metaclass (~> 0.0.1) metaclass (~> 0.0.1)
mongoid (4.0.2) mongoid (4.0.2)
@@ -99,38 +100,36 @@ GEM
moped (~> 2.0.0) moped (~> 2.0.0)
origin (~> 2.1) origin (~> 2.1)
tzinfo (>= 0.3.37) tzinfo (>= 0.3.37)
moped (2.0.4) moped (2.0.7)
bson (~> 2.2) bson (~> 3.0)
connection_pool (~> 2.0) connection_pool (~> 2.0)
optionable (~> 0.2.0) optionable (~> 0.2.0)
multi_json (1.11.0) multi_json (1.12.0)
multi_xml (0.5.5) multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
nokogiri (1.6.6.2) nokogiri (1.6.7.2)
mini_portile (~> 0.6.0) mini_portile2 (~> 2.0.0.rc2)
oauth2 (1.0.0) oauth2 (1.1.0)
faraday (>= 0.8, < 0.10) faraday (>= 0.8, < 0.10)
jwt (~> 1.0) jwt (~> 1.0, < 1.5.2)
multi_json (~> 1.3) multi_json (~> 1.3)
multi_xml (~> 0.5) multi_xml (~> 0.5)
rack (~> 1.2) rack (>= 1.2, < 3)
omniauth (1.2.2) omniauth (1.3.1)
hashie (>= 1.2, < 4) hashie (>= 1.2, < 4)
rack (~> 1.0) rack (>= 1.0, < 3)
omniauth-facebook (2.0.1) omniauth-facebook (3.0.0)
omniauth-oauth2 (~> 1.2) omniauth-oauth2 (~> 1.2)
omniauth-oauth2 (1.2.0) omniauth-oauth2 (1.4.0)
faraday (>= 0.8, < 0.10)
multi_json (~> 1.3)
oauth2 (~> 1.0) oauth2 (~> 1.0)
omniauth (~> 1.2) omniauth (~> 1.2)
omniauth-openid (1.0.1) omniauth-openid (1.0.1)
omniauth (~> 1.0) omniauth (~> 1.0)
rack-openid (~> 1.3.1) rack-openid (~> 1.3.1)
optionable (0.2.0) optionable (0.2.0)
origin (2.1.1) origin (2.2.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
rack (1.6.0) rack (1.6.4)
rack-openid (1.3.1) rack-openid (1.3.1)
rack (>= 1.1.0) rack (>= 1.1.0)
ruby-openid (>= 2.1.8) ruby-openid (>= 2.1.8)
@@ -138,33 +137,33 @@ GEM
rack (>= 1.0) rack (>= 1.0)
rails-deprecated_sanitizer (1.0.3) rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha) activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.6) rails-dom-testing (1.0.7)
activesupport (>= 4.2.0.beta, < 5.0) activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0) nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1) rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.2) rails-html-sanitizer (1.0.3)
loofah (~> 2.0) loofah (~> 2.0)
rake (10.4.2) rake (11.1.2)
rdoc (4.2.0) rdoc (4.2.2)
responders (2.1.0) json (~> 1.4)
railties (>= 4.2.0, < 5) responders (2.2.0)
railties (>= 4.2.0, < 5.1)
ruby-openid (2.7.0) ruby-openid (2.7.0)
sprockets (2.12.3) sprockets (3.6.0)
hike (~> 1.2) concurrent-ruby (~> 1.0)
multi_json (~> 1.0) rack (> 1, < 3)
rack (~> 1.0) sprockets-rails (3.0.4)
tilt (~> 1.1, != 1.3.0) actionpack (>= 4.0)
sprockets-rails (2.2.4) activesupport (>= 4.0)
actionpack (>= 3.0) sprockets (>= 3.0.0)
activesupport (>= 3.0) sqlite3 (1.3.11)
sprockets (>= 2.8, < 4.0) test_after_commit (1.0.0)
sqlite3 (1.3.10) activerecord (>= 3.2)
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (1.4.1)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
warden (1.2.4) warden (1.2.6)
rack (>= 1.0) rack (>= 1.0)
webrat (0.7.3) webrat (0.7.3)
nokogiri (>= 1.2.0) nokogiri (>= 1.2.0)
@@ -180,15 +179,16 @@ DEPENDENCIES
devise! devise!
jruby-openssl jruby-openssl
mocha (~> 1.1) mocha (~> 1.1)
mongoid (~> 4.0.0) mongoid (~> 4.0)
omniauth (~> 1.2.2) omniauth
omniauth-facebook omniauth-facebook
omniauth-oauth2 (~> 1.2.0) omniauth-oauth2
omniauth-openid (~> 1.0.1) omniauth-openid
rails! rails!
rdoc rdoc
sqlite3 sqlite3
test_after_commit
webrat (= 0.7.3) webrat (= 0.7.3)
BUNDLED WITH BUNDLED WITH
1.10.6 1.11.2

View File

@@ -0,0 +1,37 @@
source "https://rubygems.org"
gemspec path: ".."
gem "rails", "5.0.0.rc1"
gem "omniauth", " ~> 1.3"
gem "oauth2"
gem "omniauth-oauth2"
gem "rdoc"
gem "activemodel-serializers-xml", github: "rails/activemodel-serializers-xml"
gem "rails-controller-testing"
gem "responders", "~> 2.1"
group :test do
gem "omniauth-facebook"
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"
end
platforms :ruby do
gem "sqlite3"
end
# TODO:
# group :mongoid do
# gem "mongoid", "~> 4.0.0"
# end

View File

@@ -0,0 +1,199 @@
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

View File

@@ -0,0 +1,199 @@
GIT
remote: git://github.com/rails/activemodel-serializers-xml.git
revision: 570ee7ed33d60e44ca1f3ccbec3d1fbf61d52cbf
specs:
activemodel-serializers-xml (1.0.1)
activemodel (> 5.x)
activerecord (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
PATH
remote: ..
specs:
devise (4.1.0)
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.rc1)
actionpack (= 5.0.0.rc1)
nio4r (~> 1.2)
websocket-driver (~> 0.6.1)
actionmailer (5.0.0.rc1)
actionpack (= 5.0.0.rc1)
actionview (= 5.0.0.rc1)
activejob (= 5.0.0.rc1)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (5.0.0.rc1)
actionview (= 5.0.0.rc1)
activesupport (= 5.0.0.rc1)
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.rc1)
activesupport (= 5.0.0.rc1)
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.rc1)
activesupport (= 5.0.0.rc1)
globalid (>= 0.3.6)
activemodel (5.0.0.rc1)
activesupport (= 5.0.0.rc1)
activerecord (5.0.0.rc1)
activemodel (= 5.0.0.rc1)
activesupport (= 5.0.0.rc1)
arel (~> 7.0)
activesupport (5.0.0.rc1)
concurrent-ruby (~> 1.0, >= 1.0.2)
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.2)
erubis (2.7.0)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
globalid (0.3.6)
activesupport (>= 4.1.0)
hashie (3.4.4)
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.9.0)
mocha (1.1.0)
metaclass (~> 0.0.1)
multi_json (1.12.0)
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.rc1)
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.rc1)
actioncable (= 5.0.0.rc1)
actionmailer (= 5.0.0.rc1)
actionpack (= 5.0.0.rc1)
actionview (= 5.0.0.rc1)
activejob (= 5.0.0.rc1)
activemodel (= 5.0.0.rc1)
activerecord (= 5.0.0.rc1)
activesupport (= 5.0.0.rc1)
bundler (>= 1.3.0, < 2.0)
railties (= 5.0.0.rc1)
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.rc1)
actionpack (= 5.0.0.rc1)
activesupport (= 5.0.0.rc1)
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.2.0)
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
omniauth-openid
rails (= 5.0.0.rc1)
rails-controller-testing
rdoc
responders (~> 2.1)
sqlite3
webrat (= 0.7.3)
BUNDLED WITH
1.11.2

View 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

80
lib/devise.rb Normal file → Executable file
View File

@@ -12,19 +12,18 @@ module Devise
autoload :FailureApp, 'devise/failure_app' autoload :FailureApp, 'devise/failure_app'
autoload :OmniAuth, 'devise/omniauth' autoload :OmniAuth, 'devise/omniauth'
autoload :ParameterFilter, 'devise/parameter_filter' autoload :ParameterFilter, 'devise/parameter_filter'
autoload :BaseSanitizer, 'devise/parameter_sanitizer'
autoload :ParameterSanitizer, 'devise/parameter_sanitizer' autoload :ParameterSanitizer, 'devise/parameter_sanitizer'
autoload :TestHelpers, 'devise/test_helpers' autoload :TestHelpers, 'devise/test_helpers'
autoload :TimeInflector, 'devise/time_inflector' autoload :TimeInflector, 'devise/time_inflector'
autoload :TokenGenerator, 'devise/token_generator' autoload :TokenGenerator, 'devise/token_generator'
module Controllers module Controllers
autoload :Helpers, 'devise/controllers/helpers' autoload :Helpers, 'devise/controllers/helpers'
autoload :Rememberable, 'devise/controllers/rememberable' autoload :Rememberable, 'devise/controllers/rememberable'
autoload :ScopedViews, 'devise/controllers/scoped_views' autoload :ScopedViews, 'devise/controllers/scoped_views'
autoload :SignInOut, 'devise/controllers/sign_in_out' autoload :SignInOut, 'devise/controllers/sign_in_out'
autoload :StoreLocation, 'devise/controllers/store_location' autoload :StoreLocation, 'devise/controllers/store_location'
autoload :UrlHelpers, 'devise/controllers/url_helpers' autoload :UrlHelpers, 'devise/controllers/url_helpers'
end end
module Hooks module Hooks
@@ -36,17 +35,22 @@ module Devise
end end
module Strategies module Strategies
autoload :Base, 'devise/strategies/base' autoload :Base, 'devise/strategies/base'
autoload :Authenticatable, 'devise/strategies/authenticatable' autoload :Authenticatable, 'devise/strategies/authenticatable'
end 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 # Constants which holds devise configuration for extensions. Those should
# not be modified by the "end user" (this is why they are constants). # not be modified by the "end user" (this is why they are constants).
ALL = [] ALL = []
CONTROLLERS = ActiveSupport::OrderedHash.new CONTROLLERS = {}
ROUTES = ActiveSupport::OrderedHash.new ROUTES = {}
STRATEGIES = ActiveSupport::OrderedHash.new STRATEGIES = {}
URL_HELPERS = ActiveSupport::OrderedHash.new URL_HELPERS = {}
# Strategies that do not require user input. # Strategies that do not require user input.
NO_INPUT = [] NO_INPUT = []
@@ -62,9 +66,9 @@ module Devise
mattr_accessor :rememberable_options mattr_accessor :rememberable_options
@@rememberable_options = {} @@rememberable_options = {}
# The number of times to encrypt password. # The number of times to hash the password.
mattr_accessor :stretches mattr_accessor :stretches
@@stretches = 10 @@stretches = 11
# The default key used when authenticating over http auth. # The default key used when authenticating over http auth.
mattr_accessor :http_authentication_key mattr_accessor :http_authentication_key
@@ -84,7 +88,7 @@ module Devise
# Keys that should have whitespace stripped. # Keys that should have whitespace stripped.
mattr_accessor :strip_whitespace_keys mattr_accessor :strip_whitespace_keys
@@strip_whitespace_keys = [] @@strip_whitespace_keys = [:email]
# If http authentication is enabled by default. # If http authentication is enabled by default.
mattr_accessor :http_authenticatable mattr_accessor :http_authenticatable
@@ -102,11 +106,11 @@ module Devise
mattr_accessor :http_authentication_realm mattr_accessor :http_authentication_realm
@@http_authentication_realm = "Application" @@http_authentication_realm = "Application"
# Email regex used to validate email formats. It simply asserts that # Email regex used to validate email formats. It asserts that there are no
# an one (and only one) @ exists in the given string. This is mainly # @ symbols or whitespaces in either the localpart or the domain, and that
# to give user feedback and not to assert the e-mail validity. # there is a single @ symbol separating the localpart and the domain.
mattr_accessor :email_regexp mattr_accessor :email_regexp
@@email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\W]+\z/ @@email_regexp = /\A[^@\s]+@[^@\s]+\z/
# Range validation for password length # Range validation for password length
mattr_accessor :password_length mattr_accessor :password_length
@@ -138,15 +142,14 @@ module Devise
@@confirmation_keys = [:email] @@confirmation_keys = [:email]
# Defines if email should be reconfirmable. # Defines if email should be reconfirmable.
# False by default for backwards compatibility.
mattr_accessor :reconfirmable mattr_accessor :reconfirmable
@@reconfirmable = false @@reconfirmable = true
# Time interval to timeout the user session without activity. # Time interval to timeout the user session without activity.
mattr_accessor :timeout_in mattr_accessor :timeout_in
@@timeout_in = 30.minutes @@timeout_in = 30.minutes
# Used to encrypt password. Please generate one with rake secret. # Used to hash the password. Please generate one with rake secret.
mattr_accessor :pepper mattr_accessor :pepper
@@pepper = nil @@pepper = nil
@@ -203,7 +206,7 @@ module Devise
# Skip session storage for the following strategies # Skip session storage for the following strategies
mattr_accessor :skip_session_storage mattr_accessor :skip_session_storage
@@skip_session_storage = [] @@skip_session_storage = [:http_auth]
# Which formats should be treated as navigational. # Which formats should be treated as navigational.
mattr_accessor :navigational_formats mattr_accessor :navigational_formats
@@ -215,7 +218,7 @@ module Devise
# The default method used while signing out # The default method used while signing out
mattr_accessor :sign_out_via mattr_accessor :sign_out_via
@@sign_out_via = :get @@sign_out_via = :delete
# The parent controller all Devise controllers inherits from. # The parent controller all Devise controllers inherits from.
# Defaults to ApplicationController. This should be set early # Defaults to ApplicationController. This should be set early
@@ -244,15 +247,22 @@ module Devise
mattr_accessor :clean_up_csrf_token_on_authentication mattr_accessor :clean_up_csrf_token_on_authentication
@@clean_up_csrf_token_on_authentication = true @@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 # PRIVATE CONFIGURATION
# Store scopes mappings. # Store scopes mappings.
mattr_reader :mappings mattr_reader :mappings
@@mappings = ActiveSupport::OrderedHash.new @@mappings = {}
# OmniAuth configurations. # OmniAuth configurations.
mattr_reader :omniauth_configs mattr_reader :omniauth_configs
@@omniauth_configs = ActiveSupport::OrderedHash.new @@omniauth_configs = {}
# Define a set of modules that are called when a mapping is added. # Define a set of modules that are called when a mapping is added.
mattr_reader :helpers mattr_reader :helpers
@@ -276,14 +286,14 @@ module Devise
mattr_accessor :token_generator mattr_accessor :token_generator
@@token_generator = nil @@token_generator = nil
# Default way to setup Devise. Run rails generate devise_install to create # Default way to set up Devise. Run rails generate devise_install to create
# a fresh initializer with all configuration values. # a fresh initializer with all configuration values.
def self.setup def self.setup
yield self yield self
end end
class Getter class Getter
def initialize name def initialize(name)
@name = name @name = name
end end
@@ -293,12 +303,8 @@ module Devise
end end
def self.ref(arg) def self.ref(arg)
if defined?(ActiveSupport::Dependencies::ClassCache) ActiveSupport::Dependencies.reference(arg)
ActiveSupport::Dependencies::reference(arg) Getter.new(arg)
Getter.new(arg)
else
ActiveSupport::Dependencies.ref(arg)
end
end end
def self.available_router_name def self.available_router_name
@@ -419,7 +425,6 @@ module Devise
# config.omniauth :github, APP_ID, APP_SECRET # config.omniauth :github, APP_ID, APP_SECRET
# #
def self.omniauth(provider, *args) def self.omniauth(provider, *args)
@@helpers << Devise::OmniAuth::UrlHelpers
config = Devise::OmniAuth::Config.new(provider, args) config = Devise::OmniAuth::Config.new(provider, args)
@@omniauth_configs[config.strategy_name.to_sym] = config @@omniauth_configs[config.strategy_name.to_sym] = config
end end
@@ -457,10 +462,7 @@ module Devise
mapping.to.serialize_into_session(record) mapping.to.serialize_into_session(record)
end end
warden_config.serialize_from_session(mapping.name) do |key| warden_config.serialize_from_session(mapping.name) do |args|
# Previous versions contained an additional entry at the beginning of
# key with the record's class name.
args = key[-2, 2]
mapping.to.serialize_from_session(*args) mapping.to.serialize_from_session(*args)
end end
end end

View File

@@ -30,8 +30,8 @@ module Devise
# current_bloggers # Currently signed in user and admin # current_bloggers # Currently signed in user and admin
# #
# Use: # Use:
# before_filter :authenticate_blogger! # Redirects unless either a user or an admin are authenticated # before_action :authenticate_blogger! # Redirects unless either a user or an admin are authenticated
# before_filter ->{ authenticate_blogger! :admin } # Redirects to the admin login page # before_action ->{ authenticate_blogger! :admin } # Redirects to the admin login page
# current_blogger :user # Preferably returns a User if one is signed in # current_blogger :user # Preferably returns a User if one is signed in
# #
def devise_group(group_name, opts={}) def devise_group(group_name, opts={})
@@ -84,7 +84,7 @@ module Devise
end end
# Define authentication filters and accessor helpers based on mappings. # Define authentication filters and accessor helpers based on mappings.
# These filters should be used inside the controllers as before_filters, # These filters should be used inside the controllers as before_actions,
# so you can control the scope of the user who should be signed in to # so you can control the scope of the user who should be signed in to
# access that specific controller/action. # access that specific controller/action.
# Example: # Example:
@@ -104,8 +104,8 @@ module Devise
# admin_session # Session data available only to the admin scope # admin_session # Session data available only to the admin scope
# #
# Use: # Use:
# before_filter :authenticate_user! # Tell devise to use :user map # before_action :authenticate_user! # Tell devise to use :user map
# before_filter :authenticate_admin! # Tell devise to use :admin map # before_action :authenticate_admin! # Tell devise to use :admin map
# #
def self.define_helpers(mapping) #:nodoc: def self.define_helpers(mapping) #:nodoc:
mapping = mapping.name mapping = mapping.name
@@ -138,27 +138,23 @@ module Devise
# The main accessor for the warden proxy instance # The main accessor for the warden proxy instance
def warden def warden
request.env['warden'] request.env['warden'] or raise MissingWarden
end end
# Return true if it's a devise_controller. false to all controllers unless # Return true if it's a devise_controller. false to all controllers unless
# the controllers defined inside devise. Useful if you want to apply a before # the controllers defined inside devise. Useful if you want to apply a before
# filter to all controllers, except the ones in devise: # filter to all controllers, except the ones in devise:
# #
# before_filter :my_filter, unless: :devise_controller? # before_action :my_filter, unless: :devise_controller?
def devise_controller? def devise_controller?
is_a?(::DeviseController) is_a?(::DeviseController)
end end
# Setup a param sanitizer to filter parameters using strong_parameters. See # Set up a param sanitizer to filter parameters using strong_parameters. See
# lib/devise/parameter_sanitizer.rb for more info. Override this # lib/devise/parameter_sanitizer.rb for more info. Override this
# method in your application controller to use your own parameter sanitizer. # method in your application controller to use your own parameter sanitizer.
def devise_parameter_sanitizer def devise_parameter_sanitizer
@devise_parameter_sanitizer ||= if defined?(ActionController::StrongParameters) @devise_parameter_sanitizer ||= Devise::ParameterSanitizer.new(resource_class, resource_name, params)
Devise::ParameterSanitizer.new(resource_class, resource_name, params)
else
Devise::BaseSanitizer.new(resource_class, resource_name, params)
end
end end
# Tell warden that params authentication is allowed for that specific page. # Tell warden that params authentication is allowed for that specific page.
@@ -275,16 +271,21 @@ module Devise
private private
def expire_session_data_after_sign_in!
ActiveSupport::Deprecation.warn "expire_session_data_after_sign_in! is deprecated " \
"in favor of expire_data_after_sign_in!"
expire_data_after_sign_in!
end
def expire_data_after_sign_out! def expire_data_after_sign_out!
Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) } Devise.mappings.each { |_,m| instance_variable_set("@current_#{m.name}", nil) }
super super
end end
end 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 end

View File

@@ -9,11 +9,18 @@ module Devise
Rails.configuration.session_options.slice(:path, :domain, :secure) Rails.configuration.session_options.slice(:path, :domain, :secure)
end end
def remember_me_is_active?(resource)
return false unless resource.respond_to?(:remember_me)
scope = Devise::Mapping.find_scope!(resource)
_, token, generated_at = cookies.signed[remember_key(resource, scope)]
resource.remember_me?(token, generated_at)
end
# Remembers the given resource by setting up a cookie # Remembers the given resource by setting up a cookie
def remember_me(resource) def remember_me(resource)
return if env["devise.skip_storage"] return if env["devise.skip_storage"]
scope = Devise::Mapping.find_scope!(resource) scope = Devise::Mapping.find_scope!(resource)
resource.remember_me!(resource.extend_remember_period) resource.remember_me!
cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource) cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource)
end end

View File

@@ -12,20 +12,15 @@ module Devise
end end
# Sign in a user that already was authenticated. This helper is useful for logging # Sign in a user that already was authenticated. This helper is useful for logging
# users in after sign up. # users in after sign up. All options given to sign_in is passed forward
# # to the set_user method in warden.
# 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.
# #
# Examples: # Examples:
# #
# sign_in :user, @user # sign_in(scope, resource) # sign_in :user, @user # sign_in(scope, resource)
# sign_in @user # sign_in(resource) # sign_in @user # sign_in(resource)
# sign_in @user, event: :authentication # sign_in(resource, options) # sign_in @user, event: :authentication # sign_in(resource, options)
# sign_in @user, store: false # sign_in(resource, options) # sign_in @user, store: false # sign_in(resource, options)
# sign_in @user, bypass: true # sign_in(resource, options)
# #
def sign_in(resource_or_scope, *args) def sign_in(resource_or_scope, *args)
options = args.extract_options! options = args.extract_options!
@@ -35,6 +30,13 @@ module Devise
expire_data_after_sign_in! expire_data_after_sign_in!
if options[:bypass] 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) warden.session_serializer.store(resource, scope)
elsif warden.user(scope) == resource && !options.delete(:force) elsif warden.user(scope) == resource && !options.delete(:force)
# Do nothing. User already signed in and we are not forcing it. # Do nothing. User already signed in and we are not forcing it.
@@ -44,6 +46,20 @@ module Devise
end end
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 # 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 # after deleting accounts. Returns true if there was a logout and false if there
# is no user logged in on the referred scope # is no user logged in on the referred scope

View File

@@ -9,14 +9,14 @@ module Devise
::BCrypt::Password.create(password, cost: klass.stretches).to_s ::BCrypt::Password.create(password, cost: klass.stretches).to_s
end end
def self.compare(klass, encrypted_password, password) def self.compare(klass, hashed_password, password)
return false if encrypted_password.blank? return false if hashed_password.blank?
bcrypt = ::BCrypt::Password.new(encrypted_password) bcrypt = ::BCrypt::Password.new(hashed_password)
if klass.pepper.present? if klass.pepper.present?
password = "#{password}#{klass.pepper}" password = "#{password}#{klass.pepper}"
end end
password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt) password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt)
Devise.secure_compare(password, encrypted_password) Devise.secure_compare(password, hashed_password)
end end
end end
end end

View File

@@ -6,7 +6,6 @@ module Devise
# page based on current scope and mapping. If no scope is given, redirect # page based on current scope and mapping. If no scope is given, redirect
# to the default_url. # to the default_url.
class FailureApp < ActionController::Metal class FailureApp < ActionController::Metal
include ActionController::RackDelegation
include ActionController::UrlFor include ActionController::UrlFor
include ActionController::Redirecting include ActionController::Redirecting
@@ -22,7 +21,7 @@ module Devise
@respond.call(env) @respond.call(env)
end end
# Try retrieving the URL options from the parent controller (usually # Try retrieving the URL options from the parent controller (usually
# ApplicationController). Instance methods are not supported at the moment, # ApplicationController). Instance methods are not supported at the moment,
# so only the class-level attribute is used. # so only the class-level attribute is used.
def self.default_url_options(*args) def self.default_url_options(*args)
@@ -53,18 +52,27 @@ module Devise
def recall def recall
config = Rails.application.config config = Rails.application.config
if config.try(:relative_url_root) header_info = if config.try(:relative_url_root)
base_path = Pathname.new(config.relative_url_root) base_path = Pathname.new(config.relative_url_root)
full_path = Pathname.new(attempted_path) full_path = Pathname.new(attempted_path)
env["SCRIPT_NAME"] = config.relative_url_root { "SCRIPT_NAME" => config.relative_url_root,
env["PATH_INFO"] = '/' + full_path.relative_path_from(base_path).to_s "PATH_INFO" => '/' + full_path.relative_path_from(base_path).to_s }
else else
env["PATH_INFO"] = attempted_path { "PATH_INFO" => attempted_path }
end
header_info.each do | var, value|
if request.respond_to?(:set_header)
request.set_header(var, value)
else
env[var] = value
end
end end
flash.now[:alert] = i18n_message(:invalid) if is_flashing_format? flash.now[:alert] = i18n_message(:invalid) if is_flashing_format?
self.response = recall_app(warden_options[:recall]).call(env) # self.response = recall_app(warden_options[:recall]).call(env)
self.response = recall_app(warden_options[:recall]).call(request.env)
end end
def redirect def redirect
@@ -95,7 +103,7 @@ module Devise
options[:scope] = "devise.failure" options[:scope] = "devise.failure"
options[:default] = [message] options[:default] = [message]
auth_keys = scope_class.authentication_keys auth_keys = scope_class.authentication_keys
keys = auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key| scope_class.human_attribute_name(key) }
options[:authentication_keys] = keys.join(I18n.translate(:"support.array.words_connector")) options[:authentication_keys] = keys.join(I18n.translate(:"support.array.words_connector"))
options = i18n_options(options) options = i18n_options(options)
@@ -132,11 +140,10 @@ module Devise
config = Rails.application.config config = Rails.application.config
# Rails 4.2 goes into an infinite loop if opts[:script_name] is unset if config.respond_to?(:relative_url_root)
if (Rails::VERSION::MAJOR >= 4) && (Rails::VERSION::MINOR >= 2) # Rails 4.2 goes into an infinite loop if opts[:script_name] is unset
opts[:script_name] = (config.relative_url_root if config.respond_to?(:relative_url_root)) rails_4_2 = (Rails::VERSION::MAJOR >= 4) && (Rails::VERSION::MINOR >= 2)
else if config.relative_url_root.present? || rails_4_2
if config.respond_to?(:relative_url_root) && config.relative_url_root.present?
opts[:script_name] = config.relative_url_root opts[:script_name] = config.relative_url_root
end end
end end
@@ -199,11 +206,11 @@ module Devise
end end
def warden def warden
env['warden'] request.respond_to?(:get_header) ? request.get_header("warden") : env["warden"]
end end
def warden_options def warden_options
env['warden.options'] request.respond_to?(:get_header) ? request.get_header("warden.options") : env["warden.options"]
end end
def warden_message def warden_message

View File

@@ -19,9 +19,10 @@ Warden::Manager.after_set_user do |record, warden, options|
proxy = Devise::Hooks::Proxy.new(warden) proxy = Devise::Hooks::Proxy.new(warden)
if record.timedout?(last_request_at) && !env['devise.skip_timeout'] if record.timedout?(last_request_at) &&
!env['devise.skip_timeout'] &&
!proxy.remember_me_is_active?(record)
Devise.sign_out_all_scopes ? proxy.sign_out : proxy.sign_out(scope) Devise.sign_out_all_scopes ? proxy.sign_out : proxy.sign_out(scope)
throw :warden, scope: scope, message: :timeout throw :warden, scope: scope, message: :timeout
end end

View File

@@ -64,7 +64,7 @@ module Devise
template_path template_path
end end
# Setup a subject doing an I18n lookup. At first, it attempts to set a subject # Set up a subject doing an I18n lookup. At first, it attempts to set a subject
# based on the current mapping: # based on the current mapping:
# #
# en: # en:

View File

@@ -143,13 +143,25 @@ module Devise
# if new_record? || changed? # if new_record? || changed?
# pending_notifications << [notification, args] # pending_notifications << [notification, args]
# else # 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
# end # end
# #
# def send_pending_notifications # def send_pending_notifications
# pending_notifications.each do |notification, args| # 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 # end
# #
# # Empty the pending notifications array because the # # Empty the pending notifications array because the
@@ -253,7 +265,11 @@ module Devise
# Find or initialize a record with group of attributes based on a list of required attributes. # Find or initialize a record with group of attributes based on a list of required attributes.
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc: def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
attributes = attributes.slice(*required_attributes).with_indifferent_access attributes = if attributes.respond_to? :permit!
attributes.slice(*required_attributes).permit!.to_h.with_indifferent_access
else
attributes.with_indifferent_access.slice(*required_attributes)
end
attributes.delete_if { |key, value| value.blank? } attributes.delete_if { |key, value| value.blank? }
if attributes.size == required_attributes.size if attributes.size == required_attributes.size

View File

@@ -24,7 +24,7 @@ module Devise
# By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in. # By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in.
# * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as # * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as
# initial account confirmation) to be applied. Requires additional unconfirmed_email # initial account confirmation) to be applied. Requires additional unconfirmed_email
# db field to be setup (t.reconfirmable in migrations). Until confirmed, new email is # 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 # stored in unconfirmed email column, and copied to email column on successful
# confirmation. # confirmation.
# * +confirm_within+: the time before a sent confirmation token becomes invalid. # * +confirm_within+: the time before a sent confirmation token becomes invalid.
@@ -40,13 +40,18 @@ module Devise
# #
module Confirmable module Confirmable
extend ActiveSupport::Concern extend ActiveSupport::Concern
include ActionView::Helpers::DateHelper
included do included do
before_create :generate_confirmation_token, if: :confirmation_required? before_create :generate_confirmation_token, if: :confirmation_required?
after_create :send_on_create_confirmation_instructions, if: :send_confirmation_notification? after_create :skip_reconfirmation!, 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?
else # Mongoid
after_create :send_on_create_confirmation_instructions, if: :send_confirmation_notification?
after_update :send_reconfirmation_instructions, if: :reconfirmation_required?
end
before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, if: :postpone_email_change? before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, if: :postpone_email_change?
after_update :send_reconfirmation_instructions, if: :reconfirmation_required?
end end
def initialize(*args, &block) def initialize(*args, &block)
@@ -76,7 +81,7 @@ module Devise
self.confirmed_at = Time.now.utc self.confirmed_at = Time.now.utc
saved = if self.class.reconfirmable && unconfirmed_email.present? saved = if pending_reconfirmation?
skip_reconfirmation! skip_reconfirmation!
self.email = unconfirmed_email self.email = unconfirmed_email
self.unconfirmed_email = nil self.unconfirmed_email = nil
@@ -92,11 +97,6 @@ module Devise
end end
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 # Verifies whether a user is confirmed or not
def confirmed? def confirmed?
!!confirmed_at !!confirmed_at
@@ -180,7 +180,7 @@ module Devise
# Checks if the confirmation for the user is within the limit time. # Checks if the confirmation for the user is within the limit time.
# We do this by calculating if the difference between today and the # We do this by calculating if the difference between today and the
# confirmation sent date does not exceed the confirm in time configured. # confirmation sent date does not exceed the confirm in time configured.
# Confirm_within is a model configuration, must always be an integer value. # allow_unconfirmed_access_for is a model configuration, must always be an integer value.
# #
# Example: # Example:
# #
@@ -235,8 +235,7 @@ module Devise
if self.confirmation_token && !confirmation_period_expired? if self.confirmation_token && !confirmation_period_expired?
@raw_confirmation_token = self.confirmation_token @raw_confirmation_token = self.confirmation_token
else else
raw, _ = Devise.token_generator.generate(self.class, :confirmation_token) self.confirmation_token = @raw_confirmation_token = Devise.friendly_token
self.confirmation_token = @raw_confirmation_token = raw
self.confirmation_sent_at = Time.now.utc self.confirmation_sent_at = Time.now.utc
end end
end end
@@ -260,7 +259,7 @@ module Devise
end end
def reconfirmation_required? def reconfirmation_required?
self.class.reconfirmable && @reconfirmation_required && self.email.present? self.class.reconfirmable && @reconfirmation_required && (self.email.present? || self.unconfirmed_email.present?)
end end
def send_confirmation_notification? def send_confirmation_notification?
@@ -315,6 +314,7 @@ module Devise
# Find a record for confirmation by unconfirmed email field # Find a record for confirmation by unconfirmed email field
def find_by_unconfirmed_email_with_errors(attributes = {}) def find_by_unconfirmed_email_with_errors(attributes = {})
attributes = attributes.slice(*confirmation_keys).permit!.to_h if attributes.respond_to? :permit
unconfirmed_required_attributes = confirmation_keys.map { |k| k == :email ? :unconfirmed_email : k } unconfirmed_required_attributes = confirmation_keys.map { |k| k == :email ? :unconfirmed_email : k }
unconfirmed_attributes = attributes.symbolize_keys unconfirmed_attributes = attributes.symbolize_keys
unconfirmed_attributes[:unconfirmed_email] = unconfirmed_attributes.delete(:email) unconfirmed_attributes[:unconfirmed_email] = unconfirmed_attributes.delete(:email)

View File

@@ -1,14 +1,9 @@
require 'devise/strategies/database_authenticatable' require 'devise/strategies/database_authenticatable'
module Devise 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 module Models
# Authenticatable Module, responsible for encrypting password and validating # Authenticatable Module, responsible for hashing the password and
# authenticity of a user while signing in. # validating the authenticity of a user while signing in.
# #
# == Options # == Options
# #
@@ -37,7 +32,9 @@ module Devise
[:encrypted_password] + klass.authentication_keys [:encrypted_password] + klass.authentication_keys
end end
# Generates password encryption based on the given value. # Generates a hashed password based on the given value.
# For legacy reasons, we use `encrypted_password` to store
# the hashed password.
def password=(new_password) def password=(new_password)
@password = new_password @password = new_password
self.encrypted_password = password_digest(@password) if @password.present? self.encrypted_password = password_digest(@password) if @password.present?
@@ -141,11 +138,11 @@ module Devise
protected protected
# Digests the password using bcrypt. Custom encryption should override # Hashes the password using bcrypt. Custom hash functions should override
# this method to apply their own algorithm. # this method to apply their own algorithm.
# #
# See https://github.com/plataformatec/devise-encryptable for examples # See https://github.com/plataformatec/devise-encryptable for examples
# of other encryption engines. # of other hashing engines.
def password_digest(password) def password_digest(password)
Devise::Encryptor.digest(self.class, password) Devise::Encryptor.digest(self.class, password)
end end

View File

@@ -7,7 +7,7 @@ module Devise
# blocked: email and time. The former will send an email to the user when # blocked: email and time. The former will send an email to the user when
# the lock happens, containing a link to unlock its account. The second # the lock happens, containing a link to unlock its account. The second
# will unlock the user automatically after some configured time (ie 2.hours). # will unlock the user automatically after some configured time (ie 2.hours).
# It's also possible to setup lockable to use both email and time strategies. # It's also possible to set up lockable to use both email and time strategies.
# #
# == Options # == Options
# #
@@ -64,7 +64,7 @@ module Devise
def send_unlock_instructions def send_unlock_instructions
raw, enc = Devise.token_generator.generate(self.class, :unlock_token) raw, enc = Devise.token_generator.generate(self.class, :unlock_token)
self.unlock_token = enc self.unlock_token = enc
self.save(validate: false) save(validate: false)
send_devise_notification(:unlock_instructions, raw, {}) send_devise_notification(:unlock_instructions, raw, {})
raw raw
end end
@@ -155,6 +155,9 @@ module Devise
end end
module ClassMethods module ClassMethods
# List of strategies that are enabled/supported if :both is used.
BOTH_STRATEGIES = [:time, :email]
# Attempt to find a user by its unlock keys. If a record is found, send new # Attempt to find a user by its unlock keys. If a record is found, send new
# unlock instructions to it. If not user is found, returns a new user # unlock instructions to it. If not user is found, returns a new user
# with an email not found error. # with an email not found error.
@@ -181,7 +184,8 @@ module Devise
# Is the unlock enabled for the given unlock strategy? # Is the unlock enabled for the given unlock strategy?
def unlock_strategy_enabled?(strategy) def unlock_strategy_enabled?(strategy)
[:both, strategy].include?(self.unlock_strategy) self.unlock_strategy == strategy ||
(self.unlock_strategy == :both && BOTH_STRATEGIES.include?(strategy))
end end
# Is the lock enabled for the given lock strategy? # Is the lock enabled for the given lock strategy?

View File

@@ -40,19 +40,9 @@ module Devise
self.password = new_password self.password = new_password
self.password_confirmation = new_password_confirmation self.password_confirmation = new_password_confirmation
if respond_to?(:after_password_reset) && valid?
ActiveSupport::Deprecation.warn "after_password_reset is deprecated"
after_password_reset
end
save save
end 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. # Resets reset password token and send reset password instructions by email.
# Returns the token sent in the e-mail. # Returns the token sent in the e-mail.
def send_reset_password_instructions def send_reset_password_instructions
@@ -83,7 +73,7 @@ module Devise
# reset_password_period_valid? # will always return false # reset_password_period_valid? # will always return false
# #
def reset_password_period_valid? def reset_password_period_valid?
reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago.utc
end end
protected protected
@@ -99,7 +89,7 @@ module Devise
self.reset_password_token = enc self.reset_password_token = enc
self.reset_password_sent_at = Time.now.utc self.reset_password_sent_at = Time.now.utc
self.save(validate: false) save(validate: false)
raw raw
end end

View File

@@ -39,17 +39,15 @@ module Devise
module Rememberable module Rememberable
extend ActiveSupport::Concern extend ActiveSupport::Concern
attr_accessor :remember_me, :extend_remember_period attr_accessor :remember_me
def self.required_fields(klass) def self.required_fields(klass)
[:remember_created_at] [:remember_created_at]
end end
# Generate a new remember token and save the record without validations def remember_me!
# if remember expired (token is no longer valid) or extend_remember_period is true self.remember_token ||= self.class.remember_token if respond_to?(:remember_token)
def remember_me!(extend_period=false) self.remember_created_at ||= Time.now.utc
self.remember_token = self.class.remember_token if generate_remember_token?
self.remember_created_at = Time.now.utc if generate_remember_timestamp?(extend_period)
save(validate: false) if self.changed? save(validate: false) if self.changed?
end end
@@ -57,19 +55,17 @@ module Devise
# it exists), and save the record without validations. # it exists), and save the record without validations.
def forget_me! def forget_me!
return unless persisted? return unless persisted?
self.remember_token = nil if respond_to?(:remember_token=) self.remember_token = nil if respond_to?(:remember_token)
self.remember_created_at = nil if self.class.expire_all_remember_me_on_sign_out self.remember_created_at = nil if self.class.expire_all_remember_me_on_sign_out
save(validate: false) save(validate: false)
end end
# Remember token should be expired if expiration time not overpass now. def remember_expires_at
def remember_expired? self.class.remember_for.from_now
remember_created_at.nil? || (remember_expires_at <= Time.now.utc)
end end
# Remember token expires at created time + remember_for configuration def extend_remember_period
def remember_expires_at self.class.extend_remember_period
remember_created_at + self.class.remember_for
end end
def rememberable_value def rememberable_value
@@ -102,29 +98,47 @@ module Devise
def after_remembered def after_remembered
end end
protected def remember_me?(token, generated_at)
# TODO: Normalize the JSON type coercion along with the Timeoutable hook
# in a single place https://github.com/plataformatec/devise/blob/ffe9d6d406e79108cf32a2c6a1d0b3828849c40b/lib/devise/hooks/timeoutable.rb#L14-L18
if generated_at.is_a?(String)
generated_at = time_from_json(generated_at)
end
def generate_remember_token? #:nodoc: # The token is only valid if:
respond_to?(:remember_token) && remember_expired? # 1. we have a date
# 2. the current time does not pass the expiry period
# 3. the record has a remember_created_at date
# 4. the token date is bigger than the remember_created_at
# 5. the token matches
generated_at.is_a?(Time) &&
(self.class.remember_for.ago < generated_at) &&
(generated_at > (remember_created_at || Time.now).utc) &&
Devise.secure_compare(rememberable_value, token)
end end
# Generate a timestamp if extend_remember_period is true, if no remember_token private
# exists, or if an existing remember token has expired.
def generate_remember_timestamp?(extend_period) #:nodoc: def time_from_json(value)
extend_period || remember_expired? if value =~ /\A\d+\.\d+\Z/
Time.at(value.to_f)
else
Time.parse(value) rescue nil
end
end end
module ClassMethods module ClassMethods
# Create the cookie key using the record id and remember_token # Create the cookie key using the record id and remember_token
def serialize_into_cookie(record) def serialize_into_cookie(record)
[record.to_key, record.rememberable_value] [record.to_key, record.rememberable_value, Time.now.utc.to_f.to_s]
end end
# Recreate the user based on the stored cookie # Recreate the user based on the stored cookie
def serialize_from_cookie(id, remember_token) def serialize_from_cookie(*args)
id, token, generated_at = *args
record = to_adapter.get(id) record = to_adapter.get(id)
record if record && !record.remember_expired? && record if record && record.remember_me?(token, generated_at)
Devise.secure_compare(record.rememberable_value, remember_token)
end end
# Generate a token checking if one does not already exist in the database. # Generate a token checking if one does not already exist in the database.

View File

@@ -26,7 +26,6 @@ module Devise
# Checks whether the user session has expired based on configured time. # Checks whether the user session has expired based on configured time.
def timedout?(last_access) def timedout?(last_access)
return false if remember_exists_and_not_expired?
!timeout_in.nil? && last_access && last_access <= timeout_in.ago !timeout_in.nil? && last_access && last_access <= timeout_in.ago
end end
@@ -36,11 +35,6 @@ module Devise
private private
def remember_exists_and_not_expired?
return false unless respond_to?(:remember_created_at) && respond_to?(:remember_expired?)
remember_created_at && !remember_expired?
end
module ClassMethods module ClassMethods
Devise::Models.config(self, :timeout_in) Devise::Models.config(self, :timeout_in)
end end

View File

@@ -1,17 +1,24 @@
module Devise module Devise
module OmniAuth module OmniAuth
module UrlHelpers module UrlHelpers
def self.define_helpers(mapping) 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)
end end
def omniauth_authorize_path(resource_or_scope, *args) def omniauth_authorize_url(resource_or_scope, provider, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope) scope = Devise::Mapping.find_scope!(resource_or_scope)
_devise_route_context.send("#{scope}_omniauth_authorize_path", *args) _devise_route_context.send("#{scope}_#{provider}_omniauth_authorize_url", *args)
end end
def omniauth_callback_path(resource_or_scope, *args) def omniauth_callback_path(resource_or_scope, provider, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope) scope = Devise::Mapping.find_scope!(resource_or_scope)
_devise_route_context.send("#{scope}_omniauth_callback_path", *args) _devise_route_context.send("#{scope}_#{provider}_omniauth_callback_path", *args)
end
def omniauth_callback_url(resource_or_scope, provider, *args)
scope = Devise::Mapping.find_scope!(resource_or_scope)
_devise_route_context.send("#{scope}_#{provider}_omniauth_callback_url", *args)
end end
end end
end end

View File

@@ -1,99 +1,159 @@
module Devise module Devise
class BaseSanitizer # The +ParameterSanitizer+ deals with permitting specific parameters values
attr_reader :params, :resource_name, :resource_class # for each +Devise+ scope in the application.
#
# The sanitizer knows about Devise default parameters (like +password+ and
# +password_confirmation+ for the `RegistrationsController`), and you can
# extend or change the permitted parameters list on your controllers.
#
# === Permitting new parameters
#
# You can add new parameters to the permitted list using the +permit+ method
# in a +before_action+ method, for instance.
#
# class ApplicationController < ActionController::Base
# before_action :configure_permitted_parameters, if: :devise_controller?
#
# protected
#
# def configure_permitted_parameters
# # Permit the `subscribe_newsletter` parameter along with the other
# # sign up parameters.
# devise_parameter_sanitizer.permit(:sign_up, keys: [:subscribe_newsletter])
# end
# end
#
# Using a block yields an +ActionController::Parameters+ object so you can
# permit nested parameters and have more control over how the parameters are
# permitted in your controller.
#
# def configure_permitted_parameters
# devise_parameter_sanitizer.permit(:sign_up) do |user|
# user.permit(newsletter_preferences: [])
# end
# end
class ParameterSanitizer
DEFAULT_PERMITTED_ATTRIBUTES = {
sign_in: [:password, :remember_me],
sign_up: [:password, :password_confirmation],
account_update: [:password, :password_confirmation, :current_password]
}
def initialize(resource_class, resource_name, params) def initialize(resource_class, resource_name, params)
@resource_class = resource_class @auth_keys = extract_auth_keys(resource_class)
@resource_name = resource_name
@params = params @params = params
@blocks = Hash.new @resource_name = resource_name
end @permitted = {}
def for(kind, &block) DEFAULT_PERMITTED_ATTRIBUTES.each_pair do |action, keys|
if block_given? permit(action, keys: keys)
@blocks[kind] = block
else
default_for(kind)
end end
end end
def sanitize(kind) # Sanitize the parameters for a specific +action+.
if block = @blocks[kind] #
block.call(default_params) # === Arguments
#
# * +action+ - A +Symbol+ with the action that the controller is
# performing, like +sign_up+, +sign_in+, etc.
#
# === Examples
#
# # Inside the `RegistrationsController#create` action.
# resource = build_resource(devise_parameter_sanitizer.sanitize(:sign_up))
# resource.save
#
# Returns an +ActiveSupport::HashWithIndifferentAccess+ with the permitted
# attributes.
def sanitize(action)
permissions = @permitted[action]
if permissions.respond_to?(:call)
cast_to_hash permissions.call(default_params)
elsif permissions.present?
cast_to_hash permit_keys(default_params, permissions)
else else
default_sanitize(kind) unknown_action!(action)
end
end
# Add or remove new parameters to the permitted list of an +action+.
#
# === Arguments
#
# * +action+ - A +Symbol+ with the action that the controller is
# performing, like +sign_up+, +sign_in+, etc.
# * +keys:+ - An +Array+ of keys that also should be permitted.
# * +except:+ - An +Array+ of keys that shouldn't be permitted.
# * +block+ - A block that should be used to permit the action
# parameters instead of the +Array+ based approach. The block will be
# called with an +ActionController::Parameters+ instance.
#
# === Examples
#
# # Adding new parameters to be permitted in the `sign_up` action.
# devise_parameter_sanitizer.permit(:sign_up, keys: [:subscribe_newsletter])
#
# # Removing the `password` parameter from the `account_update` action.
# devise_parameter_sanitizer.permit(:account_update, except: [:password])
#
# # Using the block form to completely override how we permit the
# # parameters for the `sign_up` action.
# devise_parameter_sanitizer.permit(:sign_up) do |user|
# user.permit(:email, :password, :password_confirmation)
# end
#
#
# Returns nothing.
def permit(action, keys: nil, except: nil, &block)
if block_given?
@permitted[action] = block
end
if keys.present?
@permitted[action] ||= @auth_keys.dup
@permitted[action].concat(keys)
end
if except.present?
@permitted[action] ||= @auth_keys.dup
@permitted[action] = @permitted[action] - except
end end
end end
private private
def default_for(kind) # Cast a sanitized +ActionController::Parameters+ to a +HashWithIndifferentAccess+
raise ArgumentError, "a block is expected in Devise base sanitizer" # that can be used elsewhere.
end #
# Returns an +ActiveSupport::HashWithIndifferentAccess+.
def default_sanitize(kind) def cast_to_hash(params)
default_params # TODO: Remove the `with_indifferent_access` method call when we only support Rails 5+.
params && params.to_h.with_indifferent_access
end end
def default_params def default_params
params.fetch(resource_name, {}) @params.fetch(@resource_name, {})
end
end
class ParameterSanitizer < BaseSanitizer
def initialize(*)
super
@permitted = Hash.new { |h,k| h[k] = attributes_for(k) }
end end
def sign_in def permit_keys(parameters, keys)
permit self.for(:sign_in) parameters.permit(*keys)
end end
def sign_up def extract_auth_keys(klass)
permit self.for(:sign_up) auth_keys = klass.authentication_keys
auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys
end end
def account_update def unknown_action!(action)
permit self.for(:account_update) raise NotImplementedError, <<-MESSAGE.strip_heredoc
end "Devise doesn't know how to sanitize parameters for '#{action}'".
If you want to define a new set of parameters to be sanitized use the
`permit` method first:
private devise_parameter_sanitizer.permit(:#{action}, keys: [:param1, :param2, :param3])
MESSAGE
# TODO: We do need to flatten so it works with strong_parameters
# gem. We should drop it once we move to Rails 4 only support.
def permit(keys)
default_params.permit(*Array(keys))
end
# Change for(kind) to return the values in the @permitted
# hash, allowing the developer to customize at runtime.
def default_for(kind)
@permitted[kind] || raise("No sanitizer provided for #{kind}")
end
def default_sanitize(kind)
if respond_to?(kind, true)
send(kind)
else
raise NotImplementedError, "Devise doesn't know how to sanitize parameters for #{kind}"
end
end
def attributes_for(kind)
case kind
when :sign_in
auth_keys + [:password, :remember_me]
when :sign_up
auth_keys + [:password, :password_confirmation]
when :account_update
auth_keys + [:password, :password_confirmation, :current_password]
end
end
def auth_keys
@auth_keys ||= @resource_class.authentication_keys.respond_to?(:keys) ?
@resource_class.authentication_keys.keys : @resource_class.authentication_keys
end end
end end
end end

View File

@@ -11,7 +11,9 @@ module Devise
end end
# Force routes to be loaded if we are doing any eager load. # 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 initializer "devise.url_helpers" do
Devise.include_helpers(Devise::Controllers) Devise.include_helpers(Devise::Controllers)
@@ -39,18 +41,9 @@ module Devise
Devise.token_generator ||= Devise.token_generator ||=
if secret_key = Devise.secret_key if secret_key = Devise.secret_key
Devise::TokenGenerator.new( Devise::TokenGenerator.new(
Devise::CachingKeyGenerator.new(Devise::KeyGenerator.new(secret_key)) ActiveSupport::CachingKeyGenerator.new(ActiveSupport::KeyGenerator.new(secret_key))
) )
end end
end end
initializer "devise.fix_routes_proxy_missing_respond_to_bug" do
# Deprecate: Remove once we move to Rails 4 only.
ActionDispatch::Routing::RoutesProxy.class_eval do
def respond_to?(method, include_private = false)
super || routes.url_helpers.respond_to?(method)
end
end
end
end end
end end

View File

@@ -1,13 +1,10 @@
require "active_support/core_ext/object/try" require "active_support/core_ext/object/try"
require "active_support/core_ext/hash/slice" require "active_support/core_ext/hash/slice"
module ActionDispatch::Routing module Devise
class RouteSet #:nodoc: module RouteSet
# Ensure Devise modules are included only after loading routes, because we def finalize!
# need devise_for mappings already declared to create filters and helpers. result = super
def finalize_with_devise!
result = finalize_without_devise!
@devise_finalized ||= begin @devise_finalized ||= begin
if Devise.router_name.nil? && defined?(@devise_finalized) && self != Rails.application.try(:routes) if Devise.router_name.nil? && defined?(@devise_finalized) && self != Rails.application.try(:routes)
warn "[DEVISE] We have detected that you are using devise_for inside engine routes. " \ warn "[DEVISE] We have detected that you are using devise_for inside engine routes. " \
@@ -21,10 +18,16 @@ module ActionDispatch::Routing
Devise.regenerate_helpers! Devise.regenerate_helpers!
true true
end end
result result
end end
alias_method_chain :finalize!, :devise end
end
module ActionDispatch::Routing
class RouteSet #:nodoc:
# Ensure Devise modules are included only after loading routes, because we
# need devise_for mappings already declared to create filters and helpers.
prepend Devise::RouteSet
end end
class Mapper class Mapper
@@ -84,17 +87,17 @@ module ActionDispatch::Routing
# #
# You can configure your routes with some options: # You can configure your routes with some options:
# #
# * class_name: setup a different class to be looked up by devise, if it cannot be # * class_name: set up a different class to be looked up by devise, if it cannot be
# properly found by the route name. # properly found by the route name.
# #
# devise_for :users, class_name: 'Account' # devise_for :users, class_name: 'Account'
# #
# * path: allows you to setup path name that will be used, as rails routes does. # * path: allows you to set up path name that will be used, as rails routes does.
# The following route configuration would setup your route as /accounts instead of /users: # The following route configuration would set up your route as /accounts instead of /users:
# #
# devise_for :users, path: 'accounts' # devise_for :users, path: 'accounts'
# #
# * singular: setup the singular name for the given resource. This is used as the helper methods # * singular: set up the singular name for the given resource. This is used as the helper methods
# names in controller ("authenticate_#{singular}!", "#{singular}_signed_in?", "current_#{singular}" # names in controller ("authenticate_#{singular}!", "#{singular}_signed_in?", "current_#{singular}"
# and "#{singular}_session"), as the scope name in routes and as the scope given to warden. # and "#{singular}_session"), as the scope name in routes and as the scope given to warden.
# #
@@ -105,7 +108,7 @@ module ActionDispatch::Routing
# end # end
# #
# class ManagerController < ApplicationController # class ManagerController < ApplicationController
# before_filter authenticate_manager! # before_action authenticate_manager!
# #
# def show # def show
# @manager = current_manager # @manager = current_manager
@@ -428,27 +431,29 @@ options to another `devise_for` call outside the scope. Here is an example:
end end
ERROR ERROR
end end
current_scope = @scope.dup
path, @scope[:path] = @scope[:path], nil if @scope.respond_to? :new
@scope = @scope.new path: nil
else
@scope[:path] = nil
end
path_prefix = Devise.omniauth_path_prefix || "/#{mapping.fullpath}/auth".squeeze("/") path_prefix = Devise.omniauth_path_prefix || "/#{mapping.fullpath}/auth".squeeze("/")
set_omniauth_path_prefix!(path_prefix) set_omniauth_path_prefix!(path_prefix)
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) mapping.to.omniauth_providers.each do |provider|
match "#{path_prefix}/#{provider}",
to: "#{controllers[:omniauth_callbacks]}#passthru",
as: "#{provider}_omniauth_authorize",
via: [:get, :post]
match "#{path_prefix}/:provider", match "#{path_prefix}/#{provider}/callback",
constraints: { provider: providers }, to: "#{controllers[:omniauth_callbacks]}##{provider}",
to: "#{controllers[:omniauth_callbacks]}#passthru", as: "#{provider}_omniauth_callback",
as: :omniauth_authorize, via: [:get, :post]
via: [:get, :post] end
match "#{path_prefix}/:action/callback",
constraints: { action: providers },
to: "#{controllers[:omniauth_callbacks]}#:action",
as: :omniauth_callback,
via: [:get, :post]
ensure ensure
@scope[:path] = path @scope = current_scope
end end
def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc: def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:
@@ -457,7 +462,11 @@ ERROR
exclusive = { as: new_as, path: new_path, module: nil } exclusive = { as: new_as, path: new_path, module: nil }
exclusive.merge!(options.slice(:constraints, :defaults, :options)) exclusive.merge!(options.slice(:constraints, :defaults, :options))
exclusive.each_pair { |key, value| @scope[key] = value } if @scope.respond_to? :new
@scope = @scope.new exclusive
else
exclusive.each_pair { |key, value| @scope[key] = value }
end
yield yield
ensure ensure
@scope = current_scope @scope = current_scope

View File

@@ -3,17 +3,8 @@ module Warden::Mixins::Common
@request ||= ActionDispatch::Request.new(env) @request ||= ActionDispatch::Request.new(env)
end end
# Deprecate: Remove this check once we move to Rails 4 only.
NULL_STORE =
defined?(ActionController::RequestForgeryProtection::ProtectionMethods::NullSession::NullSessionHash) ?
ActionController::RequestForgeryProtection::ProtectionMethods::NullSession::NullSessionHash : nil
def reset_session! def reset_session!
# Calling reset_session on NULL_STORE causes it fail. request.reset_session
# This is a bug that needs to be fixed in Rails.
unless NULL_STORE && request.session.is_a?(NULL_STORE)
request.reset_session
end
end end
def cookies def cookies

View File

@@ -6,15 +6,15 @@ module Devise
class DatabaseAuthenticatable < Authenticatable class DatabaseAuthenticatable < Authenticatable
def authenticate! def authenticate!
resource = password.present? && mapping.to.find_for_database_authentication(authentication_hash) resource = password.present? && mapping.to.find_for_database_authentication(authentication_hash)
encrypted = false hashed = false
if validate(resource){ encrypted = true; resource.valid_password?(password) } if validate(resource){ hashed = true; resource.valid_password?(password) }
remember_me(resource) remember_me(resource)
resource.after_database_authentication resource.after_database_authentication
success!(resource) success!(resource)
end end
mapping.to.new.password = password if !encrypted && Devise.paranoid mapping.to.new.password = password if !hashed && Devise.paranoid
fail(:not_found_in_database) unless resource fail(:not_found_in_database) unless resource
end end
end end

View File

@@ -25,8 +25,7 @@ module Devise
end end
if validate(resource) if validate(resource)
remember_me(resource) remember_me(resource) if extend_remember_me?(resource)
extend_remember_me_period(resource)
resource.after_remembered resource.after_remembered
success!(resource) success!(resource)
end end
@@ -43,10 +42,8 @@ module Devise
private private
def extend_remember_me_period(resource) def extend_remember_me?(resource)
if resource.respond_to?(:extend_remember_period=) resource.respond_to?(:extend_remember_period) && resource.extend_remember_period
resource.extend_remember_period = mapping.to.extend_remember_period
end
end end
def remember_me? def remember_me?

View File

@@ -0,0 +1,163 @@
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
[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 = 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
end

View 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

View File

@@ -1,132 +1,13 @@
module Devise 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 module TestHelpers
def self.included(base) def self.included(base)
base.class_eval do base.class_eval do
setup :setup_controller_for_warden, :warden if respond_to?(:setup) ActiveSupport::Deprecation.warn <<-DEPRECATION
[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
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
end
# We need to setup 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)
@controller.send :render, status: status, text: response.body,
content_type: headers["Content-Type"], location: headers["Location"]
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 = ret.second
@response.body = ret.third
end
ret
end
end end
end end

View File

@@ -1,11 +1,8 @@
# Deprecate: Copied verbatim from Rails source, remove once we move to Rails 4 only.
require 'thread_safe'
require 'openssl' require 'openssl'
require 'securerandom'
module Devise module Devise
class TokenGenerator class TokenGenerator
def initialize(key_generator, digest="SHA256") def initialize(key_generator, digest = "SHA256")
@key_generator = key_generator @key_generator = key_generator
@digest = digest @digest = digest
end end
@@ -30,41 +27,4 @@ module Devise
@key_generator.generate_key("Devise #{column}") @key_generator.generate_key("Devise #{column}")
end end
end end
# KeyGenerator is a simple wrapper around OpenSSL's implementation of PBKDF2
# It can be used to derive a number of keys for various purposes from a given secret.
# This lets Rails applications have a single secure secret, but avoid reusing that
# key in multiple incompatible contexts.
class KeyGenerator
def initialize(secret, options = {})
@secret = secret
# The default iterations are higher than required for our key derivation uses
# on the off chance someone uses this for password storage
@iterations = options[:iterations] || 2**16
end
# Returns a derived key suitable for use. The default key_size is chosen
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
# i.e. OpenSSL::Digest::SHA1#block_length
def generate_key(salt, key_size=64)
OpenSSL::PKCS5.pbkdf2_hmac_sha1(@secret, salt, @iterations, key_size)
end
end
# CachingKeyGenerator is a wrapper around KeyGenerator which allows users to avoid
# re-executing the key generation process when it's called using the same salt and
# key_size
class CachingKeyGenerator
def initialize(key_generator)
@key_generator = key_generator
@cache_keys = ThreadSafe::Cache.new
end
# Returns a derived key suitable for use. The default key_size is chosen
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
# i.e. OpenSSL::Digest::SHA1#block_length
def generate_key(salt, key_size=64)
@cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size)
end
end
end end

View File

@@ -1,3 +1,3 @@
module Devise module Devise
VERSION = "3.5.3".freeze VERSION = "4.1.0".freeze
end end

View File

@@ -11,9 +11,9 @@ module ActiveRecord
def copy_devise_migration def copy_devise_migration
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name)) if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}.rb" migration_template "migration_existing.rb", "db/migrate/add_devise_to_#{table_name}.rb", migration_version: migration_version
else else
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}.rb" migration_template "migration.rb", "db/migrate/devise_create_#{table_name}.rb", migration_version: migration_version
end end
end end
@@ -75,17 +75,23 @@ RUBY
end end
def inet? def inet?
rails4? && postgresql? postgresql?
end end
def rails4? def rails5?
Rails.version.start_with? '4' Rails.version.start_with? '5'
end end
def postgresql? def postgresql?
config = ActiveRecord::Base.configurations[Rails.env] config = ActiveRecord::Base.configurations[Rails.env]
config && config['adapter'] == 'postgresql' config && config['adapter'] == 'postgresql'
end end
def migration_version
if rails5?
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end
end
end end
end end
end end

View File

@@ -1,6 +1,6 @@
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
def change def change
create_table(:<%= table_name %>) do |t| create_table :<%= table_name %> do |t|
<%= migration_data -%> <%= migration_data -%>
<% attributes.each do |attribute| -%> <% attributes.each do |attribute| -%>

View File

@@ -1,6 +1,6 @@
class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration class AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
def self.up def self.up
change_table(:<%= table_name %>) do |t| change_table :<%= table_name %> do |t|
<%= migration_data -%> <%= migration_data -%>
<% attributes.each do |attribute| -%> <% attributes.each do |attribute| -%>

View File

@@ -3,6 +3,8 @@ require 'securerandom'
module Devise module Devise
module Generators module Generators
MissingORMError = Class.new(Thor::Error)
class InstallGenerator < Rails::Generators::Base class InstallGenerator < Rails::Generators::Base
source_root File.expand_path("../../templates", __FILE__) source_root File.expand_path("../../templates", __FILE__)
@@ -10,6 +12,19 @@ module Devise
class_option :orm class_option :orm
def copy_initializer def copy_initializer
unless options[:orm]
raise MissingORMError, <<-ERROR.strip_heredoc
An ORM must be set to install Devise in your application.
Be sure to have an ORM like Active Record or Mongoid loaded in your
app or configure your own at `config/application.rb`.
config.generators do |g|
g.orm :your_orm_gem
end
ERROR
end
template "devise.rb", "config/initializers/devise.rb" template "devise.rb", "config/initializers/devise.rb"
end end

View File

@@ -8,31 +8,14 @@ module Devise
devise :database_authenticatable, :registerable, devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
CONTENT
buffer += <<-CONTENT if needs_attr_accessible?
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
CONTENT CONTENT
buffer buffer
end end
def needs_attr_accessible?
rails_3? && !strong_parameters_enabled?
end
def rails_3?
Rails::VERSION::MAJOR == 3
end
def strong_parameters_enabled?
defined?(ActionController::StrongParameters)
end
private private
def model_exists? def model_exists?
File.exists?(File.join(destination_root, model_path)) File.exist?(File.join(destination_root, model_path))
end end
def migration_exists?(table_name) def migration_exists?(table_name)

View File

@@ -21,14 +21,7 @@ Some setup you must do manually if you haven't yet:
<p class="notice"><%= notice %></p> <p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p> <p class="alert"><%= alert %></p>
4. If you are deploying on Heroku with Rails 3.2 only, you may want to set: 4. You can copy Devise views (for customization) to your app by running:
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:
rails g devise:views rails g devise:views

View File

@@ -1,6 +1,6 @@
class <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsController class <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create] # before_action :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update] # before_action :configure_account_update_params, only: [:update]
# GET /resource/sign_up # GET /resource/sign_up
# def new # def new
@@ -40,12 +40,12 @@ class <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsControl
# If you have extra params to permit, append them to the sanitizer. # If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params # def configure_sign_up_params
# devise_parameter_sanitizer.for(:sign_up) << :attribute # devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
# end # end
# If you have extra params to permit, append them to the sanitizer. # If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params # def configure_account_update_params
# devise_parameter_sanitizer.for(:account_update) << :attribute # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end # end
# The path used after sign up. # The path used after sign up.

View File

@@ -1,5 +1,5 @@
class <%= @scope_prefix %>SessionsController < Devise::SessionsController class <%= @scope_prefix %>SessionsController < Devise::SessionsController
# before_filter :configure_sign_in_params, only: [:create] # before_action :configure_sign_in_params, only: [:create]
# GET /resource/sign_in # GET /resource/sign_in
# def new # def new
@@ -20,6 +20,6 @@ class <%= @scope_prefix %>SessionsController < Devise::SessionsController
# If you have extra params to permit, append them to the sanitizer. # If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params # def configure_sign_in_params
# devise_parameter_sanitizer.for(:sign_in) << :attribute # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
# end # end
end end

39
lib/generators/templates/devise.rb Normal file → Executable file
View File

@@ -4,13 +4,9 @@ Devise.setup do |config|
# The secret key used by Devise. Devise uses this key to generate # The secret key used by Devise. Devise uses this key to generate
# random tokens. Changing this key will render invalid all existing # random tokens. Changing this key will render invalid all existing
# confirmation, reset password and unlock tokens in the database. # confirmation, reset password and unlock tokens in the database.
# Devise will use the `secret_key_base` on Rails 4+ applications as its `secret_key` # Devise will use the `secret_key_base` as its `secret_key`
# by default. You can change it below and use your own secret key. # by default. You can change it below and use your own secret key.
<% if rails_4? -%>
# config.secret_key = '<%= SecureRandom.hex(64) %>' # config.secret_key = '<%= SecureRandom.hex(64) %>'
<% else -%>
config.secret_key = '<%= SecureRandom.hex(64) %>'
<% end -%>
# ==> Mailer Configuration # ==> Mailer Configuration
# Configure the e-mail address which will be shown in Devise::Mailer, # Configure the e-mail address which will be shown in Devise::Mailer,
@@ -21,6 +17,9 @@ Devise.setup do |config|
# Configure the class responsible to send e-mails. # Configure the class responsible to send e-mails.
# config.mailer = 'Devise::Mailer' # config.mailer = 'Devise::Mailer'
# Configure the parent class responsible to send e-mails.
# config.parent_mailer = 'ActionMailer::Base'
# ==> ORM configuration # ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default) and # Load and configure the ORM. Supports :active_record (default) and
# :mongoid (bson_ext recommended) by default. Other ORMs may be # :mongoid (bson_ext recommended) by default. Other ORMs may be
@@ -91,18 +90,24 @@ Devise.setup do |config|
# from the server. You can disable this option at your own risk. # from the server. You can disable this option at your own risk.
# config.clean_up_csrf_token_on_authentication = true # 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 # ==> Configuration for :database_authenticatable
# For bcrypt, this is the cost for hashing the password and defaults to 10. If # For bcrypt, this is the cost for hashing the password and defaults to 11. If
# using other encryptors, it sets how many times you want the password re-encrypted. # using other algorithms, it sets how many times you want the password to be hashed.
# #
# Limiting the stretches to just one in testing will increase the performance of # Limiting the stretches to just one in testing will increase the performance of
# your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
# a value less than 10 in other environments. Note that, for bcrypt (the default # a value less than 10 in other environments. Note that, for bcrypt (the default
# encryptor), the cost increases exponentially with the number of stretches (e.g. # algorithm), the cost increases exponentially with the number of stretches (e.g.
# a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation). # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).
config.stretches = Rails.env.test? ? 1 : 10 config.stretches = Rails.env.test? ? 1 : 11
# Setup a pepper to generate the encrypted password. # Set up a pepper to generate the hashed password.
# config.pepper = '<%= SecureRandom.hex(64) %>' # config.pepper = '<%= SecureRandom.hex(64) %>'
# Send a notification email when the user's password is changed # Send a notification email when the user's password is changed
@@ -149,12 +154,12 @@ Devise.setup do |config|
# ==> Configuration for :validatable # ==> Configuration for :validatable
# Range for password length. # Range for password length.
config.password_length = 8..72 config.password_length = 6..128
# Email regex used to validate email formats. It simply asserts that # Email regex used to validate email formats. It simply asserts that
# one (and only one) @ exists in the given string. This is mainly # one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity. # to give user feedback and not to assert the e-mail validity.
# config.email_regexp = /\A[^@]+@[^@]+\z/ config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
# ==> Configuration for :timeoutable # ==> Configuration for :timeoutable
# The time you want to timeout the user session without activity. After this # The time you want to timeout the user session without activity. After this
@@ -202,11 +207,11 @@ Devise.setup do |config|
# config.sign_in_after_reset_password = true # config.sign_in_after_reset_password = true
# ==> Configuration for :encryptable # ==> Configuration for :encryptable
# Allow you to use another encryption algorithm besides bcrypt (default). You can use # Allow you to use another hashing or encryption algorithm besides bcrypt (default).
# :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1, # You can use :sha1, :sha512 or algorithms from others authentication tools as
# :authlogic_sha512 (then you should set stretches above to 20 for default behavior) # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20
# and :restful_authentication_sha1 (then you should set stretches to 10, and copy # for default behavior) and :restful_authentication_sha1 (then you should set
# REST_AUTH_SITE_KEY to pepper). # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).
# #
# Require the `devise-encryptable` gem when using anything other than bcrypt # Require the `devise-encryptable` gem when using anything other than bcrypt
# config.encryptor = :sha512 # config.encryptor = :sha512

View File

@@ -1,49 +0,0 @@
#!/usr/bin/env bash
# Usage: cached-bundle install --deployment
#
# After running `bundle`, caches the `vendor/bundle` directory to S3.
# On the next run, restores the cached directory before running `bundle`.
# When `Gemfile.lock` changes, the cache gets rebuilt.
#
# Requirements:
# - Gemfile.lock
# - TRAVIS_REPO_SLUG
# - TRAVIS_RUBY_VERSION
# - AMAZON_S3_BUCKET
# - script/s3-put
# - bundle
# - curl
#
# Author: Mislav Marohnić
set -e
compute_md5() {
local output="$(openssl md5)"
echo "${output##* }"
}
download() {
curl --tcp-nodelay -qsfL "$1" -o "$2"
}
gemfile="${BUNDLE_GEMFILE:-Gemfile}"
bundle_fullpath="$(dirname $gemfile)/vendor/bundle"
bundle_path=${bundle_fullpath#$PWD/}
gemfile_hash="$(compute_md5 <"${gemfile}.lock")"
cache_name="${TRAVIS_RUBY_VERSION}-${gemfile_hash}.tgz"
fetch_url="http://${AMAZON_S3_BUCKET}.s3.amazonaws.com/${TRAVIS_REPO_SLUG}/${cache_name}"
if download "$fetch_url" "$cache_name"; then
echo "Reusing cached bundle ${cache_name}"
tar xzf "$cache_name"
fi
bundle "$@"
if [ ! -f "$cache_name" ] && [ -n "$AMAZON_SECRET_ACCESS_KEY" ]; then
echo "Caching \`${bundle_path}' to S3"
tar czf "$cache_name" "$bundle_path"
script/s3-put "$cache_name" "${AMAZON_S3_BUCKET}:${TRAVIS_REPO_SLUG}/${cache_name}"
fi

View File

@@ -1,71 +0,0 @@
#!/usr/bin/env bash
# Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>]
#
# Uploads a file to the Amazon S3 service.
# Outputs the URL for the newly uploaded file.
#
# Requirements:
# - AMAZON_ACCESS_KEY_ID
# - AMAZON_SECRET_ACCESS_KEY
# - openssl
# - curl
#
# Author: Mislav Marohnić
set -e
authorization() {
local signature="$(string_to_sign | hmac_sha1 | base64)"
echo "AWS ${AMAZON_ACCESS_KEY_ID?}:${signature}"
}
hmac_sha1() {
openssl dgst -binary -sha1 -hmac "${AMAZON_SECRET_ACCESS_KEY?}"
}
base64() {
openssl enc -base64
}
bin_md5() {
openssl dgst -binary -md5
}
string_to_sign() {
echo "$http_method"
echo "$content_md5"
echo "$content_type"
echo "$date"
echo "x-amz-acl:$acl"
printf "/$bucket/$remote_path"
}
date_string() {
LC_TIME=C date "+%a, %d %h %Y %T %z"
}
file="$1"
bucket="${2%%:*}"
remote_path="${2#*:}"
content_type="$3"
if [ -z "$remote_path" ] || [ "$remote_path" = "$bucket" ]; then
remote_path="${file##*/}"
fi
http_method=PUT
acl="public-read"
content_md5="$(bin_md5 < "$file" | base64)"
date="$(date_string)"
url="https://$bucket.s3.amazonaws.com/$remote_path"
curl -qsSf -T "$file" \
-H "Authorization: $(authorization)" \
-H "x-amz-acl: $acl" \
-H "Date: $date" \
-H "Content-MD5: $content_md5" \
-H "Content-Type: $content_type" \
"$url"
echo "$url"

View File

@@ -1,9 +1,9 @@
require 'test_helper' require 'test_helper'
class CustomRegistrationsControllerTest < ActionController::TestCase class CustomRegistrationsControllerTest < Devise::ControllerTestCase
tests Custom::RegistrationsController tests Custom::RegistrationsController
include Devise::TestHelpers include Devise::Test::ControllerHelpers
setup do setup do
request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
@@ -12,24 +12,24 @@ class CustomRegistrationsControllerTest < ActionController::TestCase
end end
test "yield resource to block on create success" do test "yield resource to block on create success" do
post :create, { user: { email: "user@example.org", password: "password", password_confirmation: "password" } } post :create, params: { user: { email: "user@example.org", password: "password", password_confirmation: "password" } }
assert @controller.create_block_called?, "create failed to yield resource to provided block" assert @controller.create_block_called?, "create failed to yield resource to provided block"
end end
test "yield resource to block on create failure" do test "yield resource to block on create failure" do
post :create, { user: { } } post :create, params: { user: { } }
assert @controller.create_block_called?, "create failed to yield resource to provided block" assert @controller.create_block_called?, "create failed to yield resource to provided block"
end end
test "yield resource to block on update success" do test "yield resource to block on update success" do
sign_in @user sign_in @user
put :update, { user: { current_password: @password } } put :update, params: { user: { current_password: @password } }
assert @controller.update_block_called?, "update failed to yield resource to provided block" assert @controller.update_block_called?, "update failed to yield resource to provided block"
end end
test "yield resource to block on update failure" do test "yield resource to block on update failure" do
sign_in @user sign_in @user
put :update, { user: { } } put :update, params: { user: { } }
assert @controller.update_block_called?, "update failed to yield resource to provided block" assert @controller.update_block_called?, "update failed to yield resource to provided block"
end end

View File

@@ -24,10 +24,10 @@ class CustomStrategy < Warden::Strategies::Base
end end
end end
class CustomStrategyTest < ActionController::TestCase class CustomStrategyTest < Devise::ControllerTestCase
tests CustomStrategyController tests CustomStrategyController
include Devise::TestHelpers include Devise::Test::ControllerHelpers
setup do setup do
Warden::Strategies.add(:custom_strategy, CustomStrategy) Warden::Strategies.add(:custom_strategy, CustomStrategy)
@@ -41,8 +41,9 @@ class CustomStrategyTest < ActionController::TestCase
ret = get :new ret = get :new
# check the returned rack array # check the returned rack array
assert ret.is_a?(Array) # assert ret.is_a?(Array)
assert_equal 400, ret.first # assert_equal 400, ret.first
assert ret.is_a?(ActionDispatch::TestResponse)
# check the saved response as well. This is purely so that the response is available to the testing framework # check the saved response as well. This is purely so that the response is available to the testing framework
# for verification. In production, the above array would be delivered directly to Rack. # for verification. In production, the above array would be delivered directly to Rack.
@@ -53,8 +54,9 @@ class CustomStrategyTest < ActionController::TestCase
ret = get :new ret = get :new
# check the returned rack array # check the returned rack array
assert ret.is_a?(Array) # assert ret.is_a?(Array)
assert_equal ret.third['X-FOO'], 'BAR' # assert_equal ret.third['X-FOO'], 'BAR'
assert ret.is_a?(ActionDispatch::TestResponse)
# check the saved response headers as well. # check the saved response headers as well.
assert_equal response.headers['X-FOO'], 'BAR' assert_equal response.headers['X-FOO'], 'BAR'

View File

@@ -4,14 +4,15 @@ class ApiController < ActionController::Metal
include Devise::Controllers::Helpers include Devise::Controllers::Helpers
end end
class HelperMethodsTest < ActionController::TestCase class HelperMethodsTest < Devise::ControllerTestCase
tests ApiController tests ApiController
test 'includes Devise::Controllers::Helpers' do test 'includes Devise::Controllers::Helpers' do
assert_includes @controller.class.ancestors, Devise::Controllers::Helpers assert_includes @controller.class.ancestors, Devise::Controllers::Helpers
end end
test 'does not respond_to helper_method' do test 'does not respond_to helper or helper_method' do
refute_respond_to @controller.class, :helper
refute_respond_to @controller.class, :helper_method refute_respond_to @controller.class, :helper_method
end end

View File

@@ -1,7 +1,7 @@
require 'test_helper' require 'test_helper'
require 'ostruct' require 'ostruct'
class ControllerAuthenticatableTest < ActionController::TestCase class ControllerAuthenticatableTest < Devise::ControllerTestCase
tests ApplicationController tests ApplicationController
def setup def setup
@@ -96,7 +96,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
test 'proxy admin_signed_in? to authenticatewith admin scope' do test 'proxy admin_signed_in? to authenticatewith admin scope' do
@mock_warden.expects(:authenticate).with(scope: :admin) @mock_warden.expects(:authenticate).with(scope: :admin)
assert_not @controller.admin_signed_in? refute @controller.admin_signed_in?
end end
test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
@@ -150,11 +150,11 @@ class ControllerAuthenticatableTest < ActionController::TestCase
@controller.sign_in(user, force: true) @controller.sign_in(user, force: true)
end end
test 'sign in accepts bypass as option' do test 'bypass the sign in' do
user = User.new user = User.new
@mock_warden.expects(:session_serializer).returns(serializer = mock()) @mock_warden.expects(:session_serializer).returns(serializer = mock())
serializer.expects(:store).with(user, :user) serializer.expects(:store).with(user, :user)
@controller.sign_in(user, bypass: true) @controller.bypass_sign_in(user)
end end
test 'sign out clears up any signed in user from all scopes' do test 'sign out clears up any signed in user from all scopes' do
@@ -311,6 +311,6 @@ class ControllerAuthenticatableTest < ActionController::TestCase
end end
test 'is not a devise controller' do test 'is not a devise controller' do
assert_not @controller.devise_controller? refute @controller.devise_controller?
end end
end end

View File

@@ -14,7 +14,7 @@ class AnotherInheritedController < SessionsInheritedController
end end
end end
class InheritedControllerTest < ActionController::TestCase class InheritedControllerTest < Devise::ControllerTestCase
tests SessionsInheritedController tests SessionsInheritedController
def setup def setup
@@ -32,7 +32,7 @@ class InheritedControllerTest < ActionController::TestCase
end end
end end
class AnotherInheritedControllerTest < ActionController::TestCase class AnotherInheritedControllerTest < Devise::ControllerTestCase
tests AnotherInheritedController tests AnotherInheritedController
def setup def setup

View File

@@ -3,7 +3,7 @@ require 'test_helper'
class MyController < DeviseController class MyController < DeviseController
end end
class HelpersTest < ActionController::TestCase class HelpersTest < Devise::ControllerTestCase
tests MyController tests MyController
def setup def setup
@@ -36,18 +36,16 @@ class HelpersTest < ActionController::TestCase
test 'get resource params from request params using resource name as key' do test 'get resource params from request params using resource name as key' do
user_params = {'email' => 'shirley@templar.com'} user_params = {'email' => 'shirley@templar.com'}
params = if Devise.rails4? # Stub controller name so strong parameters can filter properly.
# Stub controller name so strong parameters can filter properly. # DeviseController does not allow any parameters by default.
# DeviseController does not allow any parameters by default. @controller.stubs(:controller_name).returns(:sessions_controller)
@controller.stubs(:controller_name).returns(:sessions_controller)
params = ActionController::Parameters.new({'user' => user_params})
ActionController::Parameters.new({'user' => user_params})
else
HashWithIndifferentAccess.new({'user' => user_params})
end
@controller.stubs(:params).returns(params) @controller.stubs(:params).returns(params)
assert_equal user_params, @controller.send(:resource_params) res_params = @controller.send(:resource_params).permit!.to_h
assert_equal user_params, res_params
end end
test 'resources methods are not controller actions' do test 'resources methods are not controller actions' do
@@ -121,7 +119,7 @@ class HelpersTest < ActionController::TestCase
MyController.send(:public, :navigational_formats) MyController.send(:public, :navigational_formats)
swap Devise, navigational_formats: ['*/*', :html] do swap Devise, navigational_formats: ['*/*', :html] do
assert_not @controller.navigational_formats.include?("*/*") refute @controller.navigational_formats.include?("*/*")
end end
MyController.send(:protected, :navigational_formats) MyController.send(:protected, :navigational_formats)

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class LoadHooksControllerTest < ActionController::TestCase class LoadHooksControllerTest < Devise::ControllerTestCase
setup do setup do
ActiveSupport.on_load(:devise_controller) do ActiveSupport.on_load(:devise_controller) do
define_method :defined_by_load_hook do define_method :defined_by_load_hook do

View File

@@ -1,8 +1,8 @@
require 'test_helper' require 'test_helper'
class PasswordsControllerTest < ActionController::TestCase class PasswordsControllerTest < Devise::ControllerTestCase
tests Devise::PasswordsController tests Devise::PasswordsController
include Devise::TestHelpers include Devise::Test::ControllerHelpers
setup do setup do
request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
@@ -11,8 +11,9 @@ class PasswordsControllerTest < ActionController::TestCase
end end
def put_update_with_params def put_update_with_params
put :update, "user" => { put :update, params: { "user" => {
"reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567" "reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567"
}
} }
end end

View File

@@ -1,20 +1,21 @@
require 'test_helper' require 'test_helper'
class SessionsControllerTest < ActionController::TestCase class SessionsControllerTest < Devise::ControllerTestCase
tests Devise::SessionsController tests Devise::SessionsController
include Devise::TestHelpers include Devise::Test::ControllerHelpers
test "#create doesn't raise unpermitted params when sign in fails" do test "#create doesn't raise unpermitted params when sign in fails" do
begin begin
subscriber = ActiveSupport::Notifications.subscribe /unpermitted_parameters/ do |name, start, finish, id, payload| subscriber = ActiveSupport::Notifications.subscribe %r{unpermitted_parameters} do |name, start, finish, id, payload|
flunk "Unpermitted params: #{payload}" flunk "Unpermitted params: #{payload}"
end end
request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
request.session["user_return_to"] = 'foo.bar' request.session["user_return_to"] = 'foo.bar'
create_user create_user
post :create, user: { post :create, params: { user: {
email: "wrong@email.com", email: "wrong@email.com",
password: "wrongpassword" password: "wrongpassword"
}
} }
assert_equal 200, @response.status assert_equal 200, @response.status
ensure ensure
@@ -37,11 +38,11 @@ class SessionsControllerTest < ActionController::TestCase
user = create_user user = create_user
user.confirm user.confirm
post :create, user: { post :create, params: { user: {
email: user.email, email: user.email,
password: user.password password: user.password
}
} }
assert_nil request.session["user_return_to"] assert_nil request.session["user_return_to"]
end end
@@ -51,9 +52,10 @@ class SessionsControllerTest < ActionController::TestCase
user = create_user user = create_user
user.confirm user.confirm
post :create, format: 'json', user: { post :create, params: { format: 'json', user: {
email: user.email, email: user.email,
password: user.password password: user.password
}
} }
assert_equal 'foo.bar', request.session["user_return_to"] assert_equal 'foo.bar', request.session["user_return_to"]
@@ -61,9 +63,10 @@ class SessionsControllerTest < ActionController::TestCase
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
post :create, user: { post :create, params: { user: {
email: "nosuchuser@example.com", email: "nosuchuser@example.com",
password: "wevdude" password: "wevdude"
}
} }
assert_equal 200, @response.status assert_equal 200, @response.status
assert_template "devise/sessions/new" assert_template "devise/sessions/new"
@@ -73,11 +76,11 @@ class SessionsControllerTest < ActionController::TestCase
request.env["devise.mapping"] = Devise.mappings[:user] request.env["devise.mapping"] = Devise.mappings[:user]
user = create_user user = create_user
user.confirm user.confirm
post :create, format: 'json', user: { post :create, params: { format: 'json', user: {
email: user.email, email: user.email,
password: user.password password: user.password
}
} }
delete :destroy, format: 'json' delete :destroy, format: 'json'
assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}" assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
assert_equal 204, @response.status assert_equal 204, @response.status

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class RoutesTest < ActionController::TestCase class RoutesTest < Devise::ControllerTestCase
tests ApplicationController tests ApplicationController
def assert_path_and_url(name, prepend_path=nil) def assert_path_and_url(name, prepend_path=nil)

16
test/devise_test.rb Normal file → Executable file
View File

@@ -69,8 +69,8 @@ class DeviseTest < ActiveSupport::TestCase
test 'add new module using the helper method' do test 'add new module using the helper method' do
assert_nothing_raised(Exception) { Devise.add_module(:coconut) } assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
assert_not Devise::STRATEGIES.include?(:coconut) refute Devise::STRATEGIES.include?(:coconut)
assert_not defined?(Devise::Models::Coconut) refute defined?(Devise::Models::Coconut)
Devise::ALL.delete(:coconut) Devise::ALL.delete(:coconut)
assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) } assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) }
@@ -86,16 +86,16 @@ class DeviseTest < ActiveSupport::TestCase
test 'should complain when comparing empty or different sized passes' do test 'should complain when comparing empty or different sized passes' do
[nil, ""].each do |empty| [nil, ""].each do |empty|
assert_not Devise.secure_compare(empty, "something") refute Devise.secure_compare(empty, "something")
assert_not Devise.secure_compare("something", empty) refute Devise.secure_compare("something", empty)
assert_not Devise.secure_compare(empty, empty) refute Devise.secure_compare(empty, empty)
end end
assert_not Devise.secure_compare("size_1", "size_four") refute Devise.secure_compare("size_1", "size_four")
end end
test 'Devise.email_regexp should match valid email addresses' do test 'Devise.email_regexp should match valid email addresses' do
valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua"] valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua", "test@tt", "test@valid---domain.com"]
non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com", "test_user@example.com."] non_valid_emails = ["rex", "test user@example.com", "test_user@example server.com"]
valid_emails.each do |email| valid_emails.each do |email|
assert_match Devise.email_regexp, email assert_match Devise.email_regexp, email

View File

@@ -53,11 +53,16 @@ class FailureTest < ActiveSupport::TestCase
'REQUEST_METHOD' => 'GET', 'REQUEST_METHOD' => 'GET',
'warden.options' => { scope: :user }, 'warden.options' => { scope: :user },
'rack.session' => {}, 'rack.session' => {},
'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime::HTML), 'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime[:html]),
'rack.input' => "", 'rack.input' => "",
'warden' => OpenStruct.new(message: nil) 'warden' => OpenStruct.new(message: nil)
}.merge!(env_params) }.merge!(env_params)
# Passing nil for action_dispatch.request.formats prevents the default from being used in Rails 5, need to remove it
if env.has_key?('action_dispatch.request.formats') && env['action_dispatch.request.formats'].nil?
env.delete 'action_dispatch.request.formats' unless env['action_dispatch.request.formats']
end
@response = (env.delete(:app) || Devise::FailureApp).call(env).to_a @response = (env.delete(:app) || Devise::FailureApp).call(env).to_a
@request = ActionDispatch::Request.new(env) @request = ActionDispatch::Request.new(env)
end end
@@ -128,14 +133,14 @@ class FailureTest < ActiveSupport::TestCase
test 'uses the proxy failure message as symbol' do test 'uses the proxy failure message as symbol' do
call_failure('warden' => OpenStruct.new(message: :invalid)) call_failure('warden' => OpenStruct.new(message: :invalid))
assert_equal 'Invalid email or password.', @request.flash[:alert] assert_equal 'Invalid Email or password.', @request.flash[:alert]
assert_equal 'http://test.host/users/sign_in', @response.second["Location"] assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
end end
test 'supports authentication_keys as a Hash for the flash message' do test 'supports authentication_keys as a Hash for the flash message' do
swap Devise, authentication_keys: { email: true, login: true } do swap Devise, authentication_keys: { email: true, login: true } do
call_failure('warden' => OpenStruct.new(message: :invalid)) call_failure('warden' => OpenStruct.new(message: :invalid))
assert_equal 'Invalid email, login or password.', @request.flash[:alert] assert_equal 'Invalid Email, Login or password.', @request.flash[:alert]
end end
end end
@@ -155,7 +160,7 @@ class FailureTest < ActiveSupport::TestCase
assert_equal 'text/html; charset=utf-8', @response.second['Content-Type'] assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
end end
test 'setup a default message' do test 'set up a default message' do
call_failure call_failure
assert_match(/You are being/, @response.last.body) assert_match(/You are being/, @response.last.body)
assert_match(/redirected/, @response.last.body) assert_match(/redirected/, @response.last.body)
@@ -164,14 +169,14 @@ class FailureTest < ActiveSupport::TestCase
test 'works for any navigational format' do test 'works for any navigational format' do
swap Devise, navigational_formats: [:xml] do swap Devise, navigational_formats: [:xml] do
call_failure('formats' => Mime::XML) call_failure('formats' => Mime[:xml])
assert_equal 302, @response.first assert_equal 302, @response.first
end end
end end
test 'redirects the correct format if it is a non-html format request' do test 'redirects the correct format if it is a non-html format request' do
swap Devise, navigational_formats: [:js] do swap Devise, navigational_formats: [:js] do
call_failure('formats' => Mime::JS) call_failure('formats' => Mime[:js])
assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"] assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
end end
end end
@@ -179,18 +184,18 @@ class FailureTest < ActiveSupport::TestCase
context 'For HTTP request' do context 'For HTTP request' do
test 'return 401 status' do test 'return 401 status' do
call_failure('formats' => Mime::XML) call_failure('formats' => Mime[:xml])
assert_equal 401, @response.first assert_equal 401, @response.first
end end
test 'return appropriate body for xml' do test 'return appropriate body for xml' do
call_failure('formats' => Mime::XML) call_failure('formats' => Mime[:xml])
result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n) result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n)
assert_equal result, @response.last.body assert_equal result, @response.last.body
end end
test 'return appropriate body for json' do test 'return appropriate body for json' do
call_failure('formats' => Mime::JSON) call_failure('formats' => Mime[:json])
result = %({"error":"You need to sign in or sign up before continuing."}) result = %({"error":"You need to sign in or sign up before continuing."})
assert_equal result, @response.last.body assert_equal result, @response.last.body
end end
@@ -201,34 +206,34 @@ class FailureTest < ActiveSupport::TestCase
end end
test 'return WWW-authenticate headers if model allows' do test 'return WWW-authenticate headers if model allows' do
call_failure('formats' => Mime::XML) call_failure('formats' => Mime[:xml])
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"] assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
end end
test 'does not return WWW-authenticate headers if model does not allow' do test 'does not return WWW-authenticate headers if model does not allow' do
swap Devise, http_authenticatable: false do swap Devise, http_authenticatable: false do
call_failure('formats' => Mime::XML) call_failure('formats' => Mime[:xml])
assert_nil @response.second["WWW-Authenticate"] assert_nil @response.second["WWW-Authenticate"]
end end
end end
test 'works for any non navigational format' do test 'works for any non navigational format' do
swap Devise, navigational_formats: [] do swap Devise, navigational_formats: [] do
call_failure('formats' => Mime::HTML) call_failure('formats' => Mime[:html])
assert_equal 401, @response.first assert_equal 401, @response.first
end end
end end
test 'uses the failure message as response body' do test 'uses the failure message as response body' do
call_failure('formats' => Mime::XML, 'warden' => OpenStruct.new(message: :invalid)) call_failure('formats' => Mime[:xml], 'warden' => OpenStruct.new(message: :invalid))
assert_match '<error>Invalid email or password.</error>', @response.third.body assert_match '<error>Invalid Email or password.</error>', @response.third.body
end end
context 'on ajax call' do context 'on ajax call' do
context 'when http_authenticatable_on_xhr is false' do context 'when http_authenticatable_on_xhr is false' do
test 'dont return 401 with navigational formats' do test 'dont return 401 with navigational formats' do
swap Devise, http_authenticatable_on_xhr: false do swap Devise, http_authenticatable_on_xhr: false do
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
assert_equal 302, @response.first assert_equal 302, @response.first
assert_equal 'http://test.host/users/sign_in', @response.second["Location"] assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
end end
@@ -236,7 +241,7 @@ class FailureTest < ActiveSupport::TestCase
test 'dont return 401 with non navigational formats' do test 'dont return 401 with non navigational formats' do
swap Devise, http_authenticatable_on_xhr: false do swap Devise, http_authenticatable_on_xhr: false do
call_failure('formats' => Mime::JSON, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') call_failure('formats' => Mime[:json], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
assert_equal 302, @response.first assert_equal 302, @response.first
assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"] assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
end end
@@ -246,14 +251,14 @@ class FailureTest < ActiveSupport::TestCase
context 'when http_authenticatable_on_xhr is true' do context 'when http_authenticatable_on_xhr is true' do
test 'return 401' do test 'return 401' do
swap Devise, http_authenticatable_on_xhr: true do swap Devise, http_authenticatable_on_xhr: true do
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
assert_equal 401, @response.first assert_equal 401, @response.first
end end
end end
test 'skip WWW-Authenticate header' do test 'skip WWW-Authenticate header' do
swap Devise, http_authenticatable_on_xhr: true do swap Devise, http_authenticatable_on_xhr: true do
call_failure('formats' => Mime::HTML, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
assert_nil @response.second['WWW-Authenticate'] assert_nil @response.second['WWW-Authenticate']
end end
end end
@@ -270,7 +275,7 @@ class FailureTest < ActiveSupport::TestCase
} }
call_failure(env) call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>') assert @response.third.body.include?('<h2>Log in</h2>')
assert @response.third.body.include?('Invalid email or password.') assert @response.third.body.include?('Invalid Email or password.')
end end
test 'calls the original controller if not confirmed email' do test 'calls the original controller if not confirmed email' do
@@ -305,7 +310,7 @@ class FailureTest < ActiveSupport::TestCase
} }
call_failure(env) call_failure(env)
assert @response.third.body.include?('<h2>Log in</h2>') assert @response.third.body.include?('<h2>Log in</h2>')
assert @response.third.body.include?('Invalid email or password.') assert @response.third.body.include?('Invalid Email or password.')
assert_equal @request.env["SCRIPT_NAME"], '/sample' assert_equal @request.env["SCRIPT_NAME"], '/sample'
assert_equal @request.env["PATH_INFO"], '/users/sign_in' assert_equal @request.env["PATH_INFO"], '/users/sign_in'
end end

View File

@@ -69,41 +69,15 @@ if DEVISE_ORM == :active_record
setup :prepare_destination setup :prepare_destination
test "all files are properly created in rails 4.0" do test "all files are properly created in rails 4.0" do
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(false)
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
run_generator ["monster"] run_generator ["monster"]
assert_file "app/models/rails_engine/monster.rb", /devise/ assert_file "app/models/rails_engine/monster.rb", /devise/
assert_file "app/models/rails_engine/monster.rb" do |content| assert_file "app/models/rails_engine/monster.rb" do |content|
assert_no_match /attr_accessible :email/, content assert_no_match %r{attr_accessible :email}, content
end end
end end
end end
test "all files are properly created in rails 3.2 when strong_parameters gem is not installed" do
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(true)
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(false)
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
run_generator ["monster"]
assert_file "app/models/rails_engine/monster.rb", /devise/
assert_file "app/models/rails_engine/monster.rb" do |content|
assert_match /attr_accessible :email/, content
end
end
end
test "all files are properly created in rails 3.2 when strong_parameters gem is installed" do
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:rails_3?).returns(true)
ActiveRecord::Generators::DeviseGenerator.any_instance.stubs(:strong_parameters_enabled?).returns(true)
simulate_inside_engine(RailsEngine::Engine, RailsEngine) do
run_generator ["monster"]
assert_file "app/models/rails_engine/monster.rb", /devise/
assert_file "app/models/rails_engine/monster.rb" do |content|
assert_no_match /attr_accessible :email/, content
end
end
end
end end
end end

View File

@@ -5,9 +5,20 @@ class InstallGeneratorTest < Rails::Generators::TestCase
destination File.expand_path("../../tmp", __FILE__) destination File.expand_path("../../tmp", __FILE__)
setup :prepare_destination setup :prepare_destination
test "Assert all files are properly created" do test "assert all files are properly created" do
run_generator run_generator(["--orm=active_record"])
assert_file "config/initializers/devise.rb" assert_file "config/initializers/devise.rb", /devise\/orm\/active_record/
assert_file "config/locales/devise.en.yml" assert_file "config/locales/devise.en.yml"
end end
test "fails if no ORM is specified" do
stderr = capture(:stderr) do
run_generator
end
assert_match %r{An ORM must be set to install Devise}, stderr
assert_no_file "config/initializers/devise.rb"
assert_no_file "config/locales/devise.en.yml"
end
end end

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class DeviseHelperTest < ActionDispatch::IntegrationTest class DeviseHelperTest < Devise::IntegrationTest
setup do setup do
model_labels = { models: { user: "the user" } } model_labels = { models: { user: "the user" } }
translations = { translations = {

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class AuthenticationSanityTest < ActionDispatch::IntegrationTest class AuthenticationSanityTest < Devise::IntegrationTest
test 'home should be accessible without sign in' do test 'home should be accessible without sign in' do
visit '/' visit '/'
assert_response :success assert_response :success
@@ -10,13 +10,13 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
test 'sign in as user should not authenticate admin scope' do test 'sign in as user should not authenticate admin scope' do
sign_in_as_user sign_in_as_user
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
test 'sign in as admin should not authenticate user scope' do test 'sign in as admin should not authenticate user scope' do
sign_in_as_admin sign_in_as_admin
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'sign in as both user and admin at same time' do test 'sign in as both user and admin at same time' do
@@ -30,8 +30,8 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
swap Devise, sign_out_all_scopes: false do swap Devise, sign_out_all_scopes: false do
sign_in_as_user sign_in_as_user
sign_in_as_admin sign_in_as_admin
get destroy_user_session_path delete destroy_user_session_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
end end
end end
@@ -41,8 +41,8 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
sign_in_as_user sign_in_as_user
sign_in_as_admin sign_in_as_admin
get destroy_admin_session_path delete destroy_admin_session_path
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
end end
end end
@@ -52,9 +52,9 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
sign_in_as_user sign_in_as_user
sign_in_as_admin sign_in_as_admin
get destroy_user_session_path delete destroy_user_session_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
end end
@@ -63,22 +63,22 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
sign_in_as_user sign_in_as_user
sign_in_as_admin sign_in_as_admin
get destroy_admin_session_path delete destroy_admin_session_path
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
test 'not signed in as admin should not be able to access admins actions' do test 'not signed in as admin should not be able to access admins actions' do
get admins_path get admins_path
assert_redirected_to new_admin_session_path assert_redirected_to new_admin_session_path
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
test 'signed in as user should not be able to access admins actions' do test 'signed in as user should not be able to access admins actions' do
sign_in_as_user sign_in_as_user
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
get admins_path get admins_path
assert_redirected_to new_admin_session_path assert_redirected_to new_admin_session_path
@@ -87,7 +87,7 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
test 'signed in as admin should be able to access admin actions' do test 'signed in as admin should be able to access admin actions' do
sign_in_as_admin sign_in_as_admin
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
get admins_path get admins_path
@@ -109,17 +109,17 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
sign_in_as_admin sign_in_as_admin
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
get destroy_admin_session_path delete destroy_admin_session_path
assert_response :redirect assert_response :redirect
assert_redirected_to root_path assert_redirected_to root_path
get root_path get root_path
assert_contain 'Signed out successfully' assert_contain 'Signed out successfully'
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
test 'unauthenticated admin set message on sign out' do test 'unauthenticated admin set message on sign out' do
get destroy_admin_session_path delete destroy_admin_session_path
assert_response :redirect assert_response :redirect
assert_redirected_to root_path assert_redirected_to root_path
@@ -134,17 +134,17 @@ class AuthenticationSanityTest < ActionDispatch::IntegrationTest
end end
end end
class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest class AuthenticationRoutesRestrictions < Devise::IntegrationTest
test 'not signed in should not be able to access private route (authenticate denied)' do test 'not signed in should not be able to access private route (authenticate denied)' do
get private_path get private_path
assert_redirected_to new_admin_session_path assert_redirected_to new_admin_session_path
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
test 'signed in as user should not be able to access private route restricted to admins (authenticate denied)' do test 'signed in as user should not be able to access private route restricted to admins (authenticate denied)' do
sign_in_as_user sign_in_as_user
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
get private_path get private_path
assert_redirected_to new_admin_session_path assert_redirected_to new_admin_session_path
end end
@@ -152,7 +152,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
test 'signed in as admin should be able to access private route restricted to admins (authenticate accepted)' do test 'signed in as admin should be able to access private route restricted to admins (authenticate accepted)' do
sign_in_as_admin sign_in_as_admin
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
get private_path get private_path
@@ -164,7 +164,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do
sign_in_as_admin(active: false) sign_in_as_admin(active: false)
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert_raises ActionController::RoutingError do assert_raises ActionController::RoutingError do
get "/private/active" get "/private/active"
@@ -174,7 +174,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do
sign_in_as_admin(active: true) sign_in_as_admin(active: true)
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
get private_active_path get private_active_path
@@ -186,7 +186,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
test 'signed in as admin should get admin dashboard (authenticated accepted)' do test 'signed in as admin should get admin dashboard (authenticated accepted)' do
sign_in_as_admin sign_in_as_admin
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
get dashboard_path get dashboard_path
@@ -198,7 +198,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
test 'signed in as user should get user dashboard (authenticated accepted)' do test 'signed in as user should get user dashboard (authenticated accepted)' do
sign_in_as_user sign_in_as_user
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
get dashboard_path get dashboard_path
@@ -216,7 +216,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do
sign_in_as_admin(active: false) sign_in_as_admin(active: false)
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert_raises ActionController::RoutingError do assert_raises ActionController::RoutingError do
get "/dashboard/active" get "/dashboard/active"
@@ -226,7 +226,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do
sign_in_as_admin(active: true) sign_in_as_admin(active: true)
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
get dashboard_active_path get dashboard_active_path
@@ -238,7 +238,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
test 'signed in user should not see unauthenticated page (unauthenticated denied)' do test 'signed in user should not see unauthenticated page (unauthenticated denied)' do
sign_in_as_user sign_in_as_user
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
assert_raises ActionController::RoutingError do assert_raises ActionController::RoutingError do
get join_path get join_path
@@ -254,7 +254,7 @@ class AuthenticationRoutesRestrictions < ActionDispatch::IntegrationTest
end end
end end
class AuthenticationRedirectTest < ActionDispatch::IntegrationTest class AuthenticationRedirectTest < Devise::IntegrationTest
test 'redirect from warden shows sign in or sign up message' do test 'redirect from warden shows sign in or sign up message' do
get admins_path get admins_path
@@ -300,7 +300,7 @@ class AuthenticationRedirectTest < ActionDispatch::IntegrationTest
end end
test 'xml http requests does not store urls for redirect' do test 'xml http requests does not store urls for redirect' do
get users_path, {}, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest' get users_path, headers: { 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest' }
assert_equal 401, response.status assert_equal 401, response.status
assert_nil session[:"user_return_to"] assert_nil session[:"user_return_to"]
end end
@@ -317,7 +317,7 @@ class AuthenticationRedirectTest < ActionDispatch::IntegrationTest
end end
end end
class AuthenticationSessionTest < ActionDispatch::IntegrationTest class AuthenticationSessionTest < Devise::IntegrationTest
test 'destroyed account is signed out' do test 'destroyed account is signed out' do
sign_in_as_user sign_in_as_user
get '/users' get '/users'
@@ -347,37 +347,6 @@ class AuthenticationSessionTest < ActionDispatch::IntegrationTest
assert_equal "Cart", @controller.user_session[:cart] assert_equal "Cart", @controller.user_session[:cart]
end end
test 'does not explode when class name is still stored in session' do
# In order to test that old sessions do not break with the new scoped
# deserialization, we need to serialize the session the old way. This is
# done by removing the newly used scoped serialization method
# (#user_serialize) and bringing back the old uncsoped #serialize method
# that includes the record's class name in the serialization.
begin
Warden::SessionSerializer.class_eval do
alias_method :original_serialize, :serialize
alias_method :original_user_serialize, :user_serialize
remove_method :user_serialize
def serialize(record)
klass = record.class
array = klass.serialize_into_session(record)
array.unshift(klass.name)
end
end
sign_in_as_user
assert warden.authenticated?(:user)
ensure
Warden::SessionSerializer.class_eval do
alias_method :serialize, :original_serialize
remove_method :original_serialize
alias_method :user_serialize, :original_user_serialize
remove_method :original_user_serialize
end
end
end
test 'session id is changed on sign in' do test 'session id is changed on sign in' do
get '/users' get '/users'
session_id = request.session["session_id"] session_id = request.session["session_id"]
@@ -390,13 +359,13 @@ class AuthenticationSessionTest < ActionDispatch::IntegrationTest
end end
end end
class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest class AuthenticationWithScopedViewsTest < Devise::IntegrationTest
test 'renders the scoped view if turned on and view is available' do test 'renders the scoped view if turned on and view is available' do
swap Devise, scoped_views: true do swap Devise, scoped_views: true do
assert_raise Webrat::NotFoundError do assert_raise Webrat::NotFoundError do
sign_in_as_user sign_in_as_user
end end
assert_match /Special user view/, response.body assert_match %r{Special user view}, response.body
end end
end end
@@ -407,7 +376,7 @@ class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
sign_in_as_user sign_in_as_user
end end
assert_match /Special user view/, response.body assert_match %r{Special user view}, response.body
assert !Devise::PasswordsController.scoped_views? assert !Devise::PasswordsController.scoped_views?
ensure ensure
Devise::SessionsController.send :remove_instance_variable, :@scoped_views Devise::SessionsController.send :remove_instance_variable, :@scoped_views
@@ -431,17 +400,17 @@ class AuthenticationWithScopedViewsTest < ActionDispatch::IntegrationTest
end end
end end
class AuthenticationOthersTest < ActionDispatch::IntegrationTest class AuthenticationOthersTest < Devise::IntegrationTest
test 'handles unverified requests gets rid of caches' do test 'handles unverified requests gets rid of caches' do
swap ApplicationController, allow_forgery_protection: true do swap ApplicationController, allow_forgery_protection: true do
post exhibit_user_url(1) post exhibit_user_url(1)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
sign_in_as_user sign_in_as_user
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
post exhibit_user_url(1) post exhibit_user_url(1)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert_equal "User is not authenticated", response.body assert_equal "User is not authenticated", response.body
end end
end end
@@ -472,7 +441,7 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
test 'sign in with script name' do test 'sign in with script name' do
assert_nothing_raised do assert_nothing_raised do
get new_user_session_path, {}, "SCRIPT_NAME" => "/omg" get new_user_session_path, headers: { "SCRIPT_NAME" => "/omg" }
fill_in "email", with: "user@test.com" fill_in "email", with: "user@test.com"
end end
end end
@@ -480,7 +449,7 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
test 'sign in stub in xml format' do test 'sign in stub in xml format' do
get new_user_session_path(format: 'xml') get new_user_session_path(format: 'xml')
assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body assert_match '<?xml version="1.0" encoding="UTF-8"?>', response.body
assert_match /<user>.*<\/user>/m, response.body assert_match %r{<user>.*</user>}m, response.body
assert_match '<email></email>', response.body assert_match '<email></email>', response.body
assert_match '<password nil="true"', response.body assert_match '<password nil="true"', response.body
end end
@@ -504,12 +473,12 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
test 'uses the mapping from router' do test 'uses the mapping from router' do
sign_in_as_user visit: "/as/sign_in" sign_in_as_user visit: "/as/sign_in"
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
test 'sign in with xml format returns xml response' do test 'sign in with xml format returns xml response' do
create_user create_user
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'} post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} }
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end end
@@ -519,49 +488,49 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
create_user create_user
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'} post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} }
assert_response :success assert_response :success
get new_user_session_path(format: 'xml') get new_user_session_path(format: 'xml')
assert_response :success assert_response :success
post user_session_path(format: 'xml'), user: {email: "user@test.com", password: '12345678'} post user_session_path(format: 'xml'), params: { user: {email: "user@test.com", password: '12345678'} }
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
end end
test 'sign out with html redirects' do test 'sign out with html redirects' do
sign_in_as_user sign_in_as_user
get destroy_user_session_path delete destroy_user_session_path
assert_response :redirect assert_response :redirect
assert_current_url '/' assert_current_url '/'
sign_in_as_user sign_in_as_user
get destroy_user_session_path(format: 'html') delete destroy_user_session_path(format: 'html')
assert_response :redirect assert_response :redirect
assert_current_url '/' assert_current_url '/'
end end
test 'sign out with xml format returns no content' do test 'sign out with xml format returns no content' do
sign_in_as_user sign_in_as_user
get destroy_user_session_path(format: 'xml') delete destroy_user_session_path(format: 'xml')
assert_response :no_content assert_response :no_content
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'sign out with json format returns no content' do test 'sign out with json format returns no content' do
sign_in_as_user sign_in_as_user
get destroy_user_session_path(format: 'json') delete destroy_user_session_path(format: 'json')
assert_response :no_content assert_response :no_content
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'sign out with non-navigational format via XHR does not redirect' do test 'sign out with non-navigational format via XHR does not redirect' do
swap Devise, navigational_formats: ['*/*', :html] do swap Devise, navigational_formats: ['*/*', :html] do
sign_in_as_user sign_in_as_admin
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "application/json,text/javascript,*/*" } # NOTE: Bug is triggered by combination of XHR and */*. 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_response :no_content
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -569,19 +538,19 @@ class AuthenticationOthersTest < ActionDispatch::IntegrationTest
test 'sign out with navigational format via XHR does redirect' do test 'sign out with navigational format via XHR does redirect' do
swap Devise, navigational_formats: ['*/*', :html] do swap Devise, navigational_formats: ['*/*', :html] do
sign_in_as_user sign_in_as_user
xml_http_request :get, destroy_user_session_path, {}, { "HTTP_ACCEPT" => "text/html,*/*" } delete destroy_user_session_path, xhr: true, headers: { "HTTP_ACCEPT" => "text/html,*/*" }
assert_response :redirect assert_response :redirect
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
end end
class AuthenticationKeysTest < ActionDispatch::IntegrationTest class AuthenticationKeysTest < Devise::IntegrationTest
test 'missing authentication keys cause authentication to abort' do test 'missing authentication keys cause authentication to abort' do
swap Devise, authentication_keys: [:subdomain] do swap Devise, authentication_keys: [:subdomain] do
sign_in_as_user sign_in_as_user
assert_contain "Invalid subdomain or password." assert_contain "Invalid Subdomain or password."
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -593,7 +562,7 @@ class AuthenticationKeysTest < ActionDispatch::IntegrationTest
end end
end end
class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest class AuthenticationRequestKeysTest < Devise::IntegrationTest
test 'request keys are used on authentication' do test 'request keys are used on authentication' do
host! 'foo.bar.baz' host! 'foo.bar.baz'
@@ -610,7 +579,7 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
sign_in_as_user sign_in_as_user
end end
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -619,8 +588,8 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
swap Devise, request_keys: [:subdomain] do swap Devise, request_keys: [:subdomain] do
sign_in_as_user sign_in_as_user
assert_contain "Invalid email or password." assert_contain "Invalid Email or password."
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -634,7 +603,7 @@ class AuthenticationRequestKeysTest < ActionDispatch::IntegrationTest
end end
end end
class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest class AuthenticationSignOutViaTest < Devise::IntegrationTest
def sign_in!(scope) def sign_in!(scope)
sign_in_as_admin(visit: send("new_#{scope}_session_path")) sign_in_as_admin(visit: send("new_#{scope}_session_path"))
assert warden.authenticated?(scope) assert warden.authenticated?(scope)
@@ -643,7 +612,7 @@ class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
test 'allow sign out via delete when sign_out_via provides only delete' do test 'allow sign out via delete when sign_out_via provides only delete' do
sign_in!(:sign_out_via_delete) sign_in!(:sign_out_via_delete)
delete destroy_sign_out_via_delete_session_path delete destroy_sign_out_via_delete_session_path
assert_not warden.authenticated?(:sign_out_via_delete) refute warden.authenticated?(:sign_out_via_delete)
end end
test 'do not allow sign out via get when sign_out_via provides only delete' do test 'do not allow sign out via get when sign_out_via provides only delete' do
@@ -657,7 +626,7 @@ class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
test 'allow sign out via post when sign_out_via provides only post' do test 'allow sign out via post when sign_out_via provides only post' do
sign_in!(:sign_out_via_post) sign_in!(:sign_out_via_post)
post destroy_sign_out_via_post_session_path post destroy_sign_out_via_post_session_path
assert_not warden.authenticated?(:sign_out_via_post) refute warden.authenticated?(:sign_out_via_post)
end end
test 'do not allow sign out via get when sign_out_via provides only post' do test 'do not allow sign out via get when sign_out_via provides only post' do
@@ -671,13 +640,13 @@ class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
test 'allow sign out via delete when sign_out_via provides delete and post' do test 'allow sign out via delete when sign_out_via provides delete and post' do
sign_in!(:sign_out_via_delete_or_post) sign_in!(:sign_out_via_delete_or_post)
delete destroy_sign_out_via_delete_or_post_session_path 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 end
test 'allow sign out via post when sign_out_via provides delete and post' do test 'allow sign out via post when sign_out_via provides delete and post' do
sign_in!(:sign_out_via_delete_or_post) sign_in!(:sign_out_via_delete_or_post)
post destroy_sign_out_via_delete_or_post_session_path 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 end
test 'do not allow sign out via get when sign_out_via provides delete and post' do test 'do not allow sign out via get when sign_out_via provides delete and post' do
@@ -689,7 +658,7 @@ class AuthenticationSignOutViaTest < ActionDispatch::IntegrationTest
end end
end end
class DoubleAuthenticationRedirectTest < ActionDispatch::IntegrationTest class DoubleAuthenticationRedirectTest < Devise::IntegrationTest
test 'signed in as user redirects when visiting user sign in page' do test 'signed in as user redirects when visiting user sign in page' do
sign_in_as_user sign_in_as_user
get new_user_session_path(format: :html) get new_user_session_path(format: :html)
@@ -712,7 +681,7 @@ class DoubleAuthenticationRedirectTest < ActionDispatch::IntegrationTest
end end
end end
class DoubleSignOutRedirectTest < ActionDispatch::IntegrationTest class DoubleSignOutRedirectTest < Devise::IntegrationTest
test 'sign out after already having signed out redirects to sign in' do test 'sign out after already having signed out redirects to sign in' do
sign_in_as_user sign_in_as_user

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class ConfirmationTest < ActionDispatch::IntegrationTest class ConfirmationTest < Devise::IntegrationTest
def visit_user_confirmation_with_token(confirmation_token) def visit_user_confirmation_with_token(confirmation_token)
visit user_confirmation_path(confirmation_token: confirmation_token) visit user_confirmation_path(confirmation_token: confirmation_token)
@@ -35,18 +35,18 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
test 'user with invalid confirmation token should not be able to confirm an account' do test 'user with invalid confirmation token should not be able to confirm an account' do
visit_user_confirmation_with_token('invalid_confirmation') visit_user_confirmation_with_token('invalid_confirmation')
assert_have_selector '#error_explanation' assert_have_selector '#error_explanation'
assert_contain /Confirmation token(.*)invalid/ assert_contain %r{Confirmation token(.*)invalid}
end end
test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do 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 swap Devise, confirm_within: 3.days do
user = create_user(confirm: false, confirmation_sent_at: 4.days.ago) 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) visit_user_confirmation_with_token(user.raw_confirmation_token)
assert_have_selector '#error_explanation' assert_have_selector '#error_explanation'
assert_contain /needs to be confirmed within 3 days/ 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}" assert_current_url "/users/confirmation?confirmation_token=#{user.raw_confirmation_token}"
end end
end end
@@ -84,7 +84,7 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
test 'user with valid confirmation token should be able to confirm an account before the token has expired' do 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 swap Devise, confirm_within: 3.days do
user = create_user(confirm: false, confirmation_sent_at: 2.days.ago) 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) visit_user_confirmation_with_token(user.raw_confirmation_token)
assert_contain 'Your email address has been successfully confirmed.' assert_contain 'Your email address has been successfully confirmed.'
@@ -130,7 +130,7 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
sign_in_as_user(confirm: false) sign_in_as_user(confirm: false)
assert_contain 'You have to confirm your email address before continuing' assert_contain 'You have to confirm your email address before continuing'
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -140,8 +140,8 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
fill_in 'password', with: 'invalid' fill_in 'password', with: 'invalid'
end end
assert_contain 'Invalid email or password' assert_contain 'Invalid Email or password'
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -184,14 +184,14 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
test 'resent confirmation token with valid E-Mail in XML format should return valid response' do test 'resent confirmation token with valid E-Mail in XML format should return valid response' do
user = create_user(confirm: false) user = create_user(confirm: false)
post user_confirmation_path(format: 'xml'), user: { email: user.email } post user_confirmation_path(format: 'xml'), params: { user: { email: user.email } }
assert_response :success assert_response :success
assert_equal response.body, {}.to_xml assert_equal response.body, {}.to_xml
end end
test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do test 'resent confirmation token with invalid E-Mail in XML format should return invalid response' do
create_user(confirm: false) create_user(confirm: false)
post user_confirmation_path(format: 'xml'), user: { email: 'invalid.test@test.com' } post user_confirmation_path(format: 'xml'), params: { user: { email: 'invalid.test@test.com' } }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
@@ -213,7 +213,7 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
test 'request an account confirmation account with JSON, should return an empty JSON' do test 'request an account confirmation account with JSON, should return an empty JSON' do
user = create_user(confirm: false) user = create_user(confirm: false)
post user_confirmation_path, user: { email: user.email }, format: :json post user_confirmation_path, params: { user: { email: user.email }, format: :json }
assert_response :success assert_response :success
assert_equal response.body, {}.to_json assert_equal response.body, {}.to_json
end end
@@ -249,7 +249,7 @@ class ConfirmationTest < ActionDispatch::IntegrationTest
end end
end end
class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest class ConfirmationOnChangeTest < Devise::IntegrationTest
def create_second_admin(options={}) def create_second_admin(options={})
@admin = nil @admin = nil
create_admin(options) create_admin(options)
@@ -284,7 +284,7 @@ class ConfirmationOnChangeTest < ActionDispatch::IntegrationTest
assert_contain 'Your email address has been successfully confirmed.' assert_contain 'Your email address has been successfully confirmed.'
assert_current_url '/admin_area/sign_in' assert_current_url '/admin_area/sign_in'
assert admin.reload.confirmed? assert admin.reload.confirmed?
assert_not admin.reload.pending_reconfirmation? refute admin.reload.pending_reconfirmation?
end end
test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do 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 < ActionDispatch::IntegrationTest
assert_contain 'Your email address has been successfully confirmed.' assert_contain 'Your email address has been successfully confirmed.'
assert_current_url '/admin_area/sign_in' assert_current_url '/admin_area/sign_in'
assert admin.reload.confirmed? assert admin.reload.confirmed?
assert_not admin.reload.pending_reconfirmation? refute admin.reload.pending_reconfirmation?
end end
test 'admin email should be unique also within unconfirmed_email' do test 'admin email should be unique also within unconfirmed_email' do

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest class DatabaseAuthenticationTest < Devise::IntegrationTest
test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do
create_user(email: 'Foo@Bar.com') create_user(email: 'Foo@Bar.com')
@@ -19,7 +19,7 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
fill_in 'email', with: 'foo@bar.com' fill_in 'email', with: 'foo@bar.com'
end end
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -41,14 +41,14 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
fill_in 'email', with: ' foo@bar.com ' fill_in 'email', with: ' foo@bar.com '
end end
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
test 'sign in should not authenticate if not using proper authentication keys' do test 'sign in should not authenticate if not using proper authentication keys' do
swap Devise, authentication_keys: [:username] do swap Devise, authentication_keys: [:username] do
sign_in_as_user sign_in_as_user
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -59,7 +59,7 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
end end
assert_contain 'Invalid email address' assert_contain 'Invalid email address'
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
end end
@@ -68,8 +68,8 @@ class DatabaseAuthenticationTest < ActionDispatch::IntegrationTest
fill_in 'password', with: 'abcdef' fill_in 'password', with: 'abcdef'
end end
assert_contain 'Invalid email or password' assert_contain 'Invalid Email or password'
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
test 'error message is configurable by resource name' do test 'error message is configurable by resource name' do

View File

@@ -1,23 +1,25 @@
require 'test_helper' require 'test_helper'
class HttpAuthenticationTest < ActionDispatch::IntegrationTest class HttpAuthenticationTest < Devise::IntegrationTest
test 'handles unverified requests gets rid of caches but continues signed in' do test 'handles unverified requests gets rid of caches but continues signed in' do
swap ApplicationController, allow_forgery_protection: true do swap ApplicationController, allow_forgery_protection: true do
create_user create_user
post exhibit_user_url(1), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("user@test.com:12345678")}" post exhibit_user_url(1), headers: { "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("user@test.com:12345678")}" }
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert_equal "User is authenticated", response.body assert_equal "User is authenticated", response.body
end end
end end
test 'sign in should authenticate with http' do test 'sign in should authenticate with http' do
sign_in_as_new_user_with_http swap Devise, skip_session_storage: [] do
assert_response 200 sign_in_as_new_user_with_http
assert_match '<email>user@test.com</email>', response.body assert_response 200
assert warden.authenticated?(:user) assert_match '<email>user@test.com</email>', response.body
assert warden.authenticated?(:user)
get users_path(format: :xml) get users_path(format: :xml)
assert_response 200 assert_response 200
end
end end
test 'sign in should authenticate with http but not emit a cookie if skipping session storage' do test 'sign in should authenticate with http but not emit a cookie if skipping session storage' do
@@ -42,7 +44,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
sign_in_as_new_user_with_http("unknown") sign_in_as_new_user_with_http("unknown")
assert_equal 401, status assert_equal 401, status
assert_equal "application/xml; charset=utf-8", headers["Content-Type"] assert_equal "application/xml; charset=utf-8", headers["Content-Type"]
assert_match "<error>Invalid email or password.</error>", response.body assert_match "<error>Invalid Email or password.</error>", response.body
end end
test 'returns a custom response with www-authenticate and chosen realm' do test 'returns a custom response with www-authenticate and chosen realm' do
@@ -63,7 +65,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
end end
test 'it uses appropriate authentication_keys when configured with hash' do 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") sign_in_as_new_user_with_http("usertest")
assert_response :success assert_response :success
assert_match '<email>user@test.com</email>', response.body assert_match '<email>user@test.com</email>', response.body
@@ -72,7 +74,7 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
end end
test 'it uses the appropriate key when configured explicitly' do 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") sign_in_as_new_user_with_http("usertest")
assert_response :success assert_response :success
assert_match '<email>user@test.com</email>', response.body assert_match '<email>user@test.com</email>', response.body
@@ -89,17 +91,16 @@ class HttpAuthenticationTest < ActionDispatch::IntegrationTest
end end
private private
def sign_in_as_new_user_with_http(username="user@test.com", password="12345678") def sign_in_as_new_user_with_http(username="user@test.com", password="12345678")
user = create_user user = create_user
get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}" get users_path(format: :xml), headers: { "HTTP_AUTHORIZATION" => "Basic #{Base64.encode64("#{username}:#{password}")}" }
user user
end end
# Sign in with oauth2 token. This is just to test that it isn't misinterpreted as basic authentication # Sign in with oauth2 token. This is just to test that it isn't misinterpreted as basic authentication
def add_oauth2_header def add_oauth2_header
user = create_user user = create_user
get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:12345678")}" get users_path(format: :xml), headers: { "HTTP_AUTHORIZATION" => "OAuth #{Base64.encode64("#{user.email}:12345678")}" }
end end
end end

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class LockTest < ActionDispatch::IntegrationTest class LockTest < Devise::IntegrationTest
def visit_user_unlock_with_token(unlock_token) def visit_user_unlock_with_token(unlock_token)
visit user_unlock_path(unlock_token: unlock_token) visit user_unlock_path(unlock_token: unlock_token)
@@ -75,7 +75,7 @@ class LockTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert_current_url '/users/unlock?unlock_token=invalid_token' assert_current_url '/users/unlock?unlock_token=invalid_token'
assert_have_selector '#error_explanation' assert_have_selector '#error_explanation'
assert_contain /Unlock token(.*)invalid/ assert_contain %r{Unlock token(.*)invalid}
end end
test "locked user should be able to unlock account" do test "locked user should be able to unlock account" do
@@ -85,7 +85,7 @@ class LockTest < ActionDispatch::IntegrationTest
assert_current_url "/users/sign_in" assert_current_url "/users/sign_in"
assert_contain 'Your account has been unlocked successfully. Please sign in to continue.' 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 end
test "user should not send a new e-mail if already locked" do test "user should not send a new e-mail if already locked" do
@@ -132,9 +132,10 @@ class LockTest < ActionDispatch::IntegrationTest
user = create_user(locked: true) user = create_user(locked: true)
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
post user_unlock_path(format: 'xml'), user: {email: user.email} post user_unlock_path(format: 'xml'), params: { user: {email: user.email} }
assert_response :success assert_response :success
assert_equal response.body, {}.to_xml assert_equal response.body, {}.to_xml
assert_equal 1, ActionMailer::Base.deliveries.size assert_equal 1, ActionMailer::Base.deliveries.size
end end
@@ -142,7 +143,7 @@ class LockTest < ActionDispatch::IntegrationTest
user = create_user(locked: false) user = create_user(locked: false)
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
post user_unlock_path(format: 'xml'), user: {email: user.email} post user_unlock_path(format: 'xml'), params: { user: {email: user.email} }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
assert_equal 0, ActionMailer::Base.deliveries.size assert_equal 0, ActionMailer::Base.deliveries.size

View File

@@ -1,7 +1,7 @@
require 'test_helper' require 'test_helper'
class OmniauthableIntegrationTest < ActionDispatch::IntegrationTest class OmniauthableIntegrationTest < Devise::IntegrationTest
FACEBOOK_INFO = { FACEBOOK_INFO = {
"id" => '12345', "id" => '12345',
"link" => 'http://facebook.com/josevalim', "link" => 'http://facebook.com/josevalim',
@@ -71,7 +71,7 @@ class OmniauthableIntegrationTest < ActionDispatch::IntegrationTest
assert_current_url "/" assert_current_url "/"
assert_contain "You have signed up successfully." assert_contain "You have signed up successfully."
assert_contain "Hello User user@example.com" assert_contain "Hello User user@example.com"
assert_not session["devise.facebook_data"] refute session["devise.facebook_data"]
end end
test "cleans up session on cancel" do test "cleans up session on cancel" do

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class PasswordTest < ActionDispatch::IntegrationTest class PasswordTest < Devise::IntegrationTest
def visit_new_password_path def visit_new_password_path
visit new_user_session_path visit new_user_session_path
@@ -10,7 +10,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
def request_forgot_password(&block) def request_forgot_password(&block)
visit_new_password_path visit_new_password_path
assert_response :success assert_response :success
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
fill_in 'email', with: 'user@test.com' fill_in 'email', with: 'user@test.com'
yield if block_given? yield if block_given?
@@ -146,8 +146,8 @@ class PasswordTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert_current_url '/users/password' assert_current_url '/users/password'
assert_have_selector '#error_explanation' assert_have_selector '#error_explanation'
assert_contain /Reset password token(.*)invalid/ assert_contain %r{Reset password token(.*)invalid}
assert_not user.reload.valid_password?('987654321') refute user.reload.valid_password?('987654321')
end end
test 'not authenticated user with valid reset password token but invalid password should not be able to change their password' do test 'not authenticated user with valid reset password token but invalid password should not be able to change their password' do
@@ -160,9 +160,8 @@ class PasswordTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert_current_url '/users/password' assert_current_url '/users/password'
assert_have_selector '#error_explanation' assert_have_selector '#error_explanation'
assert_contain Devise.rails4? ? assert_contain "Password confirmation doesn't match Password"
"Password confirmation doesn't match Password" : "Password doesn't match confirmation" refute user.reload.valid_password?('987654321')
assert_not user.reload.valid_password?('987654321')
end end
test 'not authenticated user with valid data should be able to change their password' do test 'not authenticated user with valid data should be able to change their password' do
@@ -182,7 +181,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
reset_password { fill_in 'Confirm new password', with: 'other_password' } reset_password { fill_in 'Confirm new password', with: 'other_password' }
assert_response :success assert_response :success
assert_have_selector '#error_explanation' assert_have_selector '#error_explanation'
assert_not user.reload.valid_password?('987654321') refute user.reload.valid_password?('987654321')
reset_password visit: false reset_password visit: false
assert_contain 'Your password has been changed successfully.' assert_contain 'Your password has been changed successfully.'
@@ -213,7 +212,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do test 'does not sign in user automatically after changing its password if it\'s locked and unlock strategy is :none or :time' do
[:none, :time].each do |strategy| [:none, :time].each do |strategy|
swap Devise, unlock_strategy: strategy do swap Devise, unlock_strategy: strategy do
user = create_user(locked: true) create_user(locked: true)
request_forgot_password request_forgot_password
reset_password reset_password
@@ -251,14 +250,14 @@ class PasswordTest < ActionDispatch::IntegrationTest
test 'reset password request with valid E-Mail in XML format should return valid response' do test 'reset password request with valid E-Mail in XML format should return valid response' do
create_user create_user
post user_password_path(format: 'xml'), user: {email: "user@test.com"} post user_password_path(format: 'xml'), params: { user: {email: "user@test.com"} }
assert_response :success assert_response :success
assert_equal response.body, { }.to_xml assert_equal response.body, { }.to_xml
end end
test 'reset password request with invalid E-Mail in XML format should return valid response' do test 'reset password request with invalid E-Mail in XML format should return valid response' do
create_user create_user
post user_password_path(format: 'xml'), user: {email: "invalid.test@test.com"} post user_password_path(format: 'xml'), params: { user: {email: "invalid.test@test.com"} }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
@@ -266,7 +265,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do test 'reset password request with invalid E-Mail in XML format should return empty and valid response' do
swap Devise, paranoid: true do swap Devise, paranoid: true do
create_user create_user
post user_password_path(format: 'xml'), user: {email: "invalid@test.com"} post user_password_path(format: 'xml'), params: { user: {email: "invalid@test.com"} }
assert_response :success assert_response :success
assert_equal response.body, { }.to_xml assert_equal response.body, { }.to_xml
end end
@@ -275,8 +274,9 @@ class PasswordTest < ActionDispatch::IntegrationTest
test 'change password with valid parameters in XML format should return valid response' do test 'change password with valid parameters in XML format should return valid response' do
create_user create_user
request_forgot_password request_forgot_password
put user_password_path(format: 'xml'), user: { put user_password_path(format: 'xml'), params: { user: {
reset_password_token: 'abcdef', password: '987654321', password_confirmation: '987654321' reset_password_token: 'abcdef', password: '987654321', password_confirmation: '987654321'
}
} }
assert_response :success assert_response :success
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
@@ -285,7 +285,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
test 'change password with invalid token in XML format should return invalid response' do test 'change password with invalid token in XML format should return invalid response' do
create_user create_user
request_forgot_password request_forgot_password
put user_password_path(format: 'xml'), user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} put user_password_path(format: 'xml'), params: { user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
@@ -293,7 +293,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
test 'change password with invalid new password in XML format should return invalid response' do test 'change password with invalid new password in XML format should return invalid response' do
user = create_user user = create_user
request_forgot_password request_forgot_password
put user_password_path(format: 'xml'), user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} put user_password_path(format: 'xml'), params: { user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
@@ -301,7 +301,7 @@ class PasswordTest < ActionDispatch::IntegrationTest
test "when using json requests to ask a confirmable request, should not return the object" do test "when using json requests to ask a confirmable request, should not return the object" do
user = create_user(confirm: false) user = create_user(confirm: false)
post user_password_path(format: :json), user: { email: user.email } post user_password_path(format: :json), params: { user: { email: user.email } }
assert_response :success assert_response :success
assert_equal response.body, "{}" assert_equal response.body, "{}"

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class RegistrationTest < ActionDispatch::IntegrationTest class RegistrationTest < Devise::IntegrationTest
test 'a guest admin should be able to sign in successfully' do test 'a guest admin should be able to sign in successfully' do
get new_admin_session_path get new_admin_session_path
@@ -64,11 +64,11 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_not_contain 'You have to confirm your account before continuing' assert_not_contain 'You have to confirm your account before continuing'
assert_current_url "/" assert_current_url "/"
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
user = User.to_adapter.find_first(order: [:id, :desc]) user = User.to_adapter.find_first(order: [:id, :desc])
assert_equal user.email, 'new_user@test.com' assert_equal user.email, 'new_user@test.com'
assert_not user.confirmed? refute user.confirmed?
end end
test 'a guest user should receive the confirmation instructions from the default mailer' do test 'a guest user should receive the confirmation instructions from the default mailer' do
@@ -92,7 +92,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
click_button 'Sign up' click_button 'Sign up'
assert_current_url "/?custom=1" assert_current_url "/?custom=1"
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'a guest user cannot sign up with invalid information' do test 'a guest user cannot sign up with invalid information' do
@@ -110,12 +110,11 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_template 'registrations/new' assert_template 'registrations/new'
assert_have_selector '#error_explanation' assert_have_selector '#error_explanation'
assert_contain "Email is invalid" assert_contain "Email is invalid"
assert_contain Devise.rails4? ? assert_contain "Password confirmation doesn't match Password"
"Password confirmation doesn't match Password" : "Password doesn't match confirmation"
assert_contain "2 errors prohibited" assert_contain "2 errors prohibited"
assert_nil User.to_adapter.find_first assert_nil User.to_adapter.find_first
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'a guest should not sign up with email/password that already exists' do test 'a guest should not sign up with email/password that already exists' do
@@ -134,7 +133,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
assert_current_url '/users' assert_current_url '/users'
assert_contain(/Email.*already.*taken/) assert_contain(/Email.*already.*taken/)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'a guest should not be able to change account' do test 'a guest should not be able to change account' do
@@ -217,9 +216,14 @@ class RegistrationTest < ActionDispatch::IntegrationTest
fill_in 'current password', with: '12345678' fill_in 'current password', with: '12345678'
click_button 'Update' click_button 'Update'
assert_contain Devise.rails4? ? assert_contain "Password confirmation doesn't match Password"
"Password confirmation doesn't match Password" : "Password doesn't match confirmation" refute User.to_adapter.find_first.valid_password?('pas123')
assert_not 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 end
test 'a signed in user should be able to cancel their account' do test 'a signed in user should be able to cancel their account' do
@@ -259,7 +263,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
end end
test 'an admin sign up with valid information in XML format should return valid response' do test 'an admin sign up with valid information in XML format should return valid response' do
post admin_registration_path(format: 'xml'), admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } post admin_registration_path(format: 'xml'), params: { admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<admin>)
@@ -268,7 +272,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
end end
test 'a user sign up with valid information in XML format should return valid response' do test 'a user sign up with valid information in XML format should return valid response' do
post user_registration_path(format: 'xml'), user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }
assert_response :success assert_response :success
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>)
@@ -277,21 +281,21 @@ class RegistrationTest < ActionDispatch::IntegrationTest
end end
test 'a user sign up with invalid information in XML format should return invalid response' do test 'a user sign up with invalid information in XML format should return invalid response' do
post user_registration_path(format: 'xml'), user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } post user_registration_path(format: 'xml'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>) assert response.body.include? %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>)
end end
test 'a user update information with valid data in XML format should return valid response' do test 'a user update information with valid data in XML format should return valid response' do
user = sign_in_as_user user = sign_in_as_user
put user_registration_path(format: 'xml'), user: { current_password: '12345678', email: 'user.new@test.com' } put user_registration_path(format: 'xml'), params: { user: { current_password: '12345678', email: 'user.new@test.com' } }
assert_response :success assert_response :success
assert_equal user.reload.email, 'user.new@test.com' assert_equal user.reload.email, 'user.new@test.com'
end end
test 'a user update information with invalid data in XML format should return invalid response' do test 'a user update information with invalid data in XML format should return invalid response' do
user = sign_in_as_user user = sign_in_as_user
put user_registration_path(format: 'xml'), user: { current_password: 'invalid', email: 'user.new@test.com' } put user_registration_path(format: 'xml'), params: { user: { current_password: 'invalid', email: 'user.new@test.com' } }
assert_response :unprocessable_entity assert_response :unprocessable_entity
assert_equal user.reload.email, 'user@test.com' assert_equal user.reload.email, 'user@test.com'
end end
@@ -304,7 +308,7 @@ class RegistrationTest < ActionDispatch::IntegrationTest
end end
end end
class ReconfirmableRegistrationTest < ActionDispatch::IntegrationTest class ReconfirmableRegistrationTest < Devise::IntegrationTest
test 'a signed in admin should see a more appropriate flash message when editing their account if reconfirmable is enabled' do test 'a signed in admin should see a more appropriate flash message when editing their account if reconfirmable is enabled' do
sign_in_as_admin sign_in_as_admin
get edit_admin_registration_path get edit_admin_registration_path

View File

@@ -1,16 +1,16 @@
require 'test_helper' require 'test_helper'
class RememberMeTest < ActionDispatch::IntegrationTest class RememberMeTest < Devise::IntegrationTest
def create_user_and_remember(add_to_token='') def create_user_and_remember(add_to_token='')
user = create_user user = create_user
user.remember_me! user.remember_me!
raw_cookie = User.serialize_into_cookie(user).tap { |a| a.last << add_to_token } raw_cookie = User.serialize_into_cookie(user).tap { |a| a[1] << add_to_token }
cookies['remember_user_token'] = generate_signed_cookie(raw_cookie) cookies['remember_user_token'] = generate_signed_cookie(raw_cookie)
user user
end end
def generate_signed_cookie(raw_cookie) def generate_signed_cookie(raw_cookie)
request = ActionDispatch::TestRequest.new request = Devise.rails5? ? ActionDispatch::TestRequest.create : ActionDispatch::TestRequest.new
request.cookie_jar.signed['raw_cookie'] = raw_cookie request.cookie_jar.signed['raw_cookie'] = raw_cookie
request.cookie_jar['raw_cookie'] request.cookie_jar['raw_cookie']
end end
@@ -33,12 +33,12 @@ class RememberMeTest < ActionDispatch::IntegrationTest
test 'handle unverified requests gets rid of caches' do test 'handle unverified requests gets rid of caches' do
swap ApplicationController, allow_forgery_protection: true do swap ApplicationController, allow_forgery_protection: true do
post exhibit_user_url(1) post exhibit_user_url(1)
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
create_user_and_remember create_user_and_remember
post exhibit_user_url(1) post exhibit_user_url(1)
assert_equal "User is not authenticated", response.body assert_equal "User is not authenticated", response.body
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -47,10 +47,12 @@ class RememberMeTest < ActionDispatch::IntegrationTest
get new_user_session_path get new_user_session_path
assert request.session[:_csrf_token] assert request.session[:_csrf_token]
post user_session_path, authenticity_token: "oops", user: post user_session_path, params: {
{ email: "jose.valim@gmail.com", password: "123456", remember_me: "1" } authenticity_token: "oops",
assert_not warden.authenticated?(:user) user: { email: "jose.valim@gmail.com", password: "123456", remember_me: "1" }
assert_not request.cookies['remember_user_token'] }
refute warden.authenticated?(:user)
refute request.cookies['remember_user_token']
end end
end end
@@ -92,7 +94,6 @@ class RememberMeTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert warden.user(:user) == user assert warden.user(:user) == user
assert_match /remember_user_token[^\n]*HttpOnly/, response.headers["Set-Cookie"], "Expected Set-Cookie header in response to set HttpOnly flag on remember_user_token cookie."
end end
test 'remember the user before sign up and redirect them to their home' do test 'remember the user before sign up and redirect them to their home' do
@@ -118,26 +119,60 @@ class RememberMeTest < ActionDispatch::IntegrationTest
end end
end end
test 'extends remember period when extend remember period config is true' do
swap Devise, extend_remember_period: true, remember_for: 1.year do
create_user_and_remember
old_remember_token = nil
travel_to 1.day.ago do
get root_path
old_remember_token = request.cookies['remember_user_token']
end
get root_path
current_remember_token = request.cookies['remember_user_token']
refute_equal old_remember_token, current_remember_token
end
end
test 'does not extend remember period when extend period config is false' do
swap Devise, extend_remember_period: false, remember_for: 1.year do
create_user_and_remember
old_remember_token = nil
travel_to 1.day.ago do
get root_path
old_remember_token = request.cookies['remember_user_token']
end
get root_path
current_remember_token = request.cookies['remember_user_token']
assert_equal old_remember_token, current_remember_token
end
end
test 'do not remember other scopes' do test 'do not remember other scopes' do
create_user_and_remember create_user_and_remember
get root_path get root_path
assert_response :success assert_response :success
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
test 'do not remember with invalid token' do test 'do not remember with invalid token' do
create_user_and_remember('add') create_user_and_remember('add')
get users_path get users_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert_redirected_to new_user_session_path assert_redirected_to new_user_session_path
end end
test 'do not remember with expired token' do test 'do not remember with expired token' do
create_user_and_remember create_user_and_remember
swap Devise, remember_for: 0 do swap Devise, remember_for: 0.days do
get users_path get users_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert_redirected_to new_user_session_path assert_redirected_to new_user_session_path
end end
end end
@@ -147,12 +182,12 @@ class RememberMeTest < ActionDispatch::IntegrationTest
get users_path get users_path
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
get destroy_user_session_path delete destroy_user_session_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert_nil warden.cookies['remember_user_token'] assert_nil warden.cookies['remember_user_token']
get users_path get users_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'changing user password expires remember me token' do test 'changing user password expires remember me token' do
@@ -162,7 +197,7 @@ class RememberMeTest < ActionDispatch::IntegrationTest
user.save! user.save!
get users_path get users_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'valid sign in calls after_remembered callback' do test 'valid sign in calls after_remembered callback' do

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class SessionTimeoutTest < ActionDispatch::IntegrationTest class SessionTimeoutTest < Devise::IntegrationTest
def last_request_at def last_request_at
@controller.user_session['last_request_at'] @controller.user_session['last_request_at']
@@ -20,7 +20,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
old_last_request = last_request_at old_last_request = last_request_at
assert_not_nil last_request_at assert_not_nil last_request_at
get users_path, {}, 'devise.skip_trackable' => true get users_path, headers: { 'devise.skip_trackable' => true }
assert_equal old_last_request, last_request_at assert_equal old_last_request, last_request_at
end end
@@ -32,7 +32,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
new_time = 2.seconds.from_now new_time = 2.seconds.from_now
Time.stubs(:now).returns(new_time) Time.stubs(:now).returns(new_time)
get users_path, {}, 'devise.skip_timeoutable' => true get users_path, headers: { 'devise.skip_timeoutable' => true }
assert_equal old_last_request, last_request_at assert_equal old_last_request, last_request_at
end end
@@ -56,7 +56,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
get users_path get users_path
assert_redirected_to users_path assert_redirected_to users_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert warden.authenticated?(:admin) assert warden.authenticated?(:admin)
end end
end end
@@ -70,8 +70,8 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
assert_not_nil last_request_at assert_not_nil last_request_at
get root_path get root_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
assert_not warden.authenticated?(:admin) refute warden.authenticated?(:admin)
end end
end end
@@ -89,7 +89,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
user = sign_in_as_user user = sign_in_as_user
get expire_user_path(user) get expire_user_path(user)
get destroy_user_session_path delete destroy_user_session_path
assert_response :redirect assert_response :redirect
assert_redirected_to root_path assert_redirected_to root_path
@@ -108,14 +108,14 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
assert_contain 'Sign in' assert_contain 'Sign in'
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
test 'time out is not triggered on sign in' do test 'time out is not triggered on sign in' do
user = sign_in_as_user user = sign_in_as_user
get expire_user_path(user) get expire_user_path(user)
post "/users/sign_in", email: user.email, password: "123456" post "/users/sign_in", params: { email: user.email, password: "123456" }
assert_response :redirect assert_response :redirect
follow_redirect! follow_redirect!
@@ -134,7 +134,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
get expire_user_path(user) get expire_user_path(user)
get users_path get users_path
assert_redirected_to users_path assert_redirected_to users_path
assert_not warden.authenticated?(:user) refute warden.authenticated?(:user)
end end
end end
@@ -175,7 +175,7 @@ class SessionTimeoutTest < ActionDispatch::IntegrationTest
assert warden.authenticated?(:user) assert warden.authenticated?(:user)
end end
test 'does not crashes when the last_request_at is a String' do test 'does not crash when the last_request_at is a String' do
user = sign_in_as_user user = sign_in_as_user
get edit_form_user_path(user, last_request_at: Time.now.utc.to_s) get edit_form_user_path(user, last_request_at: Time.now.utc.to_s)

View File

@@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class TrackableHooksTest < ActionDispatch::IntegrationTest class TrackableHooksTest < Devise::IntegrationTest
test "current and last sign in timestamps are updated on each sign in" do test "current and last sign in timestamps are updated on each sign in" do
user = create_user user = create_user
@@ -16,7 +16,7 @@ class TrackableHooksTest < ActionDispatch::IntegrationTest
assert_equal user.current_sign_in_at, user.last_sign_in_at assert_equal user.current_sign_in_at, user.last_sign_in_at
assert user.current_sign_in_at >= user.created_at assert user.current_sign_in_at >= user.created_at
visit destroy_user_session_path delete destroy_user_session_path
new_time = 2.seconds.from_now new_time = 2.seconds.from_now
Time.stubs(:now).returns(new_time) Time.stubs(:now).returns(new_time)
@@ -56,7 +56,7 @@ class TrackableHooksTest < ActionDispatch::IntegrationTest
user.reload user.reload
assert_equal 1, user.sign_in_count assert_equal 1, user.sign_in_count
visit destroy_user_session_path delete destroy_user_session_path
sign_in_as_user sign_in_as_user
user.reload user.reload
assert_equal 2, user.sign_in_count assert_equal 2, user.sign_in_count
@@ -80,7 +80,7 @@ class TrackableHooksTest < ActionDispatch::IntegrationTest
end end
user.reload user.reload
assert_equal 0, user.sign_in_count assert_equal 0, user.sign_in_count
visit destroy_user_session_path delete destroy_user_session_path
sign_in_as_user do sign_in_as_user do
header 'devise.skip_trackable', false header 'devise.skip_trackable', false

View File

@@ -37,16 +37,16 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
assert_equal [user.email], mail.to assert_equal [user.email], mail.to
end end
test 'setup sender from configuration' do test 'set up sender from configuration' do
assert_equal ['test@example.com'], mail.from assert_equal ['test@example.com'], mail.from
end end
test 'setup sender from custom mailer defaults' do test 'set up sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer' Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from assert_equal ['custom@example.com'], mail.from
end end
test 'setup sender from custom mailer defaults with proc' do test 'set up sender from custom mailer defaults with proc' do
Devise.mailer = 'Users::FromProcMailer' Devise.mailer = 'Users::FromProcMailer'
assert_equal ['custom@example.com'], mail.from assert_equal ['custom@example.com'], mail.from
end end
@@ -56,17 +56,17 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
assert_present mail.body.encoded assert_present mail.body.encoded
end end
test 'setup reply to as copy from sender' do test 'set up reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to assert_equal ['test@example.com'], mail.reply_to
end end
test 'setup reply to as different if set in defaults' do test 'set up reply to as different if set in defaults' do
Devise.mailer = 'Users::ReplyToMailer' Devise.mailer = 'Users::ReplyToMailer'
assert_equal ['custom@example.com'], mail.from assert_equal ['custom@example.com'], mail.from
assert_equal ['custom_reply_to@example.com'], mail.reply_to assert_equal ['custom_reply_to@example.com'], mail.reply_to
end end
test 'setup subject from I18n' do test 'set up subject from I18n' do
store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do
assert_equal 'Account Confirmation', mail.subject assert_equal 'Account Confirmation', mail.subject
end end

View File

@@ -39,16 +39,16 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
assert_equal [user.email], mail.to assert_equal [user.email], mail.to
end end
test 'setup sender from configuration' do test 'set up sender from configuration' do
assert_equal ['test@example.com'], mail.from assert_equal ['test@example.com'], mail.from
end end
test 'setup sender from custom mailer defaults' do test 'set up sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer' Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from assert_equal ['custom@example.com'], mail.from
end end
test 'setup sender from custom mailer defaults with proc' do test 'set up sender from custom mailer defaults with proc' do
Devise.mailer = 'Users::FromProcMailer' Devise.mailer = 'Users::FromProcMailer'
assert_equal ['custom@example.com'], mail.from assert_equal ['custom@example.com'], mail.from
end end
@@ -58,11 +58,11 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
assert_present mail.body.encoded assert_present mail.body.encoded
end end
test 'setup reply to as copy from sender' do test 'set up reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to assert_equal ['test@example.com'], mail.reply_to
end end
test 'setup subject from I18n' do test 'set up subject from I18n' do
store_translations :en, devise: { mailer: { reset_password_instructions: { subject: 'Reset instructions' } } } do store_translations :en, devise: { mailer: { reset_password_instructions: { subject: 'Reset instructions' } } } do
assert_equal 'Reset instructions', mail.subject assert_equal 'Reset instructions', mail.subject
end end

View File

@@ -40,16 +40,16 @@ class UnlockInstructionsTest < ActionMailer::TestCase
assert_equal [user.email], mail.to assert_equal [user.email], mail.to
end end
test 'setup sender from configuration' do test 'set up sender from configuration' do
assert_equal ['test@example.com'], mail.from assert_equal ['test@example.com'], mail.from
end end
test 'setup sender from custom mailer defaults' do test 'set up sender from custom mailer defaults' do
Devise.mailer = 'Users::Mailer' Devise.mailer = 'Users::Mailer'
assert_equal ['custom@example.com'], mail.from assert_equal ['custom@example.com'], mail.from
end end
test 'setup sender from custom mailer defaults with proc' do test 'set up sender from custom mailer defaults with proc' do
Devise.mailer = 'Users::FromProcMailer' Devise.mailer = 'Users::FromProcMailer'
assert_equal ['custom@example.com'], mail.from assert_equal ['custom@example.com'], mail.from
end end
@@ -59,11 +59,11 @@ class UnlockInstructionsTest < ActionMailer::TestCase
assert_present mail.body.encoded assert_present mail.body.encoded
end end
test 'setup reply to as copy from sender' do test 'set up reply to as copy from sender' do
assert_equal ['test@example.com'], mail.reply_to assert_equal ['test@example.com'], mail.reply_to
end end
test 'setup subject from I18n' do test 'set up subject from I18n' do
store_translations :en, devise: { mailer: { unlock_instructions: { subject: 'Yo unlock instructions' } } } do store_translations :en, devise: { mailer: { unlock_instructions: { subject: 'Yo unlock instructions' } } } do
assert_equal 'Yo unlock instructions', mail.subject assert_equal 'Yo unlock instructions', mail.subject
end end

View File

@@ -35,8 +35,8 @@ class MappingTest < ActiveSupport::TestCase
assert_equal [], Devise.mappings[:skip_admin].used_routes assert_equal [], Devise.mappings[:skip_admin].used_routes
end end
test 'sign_out_via defaults to :get' do test 'sign_out_via defaults to :delete' do
assert_equal :get, Devise.mappings[:user].sign_out_via assert_equal :delete, Devise.mappings[:user].sign_out_via
end end
test 'allows custom sign_out_via to be given' do test 'allows custom sign_out_via to be given' do
@@ -115,7 +115,7 @@ class MappingTest < ActiveSupport::TestCase
assert mapping.authenticatable? assert mapping.authenticatable?
assert mapping.recoverable? assert mapping.recoverable?
assert mapping.lockable? assert mapping.lockable?
assert_not mapping.omniauthable? refute mapping.omniauthable?
end end
test 'find mapping by path' do test 'find mapping by path' do

View File

@@ -28,9 +28,9 @@ class ConfirmableTest < ActiveSupport::TestCase
end end
test 'should verify whether a user is confirmed or not' do test 'should verify whether a user is confirmed or not' do
assert_not new_user.confirmed? refute new_user.confirmed?
user = create_user user = create_user
assert_not user.confirmed? refute user.confirmed?
user.confirm user.confirm
assert user.confirmed? assert user.confirmed?
end end
@@ -40,7 +40,7 @@ class ConfirmableTest < ActiveSupport::TestCase
assert user.confirm assert user.confirm
assert_blank user.errors[:email] 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 assert_equal "was already confirmed, please try signing in", user.errors[:email].join
end end
@@ -54,13 +54,13 @@ class ConfirmableTest < ActiveSupport::TestCase
test 'should return a new record with errors when a invalid token is given' do test 'should return a new record with errors when a invalid token is given' do
confirmed_user = User.confirm_by_token('invalid_confirmation_token') 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 assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
end end
test 'should return a new record with errors when a blank token is given' do test 'should return a new record with errors when a blank token is given' do
confirmed_user = User.confirm_by_token('') 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 assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
end end
@@ -114,7 +114,7 @@ class ConfirmableTest < ActiveSupport::TestCase
assert_email_not_sent do assert_email_not_sent do
user.save! user.save!
assert !user.confirmed? refute user.confirmed?
end end
end end
@@ -134,7 +134,7 @@ class ConfirmableTest < ActiveSupport::TestCase
test 'should return a new user if no email was found' do test 'should return a new user if no email was found' do
confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com") confirmation_user = User.send_confirmation_instructions(email: "invalid@example.com")
assert_not confirmation_user.persisted? refute confirmation_user.persisted?
end end
test 'should add error to new user email if no email was found' do test 'should add error to new user email if no email was found' do
@@ -181,16 +181,16 @@ class ConfirmableTest < ActiveSupport::TestCase
test 'should not be able to send instructions if the user is already confirmed' do test 'should not be able to send instructions if the user is already confirmed' do
user = create_user user = create_user
user.confirm user.confirm
assert_not user.resend_confirmation_instructions refute user.resend_confirmation_instructions
assert user.confirmed? assert user.confirmed?
assert_equal 'was already confirmed, please try signing in', user.errors[:email].join assert_equal 'was already confirmed, please try signing in', user.errors[:email].join
end end
test 'confirm time should fallback to devise confirm in default configuration' do test 'confirm time should fallback to devise confirm in default configuration' do
swap Devise, allow_unconfirmed_access_for: 1.day do swap Devise, allow_unconfirmed_access_for: 1.day do
user = new_user user = create_user
user.confirmation_sent_at = 2.days.ago 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 Devise.allow_unconfirmed_access_for = 3.days
assert user.active_for_authentication? assert user.active_for_authentication?
@@ -206,14 +206,14 @@ class ConfirmableTest < ActiveSupport::TestCase
assert user.active_for_authentication? assert user.active_for_authentication?
user.confirmation_sent_at = 5.days.ago user.confirmation_sent_at = 5.days.ago
assert_not user.active_for_authentication? refute user.active_for_authentication?
end end
end end
test 'should be active when already confirmed' do test 'should be active when already confirmed' do
user = create_user user = create_user
assert_not user.confirmed? refute user.confirmed?
assert_not user.active_for_authentication? refute user.active_for_authentication?
user.confirm user.confirm
assert user.confirmed? assert user.confirmed?
@@ -224,7 +224,7 @@ class ConfirmableTest < ActiveSupport::TestCase
Devise.allow_unconfirmed_access_for = 0.days Devise.allow_unconfirmed_access_for = 0.days
user = create_user user = create_user
user.confirmation_sent_at = Time.zone.today user.confirmation_sent_at = Time.zone.today
assert_not user.active_for_authentication? refute user.active_for_authentication?
end end
test 'should be active when we set allow_unconfirmed_access_for to nil' do 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 = create_user
user.confirmation_sent_at = nil user.confirmation_sent_at = nil
user.save user.save
assert_not user.reload.active_for_authentication? refute user.reload.active_for_authentication?
end end
test 'should be active without confirmation when confirmation is not required' do test 'should be active without confirmation when confirmation is not required' do
@@ -256,7 +256,7 @@ class ConfirmableTest < ActiveSupport::TestCase
user.instance_eval { def confirmation_required?; false end } user.instance_eval { def confirmation_required?; false end }
user.confirmation_sent_at = nil user.confirmation_sent_at = nil
user.save user.save
assert user.reload.confirm! assert user.reload.confirm
end end
end end
@@ -272,7 +272,7 @@ class ConfirmableTest < ActiveSupport::TestCase
swap Devise, confirmation_keys: [:username, :email] do swap Devise, confirmation_keys: [:username, :email] do
user = create_user user = create_user
confirm_user = User.send_confirmation_instructions(email: user.email) 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 assert_equal "can't be blank", confirm_user.errors[:username].join
end end
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 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 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
end end
@@ -337,14 +337,14 @@ class ConfirmableTest < ActiveSupport::TestCase
self.username = self.username.to_s + 'updated' self.username = self.username.to_s + 'updated'
end end
old = user.username old = user.username
assert_not user.confirm refute user.confirm
assert_equal user.username, old assert_equal user.username, old
end end
test 'should always perform validations upon confirm when ensure valid true' do test 'should always perform validations upon confirm when ensure valid true' do
admin = create_admin admin = create_admin
admin.stubs(:valid?).returns(false) admin.stubs(:valid?).returns(false)
assert_not admin.confirm(ensure_valid: true) refute admin.confirm(ensure_valid: true)
end end
end end
@@ -370,7 +370,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
admin.skip_reconfirmation! admin.skip_reconfirmation!
assert admin.update_attributes(email: 'new_test@example.com') assert admin.update_attributes(email: 'new_test@example.com')
assert admin.confirmed? assert admin.confirmed?
assert_not admin.pending_reconfirmation? refute admin.pending_reconfirmation?
assert_equal original_token, admin.confirmation_token assert_equal original_token, admin.confirmation_token
end end
@@ -401,6 +401,14 @@ class ReconfirmableTest < ActiveSupport::TestCase
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
end end
test 'should send confirmation instructions by email after changing email from nil' do
admin = create_admin(email: nil)
assert_email_sent "new_test@example.com" do
assert admin.update_attributes(email: 'new_test@example.com')
end
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
end
test 'should not send confirmation by email after changing password' do test 'should not send confirmation by email after changing password' do
admin = create_admin admin = create_admin
assert admin.confirm assert admin.confirm
@@ -453,7 +461,7 @@ class ReconfirmableTest < ActiveSupport::TestCase
test 'should return a new admin if no email or unconfirmed_email was found' do 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") confirmation_admin = Admin.send_confirmation_instructions(email: "invalid@email.com")
assert_not confirmation_admin.persisted? refute confirmation_admin.persisted?
end end
test 'should add error to new admin email if no email or unconfirmed_email was found' do test 'should add error to new admin email if no email or unconfirmed_email was found' do
@@ -471,19 +479,33 @@ class ReconfirmableTest < ActiveSupport::TestCase
end end
test 'required_fields should contain the fields that Devise uses' do test 'required_fields should contain the fields that Devise uses' do
assert_same_content Devise::Models::Confirmable.required_fields(User), [ assert_equal Devise::Models::Confirmable.required_fields(User), [
:confirmation_sent_at,
:confirmation_token, :confirmation_token,
:confirmed_at :confirmed_at,
:confirmation_sent_at
] ]
end end
test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do
assert_same_content Devise::Models::Confirmable.required_fields(Admin), [ assert_equal Devise::Models::Confirmable.required_fields(Admin), [
:confirmation_sent_at,
:confirmation_token, :confirmation_token,
:confirmed_at, :confirmed_at,
:confirmation_sent_at,
:unconfirmed_email :unconfirmed_email
] ]
end end
test 'should not require reconfirmation after creating a record' do
admin = create_admin
assert !admin.pending_reconfirmation?
end
test 'should not require reconfirmation after creating a record with #save called in callback' do
class Admin::WithSaveInCallback < Admin
after_create :save
end
admin = Admin::WithSaveInCallback.create(valid_attributes.except(:username))
assert !admin.pending_reconfirmation?
end
end end

View File

@@ -92,28 +92,28 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert user.respond_to?(:password_confirmation) assert user.respond_to?(:password_confirmation)
end end
test 'should generate encrypted password while setting password' do test 'should generate a hashed password while setting password' do
user = new_user user = new_user
assert_present user.encrypted_password assert_present user.encrypted_password
end end
test 'should support custom encryption methods' do test 'should support custom hashing methods' do
user = UserWithCustomEncryption.new(password: '654321') user = UserWithCustomHashing.new(password: '654321')
assert_equal user.encrypted_password, '123456' assert_equal user.encrypted_password, '123456'
end end
test 'allow authenticatable_salt to work even with nil encrypted password' do test 'allow authenticatable_salt to work even with nil hashed password' do
user = User.new user = User.new
user.encrypted_password = nil user.encrypted_password = nil
assert_nil user.authenticatable_salt assert_nil user.authenticatable_salt
end end
test 'should not generate encrypted password if password is blank' do test 'should not generate a hashed password if password is blank' do
assert_blank new_user(password: nil).encrypted_password assert_blank new_user(password: nil).encrypted_password
assert_blank new_user(password: '').encrypted_password assert_blank new_user(password: '').encrypted_password
end end
test 'should encrypt password again if password has changed' do test 'should hash password again if password has changed' do
user = create_user user = create_user
encrypted_password = user.encrypted_password encrypted_password = user.encrypted_password
user.password = user.password_confirmation = 'new_password' user.password = user.password_confirmation = 'new_password'
@@ -124,7 +124,7 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
test 'should test for a valid password' do test 'should test for a valid password' do
user = create_user user = create_user
assert user.valid_password?('12345678') assert user.valid_password?('12345678')
assert_not user.valid_password?('654321') refute user.valid_password?('654321')
end end
test 'should not raise error with an empty password' do 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 test 'should be an invalid password if the user has an empty password' do
user = create_user user = create_user
user.encrypted_password = '' user.encrypted_password = ''
assert_not user.valid_password?('654321') refute user.valid_password?('654321')
end end
test 'should respond to current password' do 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 test 'should add an error to current password when it is invalid' do
user = create_user 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') password: 'pass4321', password_confirmation: 'pass4321')
assert user.reload.valid_password?('12345678') assert user.reload.valid_password?('12345678')
assert_match "is invalid", user.errors[:current_password].join 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 test 'should add an error to current password when it is blank' do
user = create_user user = create_user
assert_not user.update_with_password(password: 'pass4321', refute user.update_with_password(password: 'pass4321',
password_confirmation: 'pass4321') password_confirmation: 'pass4321')
assert user.reload.valid_password?('12345678') assert user.reload.valid_password?('12345678')
assert_match "can't be blank", user.errors[:current_password].join 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 = UserWithValidation.create!(valid_attributes)
user.save user.save
assert user.persisted? assert user.persisted?
assert_not user.update_with_password(username: "") refute user.update_with_password(username: "")
assert_match "usertest", user.reload.username assert_match "usertest", user.reload.username
assert_match "can't be blank", user.errors[:username].join assert_match "can't be blank", user.errors[:username].join
end end
@@ -183,14 +183,14 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
test 'should not update password with invalid confirmation' do test 'should not update password with invalid confirmation' do
user = create_user 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') password: 'pass4321', password_confirmation: 'other')
assert user.reload.valid_password?('12345678') assert user.reload.valid_password?('12345678')
end end
test 'should clean up password fields on failure' do test 'should clean up password fields on failure' do
user = create_user 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') password: 'pass4321', password_confirmation: 'other')
assert user.password.blank? assert user.password.blank?
assert user.password_confirmation.blank? assert user.password_confirmation.blank?
@@ -217,14 +217,14 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
test 'should not destroy user with invalid password' do test 'should not destroy user with invalid password' do
user = create_user user = create_user
assert_not user.destroy_with_password('other') refute user.destroy_with_password('other')
assert user.persisted? assert user.persisted?
assert_match "is invalid", user.errors[:current_password].join assert_match "is invalid", user.errors[:current_password].join
end end
test 'should not destroy user with blank password' do test 'should not destroy user with blank password' do
user = create_user user = create_user
assert_not user.destroy_with_password(nil) refute user.destroy_with_password(nil)
assert user.persisted? assert user.persisted?
assert_match "can't be blank", user.errors[:current_password].join assert_match "can't be blank", user.errors[:current_password].join
end end
@@ -252,15 +252,15 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
end end
test 'required_fields should be encryptable_password and the email field by default' do test 'required_fields should be encryptable_password and the email field by default' do
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [ assert_equal Devise::Models::DatabaseAuthenticatable.required_fields(User), [
:email, :encrypted_password,
:encrypted_password :email
] ]
end end
test 'required_fields should be encryptable_password and the login when the login is on authentication_keys' do test 'required_fields should be encryptable_password and the login when the login is on authentication_keys' do
swap Devise, authentication_keys: [:login] 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, :encrypted_password,
:login :login
] ]

Some files were not shown because too many files have changed in this diff Show More