Skip to content

Commit 4deed0b

Browse files
committed
Validate origin URI. Address review comments
1 parent c59973c commit 4deed0b

5 files changed

Lines changed: 22 additions & 2 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def event_status_icon(event, size = nil)
9595
end
9696

9797
def exchange_icon(resource, size = nil)
98-
return unless resource.origin_uri
98+
return unless resource.origin_uri.present?
9999
"<span class='exchange-icon pull-right'>#{icon_for(:exchanged, size)}</span>".html_safe
100100
end
101101

app/models/event.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class Event < ApplicationRecord
157157
validates :presence, inclusion: { in: presences.keys, allow_blank: true }
158158
validates :keywords, length: { maximum: 20 }
159159
validate :allowed_url
160+
validates :origin_uri, url: { allow_blank: true }
161+
160162
clean_array_fields(:keywords, :fields, :event_types, :target_audience,
161163
:eligibility, :host_institutions, :sponsors)
162164
update_suggestions(:keywords, :target_audience, :host_institutions)

app/models/material.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class Material < ApplicationRecord
123123
validates :url, url: true
124124
validates :other_types, presence: true, if: proc { |m| m.resource_type.include?('other') }
125125
validates :keywords, length: { maximum: 20 }
126+
validates :origin_uri, url: { allow_blank: true }
126127

127128
clean_array_fields(:keywords, :fields,
128129
:target_audience, :resource_type, :subsets)

lib/ingestors/oai_pmh_ingestor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def read_oai_rdf(client, tess_instance: false)
9191

9292
extra_metadata = {}
9393
if tess_instance
94-
origin_uri = metadata_tag.at_xpath('//rdf:RDF/*/@rdf:about', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')&.to_s
94+
origin_uri = metadata_tag.at_xpath('//rdf:RDF/*/@rdf:about', 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')&.value
9595
extra_metadata[:origin_uri] = origin_uri
9696
end
9797

test/models/material_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,4 +751,21 @@ class MaterialTest < ActiveSupport::TestCase
751751
bioschemas = m.to_bioschemas.first.generate
752752
refute bioschemas.key?(:license)
753753
end
754+
755+
test 'validates origin_uri' do
756+
@material.origin_uri = nil
757+
assert @material.valid?
758+
759+
@material.origin_uri = ''
760+
assert @material.valid?
761+
762+
@material.origin_uri = 'https://tess-instance.org/materials/123'
763+
assert @material.valid?
764+
765+
@material.origin_uri = 'hamster'
766+
refute @material.valid?
767+
768+
@material.origin_uri = 'ftp://tess-instance.org/materials/123'
769+
refute @material.valid?
770+
end
754771
end

0 commit comments

Comments
 (0)