Commit 44266031d154be5f0bfaaaad1fc9668bf770b443
1 parent
57a47d2f
Exists in
master
and in
29 other branches
Allow person creation with a identifier different from his user login
Showing
2 changed files
with
10 additions
and
2 deletions
Show diff stats
app/models/user.rb
@@ -45,7 +45,7 @@ class User < ActiveRecord::Base | @@ -45,7 +45,7 @@ class User < ActiveRecord::Base | ||
45 | p = Person.new | 45 | p = Person.new |
46 | 46 | ||
47 | p.attributes = user.person_data | 47 | p.attributes = user.person_data |
48 | - p.identifier = user.login | 48 | + p.identifier = user.login if p.identifier.blank? |
49 | p.user = user | 49 | p.user = user |
50 | p.environment = user.environment | 50 | p.environment = user.environment |
51 | p.name ||= user.name || user.login | 51 | p.name ||= user.name || user.login |
test/unit/user_test.rb
@@ -87,6 +87,14 @@ class UserTest < ActiveSupport::TestCase | @@ -87,6 +87,14 @@ class UserTest < ActiveSupport::TestCase | ||
87 | assert_equal person_count + 1, Person.count | 87 | assert_equal person_count + 1, Person.count |
88 | end | 88 | end |
89 | 89 | ||
90 | + def test_should_create_person_with_identifier_different_from_login | ||
91 | + user = User.create!(:login => 'new_user', :email => 'new_user@example.com', :password => 'test', :password_confirmation => 'test', :person_data => {:identifier => "new_test"}) | ||
92 | + | ||
93 | + assert Person.exists?(['user_id = ?', user.id]) | ||
94 | + | ||
95 | + assert user.login != user.person.identifier | ||
96 | + end | ||
97 | + | ||
90 | def test_login_validation | 98 | def test_login_validation |
91 | u = User.new | 99 | u = User.new |
92 | u.valid? | 100 | u.valid? |
@@ -355,7 +363,7 @@ class UserTest < ActiveSupport::TestCase | @@ -355,7 +363,7 @@ class UserTest < ActiveSupport::TestCase | ||
355 | Person.any_instance.stubs(:created_at).returns(DateTime.parse('16-08-2010')) | 363 | Person.any_instance.stubs(:created_at).returns(DateTime.parse('16-08-2010')) |
356 | expected_hash = { | 364 | expected_hash = { |
357 | 'login' => 'x_and_y', 'is_admin' => true, 'since_month' => 8, | 365 | 'login' => 'x_and_y', 'is_admin' => true, 'since_month' => 8, |
358 | - 'chat_enabled' => false, 'since_year' => 2010, 'email_domain' => nil, | 366 | + 'chat_enabled' => false, 'since_year' => 2010, 'email_domain' => nil, |
359 | 'amount_of_friends' => 0, 'friends_list' => {}, 'enterprises' => [], | 367 | 'amount_of_friends' => 0, 'friends_list' => {}, 'enterprises' => [], |
360 | } | 368 | } |
361 | 369 |