From 231ce5d3cb531f5e31e368ef73cd7118ca259f5b Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Tue, 10 Aug 2021 20:53:03 +0700 Subject: [PATCH] [15-minute fix] Add `created_at` to listings API response (#14437) * Add created_at to listings API response * Add created_at listing attribute to org controller --- app/controllers/api/v0/listings_controller.rb | 2 +- app/controllers/api/v0/organizations_controller.rb | 2 +- app/views/api/v0/shared/_listing.json.jbuilder | 1 + spec/requests/api/v0/listings_spec.rb | 7 +++++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v0/listings_controller.rb b/app/controllers/api/v0/listings_controller.rb index 20e4a90cd..181367048 100644 --- a/app/controllers/api/v0/listings_controller.rb +++ b/app/controllers/api/v0/listings_controller.rb @@ -18,7 +18,7 @@ module Api # actual column name for the listing category, prefixed with classified_. ATTRIBUTES_FOR_SERIALIZATION = %i[ id user_id organization_id title slug body_markdown cached_tag_list - classified_listing_category_id processed_html published + classified_listing_category_id processed_html published created_at ].freeze private_constant :ATTRIBUTES_FOR_SERIALIZATION diff --git a/app/controllers/api/v0/organizations_controller.rb b/app/controllers/api/v0/organizations_controller.rb index d8c25b0e8..a2e6cf8a9 100644 --- a/app/controllers/api/v0/organizations_controller.rb +++ b/app/controllers/api/v0/organizations_controller.rb @@ -17,7 +17,7 @@ module Api LISTINGS_FOR_SERIALIZATION = %i[ id user_id organization_id title slug body_markdown cached_tag_list - classified_listing_category_id processed_html published + classified_listing_category_id processed_html published created_at ].freeze private_constant :LISTINGS_FOR_SERIALIZATION diff --git a/app/views/api/v0/shared/_listing.json.jbuilder b/app/views/api/v0/shared/_listing.json.jbuilder index f6b0ab88e..838a2fa28 100644 --- a/app/views/api/v0/shared/_listing.json.jbuilder +++ b/app/views/api/v0/shared/_listing.json.jbuilder @@ -14,3 +14,4 @@ json.extract!( json.listing_category_id listing.classified_listing_category_id json.tag_list listing.cached_tag_list json.tags listing.tag_list +json.created_at utc_iso_timestamp(listing.created_at) diff --git a/spec/requests/api/v0/listings_spec.rb b/spec/requests/api/v0/listings_spec.rb index 2b74ba0e2..77c5bacb8 100644 --- a/spec/requests/api/v0/listings_spec.rb +++ b/spec/requests/api/v0/listings_spec.rb @@ -106,6 +106,13 @@ RSpec.describe "Api::V0::Listings", type: :request do get api_listings_path expect(response.parsed_body.detect { |l| l["published"] == false }).to be_nil end + + # Regression test for https://github.com/forem/forem/issues/14436 + it "includes the created at timestamp for listings" do + get api_listings_path + listing = response.parsed_body.first + expect(listing["created_at"]).to match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z/) + end end describe "GET /api/listings/category/:category" do