rspec控制器规范访问路由

时间:2012-08-28 02:56:59

标签: ruby-on-rails ruby ruby-on-rails-3 rspec ruby-on-rails-3.1

我有一个位置资源并通过以下方式访问:

http://localhost:3000/locations/37/edit

在我的规范中,我有:

it "should allows us to edit" do
  @u=User.find_by_email('jon@domain.com')
  session[:user_id]=@u.id    
  get edit_location_path, {:id => '37'}

但收到以下错误:

Failures:

  1) LocationsController should allows us to edit
     Failure/Error: get edit_location_path, :id => '37'
     ActionController::RoutingError:
       No route matches {:action=>"edit", :controller=>"locations"}
     # ./spec/controllers/locations_controller_spec.rb:12:in `block (2 levels) in <top (required)>'

如何指定此资源的链接?

THX

2 个答案:

答案 0 :(得分:2)

假设它是描述LocationsController的控制器规范,您可以使用get :edit, :id => 37访问它。

答案 1 :(得分:1)

只做get edit_location_path(37) ??