Sha256: 695a0bb678cbfc008f3537b4bf0128a97b6cf8004a8d08e89edae04015bd1fb6

Contents?: true

Size: 1.88 KB

Versions: 95

Compression:

Stored size: 1.88 KB

Contents

require 'test_helper'

ActionController::Routing::Routes.draw do |map|
  map.connect ':controller/:action/:id'
end

class LocationAwareController < ActionController::Base #:nodoc: all
  geocode_ip_address
  
  def index
    render :nothing => true
  end
  
  def rescue_action(e) raise e end; 
end

class ActionController::TestRequest #:nodoc: all
  attr_accessor :remote_ip
end

class IpGeocodeLookupTest < ActionController::TestCase
  tests LocationAwareController
  
  def setup
    @success = GeoKit::GeoLoc.new
    @success.provider = "hostip"
    @success.lat = 41.7696
    @success.lng = -88.4588
    @success.city = "Sugar Grove"
    @success.state = "IL"
    @success.country_code = "US"
    @success.success = true
    
    @failure = GeoKit::GeoLoc.new
    @failure.provider = "hostip"
    @failure.city = "(Private Address)"
    @failure.success = false
  end

  def test_no_location_in_cookie_or_session
    Geokit::Geocoders::MultiGeocoder.expects(:geocode).with("good ip").returns(@success)
    @request.remote_ip = "good ip"
    get :index
    verify
  end
  
  def test_location_in_cookie
    @request.remote_ip = "good ip"
    @request.cookies['geo_location'] = @success.to_yaml
    get :index
    verify
  end
  
  def test_location_in_session
    @request.remote_ip = "good ip"
    @request.session[:geo_location] = @success
    @request.cookies['geo_location'] = CGI::Cookie.new('geo_location', @success.to_yaml)
    get :index
    verify
  end
  
  def test_ip_not_located
    Geokit::Geocoders::MultiGeocoder.expects(:geocode).with("bad ip").returns(@failure)
    @request.remote_ip = "bad ip"
    get :index
    assert_nil @request.session[:geo_location]
  end
  
  private
  
  def verify
    assert_response :success    
    assert_equal @success, @request.session[:geo_location]
    assert_not_nil cookies['geo_location']
    assert_equal @success, YAML.load(cookies['geo_location'])
  end
end

Version data entries

95 entries across 95 versions & 3 rubygems

Version Path
earth-0.4.12 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.11 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.10 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.9 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.8 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.7 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.6 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.5 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.4 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.3 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.2 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.1 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.4.0 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.3.15 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.3.14 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.3.13 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.3.11 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.3.10 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.3.9 vendor/geokit-rails/test/ip_geocode_lookup_test.rb
earth-0.3.8 vendor/geokit-rails/test/ip_geocode_lookup_test.rb