Add more fields to workout
This commit is contained in:
parent
6b377a577e
commit
1fc9dda21f
9 changed files with 57 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
<%= @workout.date %>
|
||||
<%= @workout.date %><br/>
|
||||
<%= @workout.day_type %><br/>
|
||||
<%= @workout.comment %><br/>
|
||||
|
|
11
db/migrate/20130810191419_add_fields_to_workout.rb
Normal file
11
db/migrate/20130810191419_add_fields_to_workout.rb
Normal 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
|
9
db/migrate/20130810192652_change_col_type_in_workouts.rb
Normal file
9
db/migrate/20130810192652_change_col_type_in_workouts.rb
Normal 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
|
9
db/migrate/20130811021123_change_day_type_in_workotus.rb
Normal file
9
db/migrate/20130811021123_change_day_type_in_workotus.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :workout do
|
||||
date Time.now
|
||||
day_type { %w(heavy medium light).sample }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue