Skip to content

Commit

Permalink
Merge 37287c2 into 178d714
Browse files Browse the repository at this point in the history
  • Loading branch information
jensb committed Nov 7, 2015
2 parents 178d714 + 37287c2 commit aa0bc5c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/geokit-rails/acts_as_mappable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def adapter
def within(distance, options = {})
options[:within] = distance
#geo_scope(options)
where(distance_conditions(options))
with_latlng.where(distance_conditions(options))
end
alias inside within

Expand Down Expand Up @@ -140,7 +140,11 @@ def by_distance(options = {})
bounds = extract_bounds_from_options(options)
distance_column_name = distance_sql(origin, units, formula)
#geo_scope(options).order("#{distance_column_name} asc")
order("#{distance_column_name} #{options[:reverse] ? 'DESC' : 'ASC'}")
with_latlng.order("#{distance_column_name} #{options[:reverse] ? 'DESC' : 'ASC'}")
end

def with_latlng
where("#{qualified_lat_column_name} IS NOT NULL AND #{qualified_lng_column_name} IS NOT NULL")
end

def closest(options = {})
Expand Down
2 changes: 1 addition & 1 deletion test/acts_as_mappable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def test_find_with_through_with_hash
end

def test_sort_by_distance_from
locations = Location.all
locations = Location.with_latlng.all
unsorted = [locations(:a), locations(:b), locations(:c), locations(:d), locations(:e), locations(:f)]
sorted = [locations(:a), locations(:b), locations(:c), locations(:f), locations(:d), locations(:e)]
assert_equal sorted, locations.sort_by{|l| l.distance_to(locations(:a))}
Expand Down
9 changes: 8 additions & 1 deletion test/fixtures/custom_locations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ f:
state: TX
postal_code: 75039
latitude: 32.895155
longitude: -96.958444
longitude: -96.958444
g:
id: 7
company_id: 2
street: 4711 N Macarthur Blvd # 160
city: Nowhere
state: TX
postal_code: 12345
9 changes: 8 additions & 1 deletion test/fixtures/locations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ f:
state: TX
postal_code: 75039
lat: 32.895155
lng: -96.958444
lng: -96.958444
g:
id: 7
company_id: 2
street: 4711 N Macarthur Blvd # 160
city: Nowhere
state: TX
postal_code: 12345

0 comments on commit aa0bc5c

Please sign in to comment.