2013-08-04 20:58:01 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe "Workouts" do
|
2013-08-10 02:31:46 -04:00
|
|
|
before :each do
|
2013-08-04 20:58:01 -04:00
|
|
|
@workout = FactoryGirl.create(:workout)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /workouts" do
|
|
|
|
it "should return workouts" do
|
|
|
|
visit workouts_path
|
|
|
|
page.should have_content @workout.date
|
|
|
|
end
|
|
|
|
end
|
2013-08-04 21:51:46 -04:00
|
|
|
|
|
|
|
describe "GET /workouts/(:id)" do
|
2013-08-04 23:40:58 -04:00
|
|
|
it "should visit a workout" do
|
|
|
|
visit workouts_path
|
|
|
|
click_link @workout.date
|
|
|
|
|
|
|
|
current_path.should == workout_path(@workout.id)
|
|
|
|
page.should have_content @workout.date
|
|
|
|
end
|
|
|
|
|
2013-08-04 21:51:46 -04:00
|
|
|
it "should return the correct workout" do
|
|
|
|
visit "#{workouts_path}/#{@workout.id}"
|
|
|
|
page.should have_content @workout.date
|
|
|
|
end
|
|
|
|
end
|
2013-08-05 01:07:11 -04:00
|
|
|
|
2013-08-10 08:36:43 -04:00
|
|
|
describe "GET /workouts/(:id)" do
|
|
|
|
it "should show the edit form" do
|
2013-08-05 01:07:11 -04:00
|
|
|
visit workouts_path
|
|
|
|
find("#workout_#{@workout.id}").click_link 'Edit'
|
2013-08-10 02:11:11 -04:00
|
|
|
|
2013-08-05 01:07:11 -04:00
|
|
|
current_path.should == edit_workout_path(@workout)
|
|
|
|
end
|
|
|
|
end
|
2013-08-10 08:36:43 -04:00
|
|
|
|
|
|
|
describe "PUT /workouts/edit/(:id)" do
|
|
|
|
it 'should update a workout' do
|
|
|
|
visit workouts_path
|
|
|
|
find("#workout_#{@workout.id}").click_link 'Edit'
|
|
|
|
|
|
|
|
fill_in 'Date', :with => Date.today
|
|
|
|
click_button 'Update Workout'
|
|
|
|
|
|
|
|
page.should have_content 'Workout updated'
|
|
|
|
end
|
2013-08-11 13:35:08 -04:00
|
|
|
|
|
|
|
it "should not edit with bad data" do
|
|
|
|
visit workouts_path
|
|
|
|
find("#workout_#{@workout.id}").click_link 'Edit'
|
|
|
|
|
|
|
|
fill_in 'Date', :with => '2013-13-13'
|
|
|
|
click_button 'Update Workout'
|
|
|
|
|
|
|
|
page.should have_content "Date is not a valid date"
|
|
|
|
end
|
2013-08-10 08:36:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /workouts/new" do
|
|
|
|
it "should show the create workout form" do
|
|
|
|
visit workouts_path
|
|
|
|
click_link 'Create'
|
|
|
|
|
|
|
|
current_path.should == new_workout_path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /workouts/create" do
|
|
|
|
it "should create a new workout" do
|
|
|
|
visit workouts_path
|
|
|
|
click_link 'Create'
|
|
|
|
|
|
|
|
fill_in 'Date', :with => Date.today
|
2013-08-10 22:15:26 -04:00
|
|
|
select 'Heavy', :from => 'Day type'
|
2013-08-10 08:36:43 -04:00
|
|
|
click_button 'Create Workout'
|
|
|
|
|
|
|
|
page.should have_content 'Workout created'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have a working javascript datepicker", :js => true do
|
|
|
|
visit workouts_path
|
|
|
|
click_link 'Create'
|
|
|
|
|
|
|
|
page.execute_script %Q{ $('#workout_date').trigger("focus") }
|
|
|
|
page.execute_script %Q{ $("a.ui-state-default:contains('10')").trigger("click") }
|
|
|
|
click_button 'Create Workout'
|
|
|
|
|
|
|
|
page.should have_content 'Workout created'
|
|
|
|
end
|
|
|
|
|
2013-08-10 09:24:49 -04:00
|
|
|
it "should only accept real dates" do
|
2013-08-10 08:36:43 -04:00
|
|
|
visit workouts_path
|
|
|
|
click_link 'Create'
|
2013-08-10 09:24:49 -04:00
|
|
|
fill_in 'Date', :with => '2013-13-13'
|
2013-08-10 22:15:26 -04:00
|
|
|
select 'Heavy', :from => 'Day type'
|
2013-08-10 08:36:43 -04:00
|
|
|
click_button 'Create Workout'
|
|
|
|
|
2013-08-10 09:24:49 -04:00
|
|
|
page.should have_content "Date is not a valid date"
|
2013-08-10 08:36:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "DELETE /workouts/(:id)" do
|
|
|
|
it 'should delete a workout' do
|
|
|
|
visit workouts_path
|
|
|
|
find("#workout_#{@workout.id}").click_link 'Delete'
|
|
|
|
|
|
|
|
page.should have_content 'Workout deleted'
|
|
|
|
end
|
|
|
|
end
|
2013-08-04 20:58:01 -04:00
|
|
|
end
|
2013-08-10 08:36:43 -04:00
|
|
|
|