Commit ec381d9
Changed files (2)
app
models
spec
models
app/models/exercise_set.rb
@@ -1,9 +1,10 @@
class ExerciseSet < ActiveRecord::Base
belongs_to :exercise
belongs_to :workout
- scope :for, ->(exercise) { where(exercise: exercise).order(:created_at) }
+ scope :for, ->(exercise) { where(exercise: exercise).in_order }
scope :successful, -> { where('actual_repetitions = target_repetitions') }
scope :work, -> { where(type: WorkSet.name) }
+ scope :in_order, -> { order(:created_at) }
def work?
type == WorkSet.name
spec/models/workout_spec.rb
@@ -31,14 +31,16 @@ describe Workout, type: :model do
expect(result).to be_persisted
expect(result.exercise).to eql(squat)
expect(subject.progress_for(squat).to_sets).to eql([5, 3])
- expect(subject.sets.at(0).exercise).to eql(squat)
- expect(subject.sets.at(0).target_weight).to eql(target_weight.to_f)
- expect(subject.sets.at(0).target_repetitions).to eql(5)
- expect(subject.sets.at(0).actual_repetitions).to eql(5)
- expect(subject.sets.at(1).exercise).to eql(squat)
- expect(subject.sets.at(1).target_weight).to eql(target_weight.to_f)
- expect(subject.sets.at(1).target_repetitions).to eql(5)
- expect(subject.sets.at(1).actual_repetitions).to eql(3)
+ set = subject.sets.in_order.at(0)
+ expect(set.exercise).to eql(squat)
+ expect(set.target_weight).to eql(target_weight.to_f)
+ expect(set.target_repetitions).to eql(5)
+ expect(set.actual_repetitions).to eql(5)
+ set = subject.sets.in_order.at(1)
+ expect(set.exercise).to eql(squat)
+ expect(set.target_weight).to eql(target_weight.to_f)
+ expect(set.target_repetitions).to eql(5)
+ expect(set.actual_repetitions).to eql(3)
end
it "updates a completed exercise" do