Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ClayShentrup/2f5e35cc8f980b6ded9c26e65585f18f to your computer and use it in GitHub Desktop.
Save ClayShentrup/2f5e35cc8f980b6ded9c26e65585f18f to your computer and use it in GitHub Desktop.
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