Commit 4b56d95

mo khan <mo@mokhan.ca>
2016-12-25 18:07:44
include the routine info.
1 parent eacc4b9
Changed files (2)
app
views
api
spec
app/views/api/workouts/new.json.jbuilder
@@ -1,5 +1,12 @@
 json.body_weight @workout.body_weight
+json.routine do |routine|
+  json.id @workout.routine.id
+  json.name @workout.routine.name
+end
 json.exercises @workout.sets.group_by(&:exercise) do |exercise, sets|
   json.id exercise.id
   json.name exercise.name
 end
+#json.sets @workout.sets.group_by(&:exercise) do |exercise, set|
+  #json.partial! 'sets/set', set: set
+#end
spec/controllers/api/workouts_controller_spec.rb
@@ -30,13 +30,19 @@ describe Api::WorkoutsController do
       json = JSON.parse(response.body, symbolize_names: true)
 
       expect(json[:body_weight]).to eql({ amount: 0.0, unit: 'lbs' })
+      expect(json[:routine]).to eql({ id: routine_a.id, name: routine_a.name })
       expect(json[:exercises]).to match_array([
-        { id: barbell_row.id, name: barbell_row.name, },
+        { id: barbell_row.id, name: barbell_row.name },
         { id: bench_press.id, name: bench_press.name, },
         { id: dips.id, name: dips.name, },
         { id: planks.id, name: planks.name, },
         { id: squat.id, name: squat.name, },
       ])
+      #expect(json[:sets]).to eql({
+        #squat.id => [
+          #{ id: nil, type: 'WorkSet', target: { amount: 315, unit: 'lbs' }, actual: nil }
+        #]
+      #})
     end
   end
 end