Validate username uniq in scope of namespace

This commit is contained in:
Dmitriy Zaporozhets 2013-01-07 17:36:24 +02:00
parent a0bd09ab83
commit fb470e8e2a
4 changed files with 18 additions and 12 deletions

View file

@ -67,6 +67,8 @@ class User < ActiveRecord::Base
message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" } message: "only letters, digits & '_' '-' '.' allowed. Letter should be first" }
validate :namespace_uniq, if: ->(user) { user.username_changed? }
before_validation :generate_password, on: :create before_validation :generate_password, on: :create
before_save :ensure_authentication_token before_save :ensure_authentication_token
alias_attribute :private_token, :authentication_token alias_attribute :private_token, :authentication_token
@ -135,6 +137,12 @@ class User < ActiveRecord::Base
end end
end end
def namespace_uniq
namespace_name = self.username
if Namespace.find_by_path(namespace_name)
self.errors.add :username, "already exist"
end
end
# Namespaces user has access to # Namespaces user has access to
def namespaces def namespaces

View file

@ -69,7 +69,7 @@
%i.icon-ok %i.icon-ok
Saved Saved
%span.update-failed.cred.hide %span.update-failed.cred.hide
%i.icon-ok %i.icon-remove
Failed Failed
%ul.cred %ul.cred
%li It will change web url for personal projects. %li It will change web url for personal projects.

View file

@ -50,12 +50,12 @@ class ProjectMilestones < Spinach::FeatureSteps
end end
Then "I should see 3 issues" do Then "I should see 3 issues" do
page.should have_selector('.milestone-issue-filter li', count: 4) page.should have_selector('.milestone-issue-filter .well-list li', count: 4)
page.should have_selector('.milestone-issue-filter li.hide', count: 1) page.should have_selector('.milestone-issue-filter .well-list li.hide', count: 1)
end end
Then "I should see 4 issues" do Then "I should see 4 issues" do
page.should have_selector('.milestone-issue-filter li', count: 4) page.should have_selector('.milestone-issue-filter .well-list li', count: 4)
page.should_not have_selector('.milestone-issue-filter li.hide') page.should_not have_selector('.milestone-issue-filter .well-list li.hide')
end end
end end

View file

@ -1,7 +1,5 @@
task :travis do desc "Travis run tests"
["rake spinach", "rake spec"].each do |cmd| task :travis => [
puts "Starting to run #{cmd}..." :spinach,
system("export DISPLAY=:99.0 && bundle exec #{cmd}") :spec
raise "#{cmd} failed!" unless $?.exitstatus == 0 ]
end
end