These are the tests
def test_should_reject_missing_entry_attribute
post :create, :entry => { :name => 'entry without content' }
assert assigns(:entry).errors.on(:content)
end
def test_should_add_entry
post :create, :entry => {
:title => 'test entry',
:content => 'test content'
}
assert ! assigns(:entry).new_record?
assert_redirected_to entries_path
assert_not_nil flash[:notice]
end
These are the problem results
1) Error:
test_should_add_entry(EntriesControllerTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.new_record?
/test/functional/entries_controller_test.rb:29:in `test_should_add_entry'
2) Error:
test_should_reject_missing_entry_attribute(EntriesControllerTest):
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.errors
/test/functional/entries_controller_test.rb:22:in `test_should_reject_missing_entry_attribute'
It seems no Entry is being created, however, it works in the application, an new entry is created fine. This is entries_controller.rb
class EntriesController < ApplicationController
before_filter :login_required, :only => [ :new, :create ]
def index
@entry = Entry.find(:all)
end
def new
@entry = Entry.new
end
def show
@entry = Entry.find(params[:id])
end
def edit
@entry = Entry.find(params[:id])
end
def update
@entry = Entry.find(params[:id])
@entry.update_attributes(params[:entry])
render :action => 'show'
end
def create
@entry = Entry.new(params[:entry])
if @entry.save
flash[:notice] = 'Entry was successfully created.'
redirect_to entries_path
else
render :action => 'new'
end
end
def destroy
@entry = Entry.find(params[:id])
@entry.destroy
redirect_to(entries_path)
end
end
Any ideas?