Skip to content

Commit

Permalink
UPdated tests to make sure they work. IpGeocodeLookupTest is broken i…
Browse files Browse the repository at this point in the history
…n Rails 2.3.0
glennpow committed Feb 15, 2009
1 parent a9d972d commit 4199fb2
Showing 7 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/geokit-rails/acts_as_mappable.rb
Original file line number Diff line number Diff line change
@@ -383,7 +383,7 @@ def add_distance_to_select(options, origin, units=default_units, formula=default
distance_selector = distance_sql(origin, units, formula) + " AS #{distance_column_name}"
selector = options.has_key?(:select) && options[:select] ? options[:select] : "*"
options[:select] = "#{selector}, #{distance_selector}"
end
end
end

# Looks for the distance column and replaces it with the distance sql. If an origin was not
29 changes: 14 additions & 15 deletions test/acts_as_mappable_test.rb
Original file line number Diff line number Diff line change
@@ -35,27 +35,26 @@ def to_s
end

# Uses :through
class Organization < ActiveRecord::Base #:nodoc: all
has_one :address, :as => :addressable
acts_as_mappable :through => :address
class MockOrganization < ActiveRecord::Base #:nodoc: all
has_one :mock_address, :as => :addressable
acts_as_mappable :through => :mock_address
end

# Used by :through
class Address < ActiveRecord::Base #:nodoc: all
class MockAddress < ActiveRecord::Base #:nodoc: all
belongs_to :addressable, :polymorphic => true
acts_as_mappable
end

class ActsAsMappableTest < Test::Unit::TestCase #:nodoc: all
class ActsAsMappableTest < ActiveSupport::TestCase #:nodoc: all

LOCATION_A_IP = "217.10.83.5"

#self.fixture_path = File.dirname(__FILE__) + '/fixtures'
#self.fixture_path = RAILS_ROOT + '/test/fixtures/'
#puts "Rails Path #{RAILS_ROOT}"
#puts "Fixture Path: #{self.fixture_path}"
#self.fixture_path = ' /Users/bill_eisenhauer/Projects/geokit_test/test/fixtures/'
fixtures :companies, :locations, :custom_locations, :stores
self.fixture_path = File.dirname(__FILE__) + '/fixtures'
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
self.pre_loaded_fixtures = true
fixtures :companies, :locations, :custom_locations, :stores, :mock_organizations, :mock_addresses

def setup
@location_a = GeoKit::GeoLoc.new
@@ -76,8 +75,8 @@ def setup
@loc_e = locations(:e)
@custom_loc_e = custom_locations(:e)

@barnes_and_noble = organizations(:barnes_and_noble)
@address = address(:address_barnes_and_noble)
@barnes_and_noble = mock_organizations(:barnes_and_noble)
@address = mock_addresses(:address_barnes_and_noble)
end

def test_override_default_units_the_hard_way
@@ -498,9 +497,9 @@ def test_auto_geocode_failure
# Test :through

def test_find_with_through
organizations = Organization.find(:all, :origin => @location_a, :order => 'distance ASC')
organizations = MockOrganization.find(:all, :origin => @location_a, :order => 'distance ASC')
assert_equal 2, organizations.size
organizations = Organization.count(:origin => @location_a, :conditions => "distance < 3.97")
organizations = MockOrganization.count(:origin => @location_a, :conditions => "distance < 3.97")
assert_equal 1, organizations
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
address_starbucks:
addressable: starbucks (Organization)
addressable: starbucks (MockOrganization)
street: 106 N Denton Tap Rd # 350
city: Coppell
state: TX
@@ -8,7 +8,7 @@ address_starbucks:
lng: -96.990159

address_barnes_and_noble:
addressable: barnes_and_noble (Organization)
addressable: barnes_and_noble (MockOrganization)
street: 5904 N Macarthur Blvd # 160
city: Irving
state: TX
File renamed without changes.
2 changes: 1 addition & 1 deletion test/ip_geocode_lookup_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require File.join(File.dirname(__FILE__), '../../../../config/environment')
require ENV['environment'] || File.join(plugin_test_dir, '../../../../config/environment')
require 'action_controller/test_process'
require 'test/unit'
require 'rubygems'
4 changes: 2 additions & 2 deletions test/schema.rb
Original file line number Diff line number Diff line change
@@ -29,11 +29,11 @@
t.column :lng, :decimal, :precision => 15, :scale => 10
end

create_table :organizations, :force => true do |t|
create_table :mock_organizations, :force => true do |t|
t.column :name, :string
end

create_table :addresses, :force => true do |t|
create_table :mock_addresses, :force => true do |t|
t.column :addressable_id, :integer, :null => false
t.column :addressable_type, :string, :null => false
t.column :street, :string, :limit => 60
12 changes: 8 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
require 'test/unit'
ENV["RAILS_ENV"] = "test"
require "test/unit"
require "rubygems"
#require File.dirname(__FILE__) + '/../init'
require 'geokit'

plugin_test_dir = File.dirname(__FILE__)

# Load the Rails environment
require File.join(plugin_test_dir, '../../../../config/environment')
require 'active_record/fixtures'
require ENV['environment'] || File.join(plugin_test_dir, '../../../../config/environment')
require 'test_help'
#require 'active_record/fixtures'
databases = YAML::load(IO.read(plugin_test_dir + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(plugin_test_dir + "/debug.log")

@@ -16,4 +20,4 @@
load(File.join(plugin_test_dir, 'schema.rb'))

# Load fixtures from the plugin
Test::Unit::TestCase.fixture_path = File.join(plugin_test_dir, 'fixtures/')
#Test::Unit::TestCase.fixture_path = File.join(plugin_test_dir, 'fixtures/')

0 comments on commit 4199fb2

Please sign in to comment.