Commit d89230cf341843386f3958a48ae5dad4085b3e6d

Authored by Nathan Broadbent
2 parents 3b3cbb0d 217ca5b5
Exists in master and in 1 other branch production

Merge pull request #430 from iFixit/user-create-blank-github-username

Github Login: allow setting to blank
app/models/user.rb
... ... @@ -52,6 +52,13 @@ class User
52 52 github_account? && Errbit::Config.github_access_scope.include?('repo')
53 53 end
54 54  
  55 + def github_login=(login)
  56 + if login.is_a?(String) && login.strip.empty?
  57 + login = nil
  58 + end
  59 + self[:github_login] = login
  60 + end
  61 +
55 62 protected
56 63  
57 64 def destroy_watchers
... ...
spec/controllers/users_controller_spec.rb
... ... @@ -79,6 +79,11 @@ describe UsersController do
79 79 @user.reload.time_zone.should == "Warsaw"
80 80 end
81 81  
  82 + it "should be able to not set github_login option" do
  83 + put :update, :id => @user.to_param, :user => {:github_login => " "}
  84 + @user.reload.github_login.should == nil
  85 + end
  86 +
82 87 it "should be able to set github_login option" do
83 88 put :update, :id => @user.to_param, :user => {:github_login => "awesome_name"}
84 89 @user.reload.github_login.should == "awesome_name"
... ...
spec/models/user_spec.rb
... ... @@ -29,6 +29,15 @@ describe User do
29 29 user2.should_not be_valid
30 30 user2.errors[:github_login].should include("is already taken")
31 31 end
  32 +
  33 + it 'allows blank / null github_login' do
  34 + user1 = Fabricate(:user, :github_login => ' ')
  35 + user1.should be_valid
  36 +
  37 + user2 = Fabricate.build(:user, :github_login => ' ')
  38 + user2.save
  39 + user2.should be_valid
  40 + end
32 41 end
33 42  
34 43 context 'Watchers' do
... ...