summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
Diffstat (limited to 'users')
-rw-r--r--users/app/models/identity.rb20
-rw-r--r--users/test/unit/identity_test.rb34
2 files changed, 54 insertions, 0 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb
new file mode 100644
index 0000000..a081394
--- /dev/null
+++ b/users/app/models/identity.rb
@@ -0,0 +1,20 @@
+class Identity < CouchRest::Model::Base
+
+ use_database :identities
+
+ belongs_to :user
+
+ property :address
+ property :destination
+
+ def initialize(attribs = {}, &block):q
+ attribs.reverse_merge! user_id: user.id,
+ address: user.main_email_address,
+ destination: user.main_email_address
+ Identity.new attribs
+ end
+
+ design do
+ view :by_user_id
+ end
+end
diff --git a/users/test/unit/identity_test.rb b/users/test/unit/identity_test.rb
new file mode 100644
index 0000000..389ef89
--- /dev/null
+++ b/users/test/unit/identity_test.rb
@@ -0,0 +1,34 @@
+require 'test_helper'
+
+class IdentityTest < ActiveSupport::TestCase
+
+ setup do
+ @user = FactoryGirl.create(:user)
+ end
+
+ test "user has identity to start with" do
+ id = Identity.new user_id: @user.id
+ id.save
+ assert_equal 1, Identity.by_user_id.key(@user.id).count
+ identity = Identity.find_by_user_id(@user.id)
+ assert_equal @user.email_address, identity.address
+ assert_equal @user.email_address, identity.destination
+ assert_equal @user, identity.user
+ end
+
+ test "add alias" do
+ skip
+ @user.create_identity address: @alias
+ end
+
+ test "add forward" do
+ skip
+ @user.create_identity destination: @external
+ end
+
+ test "forward alias" do
+ skip
+ @user.create_identity address: @alias, destination: @external
+ end
+
+end