Permalink
Browse files

Handle another way of specifying parent species

  • Loading branch information...
mwilden committed Aug 15, 2012
1 parent 9820626 commit f40a5e3929e39a552082e26172f622b2a844f9e0
Showing with 37 additions and 21 deletions.
  1. +5 −2 app/models/subspecies.rb
  2. +32 −19 spec/models/subspecies_spec.rb
View
@@ -38,12 +38,15 @@ def create_forward_ref_to_parent_species data
end
def self.get_currently_subspecies_of_from_history history
+ parent_species = nil
for item in history or []
if item[:currently_subspecies_of]
- return item[:currently_subspecies_of][:species][:species_epithet]
+ parent_species = item[:currently_subspecies_of][:species][:species_epithet]
+ elsif item[:revived_from_synonymy]
+ parent_species = item[:revived_from_synonymy][:subspecies_of].try(:[], :species_epithet)
end
end
- nil
+ parent_species
end
end
@@ -47,26 +47,39 @@
ref.epithet.should == 'gilviventris'
end
- it "should import a subspecies that has a subspecies protonym for a different species than current" do
- genus = create_genus 'Camponotus'
- create_species 'Camponotus hova'
+ describe "When the protonym has a different species" do
+ it "should insert the species from the 'Currently subspecies of' history item" do
+ genus = create_genus 'Camponotus'
+ create_species 'Camponotus hova'
+ subspecies = Species.import(
+ genus: genus,
+ species_group_epithet: 'radamae',
+ protonym: {
+ genus_name: 'Camponotus',
+ species_epithet: 'maculatus',
+ subspecies: [{type: 'r.', subspecies_epithet: 'radamae'}]
+ },
+ raw_history: [{currently_subspecies_of: {species: {species_epithet: 'hova'}}}]
+ )
+ Subspecies.find(subspecies).name.to_s.should == 'Camponotus hova maculatus r. radamae'
+ end
- subspecies = Species.import(
- genus: genus,
- species_group_epithet: 'radamae',
- protonym: {
- genus_name: 'Camponotus',
- species_epithet: 'maculatus',
- subspecies: [{type: 'r.', subspecies_epithet: 'radamae'}]
- },
- raw_history: [{currently_subspecies_of: {species: {species_epithet: 'hova'}}}]
- )
- subspecies = Subspecies.find subspecies
- subspecies.name.to_s.should == 'Camponotus hova maculatus r. radamae'
- ref = SpeciesGroupForwardRef.first
- ref.fixee.should == subspecies
- ref.genus.should == genus
- ref.epithet.should == 'hova'
+ it "should insert the species from the 'Revived from synonymy as subspecies of' history item" do
+ genus = create_genus 'Crematogaster'
+ create_species 'Crematogaster castanea'
+
+ subspecies = Species.import(
+ genus: genus,
+ species_group_epithet: 'mediorufa',
+ protonym: {
+ genus_name: 'Crematogaster',
+ species_epithet: 'tricolor',
+ subspecies: [{type: 'var.', subspecies_epithet: 'mediorufa'}]
+ },
+ raw_history: [{revived_from_synonymy: {subspecies_of: {species_epithet: 'castanea'}}}],
+ )
+ Subspecies.find(subspecies).name.to_s.should == 'Crematogaster castanea tricolor var. mediorufa'
+ end
end
it "should import a subspecies that has a species protonym" do

0 comments on commit f40a5e3

Please sign in to comment.