aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/models/info_request_spec.rb2
-rw-r--r--spec/models/user_spec.rb47
2 files changed, 39 insertions, 10 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 353ef3243..add67b44f 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -14,7 +14,7 @@ describe InfoRequest, " when emailing" do
it "should recognise its own incoming email" do
incoming_email = @info_request.incoming_email
found_info_request = InfoRequest.find_by_incoming_email(incoming_email)
- found_info_request.should ==(@info_request)
+ found_info_request.should == (@info_request)
end
end
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