Skip to content

Commit

Permalink
Fix Local::FieldNumber expectation.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Sep 26, 2024
1 parent 5e93fce commit f1f2714
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
9 changes: 0 additions & 9 deletions app/models/identifier/local/field_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class Identifier::Local::FieldNumber < Identifier::Local
include Shared::DwcOccurrenceHooks

validate :assigned_to_collecting_event
validate :same_as_verbatim

def dwc_occurrences
DwcOccurrence
Expand All @@ -19,14 +18,6 @@ def dwc_occurrences

private

def same_as_verbatim
unless errors.any? || !identifier_object.present?
if identifier_object.verbatim_field_number.present? && build_cached != identifier_object.verbatim_field_number
errors.add(:identifier, 'not identical to CollectingEvent verbatim_field_number')
end
end
end

def assigned_to_collecting_event
errors.add(:identifier_object_type, 'only assignable to CollectingEvents') if (identifier_object_type && identifier_object_type != 'CollectingEvent') || (identifier_object && !identifier_object.kind_of?(CollectingEvent))
end
Expand Down
5 changes: 2 additions & 3 deletions spec/models/identifier/local/field_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
expect(i.errors.key?(:identifier_object_type)).to be_falsey
end

specify 'must be same as verbatim_field_number if provided' do
specify 'may be different than verbatim_field_number if provided' do
c = FactoryBot.create(:valid_collecting_event, verbatim_field_number: 'NS345')

i = Identifier::Local::FieldNumber.new(identifier: '345', namespace: n, identifier_object: c)
expect(i.valid?).to be_falsey
expect(i.errors.key?(:identifier)).to be_truthy
expect(i.valid?).to be_truthy
end

end

0 comments on commit f1f2714

Please sign in to comment.