user_spec.rb 1.76 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1 2 3 4 5
require 'spec_helper'

describe User do
  describe "Associations" do
    it { should have_many(:projects) }
6 7 8 9 10 11
    it { should have_many(:users_projects).dependent(:destroy) }
    it { should have_many(:issues).dependent(:destroy) }
    it { should have_many(:assigned_issues).dependent(:destroy) }
    it { should have_many(:merge_requests).dependent(:destroy) }
    it { should have_many(:assigned_merge_requests).dependent(:destroy) }
    it { should have_many(:notes).dependent(:destroy) }
gitlabhq's avatar
gitlabhq committed
12 13 14 15 16 17
  end

  describe "Respond to" do
    it { should respond_to(:is_admin?) }
    it { should respond_to(:identifier) }
    it { should respond_to(:name) }
Nihad Abbasov's avatar
Nihad Abbasov committed
18
    it { should respond_to(:private_token) }
gitlabhq's avatar
gitlabhq committed
19 20
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
21
  it "should return valid identifier" do
22
    user = User.new(email: "test@mail.com")
Drew's avatar
Drew committed
23
    user.identifier.should == "test_mail_com"
gitlabhq's avatar
gitlabhq committed
24
  end
25

26
  it "should return identifier without + sign" do
27
    user = User.new(email: "test+foo@mail.com")
28 29 30
    user.identifier.should == "test_foo_mail_com"
  end

31
  it "should execute callback when force_random_password specified" do
32
    user = User.new(email: "test@mail.com", force_random_password: true)
33 34 35 36 37
    user.should_receive(:generate_password)
    user.save
  end

  it "should not generate password by default" do
38
    user = Factory(:user, password: 'abcdefg', password_confirmation: 'abcdefg')
39 40 41 42 43
    user.password.should == 'abcdefg'
  end

  it "should generate password when forcing random password" do
    Devise.stub(:friendly_token).and_return('123456789')
44
    user = User.create(email: "test1@mail.com", force_random_password: true)
45 46
    user.password.should == user.password_confirmation
    user.password.should == '12345678'
47 48
  end

Nihad Abbasov's avatar
Nihad Abbasov committed
49 50 51 52
  it "should have authentication token" do
    user = Factory(:user)
    user.authentication_token.should_not == ""
  end
gitlabhq's avatar
gitlabhq committed
53
end