diff options
author | Azul <azul@leap.se> | 2013-07-18 12:28:51 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2013-07-24 10:55:50 +0200 |
commit | a2e49d1b946fa34dd41ce1f07920515df13e09db (patch) | |
tree | ddd2dcd48954c50b676b2f585e1c29a7f477faf0 | |
parent | cc96c60c4617c09379d5e1ddbefa42407329c19a (diff) |
local email adds domain if needed
-rw-r--r-- | users/app/models/local_email.rb | 20 | ||||
-rw-r--r-- | users/test/unit/local_email_test.rb | 27 |
2 files changed, 39 insertions, 8 deletions
diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb index 1cadc71..d919102 100644 --- a/users/app/models/local_email.rb +++ b/users/app/models/local_email.rb @@ -6,15 +6,17 @@ class LocalEmail < Email validate :differs_from_login =end - - def email=(value) - return if value.blank? - self.username = value - strip_domain_if_needed + def initialize(s) + super + append_domain_if_needed end def to_key - [username] + [handle] + end + + def handle + gsub(/@#{APP_CONFIG[:domain]}/i, '') end protected @@ -42,8 +44,10 @@ class LocalEmail < Email end end - def strip_domain_if_needed - self.username.gsub! /@#{APP_CONFIG[:domain]}/i, '' + def append_domain_if_needed + unless self.index('@') + self << "@#{APP_CONFIG[:domain]}" + end end end diff --git a/users/test/unit/local_email_test.rb b/users/test/unit/local_email_test.rb new file mode 100644 index 0000000..9031a98 --- /dev/null +++ b/users/test/unit/local_email_test.rb @@ -0,0 +1,27 @@ +require 'test_helper' + +class LocalEmailTest < ActiveSupport::TestCase + + test "appends domain" do + local = LocalEmail.new(handle) + assert_equal LocalEmail.new(email), local + end + + test "returns handle" do + local = LocalEmail.new(email) + assert_equal handle, local.handle + end + + test "prints full email" do + local = LocalEmail.new(handle) + assert_equal email, "#{local}" + end + + def handle + "asdf" + end + + def email + "asdf@" + APP_CONFIG[:domain] + end +end |