Permalink
Browse files

Insert species name correctly when creating subspecies name (GREEN)

  • Loading branch information...
1 parent 65232e2 commit 98206266e13513f81635e56cfdcb507a4ea2600b @mwilden mwilden committed Aug 15, 2012
Showing with 25 additions and 1 deletion.
  1. +9 −0 app/models/subspecies.rb
  2. +16 −1 spec/models/subspecies_spec.rb
View
@@ -9,9 +9,18 @@ def self.import_name data
name_data = data[:protonym]
name_data[:genus] = data[:genus]
name_data[:subspecies_epithet] = data[:species_group_epithet] || data[:species_epithet]
+ adjust_species_when_differs_from_protonym name_data, data[:raw_history]
Name.import name_data
end
+ def self.adjust_species_when_differs_from_protonym name_data, history
+ currently_subspecies_of = get_currently_subspecies_of_from_history history
+ return unless currently_subspecies_of
+ name_data[:subspecies] ||= []
+ name_data[:subspecies].unshift subspecies_epithet: name_data[:species_epithet]
+ name_data[:species_epithet] = currently_subspecies_of
+ end
+
def self.after_creating taxon, data
super
taxon.create_forward_ref_to_parent_species data
@@ -62,13 +62,28 @@
raw_history: [{currently_subspecies_of: {species: {species_epithet: 'hova'}}}]
)
subspecies = Subspecies.find subspecies
- subspecies.name.to_s.should == 'Camponotus maculatus r. radamae'
+ 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'
end
+ it "should import a subspecies that has a species protonym" do
+ genus = create_genus 'Acromyrmex'
+ subspecies = Species.import(
+ genus: genus,
+ species_group_epithet: 'boliviensis',
+ protonym: {
+ genus_name: 'Acromyrmex',
+ species_epithet: 'boliviensis',
+ },
+ raw_history: [{currently_subspecies_of: {species: {species_epithet: 'lundii'}}}]
+ )
+ subspecies = Subspecies.find subspecies
+ subspecies.name.to_s.should == 'Acromyrmex lundii boliviensis'
+ end
+
it "should use the right epithet when the protonym differs" do
subspecies = Species.import(
species_group_epithet: 'brunneus',

0 comments on commit 9820626

Please sign in to comment.