Skip to content

Commit

Permalink
Fixes #275. Ignore engine path if it is mounted to root.
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed May 28, 2021
1 parent 944fd05 commit 55511c7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## master

## v2.0.3

* Fixed backward compatibility issue [#275](https://github.com/railsware/js-routes/issues/275)

## v2.0.2

* Fixed backward compatibility issue [#274](https://github.com/railsware/js-routes/issues/274)
Expand Down
2 changes: 1 addition & 1 deletion lib/js_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def serialize(spec, parent_spec=nil)
return spec.tr(':*', '') if spec.is_a?(String)

result = serialize_spec(spec, parent_spec)
if parent_spec && result[1].is_a?(String)
if parent_spec && result[1].is_a?(String) && parent_spec.type != :SLASH
result = [
# We encode node symbols as integer
# to reduce the routes.js file size
Expand Down
4 changes: 4 additions & 0 deletions spec/js_routes/rails_routes_compatibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
it "should support single route mapping" do
expect(evaljs("Routes.support_path({page: 3})")).to eq(test_routes.support_path(:page => 3))
end

it 'works' do
expect(evaljs("Routes.planner_manage_path()")).to eq(planner_routes.manage_path)
end
end

it "shouldn't require the format" do
Expand Down
10 changes: 10 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,21 @@ def blog_routes
BlogEngine::Engine.routes.url_helpers
end

def planner_routes
Planner::Engine.routes.url_helpers
end

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular "budgie", "budgies"
end


module Planner
class Engine < Rails::Engine
isolate_namespace Planner
end
end

module BlogEngine
class Engine < Rails::Engine
isolate_namespace BlogEngine
Expand Down
10 changes: 7 additions & 3 deletions spec/support/routes.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
def draw_routes
Planner::Engine.routes.draw do
get "/manage" => 'foo#foo', as: :manage
end

BlogEngine::Engine.routes.draw do
root to: "application#index"
resources :posts
resources :posts, only: [:show, :index]
end
App.routes.draw do

mount Planner::Engine, at: "/", as: :planner

mount BlogEngine::Engine => "/blog", as: :blog_app
get 'support(/page/:page)', to: BlogEngine::Engine, as: 'support'

resources :inboxes, only: [:index, :show] do
Expand Down Expand Up @@ -43,8 +49,6 @@ def draw_routes
get 'books/*section/:title' => 'books#show', :as => :book
get 'books/:title/*section' => 'books#show', :as => :book_title

mount BlogEngine::Engine => "/blog", :as => :blog_app

get '/no_format' => "foo#foo", :format => false, :as => :no_format

get '/json_only' => "foo#foo", :format => true, :constraints => {:format => /json/}, :as => :json_only
Expand Down

0 comments on commit 55511c7

Please sign in to comment.