Agile Web Development with Rails, Edition 4

Agile Web Development with Rails, Edition 4

21.1 Views 19 Active Record

20.1 Testing Routes

1\d tests, 4\d assertions, 0 failures, 0 errors.

Traceback:
  /home/rubys/git/awdwr/edition4/checkdepot.rb:315:in `block in <class:DepotTest>'
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
/home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:167:in `block in non_options': file not found: test/unit/**/*_test.rb (ArgumentError)
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:146:in `map!'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:146:in `non_options'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:207:in `non_options'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:52:in `process_args'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/minitest/unit.rb:891:in `_run'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/minitest/unit.rb:884:in `run'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:21:in `run'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:606:in `run'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:326:in `block (2 levels) in autorun'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:27:in `run_once'
	from /home/rubys/.rvm/rubies/ruby-1.9.3-r33476/lib/ruby/1.9.1/test/unit.rb:325:in `block in autorun'
rake aborted!
Command failed with status (1): [/home/rubys/.rvm/rubies/ruby-1.9.3-r33476/...]

    
Tasks: TOP => test:units
(See full trace by running task with --trace)

21.1 Views 19 Active Record