Newer
Older
require 'active_support/core_ext'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
Alex Reisner
committed
##
# Simulate enough of ActiveRecord::Base that objects can be used for testing.
#
module ActiveRecord
class Base
Alex Reisner
committed
def initialize
@attributes = {}
end
Alex Reisner
committed
def read_attribute(attr_name)
alexreisner
committed
@attributes[attr_name.to_sym]
Alex Reisner
committed
end
Alex Reisner
committed
def write_attribute(attr_name, value)
alexreisner
committed
@attributes[attr_name.to_sym] = value
Alex Reisner
committed
end
Alex Reisner
committed
def update_attribute(attr_name, value)
alexreisner
committed
write_attribute(attr_name.to_sym, value)
Alex Reisner
committed
end
Alex Reisner
committed
end
end
# Require Geocoder after ActiveRecord simulator.
Alex Reisner
committed
##
Alex Reisner
committed
#
module Geocoder
extend self
private #-----------------------------------------------------------------
File.read(File.join("test", "fixtures", "madison_square_garden.json"))
end
Alex Reisner
committed
end
end
##
# Geocoded model.
#
class Venue < ActiveRecord::Base
geocoded_by :address
Alex Reisner
committed
def initialize(name, address)
super()
write_attribute :name, name
write_attribute :address, address
end
alexreisner
committed
##
# If method not found, assume it's an ActiveRecord attribute reader.
#
def method_missing(name, *args, &block)
@attributes[name]
end
Alex Reisner
committed
end
##
# Reverse geocoded model.
#
class Landmark < ActiveRecord::Base
reverse_geocoded_by :latitude, :longitude
def initialize(name, latitude, longitude)
super()
write_attribute :name, name
write_attribute :latitude, latitude
write_attribute :longitude, longitude
end
##
# If method not found, assume it's an ActiveRecord attribute reader.
#
def method_missing(name, *args, &block)
@attributes[name]
end
end
Alex Reisner
committed
def venue_params(abbrev)
{
:msg => ["Madison Square Garden", "4 Penn Plaza, New York, NY"]
}[abbrev]
end