mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-15 19:31:26 +00:00
Add a scope with_location
to Event.
This commit is contained in:
parent
94cec5e4cd
commit
aceed9ac83
3 changed files with 19 additions and 1 deletions
|
@ -28,6 +28,10 @@ class Event < ActiveRecord::Base
|
|||
where("expires_at IS NOT NULL AND expires_at < ?", Time.now)
|
||||
}
|
||||
|
||||
scope :with_location, -> {
|
||||
where.not(lat: nil).where.not(lng: nil)
|
||||
}
|
||||
|
||||
# Emit this event again, as a new Event.
|
||||
def reemit!
|
||||
agent.create_event :payload => payload, :lat => lat, :lng => lng
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<h3>Recent Event Map</h3>
|
||||
|
||||
<% events = @agent.events.where("lat IS NOT null AND lng IS NOT null").order("id desc").limit(500) %>
|
||||
<% events = @agent.events.with_location.order("id desc").limit(500) %>
|
||||
<% if events.length > 0 %>
|
||||
<div id="map_canvas" style="width:800px; height:800px"></div>
|
||||
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Event do
|
||||
describe ".with_location" do
|
||||
it "selects events with location" do
|
||||
event = events(:bob_website_agent_event)
|
||||
event.lat = 2
|
||||
event.lng = 3
|
||||
event.save!
|
||||
Event.with_location.pluck(:id).should == [event.id]
|
||||
|
||||
event.lat = nil
|
||||
event.save!
|
||||
Event.with_location.should be_empty
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reemit" do
|
||||
it "creates a new event identical to itself" do
|
||||
events(:bob_website_agent_event).lat = 2
|
||||
|
|
Loading…
Add table
Reference in a new issue