diff --git a/config/application.rb b/config/application.rb index b4c62b137b4..a7326669871 100644 --- a/config/application.rb +++ b/config/application.rb @@ -148,14 +148,6 @@ module Discourse require 'auth' Discourse.activate_plugins! unless Rails.env.test? and ENV['LOAD_PLUGINS'] != "1" - # FIXME: needs to work with engines such as docker manager - # this mounts routes_last before the engine, one option here if a hook is to hard - # is to add a constraint on the route that ensures its only captured if its a permalink - # - # initializer :add_last_routes, :after => :add_routing_paths do |app| - # app.routes_reloader.paths << File.join(Rails.root, 'config', 'routes_last.rb') - # end - config.after_initialize do # So open id logs somewhere sane OpenID::Util.logger = Rails.logger diff --git a/config/routes.rb b/config/routes.rb index 3cb72a1fa43..786b510fc20 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,7 @@ require_dependency "scheduler/web" require_dependency "admin_constraint" require_dependency "staff_constraint" require_dependency "homepage_constraint" +require_dependency "permalink_constraint" # This used to be User#username_format, but that causes a preload of the User object # and makes Guard not work properly. @@ -425,5 +426,5 @@ Discourse::Application.routes.draw do # special case for top root to: "list#top", constraints: HomePageConstraint.new("top"), :as => "top_lists" - # See config/routes_last.rb for more + get "*url", to: 'permalinks#show', constraints: PermalinkConstraint.new end diff --git a/config/routes_last.rb b/config/routes_last.rb deleted file mode 100644 index 5382e5f9e7d..00000000000 --- a/config/routes_last.rb +++ /dev/null @@ -1,10 +0,0 @@ -# These routes must be loaded after all others. -# Routes are loaded in this order: -# -# 1. config/routes.rb -# 2. routes in engines -# 3. config/routes_last.rb - -Discourse::Application.routes.draw do - get "*url", to: 'permalinks#show' -end diff --git a/lib/permalink_constraint.rb b/lib/permalink_constraint.rb new file mode 100644 index 00000000000..0abf395e282 --- /dev/null +++ b/lib/permalink_constraint.rb @@ -0,0 +1,7 @@ +class PermalinkConstraint + + def matches?(request) + Permalink.where(url: request.fullpath[1..-1]).exists? + end + +end diff --git a/spec/controllers/permalinks_controller_spec.rb b/spec/controllers/permalinks_controller_spec.rb index 6846bfb12c3..afc50e364bd 100644 --- a/spec/controllers/permalinks_controller_spec.rb +++ b/spec/controllers/permalinks_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe PermalinksController do describe 'show' do - pending "should redirect to a permalink's target_url with status 301" do + it "should redirect to a permalink's target_url with status 301" do permalink = Fabricate(:permalink) Permalink.any_instance.stubs(:target_url).returns('/t/the-topic-slug/42') get :show, url: permalink.url @@ -10,7 +10,7 @@ describe PermalinksController do response.status.should == 301 end - pending 'return 404 if permalink record does not exist' do + it 'return 404 if permalink record does not exist' do get :show, url: '/not/a/valid/url' response.status.should == 404 end