Skip to content

Instantly share code, notes, and snippets.

@yellow5
Created February 11, 2011 21:20
Show Gist options
  • Save yellow5/823053 to your computer and use it in GitHub Desktop.
Save yellow5/823053 to your computer and use it in GitHub Desktop.
An example way to verify that a foreigner key is created for your model
context "foreign keys" do
def foreign_key_definition_to(to_table, options={})
defaults = { :primary_key => "id", :column => "#{to_table.singularize}_id" }
defaults[:name] = "#{subject.class.table_name}_#{defaults[:column]}_fk"
options = defaults.merge(options)
Foreigner::ConnectionAdapters::ForeignKeyDefinition.new(subject.class.table_name, to_table, options)
end
it "should include some_model_records with dependent delete" do
subject.connection.foreign_keys(subject.class.table_name).should include(foreign_key_definition_to("some_model_records", { :dependent => :delete }))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment