Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'test_helper'
class UserSessionTest < ActiveSupport::TestCase
setup :activate_authlogic
context "A Participant" do
setup do
@participant = Factory(:participant)
assert @participant.password.present?
end
subject { @participant }
should "be not able to login with a nil password" do
assert !UserSession.create(:email => @participant.email, :password => nil) # FAILS
end
should "be not able to login with a empty password" do
assert !UserSession.create(:email => @participant.email, :password => '') # FAILS
end
should "not be able to login with incorrect credentials" do
assert !UserSession.create(:email => @participant.email, :password => 'wrong password') # FAILS
end
should "be able to login with correct credentials" do
assert UserSession.create(:email => @participant.email, :password => @participant.password)
assert_equal @participant, UserSession.find.user
end
should "be not able to login with an invalid perishable token" do
assert !UserSession.create(User.find_using_perishable_token('invalid')) # FAILS
end
should "be able to login with their perishable token" do
assert UserSession.create(User.find_using_perishable_token(@participant.perishable_token))
end
end
# Users are created without passwords and given the option of choosing one once they've logged in using an activation token
context "A unactivated Participant" do
setup do
@participant = Factory(:unactivated_participant)
assert @participant.password.nil?
assert !@participant.active?
end
subject { @participant }
should "be not able to login with a nil password" do
assert !UserSession.create(:email => @participant.email, :password => nil) # FAILS
end
should "be not able to login with a empty password" do
assert !UserSession.create(:email => @participant.email, :password => '') # FAILS
end
should "not be able to login with their perishable token" do
assert !UserSession.create(User.find_using_perishable_token(@participant.perishable_token)) # FAILS
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment