forked from prepor/subdomain_routes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed specs and code for assertions for subdomain route recogniti…
…on and generation.
- Loading branch information
Showing
7 changed files
with
131 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
require 'test/unit/testresult' | ||
require 'spec_helper' | ||
|
||
class UsersController < ActionController::Base | ||
end | ||
|
||
describe "routing assertions" do | ||
before(:each) do | ||
map_subdomain(:admin, :name => nil) do |admin| | ||
admin.resources :users | ||
end | ||
@options = { :controller => "users", :action => "index", :subdomains => [ "admin" ] } | ||
end | ||
|
||
context "for recognition" do | ||
it "should correctly succeed with a :host option and a subdomain route" do | ||
test = lambda { assert_recognizes_with_host(@options, { :path => "/users", :host => "admin.example.com" }) } | ||
test.should_not have_errors | ||
test.should_not fail | ||
end | ||
|
||
it "should correctly fail with a :host option and a subdomain route" do | ||
test = lambda { assert_recognizes_with_host(@options, { :path => "/users", :host => "www.example.com" } ) } | ||
test.should have_errors | ||
end | ||
end | ||
|
||
context "for generation" do | ||
it "should correctly succeed with :host and :path options and a subdomain route which changes the subdomain" do | ||
test = lambda { assert_generates_with_host("http://admin.example.com/users", "www.example.com", @options) } | ||
test.should_not have_errors | ||
test.should_not fail | ||
end | ||
|
||
it "should correctly fail with :host and :path options and a subdomain route which changes the subdomain" do | ||
test = lambda { assert_generates_with_host("http://admin.example.com/users", "admin.example.com", @options) } | ||
test.should_not have_errors | ||
test.should fail | ||
end | ||
|
||
it "should correctly succeed with :host and :path options and a subdomain route which doesn't change the subdomain" do | ||
test = lambda { assert_generates_with_host("/users", "admin.example.com", @options) } | ||
test.should_not have_errors | ||
test.should_not fail | ||
end | ||
|
||
it "should correctly fail with :host and :path options and a subdomain route which doesn't change the subdomain" do | ||
test = lambda { assert_generates_with_host("/users", "www.example.com", @options) } | ||
test.should_not have_errors | ||
test.should fail | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module SubdomainRoutes | ||
module TestUnitMatcher | ||
class Base | ||
class TestCase < ActionController::TestCase | ||
end | ||
|
||
def initialize(count_method, messages, spec) | ||
@count_method, @messages, @spec = count_method, messages, spec | ||
end | ||
|
||
def run_test(target) | ||
result = Test::Unit::TestResult.new | ||
spec = @spec | ||
TestCase.send :define_method, :test do | ||
copy_instance_variables_from(spec) | ||
instance_eval(&target) | ||
end | ||
TestCase.new(:test).run(result) {} | ||
result | ||
end | ||
|
||
def matches?(target) | ||
@result = run_test(target) | ||
@result_count = @result.send(@count_method) | ||
@result_count > 0 | ||
end | ||
|
||
def failure_message | ||
"Expected #{@count_method.to_s.humanize.downcase} to be more than zero, got zero.\n" | ||
end | ||
|
||
def negative_failure_message | ||
"Expected #{@count_method.to_s.humanize.downcase} to be zero, got #{@result_count}:\n" + | ||
@result.instance_variable_get(@messages).map(&:inspect).join("\n") | ||
end | ||
end | ||
|
||
def have_errors | ||
Base.new(:error_count, :@errors, self) | ||
end | ||
|
||
def fail | ||
Base.new(:failure_count, :@failures, self) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters