<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -31,7 +31,12 @@ module SubdomainFu
   
   # Is the current subdomain either nil or a mirror?
   def self.has_subdomain?(subdomain)
-    !subdomain.blank? &amp;&amp; !SubdomainFu.mirrors.include?(subdomain)
+    subdomain != false &amp;&amp; !subdomain.blank? &amp;&amp; !SubdomainFu.mirrors.include?(subdomain)
+  end
+
+  # Is the subdomain a preferred mirror
+  def self.preferred_mirror?(subdomain)
+    subdomain == SubdomainFu.preferred_mirror || SubdomainFu.preferred_mirror.nil?
   end
   
   # Gets the subdomain from the host based on the TLD size
@@ -50,7 +55,7 @@ module SubdomainFu
   # Rewrites the subdomain of the host unless they are equivalent (i.e. mirrors of each other)
   def self.rewrite_host_for_subdomains(subdomain, host)
     unless needs_rewrite?(subdomain, host)
-      if has_subdomain?(subdomain) || (subdomain_from(host) == SubdomainFu.preferred_mirror) || (!has_subdomain?(subdomain) &amp;&amp; SubdomainFu.preferred_mirror == nil)
+      if has_subdomain?(subdomain) || preferred_mirror?(subdomain_from(host))
         host
       else
         change_subdomain_of_host(SubdomainFu.preferred_mirror, host)
@@ -70,14 +75,14 @@ module SubdomainFu
   # Is this subdomain equivalent to the subdomain found in this host string?
   def self.same_subdomain?(subdomain, host)
     subdomain = nil unless subdomain
-    (subdomain == SubdomainFu.subdomain_from(host)) || 
-      (!SubdomainFu.has_subdomain?(subdomain) &amp;&amp; !SubdomainFu.has_subdomain?(SubdomainFu.subdomain_from(host)))
+    (subdomain == subdomain_from(host)) ||
+      (!has_subdomain?(subdomain) &amp;&amp; !has_subdomain?(subdomain_from(host)))
   end
   
-  def self.needs_rewrite?(subdomain, host)    
+  def self.needs_rewrite?(subdomain, host)
     return false if subdomain.nil?
-    subdomain = nil if subdomain.blank?
-    (!has_subdomain?(subdomain) &amp;&amp; subdomain != SubdomainFu.preferred_mirror &amp;&amp; SubdomainFu.preferred_mirror != nil) || 
+
+    (!has_subdomain?(subdomain) &amp;&amp; preferred_mirror?(subdomain) &amp;&amp; !preferred_mirror?(subdomain_from(host))) || 
       !same_subdomain?(subdomain, host)
   end
   </diff>
      <filename>lib/subdomain-fu.rb</filename>
    </modified>
    <modified>
      <diff>@@ -16,7 +16,7 @@ module ActionController
     private
     
     def rewrite_url_with_subdomains(options)
-      unless SubdomainFu.needs_rewrite?(options[:subdomain], (options[:host] || @request.host_with_port))
+      unless SubdomainFu.needs_rewrite?(options[:subdomain], options[:host] || @request.host_with_port)
         options.delete(:subdomain)
       else
         options[:only_path] = false</diff>
      <filename>lib/subdomain_fu/url_rewriter.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,11 @@
 require File.dirname(__FILE__) + '/spec_helper'
 
 describe &quot;SubdomainFu&quot; do
+  before do
+    SubdomainFu.tld_sizes = SubdomainFu::DEFAULT_TLD_SIZES.dup
+    SubdomainFu.preferred_mirror = nil
+  end
+
   describe &quot;TLD Sizes&quot; do
     before do
       SubdomainFu.tld_sizes = SubdomainFu::DEFAULT_TLD_SIZES.dup
@@ -37,6 +42,7 @@ describe &quot;SubdomainFu&quot; do
     it &quot;shoud be false for a nil or blank subdomain&quot; do
       SubdomainFu.has_subdomain?(&quot;&quot;).should be_false
       SubdomainFu.has_subdomain?(nil).should be_false
+      SubdomainFu.has_subdomain?(false).should be_false
     end
   end
   
@@ -63,7 +69,19 @@ describe &quot;SubdomainFu&quot; do
     SubdomainFu.host_without_subdomain(&quot;awesome.localhost:3000&quot;).should == &quot;localhost:3000&quot;
     SubdomainFu.host_without_subdomain(&quot;something.awful.localhost:3000&quot;).should == &quot;localhost:3000&quot;
   end
-  
+
+  describe &quot;#preferred_mirror?&quot; do
+    describe &quot;when preferred_mirror is false&quot; do
+      before do
+        SubdomainFu.preferred_mirror = false
+      end
+
+      it &quot;should return true for false&quot; do
+        SubdomainFu.preferred_mirror?(false).should be_true
+      end
+    end
+  end
+
   describe &quot;#rewrite_host_for_subdomains&quot; do
     it &quot;should not change the same subdomain&quot; do
       SubdomainFu.rewrite_host_for_subdomains(&quot;awesome&quot;,&quot;awesome.localhost&quot;).should == &quot;awesome.localhost&quot;
@@ -84,6 +102,16 @@ describe &quot;SubdomainFu&quot; do
     it &quot;should not remove the subdomain if passed false when it is a mirror&quot; do
       SubdomainFu.rewrite_host_for_subdomains(false,&quot;www.localhost&quot;).should == &quot;www.localhost&quot;
     end
+
+    describe &quot;when preferred_mirror is false&quot; do
+      before do
+        SubdomainFu.preferred_mirror = false
+      end
+
+      it &quot;should remove the subdomain if passed false when it is a mirror&quot; do
+        SubdomainFu.rewrite_host_for_subdomains(false,&quot;www.localhost&quot;).should == &quot;localhost&quot;
+      end
+    end
   end
   
   describe &quot;#change_subdomain_of_host&quot; do
@@ -130,4 +158,24 @@ describe &quot;SubdomainFu&quot; do
     it { SubdomainFu.same_subdomain?(nil,&quot;www.localhost&quot;).should be_true }
     it { SubdomainFu.same_subdomain?(&quot;www&quot;,&quot;awesome.localhost&quot;).should be_false }
   end
+
+  describe &quot;#needs_rewrite?&quot; do
+    it { SubdomainFu.needs_rewrite?(&quot;www&quot;,&quot;www.localhost&quot;).should be_false }
+    it { SubdomainFu.needs_rewrite?(&quot;www&quot;,&quot;localhost&quot;).should be_false }
+    it { SubdomainFu.needs_rewrite?(&quot;awesome&quot;,&quot;www.localhost&quot;).should be_true }
+    it { SubdomainFu.needs_rewrite?(&quot;cool&quot;,&quot;awesome.localhost&quot;).should be_true }
+    it { SubdomainFu.needs_rewrite?(nil,&quot;www.localhost&quot;).should be_false }
+    it { SubdomainFu.needs_rewrite?(nil,&quot;awesome.localhost&quot;).should be_false }
+    it { SubdomainFu.needs_rewrite?(false,&quot;awesome.localhost&quot;).should be_true }
+    it { SubdomainFu.needs_rewrite?(false,&quot;www.localhost&quot;).should be_false }
+    it { SubdomainFu.needs_rewrite?(&quot;www&quot;,&quot;awesome.localhost&quot;).should be_true }
+
+    describe &quot;when preferred_mirror is false&quot; do
+      before do
+        SubdomainFu.preferred_mirror = false
+      end
+
+      it { SubdomainFu.needs_rewrite?(false,&quot;www.localhost&quot;).should be_true }
+    end
+  end
 end
\ No newline at end of file</diff>
      <filename>spec/subdomain_fu_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
 describe &quot;SubdomainFu URL Writing&quot; do
   before do
     SubdomainFu.tld_size = 1
+    SubdomainFu.preferred_mirror = nil
     default_url_options[:host] = &quot;testapp.com&quot;
   end
   
@@ -47,7 +48,12 @@ describe &quot;SubdomainFu URL Writing&quot; do
       default_url_options[:host] = &quot;awesome.testapp.com&quot;
       needs_subdomain_path(:subdomain =&gt; &quot;awesome&quot;).should == &quot;/needs_subdomain&quot;
     end
-    
+
+    it &quot;should force the full url if it's a different subdomain&quot; do
+      default_url_options[:host] = &quot;awesome.testapp.com&quot;
+      needs_subdomain_path(:subdomain =&gt; &quot;crazy&quot;).should == &quot;http://crazy.testapp.com/needs_subdomain&quot;
+    end
+
     it &quot;should not force the full url if the current subdomain is nil and so is the target&quot; do
       needs_subdomain_path(:subdomain =&gt; nil).should == &quot;/needs_subdomain&quot;
     end
@@ -72,11 +78,25 @@ describe &quot;SubdomainFu URL Writing&quot; do
     it &quot;should work when passed in a paramable object&quot; do
       foo_path(Paramed.new(&quot;something&quot;), :subdomain =&gt; &quot;awesome&quot;).should == &quot;http://awesome.testapp.com/foos/something&quot;
     end
+
+    it &quot;should work when passed in a paramable object&quot; do
+      foo_path(Paramed.new(&quot;something&quot;), :subdomain =&gt; &quot;awesome&quot;).should == &quot;http://awesome.testapp.com/foos/something&quot;
+    end
     
+    it &quot;should work when passed in a paramable object and no subdomain to a _path&quot; do
+      default_url_options[:host] = &quot;awesome.testapp.com&quot;
+      foo_path(Paramed.new(&quot;something&quot;)).should == &quot;/foos/something&quot;
+    end
+
+    it &quot;should work when passed in a paramable object and no subdomain to a _url&quot; do
+      default_url_options[:host] = &quot;awesome.testapp.com&quot;
+      foo_url(Paramed.new(&quot;something&quot;)).should == &quot;http://awesome.testapp.com/foos/something&quot;
+    end
+
     it &quot;should work on nested resource collections&quot; do
       foo_bars_path(Paramed.new(&quot;something&quot;), :subdomain =&gt; &quot;awesome&quot;).should == &quot;http://awesome.testapp.com/foos/something/bars&quot;
     end
-    
+
     it &quot;should work on nested resource members&quot; do
       foo_bar_path(Paramed.new(&quot;something&quot;),Paramed.new(&quot;else&quot;), :subdomain =&gt; &quot;awesome&quot;).should == &quot;http://awesome.testapp.com/foos/something/bars/else&quot;
     end
@@ -91,13 +111,13 @@ describe &quot;SubdomainFu URL Writing&quot; do
       default_url_options[:host] = &quot;awesome.testapp.com&quot;
       needs_subdomain_url(:subdomain =&gt; false).should == &quot;http://www.testapp.com/needs_subdomain&quot;
     end
-    
+
     it &quot;should force a switch to no subdomain on a mirror if preferred_mirror is false&quot; do
       SubdomainFu.preferred_mirror = false
       default_url_options[:host] = &quot;www.testapp.com&quot;
       needs_subdomain_url(:subdomain =&gt; false).should == &quot;http://testapp.com/needs_subdomain&quot;
     end
-    
+
     after do
       SubdomainFu.preferred_mirror = nil
     end</diff>
      <filename>spec/url_rewriter_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>24866ce3592203c0563ca581aa8c150f8e0fd767</id>
    </parent>
  </parents>
  <author>
    <name>Eric Lindvall</name>
    <email>eric@5stops.com</email>
  </author>
  <url>http://github.com/mbleigh/subdomain-fu/commit/dab049be969bc848e313bab45ff8ed029f6befdf</url>
  <id>dab049be969bc848e313bab45ff8ed029f6befdf</id>
  <committed-date>2009-05-26T06:33:23-07:00</committed-date>
  <authored-date>2009-05-25T22:47:11-07:00</authored-date>
  <message>Fixing specs and adding other test cases.

Signed-off-by: Michael Bleigh &lt;michael@intridea.com&gt;</message>
  <tree>315b612e71f14729bbdcac54bbe10788d256ea34</tree>
  <committer>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </committer>
</commit>
