How do you test a controller create action with a belongs_to association that is required?
If I remove validates :address, presence: true
it works, but this validation is necessary.
models/accreditor.rb
class Accreditor < ActiveRecord::Base
belongs_to :address, dependent: :destroy
validates :address, presence: true
spec/controllers/accreditors_controller_spec.rb
describe AccreditorsController do
describe 'POST #create' do
it 'saves the new accreditor in the database' do
address = FactoryGirl.create(:address)
accreditor = FactoryGirl.build(:accreditor, address: address)
expect{
post :create, accreditor: accreditor.attributes
}.to change(Accreditor, :count).by(1)
end
end
Also, the accreditor and address factories work for all other controller actions.
This appears to be the best solution.