diff options
author | Azul <azul@leap.se> | 2012-12-13 11:49:26 +0100 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-12-13 11:49:55 +0100 |
commit | d7890d7c8af6691df2817a9b6654acf9377847bd (patch) | |
tree | c66372f4d25a34028b8873fb652761e8f4a1ec02 /users/test/unit | |
parent | 60e8fc3e1309d1c972a7695e3344e63f5d633a06 (diff) |
LocalEmail added - will validate uniqueness amongst emails and aliases
Diffstat (limited to 'users/test/unit')
-rw-r--r-- | users/test/unit/email_test.rb | 36 |
1 files changed, 21 insertions, 15 deletions
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 |