Skip to content

Commit

Permalink
ror_id should be unique.
Browse files Browse the repository at this point in the history
add some tests
  • Loading branch information
whomingbird committed Jan 27, 2025
1 parent 36f9f2b commit 5fc578c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Institution < ApplicationRecord
auto_strip_attributes :web_page

validates :title, uniqueness: true
validates :ror_id, uniqueness: true, allow_blank: true
validates :web_page, url: { allow_nil: true, allow_blank: true }
validates :country, country: true

Expand Down
16 changes: 16 additions & 0 deletions test/functional/institutions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ def test_can_not_create_institution_with_invalid_ror_id
assert_equal assigns(:institution).errors[:ror_id].first, 'is invalid.'
end


def test_can_not_create_institution_with_the_title_or_ror_id_that_already_exists
FactoryBot.create(:institution, title: 'my Institution', ror_id:'01f7bcy98')

assert_no_difference('Institution.count') do
post :create, params: { institution: { title: 'my Institution'} }
end
assert_equal assigns(:institution).errors[:title].first, 'has already been taken'

assert_no_difference('Institution.count') do
post :create, params: { institution: { title: 'my Institution new', ror_id:'01f7bcy98'} }
end
assert_equal assigns(:institution).errors[:ror_id].first, 'has already been taken'

end

def test_should_show_institution
get :show, params: { id: institutions(:one).id }
assert_response :success
Expand Down
8 changes: 8 additions & 0 deletions test/unit/institution_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,19 @@ def test_can_be_edited_by
i.ror_id='01f7bcy98'
assert i.valid?

i.ror_id = ''
assert i.valid?

i.ror_id = '1121'
assert !i.valid?

i.ror_id = '1121-1121-1121'
assert !i.valid?

#duplicate ror_id
existing_institution = FactoryBot.create(:institution, ror_id: '01f7bcy98')
new_institution = FactoryBot.build(:institution, ror_id: existing_institution.ror_id)
assert_not new_institution.valid?
end

test 'test uuid generated' do
Expand Down

0 comments on commit 5fc578c

Please sign in to comment.