使用控制器

时间:2015-06-05 15:45:27

标签: ruby-on-rails rspec

我正在使用rspec来测试我的应用程序 我有一个像这样的ID的路线

  match 'promotevuln/moderate/:id' => 'moderate#promotevuln'

这是我用

测试的代码
RSpec.describe ModerateController, :type => :controller do

  describe '#promotevuln' do
    context 'access controle' do
      before :each do
        @vuln=NewVulnerability.new(:description=>'description',:description_eng=>'description',:title=>'title',:title_eng=>'title_eng',:short_description=>'short',:short_description_eng=>'short')
      end

      it 'must be connected' do
        get :promotevuln,{:id=>@vuln.id}
        expect(response).to redirect_to(:controller => 'account', :action => 'login')
      end

但我无法通过此条件并且始终返回此错误消息

Failure/Error: get :promotevuln,{:id=>@vuln.id}
     ActionController::RoutingError:
       No route matches {:controller=>"moderate", :action=>"promotevuln"}

1 个答案:

答案 0 :(得分:0)

您正在实例化新的NewVulnerability,但您没有将其持久保存到数据库,因此其idnil