开发者

Testing member routes of a resources in rails3 with rspec

开发者 https://www.devze.com 2023-02-19 08:56 出处:网络
I\'m creating an application that will allow the user to take an exam. The exam object has_many questions and I want the user to take the exam in two parts. In order to implement this workflow, I\'ve

I'm creating an application that will allow the user to take an exam. The exam object has_many questions and I want the user to take the exam in two parts. In order to implement this workflow, I've created the following routes in config/routes.rb:

resources :exam do
  member do
    get 'get_part1'
    put 'put_part1'
    get 'get_part2'
    put 'put_part2'
  end
end

So, when the user issues GET /exam/:id/get_part1 they are shown the first set of questions, etc... I have all of this working and now I'm trying to write tests for it - I know that's backwards but it took me a while to figure out complex forms and stuff. I want to test that you cannot access the exam controller unless you are a signed in user. This is straight forward for new and create but I'm having trou开发者_StackOverflowble figuring out how to test the nested members. Here's what I've tried so far:

before(:each) do
  @exam = Exam.create
end                                                       

it "should deny access to 'get_part1'" do
  get get_part1_exam_path(@exam)                            
  response.should redirect_to(signin_path)
end

However, this test fails with the following error:

Failure/Error: get get_part1_exam_path(@exam)
ActionController::RoutingError:
  No route matches {:controller=>"exams", :action=>"/exams/1/get_part1"}

Any help would be greatly appreciated. Thanks!


Try that one:

get :get_part1, :id => @exam   (or @exam.id)
0

精彩评论

暂无评论...
验证码 换一张
取 消