Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

moved should_route macro into controller/macros

  • Loading branch information...
commit 5996f2804fdb7858d4d55ebdbed47ceade8bb6a2 1 parent da5e4b1
@croaky croaky authored
View
1  lib/shoulda/controller.rb
@@ -2,7 +2,6 @@
require 'shoulda/controller/helpers'
require 'shoulda/controller/resource_options'
require 'shoulda/controller/macros'
-require 'shoulda/controller/routing'
module Test # :nodoc: all
module Unit
View
38 lib/shoulda/controller/macros.rb
@@ -165,6 +165,44 @@ def should_render_a_form
assert_select "form", true, "The template doesn't contain a <form> element"
end
end
+
+ # Macro that creates a routing test. It tries to use the given HTTP
+ # +method+ on the given +path+, and asserts that it routes to the
+ # given +options+.
+ #
+ # If you don't specify a :controller, it will try to guess the controller
+ # based on the current test.
+ #
+ # +to_param+ is called on the +options+ given.
+ #
+ # Examples:
+ #
+ # should_route :get, '/posts', :action => :index
+ # should_route :post, '/posts', :controller => :posts, :action => :create
+ # should_route :get, '/posts/1', :action => :show, :id => 1
+ # should_route :put, '/posts/1', :action => :update, :id => "1"
+ # should_route :delete, '/posts/1', :action => :destroy, :id => 1
+ # should_route :get, '/posts/new', :action => :new
+ #
+ def should_route(method, path, options)
+ unless options[:controller]
+ options[:controller] = self.name.gsub(/ControllerTest$/, '').tableize
+ end
+ options[:controller] = options[:controller].to_s
+ options[:action] = options[:action].to_s
+
+ populated_path = path.dup
+ options.each do |key, value|
+ options[key] = value.to_param if value.respond_to? :to_param
+ populated_path.gsub!(key.inspect, value.to_s)
+ end
+
+ should_name = "route #{method.to_s.upcase} #{populated_path} to/from #{options.inspect}"
+
+ should should_name do
+ assert_routing({:method => method, :path => populated_path}, options)
+ end
+ end
end
end
end
View
10 lib/shoulda/controller/routing.rb
@@ -1,10 +0,0 @@
-require 'shoulda'
-require 'shoulda/controller/routing/macros'
-
-module Test # :nodoc: all
- module Unit
- class TestCase
- extend ThoughtBot::Shoulda::Controller::Routing::Macros
- end
- end
-end
View
47 lib/shoulda/controller/routing/macros.rb
@@ -1,47 +0,0 @@
-module ThoughtBot
- module Shoulda
- module Controller
- module Routing
- module Macros
- # Macro that creates a routing test. It tries to use the given HTTP
- # +method+ on the given +path+, and asserts that it routes to the
- # given +options+.
- #
- # If you don't specify a :controller, it will try to guess the controller
- # based on the current test.
- #
- # +to_param+ is called on the +options+ given.
- #
- # Examples:
- #
- # should_route :get, '/posts', :action => :index
- # should_route :post, '/posts', :controller => :posts, :action => :create
- # should_route :get, '/posts/1', :action => :show, :id => 1
- # should_route :put, '/posts/1', :action => :update, :id => "1"
- # should_route :delete, '/posts/1', :action => :destroy, :id => 1
- # should_route :get, '/posts/new', :action => :new
- #
- def should_route(method, path, options)
- unless options[:controller]
- options[:controller] = self.name.gsub(/ControllerTest$/, '').tableize
- end
- options[:controller] = options[:controller].to_s
- options[:action] = options[:action].to_s
-
- populated_path = path.dup
- options.each do |key, value|
- options[key] = value.to_param if value.respond_to? :to_param
- populated_path.gsub!(key.inspect, value.to_s)
- end
-
- should_name = "route #{method.to_s.upcase} #{populated_path} to/from #{options.inspect}"
-
- should should_name do
- assert_routing({:method => method, :path => populated_path}, options)
- end
- end
- end
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.