Commit 844500c

mo khan <mo@mokhan.ca>
2016-07-01 14:57:47
hound happy.
1 parent 2f1ef15
app/assets/javascripts/views/workout_view.js.coffee
@@ -29,7 +29,8 @@ class Stronglifters.WorkoutView extends Ractive
     model.save()
 
     if model.successful()
-      @displayMessage("If it was easy break for 1:30, otherwise rest for 3:00.", 'radius')
+      message = "If it was easy break for 1:30, otherwise rest for 3:00."
+      @displayMessage(message, 'radius')
     else
       @displayMessage("Take a 5:00 break.", 'alert')
     @clock.start()
app/controllers/workouts_controller.rb
@@ -10,7 +10,9 @@ class WorkoutsController < ApplicationController
   end
 
   def create
-    workout = current_user.workouts.create!(secure_params.merge!(occurred_at: DateTime.now))
+    workout = current_user.workouts.create!(
+      secure_params.merge!(occurred_at: DateTime.now)
+    )
     redirect_to edit_workout_path(workout)
   end
 
app/models/quantity.rb
@@ -7,7 +7,10 @@ class Quantity
   end
 
   def to(target_unit)
-    Quantity.new(UnitOfMeasure.for(target_unit).convert(amount, unit), target_unit)
+    Quantity.new(
+      UnitOfMeasure.for(target_unit).convert(amount, unit),
+      target_unit
+    )
   end
 
   def to_f
app/models/routine.rb
@@ -31,5 +31,6 @@ class Routine < ActiveRecord::Base
     exercises.each do |exercise|
       workout.exercise_sets << program.prepare_sets_for(user, exercise)
     end
+    workout
   end
 end
app/models/user.rb
@@ -90,10 +90,9 @@ class User < ActiveRecord::Base
   end
 
   def next_workout_for(routine = next_routine)
-    last_body_weight = last_workout.try(:body_weight)
-    workouts.build(routine: routine, body_weight: last_body_weight.to(preferred_units)).tap do |workout|
-      routine.prepare_sets_for(self, workout)
-    end
+    last_body_weight = last_workout.try(:body_weight).to(preferred_units)
+    workout = workouts.build(routine: routine, body_weight: last_body_weight)
+    routine.prepare_sets_for(self, workout)
   end
 
   def last_workout(exercise = nil)
spec/controllers/workouts_controller_spec.rb
@@ -51,7 +51,7 @@ describe WorkoutsController do
       expect(response).to redirect_to(edit_workout_path(user.workouts.last))
     end
 
-    it 'creates the workout with the selected exercises' do
+    it "creates the workout with the selected exercises" do
       post :create, workout: {
         routine_id: routine_b.id,
         body_weight: body_weight,
@@ -59,7 +59,7 @@ describe WorkoutsController do
           exercise_id: squat.id,
           target_repetitions: 5,
           target_weight: 200,
-          type: 'WorkSet',
+          type: "WorkSet",
         }]
       }
 
spec/models/csv/import_spec.rb
@@ -127,7 +127,7 @@ describe Csv::Import do
       expect(progress.sets.at(2).actual_repetitions).to eql(2)
     end
 
-    it 'imports the correct number of sets' do
+    it "imports the correct number of sets" do
       row = ["06/05/16", "", "B", "101.93", "225", "Squat", "125", "275", "5", "5", "5", "", "", "Overhead press", "57.5", "125", "5", "5", "5", "5", "5", "Deadlift", "127.5", "285", "5", "", "", "" , "", "", "", "", "", ""]
 
       subject.import(row)
spec/models/backup_file_spec.rb
@@ -22,10 +22,11 @@ describe BackupFile do
 
   describe "#process_later" do
     let(:program) { build(:program) }
+    let(:csv) { fixture_file("spreadsheet-stronglifts.csv") }
 
     it "creates a job to process later" do
       allow(UploadStrongliftsBackupJob).to receive(:perform_later)
-      subject = BackupFile.new(user, fixture_file("spreadsheet-stronglifts.csv"))
+      subject = BackupFile.new(user, csv)
       subject.process_later(program)
       expect(UploadStrongliftsBackupJob).to have_received(:perform_later)
     end
spec/models/quantity_spec.rb
@@ -1,53 +1,53 @@
-require 'spec_helper'
+require "spec_helper"
 
 describe Quantity do
   describe "#to" do
-    it 'converts lbs to kgs' do
+    it "converts lbs to kgs" do
       lbs = Quantity.new(135.0, :lbs)
       expect(lbs.to(:kg).to_f.round(1)).to eql(61.2)
     end
 
-    it 'converts kgs to kgs' do
+    it "converts kgs to kgs" do
       kgs = Quantity.new(135.0, :kgs)
       expect(kgs.to(:kgs).to_f).to eql(135.0)
     end
 
-    it 'converts kgs to lbs' do
+    it "converts kgs to lbs" do
       kgs = Quantity.new(61.2, :kgs)
       expect(kgs.to(:lbs).to_f.round(0)).to eql(135)
     end
 
-    it 'converts lbs to lbs' do
+    it "converts lbs to lbs" do
       lbs = Quantity.new(135.0, :lbs)
       expect(lbs.to(:lbs).to_f).to eql(135.0)
     end
   end
 
   describe "#eql?" do
-    it 'is equal when both are lbs' do
+    it "is equal when both are lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(135.0, :lbs)
       expect(quantity).to eql(other)
     end
 
-    it 'is equal when both are kgs' do
+    it "is equal when both are kgs" do
       quantity = Quantity.new(61.2, :kgs)
       other = Quantity.new(61.2, :kgs)
       expect(quantity).to eql(other)
     end
 
-    it 'is equal when different units' do
+    it "is equal when different units" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(61.2, :kgs)
       expect(quantity).to eql(other)
     end
 
-    it 'is equal to a float' do
+    it "is equal to a float" do
       quantity = Quantity.new(135.0, :lbs)
       expect(quantity).to eql(135.0)
     end
 
-    it 'is not equal' do
+    it "is not equal" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(135.2, :lbs)
       expect(quantity).to_not eql(other)
@@ -55,25 +55,25 @@ describe Quantity do
   end
 
   describe "#+" do
-    it 'adds lbs to lbs' do
+    it "adds lbs to lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(135.0, :lbs)
       expect(quantity + other).to eql(Quantity.new(270.0, :lbs))
     end
 
-    it 'adds kgs to lbs' do
+    it "adds kgs to lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(61.2, :kg)
       expect(quantity + other).to eql(Quantity.new(270.0, :lbs))
     end
 
-    it 'adds lbs to kgs' do
+    it "adds lbs to kgs" do
       quantity = Quantity.new(61.2, :kg)
       other = Quantity.new(135.0, :lbs)
       expect(quantity + other).to eql(Quantity.new(122.4, :kg))
     end
 
-    it 'adds a float to lbs' do
+    it "adds a float to lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = 135.0
       expect(quantity + other).to eql(Quantity.new(270.0, :lbs))
@@ -81,25 +81,25 @@ describe Quantity do
   end
 
   describe "#-" do
-    it 'subtracts lbs from lbs' do
+    it "subtracts lbs from lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(135.0, :lbs)
       expect(quantity - other).to eql(Quantity.new(0.0, :lbs))
     end
 
-    it 'subtracts kgs from lbs' do
+    it "subtracts kgs from lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(61.2, :kg)
       expect(quantity - other).to eql(Quantity.new(0.0, :lbs))
     end
 
-    it 'subtracts lbs from kgs' do
+    it "subtracts lbs from kgs" do
       quantity = Quantity.new(61.2, :kg)
       other = Quantity.new(135.0, :lbs)
       expect(quantity - other).to eql(Quantity.new(0.0, :kg))
     end
 
-    it 'subtracts a float from lbs' do
+    it "subtracts a float from lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = 135.0
       expect(quantity - other).to eql(Quantity.new(0.0, :lbs))
@@ -107,25 +107,25 @@ describe Quantity do
   end
 
   describe "#/" do
-    it 'divides lbs from lbs' do
+    it "divides lbs from lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(135.0, :lbs)
       expect(quantity / other).to eql(Quantity.new(1.0, :lbs))
     end
 
-    it 'divides kgs from lbs' do
+    it "divides kgs from lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(61.2, :kg)
       expect(quantity / other).to eql(Quantity.new(1.0, :lbs))
     end
 
-    it 'divides lbs from kgs' do
+    it "divides lbs from kgs" do
       quantity = Quantity.new(61.2, :kg)
       other = Quantity.new(135.0, :lbs)
       expect(quantity / other).to eql(Quantity.new(1.0, :kg))
     end
 
-    it 'divides a float from lbs' do
+    it "divides a float from lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = 135.0
       expect(quantity / other).to eql(Quantity.new(1.0, :lbs))
@@ -133,13 +133,13 @@ describe Quantity do
   end
 
   describe "#*" do
-    it 'multiples lbs with lbs' do
+    it "multiples lbs with lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = Quantity.new(135.0, :lbs)
       expect(quantity * other).to eql(Quantity.new(18_225.0, :lbs))
     end
 
-    it 'multiples a float with lbs' do
+    it "multiples a float with lbs" do
       quantity = Quantity.new(135.0, :lbs)
       other = 135.0
       expect(quantity * other).to eql(Quantity.new(18_225.0, :lbs))
@@ -147,7 +147,7 @@ describe Quantity do
   end
 
   describe "#>" do
-    it 'compares lbs with lbs' do
+    it "compares lbs with lbs" do
       quantity = Quantity.new(135.1, :lbs)
       other = Quantity.new(135.0, :lbs)
       expect(quantity).to be > other
@@ -156,7 +156,7 @@ describe Quantity do
   end
 
   describe "#>=" do
-    it 'compares lbs with lbs' do
+    it "compares lbs with lbs" do
       quantity = Quantity.new(135.2, :lbs)
       other = Quantity.new(135.0, :lbs)
       expect(quantity).to be >= quantity
@@ -166,7 +166,7 @@ describe Quantity do
   end
 
   describe "#<" do
-    it 'compares lbs with lbs' do
+    it "compares lbs with lbs" do
       quantity = Quantity.new(135.1, :lbs)
       other = Quantity.new(135.0, :lbs)
       expect(quantity).to_not be < other
spec/models/user_spec.rb
@@ -233,19 +233,19 @@ describe User do
     let(:routine) { create(:routine) }
     let(:body_weight) { rand(300) }
 
-    it 'includes the body weight from the previous workout' do
+    it "includes the body weight from the previous workout" do
       create(:workout, user: subject, body_weight: body_weight)
 
       workout = subject.next_workout_for(routine)
       expect(workout.body_weight).to eql(body_weight)
     end
 
-    it 'uses the correct routine' do
+    it "uses the correct routine" do
       workout = subject.next_workout_for(routine)
       expect(workout.routine).to eql(routine)
     end
 
-    it 'prepares the correct number of sets' do
+    it "prepares the correct number of sets" do
       squat = create(:exercise)
       routine.add_exercise(squat, sets: 3)
       workout = subject.next_workout_for(routine)
@@ -257,12 +257,12 @@ describe User do
     include_context "stronglifts_program"
     subject { create(:user) }
 
-    it 'routines the next workout' do
+    it "routines the next workout" do
       create(:workout, routine: routine_a, user: subject)
       expect(subject.next_routine).to eql(routine_b)
     end
 
-    it 'returns the first routine in the program' do
+    it "returns the first routine in the program" do
       expect(subject.next_routine).to eql(routine_a)
     end
   end
@@ -271,12 +271,12 @@ describe User do
     include_context "stronglifts_program"
     subject { create(:user) }
 
-    it 'returns the last workout' do
+    it "returns the last workout" do
       workout = create(:workout, user: subject, routine: routine_a)
       expect(subject.last_workout).to eql(workout)
     end
 
-    it 'returns the last workout that included a specific exercise' do
+    it "returns the last workout that included a specific exercise" do
       deadlift_workout = create(:workout, user: subject, routine: routine_b)
       deadlift_workout.train(deadlift, 315.lbs, repetitions: 5)
       bench_workout = create(:workout, user: subject, routine: routine_a)
@@ -285,11 +285,11 @@ describe User do
       expect(subject.last_workout(deadlift)).to eql(deadlift_workout)
     end
 
-    it 'returns nil when no workouts have been completed' do
+    it "returns nil when no workouts have been completed" do
       expect(subject.last_workout).to be_nil
     end
 
-    it 'returns nil when the exercise has not been performed' do
+    it "returns nil when the exercise has not been performed" do
       bench_workout = create(:workout, user: subject, routine: routine_a)
       bench_workout.train(bench_press, 195.lbs, repetitions: 5)
 
spec/models/warm_up_spec.rb
@@ -1,9 +1,9 @@
-require 'rails_helper'
+require "rails_helper"
 
 describe WarmUp do
   describe ".new" do
     describe "squat" do
-      let(:squat) { build(:exercise, name: 'Squat') }
+      let(:squat) { build(:exercise, name: "Squat") }
 
       (45..60).step(5).each do |target_weight|
         it "has zero warm up sets" do
@@ -37,7 +37,7 @@ describe WarmUp do
     end
 
     describe "barbell row" do
-      let(:barbell_row) { build(:exercise, name: 'Barbell Row') }
+      let(:barbell_row) { build(:exercise, name: "Barbell Row") }
 
       (45..100).step(5).each do |target_weight|
         it "has zero warm up sets" do
@@ -67,7 +67,7 @@ describe WarmUp do
     end
 
     describe "deadlift" do
-      let(:deadlift) { build(:exercise, name: 'Deadlift') }
+      let(:deadlift) { build(:exercise, name: "Deadlift") }
 
       (45..150).step(5).each do |target_weight|
         it "has zero warm up sets at #{target_weight} lbs" do
spec/models/workout_spec.rb
@@ -24,7 +24,7 @@ describe Workout, type: :model do
       expect(subject.sets.at(0).actual_repetitions).to eql(5)
     end
 
-    it 'records the next set' do
+    it "records the next set" do
       subject.train(squat, target_weight, repetitions: 5)
       result = subject.train(squat, target_weight, repetitions: 3)
 
spec/support/pages/edit_workout_page.rb
@@ -9,7 +9,7 @@ class EditWorkoutPage < PageModel
     click_link(exercise.name)
   end
 
-  def complete(set: , repetitions: 5)
+  def complete(set:, repetitions: 5)
     click_map = { 5 => 1, 4 => 2, 3 => 3, 2 => 4, 1 => 5 }
     click_map[repetitions].times do
       find_by_id(set.id).click
spec/support/pages/new_workout_page.rb
@@ -7,11 +7,11 @@ class NewWorkoutPage < PageModel
 
   def change_body_weight(weight)
     within "#new_workout" do
-      fill_in 'workout_body_weight', with: weight
+      fill_in "workout_body_weight", with: weight
     end
   end
 
   def click_start
-    click_button 'Start'
+    click_button "Start"
   end
 end
spec/support/stronglifts_program.rb
@@ -6,18 +6,30 @@ shared_context "stronglifts_program" do
   let!(:bench_press) { create(:exercise, name: "Bench Press") }
   let!(:barbell_row) { create(:exercise, name: "Barbell Row") }
   let!(:dips) { create(:exercise, name: "Dips") }
-  let!(:squat_workout) { routine_a.add_exercise(squat, sets: 5, repetitions: 5) }
-  let!(:bench_workout) { routine_a.add_exercise(bench_press, sets: 5, repetitions: 5) }
-  let!(:row_workout) { routine_a.add_exercise(barbell_row, sets: 5, repetitions: 5) }
+  let!(:squat_workout) do
+    routine_a.add_exercise(squat, sets: 5, repetitions: 5)
+  end
+  let!(:bench_workout) do
+    routine_a.add_exercise(bench_press, sets: 5, repetitions: 5)
+  end
+  let!(:row_workout) do
+    routine_a.add_exercise(barbell_row, sets: 5, repetitions: 5)
+  end
   let!(:dips_workout) { routine_a.add_exercise(dips, sets: 3, repetitions: 5) }
 
   let!(:routine_b) { program.routines.create name: "B" }
   let!(:overhead_press) { create(:exercise, name: "Overhead Press") }
   let!(:deadlift) { create(:exercise, name: "Deadlift") }
   let!(:chinups) { create(:exercise, name: "Chinups") }
-  let!(:squat_workout_b) { routine_b.add_exercise(squat, sets: 5, repetitions: 5) }
-  let!(:overhead_press_workout) { routine_b.add_exercise(overhead_press, sets: 5, repetitions: 5) }
-  let!(:deadlift_workout) { routine_b.add_exercise(deadlift, sets: 1, repetitions: 5) }
+  let!(:squat_workout_b) do
+    routine_b.add_exercise(squat, sets: 5, repetitions: 5)
+  end
+  let!(:overhead_press_workout) do
+    routine_b.add_exercise(overhead_press, sets: 5, repetitions: 5)
+  end
+  let!(:deadlift_workout) do
+    routine_b.add_exercise(deadlift, sets: 1, repetitions: 5)
+  end
   let!(:chinups_workout) do
     routine_b.add_exercise(chinups, sets: 3, repetitions: 5)
   end