Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NOT NULL checks for latitude and longitude #86

Merged
merged 5 commits into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [90/80]

end

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [102/80]

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