Rspec控制器错误:没有路由匹配{:controller =>“预订”,:action =>“/ dashboard / index”}

时间:2013-02-15 16:27:57

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

当我尝试测试mi控制器时出现错误,我是rspec测试的新手,也许还有一些我不会做的事情。

$ rspec spec / controllers / booking_controller_spec.rb

我收到以下错误:

没有路线匹配{:controller =>“预订”,:action =>“/ dashboard / index”}

我不明白为什么?所以,如果有任何帮助,我真的很感激一些帮助。

文件结构:

app/models/booking.rb
app/models/user.rb
app/models/role.rb
app/models/ability.rb   

app/controllers/bookings_controller.rb

app/views/bookings/index.html.erb
app/views/dashboard/index.html.erb

app/spec/controllers/bookings_controller_spec.rb

我的失败规范:

describe BookingsController do
    context 'as guest' do
    before(:each) do
        @user = User.new(:email => 'mail_admin@test.com',
                    :username => 'admin',
                    :password => 'password_admin',
                    :password_confirmation => 'password_admin')
        @user.save
        #when i save, with gem CanCan i assign a default role to @user
        #with the default role the user only can see the views/dashboard/index.html.erb
    end

    it 'should not render index template from bookings' do
        get :index
        response.should_not render_template(:index)
    end

    it 'should render index template from dashboard' do
        get '/dashboard/index'
        response.should render_template('index')
    end
end 
end

控制器:

class BookingsController < ApplicationController
load_and_authorize_resource

   def index
    ...      
   end

   def show
    ...
   end
end

我的模特:

class Booking < Activerecord::Base
paginates_per 20

   def 
    ...      
   end

   def 
    ...
   end
end

用户:

Class User < ActiveRecord::Base
  after_save :set_default_role
  rolify
  .
  .
  .
  .
  def set_default_role
    self.add_role :default
  end
end

作用:

class Role < ActiveRecord::Base
  ROLES = {"admin" => "Admin", "default" => "Default"}
  .
  .
  .
  . 
  scopify
end

能力:

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new
    if user.has_role? :admin
      can :manage, :all
    elsif user.has_role? :data_consistency
      can :read, Booking
    end
  end
end

0 个答案:

没有答案