Skip to content

Commit

Permalink
Merge pull request #792 from datacite/doi-estimate
Browse files Browse the repository at this point in the history
Doi estimate
  • Loading branch information
svogt0511 authored Mar 14, 2022
2 parents 4c2dfd3 + 7a07b1e commit bfda30b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
30 changes: 2 additions & 28 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ class Provider < ApplicationRecord
# validates :voting_contact, contact: true
# validates :billing_information, billing_information: true

# validates :doi_estimate, numericality: { only_integer: true, greater_than_or_equal_to: 0 } if :member_type === "consortium_organization"
validate :doi_estimate_field
validates :doi_estimate, numericality: { only_integer: true, greater_than_or_equal_to: 0 }

strip_attributes

Expand Down Expand Up @@ -839,27 +838,6 @@ def activity_id_not_changed
end
end

def doi_estimate_field
if member_type == "consortium_organization"
begin
num = Integer(doi_estimate)
if num < 0
errors.add(
:doi_estimate,
:doi_estimate_invalid,
value: "The doi_estimate must be a nonnegative integer.",
)
end
rescue
errors.add(
:doi_estimate,
:doi_estimate_invalid,
value: "The doi_estimate must be a nonnegative integer.",
)
end
end
end

# attributes to be sent to elasticsearch index
def to_jsonapi
attributes = {
Expand Down Expand Up @@ -947,11 +925,7 @@ def set_defaults
self.billing_information = {} if billing_information.blank?
self.consortium_id = nil unless member_type == "consortium_organization"
self.non_profit_status = "non-profit" if non_profit_status.blank?
if member_type == "consortium_organization"
self.doi_estimate = doi_estimate.to_i
else
self.doi_estimate = 0
end
self.doi_estimate = doi_estimate.to_i

# custom filename for attachment as data URLs don't support filenames
if logo_content_type.present?
Expand Down
2 changes: 1 addition & 1 deletion spec/models/provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
subject.doi_estimate = value
expect(subject.save).to be false
expect(subject.errors.details).to eq(
doi_estimate: [{ error: :doi_estimate_invalid, value: "The doi_estimate must be a nonnegative integer." }]
doi_estimate: [{ count: 0, error: :greater_than_or_equal_to, value: value.to_i }]
)
end
end
Expand Down

0 comments on commit bfda30b

Please sign in to comment.