summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-05-13 14:03:53 +0200
committerAzul <azul@leap.se>2014-05-13 14:42:07 +0200
commitbbe9de73352b5aa937173b4158267f6a37e9ca5f (patch)
tree3006005b5f700adcee472cf8bf1d701c241a6d30
parent81a4a0527639fe4b560b8d98f977f6dbac67bb41 (diff)
destinguish user.email from user.email_address
use the former if you want a working email account or nil, the latter if you want the email address associated with a given user no matter if the user actually has an email account or not.
-rw-r--r--app/models/anonymous_user.rb4
-rw-r--r--app/models/user.rb11
-rw-r--r--test/unit/account_test.rb2
3 files changed, 14 insertions, 3 deletions
diff --git a/app/models/anonymous_user.rb b/app/models/anonymous_user.rb
index 360a577..87239eb 100644
--- a/app/models/anonymous_user.rb
+++ b/app/models/anonymous_user.rb
@@ -13,6 +13,10 @@ class AnonymousUser < Object
nil
end
+ def email
+ nil
+ end
+
def email_address
nil
end
diff --git a/app/models/user.rb b/app/models/user.rb
index a809879..6678de6 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -61,12 +61,19 @@ class User < CouchRest::Model::Base
login
end
- def email_address
+ # use this if you want to get a working email address only.
+ def email
if effective_service_level.provides?('email')
- LocalEmail.new(login)
+ email_address
end
end
+ # use this if you want the email address associated with a
+ # user no matter if the user actually has a local email account
+ def email_address
+ LocalEmail.new(login)
+ end
+
# Since we are storing admins by login, we cannot allow admins to change their login.
def is_admin?
APP_CONFIG['admins'].include? self.login
diff --git a/test/unit/account_test.rb b/test/unit/account_test.rb
index 4fb3c3d..b2bfe27 100644
--- a/test/unit/account_test.rb
+++ b/test/unit/account_test.rb
@@ -8,7 +8,7 @@ class AccountTest < ActiveSupport::TestCase
test "create a new account" do
user = Account.create(FactoryGirl.attributes_for(:user))
- assert user.valid?
+ assert user.valid?, "unexpected errors: #{user.errors.inspect}"
assert user.persisted?
assert id = user.identity
assert_equal user.email_address, id.address