Sha256: c998b1a93648dc691160b36c3b98c93e6e0c387fe5761c5ecad0a8457a82cc05

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8
$: << File.join(File.dirname(__FILE__), "..")
require 'test_helper'

class QueryTest < GeocoderTestCase

  def test_ip_address_detection
    assert Geocoder::Query.new("232.65.123.94").ip_address?
    assert Geocoder::Query.new("3ffe:0b00:0000:0000:0001:0000:0000:000a").ip_address?
    assert !Geocoder::Query.new("232.65.123.94.43").ip_address?
    assert !Geocoder::Query.new("::ffff:123.456.789").ip_address?
  end

  def test_blank_query_detection
    assert Geocoder::Query.new(nil).blank?
    assert Geocoder::Query.new("").blank?
    assert Geocoder::Query.new("\t  ").blank?
    assert !Geocoder::Query.new("a").blank?
    assert !Geocoder::Query.new("Москва").blank? # no ASCII characters
    assert !Geocoder::Query.new("\na").blank?

    assert Geocoder::Query.new(nil, :params => {}).blank?
    assert !Geocoder::Query.new(nil, :params => {:woeid => 1234567}).blank?
  end

  def test_blank_query_detection_for_coordinates
    assert Geocoder::Query.new([nil,nil]).blank?
    assert Geocoder::Query.new([87,nil]).blank?
  end

  def test_coordinates_detection
    assert Geocoder::Query.new("51.178844,5").coordinates?
    assert Geocoder::Query.new("51.178844, -1.826189").coordinates?
    assert !Geocoder::Query.new("232.65.123").coordinates?
    assert !Geocoder::Query.new("Test\n51.178844, -1.826189").coordinates?
  end

  def test_loopback_ip_address
    assert Geocoder::Query.new("127.0.0.1").loopback_ip_address?
    assert !Geocoder::Query.new("232.65.123.234").loopback_ip_address?
  end

  def test_sanitized_text_with_array
    q = Geocoder::Query.new([43.1313,11.3131])
    assert_equal "43.1313,11.3131", q.sanitized_text
  end

  def test_custom_lookup
    query = Geocoder::Query.new("address", :lookup => :nominatim)
    assert_equal Geocoder::Lookup::Nominatim, query.lookup.class
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
geocoder-1.2.7 test/unit/query_test.rb
geocoder-kb-1.2.6 test/unit/query_test.rb
geocoder-1.2.6 test/unit/query_test.rb
bw-geocoder-1.2.6 test/unit/query_test.rb
bw-geocoder-1.2.5 test/unit/query_test.rb