Users are redirected to the url they clicked login/signup from (#446)

This commit is contained in:
farhatahmad
2019-04-11 12:45:43 -04:00
committed by Jesus Federico
parent d39a11059e
commit a14007743f
4 changed files with 71 additions and 5 deletions

View File

@ -89,6 +89,57 @@ describe SessionsController, type: :controller do
expect(@request.session[:user_id]).to be_nil
expect(response).to redirect_to(account_activation_path(email: @user3.email))
end
it "redirects the user to the page they clicked sign in from" do
user = create(:user, provider: "greenlight",
password: "example", password_confirmation: 'example')
url = Faker::Internet.domain_name
@request.cookies[:return_to] = url
post :create, params: {
session: {
email: user.email,
password: 'example',
},
}
expect(@request.session[:user_id]).to eql(user.id)
expect(response).to redirect_to(url)
end
it "redirects the user to their home room if they clicked the sign in button from root" do
user = create(:user, provider: "greenlight",
password: "example", password_confirmation: 'example')
@request.cookies[:return_to] = root_url
post :create, params: {
session: {
email: user.email,
password: 'example',
},
}
expect(@request.session[:user_id]).to eql(user.id)
expect(response).to redirect_to(user.main_room)
end
it "redirects the user to their home room if return_to cookie doesn't exist" do
user = create(:user, provider: "greenlight",
password: "example", password_confirmation: 'example')
post :create, params: {
session: {
email: user.email,
password: 'example',
},
}
expect(@request.session[:user_id]).to eql(user.id)
expect(response).to redirect_to(user.main_room)
end
end
describe "GET/POST #omniauth" do