I'm using Rails 3.2.13 with postgres, rspec 2.13, capybara 2.0.3 and database_cleaner 0.9.1. I'm also using AngularJS. I have a spec with js:true which tests the submission of a form (creating a standard rails model instance). The only thing that's maybe not standard Rails is that I submit this form via Ajax using AngularJS. Whenever the spec runs, I get the following error:
An error occurred in an after hook
NoMethodError: undefined method `each' for nil:NilClass
occurred at /Users/morgler/.rvm/gems/ruby-1.9.3-p194@pennyworth/gems/activerecord- 3.2.13/lib/active_record/associations/collection_association.rb:310:in `replace'
The spec subsequently fails. To me it seems, this error occurs in the after hook when the database_cleaner runs. I got this in my spec_helper.rb:
config.before(:each) do
if Capybara.current_driver == :rack_test
DatabaseCleaner.strategy = :transaction
else
DatabaseCleaner.strategy = :truncation
end
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
The code to submit the form via AngularJS upon clicking the form's submit button is:
$scope.saveOrderProcess = (event) ->
if $scope.orderProcess.id
$scope.orderProcess.$update()
else
OrderProcess.create($scope.orderProcess)
Any idea, what I am missing here?