Sha256: b4a4a6e7619597fda4bf04e8505cf994ac5508c9b61a257732233f5a71b12970

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require 'test_helper'

class NearTest < Test::Unit::TestCase

  def test_near_scope_options_without_sqlite_includes_bounding_box_condition
    result = Event.send(:near_scope_options, 1.0, 2.0, 5)

    assert_match /test_table_name.latitude BETWEEN 0.9276\d* AND 1.0723\d* AND test_table_name.longitude BETWEEN 1.9276\d* AND 2.0723\d* AND /,
      result[:conditions][0]
  end

  def test_near_scope_options_with_defaults
    result = Event.send(:near_scope_options, 1.0, 2.0, 5)

    assert_match /AS distance/, result[:select]
    assert_match /AS bearing/, result[:select]
    assert_no_consecutive_comma(result[:select])
  end

  def test_near_scope_options_with_no_distance
    result = Event.send(:near_scope_options, 1.0, 2.0, 5, :select_distance => false)

    assert_no_match /AS distance/, result[:select]
    assert_match /AS bearing/, result[:select]
    assert_no_match /distance/, result[:condition]
    assert_no_match /distance/, result[:order]
    assert_no_consecutive_comma(result[:select])
  end

  def test_near_scope_options_with_no_bearing
    result = Event.send(:near_scope_options, 1.0, 2.0, 5, :select_bearing => false)

    assert_match /AS distance/, result[:select]
    assert_no_match /AS bearing/, result[:select]
    assert_no_consecutive_comma(result[:select])
  end

  private

  def assert_no_consecutive_comma(string)
    assert_no_match /, *,/, string, "two consecutive commas"
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
geocoder-1.1.8 test/near_test.rb
geocoder-1.1.7 test/near_test.rb
geocoder-sgonyea-1.1.6.1 test/near_test.rb