Added new "address" field to geo location feature and added integration tests.
This commit is contained in:
parent
b3b76acc89
commit
3a0928d7dc
3 changed files with 111 additions and 3 deletions
|
@ -13,7 +13,7 @@ class Observer::User::Geo < ActiveRecord::Observer
|
|||
# check if geo need to be updated
|
||||
def check_geo(record)
|
||||
|
||||
location = %w(street zip city country)
|
||||
location = %w(address street zip city country)
|
||||
|
||||
# check if geo update is needed based on old/new location
|
||||
if record.id
|
||||
|
@ -42,7 +42,7 @@ class Observer::User::Geo < ActiveRecord::Observer
|
|||
# update geo data of user
|
||||
def geo_update(record)
|
||||
address = ''
|
||||
location = %w(street zip city country)
|
||||
location = %w(address street zip city country)
|
||||
location.each { |item|
|
||||
if record[item] && record[item] != ''
|
||||
address = address + ',' + record[item]
|
||||
|
|
|
@ -18,7 +18,7 @@ returns
|
|||
|
||||
def search_index_data
|
||||
attributes = { 'fullname' => "#{ self['firstname'] } #{ self['lastname'] }" }
|
||||
%w(login firstname lastname phone email city country note created_at).each { |key|
|
||||
%w(login firstname lastname phone email address city country note created_at).each { |key|
|
||||
if self[key] && (!self.respond_to?('empty?') || !self[key].empty?)
|
||||
attributes[key] = self[key]
|
||||
end
|
||||
|
|
108
test/integration/geo_location_test.rb
Normal file
108
test/integration/geo_location_test.rb
Normal file
|
@ -0,0 +1,108 @@
|
|||
# encoding: utf-8
|
||||
require 'integration_test_helper'
|
||||
|
||||
class GeoLocationTest < ActiveSupport::TestCase
|
||||
|
||||
# check
|
||||
test 'check simple results' do
|
||||
|
||||
result = GeoLocation.geocode( 'Marienstrasse 13, 10117 Berlin' )
|
||||
assert(result)
|
||||
assert_equal(52.52204, result[0])
|
||||
assert_equal(13.38319, result[1])
|
||||
|
||||
result = GeoLocation.geocode( 'Marienstrasse 13 10117 Berlin' )
|
||||
assert(result)
|
||||
assert_equal(52.52204, result[0])
|
||||
assert_equal(13.38319, result[1])
|
||||
|
||||
result = GeoLocation.geocode( 'Martinsbruggstrasse 35, 9016 St. Gallen' )
|
||||
assert(result)
|
||||
assert_equal(47.4366664, result[0])
|
||||
assert_equal(9.409814899999999, result[1])
|
||||
|
||||
result = GeoLocation.geocode( 'Martinsbruggstrasse 35 9016 St. Gallen' )
|
||||
assert(result)
|
||||
assert_equal(47.4366664, result[0])
|
||||
assert_equal(9.409814899999999, result[1])
|
||||
|
||||
end
|
||||
|
||||
test 'check user results' do
|
||||
|
||||
user1 = User.create(
|
||||
login: 'some_geo_login1',
|
||||
firstname: 'First',
|
||||
lastname: 'Last',
|
||||
email: 'some_geo_login1@example.com',
|
||||
password: 'test',
|
||||
address: 'Marienstrasse 13 10117 Berlin',
|
||||
active: false,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1
|
||||
)
|
||||
assert(user1.preferences)
|
||||
assert(user1.preferences['lat'])
|
||||
assert(user1.preferences['lng'])
|
||||
assert_equal(52.52204, user1.preferences['lat'])
|
||||
assert_equal(13.38319, user1.preferences['lng'])
|
||||
|
||||
user2 = User.create(
|
||||
login: 'some_geo_login2',
|
||||
firstname: 'First',
|
||||
lastname: 'Last',
|
||||
email: 'some_geo_login1@example.com',
|
||||
password: 'test',
|
||||
street: 'Marienstrasse 13',
|
||||
city: 'Berlin',
|
||||
zip: '10117',
|
||||
active: false,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1
|
||||
)
|
||||
assert(user2.preferences)
|
||||
assert(user2.preferences['lat'])
|
||||
assert(user2.preferences['lng'])
|
||||
assert_equal(52.52204, user2.preferences['lat'])
|
||||
assert_equal(13.38319, user2.preferences['lng'])
|
||||
|
||||
|
||||
user3 = User.create(
|
||||
login: 'some_geo_login3',
|
||||
firstname: 'First',
|
||||
lastname: 'Last',
|
||||
email: 'some_geo_login3@example.com',
|
||||
password: 'test',
|
||||
address: 'Martinsbruggstrasse 35, 9016 St. Gallen',
|
||||
active: false,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1
|
||||
)
|
||||
assert(user3.preferences)
|
||||
assert(user3.preferences['lat'])
|
||||
assert(user3.preferences['lng'])
|
||||
assert_equal(47.4366664, user3.preferences['lat'])
|
||||
assert_equal(9.409814899999999, user3.preferences['lng'])
|
||||
|
||||
|
||||
user4 = User.create(
|
||||
login: 'some_geo_login4',
|
||||
firstname: 'First',
|
||||
lastname: 'Last',
|
||||
email: 'some_geo_login4@example.com',
|
||||
password: 'test',
|
||||
street: 'Martinsbruggstrasse 35',
|
||||
city: 'St. Gallen',
|
||||
zip: '9016',
|
||||
active: false,
|
||||
updated_by_id: 1,
|
||||
created_by_id: 1
|
||||
)
|
||||
assert(user4.preferences)
|
||||
assert(user4.preferences['lat'])
|
||||
assert(user4.preferences['lng'])
|
||||
assert_equal(47.4366664, user4.preferences['lat'])
|
||||
assert_equal(9.409814899999999, user4.preferences['lng'])
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue