Created
February 19, 2010 10:20
-
-
Save jamesbebbington/308612 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
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 [email protected]? | |
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