Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cascade deletes

  • Loading branch information...
commit 04f3a34ddb4b24cd62b8d291ac1e057f6f7f87e2 1 parent 37d2490
@mwilden mwilden authored
View
2  app/models/protonym.rb
@@ -1,6 +1,6 @@
# coding: UTF-8
class Protonym < ActiveRecord::Base
- belongs_to :authorship, :class_name => 'Citation'
+ belongs_to :authorship, class_name: 'Citation', dependent: :destroy
def self.import data
transaction do
View
6 app/models/taxon.rb
@@ -6,10 +6,10 @@ class Taxon < ActiveRecord::Base
belongs_to :synonym_of, :class_name => 'Taxon', :foreign_key => :synonym_of_id
has_one :homonym_replaced, :class_name => 'Taxon', :foreign_key => :homonym_replaced_by_id
- belongs_to :protonym
+ belongs_to :protonym, dependent: :destroy
belongs_to :homonym_replaced_by, :class_name => 'Taxon'
- has_many :taxonomic_history_items, :order => :position
- has_many :reference_sections, :order => :position
+ has_many :taxonomic_history_items, order: :position, dependent: :destroy
+ has_many :reference_sections, :order => :position, dependent: :destroy
validates_presence_of :name
View
9 features/step_definitions/taxon_steps.rb
@@ -1,11 +1,8 @@
# coding: UTF-8
Given /^the Formicidae family exists$/ do
- Taxon.delete_all
- Protonym.delete_all
- Citation.delete_all
- ForwardReference.delete_all
- Reference.delete_all
- TaxonomicHistoryItem.delete_all
+ Taxon.destroy_all
+ ForwardReference.destroy_all
+ Reference.destroy_all
Factory :article_reference, :author_names => [Factory(:author_name, :name => 'Latreille, I.')], :citation_year => '1809', :title => 'Ants', :bolton_key_cache => 'Latreille 1809'
View
2  features/support/hooks.rb
@@ -1,6 +1,6 @@
# coding: UTF-8
Before do
- Family.delete_all
+ Family.destroy_all
Factory :family, protonym: nil
$ReleaseType = ProductionReleaseType.new
end
View
8 lib/importers/bolton/catalog/species/importer.rb
@@ -2,9 +2,11 @@
class Importers::Bolton::Catalog::Species::Importer < Importers::Bolton::Catalog::Importer
def initialize options = {}
- Species.delete_all
- Subspecies.delete_all
- ForwardReference.delete_all
+
+ Species.destroy_all
+ Subspecies.destroy_all
+ ForwardReference.destroy_all
+
@options = options.reverse_merge show_progress: false
@continue_after_parse_error = true
@return_blank_lines = false
View
8 lib/importers/bolton/catalog/subfamily/importer.rb
@@ -19,11 +19,9 @@
class Importers::Bolton::Catalog::Subfamily::Importer < Importers::Bolton::Catalog::Importer
def import
- Taxon.delete_all
- Protonym.delete_all
- Citation.delete_all
- ForwardReference.delete_all
- MissingReference.delete_all
+ Taxon.destroy_all
+ ForwardReference.destroy_all
+ MissingReference.destroy_all
parse_family
parse_supersubfamilies
View
12 spec/models/protonym_spec.rb
@@ -66,4 +66,16 @@
end
+ describe "Cascading delete" do
+ it "should delete the citation when the protonym is deleted" do
+ genus = FactoryGirl.create :genus, tribe: nil, subfamily: nil
+ Protonym.count.should == 1
+ Citation.count.should == 1
+
+ genus.destroy
+ Protonym.count.should be_zero
+ Citation.count.should be_zero
+ end
+ end
+
end
View
26 spec/models/taxon_spec.rb
@@ -326,4 +326,30 @@
end
end
+ describe "Cascading delete" do
+ it "should delete the protonym when the taxon is deleted" do
+ Taxon.count.should be_zero
+ Protonym.count.should be_zero
+
+ genus = FactoryGirl.create :genus, tribe: nil, subfamily: nil
+ Taxon.count.should == 1
+ Protonym.count.should == 1
+
+ genus.destroy
+ Taxon.count.should be_zero
+ Protonym.count.should be_zero
+ end
+ it "should delete history and reference sections when the taxon is deleted" do
+ Taxon.count.should be_zero
+ ReferenceSection.count.should be_zero
+
+ genus = FactoryGirl.create :genus, tribe: nil, subfamily: nil
+ genus.reference_sections.create! title: 'title', references: 'references'
+ ReferenceSection.count.should == 1
+
+ genus.destroy
+ ReferenceSection.count.should be_zero
+ end
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.