From 21ae49ab9282422d52cae24d983494d72b3a4105 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 28 Mar 2018 11:31:43 +0800 Subject: [PATCH] Simplify log in for request specs. --- app/controllers/session_controller.rb | 2 +- config/routes.rb | 2 +- spec/requests/users_controller_spec.rb | 6 +++--- spec/support/integration_helpers.rb | 6 +----- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb index 5d9f8473bcc..29b4e5256f6 100644 --- a/app/controllers/session_controller.rb +++ b/app/controllers/session_controller.rb @@ -75,7 +75,7 @@ class SessionController < ApplicationController # For use in development mode only when login options could be limited or disabled. # NEVER allow this to work in production. - if Rails.env.development? + if !Rails.env.production? skip_before_action :check_xhr, only: [:become] def become diff --git a/config/routes.rb b/config/routes.rb index 241d404f0bc..8039c8ef627 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -292,7 +292,7 @@ Discourse::Application.routes.draw do get "extra-locales/:bundle" => "extra_locales#show" resources :session, id: RouteFormat.username, only: [:create, :destroy, :become] do - if Rails.env.development? + if !Rails.env.production? get 'become' end diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb index bd5f961f1f8..6f8be029cf7 100644 --- a/spec/requests/users_controller_spec.rb +++ b/spec/requests/users_controller_spec.rb @@ -436,7 +436,7 @@ RSpec.describe UsersController do SiteSetting.enable_local_logins = false post "/users/second_factors.json", params: { - password: 'somecomplicatedpassword' + password: 'myawesomepassword' } expect(response.status).to eq(404) @@ -449,7 +449,7 @@ RSpec.describe UsersController do SiteSetting.enable_sso = true post "/users/second_factors.json", params: { - password: 'somecomplicatedpassword' + password: 'myawesomepassword' } expect(response.status).to eq(404) @@ -461,7 +461,7 @@ RSpec.describe UsersController do user.user_second_factor.update!(data: "abcdefghijklmnop") post "/users/second_factors.json", params: { - password: 'somecomplicatedpassword' + password: 'myawesomepassword' } expect(response.status).to eq(200) diff --git a/spec/support/integration_helpers.rb b/spec/support/integration_helpers.rb index ceea9935559..94d245caae2 100644 --- a/spec/support/integration_helpers.rb +++ b/spec/support/integration_helpers.rb @@ -24,11 +24,7 @@ module IntegrationHelpers end def sign_in(user) - password = 'somecomplicatedpassword' - user.update!(password: password) - Fabricate(:email_token, confirmed: true, user: user) - post "/session.json", params: { login: user.username, password: password } - expect(response).to be_success + get "/session/#{user.username}/become" user end end