diff --git a/test/unit/near_test.rb b/test/unit/near_test.rb index 520459fc2abd46f5dbdc7cbda0ec72e2181fb72e..5166fc2b6fdcf3212983cd0e7ac11829321c6c51 100644 --- a/test/unit/near_test.rb +++ b/test/unit/near_test.rb @@ -4,38 +4,46 @@ require 'test_helper' class NearTest < GeocoderTestCase - if ENV['DB'] != 'sqlite' - def test_near_scope_options_without_sqlite_includes_bounding_box_condition - result = PlaceWithCustomResultsHandling.send(:near_scope_options, 1.0, 2.0, 5) - table_name = PlaceWithCustomResultsHandling.table_name - assert_match(/#{table_name}.latitude BETWEEN 0.9276\d* AND 1.0723\d* AND #{table_name}.longitude BETWEEN 1.9276\d* AND 2.0723\d* AND /, result[:conditions][0]) - end - - def test_near_scope_options_without_sqlite_includes_radius_condition - result = Place.send(:near_scope_options, 1.0, 2.0, 5) - assert_match(/BETWEEN \? AND \?$/, result[:conditions][0]) - end - - def test_near_scope_options_without_sqlite_includes_radius_default_min_radius - result = Place.send(:near_scope_options, 1.0, 2.0, 5) - - assert_equal(0, result[:conditions][1]) - assert_equal(5, result[:conditions][2]) - end - - def test_near_scope_options_without_sqlite_includes_radius_custom_min_radius - result = Place.send(:near_scope_options, 1.0, 2.0, 5, :min_radius => 3) - - assert_equal(3, result[:conditions][1]) - assert_equal(5, result[:conditions][2]) - end - - def test_near_scope_options_without_sqlite_includes_radius_bogus_min_radius - result = Place.send(:near_scope_options, 1.0, 2.0, 5, :min_radius => 'bogus') - - assert_equal(0, result[:conditions][1]) - assert_equal(5, result[:conditions][2]) - end + def test_near_scope_options_without_sqlite_includes_bounding_box_condition + omit("Not applicable to SQLite") if ENV['DB'] == 'sqlite' + + result = PlaceWithCustomResultsHandling.send(:near_scope_options, 1.0, 2.0, 5) + table_name = PlaceWithCustomResultsHandling.table_name + assert_match(/#{table_name}.latitude BETWEEN 0.9276\d* AND 1.0723\d* AND #{table_name}.longitude BETWEEN 1.9276\d* AND 2.0723\d* AND /, result[:conditions][0]) + end + + def test_near_scope_options_without_sqlite_includes_radius_condition + omit("Not applicable to SQLite") if ENV['DB'] == 'sqlite' + + result = Place.send(:near_scope_options, 1.0, 2.0, 5) + assert_match(/BETWEEN \? AND \?$/, result[:conditions][0]) + end + + def test_near_scope_options_without_sqlite_includes_radius_default_min_radius + omit("Not applicable to SQLite") if ENV['DB'] == 'sqlite' + + result = Place.send(:near_scope_options, 1.0, 2.0, 5) + + assert_equal(0, result[:conditions][1]) + assert_equal(5, result[:conditions][2]) + end + + def test_near_scope_options_without_sqlite_includes_radius_custom_min_radius + omit("Not applicable to SQLite") if ENV['DB'] == 'sqlite' + + result = Place.send(:near_scope_options, 1.0, 2.0, 5, :min_radius => 3) + + assert_equal(3, result[:conditions][1]) + assert_equal(5, result[:conditions][2]) + end + + def test_near_scope_options_without_sqlite_includes_radius_bogus_min_radius + omit("Not applicable to SQLite") if ENV['DB'] == 'sqlite' + + result = Place.send(:near_scope_options, 1.0, 2.0, 5, :min_radius => 'bogus') + + assert_equal(0, result[:conditions][1]) + assert_equal(5, result[:conditions][2]) end def test_near_scope_options_with_defaults