From 01725d9344185d1d221acb9e410a55be4b4e5bdf Mon Sep 17 00:00:00 2001 From: Rafi Date: Thu, 5 Nov 2020 12:39:43 +0530 Subject: [PATCH] Fixing date in listing modal (#11260) * Fixing date in listing modal * Adding test * Fixing test message --- app/controllers/listings_controller.rb | 3 ++- spec/requests/listings_spec.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index 875eee12c..b35f35672 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -3,7 +3,8 @@ class ListingsController < ApplicationController INDEX_JSON_OPTIONS = { only: %i[ - title processed_html tag_list category id user_id slug contact_via_connect location + title processed_html tag_list category id user_id slug contact_via_connect location bumped_at + originally_published_at ], include: { author: { only: %i[username name], methods: %i[username profile_image_90] }, diff --git a/spec/requests/listings_spec.rb b/spec/requests/listings_spec.rb index 1457f7d11..b194c4f14 100644 --- a/spec/requests/listings_spec.rb +++ b/spec/requests/listings_spec.rb @@ -1,4 +1,5 @@ require "rails_helper" +require "nokogiri" RSpec.describe "/listings", type: :request do let(:user) { create(:user) } @@ -35,6 +36,8 @@ RSpec.describe "/listings", type: :request do before do sign_in user create_list(:credit, 25, user: user) + listing_params[:listing][:post_as_organization] = "1" + post "/listings", params: listing_params end it "returns text/html and has status 200" do @@ -43,6 +46,21 @@ RSpec.describe "/listings", type: :request do expect(response).to have_http_status(:ok) end + it "listings have correct keys" do + get "/listings" + + parsed_response = Nokogiri.HTML(response.body) + + listings = JSON.parse(parsed_response.xpath("//*[@id='listings-index-container']")[0]["data-listings"]) + + index_keys = %w[ + title processed_html tag_list id user_id slug contact_via_connect location bumped_at + originally_published_at author user + ] + + expect(listings.first.keys).to match_array index_keys + end + context "when the user has no params" do it "shows all active listings" do get "/listings"