diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bd210b5..b14e0fc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,32 +1,34 @@ -begin - require File.dirname(__FILE__) + '/../../../../spec/spec_helper' -#rescue LoadError -# puts "You need to install RSpec in your base app. Add 'rspec-rails' to your Gemfile." -# exit -end +require 'action_controller/railtie' +require 'active_support/core_ext/hash/slice' +require 'rspec' +require 'subdomain-fu' + +Rails.env = 'test' -plugin_spec_dir = File.dirname(__FILE__) -ActiveRecord::Base.logger = Logger.new(plugin_spec_dir + "/debug.log") +module SubdomainFu + class TestApplication < Rails::Application + end +end -Rails3::Application.routes.draw do |map| - map.needs_subdomain '/needs_subdomain', :controller => "fu", :action => "awesome" - map.no_subdomain '/no_subdomain', :controller => "fu", :action => "lame" - map.needs_awesome '/needs_awesome', :controller => "fu", :action => "lame" +SubdomainFu::TestApplication.routes.draw do + match '/needs_subdomain' => "fu#awesome", :as => 'needs_subdomain' + match '/no_subdomain' => "fu#lame", :as => 'no_subdomain' + match '/needs_awesome' => "fu#lame", :as => 'needs_awesome' - map.resources :foos do |fu| - fu.resources :bars + resources :foos do + resources :bars end - map.connect '/', :controller => "site", :action => "home", :conditions => {:subdomain => false} - map.connect '/', :controller => "app", :action => "home", :conditions => {:subdomain => true} - map.connect '/', :controller => "mobile", :action => "home", :conditions => {:subdomain => "m"} + match '/' => "site#home", :constraints => { :subdomain => '' } + #match '/' => "app#home", :constraints => { :subdomain => true } + match '/' => "mobile#home", :constraints => { :subdomain => "m" } - map.connect '/subdomain_here', :controller => "app", :action => "success", :conditions => {:subdomain => true} - map.connect '/no_subdomain_here', :controller => "site", :action => "success", :conditions => {:subdomain => false} - map.connect '/m_subdomain_here', :controller => "mobile", :action => "success", :conditions => {:subdomain => "m"} - map.connect '/numbers_only_here', :controller => "numbers", :action => "success", :conditions => {:subdomain => /[0-9]+/} + #match '/subdomain_here' => "app#success", :constraints => { :subdomain => true } + match '/no_subdomain_here' => "site#success", :constraints => { :subdomain => '' } + match '/m_subdomain_here' => "mobile#success", :constraints => { :subdomain => "m" } + match '/numbers_only_here' => "numbers#success", :constraints => { :subdomain => /[0-9]+/ } - map.connect '/:controller/:action/:id' + match ':controller(/:action(/:id(.:format)))' end class Paramed @@ -39,4 +41,4 @@ def to_param end end -include ActionController::UrlWriter +include Rails.application.routes.url_helpers \ No newline at end of file diff --git a/spec/subdomain_fu_spec.rb b/spec/subdomain_fu_spec.rb index 3df42fe..1b73817 100644 --- a/spec/subdomain_fu_spec.rb +++ b/spec/subdomain_fu_spec.rb @@ -2,32 +2,32 @@ describe "SubdomainFu" do before do - SubdomainFu.tld_sizes = SubdomainFu::DEFAULT_TLD_SIZES.dup - SubdomainFu.mirrors = SubdomainFu::DEFAULT_MIRRORS.dup - SubdomainFu.preferred_mirror = nil + SubdomainFu.config.tld_sizes = SubdomainFu::Configuration.defaults[:tld_sizes].dup + SubdomainFu.config.mirrors = SubdomainFu::Configuration.defaults[:mirrors].dup + SubdomainFu.config.preferred_mirror = nil end describe "TLD Sizes" do before do - SubdomainFu.tld_sizes = SubdomainFu::DEFAULT_TLD_SIZES.dup + SubdomainFu.config.tld_sizes = SubdomainFu::Configuration.defaults[:tld_sizes].dup end - it { SubdomainFu.tld_sizes.should be_kind_of(Hash) } + it { SubdomainFu.config.tld_sizes.should be_kind_of(Hash) } it "should have default values for development, test, and production" do - SubdomainFu.tld_sizes[:development].should == 0 - SubdomainFu.tld_sizes[:test].should == 0 - SubdomainFu.tld_sizes[:production].should == 1 + SubdomainFu.config.tld_sizes[:development].should == 0 + SubdomainFu.config.tld_sizes[:test].should == 0 + SubdomainFu.config.tld_sizes[:production].should == 1 end it "#tld_size should be for the current environment" do - SubdomainFu.tld_size.should == SubdomainFu.tld_sizes[RAILS_ENV.to_sym] + SubdomainFu.config.tld_size.should == SubdomainFu.config.tld_sizes[Rails.env.to_sym] end it "should be able to be set for the current environment" do - SubdomainFu.tld_size = 5 - SubdomainFu.tld_size.should == 5 - SubdomainFu.tld_sizes[:test].should == 5 + SubdomainFu.config.tld_size = 5 + SubdomainFu.config.tld_size.should == 5 + SubdomainFu.config.tld_sizes[:test].should == 5 end end @@ -37,7 +37,7 @@ end it "should be false for mirrored subdomains" do - SubdomainFu.has_subdomain?(SubdomainFu.mirrors.first).should be_false + SubdomainFu.has_subdomain?(SubdomainFu.config.mirrors.first).should be_false end it "shoud be false for a nil or blank subdomain" do @@ -50,11 +50,11 @@ describe "#subdomain_from" do it "should return the subdomain based on the TLD of the current environment" do SubdomainFu.subdomain_from("awesome.localhost").should == "awesome" - SubdomainFu.tld_size = 2 + SubdomainFu.config.tld_size = 2 SubdomainFu.subdomain_from("awesome.localhost.co.uk").should == "awesome" - SubdomainFu.tld_size = 1 + SubdomainFu.config.tld_size = 1 SubdomainFu.subdomain_from("awesome.localhost.com").should == "awesome" - SubdomainFu.tld_size = 0 + SubdomainFu.config.tld_size = 0 end it "should join deep subdomains with a period" do @@ -75,7 +75,7 @@ describe "#preferred_mirror?" do describe "when preferred_mirror is false" do before do - SubdomainFu.preferred_mirror = false + SubdomainFu.config.preferred_mirror = false end it "should return true for false" do @@ -98,7 +98,7 @@ end it "should not change the subdomain for a host the same or smaller than the tld size" do - SubdomainFu.tld_size = 1 + SubdomainFu.config.tld_size = 1 SubdomainFu.rewrite_host_for_subdomains("cool","localhost").should == "localhost" end @@ -116,7 +116,7 @@ describe "when preferred_mirror is false" do before do - SubdomainFu.preferred_mirror = false + SubdomainFu.config.preferred_mirror = false end it "should remove the subdomain if passed false when it is a mirror" do @@ -219,7 +219,7 @@ describe "when preferred_mirror is false" do before do - SubdomainFu.preferred_mirror = false + SubdomainFu.config.preferred_mirror = false end it { SubdomainFu.needs_rewrite?("www","www.localhost").should be_false } @@ -236,7 +236,7 @@ describe "when preferred_mirror is string" do before do - SubdomainFu.preferred_mirror = "www" + SubdomainFu.config.preferred_mirror = "www" end it { SubdomainFu.needs_rewrite?("www","www.localhost").should be_false } diff --git a/spec/url_rewriter_spec.rb b/spec/url_rewriter_spec.rb index f35820f..d67321e 100644 --- a/spec/url_rewriter_spec.rb +++ b/spec/url_rewriter_spec.rb @@ -2,10 +2,10 @@ describe "SubdomainFu URL Writing" do before do - SubdomainFu.tld_size = 1 - SubdomainFu.mirrors = SubdomainFu::DEFAULT_MIRRORS.dup - SubdomainFu.override_only_path = true - SubdomainFu.preferred_mirror = nil + SubdomainFu.config.tld_size = 1 + SubdomainFu.config.mirrors = SubdomainFu::Configuration.defaults[:mirrors].dup + SubdomainFu.config.override_only_path = true + SubdomainFu.config.preferred_mirror = nil default_url_options[:host] = "example.com" end @@ -23,12 +23,12 @@ end it "should should not force the full url with :only_path if override_only_path is false (default)" do - SubdomainFu.override_only_path = false + SubdomainFu.config.override_only_path = false url_for(:controller => "something", :action => "other", :subdomain => "awesome", :only_path => true).should == "/something/other" end it "should should force the full url, even with :only_path if override_only_path is true" do - SubdomainFu.override_only_path = true + SubdomainFu.config.override_only_path = true url_for(:controller => "something", :action => "other", :subdomain => "awesome", :only_path => true).should == "http://awesome.example.com/something/other" end end @@ -112,8 +112,8 @@ describe "Preferred Mirror" do before do - SubdomainFu.preferred_mirror = "www" - SubdomainFu.override_only_path = true + SubdomainFu.config.preferred_mirror = "www" + SubdomainFu.config.override_only_path = true end it "should switch to the preferred mirror instead of no subdomain" do @@ -132,18 +132,18 @@ end it "should force a switch to no subdomain on a mirror if preferred_mirror is false" do - SubdomainFu.preferred_mirror = false + SubdomainFu.config.preferred_mirror = false default_url_options[:host] = "www.example.com" needs_subdomain_url(:subdomain => false).should == "http://example.com/needs_subdomain" end after do - SubdomainFu.preferred_mirror = nil + SubdomainFu.config.preferred_mirror = nil end end after do - SubdomainFu.tld_size = 0 + SubdomainFu.config.tld_size = 0 default_url_options[:host] = "localhost" end end