summaryrefslogtreecommitdiff
path: root/users/test/unit
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-09 10:52:23 +0100
committerAzul <azul@leap.se>2012-12-09 10:52:23 +0100
commit4dffda05477f74c90197948bb6f13bedc8b2a19f (patch)
treed78706cb5d6a49d8919c1dbcf340d436257956e4 /users/test/unit
parent5cfabde4f04d9212af5efee805479bd1be3c5cf1 (diff)
first steps towards email aliases
* unit tests draft * controller draft
Diffstat (limited to 'users/test/unit')
-rw-r--r--users/test/unit/email_alias_test.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/users/test/unit/email_alias_test.rb b/users/test/unit/email_alias_test.rb
new file mode 100644
index 0000000..86cb10f
--- /dev/null
+++ b/users/test/unit/email_alias_test.rb
@@ -0,0 +1,50 @@
+require 'test_helper'
+
+class EmailAliasTest < ActiveSupport::TestCase
+
+ setup do
+ @attribs = User.valid_attributes_hash
+ User.find_by_login(@attribs[:login]).try(:destroy)
+ @user = User.new(@attribs)
+ end
+
+ test "no email aliases set in the beginning" do
+ assert_equal [], @user.email_aliases
+ end
+
+ test "adding email alias" do
+ email_alias = "valid_alias@domain.net"
+ @user.add_email_alias(email_alias)
+ assert_equal [email_alias], @user.email_aliases
+ end
+
+ test "email aliases need to be unique" do
+ # todo build helper for this ... make_record(User)
+ email_alias = "valid_alias@domain.net"
+ attribs = User.valid_attributes_hash.merge(:login => "other_user")
+ User.find_by_login(attribs[:login]).try(:destroy)
+ other_user = User.new(attribs)
+ other_user.add_email_alias(email_alias)
+ @user.add_email_alias(email_alias)
+ # todo: how do we handle errors? Should email_alias become an ActiveModel?
+ assert_equal [], @user.email_aliases
+ end
+
+ test "email aliases may not conflict with emails" do
+ # todo build helper for this ... make_record(User)
+ email_alias = "valid_alias@domain.net"
+ attribs = User.valid_attributes_hash.merge(:login => "other_user", :email => email_alias)
+ User.find_by_login(attribs[:login]).try(:destroy)
+ other_user = User.new(attribs)
+ @user.add_email_alias(email_alias)
+ # todo: how do we handle errors? Should email_alias become an ActiveModel?
+ assert_equal [], @user.email_aliases
+ end
+
+ test "can retrieve user by email alias" do
+ email_alias = "valid_alias@domain.net"
+ @user.add_email_alias(email_alias)
+ assert_equal @user, User.find_by_email_alias(email_alias)
+ assert_equal @user, User.find_by_email(email_alias)
+ end
+end