Skip to content
Snippets Groups Projects
Commit 622cc460 authored by Matthew Landauer's avatar Matthew Landauer
Browse files

Added regression test for near_scope_options

parent 660f4934
No related branches found
No related tags found
No related merge requests found
......@@ -77,8 +77,6 @@ module Geocoder::Store
end
end
private # ----------------------------------------------------------------
##
# Get options hash suitable for passing to ActiveRecord.find to get
# records within a radius (in kilometers) of the given point.
......@@ -119,6 +117,8 @@ module Geocoder::Store
}
end
private # ----------------------------------------------------------------
##
# SQL for calculating distance based on the current database's
# capabilities (trig functions?).
......
require 'test_helper'
class NearTest < Test::Unit::TestCase
def test_near_scope_options
result = Event.near_scope_options(1.0, 2.0, 5)
expected = {
:select =>
"test_table_name.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((1.0 - test_table_name.latitude) * PI() / 180 / 2), 2) + COS(1.0 * PI() / 180) * COS(test_table_name.latitude * PI() / 180) * POWER(SIN((2.0 - test_table_name.longitude) * PI() / 180 / 2), 2))) AS distance, CAST(DEGREES(ATAN2( RADIANS(test_table_name.longitude - 2.0), RADIANS(test_table_name.latitude - 1.0))) + 360 AS decimal) % 360 AS bearing",
:conditions =>
["3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((1.0 - test_table_name.latitude) * PI() / 180 / 2), 2) + COS(1.0 * PI() / 180) * COS(test_table_name.latitude * PI() / 180) * POWER(SIN((2.0 - test_table_name.longitude) * PI() / 180 / 2), 2))) <= ?", 5],
:order => "distance ASC"
}
assert_equal expected, result
end
end
......@@ -4,6 +4,12 @@ require 'test/unit'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
class MysqlConnection
def adapter_name
"mysql"
end
end
##
# Simulate enough of ActiveRecord::Base that objects can be used for testing.
#
......@@ -28,6 +34,10 @@ module ActiveRecord
def self.scope(*args); end
def self.connection
MysqlConnection.new
end
def method_missing(name, *args, &block)
if name.to_s[-1..-1] == "="
write_attribute name.to_s[0...-1], *args
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment