This commit builds on the conditional rendering of navigation links by
adding a routing constraint to all :listing routes.
The impact is, if we were to disable the listing feature (e.g.,
`FeatureFlag.disable(:listing_feature_enabled)`) all requests to `GET
/listings` (and those drawn in the [config/routes/listings.rb][1] file)
would return a 404 response.
Related to forem/rfcs#291, #16335, #16338, #16362.
Testing this change:
1. Start your local application (e.g. `$ bin/startup`)
2. Go to http://localhost:3000/listings
3. You should get a Successful response.
4. Now disable the feature (e.g. `$ bin/rails r \
"FeatureFlag.disable(:listing_feature_enabled)"`)
5. Refresh http://localhost:3000/listings
6. You should get an `ActiveRecord::RecordNotFound` error; because the
application is now looking for a user or org named "listings"; in other
words we're not routing `GET "/listings"` to `listings#index` controller
action.
7. Now enable the feature (e.g. `$ bin/rails r \
"FeatureFlag.enable(:listing_feature_enabled)"`)
8. Refresh http://localhost:3000/listings
9. You should get a Successful response.
10. Goto 4
This commit is intended to be the penultimate change before we toggle
the listings section off by default.
[1]:c2ce2c32d5/config/routes/listing.rb (L1)
84 lines
2.3 KiB
Ruby
84 lines
2.3 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "all routes", type: :routing do
|
|
let(:podcast) { create(:podcast) }
|
|
let(:user) { create(:user) }
|
|
|
|
describe "#root_url" do
|
|
it "matches URL.url('/')" do
|
|
expect(root_url).to eq(URL.url("/"))
|
|
end
|
|
end
|
|
|
|
describe "/listings" do
|
|
subject(:a_request) { { get: "/listings" } }
|
|
|
|
context "when enabled" do
|
|
before { allow(Listing).to receive(:feature_enabled?).and_return(true) }
|
|
|
|
it { is_expected.to route_to(controller: "listings", action: "index", locale: nil) }
|
|
end
|
|
|
|
context "when disabled" do
|
|
before { allow(Listing).to receive(:feature_enabled?).and_return(false) }
|
|
|
|
it { is_expected.not_to route_to(controller: "listings", action: "index", locale: nil) }
|
|
end
|
|
end
|
|
|
|
it "renders a podcast index if there is a podcast with the slug successfully" do
|
|
expect(get: "/#{podcast.slug}").to route_to(
|
|
controller: "stories",
|
|
action: "index",
|
|
username: podcast.slug,
|
|
locale: nil, # default locale
|
|
)
|
|
end
|
|
|
|
it "renders a user index if there is a user with the username successfully" do
|
|
expect(get: "/#{user.username}").to route_to(
|
|
controller: "stories",
|
|
action: "index",
|
|
username: user.username,
|
|
locale: nil, # default locale
|
|
)
|
|
end
|
|
|
|
it "renders a user's story successfully" do
|
|
expect(get: "/ben/this-is-a-slug").to route_to(
|
|
controller: "stories",
|
|
action: "show",
|
|
slug: "this-is-a-slug",
|
|
username: "ben",
|
|
locale: nil, # default locale
|
|
)
|
|
end
|
|
|
|
context "when redirected routes" do
|
|
include RSpec::Rails::RequestExampleGroup
|
|
|
|
it "redirects /settings/integrations to /settings/extensions" do
|
|
get user_settings_path(:integrations)
|
|
|
|
expect(response).to redirect_to(user_settings_path(:extensions))
|
|
end
|
|
|
|
it "redirects /settings/misc to /settings" do
|
|
get user_settings_path(:misc)
|
|
|
|
expect(response).to redirect_to(user_settings_path)
|
|
end
|
|
|
|
it "redirects /settings/publishing-from-rss to /settings/extensions" do
|
|
get user_settings_path("publishing-from-rss")
|
|
|
|
expect(response).to redirect_to(user_settings_path(:extensions))
|
|
end
|
|
|
|
it "redirects /settings/ux to /settings/customization" do
|
|
get user_settings_path(:ux)
|
|
|
|
expect(response).to redirect_to(user_settings_path(:customization))
|
|
end
|
|
end
|
|
end
|