21.1 Views 19 Action Controller
edit test/unit/routing_test.rb
require 'test_helper'
require './config/routes.rb'
class RoutingTest < ActionController::TestCase
def test_recognizes
# Check the default index action gets generated
assert_recognizes({"controller" => "store", "action" => "index"}, "/")
# Check routing to an action
assert_recognizes({"controller" => "products", "action" => "index"},
"/products")
# And routing with a parameter
assert_recognizes({ "controller" => "line_items",
"action" => "create",
"product_id" => "1" },
{:path => "/line_items", :method => :post},
{"product_id" => "1"})
end
def test_generates
assert_generates("/", :controller => "store", :action => "index")
assert_generates("/products",
{ :controller => "products", :action => "index"})
assert_generates("/line_items",
{ :controller => "line_items", :action => "create",
:product_id => "1"},
{:method => :post}, { :product_id => "1"})
end
def test_routing
assert_routing("/", :controller => "store", :action => "index")
assert_routing("/products", :controller => "products", :action => "index")
assert_routing({:path => "/line_items", :method => :post},
{ :controller => "line_items", :action => "create",
:product_id => "1"},
{}, { :product_id => "1"})
end
end
rake test:units
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Loaded suite /home/rubys/.rvm/gems/ruby-1.8.7-p374/gems/rake-10.1.1/lib/rake/rake_test_loader
Started
..........
Finished in 0.395809 seconds.
10 tests, 46 assertions, 0 failures, 0 errors