Improved unit tests.

This commit is contained in:
Martin Edenhofer 2015-09-11 19:19:13 +02:00
parent 33b0cc5163
commit a77361869a
2 changed files with 26 additions and 9 deletions

View file

@ -331,7 +331,7 @@ returns
=begin
create model if not exists (check exists based on id, name, login or locale)
create model if not exists (check exists based on id, name, login, email or locale)
result = Model.create_if_not_exists( attributes )
@ -359,6 +359,13 @@ returns
records.each {|loop_record|
return loop_record if loop_record.login == data[:login]
}
elsif data[:email]
# do lookup with == to handle case insensitive databases
records = where( email: data[:email] )
records.each {|loop_record|
return loop_record if loop_record.email == data[:email]
}
elsif data[:locale] && data[:source]
# do lookup with == to handle case insensitive databases
@ -372,7 +379,7 @@ returns
=begin
create or update model (check exists based on id, name, login or locale)
create or update model (check exists based on id, name, login, email or locale)
result = Model.create_or_update( attributes )
@ -418,6 +425,19 @@ returns
record = new( data )
record.save
return record
elsif data[:email]
# do lookup with == to handle case insensitive databases
records = where( email: data[:email] )
records.each {|loop_record|
if loop_record.email.downcase == data[:email].downcase
loop_record.update_attributes( data )
return loop_record
end
}
record = new( data )
record.save
return record
elsif data[:locale]
# do lookup with == to handle case insensitive databases

View file

@ -4,8 +4,7 @@ require 'test_helper'
class EmailAddressTest < ActiveSupport::TestCase
test 'basic tests' do
EmailAddress.delete_all
email_address1 = EmailAddress.create(
email_address1 = EmailAddress.create_or_update(
realname: 'address #1',
email: 'address1@example.com',
active: true,
@ -22,8 +21,7 @@ class EmailAddressTest < ActiveSupport::TestCase
test 'group tests' do
EmailAddress.delete_all
email_address1 = EmailAddress.create(
email_address1 = EmailAddress.create_or_update(
realname: 'address #1',
email: 'address1@example.com',
active: true,
@ -55,8 +53,7 @@ class EmailAddressTest < ActiveSupport::TestCase
created_by_id: 1,
)
EmailAddress.delete_all
email_address1 = EmailAddress.create(
email_address1 = EmailAddress.create_or_update(
realname: 'address #1',
email: 'address1@example.com',
active: true,
@ -64,7 +61,7 @@ class EmailAddressTest < ActiveSupport::TestCase
updated_by_id: 1,
created_by_id: 1,
)
email_address2 = EmailAddress.create(
email_address2 = EmailAddress.create_or_update(
realname: 'address #2',
email: 'address2@example.com',
active: true,