Skip to content

Instantly share code, notes, and snippets.

@tomciopp
Created May 2, 2012 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomciopp/2574174 to your computer and use it in GitHub Desktop.
Save tomciopp/2574174 to your computer and use it in GitHub Desktop.
calling the geocoding method
Here is the test I have written:
// Another factory is created before this with the same address
it "should not call the geocoding method but should grab data from the database" do
@dest3 = FactoryGirl.create(:destination)
@dest3.should_not_receive(:geocoding)
end
// This method should fail but it passes
def find_coordinates
coords = geocoding(self.address)
self.latitude, self.longitude = coords.first, coords.last
end
// Implementation of the method that checks the db for records:
def find_coordinates
cache = Destination.where(address: self.address).first
if cache.nil?
coords = geocoding(self.address)
self.latitude, self.longitude = coords.first, coords.last
else
self.latitude, self.longitude = cache.latitude, cache.longitude
end
end
No matter what the tests I have written state that this method is not being called when I know it is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment