这是我的user.rb文件,我在那里使用geocoded_by:full_address.Which在运行minitest案例时给出了以下错误“ArgumentError:未知的存根请求2000 h st nw room 1 washington district of columbia 20037”。以下是单元测试代码。
def full_address
@address = ""
@address << " " << self.street_address_1.to_s unless self.street_address_1.blank?
@address << " " << self.street_address_2.to_s unless self.street_address_2.blank?
@address << " " << self.city.to_s unless self.city.blank?
@address << " " << self.state.name.to_s unless self.state_id.blank?
@address << " " << self.zip.to_s unless self.zip.blank?
@address.strip.downcase
端
test "in_user_range? returns false if not in range" do
item = items(:protein_only_item)
user = users(:user2)
user.latitude = 41.542517 # west des moines ia
user.longitude = -93.760625 # west des moines ia
user.geocode
item.in_user_range?(user)
端
答案 0 :(得分:0)
我们只需要在地理编码
之前添加存根
Geocoder.configure(:lookup => :test)
Geocoder::Lookup::Test.add_stub(
"New York, NY", [
{
'latitude' => 40.7143528,
'longitude' => -74.0059731,
'address' => 'New York, NY, USA',
'state' => 'New York',
'state_code' => 'NY',
'country' => 'United States',
'country_code' => 'US'
}])