Skip to content

Commit

Permalink
only allowed doi agency field from controlled list
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jun 3, 2020
1 parent 0f66dc7 commit dc24aee
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Doi < ActiveRecord::Base
validates_format_of :doi, with: /\A10\.\d{4,5}\/[-\._;()\/:a-zA-Z0-9\*~\$\=]+\z/, on: :create
validates_format_of :url, with: /\A(ftp|http|https):\/\/[\S]+/, if: :url?, message: "URL is not valid"
validates_uniqueness_of :doi, message: "This DOI has already been taken", unless: :only_validate
validates_inclusion_of :agency, :in => %w( DataCite Crossref KISTI mEDRA ISTIC JaLC Airiti CNKI OP)
validates :last_landing_page_status, numericality: { only_integer: true }, if: :last_landing_page_status?
validates :xml, presence: true, xml_schema: true, if: Proc.new { |doi| doi.validatable? }
validate :check_dates, if: :dates?
Expand Down
68 changes: 68 additions & 0 deletions spec/models/doi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,74 @@
end
end

describe "validate agency" do
it "DataCite" do
subject = build(:doi, agency: "DataCite")
expect(subject).to be_valid
expect(subject.agency).to eq("DataCite")
end

it "Crossref" do
subject = build(:doi, agency: "Crossref")
expect(subject).to be_valid
expect(subject.agency).to eq("Crossref")
end

it "KISTI" do
subject = build(:doi, agency: "KISTI")
expect(subject).to be_valid
expect(subject.agency).to eq("KISTI")
end

it "mEDRA" do
subject = build(:doi, agency: "mEDRA")
expect(subject).to be_valid
expect(subject.agency).to eq("mEDRA")
end

it "ISTIC" do
subject = build(:doi, agency: "ISTIC")
expect(subject).to be_valid
expect(subject.agency).to eq("ISTIC")
end

it "JaLC" do
subject = build(:doi, agency: "JaLC")
expect(subject).to be_valid
expect(subject.agency).to eq("JaLC")
end

it "Airiti" do
subject = build(:doi, agency: "Airiti")
expect(subject).to be_valid
expect(subject.agency).to eq("Airiti")
end

it "CNKI" do
subject = build(:doi, agency: "CNKI")
expect(subject).to be_valid
expect(subject.agency).to eq("CNKI")
end

it "OP" do
subject = build(:doi, agency: "OP")
expect(subject).to be_valid
expect(subject.agency).to eq("OP")
end

it "XXX" do
subject = build(:doi, agency: "XXX")
expect(subject).to_not be_valid
expect(subject.errors.messages).to eq(:agency=>["is not included in the list"])
end

it "default" do
subject = build(:doi)
expect(subject).to be_valid
expect(subject.agency).to eq("DataCite")
end
end

describe "state" do
subject { create(:doi) }

Expand Down

0 comments on commit dc24aee

Please sign in to comment.