Skip to content

Commit

Permalink
priority update
Browse files Browse the repository at this point in the history
  • Loading branch information
proceps committed Jan 30, 2014
1 parent 295f712 commit 729635f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/models/taxon_name_relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TaxonNameRelationship < ActiveRecord::Base
scope :where_object_is_taxon_name, -> (taxon_name) {where(object_taxon_name_id: taxon_name)}
scope :with_type_string, -> (type_string) {where('type LIKE ?', "#{type_string}" ) }
scope :with_type_base, -> (base_string) {where('type LIKE ?', "#{base_string}%" ) }
scope :with_two_type_bases, -> (base_string1, base_string2) {where("type LIKE '#{base_string1}%' OR type LIKE '#{base_string2}%'" ) }
scope :with_type_array, -> (base_array) {where('type IN (?)', base_array ) }
scope :with_type_contains, -> (base_string) {where('type LIKE ?', "%#{base_string}%" ) }
scope :not_self, -> (id) {where('id <> ?', id )}
Expand Down Expand Up @@ -444,7 +445,9 @@ def sv_validate_priority
elsif !!date1 and !!date2
case self.type_class.nomenclatural_priority
when :direct
soft_validations.add(:type, "#{self.type_class.subject_relationship_name.capitalize} should not be older than related taxon")
if self.type_class.to_s =~ /Iczn::Invalidating::Homonym/ || TaxonNameRelationship.where_subject_is_taxon_name(self.subject_taxon_name).with_two_type_bases('TaxonNameRelationship::Iczn::Invalidating::Homonym', 'TaxonNameRelationship::Iczn::Validating').not_self(self).empty?
soft_validations.add(:type, "#{self.type_class.subject_relationship_name.capitalize} should not be older than related taxon")
end
when :reverse
if self.type_name =~ /TaxonNameRelationship::(Typification|Combination|OriginalCombination)/
soft_validations.add(:subject_taxon_name_id, "#{self.type_class.object_relationship_name.capitalize} should not be younger than the taxon")
Expand Down
16 changes: 14 additions & 2 deletions spec/models/taxon_name_relationship_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
expect(r1.soft_validations.messages_on(:type).count).to eq(1)
end
specify 'direct priority' do
r1 = FactoryGirl.build_stubbed(:taxon_name_relationship, subject_taxon_name: @s2, object_taxon_name: @s1, type: 'TaxonNameRelationship::Iczn::Invalidating::Synonym::Objective')
r1 = FactoryGirl.build_stubbed(:taxon_name_relationship, subject_taxon_name: @s1, object_taxon_name: @s2, type: 'TaxonNameRelationship::Iczn::Invalidating::Synonym::Objective')
r1.soft_validate(:validate_priority)
expect(r1.soft_validations.messages_on(:type).count).to eq(1)
end
Expand All @@ -470,7 +470,19 @@
specify 'reverse priority original genus' do
r1 = FactoryGirl.build_stubbed(:taxon_name_relationship, subject_taxon_name: @g1, object_taxon_name: @s2, type: 'TaxonNameRelationship::OriginalCombination::OriginalGenus')
r1.soft_validate(:validate_priority)
expect(r1.soft_validations.messages_on(:subject_taxon_name_id).count).to eq(1)
expect(r1.soft_validations.messages_on(:subject_taxon_name_id).count).to eq(1)
end
specify 'synonym and homonym' do
r1 = FactoryGirl.create(:taxon_name_relationship, subject_taxon_name: @s1, object_taxon_name: @s2, type: 'TaxonNameRelationship::Iczn::Invalidating::Synonym::Subjective')
r1.soft_validate(:validate_priority)
expect(r1.soft_validations.messages_on(:type).count).to eq(1)
r2 = FactoryGirl.create(:taxon_name_relationship, subject_taxon_name: @s1, object_taxon_name: @species, type: 'TaxonNameRelationship::Iczn::Invalidating::Homonym::Secondary')
r1.soft_validate(:validate_priority)
expect(r1.soft_validations.messages_on(:type).empty?).to be_true
r2.type = 'TaxonNameRelationship::Iczn::Validating::ConservedName'
expect(r2.save).to be_true
r1.soft_validate(:validate_priority)
expect(r1.soft_validations.messages_on(:type).empty?).to be_true
end
end

Expand Down

0 comments on commit 729635f

Please sign in to comment.