diff options
author | francis <francis> | 2007-10-30 20:24:58 +0000 |
---|---|---|
committer | francis <francis> | 2007-10-30 20:24:58 +0000 |
commit | 244b9524f8e14e04b3140616f44f461db4263ca2 (patch) | |
tree | 71fbaa3078caa22e5a375ffd261f9c237fc689ac /spec/models/user_spec.rb | |
parent | 6e464d5529e87be045736b518e004d63d10dbaaa (diff) |
More tests on user model
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 021e39483..5e9e89a1a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2,13 +2,34 @@ require File.dirname(__FILE__) + '/../spec_helper' describe User, " when authenticating" do before do - @user = User.new + @empty_user = User.new + + @full_user = User.new + @full_user.name = "Sensible User" + @full_user.password = "foolishpassword" + @full_user.email = "sensible@localhost" + @full_user.save end it "should create a hashed password when the password is set" do - @user.hashed_password.should be_nil - @user.password = "a test password" - @user.hashed_password.should_not be_nil + @empty_user.hashed_password.should be_nil + @empty_user.password = "a test password" + @empty_user.hashed_password.should_not be_nil + end + + it "should not find the user when given the wrong password" do + found_user = User.authenticate("sensible@localhost", "iownzyou") + found_user.should be_nil + end + + it "should not find the user when given the wrong email" do + found_user = User.authenticate("soccer@localhost", "foolishpassword") + found_user.should be_nil + end + + it "should find the user when given the right email and password" do + found_user = User.authenticate("sensible@localhost", "foolishpassword") + found_user.should == (@full_user) end end @@ -32,14 +53,14 @@ describe User, " when saving" do it "should not save with no password" do @user.name = "Mr. Silly" @user.password = "" - @user.email = "francis@mysociety.org" + @user.email = "silly@localhost" lambda { @user.save! }.should raise_error(ActiveRecord::RecordInvalid) end it "should save with reasonable name, password and email" do - @user.name = "Mr. Silly" + @user.name = "Mr. Reasonable" @user.password = "insecurepassword" - @user.email = "francis@mysociety.org" + @user.email = "reasonable@localhost" @user.save! end end |