Add reminder model

This commit is contained in:
Erik Michaels-Ober 2011-05-22 07:35:46 -07:00
parent 6ded1e3bf3
commit 8d2a627ba7
9 changed files with 53 additions and 11 deletions

View File

@ -1,6 +1,7 @@
class Hydrant < ActiveRecord::Base
validates_presence_of :lat, :lng
belongs_to :user
has_many :reminders
def self.find_closest(lat, lng, limit=50)
query = <<-SQL

6
app/models/reminder.rb Normal file
View File

@ -0,0 +1,6 @@
class Reminder < ActiveRecord::Base
validates_presence_of :from_user, :to_user, :hydrant
belongs_to :from_user, :class_name => "User"
belongs_to :to_user, :class_name => "User"
belongs_to :hydrant
end

View File

@ -3,4 +3,6 @@ class User < ActiveRecord::Base
attr_accessible :email, :name, :organization, :voice_number, :sms_number, :password, :password_confirmation, :remember_me
validates_presence_of :name
has_many :hydrants
has_many :reminders_to, :class_name => "Reminder", :foreign_key => "to_user_id"
has_many :reminders_from, :class_name => "Reminder", :foreign_key => "from_user_id"
end

View File

@ -1,5 +1,5 @@
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
def change
create_table :users do |t|
t.timestamps
t.string :name, :null => false
@ -16,8 +16,4 @@ class DeviseCreateUsers < ActiveRecord::Migration
add_index :users, :email, :unique => true
add_index :users, :reset_password_token, :unique => true
end
def self.down
drop_table :users
end
end

View File

@ -1,5 +1,5 @@
class CreateHydrants < ActiveRecord::Migration
def self.up
def change
create_table :hydrants do |t|
t.timestamps
t.string :name
@ -8,10 +8,7 @@ class CreateHydrants < ActiveRecord::Migration
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

@ -0,0 +1,14 @@
class CreateReminders < ActiveRecord::Migration
def change
create_table :reminders do |t|
t.timestamps
t.integer :from_user_id, :null => false
t.integer :to_user_id, :null => false
t.integer :hydrant_id, :null => false
end
add_index :reminders, :from_user_id
add_index :reminders, :to_user_id
add_index :reminders, :hydrant_id
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110223180521) do
ActiveRecord::Schema.define(:version => 3) do
create_table "hydrants", :force => true do |t|
t.datetime "created_at"
@ -24,6 +24,18 @@ ActiveRecord::Schema.define(:version => 20110223180521) do
add_index "hydrants", ["city_id"], :name => "index_hydrants_on_city_id", :unique => true
create_table "reminders", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.integer "from_user_id", :null => false
t.integer "to_user_id", :null => false
t.integer "hydrant_id", :null => false
end
add_index "reminders", ["from_user_id"], :name => "index_reminders_on_from_user_id"
add_index "reminders", ["hydrant_id"], :name => "index_reminders_on_hydrant_id"
add_index "reminders", ["to_user_id"], :name => "index_reminders_on_to_user_id"
create_table "users", :force => true do |t|
t.datetime "created_at"
t.datetime "updated_at"

5
test/fixtures/reminders.yml vendored Normal file
View File

@ -0,0 +1,5 @@
---
reminder_1:
from_user: erik
to_user: dan
hydrant: hydrant_1

View File

@ -6,3 +6,12 @@ erik:
voice_number: 1234567890
sms_number: 1234567890
encrypted_password: "$2a$10$KF/JMZ494ZLhWLgHZeBTf.cSL4l0Wjij4gIZP7BzkueAC1p4nW0ma"
dan:
name: Dan Melton
organization: Code for America
email: dan@example.com
voice_number: 1234567890
sms_number: 1234567890
encrypted_password: "$2a$10$KF/JMZ494ZLhWLgHZeBTf.cSL4l0Wjij4gIZP7BzkueAC1p4nW0ma"