测试嵌套控制器:NoMethodError:未定义的方法`空?'为零:NilClass

时间:2013-05-03 10:04:07

标签: ruby-on-rails controller factory-bot rspec-rails slug

我一直试图让我的控制器测试通过...... 我的routes.rb

namespace :school do
  resource :account, :except => [:new, :create, :destroy], :controller => 'account'
  resources :classes, :path => "" do
   resources :discussions do
    resources :comments
  end
  resources :materials
end
end 

MY DiscussionController规格:

describe "POST 'create'" do
 before(:each) do
  @user = FactoryGirl.create(:coordinator_user)
  login_user(@user)
  @klass = FactoryGirl.build(:klass)
  @klass.creator = @user
  @klass.save
  @parameters = FactoryGirl.attributes_for(:discussion, :klass_id => @klass, :user_id => @user)
end

context "with valid parameters" do
  it "creates a new job" do
    expect { post :create, :class_id => @klass.id, :discussion => @parameters }.to   change(Discussion, :count).by(1)
  end

  it "should create a new discussion" do
    post :create, :class_id => @klass.id
    response.should be_redirect
    response.should redirect_to(school_account_path(assigns(:discussion).id))
    assigns(:discussion).should_not be_nil
    assigns(:discussion).should_not be_new_record
  end

end

我得到错误:1)NoMethodError:未定义的方法empty?' for nil:NilClass # ./lib/slug.rb:3:in slug' 无法理解这里的内容是什么。

0 个答案:

没有答案