+
+ Listing Categories
+
<%= form_tag(admin_listings_path, method: "get", role: "search", class: "crayons-card crayons-card--secondary p-4 flex items-center") do %>
diff --git a/config/routes.rb b/config/routes.rb
index 7faa1310e..3254729dc 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -62,6 +62,9 @@ Rails.application.routes.draw do
resources :broadcasts
resources :buffer_updates, only: %i[create update]
resources :listings, only: %i[index edit update destroy]
+ resources :listing_categories, only: %i[index edit update new create
+ destroy], path: "listings/categories"
+
resources :comments, only: [:index]
resources :events, only: %i[index create update]
resources :feedback_messages, only: %i[index show]
@@ -126,6 +129,7 @@ Rails.application.routes.draw do
resource :config
resources :badges, only: %i[index edit update new create]
resources :display_ads, only: %i[index edit update new create destroy]
+
resources :html_variants, only: %i[index edit update new create show destroy]
# These redirects serve as a safegaurd to prevent 404s for any Admins
# who have the old badge_achievement URLs bookmarked.
diff --git a/spec/requests/admin/listings_catogires_spec.rb b/spec/requests/admin/listings_catogires_spec.rb
new file mode 100644
index 000000000..1f570d532
--- /dev/null
+++ b/spec/requests/admin/listings_catogires_spec.rb
@@ -0,0 +1,121 @@
+require "rails_helper"
+require "requests/shared_examples/internal_policy_dependant_request"
+
+RSpec.describe "/admin/listings/categories", type: :request do
+ let(:get_resource) { get "/admin/listings/categories" }
+ let(:params) do
+ { name: "Computer stuff", cost: 22, rules: "Things computers do",
+ slug: "computer", social_preview_color: "#000", social_preview_description: "Computer things" }
+ end
+ let(:post_resource) { post "/admin/listings/categories", params: params }
+
+ it_behaves_like "an InternalPolicy dependant request", ListingCategory do
+ let(:request) { get_resource }
+ end
+
+ context "when the user is not an admin" do
+ let(:user) { create(:user) }
+
+ before { sign_in user }
+
+ describe "GET /admin/listings/categories" do
+ it "blocks the request" do
+ expect { get_resource }.to raise_error(Pundit::NotAuthorizedError)
+ end
+ end
+
+ describe "POST /admin/listings/categories" do
+ it "blocks the request" do
+ expect { post_resource }.to raise_error(Pundit::NotAuthorizedError)
+ end
+ end
+ end
+
+ context "when the user is a super admin" do
+ let(:super_admin) { create(:user, :super_admin) }
+
+ before { sign_in super_admin }
+
+ describe "GET /admin/listings/categories" do
+ it "allows the request" do
+ get_resource
+ expect(response).to have_http_status(:ok)
+ end
+ end
+
+ describe "POST /admin/listings/categories" do
+ it "creates a new listing_category" do
+ expect do
+ post_resource
+ end.to change { ListingCategory.all.count }.by(1)
+ end
+ end
+
+ describe "PUT /admin/listings/categories" do
+ let!(:listing_category) { create(:listing_category, name: "Computers") }
+
+ it "updates Listing Category name" do
+ Timecop.freeze(Time.current) do
+ expect do
+ put "/admin/listings/categories/#{listing_category.id}", params: params
+ end.to change { listing_category.reload.name }.from("Computers").to("Computer stuff")
+ end
+ end
+ end
+
+ describe "DELETE /admin/listing/categories/:id" do
+ let!(:listing_category) { create(:listing_category) }
+
+ it "deletes the Listing Category" do
+ expect do
+ delete "/admin/listings/categories/#{listing_category.id}"
+ end.to change { ListingCategory.all.count }.by(-1)
+ expect(response.body).to redirect_to "/admin/listings/categories"
+ end
+ end
+ end
+
+ context "when the user is a single resource admin" do
+ let(:single_resource_admin) { create(:user, :single_resource_admin, resource: ListingCategory) }
+
+ before { sign_in single_resource_admin }
+
+ describe "GET /admin/listings/categories" do
+ it "allows the request" do
+ get_resource
+ expect(response).to have_http_status(:ok)
+ end
+ end
+
+ describe "POST /admin/listings/categories" do
+ it "creates a new listing_category" do
+ expect do
+ post_resource
+ end.to change { ListingCategory.all.count }.by(1)
+ end
+ end
+
+ describe "PUT /admin/listings/categories" do
+ let!(:listing_category) { create(:listing_category, name: "Computers") }
+
+ it "updates Listing Category name" do
+ Timecop.freeze(Time.current) do
+ expect do
+ put "/admin/listings/categories/#{listing_category.id}", params: params
+ end.to change { listing_category.reload.name }.from("Computers").to("Computer stuff")
+ end
+ end
+ end
+
+ describe "DELETE /admin/listing/categories/:id" do
+ let!(:listing_category) { create(:listing_category) }
+
+ it "deletes the Listing Category" do
+ expect do
+ delete "/admin/listings/categories/#{listing_category.id}"
+ end.to change { ListingCategory.all.count }.by(-1)
+ expect(response.body).to redirect_to "/admin/listings/categories"
+ end
+ end
+ end
+end