From 87c22d4a96844c63024d036f3d6f7dc6b6db52b7 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Mon, 27 Apr 2020 15:05:53 -0500 Subject: [PATCH] Set default `planted_at` value --- app/serializers/plant_serializer.rb | 4 ++++ spec/controllers/api/points/index_spec.rb | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/serializers/plant_serializer.rb b/app/serializers/plant_serializer.rb index 40cf71326..30883b2b0 100644 --- a/app/serializers/plant_serializer.rb +++ b/app/serializers/plant_serializer.rb @@ -1,6 +1,10 @@ class PlantSerializer < BasePointSerializer attributes :openfarm_slug, :plant_stage, :planted_at, :radius, :meta + def planted_at + object.planted_at || object.created_at + end + def x object.x.round end diff --git a/spec/controllers/api/points/index_spec.rb b/spec/controllers/api/points/index_spec.rb index 9b55350cc..35e707e20 100644 --- a/spec/controllers/api/points/index_spec.rb +++ b/spec/controllers/api/points/index_spec.rb @@ -9,8 +9,8 @@ describe Api::PointsController do end let(:auth_token) do params = { email: user.email, - password: "password123", - fbos_version: Gem::Version.new("999.9.9") } + password: "password123", + fbos_version: Gem::Version.new("999.9.9") } Auth::CreateToken.run!(params)[:token].encoded end @@ -130,6 +130,7 @@ describe Api::PointsController do get :index expect(response.status).to eq(200) expect(json.length).to eq(3) + json.map { |json| expect(json[:created_at]).to eq(json[:planted_at]) } end it "lists all tool slots" do Point.destroy_all