From 7df417e63a275dfa711ebe5a52c2083698fccc20 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Sun, 13 Mar 2022 22:55:03 -0400 Subject: [PATCH 1/3] Salesforce - doi_estimate_year_one field. (Allow doi_estimate to be set for any org type.) --- app/models/provider.rb | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/app/models/provider.rb b/app/models/provider.rb index f742696a4..898d9feb3 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -840,24 +840,20 @@ def activity_id_not_changed 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 + 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 # attributes to be sent to elasticsearch index @@ -947,11 +943,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? From d8f4e378323e8c86579d5466b5a236a589df4ba9 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Mon, 14 Mar 2022 00:24:07 -0400 Subject: [PATCH 2/3] Salesforce - doi_estimate_year_one field. (Allow doi_estimate to be set for any org type.) --- app/models/provider.rb | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/app/models/provider.rb b/app/models/provider.rb index 898d9feb3..54f850b19 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -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 @@ -839,23 +838,6 @@ def activity_id_not_changed end end - def doi_estimate_field - 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 - # attributes to be sent to elasticsearch index def to_jsonapi attributes = { From 7a07b1e46bcbce6c35b883e0a5b2772346b06b35 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Mon, 14 Mar 2022 00:55:53 -0400 Subject: [PATCH 3/3] fix test --- spec/models/provider_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index dc220a3de..f0a0891b2 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -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