2017-05-22 5 views
0

This is my user.rb file, where I have use geocoded_by :full_address.Which give me follwing error on running minitest cases "ArgumentError: unknown stub request 2000 h st nw room 1 washington district of columbia 20037". Following is code of unit test.スタブアウトアドレスジオコーディング、単体テスト中

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

私はここに長いアドレス文字列を返すようにしようとルビーの方法を参照してください。 ユニットテストもコピーしてください。特に、スタブしようとしている場所でテストをコピーしてください。 – rohan

+0

@rohanテストケースも追加しました。 'user.geocode'でエラーが表示されます。 –

答えて

0

We just need to add stub before geocode

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' 
}]) 
関連する問題