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:
@@ -1,6 +1,7 @@
|
|||||||
class PaidTimeOff < ActiveRecord::Base
|
class PaidTimeOff < ActiveRecord::Base
|
||||||
attr_accessible :pto_earned, :pto_taken, :sick_days_earned, :sick_days_taken, :user_id
|
attr_accessible :pto_earned, :pto_taken, :sick_days_earned, :sick_days_taken, :user_id
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
has_one :schedule, :foreign_key => :user_id, :primary_key => :user_id
|
||||||
|
|
||||||
# Refactor this duplication when it's not 3am
|
# Refactor this duplication when it's not 3am
|
||||||
def sick_days_remaining(val="")
|
def sick_days_remaining(val="")
|
||||||
|
|||||||
@@ -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
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# 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|
|
create_table "paid_time_offs", :force => true do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
@@ -32,6 +32,17 @@ ActiveRecord::Schema.define(:version => 20130525001150) do
|
|||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
end
|
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|
|
create_table "users", :force => true do |t|
|
||||||
t.string "email"
|
t.string "email"
|
||||||
t.string "password"
|
t.string "password"
|
||||||
|
|||||||
+24
@@ -105,6 +105,26 @@ paid_time_off = [
|
|||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
schedule = [
|
||||||
|
{
|
||||||
|
:user_id => 2,
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:user_id => 3,
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:user_id => 4,
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:user_id => 5,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
users.each do |user_info|
|
users.each do |user_info|
|
||||||
User.create!(user_info)
|
User.create!(user_info)
|
||||||
@@ -117,3 +137,7 @@ end
|
|||||||
paid_time_off.each do |pto|
|
paid_time_off.each do |pto|
|
||||||
PaidTimeOff.create!(pto)
|
PaidTimeOff.create!(pto)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
schedule.each do |event|
|
||||||
|
Schedule.create!(event)
|
||||||
|
end
|
||||||
Vendored
+17
@@ -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
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ScheduleTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user