Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
RDMS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
researchdata
RDMS
Commits
b7853e80
Commit
b7853e80
authored
2 years ago
by
Anusha Ranganathan
Browse files
Options
Downloads
Patches
Plain Diff
Adding tests for dataset model
parent
1c0a9af7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!19
Develop
,
!3
Feature/18 datacite metadata model
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hyrax/app/models/dataset.rb
+24
-33
24 additions, 33 deletions
hyrax/app/models/dataset.rb
hyrax/spec/models/dataset_spec.rb
+444
-2
444 additions, 2 deletions
hyrax/spec/models/dataset_spec.rb
with
468 additions
and
35 deletions
hyrax/app/models/dataset.rb
+
24
−
33
View file @
b7853e80
...
...
@@ -13,25 +13,30 @@ class Dataset < ActiveFedora::Base
# property date_uploaded - defined in core metadata - keep
# property depositor - defined in core metadata - keep
# property title - defined in core metadata - keep
# property based_near - defined in the basic metadata - ignore
# property bibliographic_citation - defined in the basic metadata - keep
# property contributor - defined in the basic metadata - ignore
# property alternative_title - defined in the basic metadata - keep
# property label - defined in the basic metadata - keep (used for version label)
# property relative_path - defined in the basic metadata - ignore (used for file storage)
# property import_url - defined in the basic metadata - ignore (used for file imports)
# property resource_type - defined in the basic metadata - keep
# property creator - defined in the basic metadata - ignore
# property date_created - defined in the basic metadata - keep
# property description - defined in the basic metadata - keep (used as abstract)
# property identifier - defined in the basic metadata - ignore
# property import_url - defined in the basic metadata - ignore
# property contributor - defined in the basic metadata - ignore
# property description - defined in the basic metadata - keep
# property abstract - defined in the basic metadata - keep
# property keyword - defined in the basic metadata - keep
# property label - defined in the basic metadata - keep (used for version label)
# property language - defined in the basic metadata - keep
# property license - defined in the basic metadata - keep
# property rights_notes - defined in the basic metadata - keep
# property rights_statement - defined in the basic metadata - keep
# property access_right - defined in the basic metadata - keep
# property publisher - defined in the basic metadata - keep
# property date_created - defined in the basic metadata - keep
# property subject - defined in the basic metadata - keep
# property language - defined in the basic metadata - keep
# property identifier - defined in the basic metadata - ignore
# property based_near - defined in the basic metadata - ignore
# property related_url - defined in the basic metadata - ignore
# property relative_path - defined in the basic metadata - ignore
# property resource_type - defined in the basic metadata - keep
# property license (rights) - defined in the basic metadata - keep
# property rights_statement - defined in the basic metadata - keep
# property bibliographic_citation - defined in the basic metadata - keep
# property source - defined in the basic metadata - keep
# property subject - defined in the basic metadata - keep
property
:doi
,
predicate:
::
RDF
::
Vocab
::
DataCite
.
doi
,
multiple:
false
do
|
index
|
index
.
as
:symbol
...
...
@@ -39,34 +44,20 @@ class Dataset < ActiveFedora::Base
property
:complex_person
,
predicate:
::
RDF
::
Vocab
::
SIOC
.
has_creator
,
class_name
:"ComplexPerson"
property
:alternative_title
,
predicate:
::
RDF
::
Vocab
::
DC
.
alternative
,
multiple:
false
do
|
index
|
index
.
as
:stored_searchable
end
# property publisher - defined in the basic metadata
property
:date_published
,
predicate:
::
RDF
::
Vocab
::
Rdms
.
datePublished
,
multiple:
false
do
|
index
|
index
.
type
:date
index
.
as
:stored_sortable
end
# property resource_type - defined in the basic metadata
# property subject - defined in the basic metadata
# property :date_published, predicate: ::RDF::Vocab::Rdms.datePublished, multiple: false do |index|
# index.type :date
# index.as :stored_sortable
# end
property
:complex_date
,
predicate:
::
RDF
::
Vocab
::
DC
.
date
,
class_name
:"ComplexDate"
# property language - defined in the basic metadata
property
:complex_identifier
,
predicate:
::
RDF
::
Vocab
::
Rdms
.
identifier
,
class_name
:"ComplexIdentifier"
# size and format to be obtained from the files attached
# label property in basic metadata can be used for version label
# rights - leave for now. There's rights and license will that suffice. Do we need to record date?
# description is in the basic metadata and used for abstract. Ignoring other descriptions for now.
# description and abstract is in the basic metadata. Ignoring other descriptions for now.
# Geolocation - would this be used? Ignoring for now.
...
...
This diff is collapsed.
Click to expand it.
hyrax/spec/models/dataset_spec.rb
+
444
−
2
View file @
b7853e80
...
...
@@ -3,7 +3,449 @@
require
'rails_helper'
RSpec
.
describe
Dataset
do
it
"has tests"
do
skip
"Add your tests here"
it
'has human readable type for the dataset'
do
@obj
=
build
(
:dataset
)
expect
(
@obj
.
human_readable_type
).
to
eq
(
'Dataset'
)
end
describe
'date_modified'
do
it
'has date_modified as singular'
do
@obj
=
build
(
:dataset
,
date_modified:
'2018/04/23'
)
expect
(
@obj
.
date_modified
).
to
eq
'2018/04/23'
end
end
describe
'date_uploaded'
do
it
'has date_uploaded as singular'
do
@obj
=
build
(
:dataset
,
date_uploaded:
'2018 01 02'
)
expect
(
@obj
.
date_uploaded
).
to
eq
'2018 01 02'
end
end
describe
'depositor'
do
it
'has depositor'
do
@obj
=
build
(
:dataset
,
depositor:
'Name of depositor'
)
expect
(
@obj
.
depositor
).
to
eq
'Name of depositor'
end
end
describe
'title'
do
it
'requires title'
do
@obj
=
build
(
:dataset
,
title:
nil
)
expect
{
@obj
.
save!
}.
to
raise_error
(
ActiveFedora
::
RecordInvalid
,
'Validation failed: Title Your work must have a title.'
)
end
it
'has a multi valued title field'
do
@obj
=
build
(
:dataset
,
title:
[
'test dataset'
])
expect
(
@obj
.
title
).
to
eq
[
'test dataset'
]
end
end
describe
'alternative_title'
do
it
'has alternative_title'
do
@obj
=
build
(
:dataset
,
alternative_title:
[
'Alternative Title'
])
expect
(
@obj
.
alternative_title
).
to
eq
[
'Alternative Title'
]
end
end
describe
'label'
do
it
'has label as singular'
do
@obj
=
build
(
:dataset
,
label:
'Label 1'
)
expect
(
@obj
.
label
).
to
eq
'Label 1'
end
end
describe
'relative_path'
do
it
'has relative_path as singular'
do
@obj
=
build
(
:dataset
,
relative_path:
'relative/path/to/file'
)
expect
(
@obj
.
relative_path
).
to
eq
'relative/path/to/file'
end
end
describe
'import_url'
do
it
'has import_url as singular'
do
@obj
=
build
(
:dataset
,
import_url:
'http://example.com/import/url'
)
expect
(
@obj
.
import_url
).
to
eq
'http://example.com/import/url'
end
end
describe
'resource_type'
do
it
'has resource_type'
do
@obj
=
build
(
:dataset
,
resource_type:
[
'Dataset'
])
expect
(
@obj
.
resource_type
).
to
eq
[
'Dataset'
]
end
end
describe
'creator'
do
it
'has creator'
do
@obj
=
build
(
:dataset
,
creator:
[
'Creator 1'
])
expect
(
@obj
.
creator
).
to
eq
[
'Creator 1'
]
end
end
describe
'contributor'
do
it
'has contributor'
do
@obj
=
build
(
:dataset
,
contributor:
[
'contributor 1'
])
expect
(
@obj
.
contributor
).
to
eq
[
'contributor 1'
]
end
end
describe
'description'
do
it
'has description'
do
@obj
=
build
(
:dataset
,
description:
[
'description 1'
])
expect
(
@obj
.
description
).
to
eq
[
'description 1'
]
end
end
describe
'abstract'
do
it
'has abstract'
do
@obj
=
build
(
:dataset
,
abstract:
[
'abstract 1'
])
expect
(
@obj
.
abstract
).
to
eq
[
'abstract 1'
]
end
end
describe
'keyword'
do
it
'has keyword'
do
@obj
=
build
(
:dataset
,
keyword:
[
'keyword 2'
,
'3 keyword'
,
'keyword 1'
])
expect
(
@obj
.
keyword
).
to
eq
[
'keyword 2'
,
'3 keyword'
,
'keyword 1'
]
end
end
describe
'license'
do
it
'has license'
do
@obj
=
build
(
:dataset
,
license:
[
'CC-0'
])
expect
(
@obj
.
license
).
to
eq
[
'CC-0'
]
end
end
describe
'rights_notes'
do
it
'has rights_notes'
do
@obj
=
build
(
:dataset
,
rights_notes:
[
'rights_notes 1'
])
expect
(
@obj
.
rights_notes
).
to
eq
[
'rights_notes 1'
]
end
end
describe
'rights_statement'
do
it
'has rights_statement'
do
@obj
=
build
(
:dataset
,
rights_statement:
[
'rights_statement 1'
])
expect
(
@obj
.
rights_statement
).
to
eq
[
'rights_statement 1'
]
end
end
describe
'access_right'
do
it
'has access_right'
do
@obj
=
build
(
:dataset
,
access_right:
[
'access_right 1'
])
expect
(
@obj
.
access_right
).
to
eq
[
'access_right 1'
]
end
end
describe
'publisher'
do
it
'has publisher'
do
@obj
=
build
(
:dataset
,
publisher:
[
'publisher 1'
])
expect
(
@obj
.
publisher
).
to
eq
[
'publisher 1'
]
end
end
describe
'date_created'
do
it
'has date_created'
do
@obj
=
build
(
:dataset
,
date_created:
[
'date_created 1'
])
expect
(
@obj
.
date_created
).
to
eq
[
'date_created 1'
]
end
end
describe
'subject'
do
it
'has subject'
do
@obj
=
build
(
:dataset
,
subject:
[
'subject 1'
])
expect
(
@obj
.
subject
).
to
eq
[
'subject 1'
]
end
end
describe
'language'
do
it
'has language'
do
@obj
=
build
(
:dataset
,
language:
[
'language 1'
])
expect
(
@obj
.
language
).
to
eq
[
'language 1'
]
end
end
describe
'identifier'
do
it
'has identifier'
do
@obj
=
build
(
:dataset
,
identifier:
[
'identifier 1'
])
expect
(
@obj
.
identifier
).
to
eq
[
'identifier 1'
]
end
end
describe
'based_near'
do
it
'has based_near'
do
@obj
=
build
(
:dataset
,
based_near:
[
'me'
])
expect
(
@obj
.
based_near
).
to
eq
[
'me'
]
end
end
describe
'related_url'
do
it
'has related_url'
do
@obj
=
build
(
:dataset
,
related_url:
[
'http://example.com/related/url'
])
expect
(
@obj
.
related_url
).
to
eq
[
'http://example.com/related/url'
]
end
end
describe
'bibliographic_citation'
do
it
'has bibliographic_citation'
do
@obj
=
build
(
:dataset
,
bibliographic_citation:
[
'bibliographic_citation 1'
])
expect
(
@obj
.
bibliographic_citation
).
to
eq
[
'bibliographic_citation 1'
]
end
end
describe
'source'
do
it
'has source'
do
@obj
=
build
(
:dataset
,
source:
[
'Source 1'
])
expect
(
@obj
.
source
).
to
eq
[
'Source 1'
]
end
end
describe
'doi'
do
it
'has doi as singular'
do
@obj
=
build
(
:dataset
,
doi:
'123167641234'
)
expect
(
@obj
.
doi
).
to
eq
'123167641234'
end
end
describe
'complex_person'
do
it
'creates a person active triple resource with name'
do
@obj
=
build
(
:dataset
,
complex_person_attributes:
[{
name:
'Anamika'
}]
)
expect
(
@obj
.
complex_person
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_person
.
first
.
name
).
to
eq
[
'Anamika'
]
expect
(
@obj
.
complex_person
.
first
.
first_name
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
last_name
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
email
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
affiliation
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
role
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
orcid
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
display_order
).
to
be_empty
end
it
'creates a person active triple resource with name, affiliation, orcid, role and display order'
do
@obj
=
build
(
:dataset
,
complex_person_attributes:
[{
name:
'Anamika'
,
affiliation:
'Some org'
,
role:
'Creator'
,
orcid:
'1231234'
,
display_order:
1
}]
)
expect
(
@obj
.
complex_person
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_person
.
first
.
name
).
to
eq
[
'Anamika'
]
expect
(
@obj
.
complex_person
.
first
.
first_name
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
last_name
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
email
).
to
be_empty
expect
(
@obj
.
complex_person
.
first
.
role
).
to
eq
[
'Creator'
]
expect
(
@obj
.
complex_person
.
first
.
orcid
).
to
eq
[
'1231234'
]
expect
(
@obj
.
complex_person
.
first
.
display_order
).
to
eq
([
1
])
expect
(
@obj
.
complex_person
.
first
.
affiliation
).
to
eq
([
'Some org'
])
end
it
'rejects person active triple with no name and only orcid'
do
@obj
=
build
(
:dataset
,
complex_person_attributes:
[{
orcid:
'http://example.com/person/123456'
}]
)
expect
(
@obj
.
complex_person
).
to
be_empty
end
end
describe
'complex_date'
do
it
'creates a date active triple resource with all the attributes'
do
@obj
=
build
(
:dataset
,
complex_date_attributes:
[{
date:
'1978-10-28'
,
description:
'Some kind of a date'
,
}]
)
expect
(
@obj
.
complex_date
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_date
.
first
.
date
).
to
eq
[
'1978-10-28'
]
expect
(
@obj
.
complex_date
.
first
.
description
).
to
eq
[
'Some kind of a date'
]
end
it
'creates a date active triple resource with just the date'
do
@obj
=
build
(
:dataset
,
complex_date_attributes:
[{
date:
'1984-09-01'
}]
)
expect
(
@obj
.
complex_date
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_date
.
first
.
date
).
to
eq
[
'1984-09-01'
]
expect
(
@obj
.
complex_date
.
first
.
description
).
to
be_empty
end
it
'rejects a date active triple with no date'
do
@obj
=
build
(
:dataset
,
complex_date_attributes:
[{
description:
'Local date'
}]
)
expect
(
@obj
.
complex_date
).
to
be_empty
end
end
describe
'complex_identifier'
do
it
'creates an identifier active triple resource with all the attributes'
do
@obj
=
build
(
:dataset
,
complex_identifier_attributes:
[{
identifier:
'0000-0000-0000-0000'
,
scheme:
'uri_of_ORCID_scheme'
,
label:
'ORCID'
}]
)
expect
(
@obj
.
complex_identifier
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_identifier
.
first
.
identifier
).
to
eq
[
'0000-0000-0000-0000'
]
expect
(
@obj
.
complex_identifier
.
first
.
scheme
).
to
eq
[
'uri_of_ORCID_scheme'
]
expect
(
@obj
.
complex_identifier
.
first
.
label
).
to
eq
[
'ORCID'
]
end
it
'creates an identifier active triple resource with just the identifier'
do
@obj
=
build
(
:dataset
,
complex_identifier_attributes:
[{
identifier:
'1234'
}]
)
expect
(
@obj
.
complex_identifier
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_identifier
.
first
.
identifier
).
to
eq
[
'1234'
]
expect
(
@obj
.
complex_identifier
.
first
.
label
).
to
be_empty
expect
(
@obj
.
complex_identifier
.
first
.
scheme
).
to
be_empty
end
it
'rejects an identifier active triple with no identifier'
do
@obj
=
build
(
:dataset
,
complex_identifier_attributes:
[{
label:
'Local'
}]
)
expect
(
@obj
.
complex_identifier
).
to
be_empty
end
end
describe
'complex_funding_reference'
do
it
'creates a complex funding reference active triple resource with funding reference'
do
@obj
=
build
(
:dataset
,
complex_funding_reference_attributes:
[{
funder_identifier:
'f1234'
,
funder_name:
'Bank'
,
award_title:
'No free lunch'
}]
)
expect
(
@obj
.
complex_funding_reference
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_funding_reference
.
first
.
id
).
to
include
(
'#fundref'
)
expect
(
@obj
.
complex_funding_reference
.
first
.
funder_identifier
).
to
eq
[
'f1234'
]
expect
(
@obj
.
complex_funding_reference
.
first
.
funder_name
).
to
eq
[
'Bank'
]
expect
(
@obj
.
complex_funding_reference
.
first
.
award_number
).
to
be_empty
expect
(
@obj
.
complex_funding_reference
.
first
.
award_uri
).
to
be_empty
expect
(
@obj
.
complex_funding_reference
.
first
.
award_title
).
to
eq
[
'No free lunch'
]
end
it
'creates a complex funding reference active triple resource with all the attributes'
do
@obj
=
build
(
:dataset
,
complex_funding_reference_attributes:
[{
funder_identifier:
'f1234'
,
funder_name:
'Bank'
,
award_number:
'a1234'
,
award_uri:
'http://award.com/a1234'
,
award_title:
'No free lunch'
}]
)
expect
(
@obj
.
complex_funding_reference
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_funding_reference
.
first
.
id
).
to
include
(
'#fundref'
)
expect
(
@obj
.
complex_funding_reference
.
first
.
funder_identifier
).
to
eq
[
'f1234'
]
expect
(
@obj
.
complex_funding_reference
.
first
.
funder_name
).
to
eq
[
'Bank'
]
expect
(
@obj
.
complex_funding_reference
.
first
.
award_number
).
to
eq
[
'a1234'
]
expect
(
@obj
.
complex_funding_reference
.
first
.
award_uri
).
to
eq
[
'http://award.com/a1234'
]
expect
(
@obj
.
complex_funding_reference
.
first
.
award_title
).
to
eq
[
'No free lunch'
]
end
it
'rejects a complex funding reference active triple with no attributes'
do
@obj
=
build
(
:dataset
,
complex_funding_reference_attributes:
[{
funder_identifier:
''
,
funder_name:
''
}]
)
expect
(
@obj
.
complex_funding_reference
).
to
be_empty
end
end
describe
'complex_relation'
do
it
'creates a relation active triple resource with all the attributes'
do
@obj
=
build
(
:dataset
,
complex_relation_attributes:
[{
title:
'A related item'
,
url:
'http://example.com/relation'
,
complex_identifier_attributes:
[{
identifier:
[
'123456'
],
label:
[
'local'
]
}],
relationship:
'IsPartOf'
}]
)
expect
(
@obj
.
complex_relation
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_relation
.
first
.
title
).
to
eq
[
'A related item'
]
expect
(
@obj
.
complex_relation
.
first
.
url
).
to
eq
[
'http://example.com/relation'
]
expect
(
@obj
.
complex_relation
.
first
.
complex_identifier
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_relation
.
first
.
complex_identifier
.
first
.
identifier
).
to
eq
[
'123456'
]
expect
(
@obj
.
complex_relation
.
first
.
complex_identifier
.
first
.
label
).
to
eq
[
'local'
]
expect
(
@obj
.
complex_relation
.
first
.
relationship
).
to
eq
[
'IsPartOf'
]
end
it
'creates a relation active triple resource with title, url, identifier and relationship role'
do
@obj
=
build
(
:dataset
,
complex_relation_attributes:
[{
title:
'A relation label'
,
url:
'http://example.com/relation'
,
complex_identifier_attributes:
[{
identifier:
[
'123456'
]
}],
relationship:
'isNewVersionOf'
}]
)
expect
(
@obj
.
complex_relation
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_relation
.
first
.
title
).
to
eq
[
'A relation label'
]
expect
(
@obj
.
complex_relation
.
first
.
url
).
to
eq
[
'http://example.com/relation'
]
expect
(
@obj
.
complex_relation
.
first
.
complex_identifier
.
first
).
to
be_kind_of
ActiveTriples
::
Resource
expect
(
@obj
.
complex_relation
.
first
.
complex_identifier
.
first
.
identifier
).
to
eq
[
'123456'
]
expect
(
@obj
.
complex_relation
.
first
.
complex_identifier
.
first
.
label
).
to
be_empty
expect
(
@obj
.
complex_relation
.
first
.
relationship
).
to
eq
[
'isNewVersionOf'
]
end
it
'rejects relation active triple with url'
do
@obj
=
build
(
:dataset
,
complex_relation_attributes:
[{
url:
'http://example.com/relation'
}]
)
expect
(
@obj
.
complex_relation
).
to
be_empty
end
it
'rejects relation active triple with identifier'
do
@obj
=
build
(
:dataset
,
complex_relation_attributes:
[{
complex_identifier_attributes:
[{
identifier:
[
'123456'
],
label:
'Local'
}],
}]
)
expect
(
@obj
.
complex_relation
).
to
be_empty
end
it
'rejects relation active triple with reltionship name'
do
@obj
=
build
(
:dataset
,
complex_relation_attributes:
[{
relationship:
'isPartOf'
}]
)
expect
(
@obj
.
complex_relation
).
to
be_empty
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment