diff --git a/app/controllers/listings_controller.rb b/app/controllers/listings_controller.rb index c42699bc5..875eee12c 100644 --- a/app/controllers/listings_controller.rb +++ b/app/controllers/listings_controller.rb @@ -13,9 +13,10 @@ class ListingsController < ApplicationController DASHBOARD_JSON_OPTIONS = { only: %i[ - title tag_list created_at expires_at bumped_at updated_at category id + title tag_list created_at expires_at bumped_at updated_at id user_id slug organization_id location published ], + methods: %i[category], include: { author: { only: %i[username name], methods: %i[username profile_image_90] } } @@ -68,7 +69,7 @@ class ListingsController < ApplicationController def dashboard listings = current_user.listings - .includes(:organization, :taggings) + .includes(:organization, :taggings, :listing_category) @listings_json = listings.to_json(DASHBOARD_JSON_OPTIONS) organizations_ids = current_user.organization_memberships diff --git a/spec/requests/listings_spec.rb b/spec/requests/listings_spec.rb index e3dfffb39..1457f7d11 100644 --- a/spec/requests/listings_spec.rb +++ b/spec/requests/listings_spec.rb @@ -80,6 +80,16 @@ RSpec.describe "/listings", type: :request do end end + describe "GET /listings/dashboard" do + before { sign_in user } + + it "returns a category for draft listings" do + post "/listings", params: draft_params + get "/listings/dashboard" + expect(response.body).to include(CGI.escapeHTML("\"category\":\"#{edu_category.slug}\"")) + end + end + describe "GET /listings/new" do before { sign_in user }