Commit 5f98e6b

mo khan <mo@mokhan.ca>
2016-06-30 04:05:40
add the next warmup set.
1 parent 4fe3b12
Changed files (2)
app/models/user_recommendation.rb
@@ -11,15 +11,23 @@ class UserRecommendation
     target_weight = next_weight
     warm_up_sets = []
     if target_weight >= 65.lbs
-       2.times.map do
+      2.times.map do
         warm_up_sets << ExerciseSet.new(
           type: :warm_up,
           exercise: exercise,
           target_weight: 45.lbs,
-          #target_repetitions: repetitions,
+          target_repetitions: 5,
         )
       end
     end
+    if target_weight >= 95.lbs
+      warm_up_sets << ExerciseSet.new(
+        type: :warm_up,
+        exercise: exercise,
+        target_weight: 65.lbs,
+        target_repetitions: 3,
+      )
+    end
     work_sets = sets.times.map do
       ExerciseSet.new(
         type: :work,
@@ -31,7 +39,6 @@ class UserRecommendation
     (warm_up_sets + work_sets).compact
   end
 
-
   def repetitions
     recommendation.repetitions
   end
spec/models/program_spec.rb
@@ -82,7 +82,22 @@ describe Program do
             warmup_sets = sets.find_all { |x| x.warm_up? }
             expect(warmup_sets.length).to eql(2)
             expect(warmup_sets.at(0).target_weight.lbs).to eql(45.lbs)
+            expect(warmup_sets.at(0).target_repetitions).to eql(5)
             expect(warmup_sets.at(1).target_weight.lbs).to eql(45.lbs)
+            expect(warmup_sets.at(1).target_repetitions).to eql(5)
+          end
+        end
+
+        describe "when the work set is between 95 lbs and 105 lbs" do
+          it 'returns another warm up set' do
+            workout = create(:workout, user: user, routine: routine_a)
+            5.times { |n| workout.train(squat, 95, repetitions: 5) }
+
+            sets = subject.prepare_sets_for(user, squat)
+            warmup_sets = sets.find_all { |x| x.warm_up? }
+            expect(warmup_sets.length).to eql(3)
+            expect(warmup_sets.at(2).target_weight.lbs).to eql(65.lbs)
+            expect(warmup_sets.at(2).target_repetitions).to eql(3)
           end
         end
       end