Skip to content

Commit

Permalink
Questions about FG intentions, updating set_cached_higher_classificat…
Browse files Browse the repository at this point in the history
…ion to use native method.
  • Loading branch information
mjy committed Oct 21, 2013
1 parent dce8fc6 commit 15cf266
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/taxon_name.rb
Expand Up @@ -73,6 +73,7 @@ def set_type_if_empty
end

def set_cached_name
# TODO: Dmitry- Move this to a Constant
genus_species_ranks = NomenclaturalRank::Iczn::GenusGroup.descendants + NomenclaturalRank::Iczn::SpeciesGroup.descendants + NomenclaturalRank::Icn::GenusGroup.descendants + [NomenclaturalRank::Icn::Species] + NomenclaturalRank::Icn::InfraspecificGroup.descendants
if !genus_species_ranks.include?(self.rank_class)
cached_name = nil
Expand Down Expand Up @@ -131,7 +132,7 @@ def set_cached_author_year

def set_cached_higher_classification
# see config/initializers/ranks for FAMILY_AND_ABOVE_RANKS
hc = (self.ancestors + [self]).select{|i| FAMILY_AND_ABOVE_RANKS.include?(i.rank_class)}.collect{|i| i.name}.join(':')
hc = self.self_and_ancestors.select{|i| FAMILY_AND_ABOVE_RANKS.include?(i.rank_class)}.collect{|i| i.name}.join(':')
self.cached_higher_classification = hc
end

Expand Down
5 changes: 4 additions & 1 deletion spec/models/taxon_name_spec.rb
Expand Up @@ -118,9 +118,12 @@
end

specify 'cached_names are be set with ancestors' do
expect(subspecies.cached_higher_classification).to eq('aaa') # it is 'aaa' in FactoryGirl
# Dmitry: We don't want to test that it starts with 'aaa' unless we *intend* for the record to be invalid by default,
# do we intend this?
# expect(subspecies.cached_higher_classification).to eq('aaa') # it is 'aaa' in FactoryGirl
subspecies.valid?
expect(subspecies.cached_higher_classification).to eq('Animalia:Arthropoda:Insecta:Hemiptera:Cicadellidae:Typhlocybinae:Erythroneurini')

expect(subspecies.cached_author_year).to eq('McAtee, 1900')
expect(subspecies.cached_name).to eq('Erythroneura (Erythroneura) vitis ssp')
variety.valid?
Expand Down

0 comments on commit 15cf266

Please sign in to comment.