我一直试图让我的控制器测试通过...我的 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
我的 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: undefined method empty?' for nil:NilClass # ./lib/slug.rb:3:in
slug' 无法理解这里的 nil 是什么。