Skip to content

Commit d44ccd3

Browse files
committed
Tests & fixes
1 parent 255c43c commit d44ccd3

6 files changed

Lines changed: 102 additions & 8 deletions

File tree

lib/bioschemas/generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def self.provider(resource)
148148
p << {
149149
'@type' => 'Organization',
150150
'name' => node.full_title,
151-
'url' => node.url
151+
'url' => node.home_page
152152
}
153153
end
154154

lib/bioschemas/learning_resource_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def self.bioschemas_profile
1212
property :learningResourceType, :resource_type
1313
property :url, :url
1414
property :identifier, :doi
15-
property :verison, :version
15+
property :version, :version
1616
property :description, :description
1717
property :keywords, :keywords
1818
property :author, -> (material) { material.authors.map { |p| person(p) } }

test/fixtures/events.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,11 @@ course_event:
479479
contact: MyContact
480480
eligibility: [ first_come_first_served ]
481481
timezone: UTC
482-
learning_objectives: "There are none."
482+
learning_objectives: " * Learn stuff\n * Get a job\n * Get paid\n"
483+
prerequisites: " * Sleep\n * Eat\n * Breathe\n"
483484
recognition: "Yup. You attended the workshop."
484485
target_audience: ['Everyone!']
486+
language: 'de'
485487

486488
hybrid_event:
487489
presence: 2

test/fixtures/materials.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ material_with_optionals:
138138
subsets: [ 'https://training.com/material/023/part-one', 'https://training.com/material/023/part-two' ]
139139
authors: [ 'Nicolai Tesla', 'Thomas Edison' ]
140140
contributors: [ 'Dr Dre' ]
141-
prerequisites: 'None'
141+
prerequisites: " * None\n * Nothing at all\n"
142142
syllabus: '1. Overview\ 2. The main part\ 3. Summing up'
143-
learning_objectives: 'Understand the new materials model'
143+
learning_objectives: ' - Understand the new materials model'
144144
difficulty_level: intermediate
145145
remote_created_date: 2021-07-12
146146
remote_updated_date: 2021-07-13

test/integration/bioschemas_test.rb

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class BioschemasTest < ActionDispatch::IntegrationTest
7878

7979
test 'Course/CourseInstance & Event bioschemas on show page for course event' do
8080
event = events(:course_event)
81+
event.external_resources.create!({ title: 'Cool website', url: 'https://external-resource.pizza' })
8182
url = event_url(event.id)
8283

8384
get url
@@ -116,6 +117,9 @@ class BioschemasTest < ActionDispatch::IntegrationTest
116117
assert_equal ['Learn lots of stuff!'], course_props['description']
117118
assert_equal ['http://example.com/cool-course-summer'], course_props['url']
118119
assert_equal ['Ruby', 'Javascript'].sort, course_props['keywords'].sort
120+
assert_equal ['Sleep', 'Eat', 'Breathe'].sort, course_props['coursePrerequisites'].sort, 'Should split the markdown into an array'
121+
assert_equal ['Learn stuff', 'Get a job', 'Get paid'].sort, course_props['teaches'].sort, 'Should split the markdown into an array'
122+
assert_equal ['de'].sort, course_props['inLanguage']
119123

120124
assert_equal ['2015-08-23 10:16:33 UTC'], course_instance_props['startDate']
121125
assert_equal ['2015-08-24 18:07:46 UTC'], course_instance_props['endDate']
@@ -183,6 +187,59 @@ class BioschemasTest < ActionDispatch::IntegrationTest
183187
results = graph.query(q)
184188
assert_equal 1, results.count
185189
assert_equal 'CourseCo', results.first.organizer
190+
191+
# External resources
192+
q = RDF::Query.new do
193+
pattern RDF::Query::Pattern.new(course_uri, RDF::Vocab::SCHEMA.mentions, :mentions)
194+
pattern RDF::Query::Pattern.new(:mentions, RDF::Vocab::SCHEMA.name, :name)
195+
pattern RDF::Query::Pattern.new(:mentions, RDF::Vocab::SCHEMA.url, :url)
196+
end
197+
results = graph.query(q)
198+
assert_equal 1, results.count
199+
assert_equal 'Cool website', results.first.name
200+
assert_equal 'https://external-resource.pizza', results.first.url
201+
end
202+
203+
test 'handles non-list markdown for prereqs on course event' do
204+
event = events(:course_event)
205+
event.learning_objectives = "The meaning of life\n * item1 \n * item2\n"
206+
event.prerequisites = "** Get out of bed **"
207+
event.save!
208+
url = event_url(event.slug)
209+
210+
get url
211+
212+
reader = RDF::Reader.for(:rdfa).new(response.body, base_uri: url, logger: false)
213+
graph = RDF::Graph.new
214+
graph.insert_statements(reader)
215+
216+
results = graph.query([:subject, RDF.type, RDF::Vocab::SCHEMA.Course])
217+
course_uri = results.first.subject
218+
assert_equal 1, results.count
219+
assert_equal url, course_uri
220+
221+
results = graph.query([course_uri, RDF::Vocab::SCHEMA.hasCourseInstance, :course_instance])
222+
assert_equal 1, results.count
223+
224+
results = graph.query([results.first.object, RDF.type, RDF::Vocab::SCHEMA.CourseInstance])
225+
course_instance_uri = results.first.subject
226+
assert_equal 1, results.count
227+
228+
course_props = {}
229+
graph.query([course_uri, :p, :o]).each do |result|
230+
key = result.predicate.to_s.split('/').last
231+
course_props[key] ||= []
232+
course_props[key] << result.object.to_s
233+
end
234+
course_instance_props = {}
235+
graph.query([course_instance_uri, :p, :o]).each do |result|
236+
key = result.predicate.to_s.split('/').last
237+
course_instance_props[key] ||= []
238+
course_instance_props[key] << result.object.to_s
239+
end
240+
241+
assert_equal ['** Get out of bed **'], course_props['coursePrerequisites']
242+
assert_equal ["The meaning of life\n * item1 \n * item2\n"], course_props['teaches']
186243
end
187244

188245
test 'Bioschemas on event index page' do
@@ -207,7 +264,10 @@ class BioschemasTest < ActionDispatch::IntegrationTest
207264

208265
test 'LearningResource bioschemas on show page for material' do
209266
material = materials(:material_with_optionals)
210-
url = material_url(material.id)
267+
material.external_resources.create!({ title: 'Cool website', url: 'https://external-resource.pizza' })
268+
material.node_names = ['Westeros']
269+
material.save!
270+
url = material_url(material.slug)
211271

212272
get url
213273

@@ -233,6 +293,15 @@ class BioschemasTest < ActionDispatch::IntegrationTest
233293
assert_equal ['2021-07-12'], props['dateCreated']
234294
assert_equal ['2021-07-13'], props['dateModified']
235295
assert_equal ['intermediate'], props['educationalLevel']
296+
assert_equal ['Quiz', 'Presentation'].sort, props['learningResourceType'].sort
297+
assert_equal ['http://dx.doi.ac.uk/2q3093032'], props['identifier']
298+
assert_equal ['1.0.3'], props['version']
299+
assert_equal ['2021-07-12'], props['dateCreated']
300+
assert_equal ['2021-07-13'], props['dateModified']
301+
assert_equal ['2021-07-14'], props['datePublished']
302+
assert_equal ['development'], props['creativeWorkStatus']
303+
assert_equal ['None', 'Nothing at all'].sort, props['competencyRequired'].sort, 'Should split the markdown into an array'
304+
assert_equal [' - Understand the new materials model'].sort, props['teaches'].sort, 'Should not split the markdown into an array'
236305

237306
# Audience
238307
q = RDF::Query.new do
@@ -276,6 +345,29 @@ class BioschemasTest < ActionDispatch::IntegrationTest
276345
assert_equal 1, results.count
277346
authors = results.map(&:contributor)
278347
assert_includes authors, 'Dr Dre'
348+
349+
# Provider
350+
q = RDF::Query.new do
351+
pattern RDF::Query::Pattern.new(material_uri, RDF::Vocab::SCHEMA.provider, :provider_info)
352+
pattern RDF::Query::Pattern.new(:provider_info, RDF::Vocab::SCHEMA.name, :name)
353+
pattern RDF::Query::Pattern.new(:provider_info, RDF::Vocab::SCHEMA.url, :url)
354+
end
355+
results = graph.query(q)
356+
providers = results.map { |r| [r.name, r.url] }
357+
assert_equal 2, providers.count
358+
assert_includes providers, ['ELIXIR Westeros', 'http://example.com']
359+
assert_includes providers, ['Goblet', 'http://mygoblet.org']
360+
361+
# External resources
362+
q = RDF::Query.new do
363+
pattern RDF::Query::Pattern.new(material_uri, RDF::Vocab::SCHEMA.mentions, :mentions)
364+
pattern RDF::Query::Pattern.new(:mentions, RDF::Vocab::SCHEMA.name, :name)
365+
pattern RDF::Query::Pattern.new(:mentions, RDF::Vocab::SCHEMA.url, :url)
366+
end
367+
results = graph.query(q)
368+
assert_equal 1, results.count
369+
assert_equal 'Cool website', results.first.name
370+
assert_equal 'https://external-resource.pizza', results.first.url
279371
end
280372

281373
test 'Bioschemas on material index page' do

test/models/material_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class MaterialTest < ActiveSupport::TestCase
6060
assert_equal 1, m.contributors.size, 'old contributors size not matched.'
6161
assert_equal 'Dr Dre', m.contributors[0], 'old contributors[0] not matched.'
6262

63-
assert_equal 'None', m.prerequisites, 'old prerequisites not matched.'
63+
assert_equal " * None\n * Nothing at all\n", m.prerequisites, 'old prerequisites not matched.'
6464
assert_equal '1. Overview\ 2. The main part\ 3. Summing up', m.syllabus, 'old syllabus not matched.'
65-
assert_equal 'Understand the new materials model', m.learning_objectives, 'old learning objectives not matched.'
65+
assert_equal ' - Understand the new materials model', m.learning_objectives, 'old learning objectives not matched.'
6666

6767
# update optionals
6868
m.content_provider = content_providers(:iann)

0 commit comments

Comments
 (0)