diff --git a/app/models/user.rb b/app/models/user.rb index b35c1a81..4f8223dc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -80,6 +80,15 @@ class User < ActiveRecord::Base super end + def identity_url=(url) + begin + self.write_attribute(:identity_url, OpenIdAuthentication.normalize_identifier(url)) + rescue InvalidOpenId + # Invlaid url, don't save + end + self.read_attribute(:identity_url) + end + # Returns the user that matches provided login and password, or nil def self.try_to_login(login, password) # Make sure no one can sign in with an empty password diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 54f15b69..515927ff 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -184,4 +184,23 @@ class UserTest < Test::Unit::TestCase assert !u.password.blank? assert !u.password_confirmation.blank? end + + def test_setting_identity_url + normalized_open_id_url = 'http://example.com/' + u = User.new( :identity_url => 'http://example.com/' ) + assert_equal normalized_open_id_url, u.identity_url + end + + def test_setting_identity_url_without_trailing_slash + normalized_open_id_url = 'http://example.com/' + u = User.new( :identity_url => 'http://example.com' ) + assert_equal normalized_open_id_url, u.identity_url + end + + def test_setting_identity_url_without_protocol + normalized_open_id_url = 'http://example.com/' + u = User.new( :identity_url => 'example.com' ) + assert_equal normalized_open_id_url, u.identity_url + end + end