Commit b2ad4d5929440ad3376900312b2789fb851ad1b1

Authored by Vasiliy Ermolovich
1 parent ff21f967
Exists in master and in 1 other branch production

validates uniqueness of github_login

Showing 2 changed files with 11 additions and 0 deletions   Show diff stats
app/models/user.rb
... ... @@ -18,6 +18,7 @@ class User
18 18 before_save :ensure_authentication_token
19 19  
20 20 validates_presence_of :name
  21 + validates_uniqueness_of :github_login, :allow_nil => true
21 22  
22 23 attr_protected :admin
23 24  
... ...
spec/models/user_spec.rb
... ... @@ -19,6 +19,16 @@ describe User do
19 19 user = Fabricate.build(:user, :password => nil, :github_login => 'nashby')
20 20 user.should be_valid
21 21 end
  22 +
  23 + it 'requires uniq github login' do
  24 + user1 = Fabricate(:user, :github_login => 'nashby')
  25 + user1.should be_valid
  26 +
  27 + user2 = Fabricate.build(:user, :github_login => 'nashby')
  28 + user2.save
  29 + user2.should_not be_valid
  30 + user2.errors[:github_login].should include("is already taken")
  31 + end
22 32 end
23 33  
24 34 describe '.find_for_github_oauth' do
... ...