add geolocation search for public channels
This commit is contained in:
		@@ -125,6 +125,13 @@ describe ChannelsController do
 | 
			
		||||
        get :index, {:api_key => @user.api_key, :format => 'json'}
 | 
			
		||||
        response.should be_successful
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      it "searches nearby public channels" do
 | 
			
		||||
        channel1 = Channel.create(name: 'channel1', latitude: 10, longitude: 10, public_flag: true)
 | 
			
		||||
        channel2 = Channel.create(name: 'channel2', latitude: 60, longitude: 60, public_flag: true)
 | 
			
		||||
        get :public, {api_key: @user.api_key, latitude: 59.8, longitude: 60.2, distance: 100, format: 'json'}
 | 
			
		||||
        JSON.parse(response.body)['channels'][0]['name'].should eq("channel2")
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe "create channel" do
 | 
			
		||||
 
 | 
			
		||||
@@ -134,5 +134,17 @@ describe Channel do
 | 
			
		||||
      channels.count.should == 1
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe 'geolocation' do
 | 
			
		||||
    it 'should find nearby channels' do
 | 
			
		||||
      channel1 = Channel.create(latitude: 10, longitude: 10, public_flag: true)
 | 
			
		||||
      channel2 = Channel.create(latitude: 60, longitude: 60, public_flag: true)
 | 
			
		||||
      channel3 = Channel.create(latitude: 60, longitude: 60, public_flag: false)
 | 
			
		||||
      Channel.location_search({latitude: 9.8, longitude: 10.2, distance: 100}).first.should eq(channel1)
 | 
			
		||||
      Channel.location_search({latitude: 60.2, longitude: 59.8, distance: 100}).first.should eq(channel2)
 | 
			
		||||
      Channel.location_search({latitude: 60.2, longitude: 59.8, distance: 100}).count.should eq(1)
 | 
			
		||||
      Channel.location_search({latitude: 30.8, longitude: 30.2, distance: 100}).count.should eq(0)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user