mbleigh-subdomain-fu 0.0.5 → 0.1.0

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/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ == 2008-06-25
2
+
3
+ * Removed stray puts
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+
7
+ desc 'Run the specs'
8
+ Spec::Rake::SpecTask.new(:spec) do |t|
9
+ t.spec_opts = ['--colour --format progress --loadby mtime --reverse']
10
+ t.spec_files = FileList['spec/**/*_spec.rb']
11
+ end
12
+
13
+ begin
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gemspec|
16
+ gemspec.name = "subdomain-fu"
17
+ gemspec.summary = "SubdomainFu is a Rails plugin that provides subdomain routing and URL writing helpers."
18
+ gemspec.email = "michael@intridea.com"
19
+ gemspec.homepage = "http://github.com/mbleigh/subdomain-fu"
20
+ gemspec.files = FileList["[A-Z]*", "{lib,spec,rails}/**/*"] - FileList["**/*.log"]
21
+ gemspec.description = "SubdomainFu is a Rails plugin to provide all of the basic functionality necessary to handle multiple subdomain applications (such as Basecamp-esque subdomain accounts and more)."
22
+ gemspec.authors = ["Michael Bleigh"]
23
+ end
24
+ rescue LoadError
25
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
26
+ end
27
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/subdomain-fu.rb CHANGED
@@ -31,7 +31,12 @@ module SubdomainFu
31
31
 
32
32
  # Is the current subdomain either nil or a mirror?
33
33
  def self.has_subdomain?(subdomain)
34
- !subdomain.blank? && !SubdomainFu.mirrors.include?(subdomain)
34
+ subdomain != false && !subdomain.blank? && !SubdomainFu.mirrors.include?(subdomain)
35
+ end
36
+
37
+ # Is the subdomain a preferred mirror
38
+ def self.preferred_mirror?(subdomain)
39
+ subdomain == SubdomainFu.preferred_mirror || SubdomainFu.preferred_mirror.nil?
35
40
  end
36
41
 
37
42
  # Gets the subdomain from the host based on the TLD size
@@ -49,14 +54,15 @@ module SubdomainFu
49
54
 
50
55
  # Rewrites the subdomain of the host unless they are equivalent (i.e. mirrors of each other)
51
56
  def self.rewrite_host_for_subdomains(subdomain, host)
52
- unless needs_rewrite?(subdomain, host)
53
- if has_subdomain?(subdomain) || (subdomain_from(host) == SubdomainFu.preferred_mirror) || (!has_subdomain?(subdomain) && SubdomainFu.preferred_mirror == nil)
57
+ if needs_rewrite?(subdomain, host)
58
+ change_subdomain_of_host(subdomain || SubdomainFu.preferred_mirror, host)
59
+ else
60
+ if has_subdomain?(subdomain) || preferred_mirror?(subdomain_from(host)) ||
61
+ (subdomain.nil? && has_subdomain?(subdomain_from(host)))
54
62
  host
55
63
  else
56
64
  change_subdomain_of_host(SubdomainFu.preferred_mirror, host)
57
65
  end
58
- else
59
- change_subdomain_of_host(subdomain || SubdomainFu.preferred_mirror, host)
60
66
  end
61
67
  end
62
68
 
@@ -70,14 +76,14 @@ module SubdomainFu
70
76
  # Is this subdomain equivalent to the subdomain found in this host string?
71
77
  def self.same_subdomain?(subdomain, host)
72
78
  subdomain = nil unless subdomain
73
- (subdomain == SubdomainFu.subdomain_from(host)) ||
74
- (!SubdomainFu.has_subdomain?(subdomain) && !SubdomainFu.has_subdomain?(SubdomainFu.subdomain_from(host)))
79
+ (subdomain == subdomain_from(host)) ||
80
+ (!has_subdomain?(subdomain) && !has_subdomain?(subdomain_from(host)))
75
81
  end
76
82
 
77
- def self.needs_rewrite?(subdomain, host)
83
+ def self.needs_rewrite?(subdomain, host)
78
84
  return false if subdomain.nil?
79
- subdomain = nil if subdomain.blank?
80
- (!has_subdomain?(subdomain) && subdomain != SubdomainFu.preferred_mirror && SubdomainFu.preferred_mirror != nil) ||
85
+
86
+ (!has_subdomain?(subdomain) && preferred_mirror?(subdomain) && !preferred_mirror?(subdomain_from(host))) ||
81
87
  !same_subdomain?(subdomain, host)
82
88
  end
83
89
 
@@ -96,7 +102,6 @@ module SubdomainFu
96
102
  end
97
103
 
98
104
  protected
99
-
100
105
  def current_subdomain
101
106
  SubdomainFu.current_subdomain(request)
102
107
  end
@@ -10,7 +10,7 @@ module SubdomainFu
10
10
 
11
11
  def recognition_conditions_with_subdomain
12
12
  result = recognition_conditions_without_subdomain
13
- result << "conditions[:subdomain] === env[:subdomain]" if conditions[:subdomain] && conditions[:subdomain] != true && conditions[:subdomain] != false
13
+ result << "conditions[:subdomain] === env[:subdomain].to_s" if conditions[:subdomain] && conditions[:subdomain] != true && conditions[:subdomain] != false
14
14
  result << "SubdomainFu.has_subdomain?(env[:subdomain])" if conditions[:subdomain] == true
15
15
  result << "!SubdomainFu.has_subdomain?(env[:subdomain])" if conditions[:subdomain] == false
16
16
  result
@@ -1,11 +1,11 @@
1
1
  module ActionController
2
2
  module UrlWriter
3
3
  def url_for_with_subdomains(options)
4
- unless SubdomainFu.needs_rewrite?(options[:subdomain], options[:host] || default_url_options[:host])
5
- options.delete(:subdomain)
6
- else
4
+ if SubdomainFu.needs_rewrite?(options[:subdomain], options[:host] || default_url_options[:host]) || options[:only_path] == false
7
5
  options[:only_path] = false
8
6
  options[:host] = SubdomainFu.rewrite_host_for_subdomains(options.delete(:subdomain), options[:host] || default_url_options[:host])
7
+ else
8
+ options.delete(:subdomain)
9
9
  end
10
10
  url_for_without_subdomains(options)
11
11
  end
@@ -16,11 +16,11 @@ module ActionController
16
16
  private
17
17
 
18
18
  def rewrite_url_with_subdomains(options)
19
- unless SubdomainFu.needs_rewrite?(options[:subdomain], (options[:host] || @request.host_with_port))
20
- options.delete(:subdomain)
21
- else
19
+ if SubdomainFu.needs_rewrite?(options[:subdomain], options[:host] || @request.host_with_port) || options[:only_path] == false
22
20
  options[:only_path] = false
23
21
  options[:host] = SubdomainFu.rewrite_host_for_subdomains(options.delete(:subdomain), options[:host] || @request.host_with_port)
22
+ else
23
+ options.delete(:subdomain)
24
24
  end
25
25
  rewrite_url_without_subdomains(options)
26
26
  end
data/spec/spec.opts ADDED
@@ -0,0 +1,7 @@
1
+ --colour
2
+ --format
3
+ specdoc
4
+ --loadby
5
+ mtime
6
+ --reverse
7
+ --backtrace
@@ -1,6 +1,11 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe "SubdomainFu" do
4
+ before do
5
+ SubdomainFu.tld_sizes = SubdomainFu::DEFAULT_TLD_SIZES.dup
6
+ SubdomainFu.preferred_mirror = nil
7
+ end
8
+
4
9
  describe "TLD Sizes" do
5
10
  before do
6
11
  SubdomainFu.tld_sizes = SubdomainFu::DEFAULT_TLD_SIZES.dup
@@ -37,6 +42,7 @@ describe "SubdomainFu" do
37
42
  it "shoud be false for a nil or blank subdomain" do
38
43
  SubdomainFu.has_subdomain?("").should be_false
39
44
  SubdomainFu.has_subdomain?(nil).should be_false
45
+ SubdomainFu.has_subdomain?(false).should be_false
40
46
  end
41
47
  end
42
48
 
@@ -63,7 +69,19 @@ describe "SubdomainFu" do
63
69
  SubdomainFu.host_without_subdomain("awesome.localhost:3000").should == "localhost:3000"
64
70
  SubdomainFu.host_without_subdomain("something.awful.localhost:3000").should == "localhost:3000"
65
71
  end
66
-
72
+
73
+ describe "#preferred_mirror?" do
74
+ describe "when preferred_mirror is false" do
75
+ before do
76
+ SubdomainFu.preferred_mirror = false
77
+ end
78
+
79
+ it "should return true for false" do
80
+ SubdomainFu.preferred_mirror?(false).should be_true
81
+ end
82
+ end
83
+ end
84
+
67
85
  describe "#rewrite_host_for_subdomains" do
68
86
  it "should not change the same subdomain" do
69
87
  SubdomainFu.rewrite_host_for_subdomains("awesome","awesome.localhost").should == "awesome.localhost"
@@ -80,10 +98,28 @@ describe "SubdomainFu" do
80
98
  it "should remove the subdomain if passed false when it's not a mirror" do
81
99
  SubdomainFu.rewrite_host_for_subdomains(false,"cool.localhost").should == "localhost"
82
100
  end
83
-
101
+
84
102
  it "should not remove the subdomain if passed false when it is a mirror" do
85
103
  SubdomainFu.rewrite_host_for_subdomains(false,"www.localhost").should == "www.localhost"
86
104
  end
105
+
106
+ it "should not remove the subdomain if passed nil when it's not a mirror" do
107
+ SubdomainFu.rewrite_host_for_subdomains(nil,"cool.localhost").should == "cool.localhost"
108
+ end
109
+
110
+ describe "when preferred_mirror is false" do
111
+ before do
112
+ SubdomainFu.preferred_mirror = false
113
+ end
114
+
115
+ it "should remove the subdomain if passed false when it is a mirror" do
116
+ SubdomainFu.rewrite_host_for_subdomains(false,"www.localhost").should == "localhost"
117
+ end
118
+
119
+ it "should not remove the subdomain if passed nil when it's not a mirror" do
120
+ SubdomainFu.rewrite_host_for_subdomains(nil,"cool.localhost").should == "cool.localhost"
121
+ end
122
+ end
87
123
  end
88
124
 
89
125
  describe "#change_subdomain_of_host" do
@@ -130,4 +166,25 @@ describe "SubdomainFu" do
130
166
  it { SubdomainFu.same_subdomain?(nil,"www.localhost").should be_true }
131
167
  it { SubdomainFu.same_subdomain?("www","awesome.localhost").should be_false }
132
168
  end
169
+
170
+ describe "#needs_rewrite?" do
171
+ it { SubdomainFu.needs_rewrite?("www","www.localhost").should be_false }
172
+ it { SubdomainFu.needs_rewrite?("www","localhost").should be_false }
173
+ it { SubdomainFu.needs_rewrite?("awesome","www.localhost").should be_true }
174
+ it { SubdomainFu.needs_rewrite?("cool","awesome.localhost").should be_true }
175
+ it { SubdomainFu.needs_rewrite?(nil,"www.localhost").should be_false }
176
+ it { SubdomainFu.needs_rewrite?(nil,"awesome.localhost").should be_false }
177
+ it { SubdomainFu.needs_rewrite?(false,"awesome.localhost").should be_true }
178
+ it { SubdomainFu.needs_rewrite?(false,"www.localhost").should be_false }
179
+ it { SubdomainFu.needs_rewrite?("www","awesome.localhost").should be_true }
180
+
181
+ describe "when preferred_mirror is false" do
182
+ before do
183
+ SubdomainFu.preferred_mirror = false
184
+ end
185
+
186
+ it { SubdomainFu.needs_rewrite?(false,"www.localhost").should be_true }
187
+ it { SubdomainFu.needs_rewrite?(nil,"awesome.localhost").should be_false }
188
+ end
189
+ end
133
190
  end
@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe "SubdomainFu URL Writing" do
4
4
  before do
5
5
  SubdomainFu.tld_size = 1
6
+ SubdomainFu.preferred_mirror = nil
6
7
  default_url_options[:host] = "testapp.com"
7
8
  end
8
9
 
@@ -47,7 +48,12 @@ describe "SubdomainFu URL Writing" do
47
48
  default_url_options[:host] = "awesome.testapp.com"
48
49
  needs_subdomain_path(:subdomain => "awesome").should == "/needs_subdomain"
49
50
  end
50
-
51
+
52
+ it "should force the full url if it's a different subdomain" do
53
+ default_url_options[:host] = "awesome.testapp.com"
54
+ needs_subdomain_path(:subdomain => "crazy").should == "http://crazy.testapp.com/needs_subdomain"
55
+ end
56
+
51
57
  it "should not force the full url if the current subdomain is nil and so is the target" do
52
58
  needs_subdomain_path(:subdomain => nil).should == "/needs_subdomain"
53
59
  end
@@ -69,14 +75,28 @@ describe "SubdomainFu URL Writing" do
69
75
  foo_path(:id => "something", :subdomain => false).should == "http://testapp.com/foos/something"
70
76
  end
71
77
 
78
+ it "should work when passed in a paramable object" do
79
+ foo_path(Paramed.new("something"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something"
80
+ end
81
+
72
82
  it "should work when passed in a paramable object" do
73
83
  foo_path(Paramed.new("something"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something"
74
84
  end
75
85
 
86
+ it "should work when passed in a paramable object and no subdomain to a _path" do
87
+ default_url_options[:host] = "awesome.testapp.com"
88
+ foo_path(Paramed.new("something")).should == "/foos/something"
89
+ end
90
+
91
+ it "should work when passed in a paramable object and no subdomain to a _url" do
92
+ default_url_options[:host] = "awesome.testapp.com"
93
+ foo_url(Paramed.new("something")).should == "http://awesome.testapp.com/foos/something"
94
+ end
95
+
76
96
  it "should work on nested resource collections" do
77
97
  foo_bars_path(Paramed.new("something"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something/bars"
78
98
  end
79
-
99
+
80
100
  it "should work on nested resource members" do
81
101
  foo_bar_path(Paramed.new("something"),Paramed.new("else"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something/bars/else"
82
102
  end
@@ -91,13 +111,23 @@ describe "SubdomainFu URL Writing" do
91
111
  default_url_options[:host] = "awesome.testapp.com"
92
112
  needs_subdomain_url(:subdomain => false).should == "http://www.testapp.com/needs_subdomain"
93
113
  end
94
-
114
+
115
+ it "should switch to the preferred mirror automatically" do
116
+ default_url_options[:host] = "testapp.com"
117
+ needs_subdomain_url.should == "http://www.testapp.com/needs_subdomain"
118
+ end
119
+
120
+ it "should work when passed in a paramable object and no subdomain to a _url" do
121
+ default_url_options[:host] = "awesome.testapp.com"
122
+ foo_url(Paramed.new("something")).should == "http://awesome.testapp.com/foos/something"
123
+ end
124
+
95
125
  it "should force a switch to no subdomain on a mirror if preferred_mirror is false" do
96
126
  SubdomainFu.preferred_mirror = false
97
127
  default_url_options[:host] = "www.testapp.com"
98
128
  needs_subdomain_url(:subdomain => false).should == "http://testapp.com/needs_subdomain"
99
129
  end
100
-
130
+
101
131
  after do
102
132
  SubdomainFu.preferred_mirror = nil
103
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbleigh-subdomain-fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,37 +9,37 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-13 00:00:00 -08:00
12
+ date: 2009-05-26 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: SubdomainFu aims to solve the problem of subdomain-based routing and in a unified way, establishing simple conventions for linking between subdomains of a Rails app.
16
+ description: SubdomainFu is a Rails plugin to provide all of the basic functionality necessary to handle multiple subdomain applications (such as Basecamp-esque subdomain accounts and more).
17
17
  email: michael@intridea.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
21
21
 
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - README
24
24
  files:
25
+ - CHANGELOG
25
26
  - MIT-LICENSE
26
27
  - README
27
- - init.rb
28
- - lib/subdomain_fu
28
+ - Rakefile
29
+ - VERSION
30
+ - lib/subdomain-fu.rb
29
31
  - lib/subdomain_fu/routing_extensions.rb
30
32
  - lib/subdomain_fu/url_rewriter.rb
31
- - lib/subdomain-fu.rb
32
33
  - rails/init.rb
34
+ - spec/spec.opts
33
35
  - spec/spec_helper.rb
34
36
  - spec/subdomain_fu_spec.rb
35
37
  - spec/url_rewriter_spec.rb
36
- - subdomain-fu.gemspec
37
- has_rdoc: true
38
- homepage: http://www.actsascommunity.com/projects/subdomain-fu
38
+ has_rdoc: false
39
+ homepage: http://github.com/mbleigh/subdomain-fu
39
40
  post_install_message:
40
41
  rdoc_options:
41
- - --main
42
- - README
42
+ - --charset=UTF-8
43
43
  require_paths:
44
44
  - lib
45
45
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -59,7 +59,9 @@ requirements: []
59
59
  rubyforge_project:
60
60
  rubygems_version: 1.2.0
61
61
  signing_key:
62
- specification_version: 2
63
- summary: Provides a simple solution for route handling and linking between subdomains in a Rails application.
64
- test_files: []
65
-
62
+ specification_version: 3
63
+ summary: SubdomainFu is a Rails plugin that provides subdomain routing and URL writing helpers.
64
+ test_files:
65
+ - spec/spec_helper.rb
66
+ - spec/subdomain_fu_spec.rb
67
+ - spec/url_rewriter_spec.rb
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require File.dirname(__FILE__) + "/rails/init"
data/subdomain-fu.gemspec DELETED
@@ -1,26 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "subdomain-fu"
3
- s.version = "0.0.5"
4
- s.date = "2009-01-13"
5
- s.summary = "Provides a simple solution for route handling and linking between subdomains in a Rails application."
6
- s.email = "michael@intridea.com"
7
- s.homepage = "http://www.actsascommunity.com/projects/subdomain-fu"
8
- s.description = "SubdomainFu aims to solve the problem of subdomain-based routing and in a unified way, establishing simple conventions for linking between subdomains of a Rails app."
9
- s.has_rdoc = true
10
- s.authors = ["Michael Bleigh"]
11
- s.files = [ "MIT-LICENSE",
12
- "README",
13
- "init.rb",
14
- "lib/subdomain_fu",
15
- "lib/subdomain_fu/routing_extensions.rb",
16
- "lib/subdomain_fu/url_rewriter.rb",
17
- "lib/subdomain-fu.rb",
18
- "rails/init.rb",
19
- "spec/spec_helper.rb",
20
- "spec/subdomain_fu_spec.rb",
21
- "spec/url_rewriter_spec.rb",
22
- "subdomain-fu.gemspec" ]
23
- s.rdoc_options = ["--main", "README"]
24
- #s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
25
- #s.add_dependency("mbleigh-mash", [">= 0.0.5"])
26
- end