I am setting this up, in this way, so that we have some extensibility. We may wish to have some sort of a polymorphic association where multiple models need to have a scheduling model available to them. That being said, as of right now, only the pto model needs it so I am doing a belong_to and has_one association between the two

This commit is contained in:
Ken Johnson
2013-05-27 13:09:33 -04:00
parent 8bfdf45ff9
commit 21752fab7e
7 changed files with 79 additions and 1 deletions
+1
View File
@@ -1,6 +1,7 @@
class PaidTimeOff < ActiveRecord::Base
attr_accessible :pto_earned, :pto_taken, :sick_days_earned, :sick_days_taken, :user_id
belongs_to :user
has_one :schedule, :foreign_key => :user_id, :primary_key => :user_id
# Refactor this duplication when it's not 3am
def sick_days_remaining(val="")
+4
View File
@@ -0,0 +1,4 @@
class Schedule < ActiveRecord::Base
attr_accessible :date_begin, :date_end, :event_desc, :event_name, :event_type, :user_id
belongs_to :paid_time_off
end
@@ -0,0 +1,14 @@
class CreateSchedules < ActiveRecord::Migration
def change
create_table :schedules do |t|
t.string :event_type
t.date :date_begin
t.date :date_end
t.string :event_name
t.string :event_desc
t.integer :user_id
t.timestamps
end
end
end
+12 -1
View File
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130525001150) do
ActiveRecord::Schema.define(:version => 20130527165832) do
create_table "paid_time_offs", :force => true do |t|
t.integer "user_id"
@@ -32,6 +32,17 @@ ActiveRecord::Schema.define(:version => 20130525001150) do
t.datetime "updated_at", :null => false
end
create_table "schedules", :force => true do |t|
t.string "event_type"
t.date "date_begin"
t.date "date_end"
t.string "event_name"
t.string "event_desc"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "email"
t.string "password"
+24
View File
@@ -104,6 +104,26 @@ paid_time_off = [
}
]
schedule = [
{
:user_id => 2,
},
{
:user_id => 3,
},
{
:user_id => 4,
},
{
:user_id => 5,
}
]
users.each do |user_info|
@@ -116,4 +136,8 @@ end
paid_time_off.each do |pto|
PaidTimeOff.create!(pto)
end
schedule.each do |event|
Schedule.create!(event)
end
+17
View File
@@ -0,0 +1,17 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
event_type: MyString
date_begin: 2013-05-27
date_end: 2013-05-27
event_name: MyString
event_desc: MyString
user_id: 1
two:
event_type: MyString
date_begin: 2013-05-27
date_end: 2013-05-27
event_name: MyString
event_desc: MyString
user_id: 1
+7
View File
@@ -0,0 +1,7 @@
require 'test_helper'
class ScheduleTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end