Skip to content

Commit

Permalink
type update
Browse files Browse the repository at this point in the history
  • Loading branch information
proceps committed Jan 30, 2014
1 parent b03b6df commit 295f712
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/models/taxon_name_relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,18 @@ def sv_not_specific_relationship
end

def sv_fix_specify_synonymy_type
#TODO update to cover type specimens synonym is objective if type the same or subjective if type is different
subject_type = self.subject_taxon_name.type_taxon_name
object_type = self.object_taxon_name.type_taxon_name
s = self.subject_taxon_name
o = self.object_taxon_name
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?
if (subject_type == object_type && !subject_type.nil? ) || (!s.get_primary_type.empty? && s.matching_primary_types(s, 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?
elsif (subject_type != object_type && !subject_type.nil? ) || (!s.get_primary_type.empty? && !o.get_primary_type.empty? && !s.matching_primary_types(s, o))
if new_relationship_name == 'TaxonNameRelationship::Iczn::Invalidating::Synonym'
new_relationship_name = 'TaxonNameRelationship::Iczn::Invalidating::Synonym::Subjective'
else
Expand Down
27 changes: 27 additions & 0 deletions spec/models/taxon_name_relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,35 @@
expect(r1.soft_validations.messages_on(:type).count).to eq(1)
r1.fix_soft_validations
r1.soft_validate(:not_specific_relationship)
expect(r1.type_name).to eq('TaxonNameRelationship::Iczn::Invalidating::Synonym::Objective')
expect(r1.soft_validations.messages_on(:type).empty?).to be_true
end
specify 'same type specimen fix to objective synonym' do
s1 = FactoryGirl.create(:relationship_species, parent: @genus)
s2 = FactoryGirl.create(:relationship_species, parent: @genus)
type_material1 = FactoryGirl.create(:valid_type_material, protonym: s1)
type_material2 = FactoryGirl.create(:valid_type_material, biological_object_id: type_material1.biological_object_id, protonym: s2)
r = FactoryGirl.build_stubbed(:taxon_name_relationship, subject_taxon_name: s1, object_taxon_name: s2, type: 'TaxonNameRelationship::Iczn::Invalidating::Synonym')
r.soft_validate(:not_specific_relationship)
expect(r.soft_validations.messages_on(:type).count).to eq(1)
r.fix_soft_validations
r.soft_validate(:not_specific_relationship)
expect(r.type_name).to eq('TaxonNameRelationship::Iczn::Invalidating::Synonym::Objective')
expect(r.soft_validations.messages_on(:type).empty?).to be_true
end
specify 'subjective synonyms should have different type specimen' do
s1 = FactoryGirl.create(:relationship_species, parent: @genus)
s2 = FactoryGirl.create(:relationship_species, parent: @genus)
type_material1 = FactoryGirl.create(:valid_type_material, protonym: s1)
type_material2 = FactoryGirl.create(:valid_type_material, protonym: s2)
r = FactoryGirl.build_stubbed(:taxon_name_relationship, subject_taxon_name: s1, object_taxon_name: s2, type: 'TaxonNameRelationship::Iczn::Invalidating::Synonym')
r.soft_validate(:not_specific_relationship)
expect(r.soft_validations.messages_on(:type).count).to eq(1)
r.fix_soft_validations
r.soft_validate(:not_specific_relationship)
expect(r.type_name).to eq('TaxonNameRelationship::Iczn::Invalidating::Synonym::Subjective')
expect(r.soft_validations.messages_on(:type).empty?).to be_true
end
specify 'fix not specific relationships from homonym to primary homonym' do
s1 = FactoryGirl.create(:relationship_species, parent: @genus)
s2 = FactoryGirl.create(:relationship_species, parent: @genus)
Expand Down

0 comments on commit 295f712

Please sign in to comment.