views:

243

answers:

1

Hi everyone. I've been getting an error, which I think could be solved by disabling acts_as_audited when running tests, or at least stubbing current_user in audit sweeper. The error is below. What do you think I should do?

NoMethodError in 'Order should create a new instance given valid attributes'
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.current_user
/home/ramon/rails/app/vendor/plugins/acts_as_audited/lib/acts_as_audited/audit_sweeper.rb:73:in `send'
/home/ramon/rails/app/vendor/plugins/acts_as_audited/lib/acts_as_audited/audit_sweeper.rb:73:in `current_user'
/home/ramon/rails/app/vendor/plugins/acts_as_audited/lib/acts_as_audited/audit_sweeper.rb:61:in `after_create'
./spec/models/order_spec.rb:13:

In spec/models/order_spec.rb I've tried stubbing AuditSweeper.current_user, template.current_user, and controller.current_user to return a mock User model. None work.

Any help is appreciated. Thanks!

A: 

it looks as though one of the objects current_user is being called on is nil. so stubbing current user won't work. you need to track down the nil object and make sure it is initialized.

Karmen Blake
You're right - such a simple thing and I missed it. I'll snoop around and try other stuff out.
Ramon Tayag
cool. good luck.
Karmen Blake