Skip to content

Instantly share code, notes, and snippets.

@joshk
Created February 9, 2011 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshk/818728 to your computer and use it in GitHub Desktop.
Save joshk/818728 to your computer and use it in GitHub Desktop.
Example code for Fix Destroy Arity rails pull request
# Dev with custom destroy taking extra params
class DeveloperWithCustomDestroyMethod < ActiveRecord::Base
self.table_name = 'developers'
has_and_belongs_to_many :projects, :join_table => 'developers_projects', :foreign_key => 'developer_id'
def destroy(options ={})
super
end
end
class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
# test which uses custom destroy
def test_removing_associations_on_destroy_with_a_custom_destroy_method
david = DeveloperWithCustomDestroyMethod.find(1)
assert !david.projects.empty?
david.destroy(:with_due_diligence => true)
assert david.projects.empty?
assert DeveloperWithCustomDestroyMethod.connection.select_all("SELECT * FROM developers_projects WHERE developer_id = 1").empty?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment