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
def initialize
@attributes = {}
end
def read_attribute(attr_name)
alexreisner
committed
@attributes[attr_name.to_sym]
Alex Reisner
committed
end
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
def self.named_scope(*args); end
end
end
# Require Geocoder after ActiveRecord simulator.
Alex Reisner
committed
##
# Mock HTTP request to Google.
#
module Geocoder
def self._fetch_xml(query)
filename = File.join("test", "fixtures", "madison_square_garden.xml")
File.read(filename)
end
end
##
# Geocoded model.
#
class Venue < ActiveRecord::Base
geocoded_by :address
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
Alex Reisner
committed
def venue_params(abbrev)
{
:msg => ["Madison Square Garden", "4 Penn Plaza, New York, NY"]
}[abbrev]
end