Skip to content

Commit 8746bf3

Browse files
committed
Don't route /rails/info request to Ember
Closes [#449]. > When mounting an Ember CLI app via `mount_ember_app`, the catch-all > routes defined by Ember CLI Rails also catch requests to two of Rails' > magic routes: > > 1. `/rails/info/routes` (which is also redirected to from `/rails/info`) > 2. `/rails/info/properties` > > This adds another constraint to the mounted Ember app that will ignore > requests with a path starting with `/rails/info`. > > @stevenharman [#449]: #449
1 parent 448bae9 commit 8746bf3

File tree

6 files changed

+80
-45
lines changed

6 files changed

+80
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
master
22
------
33

4+
* Don't route requests to `/rails/info` through the mounted Ember application.
5+
46
0.7.4
57
-----
68

lib/ember_cli/ember_constraint.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module EmberCli
2+
class EmberConstraint
3+
def matches?(request)
4+
html_request?(request) && !rails_info_request?(request)
5+
end
6+
7+
private
8+
9+
def rails_info_request?(request)
10+
request.fullpath.start_with?("/rails/info")
11+
end
12+
13+
def html_request?(request)
14+
index = request.format.to_s =~ /html/ || -1
15+
16+
index > -1
17+
end
18+
end
19+
end

lib/ember_cli/html_constraint.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

lib/ember_cli/route_helpers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require "ember_cli/html_constraint"
1+
require "ember_cli/ember_constraint"
22

33
module ActionDispatch
44
module Routing
@@ -14,7 +14,7 @@ def mount_ember_app(app_name, to:, **options)
1414
format: :html,
1515
)
1616

17-
scope constraints: ::EmberCli::HtmlConstraint.new do
17+
scope constraints: ::EmberCli::EmberConstraint.new do
1818
get("#{to}(*rest)", routing_options)
1919
end
2020

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
require "ember_cli/ember_constraint"
2+
3+
describe EmberCli::EmberConstraint do
4+
describe "#matches?" do
5+
context %{when the format is "html"} do
6+
context "when the request path is for a Rails info page" do
7+
it "returns false" do
8+
constraint = EmberCli::EmberConstraint.new
9+
request = build_html_request("/rails/info")
10+
11+
expect(constraint.matches?(request)).to be false
12+
end
13+
end
14+
15+
context "when the request path is not for a Rails info page" do
16+
it "returns true" do
17+
constraint = EmberCli::EmberConstraint.new
18+
request = build_html_request("/foo")
19+
20+
expect(constraint.matches?(request)).to be true
21+
end
22+
end
23+
end
24+
25+
context %{when the format isn't "html"} do
26+
it "return false" do
27+
constraint = EmberCli::EmberConstraint.new
28+
request = build_json_request
29+
30+
expect(constraint.matches?(request)).to be false
31+
end
32+
end
33+
34+
context %"when the format is empty or nil" do
35+
it "return false" do
36+
constraint = EmberCli::EmberConstraint.new
37+
nil_request = build_request(format: nil)
38+
empty_request = build_request(format: "")
39+
40+
expect(constraint.matches?(nil_request)).to be false
41+
expect(constraint.matches?(empty_request)).to be false
42+
end
43+
end
44+
end
45+
46+
def build_request(format:, fullpath: :ignored)
47+
double(format: format, fullpath: fullpath)
48+
end
49+
50+
def build_html_request(fullpath)
51+
build_request(format: :html, fullpath: fullpath)
52+
end
53+
54+
def build_json_request
55+
build_request(format: :json)
56+
end
57+
end

spec/lib/ember_cli/html_constraint_spec.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)