summaryrefslogtreecommitdiff
path: root/users/test/unit
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-10 11:00:24 +0100
committerAzul <azul@leap.se>2012-12-10 11:00:24 +0100
commit28b21959f39b0e28c450bba54b8696632a0187fa (patch)
tree7f13cad03190324ca0d242d3aee74bfb4efb00fa /users/test/unit
parente4c7f2fb8fa2833037508f1b88f802944855fd77 (diff)
created generic Email class and use it with EmailAliases
Diffstat (limited to 'users/test/unit')
-rw-r--r--users/test/unit/email_alias_test.rb50
-rw-r--r--users/test/unit/email_aliases_test.rb30
-rw-r--r--users/test/unit/email_test.rb33
3 files changed, 63 insertions, 50 deletions
diff --git a/users/test/unit/email_alias_test.rb b/users/test/unit/email_alias_test.rb
deleted file mode 100644
index 86cb10f..0000000
--- a/users/test/unit/email_alias_test.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-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
diff --git a/users/test/unit/email_aliases_test.rb b/users/test/unit/email_aliases_test.rb
new file mode 100644
index 0000000..e737773
--- /dev/null
+++ b/users/test/unit/email_aliases_test.rb
@@ -0,0 +1,30 @@
+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.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}}
+ assert @user.changed?
+ assert @user.save
+ assert_equal email_alias, @user.email_aliases.first.to_s
+ end
+
+ test "can retrieve user by email alias" do
+ email_alias = "valid_alias@domain.net"
+ @user.attributes = {:email_aliases => [email_alias]}
+ @user.save
+ assert_equal @user, User.find_by_email_alias(email_alias)
+ assert_equal @user, User.find_by_email(email_alias)
+ end
+end
diff --git a/users/test/unit/email_test.rb b/users/test/unit/email_test.rb
new file mode 100644
index 0000000..d421b77
--- /dev/null
+++ b/users/test/unit/email_test.rb
@@ -0,0 +1,33 @@
+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 "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.attributes = {:email_aliases => [email_alias]}
+ other_user.save
+ @user.attributes = {:email_aliases => [email_alias]}
+ assert !@user.valid?
+ # TODO handle errors
+ 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.attributes = {:email_aliases => [email_alias]}
+ assert !@user.valid?
+ end
+end