Created
May 2, 2012 05:41
-
-
Save tomciopp/2574174 to your computer and use it in GitHub Desktop.
calling the geocoding method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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