From 9d956c2ae693a4fd21f90c247368b4a72ca86dd2 Mon Sep 17 00:00:00 2001 From: Michael Webb Date: Tue, 1 Aug 2023 11:35:03 +1000 Subject: [PATCH] Add last_judgement_at to API --- app/serializers/prediction_serializer.rb | 5 +++++ spec/requests/api/my_predictions_controller_spec.rb | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/app/serializers/prediction_serializer.rb b/app/serializers/prediction_serializer.rb index 6af6142a..b046048d 100644 --- a/app/serializers/prediction_serializer.rb +++ b/app/serializers/prediction_serializer.rb @@ -12,6 +12,7 @@ class PredictionSerializer < ActiveModel::Serializer :mean_confidence, :outcome, :prediction_group_id, + :last_judgement_at, :updated_at, :uuid, :version, @@ -23,4 +24,8 @@ class PredictionSerializer < ActiveModel::Serializer def creator_label object.creator.to_s end + + def last_judgement_at + object.judged_at + end end diff --git a/spec/requests/api/my_predictions_controller_spec.rb b/spec/requests/api/my_predictions_controller_spec.rb index 442133ed..50d46710 100644 --- a/spec/requests/api/my_predictions_controller_spec.rb +++ b/spec/requests/api/my_predictions_controller_spec.rb @@ -60,12 +60,16 @@ predictions = json_hash['predictions'] expect(predictions.length).to eq 2 + before_judgment_timestamp = Time.now + another_prediction.judgements.create!(outcome: true) + get url, params: params.merge(page_size: 1, page: 1) json_hash = JSON.parse(response.body) predictions = json_hash['predictions'] actor = json_hash['user'] expect(predictions.length).to eq 1 expect(predictions.first['description']).to eq another_prediction.description + expect(predictions.first['last_judgement_at'] > before_judgment_timestamp).to be true expect(actor['email']).to eq user.email get url, params: params.merge(page_size: 1, page: 2)