From 350c9c7e559f7885900e53bc0f94e2a875d3e5b9 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Fri, 18 Feb 2022 00:11:17 -0500 Subject: [PATCH 1/9] Salesforce - doi_estimate_year_one field. --- app/controllers/providers_controller.rb | 2 + app/models/provider.rb | 41 ++++++++++++++++++- app/serializers/provider_serializer.rb | 3 +- ...217020855_add_doi_estimate_to_allocator.rb | 10 +++++ db/schema.rb | 7 ++-- 5 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20220217020855_add_doi_estimate_to_allocator.rb diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 059467a2e..6f53f19e9 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -460,6 +460,7 @@ def safe_params { "secondaryServiceContact": [:uid, :email, "givenName", "familyName", :name] }, "votingContact", { "votingContact": [:uid, :email, "givenName", "familyName", :name] }, + "doiEstimateYearOne", ], keys: { "displayName" => :display_name, @@ -486,6 +487,7 @@ def safe_params "salesforceId" => :salesforce_id, "fromSalesforce" => :from_salesforce, "globusUuid" => :globus_uuid, + "doiEstimateYearOne" => :doi_estimate_year_one, }, ) end diff --git a/app/models/provider.rb b/app/models/provider.rb index 028dd1194..9a9c44f59 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -24,6 +24,7 @@ class Provider < ApplicationRecord version doi_quota_allowed doi_quota_used + doi_estimate_year_one ] # include helper module for caching infrequently changing resources @@ -63,6 +64,7 @@ class Provider < ApplicationRecord alias_attribute :created_at, :created alias_attribute :updated_at, :updated attr_readonly :symbol + attr_readonly :doi_estimate_year_one attr_reader :from_salesforce delegate :salesforce_id, to: :consortium, prefix: true, allow_nil: true @@ -149,6 +151,10 @@ class Provider < ApplicationRecord # validates :voting_contact, contact: true # validates :billing_information, billing_information: true + validates :doi_estimate_year_one, numericality: { only_integer: true }, on: :create + validate :validate_doi_estimate, on: :create + validate :freeze_doi_estimate, on: :update + strip_attributes has_many :clients, foreign_key: :allocator @@ -363,6 +369,7 @@ class Provider < ApplicationRecord updated_at: { type: :date }, deleted_at: { type: :date } } + indexes :doi_estimate_year_one, type: :integer end end @@ -428,7 +435,8 @@ def as_indexed_json(options = {}) nil else contacts.map { |m| m.try(:as_indexed_json, exclude_associations: true) } - end + end, + "doi_estimate_year_one" => doi_estimate_year_one } end @@ -537,6 +545,7 @@ def csv created: created, updated: updated, deleted_at: deleted_at, + doi_estimate_year_one: doi_estimate_year_one, }.values CSV.generate { |csv| csv << provider } @@ -826,6 +835,34 @@ def user_url ENV["VOLPINO_URL"] + "/users?provider-id=" + symbol.downcase end + def activity_id_not_changed + if activity_id_changed? && self.persisted? + errors.add(:activity_id, "Change of activity_id not allowed!") + end + end + + def validate_doi_estimate + if consortium_id && (member_type == "consortium_organization") + if !(doi_estimate_year_one > 0) + errors.add( + :doi_estimate_year_one, + "A nonzero doi estimate must be specified for consortium organizations.", + ) + end + else + if (doi_estimate_year_one > 0) + errors.add( + :doi_estimate_year_one, + "A nonzero doi estimate can only be specified for consortium organizations.", + ) + end + end + end + + def freeze_doi_estimate + errors.add(:doi_estimate_year_one, "cannot be changed") if doi_estimate_year_one_changed? + end + # attributes to be sent to elasticsearch index def to_jsonapi attributes = { @@ -859,6 +896,7 @@ def to_jsonapi "created" => created.iso8601, "updated" => updated.iso8601, "deleted_at" => deleted_at ? deleted_at.iso8601 : nil, + "doi_estimate_year_one" => doi_estimate_year_one, } { @@ -912,6 +950,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? + self.doi_estimate_year_one = 0 unless doi_estimate_year_one.present? # custom filename for attachment as data URLs don't support filenames if logo_content_type.present? diff --git a/app/serializers/provider_serializer.rb b/app/serializers/provider_serializer.rb index 4c7391c64..40149b7fe 100644 --- a/app/serializers/provider_serializer.rb +++ b/app/serializers/provider_serializer.rb @@ -39,7 +39,8 @@ class ProviderSerializer :voting_contact, :has_required_contacts, :created, - :updated + :updated, + :doi_estimate_year_one has_many :clients, record_type: :clients has_many :prefixes, record_type: :prefixes diff --git a/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb b/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb new file mode 100644 index 000000000..7e5a0d5e1 --- /dev/null +++ b/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb @@ -0,0 +1,10 @@ +class AddDoiEstimateToAllocator < ActiveRecord::Migration[5.2] + def change + add_column :allocator, :doi_estimate_year_one, :integer, default: 0, null: false + end + + + def self.down + remove_column :doi_estimate_year_one + end +end diff --git a/db/schema.rb b/db/schema.rb index 4264e1674..590bc2f54 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -12,7 +10,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_11_12_201512) do +ActiveRecord::Schema.define(version: 2022_02_17_020855) do + create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| t.string "name", limit: 191, null: false t.string "record_type", null: false @@ -77,6 +76,7 @@ t.string "logo_content_type" t.bigint "logo_file_size" t.datetime "logo_updated_at" + t.integer "doi_estimate_year_one", default: 0, null: false t.index ["globus_uuid"], name: "index_allocator_on_globus_uuid" t.index ["organization_type"], name: "index_allocator_organization_type" t.index ["symbol"], name: "symbol", unique: true @@ -299,4 +299,5 @@ t.index ["provider_id"], name: "FKE7FBD67446EBD781" t.index ["uid"], name: "index_provider_prefixes_on_uid", length: 128 end + end From a0024a0dff31a276a7fd8b2fb5ae6144f5a438d8 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Tue, 22 Feb 2022 00:21:17 -0500 Subject: [PATCH 2/9] Salesforce - doi_estimate_year_one field. --- app/models/provider.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/provider.rb b/app/models/provider.rb index 9a9c44f59..ff84f2b29 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -64,7 +64,7 @@ class Provider < ApplicationRecord alias_attribute :created_at, :created alias_attribute :updated_at, :updated attr_readonly :symbol - attr_readonly :doi_estimate_year_one + # attr_readonly :doi_estimate_year_one attr_reader :from_salesforce delegate :salesforce_id, to: :consortium, prefix: true, allow_nil: true @@ -151,9 +151,11 @@ class Provider < ApplicationRecord # validates :voting_contact, contact: true # validates :billing_information, billing_information: true - validates :doi_estimate_year_one, numericality: { only_integer: true }, on: :create - validate :validate_doi_estimate, on: :create - validate :freeze_doi_estimate, on: :update + # validates :doi_estimate_year_one, numericality: { only_integer: true }, on: :create + # validate :validate_doi_estimate, on: :create + # validate :freeze_doi_estimate, on: :update + validates :doi_estimate_year_one, numericality: { only_integer: true, greater_than_or_equal_to: 0 } + strip_attributes From f6bab3a44346e30849ac41bd996bdc8ffef45b54 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Fri, 4 Mar 2022 10:15:24 -0500 Subject: [PATCH 3/9] Salesforce - doi_estimate_year_one field. (Reset to 0 on memberType change.) --- app/models/provider.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/provider.rb b/app/models/provider.rb index ff84f2b29..44dc604c3 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -952,7 +952,11 @@ 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? - self.doi_estimate_year_one = 0 unless doi_estimate_year_one.present? + # self.doi_estimate_year_one = 0 unless doi_estimate_year_one.present? + self.doi_estimate_year_one = 0 unless ( + member_type == "consortium_organization" || + self.doi_estimate_year_one = nil + ) # custom filename for attachment as data URLs don't support filenames if logo_content_type.present? From 6f8fc3033673df3d336bdce6fe47300fc8d11af3 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Fri, 4 Mar 2022 14:17:08 -0500 Subject: [PATCH 4/9] Salesforce - doi_estimate_year_one field. (Testing) --- app/models/provider.rb | 33 +------------------------- spec/models/provider_spec.rb | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/app/models/provider.rb b/app/models/provider.rb index 44dc604c3..78e1c3ed5 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -64,7 +64,6 @@ class Provider < ApplicationRecord alias_attribute :created_at, :created alias_attribute :updated_at, :updated attr_readonly :symbol - # attr_readonly :doi_estimate_year_one attr_reader :from_salesforce delegate :salesforce_id, to: :consortium, prefix: true, allow_nil: true @@ -151,12 +150,8 @@ class Provider < ApplicationRecord # validates :voting_contact, contact: true # validates :billing_information, billing_information: true - # validates :doi_estimate_year_one, numericality: { only_integer: true }, on: :create - # validate :validate_doi_estimate, on: :create - # validate :freeze_doi_estimate, on: :update validates :doi_estimate_year_one, numericality: { only_integer: true, greater_than_or_equal_to: 0 } - strip_attributes has_many :clients, foreign_key: :allocator @@ -843,28 +838,6 @@ def activity_id_not_changed end end - def validate_doi_estimate - if consortium_id && (member_type == "consortium_organization") - if !(doi_estimate_year_one > 0) - errors.add( - :doi_estimate_year_one, - "A nonzero doi estimate must be specified for consortium organizations.", - ) - end - else - if (doi_estimate_year_one > 0) - errors.add( - :doi_estimate_year_one, - "A nonzero doi estimate can only be specified for consortium organizations.", - ) - end - end - end - - def freeze_doi_estimate - errors.add(:doi_estimate_year_one, "cannot be changed") if doi_estimate_year_one_changed? - end - # attributes to be sent to elasticsearch index def to_jsonapi attributes = { @@ -952,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? - # self.doi_estimate_year_one = 0 unless doi_estimate_year_one.present? - self.doi_estimate_year_one = 0 unless ( - member_type == "consortium_organization" || - self.doi_estimate_year_one = nil - ) + self.doi_estimate_year_one = nil unless member_type == "consortium_organization" # custom filename for attachment as data URLs don't support filenames if logo_content_type.present? diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index ab981953f..4e0109100 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -149,6 +149,51 @@ end end + describe "doi estimate" do + subject { build(:provider) } + + it "valid" do + subject.member_type = "consortium_organization" + subject.doi_estimate_year_one = "0" + expect(subject.save).to be true + expect(subject.errors.details).to be_empty + end + + it "valid" do + subject.member_type = "consortium_organization" + subject.doi_estimate_year_one = "9999" + expect(subject.save).to be true + expect(subject.errors.details).to be_empty + end + + it "invalid" do + subject.member_type = "consortium_organization" + subject.doi_estimate_year_one = "" + expect(subject.save).to be false + expect(subject.errors.details).to eq( + doi_estimate_year_one: [{ error: :not_a_number, value: "" }], + ) + end + + it "invalid" do + subject.member_type = "consortium_organization" + subject.doi_estimate_year_one = "abc" + expect(subject.save).to be false + expect(subject.errors.details).to eq( + doi_estimate_year_one: [{ error: :not_a_number, value: "abc" }], + ) + end + + it "invalid" do + subject.member_type = "consortium_organization" + subject.doi_estimate_year_one = "-1" + expect(subject.save).to be false + expect(subject.errors.details).to eq( + doi_estimate_year_one: [{ count: 0, error: :greater_than_or_equal_to, value: -1 }], + ) + end + end + describe "from_salesforce" do subject { build(:provider) } From 29ec9d9c034c7836a8860e113b1d2c9a3be9506d Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Fri, 4 Mar 2022 14:24:52 -0500 Subject: [PATCH 5/9] Salesforce - doi_estimate_year_one field. (Testing) --- app/models/provider.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/provider.rb b/app/models/provider.rb index 78e1c3ed5..ab9437a78 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -150,7 +150,7 @@ class Provider < ApplicationRecord # validates :voting_contact, contact: true # validates :billing_information, billing_information: true - validates :doi_estimate_year_one, numericality: { only_integer: true, greater_than_or_equal_to: 0 } + validates :doi_estimate_year_one, numericality: { only_integer: true, greater_than_or_equal_to: 0 } if :member_type === "consortium_organization" strip_attributes From c56cd36ef807057ef495bd2bd959122d459d411c Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Sat, 5 Mar 2022 02:49:00 -0500 Subject: [PATCH 6/9] Salesforce - doi_estimate_year_one field. (Testing) --- app/models/client.rb | 15 ----------- app/models/provider.rb | 30 +++++++++++++++++++-- spec/models/provider_spec.rb | 51 +++++++++++------------------------- 3 files changed, 44 insertions(+), 52 deletions(-) diff --git a/app/models/client.rb b/app/models/client.rb index fa938b781..05536303f 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -648,22 +648,10 @@ def to_jsonapi "deleted_at" => deleted_at ? deleted_at.iso8601 : nil, } - Rails.logger.info "SKV - TO_JSONAPI BEGIN: uid, doi_counts, dois_total, dois_current_year, dois_last_year" - Rails.logger.info uid - Rails.logger.info doi_counts - Rails.logger.info dois_total - Rails.logger.info dois_current_year - Rails.logger.info dois_last_year - Rails.logger.info "SKV - TO_JSONAPI MIDDLE: attributes" - Rails.logger.info attributes - Rails.logger.info "SKV - TO_JSONAPI END" - { "id" => symbol.downcase, "type" => "clients", "attributes" => attributes } end def self.export(query: nil) - Rails.logger.info "SKV - EXPORTING CLIENTS - BEGIN" - # Loop through all clients i = 0 page = { size: 1_000, number: 1 } @@ -688,9 +676,6 @@ def self.export(query: nil) page_num += 1 end - Rails.logger.info query - Rails.logger.info "SKV - EXPORTING CLIENTS - END" - "#{i} clients exported." end diff --git a/app/models/provider.rb b/app/models/provider.rb index ab9437a78..e7023a713 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -150,7 +150,8 @@ class Provider < ApplicationRecord # validates :voting_contact, contact: true # validates :billing_information, billing_information: true - validates :doi_estimate_year_one, numericality: { only_integer: true, greater_than_or_equal_to: 0 } if :member_type === "consortium_organization" + # validates :doi_estimate_year_one, numericality: { only_integer: true, greater_than_or_equal_to: 0 } if :member_type === "consortium_organization" + validate :doi_estimate strip_attributes @@ -838,6 +839,27 @@ def activity_id_not_changed end end + def doi_estimate + if member_type === "consortium_organization" + begin + num = Integer(doi_estimate_year_one) + if num < 0 + errors.add( + :doi_estimate_year_one, + :doi_estimate_invalid, + value: "The doi_estimate must be a nonnegative integer.", + ) + end + rescue + errors.add( + :doi_estimate_invalid, + :doi_estimate_year_one, + value: "The doi_estimate must be a nonnegative integer.", + ) + end + end + end + # attributes to be sent to elasticsearch index def to_jsonapi attributes = { @@ -925,7 +947,11 @@ 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? - self.doi_estimate_year_one = nil unless member_type == "consortium_organization" + if member_type === "consortium_organization" + self.doi_estimate_year_one = doi_estimate_year_one.to_i + else + self.doi_estimate_year_one = 0 + end # custom filename for attachment as data URLs don't support filenames if logo_content_type.present? diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index 4e0109100..7e8c61f69 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "rails_helper" +require "pp" describe Provider, type: :model do let(:provider) { create(:provider) } @@ -153,44 +154,24 @@ subject { build(:provider) } it "valid" do - subject.member_type = "consortium_organization" - subject.doi_estimate_year_one = "0" - expect(subject.save).to be true - expect(subject.errors.details).to be_empty - end - - it "valid" do - subject.member_type = "consortium_organization" - subject.doi_estimate_year_one = "9999" - expect(subject.save).to be true - expect(subject.errors.details).to be_empty - end - - it "invalid" do - subject.member_type = "consortium_organization" - subject.doi_estimate_year_one = "" - expect(subject.save).to be false - expect(subject.errors.details).to eq( - doi_estimate_year_one: [{ error: :not_a_number, value: "" }], - ) + [0, 98765, "0", "98765"].each do |value| + subject.member_type = "consortium_organization" + subject.doi_estimate_year_one = value + expect(subject.save).to be true + expect(subject.doi_estimate_year_one).to be_a_kind_of(Integer) + expect(subject.doi_estimate_year_one).to eq(value.to_i) + end end it "invalid" do - subject.member_type = "consortium_organization" - subject.doi_estimate_year_one = "abc" - expect(subject.save).to be false - expect(subject.errors.details).to eq( - doi_estimate_year_one: [{ error: :not_a_number, value: "abc" }], - ) - end - - it "invalid" do - subject.member_type = "consortium_organization" - subject.doi_estimate_year_one = "-1" - expect(subject.save).to be false - expect(subject.errors.details).to eq( - doi_estimate_year_one: [{ count: 0, error: :greater_than_or_equal_to, value: -1 }], - ) + ["-123", -123].each do |value| + subject.member_type = "consortium_organization" + subject.doi_estimate_year_one = value + expect(subject.save).to be false + expect(subject.errors.details).to eq( + doi_estimate_year_one: [{ error: :doi_estimate_invalid, value: "The doi_estimate must be a nonnegative integer." }] + ) + end end end From dd97f1314f4210ccdcaf43082db4f9cefb876fd4 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Sat, 5 Mar 2022 15:42:55 -0500 Subject: [PATCH 7/9] Salesforce - doi_estimate_year_one field. (Change the field name.) --- app/controllers/providers_controller.rb | 4 +-- app/models/provider.rb | 26 +++++++++---------- app/serializers/provider_serializer.rb | 2 +- ...217020855_add_doi_estimate_to_allocator.rb | 4 +-- db/schema.rb | 2 +- spec/models/provider_spec.rb | 10 +++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 6f53f19e9..8f3826021 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -460,7 +460,7 @@ def safe_params { "secondaryServiceContact": [:uid, :email, "givenName", "familyName", :name] }, "votingContact", { "votingContact": [:uid, :email, "givenName", "familyName", :name] }, - "doiEstimateYearOne", + "doiEstimate", ], keys: { "displayName" => :display_name, @@ -487,7 +487,7 @@ def safe_params "salesforceId" => :salesforce_id, "fromSalesforce" => :from_salesforce, "globusUuid" => :globus_uuid, - "doiEstimateYearOne" => :doi_estimate_year_one, + "doiEstimate" => :doi_estimate, }, ) end diff --git a/app/models/provider.rb b/app/models/provider.rb index e7023a713..92effeeee 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -24,7 +24,7 @@ class Provider < ApplicationRecord version doi_quota_allowed doi_quota_used - doi_estimate_year_one + doi_estimate ] # include helper module for caching infrequently changing resources @@ -150,8 +150,8 @@ class Provider < ApplicationRecord # validates :voting_contact, contact: true # validates :billing_information, billing_information: true - # validates :doi_estimate_year_one, numericality: { only_integer: true, greater_than_or_equal_to: 0 } if :member_type === "consortium_organization" - validate :doi_estimate + # validates :doi_estimate, numericality: { only_integer: true, greater_than_or_equal_to: 0 } if :member_type === "consortium_organization" + validate :doi_estimate_field strip_attributes @@ -367,7 +367,7 @@ class Provider < ApplicationRecord updated_at: { type: :date }, deleted_at: { type: :date } } - indexes :doi_estimate_year_one, type: :integer + indexes :doi_estimate, type: :integer end end @@ -434,7 +434,7 @@ def as_indexed_json(options = {}) else contacts.map { |m| m.try(:as_indexed_json, exclude_associations: true) } end, - "doi_estimate_year_one" => doi_estimate_year_one + "doi_estimate" => doi_estimate } end @@ -543,7 +543,7 @@ def csv created: created, updated: updated, deleted_at: deleted_at, - doi_estimate_year_one: doi_estimate_year_one, + doi_estimate: doi_estimate, }.values CSV.generate { |csv| csv << provider } @@ -839,21 +839,21 @@ def activity_id_not_changed end end - def doi_estimate + def doi_estimate_field if member_type === "consortium_organization" begin - num = Integer(doi_estimate_year_one) + num = Integer(doi_estimate) if num < 0 errors.add( - :doi_estimate_year_one, + :doi_estimate, :doi_estimate_invalid, value: "The doi_estimate must be a nonnegative integer.", ) end rescue errors.add( + :doi_estimate, :doi_estimate_invalid, - :doi_estimate_year_one, value: "The doi_estimate must be a nonnegative integer.", ) end @@ -893,7 +893,7 @@ def to_jsonapi "created" => created.iso8601, "updated" => updated.iso8601, "deleted_at" => deleted_at ? deleted_at.iso8601 : nil, - "doi_estimate_year_one" => doi_estimate_year_one, + "doi_estimate" => doi_estimate, } { @@ -948,9 +948,9 @@ def set_defaults 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_year_one = doi_estimate_year_one.to_i + self.doi_estimate = doi_estimate.to_i else - self.doi_estimate_year_one = 0 + self.doi_estimate = 0 end # custom filename for attachment as data URLs don't support filenames diff --git a/app/serializers/provider_serializer.rb b/app/serializers/provider_serializer.rb index 40149b7fe..3ca79adca 100644 --- a/app/serializers/provider_serializer.rb +++ b/app/serializers/provider_serializer.rb @@ -40,7 +40,7 @@ class ProviderSerializer :has_required_contacts, :created, :updated, - :doi_estimate_year_one + :doi_estimate has_many :clients, record_type: :clients has_many :prefixes, record_type: :prefixes diff --git a/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb b/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb index 7e5a0d5e1..47c0c8666 100644 --- a/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb +++ b/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb @@ -1,10 +1,10 @@ class AddDoiEstimateToAllocator < ActiveRecord::Migration[5.2] def change - add_column :allocator, :doi_estimate_year_one, :integer, default: 0, null: false + add_column :allocator, :doi_estimate, :integer, default: 0, null: false end def self.down - remove_column :doi_estimate_year_one + remove_column :doi_estimate end end diff --git a/db/schema.rb b/db/schema.rb index 590bc2f54..14df29a96 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -76,7 +76,7 @@ t.string "logo_content_type" t.bigint "logo_file_size" t.datetime "logo_updated_at" - t.integer "doi_estimate_year_one", default: 0, null: false + t.integer "doi_estimate", default: 0, null: false t.index ["globus_uuid"], name: "index_allocator_on_globus_uuid" t.index ["organization_type"], name: "index_allocator_organization_type" t.index ["symbol"], name: "symbol", unique: true diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index 7e8c61f69..36f42172b 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -156,20 +156,20 @@ it "valid" do [0, 98765, "0", "98765"].each do |value| subject.member_type = "consortium_organization" - subject.doi_estimate_year_one = value + subject.doi_estimate = value expect(subject.save).to be true - expect(subject.doi_estimate_year_one).to be_a_kind_of(Integer) - expect(subject.doi_estimate_year_one).to eq(value.to_i) + expect(subject.doi_estimate).to be_a_kind_of(Integer) + expect(subject.doi_estimate).to eq(value.to_i) end end it "invalid" do ["-123", -123].each do |value| subject.member_type = "consortium_organization" - subject.doi_estimate_year_one = value + subject.doi_estimate = value expect(subject.save).to be false expect(subject.errors.details).to eq( - doi_estimate_year_one: [{ error: :doi_estimate_invalid, value: "The doi_estimate must be a nonnegative integer." }] + doi_estimate: [{ error: :doi_estimate_invalid, value: "The doi_estimate must be a nonnegative integer." }] ) end end From a00e615579a24613d644cccc15b980b344c86f81 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Sun, 6 Mar 2022 22:24:46 -0500 Subject: [PATCH 8/9] Salesforce - doi_estimate_year_one field. (Rubocop.) --- db/migrate/20220217020855_add_doi_estimate_to_allocator.rb | 2 ++ db/schema.rb | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb b/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb index 47c0c8666..c22982d8f 100644 --- a/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb +++ b/db/migrate/20220217020855_add_doi_estimate_to_allocator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddDoiEstimateToAllocator < ActiveRecord::Migration[5.2] def change add_column :allocator, :doi_estimate, :integer, default: 0, null: false diff --git a/db/schema.rb b/db/schema.rb index 14df29a96..f55b1eeb4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,6 @@ +# frozen_string_literal: true + +# # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,7 +14,6 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema.define(version: 2022_02_17_020855) do - create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| t.string "name", limit: 191, null: false t.string "record_type", null: false @@ -299,5 +301,4 @@ t.index ["provider_id"], name: "FKE7FBD67446EBD781" t.index ["uid"], name: "index_provider_prefixes_on_uid", length: 128 end - end From c675f6c384c86b8e6eaccd86f4ce0fcb2527d875 Mon Sep 17 00:00:00 2001 From: Suzanne Vogt Date: Mon, 7 Mar 2022 13:28:52 -0500 Subject: [PATCH 9/9] Salesforce - doi_estimate_year_one field. (Review comments.) --- app/models/provider.rb | 4 ++-- spec/models/provider_spec.rb | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/provider.rb b/app/models/provider.rb index 92effeeee..f742696a4 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -840,7 +840,7 @@ def activity_id_not_changed end def doi_estimate_field - if member_type === "consortium_organization" + if member_type == "consortium_organization" begin num = Integer(doi_estimate) if num < 0 @@ -947,7 +947,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" + if member_type == "consortium_organization" self.doi_estimate = doi_estimate.to_i else self.doi_estimate = 0 diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index 36f42172b..dc220a3de 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require "rails_helper" -require "pp" describe Provider, type: :model do let(:provider) { create(:provider) }