From 3978fec3d60b91235786d33c7051440ac2e60a0f Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 12 Aug 2013 03:31:42 -0400 Subject: [PATCH] Dump of some setup but no feature adds --- app/models/lift.rb | 7 +++++++ app/models/workout.rb | 2 ++ db/migrate/20130811184122_create_lifts.rb | 13 +++++++++++++ .../20130811190304_fix_association_in_lifts.rb | 9 +++++++++ db/schema.rb | 12 +++++++++++- spec/factories/lifts.rb | 11 +++++++++++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/models/lift.rb create mode 100644 db/migrate/20130811184122_create_lifts.rb create mode 100644 db/migrate/20130811190304_fix_association_in_lifts.rb create mode 100644 spec/factories/lifts.rb diff --git a/app/models/lift.rb b/app/models/lift.rb new file mode 100644 index 0000000..97e27bd --- /dev/null +++ b/app/models/lift.rb @@ -0,0 +1,7 @@ +class Lift < ActiveRecord::Base + belongs_to :workout + + LIFTS = [:sqaut, :benchpress, :bentoverrow, :overheadpress, + :straightlegdeadlift, :uprightrow, :calfraise ] + validates_inclusion_of :lift, :in => Lift::LIFTS +end diff --git a/app/models/workout.rb b/app/models/workout.rb index 9153d1f..759a231 100644 --- a/app/models/workout.rb +++ b/app/models/workout.rb @@ -1,4 +1,6 @@ class Workout < ActiveRecord::Base + has_many :lifts, dependent: :destroy + DAY_TYPES = [:heavy, :medium, :light ] validates_date :date validates_inclusion_of :day_type, :in => Workout::DAY_TYPES diff --git a/db/migrate/20130811184122_create_lifts.rb b/db/migrate/20130811184122_create_lifts.rb new file mode 100644 index 0000000..d57e16e --- /dev/null +++ b/db/migrate/20130811184122_create_lifts.rb @@ -0,0 +1,13 @@ +class CreateLifts < ActiveRecord::Migration + def change + create_table :lifts do |t| + t.integer :parent_workout + t.string :lift_type + t.integer :sets + t.integer :repititions + t.text :comment + + t.timestamps + end + end +end diff --git a/db/migrate/20130811190304_fix_association_in_lifts.rb b/db/migrate/20130811190304_fix_association_in_lifts.rb new file mode 100644 index 0000000..2937e3a --- /dev/null +++ b/db/migrate/20130811190304_fix_association_in_lifts.rb @@ -0,0 +1,9 @@ +class FixAssociationInLifts < ActiveRecord::Migration + def self.up + rename_column :lifts, :parent_workout, :workout_id + end + + def self.down + rename_column :lifts, :workout_id, :parent_workout + end +end diff --git a/db/schema.rb b/db/schema.rb index 2a1942f..4d480f3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,17 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20130811021123) do +ActiveRecord::Schema.define(version: 20130811190304) do + + create_table "lifts", force: true do |t| + t.integer "workout_id" + t.string "lift_type" + t.integer "sets" + t.integer "repititions" + t.text "comment" + t.datetime "created_at" + t.datetime "updated_at" + end create_table "workouts", force: true do |t| t.date "date" diff --git a/spec/factories/lifts.rb b/spec/factories/lifts.rb new file mode 100644 index 0000000..d29bb1e --- /dev/null +++ b/spec/factories/lifts.rb @@ -0,0 +1,11 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :lift do + parent_workout 1 + lift_type "MyString" + sets 1 + repititions 1 + comment "MyText" + end +end