summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--users/app/models/email.rb21
-rw-r--r--users/app/models/identity.rb4
-rw-r--r--users/app/models/local_email.rb20
-rw-r--r--users/test/unit/identity_test.rb32
4 files changed, 34 insertions, 43 deletions
diff --git a/users/app/models/email.rb b/users/app/models/email.rb
index 6d82f2a..90fc645 100644
--- a/users/app/models/email.rb
+++ b/users/app/models/email.rb
@@ -1,6 +1,5 @@
-module Email
- extend ActiveSupport::Concern
-
+class Email < String
+=begin
included do
validates :email,
:format => {
@@ -8,26 +7,14 @@ module Email
:message => "needs to be a valid email address"
}
end
-
- def initialize(attributes = nil, &block)
- attributes = {:email => attributes} if attributes.is_a? String
- super(attributes, &block)
- end
-
- def to_s
- email
- end
-
- def ==(other)
- other.is_a?(Email) ? self.email == other.email : self.email == other
- end
+=end
def to_partial_path
"emails/email"
end
def to_param
- email
+ to_s
end
end
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb
index 9fd0cad..c9c8b73 100644
--- a/users/app/models/identity.rb
+++ b/users/app/models/identity.rb
@@ -4,8 +4,8 @@ class Identity < CouchRest::Model::Base
belongs_to :user
- property :address
- property :destination
+ property :address, LocalEmail
+ property :destination, Email
design do
view :by_user_id
diff --git a/users/app/models/local_email.rb b/users/app/models/local_email.rb
index 69cba01..1cadc71 100644
--- a/users/app/models/local_email.rb
+++ b/users/app/models/local_email.rb
@@ -1,25 +1,11 @@
-class LocalEmail
- include CouchRest::Model::Embeddable
- include Email
-
- property :username, String
-
- before_validation :strip_domain_if_needed
-
- validates :username,
- :presence => true,
- :format => { :with => /\A([^@\s]+)(@#{APP_CONFIG[:domain]})?\Z/i, :message => "needs to be a valid login or email address @#{APP_CONFIG[:domain]}"}
+class LocalEmail < Email
+=begin
validate :unique_on_server
validate :unique_alias_for_user
validate :differs_from_login
+=end
- validates :casted_by, :presence => true
-
- def email
- return '' if username.nil?
- username + '@' + APP_CONFIG[:domain]
- end
def email=(value)
return if value.blank?
diff --git a/users/test/unit/identity_test.rb b/users/test/unit/identity_test.rb
index 3130ddc..a5d30b0 100644
--- a/users/test/unit/identity_test.rb
+++ b/users/test/unit/identity_test.rb
@@ -6,7 +6,11 @@ class IdentityTest < ActiveSupport::TestCase
@user = FactoryGirl.create(:user)
end
- test "user has identity to start with" do
+ teardown do
+ @user.destroy
+ end
+
+ test "initial identity for a user" do
id = @user.build_identity
assert_equal @user.email_address, id.address
assert_equal @user.email_address, id.destination
@@ -14,18 +18,32 @@ class IdentityTest < ActiveSupport::TestCase
end
test "add alias" do
- skip
- @user.create_identity address: @alias
+ id = @user.build_identity address: alias_name
+ assert_equal LocalEmail.new(alias_name), id.address
+ assert_equal @user.email_address, id.destination
+ assert_equal @user, id.user
end
test "add forward" do
- skip
- @user.create_identity destination: @external
+ id = @user.build_identity destination: forward_address
+ assert_equal @user.email_address, id.address
+ assert_equal Email.new(forward_address), id.destination
+ assert_equal @user, id.user
end
test "forward alias" do
- skip
- @user.create_identity address: @alias, destination: @external
+ id = @user.build_identity address: alias_name, destination: forward_address
+ assert_equal LocalEmail.new(alias_name), id.address
+ assert_equal Email.new(forward_address), id.destination
+ assert_equal @user, id.user
+ id.save
end
+ def alias_name
+ @alias_name ||= Faker::Internet.user_name
+ end
+
+ def forward_address
+ @forward_address ||= Faker::Internet.email
+ end
end