Skip to content

Commit

Permalink
protonym_spec all methods should be covered by specs
Browse files Browse the repository at this point in the history
  • Loading branch information
proceps committed Feb 13, 2015
1 parent 20a27ae commit e745517
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
8 changes: 4 additions & 4 deletions app/models/taxon_name_relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def sv_specific_relationship
o = self.object_taxon_name
case self.type_name
when 'TaxonNameRelationship::Iczn::Invalidating::Synonym::Subjective' || 'TaxonNameRelationship::Icn::Unaccepting::Synonym::Heterotypic'
if (s.type_taxon_name == o.type_taxon_name && !s.type_taxon_name.nil? ) || (!s.get_primary_type.empty? && s.matching_primary_types(s, o) )
if (s.type_taxon_name == o.type_taxon_name && !s.type_taxon_name.nil? ) || (!s.get_primary_type.empty? && s.has_same_primary_type(o) )
soft_validations.add(:type, 'Subjective synonyms should not have the same type')
end
when 'TaxonNameRelationship::Iczn::Invalidating::Homonym'
Expand Down Expand Up @@ -331,7 +331,7 @@ def sv_objective_synonym_relationship
if self.type_name =~ /TaxonNameRelationship::(Iczn::Invalidating::Synonym::Objective|Icn::Unaccepting::Synonym::Homotypic)/
s = self.subject_taxon_name
o = self.object_taxon_name
if (s.type_taxon_name != o.type_taxon_name ) || !s.matching_primary_types(s, o)
if (s.type_taxon_name != o.type_taxon_name ) || !s.has_same_primary_type(o)
soft_validations.add(:type, 'Objective synonyms should have the same type')
end
end
Expand Down Expand Up @@ -388,13 +388,13 @@ def sv_fix_specify_synonymy_type
subject_type = s.type_taxon_name
object_type = o.type_taxon_name
new_relationship_name = self.type_name
if (subject_type == object_type && !subject_type.nil? ) || (!s.get_primary_type.empty? && s.matching_primary_types(s, o) )
if (subject_type == object_type && !subject_type.nil? ) || (!s.get_primary_type.empty? && s.has_same_primary_type(o) )
if new_relationship_name == 'TaxonNameRelationship::Iczn::Invalidating::Synonym'
new_relationship_name = 'TaxonNameRelationship::Iczn::Invalidating::Synonym::Objective'
else
new_relationship_name = 'TaxonNameRelationship::Icn::Unaccepting::Synonym::Homotypic'
end
elsif (subject_type != object_type && !subject_type.nil? ) || (!s.get_primary_type.empty? && !o.get_primary_type.empty? && !s.matching_primary_types(s, o))
elsif (subject_type != object_type && !subject_type.nil? ) || (!s.get_primary_type.empty? && !o.get_primary_type.empty? && !s.has_same_primary_type(o))
if new_relationship_name == 'TaxonNameRelationship::Iczn::Invalidating::Synonym'
new_relationship_name = 'TaxonNameRelationship::Iczn::Invalidating::Synonym::Subjective'
else
Expand Down
39 changes: 18 additions & 21 deletions spec/models/protonym_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
require 'rails_helper'

# TO resolve with Proceps
# - we need to write tests for all instance methods, including:
# all_generic_placements
# list_of_coordinated_names
# lowest_rank_coordinated_taxon
# ancestors_and_descendants
# get_primary_type
# matching_primary_types
# incorrect_originall_spelling
# incertae_sedis
# original_combination_class_relationships
# original_combination_relationships_and_stubs
#
#
# and class methods
# family_group_base ( should move to FamilyGroup rank spec likely)
#

describe Protonym, :type => :model do
let(:protonym) { Protonym.new }

Expand Down Expand Up @@ -161,9 +143,24 @@
expect(species.iczn_uncertain_placement_relationship).to eq(relationship)
end

# original_combination_class_relationships
# original_combination_relationships_and_stubs

specify 'original_combination_class_relationships' do
genus = FactoryGirl.create(:relationship_genus)
subgenus = FactoryGirl.create(:iczn_subgenus, parent: genus)
species = FactoryGirl.create(:relationship_species, parent: subgenus)
subspecies = FactoryGirl.create(:iczn_subspecies, parent: species)

expect(subspecies.original_combination_class_relationships.collect{|i| i.to_s}.sort).to eq(['TaxonNameRelationship::OriginalCombination::OriginalGenus', 'TaxonNameRelationship::OriginalCombination::OriginalSpecies', 'TaxonNameRelationship::OriginalCombination::OriginalSubgenus'])

r1 = TaxonNameRelationship.create(subject_taxon_name: genus, object_taxon_name: subspecies, type: 'TaxonNameRelationship::OriginalCombination::OriginalGenus')
r2 = TaxonNameRelationship.create(subject_taxon_name: subgenus, object_taxon_name: subspecies, type: 'TaxonNameRelationship::OriginalCombination::OriginalSubgenus')
subspecies.reload
expect(subspecies.original_combination_relationships_and_stubs.count).to eq(3)
expect(subspecies.original_combination_relationships_and_stubs[0]).to eq(r1)
expect(subspecies.original_combination_relationships_and_stubs[1]).to eq(r2)
expect(subspecies.original_combination_relationships_and_stubs[2].subject_taxon_name_id).to be_falsey
expect(subspecies.original_combination_relationships_and_stubs[2].object_taxon_name_id).to eq(subspecies.id)
expect(subspecies.original_combination_relationships_and_stubs[2].type).to eq('TaxonNameRelationship::OriginalCombination::OriginalSpecies')
end
end

context 'validation' do
Expand Down

0 comments on commit e745517

Please sign in to comment.