Last active
December 14, 2015 19:29
-
-
Save dallonf/5137332 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
layout 'basic' | |
def new | |
end | |
def create | |
puts params[:email] | |
puts params[:password] | |
user = User.find_by_email(params[:email]) | |
puts User.count # TEMPORARY debug call, outputs 0 during integration test | |
if user and user.authenticate(params[:password]) | |
session[:user_id] = user.id | |
redirect_to root_path | |
else | |
@email = params[:email] | |
@error = "Either your email or password was invalid" | |
render action: :new | |
end | |
end | |
def destroy | |
session[:user_id] = nil | |
redirect_to root_path | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test_helper' | |
class SessionsTest < ActionDispatch::IntegrationTest | |
def setup | |
@user = User.create(email: "[email protected]", name: "Nick Fury", password: "assemble", password_confirmation: "assemble") | |
end | |
test "should be able to log in from home page" do | |
visit root_path | |
within ".main-header .buttons" do | |
el = find('a[pl-login-popup-trigger]') | |
el.click | |
end | |
assert_equal root_path, current_path # Make sure it shows the popup and doesn't go to the login page | |
# @IRC guys, I'm using Poltergeist, so JavaScript works. I've already verified this | |
within ".login-form" do | |
fill_in "email", with: "[email protected]" | |
fill_in "password", with: "assemble" | |
click_on "Log In" | |
end | |
puts User.count #Outputs 1 | |
assert_equal root_path, current_path # fails here, because it redirected to the login page with the error | |
within ".main-header .buttons" do | |
assert_equal "Nick Fury", find('a').text | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
attr_accessible :email, :name, :password, :password_confirmation | |
has_secure_password | |
validates_presence_of :email, :name | |
validates_uniqueness_of :email | |
validates_email_format_of :email | |
validates_presence_of :password, on: :create | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment