Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
RSpec.shared_examples('a foreign_key constraint association') do
specify do
expect do
build(described_model, "#{association}_id" => 0).save(validate: false)
end.to raise_error(ActiveRecord::InvalidForeignKey)
end
end
RSpec.describe(Employee) do
describe('associations') do
it_behaves_like('a foreign_key constraint association') do
let(:association) { :employer }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment