我有一个这样的控制器
class RegistrationsController < Devise::RegistrationsController
before_filter :authenticate_user!, :only => [ :finalize ]
prepend_before_filter :require_no_authentication, :only => [ :complete ]
def complete
#blah
end
def finalize
#blah
end
end
在路线中它看起来像这样:
Blah::Application.routes.draw do
root to: "requests#index"
devise_for :users, :path => '', :path_names => { :sign_in => 'login', :sign_out => 'logout' }, :controllers => { :passwords => "passwords", confirmations: 'confirmations' }
#blahblah
devise_scope :user do
get '/register/:id/:token' => 'registrations#new', as: 'register'
put '/register/:id/:token' => 'registrations#complete', as: 'complete_user'
match "/finalize" => 'registrations#finalize', :as => :finalize
end
end
现在我想complete
从测试中访问这个动作:
let(:params) {
{
id: 1,
invitation_token: "INVITATION_TOKEN",
email: 'email@reporter.com',
name: 'Name',
surname: 'Surname',
title: 'Title',
password: 'asdasdasd'
}
}
it 'should be redirected to the page with information about sending confirmation email' do
put :complete, params
response.should redirect_to(verification_path)
end
它失败了:
1) RegistrationsController#complete when invited email isn't on a whitelist should be redirected to the page with information about sending confirmation email
Failure/Error: put :complete, params
ActionController::RoutingError:
No route matches {:id=>"1", :invitation_token=>"INVITATION_TOKEN", :email=>"email@reporter.com", :name=>"Name", :surname=>"Surname", :title=>"Title", :password=>"asdasdasd", :controller=>"registrations", :action=>"complete"}
# ./spec/controllers/registrations_controller_spec.rb:29:in `block (4 levels) in <top (required)>'
如何complete
从 RSpec 测试访问此操作?