public
Rubygem
Description: A new plugin approach to attempting to solve the usage of subdomains in linking and routing in Rails projects.
Homepage: http://www.actsascommunity.com/projects/subdomain-fu
Clone URL: git://github.com/mbleigh/subdomain-fu.git
Fixed issue with subdomain defaulting to none or the preferred even when 
it shouldn't. [#3 status:resolved]
mbleigh (author)
Wed Jul 09 14:29:10 -0700 2008
commit  3921d9fdce7d7cac5fee5a3a1f5e8b4b234ae325
tree    962cb8c2cd0ba9810bfca3208c4e62cebe8b9ced
parent  031a0770821f89eacde07d006c251fc18850773e
...
1
 
2
3
4
...
74
75
76
77
78
 
 
 
79
80
81
...
 
1
2
3
4
...
74
75
76
 
 
77
78
79
80
81
82
0
@@ -1,4 +1,4 @@
0
-#require 'subdomain_fu/routing_extensions'
0
+require 'subdomain_fu/routing_extensions'
0
 require 'subdomain_fu/url_rewriter'
0
 
0
 module SubdomainFu
0
@@ -74,8 +74,9 @@ module SubdomainFu
0
       (!SubdomainFu.has_subdomain?(subdomain) && !SubdomainFu.has_subdomain?(SubdomainFu.subdomain_from(host)))
0
   end
0
   
0
- def self.needs_rewrite?(subdomain, host)
0
- subdomain = nil if subdomain.blank?
0
+ def self.needs_rewrite?(subdomain, host)
0
+ return false if subdomain.nil?
0
+ subdomain = nil if subdomain.blank?
0
     (!has_subdomain?(subdomain) && subdomain != SubdomainFu.preferred_mirror && SubdomainFu.preferred_mirror != nil) ||
0
       !same_subdomain?(subdomain, host)
0
   end
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -1,5 +1,37 @@
0
 require File.dirname(__FILE__) + '/spec_helper'
0
 
0
 describe "SubdomainFu Routing" do
0
- it "should not recognize a subdomainless request for a subdomain-required request"
0
+ it "should resolve if a subdomain is required only when one is provided" # do
0
+ # testapp.com/subdomain_here => 404
0
+ # something.testapp.com/subdomain_here => app/success
0
+ # end
0
+
0
+ it "should resolve if a subdomain is prohibited only when one is not provided" # do
0
+ # testapp.com/no_subdomain_here => site/success
0
+ # something.testapp.com/no_subdomain_here => 404
0
+ # end
0
+
0
+ it "should resolve if a subdomain is prohibited if a mirror is provided" # do
0
+ # www.testapp.com/no_subdomain_hee => site/success
0
+ # end
0
+
0
+ it "should resolve if a specific subdomain is required only when that subdomain is passed" # do
0
+ # m.testapp.com/m_subdomain_here => mobile/success
0
+ # testapp.com/m_subdomain_here => 404
0
+ # something.testapp.com/m_subdomain_here => 404
0
+ # end
0
+
0
+ it "should resolve against a regex only if the subdomain matches that regex" # do
0
+ # 123.testapp.com/numbers_here => numbers/success
0
+ # abc.testapp.com/numbers_here => 404
0
+ # testapp.com/numbers_here => 404
0
+ # end
0
+
0
+ it "should differentiate between multiple identical routes with different subdomain conditions" # do
0
+ # "m.testapp.com" => mobile/home
0
+ # "testapp.com" => site/home
0
+ # "awesome.testapp.com" => app/home
0
+ # end
0
+
0
+ it "should work on map.resources"
0
 end
0
\ No newline at end of file
...
17
18
19
 
 
 
 
 
 
 
 
 
20
21
22
...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
0
@@ -17,6 +17,15 @@ ActionController::Routing::Routes.draw do |map|
0
     fu.resources :bars
0
   end
0
   
0
+ map.connect '/', :controller => "site", :action => "home", :conditions => {:subdomain => false}
0
+ map.connect '/', :controller => "app", :action => "home", :conditions => {:subdomain => true}
0
+ map.connect '/', :controller => "mobile", :action => "home", :conditions => {:subdomain => "m"}
0
+
0
+ map.connect '/subdomain_here', :controller => "app", :action => "success", :conditions => {:subdomain => true}
0
+ map.connect '/no_subdomain_here', :controller => "site", :action => "success", :conditions => {:subdomain => false}
0
+ map.connect '/m_subdomain_here', :controller => "mobile", :action => "success", :conditions => {:subdomain => "m"}
0
+ map.connect '/numbers_only_here', :controller => "numbers", :action => "success", :conditions => {:subdomain => /[0-9]+/}
0
+
0
   map.connect '/:controller/:action/:id'
0
 end
0
 
...
43
44
45
 
 
46
47
48
...
75
76
77
78
79
 
 
80
81
82
83
 
 
84
85
86
...
43
44
45
46
47
48
49
50
...
77
78
79
 
 
80
81
82
83
 
 
84
85
86
87
88
0
@@ -43,6 +43,8 @@ describe "SubdomainFu" do
0
   describe "#subdomain_from" do
0
     it "should return the subdomain based on the TLD of the current environment" do
0
       SubdomainFu.subdomain_from("awesome.localhost").should == "awesome"
0
+ SubdomainFu.tld_size = 2
0
+ SubdomainFu.subdomain_from("awesome.localhost.co.uk").should == "awesome"
0
       SubdomainFu.tld_size = 1
0
       SubdomainFu.subdomain_from("awesome.localhost.com").should == "awesome"
0
       SubdomainFu.tld_size = 0
0
@@ -75,12 +77,12 @@ describe "SubdomainFu" do
0
       SubdomainFu.rewrite_host_for_subdomains("cool","www.localhost").should == "cool.localhost"
0
     end
0
     
0
- it "should remove the subdomain if passed nil when it's not a mirror" do
0
- SubdomainFu.rewrite_host_for_subdomains(nil,"cool.localhost").should == "localhost"
0
+ it "should remove the subdomain if passed false when it's not a mirror" do
0
+ SubdomainFu.rewrite_host_for_subdomains(false,"cool.localhost").should == "localhost"
0
     end
0
     
0
- it "should not remove the subdomain if passed nil when it is a mirror" do
0
- SubdomainFu.rewrite_host_for_subdomains(nil,"www.localhost").should == "www.localhost"
0
+ it "should not remove the subdomain if passed false when it is a mirror" do
0
+ SubdomainFu.rewrite_host_for_subdomains(false,"www.localhost").should == "www.localhost"
0
     end
0
   end
0
   
...
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46
47
...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
0
@@ -42,6 +42,21 @@ describe "SubdomainFu URL Writing" do
0
     it "should should force the full url, even with _path" do
0
       needs_subdomain_path(:subdomain => "awesome").should == needs_subdomain_url(:subdomain => "awesome")
0
     end
0
+
0
+ it "should not force the full url if it's the same as the current subdomain" do
0
+ default_url_options[:host] = "awesome.testapp.com"
0
+ needs_subdomain_path(:subdomain => "awesome").should == "/needs_subdomain"
0
+ end
0
+
0
+ it "should not force the full url if the current subdomain is nil and so is the target" do
0
+ needs_subdomain_path(:subdomain => nil).should == "/needs_subdomain"
0
+ end
0
+
0
+ it "should not force the full url if no :subdomain option is given" do
0
+ needs_subdomain_path.should == "/needs_subdomain"
0
+ default_url_options[:host] = "awesome.testapp.com"
0
+ needs_subdomain_path.should == "/needs_subdomain"
0
+ end
0
   end
0
   
0
   describe "Resourced Routes" do

Comments

    No one has commented yet.