From 1b1d32ac0b909afd76a695b524b399adc1dab338 Mon Sep 17 00:00:00 2001 From: Lynn Hurley Date: Fri, 13 Oct 2017 20:18:13 -0500 Subject: [PATCH] [tests] update test suite for rails 5.1 notable changes: - added rails version to migrations - updated test requests to new format - updated several test runner dependencies - various rubocop linting fixes within test suite --- Gemfile | 37 +- Gemfile.lock | 149 ++--- .../devise_token_auth/passwords_controller.rb | 1 + .../custom_confirmations_controller_test.rb | 15 +- ...stom_omniauth_callbacks_controller_test.rb | 31 +- .../custom_passwords_controller_test.rb | 62 +- .../custom_registrations_controller_test.rb | 44 +- .../custom/custom_sessions_controller_test.rb | 34 +- ...ustom_token_validations_controller_test.rb | 24 +- .../controllers/demo_group_controller_test.rb | 14 +- test/controllers/demo_mang_controller_test.rb | 42 +- test/controllers/demo_user_controller_test.rb | 98 ++-- .../confirmations_controller_test.rb | 52 +- .../omniauth_callbacks_controller_test.rb | 170 +++--- .../passwords_controller_test.rb | 258 ++++----- .../registrations_controller_test.rb | 532 +++++++++--------- .../sessions_controller_test.rb | 229 ++++---- .../token_validations_controller_test.rb | 29 +- .../unlocks_controller_test.rb | 56 +- .../confirmations_controller_test.rb | 17 +- .../omniauth_callbacks_controller_test.rb | 28 +- .../overrides/passwords_controller_test.rb | 28 +- .../registrations_controller_test.rb | 14 +- .../overrides/sessions_controller_test.rb | 12 +- .../token_validations_controller_test.rb | 11 +- .../custom/omniauth_callbacks_controller.rb | 2 - ...15061447_devise_token_auth_create_users.rb | 2 +- ...15061805_devise_token_auth_create_mangs.rb | 2 +- ...0829044006_add_operating_thetan_to_user.rb | 2 +- ...40916224624_add_favorite_color_to_mangs.rb | 2 +- ...203_devise_token_auth_create_evil_users.rb | 2 +- ...vise_token_auth_create_only_email_users.rb | 2 +- ..._token_auth_create_unregisterable_users.rb | 2 +- ...712_devise_token_auth_create_nice_users.rb | 2 +- ...e_token_auth_create_unconfirmable_users.rb | 2 +- ...1_devise_token_auth_create_scoped_users.rb | 2 +- ...devise_token_auth_create_lockable_users.rb | 2 +- test/dummy/db/schema.rb | 312 +++++----- test/models/user_test.rb | 7 +- test/test_helper.rb | 28 +- 40 files changed, 1190 insertions(+), 1168 deletions(-) diff --git a/Gemfile b/Gemfile index 21a0c30e6..65bf5e16f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source "https://rubygems.org" +source 'https://rubygems.org' # Declare your gem's dependencies in devise_token_auth.gemspec. # Bundler will treat runtime dependencies like base dependencies, and @@ -14,34 +14,35 @@ gemspec # gem 'debugger' group :development, :test do - gem 'thor' - gem "figaro", :git => 'https://github.com/laserlemon/figaro' - gem 'omniauth-github', :git => 'https://github.com/intridea/omniauth-github' - gem 'omniauth-facebook', :git => 'https://github.com/mkdynamic/omniauth-facebook' - gem 'omniauth-google-oauth2', :git => 'https://github.com/zquestz/omniauth-google-oauth2' - gem 'rack-cors', :require => 'rack/cors' gem 'attr_encrypted' + gem 'figaro', git: 'https://github.com/laserlemon/figaro' + gem 'omniauth-facebook', git: 'https://github.com/mkdynamic/omniauth-facebook' + gem 'omniauth-github', git: 'https://github.com/intridea/omniauth-github' + gem 'omniauth-google-oauth2', git: 'https://github.com/zquestz/omniauth-google-oauth2' + gem 'rack-cors', require: 'rack/cors' + gem 'thor' # testing - #gem 'spring' - gem "pry" - gem "pry-remote" + # gem 'spring' + gem 'faker' + gem 'fuzz_ball' + gem 'guard' + gem 'guard-minitest' gem 'minitest' - gem 'minitest-rails' gem 'minitest-focus' + gem 'minitest-rails' gem 'minitest-reporters' - gem 'guard' - gem 'guard-minitest' - gem 'faker' - gem 'fuzz_ball' gem 'mocha' + gem 'pry' + gem 'pry-remote' end # code coverage, metrics group :test do - gem "codeclimate-test-reporter", require: nil + gem 'codeclimate-test-reporter', require: nil + gem 'rails-controller-testing' end group :development do - gem "github_changelog_generator" -end \ No newline at end of file + gem 'github_changelog_generator' +end diff --git a/Gemfile.lock b/Gemfile.lock index d66b604a8..5d056de52 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,44 +40,47 @@ PATH GEM remote: https://rubygems.org/ specs: - actionmailer (4.2.8) - actionpack (= 4.2.8) - actionview (= 4.2.8) - activejob (= 4.2.8) + actioncable (5.1.4) + actionpack (= 5.1.4) + nio4r (~> 2.0) + websocket-driver (~> 0.6.1) + actionmailer (5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.8) - actionview (= 4.2.8) - activesupport (= 4.2.8) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.1.4) + actionview (= 5.1.4) + activesupport (= 5.1.4) + rack (~> 2.0) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.8) - activesupport (= 4.2.8) + actionview (5.1.4) + activesupport (= 5.1.4) builder (~> 3.1) - erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + erubi (~> 1.4) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.8) - activesupport (= 4.2.8) - globalid (>= 0.3.0) - activemodel (4.2.8) - activesupport (= 4.2.8) - builder (~> 3.1) - activerecord (4.2.8) - activemodel (= 4.2.8) - activesupport (= 4.2.8) - arel (~> 6.0) - activesupport (4.2.8) + activejob (5.1.4) + activesupport (= 5.1.4) + globalid (>= 0.3.6) + activemodel (5.1.4) + activesupport (= 5.1.4) + activerecord (5.1.4) + activemodel (= 5.1.4) + activesupport (= 5.1.4) + arel (~> 8.0) + activesupport (5.1.4) + concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) ansi (1.5.0) - arel (6.0.4) + arel (8.0.0) attr_encrypted (3.0.3) encryptor (~> 3.0.0) bcrypt (3.1.11) @@ -86,6 +89,7 @@ GEM simplecov (<= 0.13) coderay (1.1.1) concurrent-ruby (1.0.5) + crass (1.0.2) devise (4.3.0) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -94,7 +98,7 @@ GEM warden (~> 1.2.3) docile (1.1.5) encryptor (3.0.0) - erubis (2.7.0) + erubi (1.7.0) faker (1.7.3) i18n (~> 0.5) faraday (0.11.0) @@ -128,31 +132,32 @@ GEM guard-compat (~> 1.2) minitest (>= 3.0) hashie (3.5.5) - i18n (0.8.1) + i18n (0.8.6) json (2.1.0) jwt (1.5.6) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) - loofah (2.0.3) + loofah (2.1.1) + crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.0.12) - mail (2.6.5) + mail (2.6.6) mime-types (>= 1.16, < 4) metaclass (0.0.4) method_source (0.8.2) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) - minitest (5.10.2) + mini_portile2 (2.3.0) + minitest (5.10.3) minitest-focus (1.1.2) minitest (>= 4, < 6) - minitest-rails (2.2.1) - minitest (~> 5.7) - railties (~> 4.1) - minitest-reporters (1.1.14) + minitest-rails (3.0.0) + minitest (~> 5.8) + railties (~> 5.0) + minitest-reporters (1.1.18) ansi builder minitest (>= 5.0) @@ -164,8 +169,9 @@ GEM multipart-post (2.0.0) mysql2 (0.4.6) nenv (0.3.0) - nokogiri (1.7.2) - mini_portile2 (~> 2.1.0) + nio4r (2.1.0) + nokogiri (1.8.1) + mini_portile2 (~> 2.3.0) notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) @@ -193,37 +199,40 @@ GEM pry (~> 0.9) slop (~> 3.0) public_suffix (2.0.5) - rack (1.6.8) + rack (2.0.3) rack-cors (0.4.1) - rack-test (0.6.3) - rack (>= 1.0) - rails (4.2.8) - actionmailer (= 4.2.8) - actionpack (= 4.2.8) - actionview (= 4.2.8) - activejob (= 4.2.8) - activemodel (= 4.2.8) - activerecord (= 4.2.8) - activesupport (= 4.2.8) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.8) - sprockets-rails - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.8) - activesupport (>= 4.2.0.beta, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) + rack-test (0.7.0) + rack (>= 1.0, < 3) + rails (5.1.4) + actioncable (= 5.1.4) + actionmailer (= 5.1.4) + actionpack (= 5.1.4) + actionview (= 5.1.4) + activejob (= 5.1.4) + activemodel (= 5.1.4) + activerecord (= 5.1.4) + activesupport (= 5.1.4) + bundler (>= 1.3.0) + railties (= 5.1.4) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.2) + actionpack (~> 5.x, >= 5.0.1) + actionview (~> 5.x, >= 5.0.1) + activesupport (~> 5.x) + rails-dom-testing (2.0.3) + activesupport (>= 4.2.0) + nokogiri (>= 1.6) rails-html-sanitizer (1.0.3) loofah (~> 2.0) - railties (4.2.8) - actionpack (= 4.2.8) - activesupport (= 4.2.8) + railties (5.1.4) + actionpack (= 5.1.4) + activesupport (= 5.1.4) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.2.2) rake - rake (12.0.0) + rake (12.1.0) rb-fsevent (0.9.8) rb-inotify (0.9.8) ffi (>= 0.5.0) @@ -231,7 +240,7 @@ GEM actionpack (>= 4.2.0, < 5.3) railties (>= 4.2.0, < 5.3) retriable (2.1.0) - ruby-progressbar (1.8.1) + ruby-progressbar (1.9.0) ruby_dep (1.5.0) sawyer (0.8.1) addressable (>= 2.3.5, < 2.6) @@ -246,17 +255,20 @@ GEM sprockets (3.7.1) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.0) + sprockets-rails (3.2.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.13) - thor (0.19.4) + thor (0.20.0) thread_safe (0.3.6) tzinfo (1.2.3) thread_safe (~> 0.1) warden (1.2.7) rack (>= 1.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) PLATFORMS ruby @@ -284,8 +296,9 @@ DEPENDENCIES pry pry-remote rack-cors + rails-controller-testing sqlite3 (~> 1.3) thor BUNDLED WITH - 1.14.6 + 1.15.4 diff --git a/app/controllers/devise_token_auth/passwords_controller.rb b/app/controllers/devise_token_auth/passwords_controller.rb index 0031c523a..f108e006d 100644 --- a/app/controllers/devise_token_auth/passwords_controller.rb +++ b/app/controllers/devise_token_auth/passwords_controller.rb @@ -81,6 +81,7 @@ def edit @resource.allow_password_change = true; @resource.save! + yield @resource if block_given? redirect_to(@resource.build_auth_url(params[:redirect_url], { diff --git a/test/controllers/custom/custom_confirmations_controller_test.rb b/test/controllers/custom/custom_confirmations_controller_test.rb index 9fbde6043..ffe076588 100644 --- a/test/controllers/custom/custom_confirmations_controller_test.rb +++ b/test/controllers/custom/custom_confirmations_controller_test.rb @@ -1,26 +1,21 @@ require 'test_helper' class Custom::ConfirmationsControllerTest < ActionController::TestCase - describe Custom::ConfirmationsController do - before do @redirect_url = Faker::Internet.url @new_user = users(:unconfirmed_email_user) - @new_user.send_confirmation_instructions({ - redirect_url: @redirect_url - }) + @new_user.send_confirmation_instructions(redirect_url: @redirect_url) @mail = ActionMailer::Base.deliveries.last @token = @mail.body.match(/confirmation_token=([^&]*)&/)[1] @client_config = @mail.body.match(/config=([^&]*)&/)[1] - get :show, {confirmation_token: @token, redirect_url: @redirect_url} + get :show, + params: { confirmation_token: @token, redirect_url: @redirect_url } end - test "yield resource to block on show success" do - assert @controller.show_block_called?, "show failed to yield resource to provided block" + test 'yield resource to block on show success' do + assert @controller.show_block_called?, 'show failed to yield resource to provided block' end - end - end diff --git a/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb b/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb index a5b8fea95..dcd4b0ad6 100644 --- a/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +++ b/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb @@ -1,30 +1,29 @@ require 'test_helper' class Custom::OmniauthCallbacksControllerTest < ActionDispatch::IntegrationTest - describe Custom::OmniauthCallbacksController do - setup do OmniAuth.config.test_mode = true - OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({ - :provider => 'facebook', - :uid => '123545', - :info => { + OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new( + provider: 'facebook', + uid: '123545', + info: { name: 'swong', email: 'swongsong@yandex.ru' } - }) + ) end - test "yield resource to block on omniauth_success success" do - @redirect_url = "http://ng-token-auth.dev/" - get_via_redirect '/nice_user_auth/facebook', { - auth_origin_url: @redirect_url, - omniauth_window_type: 'newWindow' - } - assert @controller.omniauth_success_block_called?, "omniauth_success failed to yield resource to provided block" - end + test 'yield resource to block on omniauth_success success' do + @redirect_url = 'http://ng-token-auth.dev/' + get '/nice_user_auth/facebook', + params: { auth_origin_url: @redirect_url, + omniauth_window_type: 'newWindow' } - end + follow_all_redirects! + assert @controller.omniauth_success_block_called?, + 'omniauth_success failed to yield resource to provided block' + end + end end diff --git a/test/controllers/custom/custom_passwords_controller_test.rb b/test/controllers/custom/custom_passwords_controller_test.rb index 4da315769..25755574a 100644 --- a/test/controllers/custom/custom_passwords_controller_test.rb +++ b/test/controllers/custom/custom_passwords_controller_test.rb @@ -1,19 +1,16 @@ require 'test_helper' class Custom::PasswordsControllerTest < ActionController::TestCase - describe Custom::PasswordsController do - before do @resource = users(:confirmed_email_user) @redirect_url = 'http://ng-token-auth.dev' end - test "yield resource to block on create success" do - post :create, { - email: @resource.email, - redirect_url: @redirect_url - } + test 'yield resource to block on create success' do + post :create, + params: { email: @resource.email, + redirect_url: @redirect_url } @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -22,17 +19,18 @@ class Custom::PasswordsControllerTest < ActionController::TestCase @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1]) @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1] - 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 - test "yield resource to block on edit success" do + test 'yield resource to block on edit success' do @resource = users(:unconfirmed_email_user) @redirect_url = 'http://ng-token-auth.dev' - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url - } + post :create, + params: { email: @resource.email, + redirect_url: @redirect_url }, + xhr: true @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -41,41 +39,37 @@ class Custom::PasswordsControllerTest < ActionController::TestCase @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1]) @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1] - xhr :get, :edit, { - reset_password_token: @mail_reset_token, - redirect_url: @mail_redirect_url - } - + get :edit, + params: { reset_password_token: @mail_reset_token, + redirect_url: @mail_redirect_url }, + xhr: true @resource.reload - assert @controller.edit_block_called?, "edit failed to yield resource to provided block" + assert @controller.edit_block_called?, + 'edit failed to yield resource to provided block' end - test "yield resource to block on update success" do + test 'yield resource to block on update success' do @auth_headers = @resource.create_new_auth_token request.headers.merge!(@auth_headers) @new_password = Faker::Internet.password - put :update, { - password: @new_password, - password_confirmation: @new_password - } - assert @controller.update_block_called?, "update failed to yield resource to provided block" + put :update, + params: { password: @new_password, + password_confirmation: @new_password } + assert @controller.update_block_called?, 'update failed to yield resource to provided block' end - test "yield resource to block on update success with custom json" do + test 'yield resource to block on update success with custom json' do @auth_headers = @resource.create_new_auth_token request.headers.merge!(@auth_headers) @new_password = Faker::Internet.password - put :update, { - password: @new_password, - password_confirmation: @new_password - } + put :update, + params: { password: @new_password, + password_confirmation: @new_password } @data = JSON.parse(response.body) - assert @controller.update_block_called?, "update failed to yield resource to provided block" - assert_equal @data["custom"], "foo" + assert @controller.update_block_called?, 'update failed to yield resource to provided block' + assert_equal @data['custom'], 'foo' end - end - end diff --git a/test/controllers/custom/custom_registrations_controller_test.rb b/test/controllers/custom/custom_registrations_controller_test.rb index 0a1d411c8..cd25a49b3 100644 --- a/test/controllers/custom/custom_registrations_controller_test.rb +++ b/test/controllers/custom/custom_registrations_controller_test.rb @@ -1,14 +1,12 @@ require 'test_helper' class Custom::RegistrationsControllerTest < ActionDispatch::IntegrationTest - describe Custom::RegistrationsController do - setup do @create_params = { email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", + password: 'secret123', + password_confirmation: 'secret123', confirm_success_url: Faker::Internet.url, unpermitted_param: '(x_x)' } @@ -21,32 +19,36 @@ class Custom::RegistrationsControllerTest < ActionDispatch::IntegrationTest age_token(@existing_user, @client_id) end - test "yield resource to block on create success" do - post '/nice_user_auth', @create_params - assert @controller.create_block_called?, "create failed to yield resource to provided block" + test 'yield resource to block on create success' do + post '/nice_user_auth', params: @create_params + assert @controller.create_block_called?, + 'create failed to yield resource to provided block' end - test "yield resource to block on create success with custom json" do - post '/nice_user_auth', @create_params + test 'yield resource to block on create success with custom json' do + post '/nice_user_auth', params: @create_params @data = JSON.parse(response.body) - assert @controller.create_block_called?, "create failed to yield resource to provided block" - assert_equal @data["custom"], "foo" + assert @controller.create_block_called?, + 'create failed to yield resource to provided block' + assert_equal @data['custom'], 'foo' end - test "yield resource to block on update success" do - put '/nice_user_auth', { - nickname: "Ol' Sunshine-face", - }, @auth_headers - assert @controller.update_block_called?, "update failed to yield resource to provided block" + test 'yield resource to block on update success' do + put '/nice_user_auth', + params: { + nickname: "Ol' Sunshine-face" + }, + headers: @auth_headers + assert @controller.update_block_called?, + 'update failed to yield resource to provided block' end - test "yield resource to block on destroy success" do - delete '/nice_user_auth', @auth_headers - assert @controller.destroy_block_called?, "destroy failed to yield resource to provided block" + test 'yield resource to block on destroy success' do + delete '/nice_user_auth', headers: @auth_headers + assert @controller.destroy_block_called?, + 'destroy failed to yield resource to provided block' end - end - end diff --git a/test/controllers/custom/custom_sessions_controller_test.rb b/test/controllers/custom/custom_sessions_controller_test.rb index 2f9431e1b..11187c8dc 100644 --- a/test/controllers/custom/custom_sessions_controller_test.rb +++ b/test/controllers/custom/custom_sessions_controller_test.rb @@ -1,39 +1,37 @@ require 'test_helper' class Custom::SessionsControllerTest < ActionController::TestCase - describe Custom::SessionsController do - before do @existing_user = users(:confirmed_email_user) @existing_user.skip_confirmation! @existing_user.save! end - test "yield resource to block on create success" do - post :create, { - email: @existing_user.email, - password: 'secret123' - } - assert @controller.create_block_called?, "create failed to yield resource to provided block" + test 'yield resource to block on create success' do + post :create, + params: { + email: @existing_user.email, + password: 'secret123' + } + assert @controller.create_block_called?, + 'create failed to yield resource to provided block' end - test "yield resource to block on destroy success" do + test 'yield resource to block on destroy success' do @auth_headers = @existing_user.create_new_auth_token request.headers.merge!(@auth_headers) delete :destroy, format: :json - assert @controller.destroy_block_called?, "destroy failed to yield resource to provided block" + assert @controller.destroy_block_called?, + 'destroy failed to yield resource to provided block' end - test "render method override" do - post :create, { - email: @existing_user.email, - password: 'secret123' - } + test 'render method override' do + post :create, + params: { email: @existing_user.email, + password: 'secret123' } @data = JSON.parse(response.body) - assert_equal @data["custom"], "foo" + assert_equal @data['custom'], 'foo' end - end - end diff --git a/test/controllers/custom/custom_token_validations_controller_test.rb b/test/controllers/custom/custom_token_validations_controller_test.rb index a515d561f..7d6321ce0 100644 --- a/test/controllers/custom/custom_token_validations_controller_test.rb +++ b/test/controllers/custom/custom_token_validations_controller_test.rb @@ -1,9 +1,7 @@ require 'test_helper' class Custom::TokenValidationsControllerTest < ActionDispatch::IntegrationTest - describe Custom::TokenValidationsController do - before do @resource = nice_users(:confirmed_email_user) @resource.skip_confirmation! @@ -19,20 +17,24 @@ class Custom::TokenValidationsControllerTest < ActionDispatch::IntegrationTest age_token(@resource, @client_id) end - test "yield resource to block on validate_token success" do - get '/nice_user_auth/validate_token', {}, @auth_headers - assert @controller.validate_token_block_called?, "validate_token failed to yield resource to provided block" + test 'yield resource to block on validate_token success' do + get '/nice_user_auth/validate_token', + params: {}, + headers: @auth_headers + assert @controller.validate_token_block_called?, + 'validate_token failed to yield resource to provided block' end - test "yield resource to block on validate_token success with custom json" do - get '/nice_user_auth/validate_token', {}, @auth_headers + test 'yield resource to block on validate_token success with custom json' do + get '/nice_user_auth/validate_token', + params: {}, + headers: @auth_headers @data = JSON.parse(response.body) - assert @controller.validate_token_block_called?, "validate_token failed to yield resource to provided block" - assert_equal @data["custom"], "foo" + assert @controller.validate_token_block_called?, + 'validate_token failed to yield resource to provided block' + assert_equal @data['custom'], 'foo' end - end - end diff --git a/test/controllers/demo_group_controller_test.rb b/test/controllers/demo_group_controller_test.rb index 52ad7baab..cf334f125 100644 --- a/test/controllers/demo_group_controller_test.rb +++ b/test/controllers/demo_group_controller_test.rb @@ -8,7 +8,7 @@ class DemoGroupControllerTest < ActionDispatch::IntegrationTest describe DemoGroupController do - describe "Token access" do + describe 'Token access' do before do # user @resource = users(:confirmed_email_user) @@ -38,7 +38,9 @@ class DemoGroupControllerTest < ActionDispatch::IntegrationTest # ensure that request is not treated as batch request age_token(@resource, @resource_client_id) - get '/demo/members_only_group', {}, @resource_auth_headers + get '/demo/members_only_group', + params: {}, + headers: @resource_auth_headers @resp_token = response.headers['access-token'] @resp_client_id = response.headers['client'] @@ -86,7 +88,9 @@ class DemoGroupControllerTest < ActionDispatch::IntegrationTest # ensure that request is not treated as batch request age_token(@mang, @mang_client_id) - get '/demo/members_only_group', {}, @mang_auth_headers + get '/demo/members_only_group', + params: {}, + headers: @mang_auth_headers @resp_token = response.headers['access-token'] @resp_client_id = response.headers['client'] @@ -131,7 +135,9 @@ class DemoGroupControllerTest < ActionDispatch::IntegrationTest describe 'failed access' do before do - get '/demo/members_only_group', {}, @mang_auth_headers.merge({'access-token' => "bogus"}) + get '/demo/members_only_group', + params: {}, + headers: @mang_auth_headers.merge('access-token' => 'bogus') end it 'should not return any auth headers' do diff --git a/test/controllers/demo_mang_controller_test.rb b/test/controllers/demo_mang_controller_test.rb index 5ca637885..85b542fed 100644 --- a/test/controllers/demo_mang_controller_test.rb +++ b/test/controllers/demo_mang_controller_test.rb @@ -8,7 +8,7 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest describe DemoMangController do - describe "Token access" do + describe 'Token access' do before do @resource = mangs(:confirmed_email_user) @resource.skip_confirmation! @@ -26,7 +26,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest # ensure that request is not treated as batch request age_token(@resource, @client_id) - get '/demo/members_only_mang', {}, @auth_headers + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers @resp_token = response.headers['access-token'] @resp_client_id = response.headers['client'] @@ -78,14 +80,16 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest # ensure that request is not treated as batch request age_token(@resource, @client_id) - get '/demo/members_only_mang', {}, @auth_headers.merge({'access-token' => @resp_token}) + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers.merge('access-token' => @resp_token) end it 'should not treat this request as a batch request' do refute assigns(:is_batch_request) end - it "should allow a new request to be made using new token" do + it 'should allow a new request to be made using new token' do assert_equal 200, response.status end end @@ -93,7 +97,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest describe 'failed request' do before do - get '/demo/members_only_mang', {}, @auth_headers.merge({'access-token' => "bogus"}) + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers.merge('access-token' => 'bogus') end it 'should not return any auth headers' do @@ -111,7 +117,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest @resource.reload age_token(@resource, @client_id) - get '/demo/members_only_mang', {}, @auth_headers + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers @first_is_batch_request = assigns(:is_batch_request) @first_user = assigns(:resource).dup @@ -122,7 +130,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest age_token(@resource, @client_id) # use expired auth header - get '/demo/members_only_mang', {}, @auth_headers + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers @second_is_batch_request = assigns(:is_batch_request) @second_user = assigns(:resource).dup @@ -168,15 +178,19 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest describe 'success' do before do age_token(@resource, @client_id) - #request.headers.merge!(@auth_headers) + # request.headers.merge!(@auth_headers) - get '/demo/members_only_mang', {}, @auth_headers + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers @first_is_batch_request = assigns(:is_batch_request) @first_user = assigns(:resource) @first_access_token = response.headers['access-token'] - get '/demo/members_only_mang', {}, @auth_headers + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers @second_is_batch_request = assigns(:is_batch_request) @second_user = assigns(:resource) @@ -209,7 +223,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest @resource.reload age_token(@resource, @client_id) - get '/demo/members_only_mang', {}, @auth_headers + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers @first_is_batch_request = assigns(:is_batch_request) @first_user = assigns(:resource).dup @@ -220,7 +236,9 @@ class DemoMangControllerTest < ActionDispatch::IntegrationTest age_token(@resource, @client_id) # use expired auth header - get '/demo/members_only_mang', {}, @auth_headers + get '/demo/members_only_mang', + params: {}, + headers: @auth_headers @second_is_batch_request = assigns(:is_batch_request) @second_user = assigns(:resource) diff --git a/test/controllers/demo_user_controller_test.rb b/test/controllers/demo_user_controller_test.rb index 32aab27a4..83c6d4872 100644 --- a/test/controllers/demo_user_controller_test.rb +++ b/test/controllers/demo_user_controller_test.rb @@ -9,7 +9,7 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest include Warden::Test::Helpers describe DemoUserController do - describe "Token access" do + describe 'Token access' do before do @resource = users(:confirmed_email_user) @resource.skip_confirmation! @@ -27,7 +27,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest # ensure that request is not treated as batch request age_token(@resource, @client_id) - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @resp_token = response.headers['access-token'] @resp_client_id = response.headers['client'] @@ -79,14 +81,16 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest # ensure that request is not treated as batch request age_token(@resource, @client_id) - get '/demo/members_only', {}, @auth_headers.merge({'access-token' => @resp_token}) + get '/demo/members_only', + params: {}, + headers: @auth_headers.merge('access-token' => @resp_token) end it 'should not treat this request as a batch request' do refute assigns(:is_batch_request) end - it "should allow a new request to be made using new token" do + it 'should allow a new request to be made using new token' do assert_equal 200, response.status end end @@ -94,7 +98,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest describe 'failed request' do before do - get '/demo/members_only', {}, @auth_headers.merge({'access-token' => "bogus"}) + get '/demo/members_only', + params: {}, + headers: @auth_headers.merge('access-token' => 'bogus') end it 'should not return any auth headers' do @@ -112,7 +118,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest @resource.reload age_token(@resource, @client_id) - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @first_is_batch_request = assigns(:is_batch_request) @first_user = assigns(:resource).dup @@ -123,7 +131,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest age_token(@resource, @client_id) # use expired auth header - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @second_is_batch_request = assigns(:is_batch_request) @second_user = assigns(:resource).dup @@ -169,15 +179,19 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest describe 'success' do before do age_token(@resource, @client_id) - #request.headers.merge!(@auth_headers) + # request.headers.merge!(@auth_headers) - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @first_is_batch_request = assigns(:is_batch_request) @first_user = assigns(:resource) @first_access_token = response.headers['access-token'] - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @second_is_batch_request = assigns(:is_batch_request) @second_user = assigns(:resource) @@ -210,14 +224,18 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest @resource.reload age_token(@resource, @client_id) - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @first_is_batch_request = assigns(:is_batch_request) @first_user = assigns(:resource).dup @first_access_token = response.headers['access-token'] @first_response_status = response.status - get '/demo/members_only?unbatch=true', {}, @auth_headers + get '/demo/members_only?unbatch=true', + params: {}, + headers: @auth_headers @second_is_batch_request = assigns(:is_batch_request) @second_user = assigns(:resource) @@ -235,7 +253,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest @resource.reload age_token(@resource, @client_id) - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @first_is_batch_request = assigns(:is_batch_request) @first_user = assigns(:resource).dup @@ -246,7 +266,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest age_token(@resource, @client_id) # use expired auth header - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @second_is_batch_request = assigns(:is_batch_request) @second_user = assigns(:resource) @@ -299,12 +321,12 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest assert @resource.tokens.count > 1 # password changed from new device - @resource.update_attributes({ - password: 'newsecret123', - password_confirmation: 'newsecret123' - }) + @resource.update_attributes(password: 'newsecret123', + password_confirmation: 'newsecret123') - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers end after do @@ -320,14 +342,13 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest end describe 'another device should not be able to login' do - it 'should return forbidden status' do - get '/demo/members_only', {}, @old_auth_headers + get '/demo/members_only', + params: {}, + headers: @old_auth_headers assert 401, response.status end - end - end describe 'request including destroy of token' do @@ -336,7 +357,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest DeviseTokenAuth.change_headers_on_each_request = false age_token(@resource, @client_id) - get '/demo/members_only_remove_token', {}, @auth_headers + get '/demo/members_only_remove_token', + params: {}, + headers: @auth_headers end after do @@ -351,7 +374,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest describe 'when change_headers_on_each_request is set to true' do before do age_token(@resource, @client_id) - get '/demo/members_only_remove_token', {}, @auth_headers + get '/demo/members_only_remove_token', + params: {}, + headers: @auth_headers end it 'should not return auth-headers' do @@ -368,7 +393,9 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest client_id = auth_headers_modified['client'] age_token(@resource, client_id) - get '/demo/members_only', {}, auth_headers_modified + get '/demo/members_only', + params: {}, + headers: auth_headers_modified @resp_token = response.headers['new-access-token'] end @@ -383,7 +410,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest end describe 'enable_standard_devise_support' do - before do @resource = users(:confirmed_email_user) @auth_headers = @resource.create_new_auth_token @@ -395,10 +421,12 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest @resource = users(:second_confirmed_email_user) @resource.skip_confirmation! @resource.save! - login_as( @resource, :scope => :user) + login_as(@resource, scope: :user) # no auth headers sent, testing that warden authenticates correctly. - get '/demo/members_only', {}, nil + get '/demo/members_only', + params: {}, + headers: nil @resp_token = response.headers['access-token'] @resp_client_id = response.headers['client'] @@ -419,14 +447,13 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest refute_equal @resource, @controller.current_mang end - it 'should increase the number of tokens by a factor of 2 up to 11' do @first_token = @resource.tokens.keys.first DeviseTokenAuth.max_number_of_devices = 11 (1..10).each do |n| - assert_equal [11, 2*n].min, @resource.reload.tokens.keys.length - get '/demo/members_only', {}, nil + assert_equal [11, 2 * n].min, @resource.reload.tokens.keys.length + get '/demo/members_only', params: {}, headers: nil end assert_not_includes @resource.reload.tokens.keys, @first_token @@ -459,9 +486,11 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest @resource = users(:second_confirmed_email_user) @resource.skip_confirmation! @resource.save! - login_as( @resource, :scope => :user) + login_as(@resource, scope: :user) - get '/demo/members_only', {}, @auth_headers + get '/demo/members_only', + params: {}, + headers: @auth_headers @resp_token = response.headers['access-token'] @resp_client_id = response.headers['client'] @@ -511,7 +540,6 @@ class DemoUserControllerTest < ActionDispatch::IntegrationTest refute_equal @resp_uid, @auth_headers['uid'] end end - end end end diff --git a/test/controllers/devise_token_auth/confirmations_controller_test.rb b/test/controllers/devise_token_auth/confirmations_controller_test.rb index 1bb368a32..19765ca42 100644 --- a/test/controllers/devise_token_auth/confirmations_controller_test.rb +++ b/test/controllers/devise_token_auth/confirmations_controller_test.rb @@ -14,13 +14,11 @@ def token_and_client_config_from(body) [token, client_config] end - describe "Confirmation" do + describe 'Confirmation' do before do @redirect_url = Faker::Internet.url @new_user = users(:unconfirmed_email_user) - @new_user.send_confirmation_instructions({ - redirect_url: @redirect_url - }) + @new_user.send_confirmation_instructions(redirect_url: @redirect_url) mail = ActionMailer::Base.deliveries.last @token, @client_config = token_and_client_config_from(mail.body) end @@ -30,43 +28,46 @@ def token_and_client_config_from(body) end test "should include config name as 'default' in confirmation link" do - assert_equal "default", @client_config + assert_equal 'default', @client_config end - test "should store token hash in user" do + test 'should store token hash in user' do assert @new_user.confirmation_token end - describe "success" do + describe 'success' do before do - xhr :get, :show, {confirmation_token: @token, redirect_url: @redirect_url} + get :show, + params: { confirmation_token: @token, + redirect_url: @redirect_url }, + xhr: true @resource = assigns(:resource) end - test "user should now be confirmed" do + test 'user should now be confirmed' do assert @resource.confirmed? end - test "should redirect to success url" do + test 'should redirect to success url' do assert_redirected_to(/^#{@redirect_url}/) end - test "the sign_in_count should be 1" do + test 'the sign_in_count should be 1' do assert @resource.sign_in_count == 1 end - test "User shoud have the signed in info filled" do + test 'User shoud have the signed in info filled' do assert @resource.current_sign_in_at? end - test "User shoud have the Last checkin filled" do + test 'User shoud have the Last checkin filled' do assert @resource.last_sign_in_at? end end - describe "failure" do - test "user should not be confirmed" do - assert_raises(ActionController::RoutingError) { - xhr :get, :show, {confirmation_token: "bogus"} - } + describe 'failure' do + test 'user should not be confirmed' do + assert_raises(ActionController::RoutingError) do + get :show, params: { confirmation_token: 'bogus' } + end @resource = assigns(:resource) refute @resource.confirmed? end @@ -74,7 +75,7 @@ def token_and_client_config_from(body) end # test with non-standard user class - describe "Alternate user model" do + describe 'Alternate user model' do setup do @request.env['devise.mapping'] = Devise.mappings[:mang] end @@ -84,7 +85,7 @@ def token_and_client_config_from(body) end before do - @config_name = "altUser" + @config_name = 'altUser' @new_user = mangs(:unconfirmed_email_user) @new_user.send_confirmation_instructions(client_config: @config_name) @@ -97,22 +98,23 @@ def token_and_client_config_from(body) assert @token end - test "should include config name in confirmation link" do + test 'should include config name in confirmation link' do assert_equal @config_name, @client_config end - test "should store token hash in user" do + test 'should store token hash in user' do assert @new_user.confirmation_token end - describe "success" do + describe 'success' do before do @redirect_url = Faker::Internet.url - xhr :get, :show, {confirmation_token: @token, redirect_url: @redirect_url} + get :show, params: { confirmation_token: @token, + redirect_url: @redirect_url } @resource = assigns(:resource) end - test "user should now be confirmed" do + test 'user should now be confirmed' do assert @resource.confirmed? end end diff --git a/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb b/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb index 972c57874..c411c45ed 100644 --- a/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +++ b/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb @@ -13,29 +13,30 @@ class OmniauthTest < ActionDispatch::IntegrationTest end before do - @redirect_url = "http://ng-token-auth.dev/" + @redirect_url = 'http://ng-token-auth.dev/' end def get_parsed_data_json encoded_json_data = @response.body.match(/var data \= JSON.parse\(decodeURIComponent\(\'(.+)\'\)\)\;/)[1] - JSON.parse(URI::unescape(encoded_json_data)) + JSON.parse(URI.unescape(encoded_json_data)) end describe 'success callback' do setup do - OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({ - :provider => 'facebook', - :uid => '123545', - :info => { + OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new( + provider: 'facebook', + uid: '123545', + info: { name: 'chong', email: 'chongbong@aol.com' } - }) + ) end test 'request should pass correct redirect_url' do get_success - assert_equal @redirect_url, controller.send(:omniauth_params)['auth_origin_url'] + assert_equal @redirect_url, + controller.send(:omniauth_params)['auth_origin_url'] end test 'user should have been created' do @@ -50,12 +51,14 @@ def get_parsed_data_json test 'user should be assigned token' do get_success + client_id = controller.auth_params[:client_id] token = controller.auth_params[:auth_token] expiry = controller.auth_params[:expiry] # the expiry should have been set - assert_equal expiry, @resource.tokens[client_id][:expiry] + assert_equal expiry, @resource.tokens[client_id]['expiry'] + # the token sent down to the client should now be valid assert @resource.valid_token?(token, client_id) end @@ -73,7 +76,8 @@ def get_parsed_data_json test 'should be redirected via valid url' do get_success - assert_equal 'http://www.example.com/auth/facebook/callback', request.original_url + assert_equal 'http://www.example.com/auth/facebook/callback', + request.original_url end describe 'with default user model' do @@ -91,17 +95,23 @@ def get_parsed_data_json describe 'with alternate user model' do before do - get_via_redirect '/mangs/facebook', { - auth_origin_url: @redirect_url, - omniauth_window_type: 'newWindow' - } + get '/mangs/facebook', + params: { + auth_origin_url: @redirect_url, + omniauth_window_type: 'newWindow' + } + + follow_all_redirects! + assert_equal 200, response.status @resource = assigns(:resource) end + test 'request should determine the correct resource_class' do assert_equal 'Mang', controller.send(:omniauth_params)['resource_class'] end - test 'user should be of the correct class' do + + test 'user should be of the correct class' do assert_equal Mang, @resource.class end end @@ -109,13 +119,14 @@ def get_parsed_data_json describe 'pass additional params' do before do @fav_color = 'alizarin crimson' - @unpermitted_param = "M. Bison" - get_via_redirect '/auth/facebook', { - auth_origin_url: @redirect_url, - favorite_color: @fav_color, - name: @unpermitted_param, - omniauth_window_type: 'newWindow' - } + @unpermitted_param = 'M. Bison' + get '/auth/facebook', + params: { auth_origin_url: @redirect_url, + favorite_color: @fav_color, + name: @unpermitted_param, + omniauth_window_type: 'newWindow' } + + follow_all_redirects! @resource = assigns(:resource) end @@ -133,7 +144,7 @@ def get_parsed_data_json end end - describe "oauth registration attr" do + describe 'oauth registration attr' do after do User.any_instance.unstub(:new_record?) end @@ -144,11 +155,11 @@ def get_parsed_data_json end test 'response contains oauth_registration attr' do + get '/auth/facebook', + params: { auth_origin_url: @redirect_url, + omniauth_window_type: 'newWindow' } - get_via_redirect '/auth/facebook', { - auth_origin_url: @redirect_url, - omniauth_window_type: 'newWindow' - } + follow_all_redirects! assert_equal true, controller.auth_params[:oauth_registration] end @@ -160,25 +171,24 @@ def get_parsed_data_json end test 'response does not contain oauth_registration attr' do + get '/auth/facebook', + params: { auth_origin_url: @redirect_url, + omniauth_window_type: 'newWindow' } - get_via_redirect '/auth/facebook', { - auth_origin_url: @redirect_url, - omniauth_window_type: 'newWindow' - } + follow_all_redirects! assert_equal false, controller.auth_params.key?(:oauth_registration) end - end - end describe 'using namespaces' do before do - get_via_redirect '/api/v1/auth/facebook', { - auth_origin_url: @redirect_url, - omniauth_window_type: 'newWindow' - } + get '/api/v1/auth/facebook', + params: { auth_origin_url: @redirect_url, + omniauth_window_type: 'newWindow' } + + follow_all_redirects! @resource = assigns(:resource) end @@ -201,7 +211,6 @@ def get_parsed_data_json get_success(omniauth_window_type: 'inAppBrowser') assert_expected_data_in_new_window end - end describe 'with omniauth_window_type=newWindow' do @@ -215,15 +224,17 @@ def assert_expected_data_in_new_window data = get_parsed_data_json expected_data = @resource.as_json.merge(controller.auth_params.as_json) expected_data = ActiveSupport::JSON.decode(expected_data.to_json) - assert_equal(expected_data.merge("message" => "deliverCredentials"), data) + assert_equal(expected_data.merge('message' => 'deliverCredentials'), data) end describe 'with omniauth_window_type=sameWindow' do test 'redirects to auth_origin_url with all expected query params' do - get_via_redirect '/auth/facebook', { - auth_origin_url: '/auth_origin', - omniauth_window_type: 'sameWindow' - } + get '/auth/facebook', + params: { auth_origin_url: '/auth_origin', + omniauth_window_type: 'sameWindow' } + + follow_all_redirects! + assert_equal 200, response.status # We have been forwarded to a url with all the expected @@ -232,21 +243,26 @@ def assert_expected_data_in_new_window # Assert that a uid was passed along. We have to assume # that the rest of the values were as well, as we don't # have access to @resource in this test anymore - assert(uid = controller.params['uid'], "No uid found") + assert(controller.params['uid'], 'No uid found') # check that all the auth stuff is there - [:auth_token, :client_id, :uid, :expiry, :config].each do |key| + %i[auth_token client_id uid expiry config].each do |key| assert(controller.params.key?(key), "No value for #{key.inspect}") end end end def get_success(params = {}) - get_via_redirect '/auth/facebook', { - auth_origin_url: @redirect_url, - omniauth_window_type: 'newWindow' - }.merge(params) + get '/auth/facebook', + params: { + auth_origin_url: @redirect_url, + omniauth_window_type: 'newWindow' + }.merge(params) + + follow_all_redirects! + assert_equal 200, response.status + @resource = assigns(:resource) end end @@ -254,37 +270,40 @@ def get_success(params = {}) describe 'failure callback' do setup do OmniAuth.config.mock_auth[:facebook] = :invalid_credentials - OmniAuth.config.on_failure = Proc.new { |env| + OmniAuth.config.on_failure = proc { |env| OmniAuth::FailureEndpoint.new(env).redirect_to_failure } end test 'renders expected data' do - get_via_redirect '/auth/facebook', { - auth_origin_url: @redirect_url, - omniauth_window_type: 'newWindow' - } + get '/auth/facebook', + params: { auth_origin_url: @redirect_url, + omniauth_window_type: 'newWindow' } + + follow_all_redirects! + assert_equal 200, response.status data = get_parsed_data_json - assert_equal({"error"=>"invalid_credentials", "message"=>"authFailure"}, data) + assert_equal({ 'error' => 'invalid_credentials', 'message' => 'authFailure' }, data) end test 'renders something with no auth_origin_url' do - get_via_redirect '/auth/facebook' + get '/auth/facebook' + follow_all_redirects! assert_equal 200, response.status - assert_select "body", "invalid_credentials" + assert_select 'body', 'invalid_credentials' end end describe 'User with only :database_authenticatable and :registerable included' do test 'OnlyEmailUser should not be able to use OAuth' do - assert_raises(ActionController::RoutingError) { - get_via_redirect '/only_email_auth/facebook', { - auth_origin_url: @redirect_url - } - } + assert_raises(ActionController::RoutingError) do + get '/only_email_auth/facebook', + params: { auth_origin_url: @redirect_url } + follow_all_redirects! + end end end @@ -309,9 +328,11 @@ def get_success(params = {}) end test 'request using non-whitelisted redirect fail' do - get_via_redirect '/auth/facebook', - auth_origin_url: @bad_redirect_url, - omniauth_window_type: 'newWindow' + get '/auth/facebook', + params: { auth_origin_url: @bad_redirect_url, + omniauth_window_type: 'newWindow' } + + follow_all_redirects! data = get_parsed_data_json assert_equal "Redirect to '#{@bad_redirect_url}' not allowed.", @@ -319,9 +340,13 @@ def get_success(params = {}) end test 'request to whitelisted redirect should succeed' do - get_via_redirect '/auth/facebook', - auth_origin_url: @good_redirect_url, - omniauth_window_type: 'newWindow' + get '/auth/facebook', + params: { + auth_origin_url: @good_redirect_url, + omniauth_window_type: 'newWindow' + } + + follow_all_redirects! data = get_parsed_data_json assert_equal @user_email, data['email'] @@ -329,13 +354,14 @@ def get_success(params = {}) test 'should support wildcards' do DeviseTokenAuth.redirect_whitelist = ["#{@good_redirect_url[0..8]}*"] - get_via_redirect '/auth/facebook', - auth_origin_url: @good_redirect_url, - omniauth_window_type: 'newWindow' + get '/auth/facebook', + params: { auth_origin_url: @good_redirect_url, + omniauth_window_type: 'newWindow' } + + follow_all_redirects! data = get_parsed_data_json assert_equal @user_email, data['email'] end - end end diff --git a/test/controllers/devise_token_auth/passwords_controller_test.rb b/test/controllers/devise_token_auth/passwords_controller_test.rb index bc42e59ee..bb80ce665 100644 --- a/test/controllers/devise_token_auth/passwords_controller_test.rb +++ b/test/controllers/devise_token_auth/passwords_controller_test.rb @@ -8,7 +8,7 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase describe DeviseTokenAuth::PasswordsController do - describe "Password reset" do + describe 'Password reset' do before do @resource = users(:confirmed_email_user) @redirect_url = 'http://ng-token-auth.dev' @@ -19,18 +19,19 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @auth_headers = @resource.create_new_auth_token @new_password = Faker::Internet.password - xhr :post, :create, { - redirect_url: @redirect_url - } + post :create, + params: { redirect_url: @redirect_url } @data = JSON.parse(response.body) end test 'response should fail' do assert_equal 401, response.status end + test 'error message should be returned' do - assert @data["errors"] - assert_equal @data["errors"], [I18n.t("devise_token_auth.passwords.missing_email")] + assert @data['errors'] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.passwords.missing_email')] end end @@ -39,62 +40,62 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @auth_headers = @resource.create_new_auth_token @new_password = Faker::Internet.password - xhr :post, :create, { - email: 'chester@cheet.ah', - } + post :create, + params: { email: 'chester@cheet.ah' } @data = JSON.parse(response.body) end test 'response should fail' do assert_equal 401, response.status end + test 'error message should be returned' do - assert @data["errors"] - assert_equal @data["errors"], [I18n.t("devise_token_auth.passwords.missing_redirect_url")] + assert @data['errors'] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.passwords.missing_redirect_url')] end end describe 'request password reset' do describe 'unknown user should return 404' do before do - xhr :post, :create, { - email: 'chester@cheet.ah', - redirect_url: @redirect_url - } + post :create, + params: { email: 'chester@cheet.ah', + redirect_url: @redirect_url } @data = JSON.parse(response.body) end + test 'unknown user should return 404' do assert_equal 404, response.status end test 'errors should be returned' do - assert @data["errors"] - assert_equal @data["errors"], [I18n.t("devise_token_auth.passwords.user_not_found", email: 'chester@cheet.ah')] + assert @data['errors'] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.passwords.user_not_found', + email: 'chester@cheet.ah')] end end describe 'successfully requested password reset' do before do - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url - } + post :create, + params: { email: @resource.email, + redirect_url: @redirect_url } @data = JSON.parse(response.body) end test 'response should not contain extra data' do - assert_nil @data["data"] + assert_nil @data['data'] end end - describe 'case-sensitive email' do before do - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url - } + post :create, + params: { email: @resource.email, + redirect_url: @redirect_url } @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -110,7 +111,7 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase end test 'response should contains message' do - assert_equal @data["message"], I18n.t("devise_token_auth.passwords.sended", email: @resource.email) + assert_equal @data['message'], I18n.t('devise_token_auth.passwords.sended', email: @resource.email) end test 'action should send an email' do @@ -130,41 +131,37 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase end test 'the email body should contain a link with reset token as a query param' do - user = User.reset_password_by_token({ - reset_password_token: @mail_reset_token - }) + user = User.reset_password_by_token(reset_password_token: @mail_reset_token) assert_equal user.id, @resource.id end describe 'password reset link failure' do test 'response should return 404' do - assert_raises(ActionController::RoutingError) { - xhr :get, :edit, { - reset_password_token: "bogus", - redirect_url: @mail_redirect_url - } - } + assert_raises(ActionController::RoutingError) do + get :edit, + params: { reset_password_token: 'bogus', + redirect_url: @mail_redirect_url } + end end end describe 'password reset link success' do before do - xhr :get, :edit, { - reset_password_token: @mail_reset_token, - redirect_url: @mail_redirect_url - } + get :edit, + params: { reset_password_token: @mail_reset_token, + redirect_url: @mail_redirect_url } @resource.reload raw_qs = response.location.split('?')[1] @qs = Rack::Utils.parse_nested_query(raw_qs) - @client_id = @qs["client_id"] - @expiry = @qs["expiry"] - @reset_password = @qs["reset_password"] - @token = @qs["token"] - @uid = @qs["uid"] + @client_id = @qs['client_id'] + @expiry = @qs['expiry'] + @reset_password = @qs['reset_password'] + @token = @qs['token'] + @uid = @qs['uid'] end test 'respones should have success redirect status' do @@ -183,7 +180,6 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase assert @resource.valid_token?(@token, @client_id) end end - end describe 'case-insensitive email' do @@ -197,13 +193,13 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase test 'response should return success status if configured' do @resource_class.case_insensitive_keys = [:email] - xhr :post, :create, @request_params + post :create, params: @request_params assert_equal 200, response.status end test 'response should return failure status if not configured' do @resource_class.case_insensitive_keys = [] - xhr :post, :create, @request_params + post :create, params: @request_params assert_equal 404, response.status end end @@ -216,10 +212,9 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase DeviseTokenAuth.default_password_reset_url = @redirect_url - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url - } + post :create, + params: { email: @resource.email, + redirect_url: @redirect_url } @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -256,36 +251,35 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase DeviseTokenAuth.redirect_whitelist = nil end - test "request to whitelisted redirect should be successful" do - xhr :post, :create, { - email: @resource.email, - redirect_url: @good_redirect_url - } + test 'request to whitelisted redirect should be successful' do + post :create, + params: { email: @resource.email, + redirect_url: @good_redirect_url } assert_equal 200, response.status end - test "request to non-whitelisted redirect should fail" do - xhr :post, :create, { - email: @resource.email, - redirect_url: @bad_redirect_url - } + test 'request to non-whitelisted redirect should fail' do + post :create, + params: { email: @resource.email, + redirect_url: @bad_redirect_url } assert_equal 422, response.status end - test "request to non-whitelisted redirect should return error message" do - xhr :post, :create, { - email: @resource.email, - redirect_url: @bad_redirect_url - } + test 'request to non-whitelisted redirect should return error message' do + post :create, + params: { email: @resource.email, + redirect_url: @bad_redirect_url } @data = JSON.parse(response.body) - assert @data["errors"] - assert_equal @data["errors"], [I18n.t("devise_token_auth.passwords.not_allowed_redirect_url", redirect_url: @bad_redirect_url)] + assert @data['errors'] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.passwords.not_allowed_redirect_url', + redirect_url: @bad_redirect_url)] end end - describe "change password with current password required" do + describe 'change password with current password required' do before do DeviseTokenAuth.check_current_password_before_update = :password end @@ -301,56 +295,51 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @new_password = Faker::Internet.password @resource.update password: 'secret123', password_confirmation: 'secret123' - xhr :put, :update, { - password: @new_password, - password_confirmation: @new_password, - current_password: 'secret123' - } + put :update, + params: { password: @new_password, + password_confirmation: @new_password, + current_password: 'secret123' } @data = JSON.parse(response.body) @resource.reload end - test "request should be successful" do + test 'request should be successful' do assert_equal 200, response.status end end describe 'success with after password reset' do before do - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url - } + # create a new password reset request + post :create, params: { email: @resource.email, + redirect_url: @redirect_url } @mail = ActionMailer::Base.deliveries.last @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1]) @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1] - xhr :get, :edit, { - reset_password_token: @mail_reset_token, - redirect_url: @mail_redirect_url - } + # confirm via password reset email link + get :edit, params: { reset_password_token: @mail_reset_token, + redirect_url: @mail_redirect_url } @auth_headers = @resource.create_new_auth_token request.headers.merge!(@auth_headers) @new_password = Faker::Internet.password - xhr :put, :update, { - password: @new_password, - password_confirmation: @new_password - } + put :update, params: { password: @new_password, + password_confirmation: @new_password } @data = JSON.parse(response.body) @allow_password_change = @resource.allow_password_change @resource.reload end - test "request should be successful" do + test 'request should be successful' do assert_equal 200, response.status end - test "sets allow_password_change false" do + test 'sets allow_password_change false' do assert_equal false, @allow_password_change end end @@ -361,11 +350,9 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase request.headers.merge!(@auth_headers) @new_password = Faker::Internet.password - xhr :put, :update, { - password: @new_password, - password_confirmation: @new_password, - current_password: 'not_very_secret321' - } + put :update, params: { password: @new_password, + password_confirmation: @new_password, + current_password: 'not_very_secret321' } end test 'response should fail unauthorized' do @@ -374,32 +361,31 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase end end - describe "change password" do + describe 'change password' do describe 'success' do before do @auth_headers = @resource.create_new_auth_token request.headers.merge!(@auth_headers) @new_password = Faker::Internet.password - xhr :put, :update, { - password: @new_password, - password_confirmation: @new_password - } + put :update, params: { password: @new_password, + password_confirmation: @new_password } @data = JSON.parse(response.body) @resource.reload end - test "request should be successful" do + test 'request should be successful' do assert_equal 200, response.status end - test "request should return success message" do - assert @data["message"] - assert_equal @data["message"], I18n.t("devise_token_auth.passwords.successfully_updated") + test 'request should return success message' do + assert @data['message'] + assert_equal @data['message'], + I18n.t('devise_token_auth.passwords.successfully_updated') end - test "new password should authenticate user" do + test 'new password should authenticate user' do assert @resource.valid_password?(@new_password) end end @@ -410,10 +396,8 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase request.headers.merge!(@auth_headers) @new_password = Faker::Internet.password - xhr :put, :update, { - password: 'chong', - password_confirmation: 'bong' - } + put :update, params: { password: 'chong', + password_confirmation: 'bong' } end test 'response should fail' do @@ -426,10 +410,8 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @auth_headers = @resource.create_new_auth_token @new_password = Faker::Internet.password - xhr :put, :update, { - password: @new_password, - password_confirmation: @new_password - } + put :update, params: { password: @new_password, + password_confirmation: @new_password } end test 'response should fail' do @@ -439,7 +421,7 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase end end - describe "Alternate user class" do + describe 'Alternate user class' do setup do @request.env['devise.mapping'] = Devise.mappings[:mang] end @@ -452,10 +434,8 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @resource = mangs(:confirmed_email_user) @redirect_url = 'http://ng-token-auth.dev' - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url - } + post :create, params: { email: @resource.email, + redirect_url: @redirect_url } @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -470,9 +450,7 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase end test 'the email body should contain a link with reset token as a query param' do - user = Mang.reset_password_by_token({ - reset_password_token: @mail_reset_token - }) + user = Mang.reset_password_by_token(reset_password_token: @mail_reset_token) assert_equal user.id, @resource.id end @@ -483,10 +461,8 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @resource = users(:unconfirmed_email_user) @redirect_url = 'http://ng-token-auth.dev' - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url - } + post :create, params: { email: @resource.email, + redirect_url: @redirect_url } @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -495,10 +471,8 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1]) @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1] - xhr :get, :edit, { - reset_password_token: @mail_reset_token, - redirect_url: @mail_redirect_url - } + get :edit, params: { reset_password_token: @mail_reset_token, + redirect_url: @mail_redirect_url } @resource.reload end @@ -517,10 +491,8 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @resource = unconfirmable_users(:user) @redirect_url = 'http://ng-token-auth.dev' - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url - } + post :create, params: { email: @resource.email, + redirect_url: @redirect_url } @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -529,10 +501,8 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1]) @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1] - xhr :get, :edit, { - reset_password_token: @mail_reset_token, - redirect_url: @mail_redirect_url - } + get :edit, params: { reset_password_token: @mail_reset_token, + redirect_url: @mail_redirect_url } @resource.reload end @@ -540,15 +510,13 @@ class DeviseTokenAuth::PasswordsControllerTest < ActionController::TestCase describe 'alternate user type' do before do - @resource = users(:confirmed_email_user) + @resource = users(:confirmed_email_user) @redirect_url = 'http://ng-token-auth.dev' - @config_name = "altUser" + @config_name = 'altUser' - xhr :post, :create, { - email: @resource.email, - redirect_url: @redirect_url, - config_name: @config_name - } + post :create, params: { email: @resource.email, + redirect_url: @redirect_url, + config_name: @config_name } @mail = ActionMailer::Base.deliveries.last @resource.reload diff --git a/test/controllers/devise_token_auth/registrations_controller_test.rb b/test/controllers/devise_token_auth/registrations_controller_test.rb index e0df8bc9a..b89cd7e38 100644 --- a/test/controllers/devise_token_auth/registrations_controller_test.rb +++ b/test/controllers/devise_token_auth/registrations_controller_test.rb @@ -6,13 +6,12 @@ # was the correct object stored in the response? # was the appropriate message delivered in the json payload? - class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::IntegrationTest describe DeviseTokenAuth::RegistrationsController do describe 'Validate non-empty body' do before do # need to post empty data - post '/auth', {} + post '/auth', params: {} @resource = assigns(:resource) @data = JSON.parse(response.body) @@ -35,48 +34,49 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration end end - describe "Successful registration" do + describe 'Successful registration' do before do @mails_sent = ActionMailer::Base.deliveries.count - post '/auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url, - unpermitted_param: '(x_x)' - } + post '/auth', + params: { + email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url, + unpermitted_param: '(x_x)' + } @resource = assigns(:resource) @data = JSON.parse(response.body) @mail = ActionMailer::Base.deliveries.last end - test "request should be successful" do + test 'request should be successful' do assert_equal 200, response.status end - test "user should have been created" do + test 'user should have been created' do assert @resource.id end - test "user should not be confirmed" do + test 'user should not be confirmed' do assert_nil @resource.confirmed_at end - test "new user data should be returned as json" do + test 'new user data should be returned as json' do assert @data['data']['email'] end - test "new user should receive confirmation email" do + test 'new user should receive confirmation email' do assert_equal @resource.email, @mail['to'].to_s end - test "new user password should not be returned" do + test 'new user password should not be returned' do assert_nil @data['data']['password'] end - test "only one email was sent" do + test 'only one email was sent' do assert_equal @mails_sent + 1, ActionMailer::Base.deliveries.count end end @@ -85,12 +85,11 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration test 'can use + sign in email addresses' do @plus_email = 'ak+testing@gmail.com' - post '/auth', { - email: @plus_email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url - } + post '/auth', + params: { email: @plus_email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url } @resource = assigns(:resource) @@ -109,58 +108,55 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration DeviseTokenAuth.redirect_whitelist = nil end - test "request to whitelisted redirect should be successful" do - post '/auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: @good_redirect_url, - unpermitted_param: '(x_x)' - } + test 'request to whitelisted redirect should be successful' do + post '/auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: @good_redirect_url, + unpermitted_param: '(x_x)' } assert_equal 200, response.status end - test "request to non-whitelisted redirect should fail" do - post '/auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: @bad_redirect_url, - unpermitted_param: '(x_x)' - } + test 'request to non-whitelisted redirect should fail' do + post '/auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: @bad_redirect_url, + unpermitted_param: '(x_x)' } @data = JSON.parse(response.body) assert_equal 422, response.status - assert @data["errors"] - assert_equal @data["errors"], [I18n.t("devise_token_auth.registrations.redirect_url_not_allowed", redirect_url: @bad_redirect_url)] + assert @data['errors'] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.registrations.redirect_url_not_allowed', + redirect_url: @bad_redirect_url)] end end describe 'failure if not redirecturl' do - - test "request should fail if not redirect_url" do - post '/auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - unpermitted_param: '(x_x)' - } + test 'request should fail if not redirect_url' do + post '/auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + unpermitted_param: '(x_x)' } assert_equal 422, response.status end - test "request to non-whitelisted redirect should fail" do - post '/auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - unpermitted_param: '(x_x)' - } + test 'request to non-whitelisted redirect should fail' do + post '/auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + unpermitted_param: '(x_x)' } @data = JSON.parse(response.body) - assert @data["errors"] - assert_equal @data["errors"], [I18n.t("devise_token_auth.registrations.missing_confirm_success_url")] + assert @data['errors'] + assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.missing_confirm_success_url')] end end @@ -171,12 +167,12 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration DeviseTokenAuth.default_confirm_success_url = @redirect_url - post '/auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - unpermitted_param: '(x_x)' - } + assert_difference 'ActionMailer::Base.deliveries.size', 1 do + post '/auth', params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + unpermitted_param: '(x_x)' } + end @resource = assigns(:resource) @data = JSON.parse(response.body) @@ -188,14 +184,10 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration DeviseTokenAuth.default_confirm_success_url = nil end - test "request should be successful" do + test 'request should be successful' do assert_equal 200, response.status end - test "the email was sent" do - assert_equal @mails_sent + 1, ActionMailer::Base.deliveries.count - end - test 'email contains the default redirect url' do assert_equal @redirect_url, @sent_redirect_url end @@ -205,10 +197,10 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration before do @mails_sent = ActionMailer::Base.deliveries.count - post '/api/v1/auth', { + post '/api/v1/auth', params: { email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", + password: 'secret123', + password_confirmation: 'secret123', confirm_success_url: Faker::Internet.url, unpermitted_param: '(x_x)' } @@ -218,58 +210,55 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration @mail = ActionMailer::Base.deliveries.last end - test "request should be successful" do + test 'request should be successful' do assert_equal 200, response.status end - test "user should have been created" do + test 'user should have been created' do assert @resource.id end end - describe "case-insensitive email" do - + describe 'case-insensitive email' do before do @resource_class = User @request_params = { - email: "AlternatingCase@example.com", - password: "secret123", - password_confirmation: "secret123", + email: 'AlternatingCase@example.com', + password: 'secret123', + password_confirmation: 'secret123', confirm_success_url: Faker::Internet.url } end - test "success should downcase uid if configured" do + test 'success should downcase uid if configured' do @resource_class.case_insensitive_keys = [:email] - post '/auth', @request_params + post '/auth', params: @request_params assert_equal 200, response.status @data = JSON.parse(response.body) - assert_equal "alternatingcase@example.com", @data['data']['uid'] + assert_equal 'alternatingcase@example.com', @data['data']['uid'] end - test "request should not downcase uid if not configured" do + test 'request should not downcase uid if not configured' do @resource_class.case_insensitive_keys = [] - post '/auth', @request_params + post '/auth', params: @request_params assert_equal 200, response.status @data = JSON.parse(response.body) - assert_equal "AlternatingCase@example.com", @data['data']['uid'] + assert_equal 'AlternatingCase@example.com', @data['data']['uid'] end - end - describe "Adding extra params" do + describe 'Adding extra params' do before do @redirect_url = Faker::Internet.url @operating_thetan = 2 - post '/auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: @redirect_url, - favorite_color: @fav_color, - operating_thetan: @operating_thetan - } + post '/auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: @redirect_url, + favorite_color: @fav_color, + operating_thetan: @operating_thetan } @resource = assigns(:resource) @data = JSON.parse(response.body) @@ -284,7 +273,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration assert_equal @redirect_url, @mail_redirect_url end - test "additional sign_up params should be considered" do + test 'additional sign_up params should be considered' do assert_equal @operating_thetan, @resource.operating_thetan end @@ -293,130 +282,125 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration end test "client config name falls back to 'default'" do - assert_equal "default", @mail_config_name + assert_equal 'default', @mail_config_name end end describe 'bad email' do before do - post '/auth', { - email: "false_email@", - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url - } + post '/auth', + params: { email: 'false_email@', + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should not be successful" do + test 'request should not be successful' do assert_equal 422, response.status end - test "user should not have been created" do + test 'user should not have been created' do assert_nil @resource.id end - test "error should be returned in the response" do + test 'error should be returned in the response' do assert @data['errors'].length end - test "full_messages should be included in error hash" do + test 'full_messages should be included in error hash' do assert @data['errors']['full_messages'].length end end describe 'missing email' do before do - post '/auth', { - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url - } + post '/auth', + params: { password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should not be successful" do + test 'request should not be successful' do assert_equal 422, response.status end - test "user should not have been created" do + test 'user should not have been created' do assert_nil @resource.id end - test "error should be returned in the response" do + test 'error should be returned in the response' do assert @data['errors'].length end - test "full_messages should be included in error hash" do + test 'full_messages should be included in error hash' do assert @data['errors']['full_messages'].length end end - describe "Mismatched passwords" do + describe 'Mismatched passwords' do before do - post '/auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "bogus", - confirm_success_url: Faker::Internet.url - } + post '/auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'bogus', + confirm_success_url: Faker::Internet.url } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should not be successful" do + test 'request should not be successful' do assert_equal 422, response.status end - test "user should have been created" do + test 'user should have been created' do assert_nil @resource.id end - test "error should be returned in the response" do + test 'error should be returned in the response' do assert @data['errors'].length end - test "full_messages should be included in error hash" do + test 'full_messages should be included in error hash' do assert @data['errors']['full_messages'].length end end - describe "Existing users" do + describe 'Existing users' do before do @existing_user = users(:confirmed_email_user) - post "/auth", { - email: @existing_user.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url - } + post '/auth', + params: { email: @existing_user.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should not be successful" do + test 'request should not be successful' do assert_equal 422, response.status end - test "user should have been created" do + test 'user should have been created' do assert_nil @resource.id end - test "error should be returned in the response" do + test 'error should be returned in the response' do assert @data['errors'].length end end - - describe "Destroy user account" do - describe "success" do + describe 'Destroy user account' do + describe 'success' do before do @existing_user = users(:confirmed_email_user) @auth_headers = @existing_user.create_new_auth_token @@ -425,7 +409,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration # ensure request is not treated as batch request age_token(@existing_user, @client_id) - delete "/auth", {}, @auth_headers + delete '/auth', params: {}, headers: @auth_headers @data = JSON.parse(response.body) end @@ -434,18 +418,20 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration assert_equal 200, response.status end - test "message should be returned" do - assert @data["message"] - assert_equal @data["message"], I18n.t("devise_token_auth.registrations.account_with_uid_destroyed", uid: @existing_user.uid) + test 'message should be returned' do + assert @data['message'] + assert_equal @data['message'], + I18n.t('devise_token_auth.registrations.account_with_uid_destroyed', + uid: @existing_user.uid) end - test "existing user should be deleted" do + test 'existing user should be deleted' do refute User.where(id: @existing_user.id).first end end describe 'failure: no auth headers' do before do - delete "/auth" + delete '/auth' @data = JSON.parse(response.body) end @@ -455,14 +441,13 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration test 'error should be returned' do assert @data['errors'].length - assert_equal @data['errors'], [I18n.t("devise_token_auth.registrations.account_to_destroy_not_found")] + assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.account_to_destroy_not_found')] end end end - - describe "Update user account" do - describe "existing user" do + describe 'Update user account' do + describe 'existing user' do before do @existing_user = users(:confirmed_email_user) @auth_headers = @existing_user.create_new_auth_token @@ -472,37 +457,38 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration age_token(@existing_user, @client_id) end - describe "without password check" do - describe "success" do + describe 'without password check' do + describe 'success' do before do # test valid update param @resource_class = User - @new_operating_thetan = 1000000 - @email = "AlternatingCase2@example.com" + @new_operating_thetan = 1_000_000 + @email = 'AlternatingCase2@example.com' @request_params = { operating_thetan: @new_operating_thetan, email: @email } end - test "Request was successful" do - put "/auth", @request_params, @auth_headers + test 'Request was successful' do + put '/auth', params: @request_params, headers: @auth_headers assert_equal 200, response.status end - test "Case sensitive attributes update" do + test 'Case sensitive attributes update' do @resource_class.case_insensitive_keys = [] - put "/auth", @request_params, @auth_headers + put '/auth', params: @request_params, headers: @auth_headers @data = JSON.parse(response.body) @existing_user.reload - assert_equal @new_operating_thetan, @existing_user.operating_thetan + assert_equal @new_operating_thetan, + @existing_user.operating_thetan assert_equal @email, @existing_user.email assert_equal @email, @existing_user.uid end - test "Case insensitive attributes update" do + test 'Case insensitive attributes update' do @resource_class.case_insensitive_keys = [:email] - put "/auth", @request_params, @auth_headers + put '/auth', params: @request_params, headers: @auth_headers @data = JSON.parse(response.body) @existing_user.reload assert_equal @new_operating_thetan, @existing_user.operating_thetan @@ -510,16 +496,14 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration assert_equal @email.downcase, @existing_user.uid end - test "Supply current password" do - @request_params.merge!( - current_password: "secret123", - email: "new.email@example.com", - ) + test 'Supply current password' do + @request_params[:current_password] = 'secret123' + @request_params[:email] = 'new.email@example.com' - put "/auth", @request_params, @auth_headers + put '/auth', params: @request_params, headers: @auth_headers @data = JSON.parse(response.body) @existing_user.reload - assert_equal @existing_user.email, "new.email@example.com" + assert_equal @existing_user.email, 'new.email@example.com' end end @@ -527,7 +511,7 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration before do # get the email so we can check it wasn't updated @email = @existing_user.email - put '/auth', {}, @auth_headers + put '/auth', params: {}, headers: @auth_headers @data = JSON.parse(response.body) @existing_user.reload @@ -550,29 +534,29 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration end end - describe "error" do + describe 'error' do before do # test invalid update param - @new_operating_thetan = "blegh" - put "/auth", { - operating_thetan: @new_operating_thetan - }, @auth_headers + @new_operating_thetan = 'blegh' + put '/auth', + params: { operating_thetan: @new_operating_thetan }, + headers: @auth_headers @data = JSON.parse(response.body) @existing_user.reload end - test "Request was NOT successful" do + test 'Request was NOT successful' do assert_equal 422, response.status end - test "Errors were provided with response" do - assert @data["errors"].length + test 'Errors were provided with response' do + assert @data['errors'].length end end end - describe "with password check for password update only" do + describe 'with password check for password update only' do before do DeviseTokenAuth.check_current_password_before_update = :password end @@ -581,25 +565,25 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration DeviseTokenAuth.check_current_password_before_update = false end - describe "success without password update" do + describe 'success without password update' do before do # test valid update param @resource_class = User - @new_operating_thetan = 1000000 - @email = "AlternatingCase2@example.com" + @new_operating_thetan = 1_000_000 + @email = 'AlternatingCase2@example.com' @request_params = { operating_thetan: @new_operating_thetan, email: @email } end - test "Request was successful" do - put "/auth", @request_params, @auth_headers + test 'Request was successful' do + put '/auth', params: @request_params, headers: @auth_headers assert_equal 200, response.status end end - describe "success with password update" do + describe 'success with password update' do before do @existing_user.update password: 'secret123', password_confirmation: 'secret123' @request_params = { @@ -609,15 +593,16 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration } end - test "Request was successful" do - put "/auth", @request_params, @auth_headers + test 'Request was successful' do + put '/auth', params: @request_params, headers: @auth_headers assert_equal 200, response.status end end - describe "error with password mismatch" do + describe 'error with password mismatch' do before do - @existing_user.update password: 'secret123', password_confirmation: 'secret123' + @existing_user.update password: 'secret123', + password_confirmation: 'secret123' @request_params = { password: 'the_new_secret456', password_confirmation: 'the_new_secret456', @@ -625,27 +610,28 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration } end - test "Request was NOT successful" do - put "/auth", @request_params, @auth_headers + test 'Request was NOT successful' do + put '/auth', params: @request_params, headers: @auth_headers assert_equal 422, response.status end end end - describe "with password check for all attributes" do + describe 'with password check for all attributes' do before do DeviseTokenAuth.check_current_password_before_update = :password - @new_operating_thetan = 1000000 - @email = "AlternatingCase2@example.com" + @new_operating_thetan = 1_000_000 + @email = 'AlternatingCase2@example.com' end after do DeviseTokenAuth.check_current_password_before_update = false end - describe "success with password update" do + describe 'success with password update' do before do - @existing_user.update password: 'secret123', password_confirmation: 'secret123' + @existing_user.update password: 'secret123', + password_confirmation: 'secret123' @request_params = { operating_thetan: @new_operating_thetan, email: @email, @@ -653,15 +639,16 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration } end - test "Request was successful" do - put "/auth", @request_params, @auth_headers + test 'Request was successful' do + put '/auth', params: @request_params, headers: @auth_headers assert_equal 200, response.status end end - describe "error with password mismatch" do + describe 'error with password mismatch' do before do - @existing_user.update password: 'secret123', password_confirmation: 'secret123' + @existing_user.update password: 'secret123', + password_confirmation: 'secret123' @request_params = { operating_thetan: @new_operating_thetan, email: @email, @@ -669,15 +656,15 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration } end - test "Request was NOT successful" do - put "/auth", @request_params, @auth_headers + test 'Request was NOT successful' do + put '/auth', params: @request_params, headers: @auth_headers assert_equal 422, response.status end end end end - describe "invalid user" do + describe 'invalid user' do before do @existing_user = users(:confirmed_email_user) @auth_headers = @existing_user.create_new_auth_token @@ -689,80 +676,80 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration # test valid update param @new_operating_thetan = 3 - put "/auth", { - operating_thetan: @new_operating_thetan - }, @auth_headers + put '/auth', + params: { + operating_thetan: @new_operating_thetan + }, + headers: @auth_headers @data = JSON.parse(response.body) @existing_user.reload end - test "Response should return 404 status" do + test 'Response should return 404 status' do assert_equal 404, response.status end - test "error should be returned" do - assert @data["errors"].length - assert_equal @data["errors"], [I18n.t("devise_token_auth.registrations.user_not_found")] + test 'error should be returned' do + assert @data['errors'].length + assert_equal @data['errors'], [I18n.t('devise_token_auth.registrations.user_not_found')] end - test "User should not be updated" do + test 'User should not be updated' do refute_equal @new_operating_thetan, @existing_user.operating_thetan end end end - describe "Ouath user has existing email" do + describe 'Ouath user has existing email' do before do @existing_user = users(:duplicate_email_facebook_user) - post "/auth", { - email: @existing_user.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url - } + post '/auth', + params: { email: @existing_user.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should be successful" do + test 'request should be successful' do assert_equal 200, response.status end - test "user should have been created" do + test 'user should have been created' do assert @resource.id end - test "new user data should be returned as json" do + test 'new user data should be returned as json' do assert @data['data']['email'] end end - describe "Alternate user class" do + describe 'Alternate user class' do before do - post "/mangs", { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url - } + post '/mangs', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url } @resource = assigns(:resource) @data = JSON.parse(response.body) @mail = ActionMailer::Base.deliveries.last end - test "request should be successful" do + test 'request should be successful' do assert_equal 200, response.status end - test "use should be a Mang" do - assert_equal "Mang", @resource.class.name + test 'use should be a Mang' do + assert_equal 'Mang', @resource.class.name end - test "Mang should be destroyed" do + test 'Mang should be destroyed' do @resource.skip_confirmation! @resource.save! @auth_headers = @resource.create_new_auth_token @@ -771,24 +758,25 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration # ensure request is not treated as batch request age_token(@resource, @client_id) - xhr :delete, "/mangs", {}, @auth_headers + delete '/mangs', + params: {}, + headers: @auth_headers assert_equal 200, response.status refute Mang.where(id: @resource.id).first end end - describe "Passing client config name" do + describe 'Passing client config name' do before do @config_name = 'altUser' - post "/mangs", { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url, - config_name: @config_name - } + post '/mangs', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url, + config_name: @config_name } @resource = assigns(:resource) @data = JSON.parse(response.body) @@ -808,70 +796,66 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration describe 'Excluded :registrations module' do test 'UnregisterableUser should not be able to access registration routes' do - assert_raises(ActionController::RoutingError) { - post '/unregisterable_user_auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url - } - } + assert_raises(ActionController::RoutingError) do + post '/unregisterable_user_auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url } + end end end - describe "Skipped confirmation" do + describe 'Skipped confirmation' do setup do User.set_callback(:create, :before, :skip_confirmation!) - post "/auth", { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url - } + post '/auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url } @resource = assigns(:resource) - @token = response.headers["access-token"] - @client_id = response.headers["client"] + @token = response.headers['access-token'] + @client_id = response.headers['client'] end teardown do User.skip_callback(:create, :before, :skip_confirmation!) end - test "user was created" do + test 'user was created' do assert @resource end - test "user was confirmed" do + test 'user was confirmed' do assert @resource.confirmed? end - test "auth headers were returned in response" do - assert response.headers["access-token"] - assert response.headers["token-type"] - assert response.headers["client"] - assert response.headers["expiry"] - assert response.headers["uid"] + test 'auth headers were returned in response' do + assert response.headers['access-token'] + assert response.headers['token-type'] + assert response.headers['client'] + assert response.headers['expiry'] + assert response.headers['uid'] end - test "response token is valid" do + test 'response token is valid' do assert @resource.valid_token?(@token, @client_id) end end - describe 'User with only :database_authenticatable and :registerable included' do setup do @mails_sent = ActionMailer::Base.deliveries.count - post '/only_email_auth', { - email: Faker::Internet.email, - password: "secret123", - password_confirmation: "secret123", - confirm_success_url: Faker::Internet.url, - unpermitted_param: '(x_x)' - } + post '/only_email_auth', + params: { email: Faker::Internet.email, + password: 'secret123', + password_confirmation: 'secret123', + confirm_success_url: Faker::Internet.url, + unpermitted_param: '(x_x)' } @resource = assigns(:resource) @data = JSON.parse(response.body) diff --git a/test/controllers/devise_token_auth/sessions_controller_test.rb b/test/controllers/devise_token_auth/sessions_controller_test.rb index 7dc9458b2..6374a177b 100644 --- a/test/controllers/devise_token_auth/sessions_controller_test.rb +++ b/test/controllers/devise_token_auth/sessions_controller_test.rb @@ -8,7 +8,7 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase describe DeviseTokenAuth::SessionsController do - describe "Confirmed user" do + describe 'Confirmed user' do before do @existing_user = users(:confirmed_email_user) @existing_user.skip_confirmation! @@ -23,10 +23,11 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase @old_sign_in_ip = @existing_user.current_sign_in_ip @old_last_sign_in_ip = @existing_user.last_sign_in_ip - xhr :post, :create, { - email: @existing_user.email, - password: 'secret123' - } + post :create, + params: { + email: @existing_user.email, + password: 'secret123' + } @resource = assigns(:resource) @data = JSON.parse(response.body) @@ -38,11 +39,11 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase @new_last_sign_in_ip = @resource.last_sign_in_ip end - test "request should succeed" do + test 'request should succeed' do assert_equal 200, response.status end - test "request should return user data" do + test 'request should return user data' do assert_equal @existing_user.email, @data['data']['email'] end @@ -63,31 +64,30 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase test 'sign_in_ip is updated' do refute @old_sign_in_ip - assert_equal "0.0.0.0", @new_sign_in_ip + assert_equal '0.0.0.0', @new_sign_in_ip end test 'last_sign_in_ip is updated' do refute @old_last_sign_in_ip - assert_equal "0.0.0.0", @new_last_sign_in_ip + assert_equal '0.0.0.0', @new_last_sign_in_ip end end end describe 'get sign_in is not supported' do before do - xhr :get, :new, { - nickname: @existing_user.nickname, - password: 'secret123' - } + get :new, + params: { nickname: @existing_user.nickname, + password: 'secret123' } @data = JSON.parse(response.body) end test 'user is notified that they should use post sign_in to authenticate' do assert_equal 405, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] - assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.not_supported")] + assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.not_supported')] end end @@ -95,9 +95,10 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase before do request.headers.merge!( 'email' => @existing_user.email, - 'password' => 'secret123') + 'password' => 'secret123' + ) - xhr :head, :create + head :create @data = JSON.parse(response.body) end @@ -108,10 +109,9 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase describe 'alt auth keys' do before do - xhr :post, :create, { - nickname: @existing_user.nickname, - password: 'secret123' - } + post :create, + params: { nickname: @existing_user.nickname, + password: 'secret123' } @data = JSON.parse(response.body) end @@ -123,23 +123,28 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase describe 'authed user sign out' do before do - def @controller.reset_session_called; @reset_session_called == true; end - def @controller.reset_session; @reset_session_called = true; end + def @controller.reset_session_called + @reset_session_called == true + end + + def @controller.reset_session + @reset_session_called = true + end @auth_headers = @existing_user.create_new_auth_token request.headers.merge!(@auth_headers) - xhr :delete, :destroy, format: :json + delete :destroy, format: :json end - test "user is successfully logged out" do + test 'user is successfully logged out' do assert_equal 200, response.status end - test "token was destroyed" do + test 'token was destroyed' do @existing_user.reload - refute @existing_user.tokens[@auth_headers["client"]] + refute @existing_user.tokens[@auth_headers['client']] end - test "session was destroyed" do + test 'session was destroyed' do assert_equal true, @controller.reset_session_called end end @@ -147,38 +152,39 @@ def @controller.reset_session; @reset_session_called = true; end describe 'unauthed user sign out' do before do @auth_headers = @existing_user.create_new_auth_token - xhr :delete, :destroy, format: :json + delete :destroy, format: :json @data = JSON.parse(response.body) end - test "unauthed request returns 404" do + test 'unauthed request returns 404' do assert_equal 404, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] - assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.user_not_found")] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.sessions.user_not_found')] end end describe 'failure' do before do - xhr :post, :create, { - email: @existing_user.email, - password: 'bogus' - } + post :create, + params: { email: @existing_user.email, + password: 'bogus' } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should fail" do + test 'request should fail' do assert_equal 401, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] - assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.bad_credentials")] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.sessions.bad_credentials')] end end @@ -190,31 +196,29 @@ def @controller.reset_session; @reset_session_called = true; end # which initializes client_id @controller.current_user - xhr :post, :create, { - email: @existing_user.email, - password: 'bogus' - } + post :create, + params: { email: @existing_user.email, + password: 'bogus' } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should fail" do + test 'request should fail' do assert_equal 401, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] - assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.bad_credentials")] + assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.bad_credentials')] end after do - DeviseTokenAuth.change_headers_on_each_request = true + DeviseTokenAuth.change_headers_on_each_request = true end end describe 'case-insensitive email' do - before do @resource_class = User @request_params = { @@ -223,51 +227,49 @@ def @controller.reset_session; @reset_session_called = true; end } end - test "request should succeed if configured" do + test 'request should succeed if configured' do @resource_class.case_insensitive_keys = [:email] - xhr :post, :create, @request_params + post :create, params: @request_params assert_equal 200, response.status end - test "request should fail if not configured" do + test 'request should fail if not configured' do @resource_class.case_insensitive_keys = [] - xhr :post, :create, @request_params + post :create, params: @request_params assert_equal 401, response.status end - end end - describe "Unconfirmed user" do + describe 'Unconfirmed user' do before do @unconfirmed_user = users(:unconfirmed_email_user) - xhr :post, :create, { - email: @unconfirmed_user.email, - password: 'secret123' - } + post :create, params: { email: @unconfirmed_user.email, + password: 'secret123' } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should fail" do + test 'request should fail' do assert_equal 401, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] - assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.not_confirmed", email: @unconfirmed_user.email)] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.sessions.not_confirmed', + email: @unconfirmed_user.email)] end end - describe "Unconfirmed user with allowed unconfirmed access" do + describe 'Unconfirmed user with allowed unconfirmed access' do before do @original_duration = Devise.allow_unconfirmed_access_for Devise.allow_unconfirmed_access_for = 3.days @recent_unconfirmed_user = users(:recent_unconfirmed_email_user) - xhr :post, :create, { - email: @recent_unconfirmed_user.email, - password: 'secret123' - } + post :create, + params: { email: @recent_unconfirmed_user.email, + password: 'secret123' } @resource = assigns(:resource) @data = JSON.parse(response.body) end @@ -276,24 +278,23 @@ def @controller.reset_session; @reset_session_called = true; end Devise.allow_unconfirmed_access_for = @original_duration end - test "request should succeed" do + test 'request should succeed' do assert_equal 200, response.status end - test "request should return user data" do + test 'request should return user data' do assert_equal @recent_unconfirmed_user.email, @data['data']['email'] end end - describe "Unconfirmed user with expired unconfirmed access" do + describe 'Unconfirmed user with expired unconfirmed access' do before do @original_duration = Devise.allow_unconfirmed_access_for Devise.allow_unconfirmed_access_for = 3.days @unconfirmed_user = users(:unconfirmed_email_user) - xhr :post, :create, { - email: @unconfirmed_user.email, - password: 'secret123' - } + post :create, + params: { email: @unconfirmed_user.email, + password: 'secret123' } @resource = assigns(:resource) @data = JSON.parse(response.body) end @@ -302,35 +303,34 @@ def @controller.reset_session; @reset_session_called = true; end Devise.allow_unconfirmed_access_for = @original_duration end - test "request should fail" do + test 'request should fail' do assert_equal 401, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] end end - describe "Non-existing user" do + describe 'Non-existing user' do before do - xhr :post, :create, { - email: -> { Faker::Internet.email }, - password: -> { Faker::Number.number(10) } - } + post :create, + params: { email: -> { Faker::Internet.email }, + password: -> { Faker::Number.number(10) } } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should fail" do + test 'request should fail' do assert_equal 401, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] end end - describe "Alternate user class" do + describe 'Alternate user class' do setup do @request.env['devise.mapping'] = Devise.mappings[:mang] end @@ -344,20 +344,19 @@ def @controller.reset_session; @reset_session_called = true; end @existing_user.skip_confirmation! @existing_user.save! - xhr :post, :create, { - email: @existing_user.email, - password: 'secret123' - } + post :create, + params: { email: @existing_user.email, + password: 'secret123' } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should succeed" do + test 'request should succeed' do assert_equal 200, response.status end - test "request should return user data" do + test 'request should return user data' do assert_equal @existing_user.email, @data['data']['email'] end end @@ -375,10 +374,9 @@ def @controller.reset_session; @reset_session_called = true; end @existing_user = only_email_users(:user) @existing_user.save! - xhr :post, :create, { - email: @existing_user.email, - password: 'secret123' - } + post :create, + params: { email: @existing_user.email, + password: 'secret123' } @resource = assigns(:resource) @data = JSON.parse(response.body) @@ -390,7 +388,7 @@ def @controller.reset_session; @reset_session_called = true; end end end - describe "Lockable User" do + describe 'Lockable User' do setup do @request.env['devise.mapping'] = Devise.mappings[:lockable_user] end @@ -414,65 +412,62 @@ def @controller.reset_session; @reset_session_called = true; end Devise.unlock_strategy = @original_unlock_strategy end - describe "locked user" do + describe 'locked user' do before do @locked_user = lockable_users(:locked_user) - xhr :post, :create, { - email: @locked_user.email, - password: 'secret123' - } + post :create, + params: { email: @locked_user.email, + password: 'secret123' } @data = JSON.parse(response.body) end - test "request should fail" do + test 'request should fail' do assert_equal 401, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] - assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.not_confirmed", email: @locked_user.email)] + assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.not_confirmed', email: @locked_user.email)] end end - describe "unlocked user with bad password" do + describe 'unlocked user with bad password' do before do @unlocked_user = lockable_users(:unlocked_user) - xhr :post, :create, { - email: @unlocked_user.email, - password: 'bad-password' - } + post :create, + params: { email: @unlocked_user.email, + password: 'bad-password' } @data = JSON.parse(response.body) end - test "request should fail" do + test 'request should fail' do assert_equal 401, response.status end - test "should increase failed_attempts" do + test 'should increase failed_attempts' do assert_equal 1, @unlocked_user.reload.failed_attempts end - test "response should contain errors" do + test 'response should contain errors' do assert @data['errors'] - assert_equal @data['errors'], [I18n.t("devise_token_auth.sessions.bad_credentials")] + assert_equal @data['errors'], [I18n.t('devise_token_auth.sessions.bad_credentials')] end describe 'after maximum_attempts should block the user' do before do 4.times do - xhr :post, :create, { - email: @unlocked_user.email, - password: 'bad-password' - } + post :create, + params: { email: @unlocked_user.email, + password: 'bad-password' } end @data = JSON.parse(response.body) end - test "should increase failed_attempts" do + test 'should increase failed_attempts' do assert_equal 5, @unlocked_user.reload.failed_attempts end - test "should block the user" do + test 'should block the user' do assert_equal true, @unlocked_user.reload.access_locked? end end diff --git a/test/controllers/devise_token_auth/token_validations_controller_test.rb b/test/controllers/devise_token_auth/token_validations_controller_test.rb index 8a03c4c9e..67dade450 100644 --- a/test/controllers/devise_token_auth/token_validations_controller_test.rb +++ b/test/controllers/devise_token_auth/token_validations_controller_test.rb @@ -21,51 +21,50 @@ class DeviseTokenAuth::TokenValidationsControllerTest < ActionDispatch::Integrat # ensure that request is not treated as batch request age_token(@resource, @client_id) - end describe 'vanilla user' do before do - get '/auth/validate_token', {}, @auth_headers + get '/auth/validate_token', params: {}, headers: @auth_headers @resp = JSON.parse(response.body) end - test "token valid" do + test 'token valid' do assert_equal 200, response.status end end describe 'using namespaces' do before do - get '/api/v1/auth/validate_token', {}, @auth_headers + get '/api/v1/auth/validate_token', params: {}, headers: @auth_headers @resp = JSON.parse(response.body) end - test "token valid" do + test 'token valid' do assert_equal 200, response.status end end describe 'failure' do before do - get '/api/v1/auth/validate_token', {}, @auth_headers.merge({"access-token" => "12345"}) + get '/api/v1/auth/validate_token', + params: {}, + headers: @auth_headers.merge('access-token' => '12345') @resp = JSON.parse(response.body) end - test "request should fail" do + test 'request should fail' do assert_equal 401, response.status end - test "response should contain errors" do + test 'response should contain errors' do assert @resp['errors'] - assert_equal @resp['errors'], [I18n.t("devise_token_auth.token_validations.invalid")] + assert_equal @resp['errors'], [I18n.t('devise_token_auth.token_validations.invalid')] end end - end describe 'using namespaces with unused resource' do - before do @resource = scoped_users(:confirmed_email_user) @resource.skip_confirmation! @@ -81,11 +80,11 @@ class DeviseTokenAuth::TokenValidationsControllerTest < ActionDispatch::Integrat age_token(@resource, @client_id) end - test "should be successful" do - get '/api_v2/auth/validate_token', {}, @auth_headers + test 'should be successful' do + get '/api_v2/auth/validate_token', + params: {}, + headers: @auth_headers assert_equal 200, response.status end - end - end diff --git a/test/controllers/devise_token_auth/unlocks_controller_test.rb b/test/controllers/devise_token_auth/unlocks_controller_test.rb index ea6fe48a1..71e77b29a 100644 --- a/test/controllers/devise_token_auth/unlocks_controller_test.rb +++ b/test/controllers/devise_token_auth/unlocks_controller_test.rb @@ -31,7 +31,7 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase Devise.unlock_strategy = @original_unlock_strategy end - describe "Unlocking user" do + describe 'Unlocking user' do before do @resource = lockable_users(:unlocked_user) end @@ -41,7 +41,7 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase @auth_headers = @resource.create_new_auth_token @new_password = Faker::Internet.password - xhr :post, :create, {} + post :create @data = JSON.parse(response.body) end @@ -49,17 +49,15 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase assert_equal 401, response.status end test 'error message should be returned' do - assert @data["errors"] - assert_equal @data["errors"], [I18n.t("devise_token_auth.passwords.missing_email")] + assert @data['errors'] + assert_equal @data['errors'], [I18n.t('devise_token_auth.passwords.missing_email')] end end describe 'request unlock' do describe 'unknown user should return 404' do before do - xhr :post, :create, { - email: 'chester@cheet.ah' - } + post :create, params: { email: 'chester@cheet.ah' } @data = JSON.parse(response.body) end test 'unknown user should return 404' do @@ -67,30 +65,28 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase end test 'errors should be returned' do - assert @data["errors"] - assert_equal @data["errors"], [I18n.t("devise_token_auth.passwords.user_not_found", email: 'chester@cheet.ah')] + assert @data['errors'] + assert_equal @data['errors'], + [I18n.t('devise_token_auth.passwords.user_not_found', + email: 'chester@cheet.ah')] end end describe 'successfully requested unlock' do before do - xhr :post, :create, { - email: @resource.email - } + post :create, params: { email: @resource.email } @data = JSON.parse(response.body) end test 'response should not contain extra data' do - assert_nil @data["data"] + assert_nil @data['data'] end end describe 'case-sensitive email' do before do - xhr :post, :create, { - email: @resource.email - } + post :create, params: { email: @resource.email } @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -105,7 +101,7 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase end test 'response should contains message' do - assert_equal @data["message"], I18n.t("devise_token_auth.unlocks.sended", email: @resource.email) + assert_equal @data['message'], I18n.t('devise_token_auth.unlocks.sended', email: @resource.email) end test 'action should send an email' do @@ -127,30 +123,26 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase describe 'unlock link failure' do test 'response should return 404' do - assert_raises(ActionController::RoutingError) { - xhr :get, :show, { - unlock_token: "bogus" - } - } + assert_raises(ActionController::RoutingError) do + get :show, params: { unlock_token: 'bogus' } + end end end describe 'password reset link success' do before do - xhr :get, :show, { - unlock_token: @mail_reset_token - } + get :show, params: { unlock_token: @mail_reset_token } @resource.reload raw_qs = response.location.split('?')[1] @qs = Rack::Utils.parse_nested_query(raw_qs) - @client_id = @qs["client_id"] - @expiry = @qs["expiry"] - @unlock = @qs["unlock"] - @token = @qs["token"] - @uid = @qs["uid"] + @client_id = @qs['client_id'] + @expiry = @qs['expiry'] + @unlock = @qs['unlock'] + @token = @qs['token'] + @uid = @qs['uid'] end test 'respones should have success redirect status' do @@ -181,13 +173,13 @@ class DeviseTokenAuth::UnlocksControllerTest < ActionController::TestCase test 'response should return success status if configured' do @resource_class.case_insensitive_keys = [:email] - xhr :post, :create, @request_params + post :create, params: @request_params assert_equal 200, response.status end test 'response should return failure status if not configured' do @resource_class.case_insensitive_keys = [] - xhr :post, :create, @request_params + post :create, params: @request_params assert_equal 404, response.status end end diff --git a/test/controllers/overrides/confirmations_controller_test.rb b/test/controllers/overrides/confirmations_controller_test.rb index 6f29be6f7..d22934f3d 100644 --- a/test/controllers/overrides/confirmations_controller_test.rb +++ b/test/controllers/overrides/confirmations_controller_test.rb @@ -10,14 +10,12 @@ class Overrides::ConfirmationsControllerTest < ActionDispatch::IntegrationTest describe Overrides::ConfirmationsController do before do @redirect_url = Faker::Internet.url - @new_user = evil_users(:unconfirmed_email_user) + @new_user = evil_users(:unconfirmed_email_user) # generate + send email - @new_user.send_confirmation_instructions({ - redirect_url: @redirect_url - }) + @new_user.send_confirmation_instructions(redirect_url: @redirect_url) - @mail = ActionMailer::Base.deliveries.last + @mail = ActionMailer::Base.deliveries.last @confirmation_path = @mail.body.match(/localhost([^\"]*)\"/)[1] # visit confirmation link @@ -27,16 +25,17 @@ class Overrides::ConfirmationsControllerTest < ActionDispatch::IntegrationTest @new_user.reload end - test "user is confirmed" do + test 'user is confirmed' do assert @new_user.confirmed? end - test "user can be authenticated via confirmation link" do + test 'user can be authenticated via confirmation link' do # hard coded in override controller - override_proof_str = "(^^,)" + override_proof_str = '(^^,)' # ensure present in redirect URL - override_proof_param = URI.unescape(response.headers["Location"].match(/override_proof=([^&]*)&/)[1]) + override_proof_param = URI.unescape(response.headers['Location'] + .match(/override_proof=([^&]*)&/)[1]) assert_equal override_proof_str, override_proof_param end diff --git a/test/controllers/overrides/omniauth_callbacks_controller_test.rb b/test/controllers/overrides/omniauth_callbacks_controller_test.rb index 640446202..1144ea63b 100644 --- a/test/controllers/overrides/omniauth_callbacks_controller_test.rb +++ b/test/controllers/overrides/omniauth_callbacks_controller_test.rb @@ -10,22 +10,25 @@ class Overrides::OmniauthCallbacksControllerTest < ActionDispatch::IntegrationTe describe Overrides::OmniauthCallbacksController do setup do OmniAuth.config.test_mode = true - OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({ - :provider => 'facebook', - :uid => '123545', - :info => { + OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new( + provider: 'facebook', + uid: '123545', + info: { name: 'chong', email: 'chongbong@aol.com' } - }) + ) - @favorite_color = "gray" + @favorite_color = 'gray' - get_via_redirect '/evil_user_auth/facebook', { - auth_origin_url: Faker::Internet.url, - favorite_color: @favorite_color, - omniauth_window_type: 'newWindow' - } + get '/evil_user_auth/facebook', + params: { + auth_origin_url: Faker::Internet.url, + favorite_color: @favorite_color, + omniauth_window_type: 'newWindow' + } + + follow_all_redirects! @resource = assigns(:resource) end @@ -35,7 +38,8 @@ class Overrides::OmniauthCallbacksControllerTest < ActionDispatch::IntegrationTe end test 'controller was overridden' do - assert_equal @resource.nickname, Overrides::OmniauthCallbacksController::DEFAULT_NICKNAME + assert_equal @resource.nickname, + Overrides::OmniauthCallbacksController::DEFAULT_NICKNAME end test 'whitelisted param was allowed' do diff --git a/test/controllers/overrides/passwords_controller_test.rb b/test/controllers/overrides/passwords_controller_test.rb index e2dce5034..b9c508286 100644 --- a/test/controllers/overrides/passwords_controller_test.rb +++ b/test/controllers/overrides/passwords_controller_test.rb @@ -12,10 +12,11 @@ class Overrides::PasswordsControllerTest < ActionDispatch::IntegrationTest @resource = evil_users(:confirmed_email_user) @redirect_url = Faker::Internet.url - post "/evil_user_auth/password", { - email: @resource.email, - redirect_url: @redirect_url - } + post '/evil_user_auth/password', + params: { + email: @resource.email, + redirect_url: @redirect_url + } @mail = ActionMailer::Base.deliveries.last @resource.reload @@ -24,22 +25,21 @@ class Overrides::PasswordsControllerTest < ActionDispatch::IntegrationTest @mail_redirect_url = CGI.unescape(@mail.body.match(/redirect_url=([^&]*)&/)[1]) @mail_reset_token = @mail.body.match(/reset_password_token=(.*)\"/)[1] - get '/evil_user_auth/password/edit', { - reset_password_token: @mail_reset_token, - redirect_url: @mail_redirect_url - } + get '/evil_user_auth/password/edit', + params: { reset_password_token: @mail_reset_token, + redirect_url: @mail_redirect_url } @resource.reload raw_qs = response.location.split('?')[1] @qs = Rack::Utils.parse_nested_query(raw_qs) - @client_id = @qs["client_id"] - @expiry = @qs["expiry"] - @reset_password = @qs["reset_password"] - @token = @qs["token"] - @uid = @qs["uid"] - @override_proof = @qs["override_proof"] + @client_id = @qs['client_id'] + @expiry = @qs['expiry'] + @reset_password = @qs['reset_password'] + @token = @qs['token'] + @uid = @qs['uid'] + @override_proof = @qs['override_proof'] end test 'response should have success redirect status' do diff --git a/test/controllers/overrides/registrations_controller_test.rb b/test/controllers/overrides/registrations_controller_test.rb index 39a21fc96..66c41fbf4 100644 --- a/test/controllers/overrides/registrations_controller_test.rb +++ b/test/controllers/overrides/registrations_controller_test.rb @@ -12,18 +12,17 @@ class Overrides::RegistrationsControllerTest < ActionDispatch::IntegrationTest @existing_user = evil_users(:confirmed_email_user) @auth_headers = @existing_user.create_new_auth_token @client_id = @auth_headers['client'] - @favorite_color = "pink" - + @favorite_color = 'pink' # ensure request is not treated as batch request age_token(@existing_user, @client_id) # test valid update param - @new_operating_thetan = 1000000 + @new_operating_thetan = 1_000_000 - put '/evil_user_auth', { - favorite_color: @favorite_color - }, @auth_headers + put '/evil_user_auth', + params: { favorite_color: @favorite_color }, + headers: @auth_headers @data = JSON.parse(response.body) @existing_user.reload @@ -34,7 +33,8 @@ class Overrides::RegistrationsControllerTest < ActionDispatch::IntegrationTest end test 'controller was overridden' do - assert_equal Overrides::RegistrationsController::OVERRIDE_PROOF, @data["override_proof"] + assert_equal Overrides::RegistrationsController::OVERRIDE_PROOF, + @data['override_proof'] end end end diff --git a/test/controllers/overrides/sessions_controller_test.rb b/test/controllers/overrides/sessions_controller_test.rb index 9d9686587..5a89cae3f 100644 --- a/test/controllers/overrides/sessions_controller_test.rb +++ b/test/controllers/overrides/sessions_controller_test.rb @@ -13,21 +13,21 @@ class Overrides::RegistrationsControllerTest < ActionDispatch::IntegrationTest @existing_user.skip_confirmation! @existing_user.save! - post '/evil_user_auth/sign_in', { - email: @existing_user.email, - password: 'secret123' - } + post '/evil_user_auth/sign_in', + params: { email: @existing_user.email, + password: 'secret123' } @resource = assigns(:resource) @data = JSON.parse(response.body) end - test "request should succeed" do + test 'request should succeed' do assert_equal 200, response.status end test 'controller was overridden' do - assert_equal Overrides::RegistrationsController::OVERRIDE_PROOF, @data['override_proof'] + assert_equal Overrides::RegistrationsController::OVERRIDE_PROOF, + @data['override_proof'] end end end diff --git a/test/controllers/overrides/token_validations_controller_test.rb b/test/controllers/overrides/token_validations_controller_test.rb index c5f00525f..4dd286778 100644 --- a/test/controllers/overrides/token_validations_controller_test.rb +++ b/test/controllers/overrides/token_validations_controller_test.rb @@ -22,17 +22,20 @@ class Overrides::TokenValidationsControllerTest < ActionDispatch::IntegrationTes # ensure that request is not treated as batch request age_token(@resource, @client_id) - get '/evil_user_auth/validate_token', {}, @auth_headers + get '/evil_user_auth/validate_token', + params: {}, + headers: @auth_headers @resp = JSON.parse(response.body) end - test "token valid" do + test 'token valid' do assert_equal 200, response.status end - test "controller was overridden" do - assert_equal Overrides::TokenValidationsController::OVERRIDE_PROOF, @resp["override_proof"] + test 'controller was overridden' do + assert_equal Overrides::TokenValidationsController::OVERRIDE_PROOF, + @resp['override_proof'] end end end diff --git a/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb b/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb index 6680f48dc..68d0fa748 100644 --- a/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +++ b/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb @@ -1,5 +1,4 @@ class Custom::OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController - def omniauth_success super do |resource| @omniauth_success_block_called = true unless resource.nil? @@ -9,5 +8,4 @@ def omniauth_success def omniauth_success_block_called? @omniauth_success_block_called == true end - end diff --git a/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb b/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb index 9b9084962..c966b2d3f 100644 --- a/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb +++ b/test/dummy/db/migrate/20140715061447_devise_token_auth_create_users.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateUsers < ActiveRecord::Migration +class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[4.2] def change create_table(:users) do |t| ## Database authenticatable diff --git a/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb b/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb index f1e381bbe..056d4add9 100644 --- a/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb +++ b/test/dummy/db/migrate/20140715061805_devise_token_auth_create_mangs.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateMangs < ActiveRecord::Migration +class DeviseTokenAuthCreateMangs < ActiveRecord::Migration[4.2] def change create_table(:mangs) do |t| ## Database authenticatable diff --git a/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb b/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb index 278051949..df644d592 100644 --- a/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb +++ b/test/dummy/db/migrate/20140829044006_add_operating_thetan_to_user.rb @@ -1,4 +1,4 @@ -class AddOperatingThetanToUser < ActiveRecord::Migration +class AddOperatingThetanToUser < ActiveRecord::Migration[4.2] def change add_column :users, :operating_thetan, :integer add_column :users, :favorite_color, :string diff --git a/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb b/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb index eb7e1d744..eb97800a1 100644 --- a/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb +++ b/test/dummy/db/migrate/20140916224624_add_favorite_color_to_mangs.rb @@ -1,4 +1,4 @@ -class AddFavoriteColorToMangs < ActiveRecord::Migration +class AddFavoriteColorToMangs < ActiveRecord::Migration[4.2] def change add_column :mangs, :favorite_color, :string end diff --git a/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb b/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb index 8bc60b8cf..65b049fa1 100644 --- a/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb +++ b/test/dummy/db/migrate/20140928231203_devise_token_auth_create_evil_users.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateEvilUsers < ActiveRecord::Migration +class DeviseTokenAuthCreateEvilUsers < ActiveRecord::Migration[4.2] def change create_table(:evil_users) do |t| ## Database authenticatable diff --git a/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb b/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb index 6c25075fa..2518ebb33 100644 --- a/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb +++ b/test/dummy/db/migrate/20141222035835_devise_token_auth_create_only_email_users.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateOnlyEmailUsers < ActiveRecord::Migration +class DeviseTokenAuthCreateOnlyEmailUsers < ActiveRecord::Migration[4.2] def change create_table(:only_email_users) do |t| ## Required diff --git a/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb b/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb index aa7cb7ec7..9b41a7572 100644 --- a/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb +++ b/test/dummy/db/migrate/20141222053502_devise_token_auth_create_unregisterable_users.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateUnregisterableUsers < ActiveRecord::Migration +class DeviseTokenAuthCreateUnregisterableUsers < ActiveRecord::Migration[4.2] def change create_table(:unregisterable_users) do |t| ## Required diff --git a/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb b/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb index 0b237452e..d0c8a1af9 100644 --- a/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb +++ b/test/dummy/db/migrate/20150409095712_devise_token_auth_create_nice_users.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateNiceUsers < ActiveRecord::Migration +class DeviseTokenAuthCreateNiceUsers < ActiveRecord::Migration[4.2] def change create_table(:nice_users) do |t| ## Required diff --git a/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb b/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb index af0a224a7..285e4a019 100644 --- a/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb +++ b/test/dummy/db/migrate/20150708104536_devise_token_auth_create_unconfirmable_users.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateUnconfirmableUsers < ActiveRecord::Migration +class DeviseTokenAuthCreateUnconfirmableUsers < ActiveRecord::Migration[4.2] def change create_table(:unconfirmable_users) do |t| ## Required diff --git a/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb b/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb index 0b2a9320f..da8b5fd1b 100644 --- a/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb +++ b/test/dummy/db/migrate/20160103235141_devise_token_auth_create_scoped_users.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateScopedUsers < ActiveRecord::Migration +class DeviseTokenAuthCreateScopedUsers < ActiveRecord::Migration[4.2] def change create_table(:scoped_users) do |t| ## Required diff --git a/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb b/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb index 460c0a22d..50e0d3935 100644 --- a/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb +++ b/test/dummy/db/migrate/20160629184441_devise_token_auth_create_lockable_users.rb @@ -1,6 +1,6 @@ include MigrationDatabaseHelper -class DeviseTokenAuthCreateLockableUsers < ActiveRecord::Migration +class DeviseTokenAuthCreateLockableUsers < ActiveRecord::Migration[4.2] def change create_table(:lockable_users) do |t| ## Required diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 6e5b299b1..a895e1e44 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -14,250 +13,239 @@ ActiveRecord::Schema.define(version: 20160629184441) do create_table "evil_users", force: :cascade do |t| - t.string "email" - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "email" + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "provider" - t.string "uid", default: "", null: false - t.text "tokens" - t.string "favorite_color" + t.string "unconfirmed_email" + t.string "name" + t.string "nickname" + t.string "image" + t.string "provider" + t.string "uid", default: "", null: false + t.text "tokens" + t.string "favorite_color" t.datetime "created_at" t.datetime "updated_at" + t.index ["confirmation_token"], name: "index_evil_users_on_confirmation_token", unique: true + t.index ["email"], name: "index_evil_users_on_email" + t.index ["reset_password_token"], name: "index_evil_users_on_reset_password_token", unique: true + t.index ["uid", "provider"], name: "index_evil_users_on_uid_and_provider", unique: true end - add_index "evil_users", ["confirmation_token"], name: "index_evil_users_on_confirmation_token", unique: true - add_index "evil_users", ["email"], name: "index_evil_users_on_email" - add_index "evil_users", ["reset_password_token"], name: "index_evil_users_on_reset_password_token", unique: true - add_index "evil_users", ["uid", "provider"], name: "index_evil_users_on_uid_and_provider", unique: true - create_table "lockable_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.integer "failed_attempts", default: 0, null: false - t.string "unlock_token" + t.string "provider", null: false + t.string "uid", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.integer "failed_attempts", default: 0, null: false + t.string "unlock_token" t.datetime "locked_at" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" + t.string "name" + t.string "nickname" + t.string "image" + t.string "email" + t.text "tokens" t.datetime "created_at" t.datetime "updated_at" + t.index ["email"], name: "index_lockable_users_on_email" + t.index ["uid", "provider"], name: "index_lockable_users_on_uid_and_provider", unique: true + t.index ["unlock_token"], name: "index_lockable_users_on_unlock_token", unique: true end - add_index "lockable_users", ["email"], name: "index_lockable_users_on_email" - add_index "lockable_users", ["uid", "provider"], name: "index_lockable_users_on_uid_and_provider", unique: true - add_index "lockable_users", ["unlock_token"], name: "index_lockable_users_on_unlock_token", unique: true - create_table "mangs", force: :cascade do |t| - t.string "email" - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "email" + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" - t.string "reset_password_redirect_url" + t.string "reset_password_redirect_url" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "confirm_success_url" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "provider" - t.string "uid", default: "", null: false - t.text "tokens" + t.string "unconfirmed_email" + t.string "name" + t.string "nickname" + t.string "image" + t.string "provider" + t.string "uid", default: "", null: false + t.text "tokens" t.datetime "created_at" t.datetime "updated_at" - t.string "favorite_color" + t.string "favorite_color" + t.index ["confirmation_token"], name: "index_mangs_on_confirmation_token", unique: true + t.index ["email"], name: "index_mangs_on_email" + t.index ["reset_password_token"], name: "index_mangs_on_reset_password_token", unique: true + t.index ["uid", "provider"], name: "index_mangs_on_uid_and_provider", unique: true end - add_index "mangs", ["confirmation_token"], name: "index_mangs_on_confirmation_token", unique: true - add_index "mangs", ["email"], name: "index_mangs_on_email" - add_index "mangs", ["reset_password_token"], name: "index_mangs_on_reset_password_token", unique: true - add_index "mangs", ["uid", "provider"], name: "index_mangs_on_uid_and_provider", unique: true - create_table "nice_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "provider", null: false + t.string "uid", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" + t.string "unconfirmed_email" + t.string "name" + t.string "nickname" + t.string "image" + t.string "email" + t.text "tokens" t.datetime "created_at" t.datetime "updated_at" + t.index ["email"], name: "index_nice_users_on_email" + t.index ["reset_password_token"], name: "index_nice_users_on_reset_password_token", unique: true + t.index ["uid", "provider"], name: "index_nice_users_on_uid_and_provider", unique: true end - add_index "nice_users", ["email"], name: "index_nice_users_on_email" - add_index "nice_users", ["reset_password_token"], name: "index_nice_users_on_reset_password_token", unique: true - add_index "nice_users", ["uid", "provider"], name: "index_nice_users_on_uid_and_provider", unique: true - create_table "only_email_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" + t.string "provider", null: false + t.string "uid", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "name" + t.string "nickname" + t.string "image" + t.string "email" + t.text "tokens" t.datetime "created_at" t.datetime "updated_at" + t.index ["email"], name: "index_only_email_users_on_email" + t.index ["uid", "provider"], name: "index_only_email_users_on_uid_and_provider", unique: true end - add_index "only_email_users", ["email"], name: "index_only_email_users_on_email" - add_index "only_email_users", ["uid", "provider"], name: "index_only_email_users_on_uid_and_provider", unique: true - create_table "scoped_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "provider", null: false + t.string "uid", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" + t.string "unconfirmed_email" + t.string "name" + t.string "nickname" + t.string "image" + t.string "email" + t.text "tokens" t.datetime "created_at" t.datetime "updated_at" + t.index ["email"], name: "index_scoped_users_on_email" + t.index ["reset_password_token"], name: "index_scoped_users_on_reset_password_token", unique: true + t.index ["uid", "provider"], name: "index_scoped_users_on_uid_and_provider", unique: true end - add_index "scoped_users", ["email"], name: "index_scoped_users_on_email" - add_index "scoped_users", ["reset_password_token"], name: "index_scoped_users_on_reset_password_token", unique: true - add_index "scoped_users", ["uid", "provider"], name: "index_scoped_users_on_uid_and_provider", unique: true - create_table "unconfirmable_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "provider", null: false + t.string "uid", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "name" + t.string "nickname" + t.string "image" + t.string "email" + t.text "tokens" t.datetime "created_at" t.datetime "updated_at" + t.index ["email"], name: "index_unconfirmable_users_on_email" + t.index ["reset_password_token"], name: "index_unconfirmable_users_on_reset_password_token", unique: true + t.index ["uid", "provider"], name: "index_unconfirmable_users_on_uid_and_provider", unique: true end - add_index "unconfirmable_users", ["email"], name: "index_unconfirmable_users_on_email" - add_index "unconfirmable_users", ["reset_password_token"], name: "index_unconfirmable_users_on_reset_password_token", unique: true - add_index "unconfirmable_users", ["uid", "provider"], name: "index_unconfirmable_users_on_uid_and_provider", unique: true - create_table "unregisterable_users", force: :cascade do |t| - t.string "provider", null: false - t.string "uid", default: "", null: false - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "provider", null: false + t.string "uid", default: "", null: false + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "email" - t.text "tokens" + t.string "unconfirmed_email" + t.string "name" + t.string "nickname" + t.string "image" + t.string "email" + t.text "tokens" t.datetime "created_at" t.datetime "updated_at" + t.index ["email"], name: "index_unregisterable_users_on_email" + t.index ["reset_password_token"], name: "index_unregisterable_users_on_reset_password_token", unique: true + t.index ["uid", "provider"], name: "index_unregisterable_users_on_uid_and_provider", unique: true end - add_index "unregisterable_users", ["email"], name: "index_unregisterable_users_on_email" - add_index "unregisterable_users", ["reset_password_token"], name: "index_unregisterable_users_on_reset_password_token", unique: true - add_index "unregisterable_users", ["uid", "provider"], name: "index_unregisterable_users_on_uid_and_provider", unique: true - create_table "users", force: :cascade do |t| - t.string "email" - t.string "encrypted_password", default: "", null: false - t.string "reset_password_token" + t.string "email" + t.string "encrypted_password", default: "", null: false + t.string "reset_password_token" t.datetime "reset_password_sent_at" - t.string "reset_password_redirect_url" + t.string "reset_password_redirect_url" t.datetime "remember_created_at" - t.integer "sign_in_count", default: 0, null: false + t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" - t.string "current_sign_in_ip" - t.string "last_sign_in_ip" - t.string "confirmation_token" + t.string "current_sign_in_ip" + t.string "last_sign_in_ip" + t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" - t.string "confirm_success_url" - t.string "unconfirmed_email" - t.string "name" - t.string "nickname" - t.string "image" - t.string "provider" - t.string "uid", default: "", null: false - t.text "tokens" + t.string "unconfirmed_email" + t.string "name" + t.string "nickname" + t.string "image" + t.string "provider" + t.string "uid", default: "", null: false + t.text "tokens" t.datetime "created_at" t.datetime "updated_at" - t.integer "operating_thetan" - t.string "favorite_color" + t.integer "operating_thetan" + t.string "favorite_color" + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true + t.index ["email"], name: "index_users_on_email" + t.index ["nickname"], name: "index_users_on_nickname", unique: true + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true + t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true end - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true - add_index "users", ["email"], name: "index_users_on_email" - add_index "users", ["nickname"], name: "index_users_on_nickname", unique: true - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true - add_index "users", ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true - end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index a8bc6ae56..52e113833 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -65,7 +65,7 @@ class UserTest < ActiveSupport::TestCase @resource.password_confirmation = @password assert @resource.save - refute @resource.errors.messages[:email] + assert @resource.errors.messages[:email].blank? end end @@ -112,11 +112,12 @@ def @resource.token_lifespan assert @resource.token_is_current?(@token_global, @client_id_global) time = Time.now.to_i - expiry_global = @resource.tokens[@client_id_global][:expiry] + expiry_global = @resource.tokens[@client_id_global]['expiry'] + assert expiry_global > time + DeviseTokenAuth.token_lifespan - 5.seconds assert expiry_global < time + DeviseTokenAuth.token_lifespan + 5.seconds - expiry_specific = @resource.tokens[@client_id_specific][:expiry] + expiry_specific = @resource.tokens[@client_id_specific]['expiry'] assert expiry_specific > time + 55.seconds assert expiry_specific < time + 65.seconds end diff --git a/test/test_helper.rb b/test/test_helper.rb index 48e1b1435..db413534d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,31 +1,37 @@ require 'simplecov' -#SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ - #SimpleCov::Formatter::HTMLFormatter, - #CodeClimate::TestReporter::Formatter -#] +# SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ +# SimpleCov::Formatter::HTMLFormatter, +# CodeClimate::TestReporter::Formatter +# ] SimpleCov.start 'rails' -ENV["RAILS_ENV"] = "test" +ENV['RAILS_ENV'] = 'test' -require File.expand_path("../dummy/config/environment", __FILE__) -require "rails/test_help" -require "minitest/rails" +require File.expand_path('../dummy/config/environment', __FILE__) +require 'rails/test_help' +require 'minitest/rails' # To add Capybara feature tests add `gem "minitest-rails-capybara"` # to the test group in the Gemfile and uncomment the following: # require "minitest/rails/capybara" # Uncomment for awesome colorful output -require "minitest/pride" +# require "minitest/pride" -ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) -ActionDispatch::IntegrationTest.fixture_path = File.expand_path("../fixtures", __FILE__) +ActiveSupport::TestCase.fixture_path = File.expand_path('../fixtures', __FILE__) +ActionDispatch::IntegrationTest.fixture_path = File.expand_path('../fixtures', __FILE__) # I hate the default reporter. Use ProgressReporter instead. Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new +class ActionDispatch::IntegrationTest + def follow_all_redirects! + follow_redirect! while response.status.to_s =~ /^3\d{2}/ + end +end + class ActiveSupport::TestCase ActiveRecord::Migration.check_pending!