Add more fields to workout

This commit is contained in:
Andrew Tomaka 2013-08-10 22:15:26 -04:00
parent 6b377a577e
commit 1fc9dda21f
9 changed files with 57 additions and 5 deletions

View file

@ -1,3 +1,5 @@
class Workout < ActiveRecord::Base
DAY_TYPES = %w(heavy medium light)
validates_date :date
validates_inclusion_of :day_type, :in => Workout::DAY_TYPES
end

View file

@ -6,7 +6,21 @@
<% end %>
</ul>
<% end %>
<%= f.label :date %>
<%= f.text_field :date %>
<%= f.submit nil %>
<div>
<%= f.label :date %>
<%= f.text_field :date %>
</div>
<div>
<%= f.label :day_type %>
<%= f.select :day_type, [["Heavy", 'heavy'], ["Medium", 'medium'],
["Light", 'light']] %>
</div>
<div>
<%= f.label :comment %>
<%= f.text_area :comment, rows: 7, cols: 60 %>
</div>
<div>
<%= f.submit nil %>
</div>
<% end %>

View file

@ -1 +1,3 @@
<%= @workout.date %>
<%= @workout.date %><br/>
<%= @workout.day_type %><br/>
<%= @workout.comment %><br/>

View file

@ -0,0 +1,11 @@
class AddFieldsToWorkout < ActiveRecord::Migration
def self.up
add_column :workouts, :comment, :text, :null => false, :default => ''
add_column :workouts, :type, :string, :null => false, :default => 'Heavy'
end
def self.down
remove_column :workouts, :comment
remove_column :workouts, :type
end
end

View file

@ -0,0 +1,9 @@
class ChangeColTypeInWorkouts < ActiveRecord::Migration
def self.up
rename_column :workouts, :type, :day_type
end
def self.down
rename_column :workouts, :day_type, :type
end
end

View file

@ -0,0 +1,9 @@
class ChangeDayTypeInWorkotus < ActiveRecord::Migration
def self.up
change_column_default :workouts, :day_type, 'heavy'
end
def self.down
change_column_default :workouts, :day_type, 'Heavy'
end
end

View file

@ -11,12 +11,14 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20130810061810) do
ActiveRecord::Schema.define(version: 20130811021123) do
create_table "workouts", force: true do |t|
t.date "date"
t.datetime "created_at"
t.datetime "updated_at"
t.text "comment", default: "", null: false
t.string "day_type", default: "heavy", null: false
end
end

View file

@ -3,5 +3,6 @@
FactoryGirl.define do
factory :workout do
date Time.now
day_type { %w(heavy medium light).sample }
end
end

View file

@ -63,6 +63,7 @@ describe "Workouts" do
click_link 'Create'
fill_in 'Date', :with => Date.today
select 'Heavy', :from => 'Day type'
click_button 'Create Workout'
page.should have_content 'Workout created'
@ -83,6 +84,7 @@ describe "Workouts" do
visit workouts_path
click_link 'Create'
fill_in 'Date', :with => '2013-13-13'
select 'Heavy', :from => 'Day type'
click_button 'Create Workout'
page.should have_content "Date is not a valid date"