spec/subdomain_fu_spec.rb in mbleigh-subdomain-fu-0.0.5 vs spec/subdomain_fu_spec.rb in mbleigh-subdomain-fu-0.1.0

- old
+ new

@@ -1,8 +1,13 @@ require File.dirname(__FILE__) + '/spec_helper' describe "SubdomainFu" do + before do + SubdomainFu.tld_sizes = SubdomainFu::DEFAULT_TLD_SIZES.dup + SubdomainFu.preferred_mirror = nil + end + describe "TLD Sizes" do before do SubdomainFu.tld_sizes = SubdomainFu::DEFAULT_TLD_SIZES.dup end @@ -35,10 +40,11 @@ end it "shoud be false for a nil or blank subdomain" do SubdomainFu.has_subdomain?("").should be_false SubdomainFu.has_subdomain?(nil).should be_false + SubdomainFu.has_subdomain?(false).should be_false end end describe "#subdomain_from" do it "should return the subdomain based on the TLD of the current environment" do @@ -61,11 +67,23 @@ it "#host_without_subdomain should chop of the subdomain and return the rest" do SubdomainFu.host_without_subdomain("awesome.localhost:3000").should == "localhost:3000" SubdomainFu.host_without_subdomain("something.awful.localhost:3000").should == "localhost:3000" end - + + describe "#preferred_mirror?" do + describe "when preferred_mirror is false" do + before do + SubdomainFu.preferred_mirror = false + end + + it "should return true for false" do + SubdomainFu.preferred_mirror?(false).should be_true + end + end + end + describe "#rewrite_host_for_subdomains" do it "should not change the same subdomain" do SubdomainFu.rewrite_host_for_subdomains("awesome","awesome.localhost").should == "awesome.localhost" end @@ -78,14 +96,32 @@ end it "should remove the subdomain if passed false when it's not a mirror" do SubdomainFu.rewrite_host_for_subdomains(false,"cool.localhost").should == "localhost" end - + it "should not remove the subdomain if passed false when it is a mirror" do SubdomainFu.rewrite_host_for_subdomains(false,"www.localhost").should == "www.localhost" end + + it "should not remove the subdomain if passed nil when it's not a mirror" do + SubdomainFu.rewrite_host_for_subdomains(nil,"cool.localhost").should == "cool.localhost" + end + + describe "when preferred_mirror is false" do + before do + SubdomainFu.preferred_mirror = false + end + + it "should remove the subdomain if passed false when it is a mirror" do + SubdomainFu.rewrite_host_for_subdomains(false,"www.localhost").should == "localhost" + end + + it "should not remove the subdomain if passed nil when it's not a mirror" do + SubdomainFu.rewrite_host_for_subdomains(nil,"cool.localhost").should == "cool.localhost" + end + end end describe "#change_subdomain_of_host" do it "should change it if passed a different one" do SubdomainFu.change_subdomain_of_host("awesome","cool.localhost").should == "awesome.localhost" @@ -127,7 +163,28 @@ it { SubdomainFu.same_subdomain?("www","localhost").should be_true } it { SubdomainFu.same_subdomain?("awesome","www.localhost").should be_false } it { SubdomainFu.same_subdomain?("cool","awesome.localhost").should be_false } it { SubdomainFu.same_subdomain?(nil,"www.localhost").should be_true } it { SubdomainFu.same_subdomain?("www","awesome.localhost").should be_false } + end + + describe "#needs_rewrite?" do + it { SubdomainFu.needs_rewrite?("www","www.localhost").should be_false } + it { SubdomainFu.needs_rewrite?("www","localhost").should be_false } + it { SubdomainFu.needs_rewrite?("awesome","www.localhost").should be_true } + it { SubdomainFu.needs_rewrite?("cool","awesome.localhost").should be_true } + it { SubdomainFu.needs_rewrite?(nil,"www.localhost").should be_false } + it { SubdomainFu.needs_rewrite?(nil,"awesome.localhost").should be_false } + it { SubdomainFu.needs_rewrite?(false,"awesome.localhost").should be_true } + it { SubdomainFu.needs_rewrite?(false,"www.localhost").should be_false } + it { SubdomainFu.needs_rewrite?("www","awesome.localhost").should be_true } + + describe "when preferred_mirror is false" do + before do + SubdomainFu.preferred_mirror = false + end + + it { SubdomainFu.needs_rewrite?(false,"www.localhost").should be_true } + it { SubdomainFu.needs_rewrite?(nil,"awesome.localhost").should be_false } + end end end \ No newline at end of file