diff options
author | francis <francis> | 2007-10-30 20:18:21 +0000 |
---|---|---|
committer | francis <francis> | 2007-10-30 20:18:21 +0000 |
commit | 6e464d5529e87be045736b518e004d63d10dbaaa (patch) | |
tree | 084d78189f68a1193af8afc4458d7b7a331ee5a3 /spec/models/user_spec.rb | |
parent | 389a2aabb29e5a779e5428f302a5aecda5a214d0 (diff) |
Some more tests on user class
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b4b4cfc13..021e39483 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,17 +1,46 @@ require File.dirname(__FILE__) + '/../spec_helper' describe User, " when authenticating" do + before do + @user = User.new + end - before do - @user = User.new - 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 - 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 + end end +describe User, " when saving" do + before do + @user = User.new + end + + it "should not save without setting some parameters" do + lambda { @user.save! }.should raise_error(ActiveRecord::RecordInvalid) + end + + it "should not save with misformatted email" do + @user.name = "Mr. Silly" + @user.password = "insecurepassword" + @user.email = "mousefooble" + lambda { @user.save! }.should raise_error(ActiveRecord::RecordInvalid) + end + + it "should not save with no password" do + @user.name = "Mr. Silly" + @user.password = "" + @user.email = "francis@mysociety.org" + lambda { @user.save! }.should raise_error(ActiveRecord::RecordInvalid) + end + + it "should save with reasonable name, password and email" do + @user.name = "Mr. Silly" + @user.password = "insecurepassword" + @user.email = "francis@mysociety.org" + @user.save! + end +end |