summaryrefslogtreecommitdiff
path: root/spec/models/routine_spec.rb
blob: d7ceeedb9993bbe87857c516d4a9cbf6129f6d24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require "rails_helper"

describe Routine do
  subject { build(:routine) }

  describe "#add_exercise" do
    let(:exercise) { create(:exercise) }

    before :each do
      subject.save!
    end

    it "adds a new exercise with the specified sets" do
      sets = rand(10)
      subject.add_exercise(exercise, sets: sets)
      expect(subject.recommendations.first.sets).to eql(sets)
    end

    it "adds the new exercise with the specified reps" do
      repetitions = rand(10)
      subject.add_exercise(exercise, repetitions: repetitions)
      expect(subject.recommendations.first.repetitions).to eql(repetitions)
    end

    it "adds the excercise" do
      subject.add_exercise(exercise)
      expect(subject.recommendations.first.exercise).to eql(exercise)
    end

    it "does not add a duplicate exercise" do
      subject.add_exercise(exercise)
      subject.add_exercise(exercise)
      expect(subject.exercises.count).to eql(1)
      expect(subject.recommendations.count).to eql(1)
    end

    it "adds a timed exercise" do
      subject.add_exercise(exercise, sets: 3, duration: 60.seconds)
      expect(subject.exercises).to match_array([exercise])
      expect(subject.recommendations.count).to eql(1)
      recommendation = subject.recommendations.first.reload

      expect(recommendation.duration).to eql(60.seconds.to_i)
      expect(recommendation.exercise).to eql(exercise)
      expect(recommendation.repetitions).to eql(1)
      expect(recommendation.sets).to eql(3)
    end
  end
end