aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/user_spec.rb
blob: 021e3948357ab21036c42d39fe5aab3c3283293e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
require File.dirname(__FILE__) + '/../spec_helper'

describe User, " when authenticating" do
    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

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