Add User and Hydrant classes

This commit is contained in:
Erik Michaels-Ober 2011-02-23 15:50:59 -05:00
parent 9f70bbda4e
commit 1b07d05c8e
10 changed files with 13355 additions and 8 deletions

7
app/models/hydrant.rb Normal file
View File

@ -0,0 +1,7 @@
class Hydrant < ActiveRecord::Base
belongs_to :user
def self.find_closest(lat, lng, limit=20)
Hydrant.find_by_sql(["SELECT *, (3959 * ACOS(COS(RADIANS(?)) * COS(RADIANS(lat)) * COS(radians(lng) - RADIANS(?)) + SIN(RADIANS(?)) * SIN(RADIANS(lat)))) AS distance FROM hydrants ORDER BY distance LIMIT ?", lat, lng, lat, limit])
end
end

3
app/models/user.rb Normal file
View File

@ -0,0 +1,3 @@
class User < ActiveRecord::Base
has_many :hydrants
end

View File

@ -0,0 +1,15 @@
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.timestamps
t.string :name
t.integer :voice_number
t.integer :sms_number
t.string :email
end
end
def self.down
drop_table :users
end
end

View File

@ -0,0 +1,16 @@
class CreateHydrants < ActiveRecord::Migration
def self.up
create_table :hydrants do |t|
t.timestamps
t.decimal :lat
t.decimal :lng
t.integer :city_id
t.integer :user_id
end
add_index :hydrants, :city_id, :unique => true
end
def self.down
drop_table :hydrants
end
end

View File

@ -10,6 +10,26 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 0) do
ActiveRecord::Schema.define(:version => 20110223180521) do
create_table "hydrants", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.decimal "lat"
t.decimal "lng"
t.integer "city_id"
t.integer "user_id"
end
add_index "hydrants", ["city_id"], :name => "index_hydrants_on_city_id", :unique => true
create_table "users", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
t.integer "voice_number"
t.integer "sms_number"
t.string "email"
end
end

13262
db/seeds.rb

File diff suppressed because it is too large Load Diff

11
test/fixtures/hydrants.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

11
test/fixtures/users.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View File

@ -0,0 +1,8 @@
require 'test_helper'
class HydrantTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end

8
test/unit/user_test.rb Normal file
View File

@ -0,0 +1,8 @@
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end