Skip to content

Instantly share code, notes, and snippets.

@mariovisic
Created July 11, 2011 05:41
Show Gist options
  • Select an option

  • Save mariovisic/1075360 to your computer and use it in GitHub Desktop.

Select an option

Save mariovisic/1075360 to your computer and use it in GitHub Desktop.
context 'geo finding' do
before :all do
@location_one = Factory.build(:location, :lat => 42.000000, :lng => 0.000000)
@location_two = Factory.create(:location, :lat => 42.000000, :lng => 0.050000) # 4.14km's from location one
@location_three = Factory.create(:location, :lat => 42.000000, :lng => 0.100000) # 8.29km's from location one
end
after :all do
Location.delete_all
end
it 'should match multiple locations given a range' do
Location.within(10, :origin => @location_one).size.should == 2
end
it 'should only match locations that are closer than the range given' do
Location.within(5, :origin => @location_one).should include @location_two
Location.within(5, :origin => @location_one).should_not include @location_three
end
it 'should return zero reults if no locations are within range' do
Location.within(4, :origin => @location_one).should be_blank
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment