Commit 359190d

mo khan <mo@mokhan.ca>
2016-06-27 02:40:07
add a spec for starting a new workout.
1 parent 886f2b8
Changed files (3)
app
views
spec
app/views/workouts/_workout.jbuilder
@@ -1,7 +1,7 @@
 json.id workout.id
 json.body_weight workout.body_weight
 json.routine_name workout.routine.name
-json.exercises workout.sets.order(:created_at).group_by(&:exercise) do |exercise, sets|
+json.exercises workout.sets.includes(:exercise).order(:created_at).group_by(&:exercise) do |exercise, sets|
   json.id exercise.id
   json.name exercise.name
   json.sets sets.sort_by(&:created_at) do |set|
spec/features/workouts_spec.rb
@@ -1,19 +1,33 @@
 require "rails_helper"
 
 feature "Workouts", type: :feature do
-  include_context "stronglifts_program"
-  subject { WorkoutsPage.new }
   let(:user) { create(:user, password: "password") }
-  let!(:workout) { create(:workout, user: user, routine: routine_a, occurred_at: DateTime.now, body_weight: 210.0) }
-
   before :each do
     subject.login_with(user.username, "password")
-    subject.visit_page
   end
 
-  describe "view training history" do
+  feature "viewing history" do
+    include_context "stronglifts_program"
+    subject { WorkoutsPage.new }
+    let!(:workout) { create(:workout, user: user, routine: routine_a, occurred_at: DateTime.now, body_weight: 210.0) }
+
     it "displays each training session" do
+      subject.visit_page
       expect(page).to have_content(workout.occurred_at.strftime("%a, %d %b"))
     end
   end
+
+  feature "starting a new workout" do
+    include_context "stronglifts_program"
+    subject { NewWorkoutPage.new }
+
+    it 'creates a new workout' do
+      subject.visit_page
+      subject.change_body_weight(225.0)
+      subject.click_start
+
+      expect(user.workouts.count).to eql(1)
+    end
+
+  end
 end
spec/support/pages/new_workout_page.rb
@@ -0,0 +1,17 @@
+require_relative "../page_model.rb"
+
+class NewWorkoutPage < PageModel
+  def initialize
+    super new_workout_path
+  end
+
+  def change_body_weight(weight)
+    within "#new_workout" do
+      fill_in 'workout_body_weight', with: weight
+    end
+  end
+
+  def click_start
+    click_button 'Start'
+  end
+end