Skip to content

Commit

Permalink
taxon name genter
Browse files Browse the repository at this point in the history
  • Loading branch information
proceps committed Mar 4, 2014
1 parent c78e998 commit a67b6a8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
32 changes: 17 additions & 15 deletions app/models/protonym.rb
Expand Up @@ -237,6 +237,8 @@ def sv_validate_coordinated_names
fix: :sv_fix_coordinated_names, success_message: 'Author was updated') unless self.verbatim_author == t.verbatim_author
soft_validations.add(:year_of_publication, "The year does not match with the year of the coordinated #{t.rank_class.rank_name}",
fix: :sv_fix_coordinated_names, success_message: 'Year was updated') unless self.year_of_publication == t.year_of_publication
soft_validations.add(:gender, "The gender does not match with the gender of the coordinated #{t.rank_class.rank_name}",
fix: :sv_fix_coordinated_names, success_message: 'Gender was updated') unless self.gender == t.gender
soft_validations.add(:base, "The original genus does not match with the original genus of coordinated #{t.rank_class.rank_name}",
fix: :sv_fix_coordinated_names, success_message: 'Original genus was updated') unless self.original_genus == t.original_genus
soft_validations.add(:base, "The original subgenus does not match with the original subgenus of the coordinated #{t.rank_class.rank_name}",
Expand Down Expand Up @@ -274,6 +276,10 @@ def sv_fix_coordinated_names
self.year_of_publication = t.year_of_publication
fixed = true
end
if self.gender.nil? && self.gender != t.gender
self.gender = t.gender
fixed = true
end
if self.original_genus.nil? && self.original_genus != t.original_genus
self.original_combination_genus = t.original_combination_genus
fixed = true
Expand Down Expand Up @@ -508,21 +514,17 @@ def sv_potential_homonyms
end
end

def sv_fix_add_relationship(method, object_id)
begin
Protonym.transaction do
self.save
return true
end
rescue
return false
end

false

end


# def sv_fix_add_relationship(method, object_id)
# begin
# Protonym.transaction do
# self.save
# return true
# end
# rescue
# return false
# end
# false
# end

#endregion

Expand Down
2 changes: 1 addition & 1 deletion app/models/taxon_name.rb
Expand Up @@ -316,7 +316,6 @@ def get_full_name
subgenus = ''
superspecies = ''
species = ''
gender = nil
(self.ancestors + [self]).each do |i|
if GENUS_AND_SPECIES_RANK_NAMES.include?(i.rank_class.to_s)
case i.rank_class.rank_name
Expand Down Expand Up @@ -597,6 +596,7 @@ def sv_missing_fields
soft_validations.add(:year_of_publication, 'Year is missing',
fix: :sv_fix_missing_year,
success_message: 'Year was updated') if self.year_of_publication.nil?
soft_validations.add(:gender, 'Gender is not selected') if self.rank_class.to_s =~ /Genus/ && self.gender.nil?
end

def sv_fix_missing_author
Expand Down
8 changes: 7 additions & 1 deletion spec/models/protonym_spec.rb
Expand Up @@ -276,6 +276,13 @@
expect(@kingdom.soft_validations.messages_on(:verbatim_author).empty?).to be_false
expect(@kingdom.soft_validations.messages_on(:year_of_publication).empty?).to be_false
end
specify 'missign gender' do
@genus.soft_validate(:missing_fields)
expect(@genus.soft_validations.messages_on(:gender).empty?).to be_false
@genus.gender = 'neuter'
@genus.soft_validate(:missing_fields)
expect(@genus.soft_validations.messages_on(:gender).empty?).to be_true
end
specify 'fix author and year from the source' do
#TODO citeproc gem doesn't currently support lastname without firstname
@source.update(year: 1758, author: 'Linnaeus, C.')
Expand Down Expand Up @@ -310,7 +317,6 @@

sgen.fix_soft_validations

#@genus.reload
@genus.soft_validate(:validate_coordinated_names)
sgen.soft_validate(:validate_coordinated_names)
expect(@genus.soft_validations.messages_on(:verbatim_author).empty?).to be_true
Expand Down

0 comments on commit a67b6a8

Please sign in to comment.