mholling-subdomain_routes 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/subdomain_routes/url_writer.rb +1 -2
- data/spec/url_writing_spec.rb +62 -12
- metadata +2 -2
data/VERSION.yml
CHANGED
@@ -35,7 +35,6 @@ module SubdomainRoutes
|
|
35
35
|
options[:only_path] = false
|
36
36
|
options[:host] = [ new_subdomain, domain ].reject(&:blank?).join('.')
|
37
37
|
end
|
38
|
-
options.delete(:subdomains)
|
39
38
|
options.delete(:subdomain)
|
40
39
|
end
|
41
40
|
end
|
@@ -63,7 +62,7 @@ module SubdomainRoutes
|
|
63
62
|
|
64
63
|
def self.included(base)
|
65
64
|
base.alias_method_chain :rewrite, :subdomains
|
66
|
-
base::RESERVED_OPTIONS << :subdomain
|
65
|
+
base::RESERVED_OPTIONS << :subdomain # untested!
|
67
66
|
end
|
68
67
|
|
69
68
|
def rewrite_with_subdomains(options)
|
data/spec/url_writing_spec.rb
CHANGED
@@ -5,7 +5,10 @@ describe "URL writing" do
|
|
5
5
|
context "when the host is #{host_type}" do
|
6
6
|
it "should raise an error when a subdomain route is requested" do
|
7
7
|
map_subdomain(:www) { |www| www.resources :users }
|
8
|
-
with_host(host)
|
8
|
+
with_host(host) do
|
9
|
+
lambda { www_users_path }.should raise_error(SubdomainRoutes::HostNotSupplied)
|
10
|
+
lambda { url_for(:controller => "users", :action => "index", :subdomains => ["www"]) }.should raise_error(SubdomainRoutes::HostNotSupplied)
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
context "and a non-subdomain route is requested" do
|
@@ -16,6 +19,7 @@ describe "URL writing" do
|
|
16
19
|
it "should not raise an error when the route is a path" do
|
17
20
|
with_host(host) do
|
18
21
|
lambda { users_path }.should_not raise_error
|
22
|
+
lambda { url_for(:controller => "users", :action => "index", :only_path => true) }.should_not raise_error
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -27,39 +31,60 @@ describe "URL writing" do
|
|
27
31
|
context "when a #{type} subdomain is specified" do
|
28
32
|
before(:each) do
|
29
33
|
map_subdomain(subdomain, :name => nil) { |map| map.resources :users }
|
34
|
+
@url_options = { :controller => "users", :action => "index", :subdomains => [ subdomain.to_s ] }
|
35
|
+
@path_options = @url_options.merge(:only_path => true)
|
30
36
|
end
|
31
37
|
|
32
38
|
it "should not change the host for an URL if the host subdomain matches" do
|
33
|
-
with_host(host)
|
39
|
+
with_host(host) do
|
40
|
+
users_url.should == "http://#{host}/users"
|
41
|
+
url_for(@url_options).should == "http://#{host}/users"
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
45
|
it "should change the host for an URL if the host subdomain differs" do
|
37
|
-
with_host
|
46
|
+
with_host "other.example.com" do
|
47
|
+
users_url.should == "http://#{host}/users"
|
48
|
+
url_for(@url_options).should == "http://#{host}/users"
|
49
|
+
end
|
38
50
|
end
|
39
51
|
|
40
52
|
it "should not force the host for a path if the host subdomain matches" do
|
41
|
-
with_host(host)
|
53
|
+
with_host(host) do
|
54
|
+
users_path.should == "/users"
|
55
|
+
url_for(@path_options).should == "/users"
|
56
|
+
end
|
42
57
|
end
|
43
58
|
|
44
59
|
it "should force the host for a path if the host subdomain differs" do
|
45
|
-
with_host
|
60
|
+
with_host "other.example.com" do
|
61
|
+
users_path.should == "http://#{host}/users"
|
62
|
+
url_for(@path_options).should == "http://#{host}/users"
|
63
|
+
end
|
46
64
|
end
|
47
65
|
|
48
66
|
context "and a subdomain different from the host subdomain is explicitly requested" do
|
49
67
|
it "should change the host if the requested subdomain matches" do
|
50
|
-
with_host
|
68
|
+
with_host "other.example.com" do
|
69
|
+
users_path(:subdomain => subdomain).should == "http://#{host}/users"
|
70
|
+
url_for(@path_options.merge(:subdomain => subdomain)).should == "http://#{host}/users"
|
71
|
+
end
|
51
72
|
end
|
52
73
|
|
53
74
|
it "should raise a routing error if the requested subdomain doesn't match" do
|
54
75
|
with_host(host) do
|
55
76
|
lambda { users_path(:subdomain => :other) }.should raise_error(ActionController::RoutingError)
|
77
|
+
lambda { url_for(@path_options.merge(:subdomain => :other)) }.should raise_error(ActionController::RoutingError)
|
56
78
|
end
|
57
79
|
end
|
58
80
|
end
|
59
81
|
|
60
82
|
context "and the current host's subdomain is explicitly requested" do
|
61
83
|
it "should not force the host for a path if the subdomain matches" do
|
62
|
-
with_host(host)
|
84
|
+
with_host(host) do
|
85
|
+
users_path(:subdomain => subdomain).should == "/users"
|
86
|
+
url_for(@path_options.merge(:subdomain => subdomain)).should == "/users"
|
87
|
+
end
|
63
88
|
end
|
64
89
|
end
|
65
90
|
end
|
@@ -71,17 +96,25 @@ describe "URL writing" do
|
|
71
96
|
before(:each) do
|
72
97
|
args = subdomains + [ :name => nil ]
|
73
98
|
map_subdomain(*args) { |map| map.resources :items }
|
99
|
+
@url_options = { :controller => "items", :action => "index", :subdomains => subdomains.map(&:to_s) }
|
100
|
+
@path_options = @url_options.merge(:only_path => true)
|
74
101
|
end
|
75
102
|
|
76
103
|
it "should not change the host for an URL if the host subdomain matches" do
|
77
104
|
hosts.each do |host|
|
78
|
-
with_host(host)
|
105
|
+
with_host(host) do
|
106
|
+
items_url.should == "http://#{host}/items"
|
107
|
+
url_for(@url_options).should == "http://#{host}/items"
|
108
|
+
end
|
79
109
|
end
|
80
110
|
end
|
81
111
|
|
82
112
|
it "should not force the host for a path if the host subdomain matches" do
|
83
113
|
hosts.each do |host|
|
84
|
-
with_host(host)
|
114
|
+
with_host(host) do
|
115
|
+
items_path.should == "/items"
|
116
|
+
url_for(@path_options).should == "/items"
|
117
|
+
end
|
85
118
|
end
|
86
119
|
end
|
87
120
|
|
@@ -89,6 +122,8 @@ describe "URL writing" do
|
|
89
122
|
with_host "other.example.com" do
|
90
123
|
lambda { item_url }.should raise_error(ActionController::RoutingError)
|
91
124
|
lambda { item_path }.should raise_error(ActionController::RoutingError)
|
125
|
+
lambda { url_for(@url_options) }.should raise_error(ActionController::RoutingError)
|
126
|
+
lambda { url_for(@path_options) }.should raise_error(ActionController::RoutingError)
|
92
127
|
end
|
93
128
|
end
|
94
129
|
|
@@ -96,7 +131,10 @@ describe "URL writing" do
|
|
96
131
|
it "should change the host if the requested subdomain matches" do
|
97
132
|
[ [ subdomains.first, hosts.first, hosts.last ],
|
98
133
|
[ subdomains.last, hosts.last, hosts.first ] ].each do |subdomain, new_host, old_host|
|
99
|
-
with_host(old_host)
|
134
|
+
with_host(old_host) do
|
135
|
+
items_path(:subdomain => subdomain).should == "http://#{new_host}/items"
|
136
|
+
url_for(@path_options.merge(:subdomain => subdomain)).should == "http://#{new_host}/items"
|
137
|
+
end
|
100
138
|
end
|
101
139
|
end
|
102
140
|
|
@@ -105,6 +143,7 @@ describe "URL writing" do
|
|
105
143
|
[ hosts.last, hosts.first ] ].each do |new_host, old_host|
|
106
144
|
with_host(old_host) do
|
107
145
|
lambda { items_path(:subdomain => :other) }.should raise_error(ActionController::RoutingError)
|
146
|
+
lambda { url_for(@path_options.merge(:subdomain => :other)) }.should raise_error(ActionController::RoutingError)
|
108
147
|
end
|
109
148
|
end
|
110
149
|
end
|
@@ -115,7 +154,10 @@ describe "URL writing" do
|
|
115
154
|
it "should downcase a supplied subdomain" do
|
116
155
|
map_subdomain(:www1, :www2, :name => nil) { |map| map.resources :users }
|
117
156
|
[ [ :Www1, "www1" ], [ "Www2", "www2" ] ].each do |mixedcase, lowercase|
|
118
|
-
with_host
|
157
|
+
with_host "www.example.com" do
|
158
|
+
users_url(:subdomain => mixedcase).should == "http://#{lowercase}.example.com/users"
|
159
|
+
url_for(:controller => "users", :action => "index", :subdomains => [ "www1", "www2" ], :subdomain => mixedcase).should == "http://#{lowercase}.example.com/users"
|
160
|
+
end
|
119
161
|
end
|
120
162
|
end
|
121
163
|
|
@@ -126,12 +168,16 @@ describe "URL writing" do
|
|
126
168
|
@boston = City.new
|
127
169
|
@boston.stub!(:new_record?).and_return(false)
|
128
170
|
@boston.stub!(:to_param).and_return("boston")
|
171
|
+
@url_options = { :controller => "city/events", :action => "index", :subdomains => :city_id, :subdomain => @boston.to_param }
|
172
|
+
@path_options = @url_options.merge(:only_path => true)
|
129
173
|
end
|
130
174
|
|
131
175
|
it "should not change the host if the object has the same to_param as the current subdomain" do
|
132
176
|
with_host "boston.example.com" do
|
133
177
|
city_events_url(@boston).should == "http://boston.example.com/events"
|
134
178
|
city_events_path(@boston).should == "/events"
|
179
|
+
url_for(@url_options).should == "http://boston.example.com/events"
|
180
|
+
url_for(@path_options).should == "/events"
|
135
181
|
end
|
136
182
|
end
|
137
183
|
|
@@ -139,6 +185,8 @@ describe "URL writing" do
|
|
139
185
|
with_host "example.com" do
|
140
186
|
city_events_url(@boston).should == "http://boston.example.com/events"
|
141
187
|
city_events_path(@boston).should == "http://boston.example.com/events"
|
188
|
+
url_for(@url_options).should == "http://boston.example.com/events"
|
189
|
+
url_for(@path_options).should == "http://boston.example.com/events"
|
142
190
|
end
|
143
191
|
end
|
144
192
|
|
@@ -149,10 +197,12 @@ describe "URL writing" do
|
|
149
197
|
with_host "www.example.com" do
|
150
198
|
lambda { city_events_url(@newyork) }.should raise_error(ActionController::RoutingError)
|
151
199
|
lambda { city_events_path(@newyork) }.should raise_error(ActionController::RoutingError)
|
200
|
+
lambda { url_for(@url_options.merge(:subdomain => @newyork.to_param)) }.should raise_error(ActionController::RoutingError)
|
201
|
+
lambda { url_for(@path_options.merge(:subdomain => @newyork.to_param)) }.should raise_error(ActionController::RoutingError)
|
152
202
|
end
|
153
203
|
end
|
154
204
|
|
155
|
-
it "should not allow the subdomain to be manually overridden" do
|
205
|
+
it "should not allow the subdomain to be manually overridden in a named route" do
|
156
206
|
with_host "www.example.com" do
|
157
207
|
city_events_url(@boston, :subdomain => :canberra).should == "http://boston.example.com/events"
|
158
208
|
city_events_path(@boston, :subdomain => :canberra).should == "http://boston.example.com/events"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mholling-subdomain_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Hollingworth
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-07-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|