From 915de7ace2fd2c5b25dd10bae66c55d8c6419f85 Mon Sep 17 00:00:00 2001 From: Michael Bleigh Date: Tue, 17 Jun 2008 11:52:04 -0500 Subject: [PATCH] Autotest is now working, added specs for resource-routing url writing. Routing extensions aren't working, no idea why. --- lib/autotest/discover.rb | 6 ++++++ lib/subdomain_fu/routing_extensions.rb | 10 +++++++--- rails/init.rb | 3 --- spec/routing_extension_spec.rb | 5 +++++ spec/spec.opts | 7 +++++++ spec/spec_helper.rb | 20 +++++++++++++++++--- spec/url_rewriter_spec.rb | 26 +++++++++++++++++++++++++- 7 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 lib/autotest/discover.rb create mode 100644 spec/routing_extension_spec.rb create mode 100644 spec/spec.opts diff --git a/lib/autotest/discover.rb b/lib/autotest/discover.rb new file mode 100644 index 0000000..32bd12c --- /dev/null +++ b/lib/autotest/discover.rb @@ -0,0 +1,6 @@ +# Need this to get picked up by autotest? +$:.push(File.join(File.dirname(__FILE__), %w[.. .. rspec])) + +Autotest.add_discovery do + "rspec" +end \ No newline at end of file diff --git a/lib/subdomain_fu/routing_extensions.rb b/lib/subdomain_fu/routing_extensions.rb index a695d08..39a2fd1 100644 --- a/lib/subdomain_fu/routing_extensions.rb +++ b/lib/subdomain_fu/routing_extensions.rb @@ -9,15 +9,16 @@ def self.included(base) def recognition_conditions_with_subdomain result = recognition_conditions_without_subdomain - result << "conditions[:subdomain] === env[:subdomain]" if conditions[:subdomain] && conditions[:subdomain] != true + result << "conditions[:subdomain] === env[:subdomain]" if conditions[:subdomain] && conditions[:subdomain] != true && conditions[:subdomain] != false result << "SubdomainFu.has_subdomain?(env[:subdomain])" if conditions[:subdomain] == true + result << "!SubdomainFu.has_subdomain?(env[:subdomain])" if conditions[:subdomain] == false result end end module RouteSetExtensions def self.included(base) - base.alias_method_chain :extract_request_environment, :subdomain + base.alias_method_chain :extract_request_environment, :subdomain end def extract_request_environment_with_subdomain(request) @@ -25,4 +26,7 @@ def extract_request_environment_with_subdomain(request) env.merge(:host => request.host, :domain => request.domain, :subdomain => SubdomainFu.subdomain_from(request.host)) end end -end \ No newline at end of file +end + +ActionController::Routing::RouteSet.send :include, SubdomainFu::RouteSetExtensions +ActionController::Routing::Route.send :include, SubdomainFu::RouteExtensions \ No newline at end of file diff --git a/rails/init.rb b/rails/init.rb index fa211ca..c7eb8c5 100644 --- a/rails/init.rb +++ b/rails/init.rb @@ -2,7 +2,4 @@ ActionController::Base.send :include, SubdomainFu::Controller -ActionController::Routing::RouteSet.send :include, SubdomainFu::RouteSetExtensions -ActionController::Routing::Route.send :include, SubdomainFu::RouteExtensions - RAILS_DEFAULT_LOGGER.info("** SubdomainFu: initialized properly") \ No newline at end of file diff --git a/spec/routing_extension_spec.rb b/spec/routing_extension_spec.rb new file mode 100644 index 0000000..07d0e87 --- /dev/null +++ b/spec/routing_extension_spec.rb @@ -0,0 +1,5 @@ +require File.dirname(__FILE__) + '/spec_helper' + +describe "SubdomainFu Routing" do + it "should not recognize a subdomainless request for a subdomain-required request" +end \ No newline at end of file diff --git a/spec/spec.opts b/spec/spec.opts new file mode 100644 index 0000000..49fd993 --- /dev/null +++ b/spec/spec.opts @@ -0,0 +1,7 @@ +--colour +--format +specdoc +--loadby +mtime +--reverse +--backtrace \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1c72c3d..f4236a6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,10 +10,24 @@ ActionController::Routing::Routes.draw do |map| map.needs_subdomain '/needs_subdomain', :controller => "fu", :action => "awesome", :conditions => {:subdomain => true} - map.resources :fu_somethings, :conditions => {:subdomain => true} + map.no_subdomain '/no_subdomain', :controller => "fu", :action => "lame", :conditions => {:subdomain => false} + map.needs_awesome '/needs_awesome', :controller => "fu", :action => "lame", :conditions => {:subdomain => 'awesome'} + + map.resources :foos, :conditions => {:subdomain => true} do |fu| + fu.resources :bars + end + map.connect '/:controller/:action/:id' end +class Paramed + def initialize(param) + @param = param + end + + def to_param + @param || "param" + end +end -include ActionController::UrlWriter -default_url_options[:host] = "testapp.com" \ No newline at end of file +include ActionController::UrlWriter \ No newline at end of file diff --git a/spec/url_rewriter_spec.rb b/spec/url_rewriter_spec.rb index 116c2fc..4041916 100644 --- a/spec/url_rewriter_spec.rb +++ b/spec/url_rewriter_spec.rb @@ -3,6 +3,7 @@ describe "SubdomainFu URL Writing" do before do SubdomainFu.tld_size = 1 + default_url_options[:host] = "testapp.com" end describe "#url_for" do @@ -43,8 +44,31 @@ end end + describe "Resourced Routes" do + it "should be able to add a subdomain" do + foo_path(:id => "something", :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something" + end + + it "should be able to remove a subdomain" do + default_url_options[:host] = "awesome.testapp.com" + foo_path(:id => "something", :subdomain => false).should == "http://testapp.com/foos/something" + end + + it "should work when passed in a paramable object" do + foo_path(Paramed.new("something"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something" + end + + it "should work on nested resource collections" do + foo_bars_path(Paramed.new("something"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something/bars" + end + + it "should work on nested resource members" do + foo_bar_path(Paramed.new("something"),Paramed.new("else"), :subdomain => "awesome").should == "http://awesome.testapp.com/foos/something/bars/else" + end + end + after do SubdomainFu.tld_size = 0 - default_url_options[:host] = "testapp.com" + default_url_options[:host] = "localhost" end end \ No newline at end of file