Skip to content

Instantly share code, notes, and snippets.

@dallonf
Last active December 14, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dallonf/5137332 to your computer and use it in GitHub Desktop.
Save dallonf/5137332 to your computer and use it in GitHub Desktop.
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
require 'test_helper'
class SessionsTest < ActionDispatch::IntegrationTest
def setup
@user = User.create(email: "nfury@shield.gov", 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: "nfury@shield.gov"
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
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