From 28b21959f39b0e28c450bba54b8696632a0187fa Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 10 Dec 2012 11:00:24 +0100 Subject: created generic Email class and use it with EmailAliases --- users/test/unit/email_test.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 users/test/unit/email_test.rb (limited to 'users/test/unit/email_test.rb') 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 -- cgit v1.2.3 From d7890d7c8af6691df2817a9b6654acf9377847bd Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 13 Dec 2012 11:49:26 +0100 Subject: LocalEmail added - will validate uniqueness amongst emails and aliases --- users/test/unit/email_test.rb | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'users/test/unit/email_test.rb') diff --git a/users/test/unit/email_test.rb b/users/test/unit/email_test.rb index d421b77..cba88a2 100644 --- a/users/test/unit/email_test.rb +++ b/users/test/unit/email_test.rb @@ -1,33 +1,39 @@ require 'test_helper' -class EmailAliasTest < ActiveSupport::TestCase +class EmailTest < ActiveSupport::TestCase setup do + # TODO build helper for this ... make_record(User) @attribs = User.valid_attributes_hash User.find_by_login(@attribs[:login]).try(:destroy) @user = User.new(@attribs) + @attribs.merge!(:login => "other_user") + User.find_by_login(@attribs[:login]).try(:destroy) + @other_user = User.create(@attribs) + end + + teardown do + @user.destroy if @user.persisted? # just in case + @other_user.destroy 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? + @other_user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}} + @other_user.save + @user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}} + assert @user.changed? + assert !@user.save # 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? + @other_user.email = email_alias + @other_user.save + @user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}} + assert @user.changed? + assert !@user.save end end -- cgit v1.2.3 From aed03c04270bc9b7d48048ffb2f24fecc993c7ac Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 13 Dec 2012 16:13:32 +0100 Subject: refactor: changed add_email to add_email_alias that's what it does. Changed all tests to use it instead of the attributes method --- users/test/unit/email_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'users/test/unit/email_test.rb') diff --git a/users/test/unit/email_test.rb b/users/test/unit/email_test.rb index cba88a2..1e216d6 100644 --- a/users/test/unit/email_test.rb +++ b/users/test/unit/email_test.rb @@ -20,9 +20,9 @@ class EmailTest < ActiveSupport::TestCase test "email aliases need to be unique" do email_alias = "valid_alias@domain.net" - @other_user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}} + @other_user.add_email_alias email_alias @other_user.save - @user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}} + @user.add_email_alias email_alias assert @user.changed? assert !@user.save # TODO handle errors @@ -32,7 +32,7 @@ class EmailTest < ActiveSupport::TestCase email_alias = "valid_alias@domain.net" @other_user.email = email_alias @other_user.save - @user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}} + @user.add_email_alias email_alias assert @user.changed? assert !@user.save end -- cgit v1.2.3