Created
February 9, 2011 16:15
-
-
Save joshk/818728 to your computer and use it in GitHub Desktop.
Example code for Fix Destroy Arity rails pull request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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