mods_display 0.9.1 → 1.0.0.alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +433 -35
- data/README.md +0 -95
- data/app/components/mods_display/field_component.html.erb +13 -0
- data/app/components/mods_display/field_component.rb +27 -0
- data/app/components/mods_display/list_field_component.html.erb +11 -0
- data/app/components/mods_display/list_field_component.rb +10 -0
- data/app/components/mods_display/record_component.html.erb +5 -0
- data/app/components/mods_display/record_component.rb +39 -0
- data/app/helpers/mods_display/record_helper.rb +106 -0
- data/app/models/mods_display/record.rb +26 -0
- data/config/locales/en.yml +1 -1
- data/config.ru +9 -0
- data/lib/mods_display/engine.rb +13 -0
- data/lib/mods_display/fields/access_condition.rb +4 -0
- data/lib/mods_display/fields/contents.rb +14 -15
- data/lib/mods_display/fields/field.rb +13 -149
- data/lib/mods_display/fields/genre.rb +4 -0
- data/lib/mods_display/fields/imprint.rb +52 -3
- data/lib/mods_display/fields/location.rb +1 -1
- data/lib/mods_display/fields/name.rb +11 -20
- data/lib/mods_display/fields/nested_related_item.rb +7 -18
- data/lib/mods_display/fields/note.rb +4 -0
- data/lib/mods_display/fields/related_item.rb +4 -0
- data/lib/mods_display/fields/resource_type.rb +1 -1
- data/lib/mods_display/fields/sub_title.rb +3 -3
- data/lib/mods_display/fields/subject.rb +13 -39
- data/lib/mods_display/fields/title.rb +43 -32
- data/lib/mods_display/fields/values.rb +4 -4
- data/lib/mods_display/html.rb +55 -106
- data/lib/mods_display/version.rb +1 -1
- data/lib/mods_display.rb +2 -17
- data/mods_display.gemspec +15 -9
- metadata +45 -105
- data/.github/workflows/ruby.yml +0 -24
- data/.gitignore +0 -21
- data/lib/mods_display/configuration/access_condition.rb +0 -21
- data/lib/mods_display/configuration/base.rb +0 -34
- data/lib/mods_display/configuration/genre.rb +0 -9
- data/lib/mods_display/configuration/imprint.rb +0 -13
- data/lib/mods_display/configuration/name.rb +0 -9
- data/lib/mods_display/configuration/note.rb +0 -9
- data/lib/mods_display/configuration/related_item.rb +0 -9
- data/lib/mods_display/configuration/subject.rb +0 -13
- data/lib/mods_display/configuration/title.rb +0 -9
- data/lib/mods_display/configuration.rb +0 -93
- data/lib/mods_display/controller_extension.rb +0 -32
- data/lib/mods_display/helpers/record_helper.rb +0 -131
- data/lib/mods_display/model_extension.rb +0 -22
- data/lib/mods_display/railtie.rb +0 -10
- data/spec/configuration/access_condition_spec.rb +0 -10
- data/spec/configuration/base_spec.rb +0 -39
- data/spec/fake_app.rb +0 -18
- data/spec/fields/abstract_spec.rb +0 -39
- data/spec/fields/access_condition_spec.rb +0 -107
- data/spec/fields/audience_spec.rb +0 -24
- data/spec/fields/cartographics_spec.rb +0 -38
- data/spec/fields/collection_spec.rb +0 -77
- data/spec/fields/contact_spec.rb +0 -23
- data/spec/fields/contents_spec.rb +0 -39
- data/spec/fields/description_spec.rb +0 -55
- data/spec/fields/extent_spec.rb +0 -31
- data/spec/fields/form_spec.rb +0 -49
- data/spec/fields/genre_spec.rb +0 -34
- data/spec/fields/geo_spec.rb +0 -40
- data/spec/fields/identifier_spec.rb +0 -61
- data/spec/fields/imprint_spec.rb +0 -289
- data/spec/fields/language_spec.rb +0 -51
- data/spec/fields/location_spec.rb +0 -81
- data/spec/fields/name_spec.rb +0 -166
- data/spec/fields/nested_related_item_spec.rb +0 -89
- data/spec/fields/note_spec.rb +0 -72
- data/spec/fields/related_item_spec.rb +0 -72
- data/spec/fields/resource_type_spec.rb +0 -34
- data/spec/fields/sub_title_spec.rb +0 -20
- data/spec/fields/subject_spec.rb +0 -113
- data/spec/fields/title_spec.rb +0 -74
- data/spec/fixtures/access_condition_fixtures.rb +0 -58
- data/spec/fixtures/cartographics_fixtures.rb +0 -52
- data/spec/fixtures/imprint_fixtures.rb +0 -349
- data/spec/fixtures/name_fixtures.rb +0 -398
- data/spec/fixtures/nested_realted_items_fixtures.rb +0 -64
- data/spec/fixtures/related_item_fixtures.rb +0 -107
- data/spec/fixtures/subjects_fixtures.rb +0 -115
- data/spec/fixtures/title_fixtures.rb +0 -101
- data/spec/helpers/record_helper_spec.rb +0 -241
- data/spec/integration/configuration_spec.rb +0 -57
- data/spec/integration/html_spec.rb +0 -87
- data/spec/integration/installation_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -46
- data/spec/test_fr.yml +0 -3
@@ -1,89 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ModsDisplay::NestedRelatedItem do
|
4
|
-
include RelatedItemFixtures
|
5
|
-
include NestedRelatedItemFixtures
|
6
|
-
|
7
|
-
let(:nested_related_item) do
|
8
|
-
described_class.new(
|
9
|
-
Stanford::Mods::Record.new.from_str(mods, false).related_item,
|
10
|
-
ModsDisplay::Configuration::Base.new,
|
11
|
-
double('controller')
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#label' do
|
16
|
-
subject(:label) { nested_related_item.fields.first.label }
|
17
|
-
|
18
|
-
context 'when a constituent' do
|
19
|
-
let(:mods) { multi_constituent_fixture }
|
20
|
-
|
21
|
-
it { is_expected.to eq 'Contains:' }
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'when a host' do
|
25
|
-
let(:mods) { related_item_host_fixture }
|
26
|
-
|
27
|
-
it { is_expected.to eq 'Appears in:' }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe '#fields' do
|
32
|
-
let(:mods) { multi_constituent_fixture }
|
33
|
-
subject(:fields) { nested_related_item.fields }
|
34
|
-
|
35
|
-
describe 'memoization' do
|
36
|
-
it 'only calls related_item_mods_object once per item regardless of how many times the method is called' do
|
37
|
-
expect(nested_related_item).to receive(:related_item_mods_object).exactly(2).times
|
38
|
-
|
39
|
-
5.times { nested_related_item.fields }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'when an element that should be nested' do
|
44
|
-
it 'has a field for each related item' do
|
45
|
-
expect(fields.length).to eq 1
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'when a collection' do
|
50
|
-
let(:mods) { related_item_host_fixture }
|
51
|
-
|
52
|
-
it 'is not included' do
|
53
|
-
expect(fields.length).to eq 1 # This fixture has two host related items one of which is a collection
|
54
|
-
expect(fields.first.values.to_s).not_to include 'A collection'
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'when handled by another related_item class' do
|
59
|
-
let(:mods) { basic_related_item_fixture }
|
60
|
-
|
61
|
-
it { is_expected.to be_empty }
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe '#to_html' do
|
66
|
-
subject(:html) { Capybara.string(nested_related_item.to_html) }
|
67
|
-
let(:mods) { related_item_host_fixture }
|
68
|
-
|
69
|
-
describe 'memoization' do
|
70
|
-
let(:mods) { multi_constituent_fixture }
|
71
|
-
|
72
|
-
it 'only loops throug hthe fields once regardless of how many times the method is called' do
|
73
|
-
expect(nested_related_item.fields).to receive(:each).exactly(1).times.and_call_original
|
74
|
-
|
75
|
-
5.times { nested_related_item.to_html }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'renders an unordered list with an embedded dl containing the metadata of the related item' do
|
80
|
-
within(html.first('dd')) do |dd|
|
81
|
-
expect(dd).to have_css('ul.mods_display_nested_related_items')
|
82
|
-
within(dd.find('ul.mods_display_nested_related_items li')) do |li|
|
83
|
-
expect(li).to have_css('dl dt', text: 'Custom Notes:')
|
84
|
-
expect(li).to have_css('dl dd', text: 'A note content')
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
data/spec/fields/note_spec.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
def mods_display_note(mods_record)
|
4
|
-
ModsDisplay::Note.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
|
-
end
|
6
|
-
|
7
|
-
describe ModsDisplay::Note do
|
8
|
-
before(:all) do
|
9
|
-
@note = Stanford::Mods::Record.new.from_str('<mods><note>Note Field</note></mods>', false).note
|
10
|
-
@display_label = Stanford::Mods::Record.new.from_str(
|
11
|
-
"<mods><note displayLabel='Special Label'>Note Field</note></mods>", false
|
12
|
-
).note
|
13
|
-
@sor_label = Stanford::Mods::Record.new.from_str(
|
14
|
-
"<mods><note type='statement of responsibility'>Note Field</note></mods>", false
|
15
|
-
).note
|
16
|
-
@contact_note = Stanford::Mods::Record.new.from_str(
|
17
|
-
"<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false
|
18
|
-
).note
|
19
|
-
@type_label = Stanford::Mods::Record.new.from_str(
|
20
|
-
"<mods><note type='some other Type'>Note Field</note></mods>", false
|
21
|
-
).note
|
22
|
-
@complex_label = Stanford::Mods::Record.new.from_str(
|
23
|
-
"<mods>
|
24
|
-
<note>Note Field</note><note>2nd Note Field</note>
|
25
|
-
<note type='statement of responsibility'>SoR</note>
|
26
|
-
<note>Another Note</note>
|
27
|
-
</mods>", false
|
28
|
-
).note
|
29
|
-
end
|
30
|
-
describe 'label' do
|
31
|
-
it 'should have a default label' do
|
32
|
-
expect(mods_display_note(@note).fields.first.label).to eq('Note:')
|
33
|
-
end
|
34
|
-
it 'should use the displayLabel attribute when one is available' do
|
35
|
-
expect(mods_display_note(@display_label).fields.first.label).to eq('Special Label:')
|
36
|
-
end
|
37
|
-
it 'should use get a label from a list of translations' do
|
38
|
-
expect(mods_display_note(@sor_label).fields.first.label).to eq('Statement of responsibility:')
|
39
|
-
end
|
40
|
-
it 'should use use the capitalized type attribute if one is present' do
|
41
|
-
expect(mods_display_note(@type_label).fields.first.label).to eq('Some other type:')
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe 'fields' do
|
46
|
-
it 'should handle single values' do
|
47
|
-
fields = mods_display_note(@note).fields
|
48
|
-
expect(fields.length).to eq(1)
|
49
|
-
expect(fields.first.values).to eq(['Note Field'])
|
50
|
-
end
|
51
|
-
it 'should handle complex grouping' do
|
52
|
-
fields = mods_display_note(@complex_label).fields
|
53
|
-
expect(fields.length).to eq(3)
|
54
|
-
expect(fields.first.label).to eq('Note:')
|
55
|
-
expect(fields.first.values.length).to eq 2
|
56
|
-
expect(fields.first.values).to eq(['Note Field', '2nd Note Field'])
|
57
|
-
|
58
|
-
expect(fields[1].label).to eq 'Statement of responsibility:'
|
59
|
-
expect(fields[1].values.length).to eq 1
|
60
|
-
expect(fields[1].values).to eq(['SoR'])
|
61
|
-
|
62
|
-
expect(fields.last.label).to eq('Note:')
|
63
|
-
expect(fields.last.values.length).to eq 1
|
64
|
-
expect(fields.last.values).to eq(['Another Note'])
|
65
|
-
end
|
66
|
-
it 'should not include any contact fields' do
|
67
|
-
fields = mods_display_note(@contact_note).fields
|
68
|
-
expect(fields.length).to eq(1)
|
69
|
-
expect(fields.first.values).to eq(['Note Field'])
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
def mods_display_item(mods_record)
|
4
|
-
ModsDisplay::RelatedItem.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
|
-
end
|
6
|
-
|
7
|
-
describe ModsDisplay::RelatedItem do
|
8
|
-
include RelatedItemFixtures
|
9
|
-
include NestedRelatedItemFixtures
|
10
|
-
|
11
|
-
before(:all) do
|
12
|
-
@item = Stanford::Mods::Record.new.from_str(basic_related_item_fixture, false).related_item
|
13
|
-
@linked_item = Stanford::Mods::Record.new.from_str(linked_related_item_fixture, false).related_item
|
14
|
-
@collection = Stanford::Mods::Record.new.from_str(related_item_collection_fixture, false).related_item
|
15
|
-
@display_label = Stanford::Mods::Record.new.from_str(related_item_display_label_fixture, false).related_item
|
16
|
-
@location = Stanford::Mods::Record.new.from_str(related_item_location_fixture, false).related_item
|
17
|
-
@reference = Stanford::Mods::Record.new.from_str(related_item_reference_fixture, false).related_item
|
18
|
-
@blank_item = Stanford::Mods::Record.new.from_str(blank_related_item_fixture, false).related_item
|
19
|
-
@multi_items = Stanford::Mods::Record.new.from_str(multi_related_item_fixture, false).related_item
|
20
|
-
@constituent_items = Stanford::Mods::Record.new.from_str(multi_constituent_fixture, false).related_item
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'excludes related items that will be rendered as a nested record' do
|
24
|
-
expect(mods_display_item(@constituent_items).fields).to be_empty
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'label' do
|
28
|
-
it 'should default to Related Item' do
|
29
|
-
expect(mods_display_item(@item).fields.first.label).to eq('Related item:')
|
30
|
-
end
|
31
|
-
it 'should get the location label' do
|
32
|
-
expect(mods_display_item(@location).fields.first.label).to eq('Location:')
|
33
|
-
end
|
34
|
-
it 'should get the reference label' do
|
35
|
-
expect(mods_display_item(@reference).fields.first.label).to eq('Referenced by:')
|
36
|
-
end
|
37
|
-
it 'should get the displayLabel if available' do
|
38
|
-
expect(mods_display_item(@display_label).fields.first.label).to eq('Special Item:')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
describe 'fields' do
|
42
|
-
it 'should get a location if it is available' do
|
43
|
-
fields = mods_display_item(@item).fields
|
44
|
-
expect(fields.length).to eq(1)
|
45
|
-
expect(fields.first.values).to eq(['A Related Item'])
|
46
|
-
end
|
47
|
-
it 'should return a link if there is a location/url present' do
|
48
|
-
fields = mods_display_item(@linked_item).fields
|
49
|
-
expect(fields.length).to eq(1)
|
50
|
-
expect(fields.first.values).to eq(["<a href='http://library.stanford.edu/'>A Related Item</a>"])
|
51
|
-
end
|
52
|
-
it 'should not return any fields if the described related item is a collection' do
|
53
|
-
expect(mods_display_item(@collection).fields).to eq([])
|
54
|
-
end
|
55
|
-
it 'should not return empty links when there is no title or link' do
|
56
|
-
expect(mods_display_item(@blank_item).fields).to eq([])
|
57
|
-
end
|
58
|
-
it 'should concat the isReferencedBy related item title with other metadata' do
|
59
|
-
fields = mods_display_item(@reference).fields
|
60
|
-
expect(fields.length).to eq(1)
|
61
|
-
expect(fields.first.values).to eq(['The title DATE 124'])
|
62
|
-
end
|
63
|
-
it 'should collapse labels down into the same record' do
|
64
|
-
fields = mods_display_item(@multi_items).fields
|
65
|
-
expect(fields.length).to eq(1)
|
66
|
-
expect(fields.first.label).to eq('Related item:')
|
67
|
-
expect(fields.first.values.length).to eq(2)
|
68
|
-
expect(fields.first.values.first).to(match(%r{<a href=.*>Library</a>}))
|
69
|
-
expect(fields.first.values.last).to(match(%r{<a href=.*>SDR</a>}))
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
def mods_display_resource_type(mods_record)
|
4
|
-
ModsDisplay::ResourceType.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
|
-
end
|
6
|
-
|
7
|
-
describe ModsDisplay::ResourceType do
|
8
|
-
before(:all) do
|
9
|
-
@type = Stanford::Mods::Record.new.from_str(
|
10
|
-
'<mods><typeOfResource>Resource Type</typeOfResource></mods>', false
|
11
|
-
).typeOfResource
|
12
|
-
@downcase = Stanford::Mods::Record.new.from_str(
|
13
|
-
'<mods><typeOfResource>resource type</typeOfResource></mods>', false
|
14
|
-
).typeOfResource
|
15
|
-
@display_label = Stanford::Mods::Record.new.from_str(
|
16
|
-
"<mods><typeOfResource displayLabel='Special label'>Resource Type</typeOfResource></mods>", false
|
17
|
-
).typeOfResource
|
18
|
-
end
|
19
|
-
it "should default to a label of 'Type of resource'" do
|
20
|
-
fields = mods_display_resource_type(@type).fields
|
21
|
-
expect(fields.length).to eq(1)
|
22
|
-
expect(fields.first.label).to eq('Type of resource:')
|
23
|
-
end
|
24
|
-
it 'should use the displayLabel attribute when present' do
|
25
|
-
fields = mods_display_resource_type(@display_label).fields
|
26
|
-
expect(fields.length).to eq(1)
|
27
|
-
expect(fields.first.label).to eq('Special label:')
|
28
|
-
end
|
29
|
-
it 'should capitalize the first letter of the values' do
|
30
|
-
fields = mods_display_resource_type(@downcase).fields
|
31
|
-
expect(fields.length).to eq(1)
|
32
|
-
expect(fields.first.values).to eq(['Resource type'])
|
33
|
-
end
|
34
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
def mods_display_sub_title(mods_record)
|
4
|
-
ModsDisplay::SubTitle.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
|
-
end
|
6
|
-
|
7
|
-
describe ModsDisplay::SubTitle do
|
8
|
-
before(:all) do
|
9
|
-
@title = Stanford::Mods::Record.new.from_str(
|
10
|
-
'<mods><titleInfo><title>Main Title</title></titleInfo><titleInfo><title>Sub Title</title></titleInfo></mods>',
|
11
|
-
false
|
12
|
-
).title_info
|
13
|
-
end
|
14
|
-
it 'omit the main title and only return sub titles' do
|
15
|
-
fields = mods_display_sub_title(@title).fields
|
16
|
-
expect(fields.length).to eq(1)
|
17
|
-
expect(fields.first.label).to eq('Title:')
|
18
|
-
expect(fields.first.values).to eq(['Sub Title'])
|
19
|
-
end
|
20
|
-
end
|
data/spec/fields/subject_spec.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fixtures/subjects_fixtures'
|
3
|
-
include SubjectsFixtures
|
4
|
-
|
5
|
-
def mods_display_subject(mods_record)
|
6
|
-
config = ModsDisplay::Configuration::Subject.new do
|
7
|
-
link :link_method, '%value%'
|
8
|
-
end
|
9
|
-
ModsDisplay::Subject.new(mods_record, config, TestController.new)
|
10
|
-
end
|
11
|
-
|
12
|
-
def mods_display_hierarchical_subject(mods_record)
|
13
|
-
config = ModsDisplay::Configuration::Subject.new do
|
14
|
-
hierarchical_link true
|
15
|
-
link :link_method, '%value%'
|
16
|
-
end
|
17
|
-
ModsDisplay::Subject.new(mods_record, config, TestController.new)
|
18
|
-
end
|
19
|
-
|
20
|
-
describe ModsDisplay::Subject do
|
21
|
-
before(:all) do
|
22
|
-
@subject = Stanford::Mods::Record.new.from_str(subjects, false).subject
|
23
|
-
@blank_subject = Stanford::Mods::Record.new.from_str(blank_subject, false).subject
|
24
|
-
@emdash_subject = Stanford::Mods::Record.new.from_str(emdash_subjects, false).subject
|
25
|
-
@geo_subject = Stanford::Mods::Record.new.from_str(hierarchical_geo_subjects, false).subject
|
26
|
-
@name_subject = Stanford::Mods::Record.new.from_str(name_subjects, false).subject
|
27
|
-
@blank_name_subject = Stanford::Mods::Record.new.from_str(blank_name_subject, false).subject
|
28
|
-
@complex_subject = Stanford::Mods::Record.new.from_str(complex_subjects, false).subject
|
29
|
-
@display_label = Stanford::Mods::Record.new.from_str(display_label_subjects, false).subject
|
30
|
-
end
|
31
|
-
describe 'fields' do
|
32
|
-
it 'should split individual child elments of subject into separate parts' do
|
33
|
-
fields = mods_display_subject(@subject).fields
|
34
|
-
expect(fields.length).to eq(1)
|
35
|
-
expect(fields.first.values).to eq([['Jazz', 'Japan', 'History and criticism']])
|
36
|
-
end
|
37
|
-
it 'should split horizontalized subjects split with an emdash into separate parts' do
|
38
|
-
fields = mods_display_subject(@emdash_subject).fields
|
39
|
-
expect(fields.length).to eq(1)
|
40
|
-
expect(fields.first.values).to eq([['Jazz', 'Japan', 'History and criticism']])
|
41
|
-
end
|
42
|
-
it 'should handle hierarchicalGeogaphic subjects properly' do
|
43
|
-
fields = mods_display_subject(@geo_subject).fields
|
44
|
-
expect(fields.length).to eq(1)
|
45
|
-
expect(fields.first.values).to eq([['United States', 'California', 'Stanford']])
|
46
|
-
end
|
47
|
-
it 'should handle display labels properly' do
|
48
|
-
fields = mods_display_subject(@display_label).fields
|
49
|
-
expect(fields.length).to eq(3)
|
50
|
-
expect(fields.first.label).to eq('Subject:')
|
51
|
-
expect(fields.first.values).to eq([['A Subject', 'Another Subject'], ['B Subject', 'Another B Subject']])
|
52
|
-
expect(fields[1].label).to eq('Subject Heading:')
|
53
|
-
expect(fields[1].values).to eq([['Jazz', 'Japan', 'History and criticism']])
|
54
|
-
expect(fields.last.label).to eq('Subject:')
|
55
|
-
expect(fields.last.values).to eq([['Bay Area', 'Stanford']])
|
56
|
-
end
|
57
|
-
it 'should handle blank subjects properly' do
|
58
|
-
expect(mods_display_subject(@blank_subject).fields).to eq([])
|
59
|
-
end
|
60
|
-
it 'should handle blank name subjects properly' do
|
61
|
-
expect(mods_display_subject(@blank_name_subject).fields).to eq([])
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'name subjects' do
|
66
|
-
it 'should handle name subjects properly' do
|
67
|
-
fields = mods_display_subject(@name_subject).fields
|
68
|
-
expect(fields.length).to eq(1)
|
69
|
-
expect(fields.first.values.first.first).to be_a(ModsDisplay::Name::Person)
|
70
|
-
expect(fields.first.values.first.first.name).to eq('John Doe')
|
71
|
-
end
|
72
|
-
it 'should link the name (and not the role) correctly' do
|
73
|
-
html = mods_display_subject(@name_subject).to_html
|
74
|
-
expect(html).to match(%r{<a href='.*\?John Doe'>John Doe</a>})
|
75
|
-
expect(html).to match(%r{<a href='.*\?Anonymous People'>Anonymous People</a>})
|
76
|
-
end
|
77
|
-
it 'should linke the name (and not the role) correctly when linking hierarchicaly' do
|
78
|
-
html = mods_display_hierarchical_subject(@name_subject).to_html
|
79
|
-
expect(html).to match(%r{<a href='.*\?John Doe'>John Doe</a>})
|
80
|
-
expect(html).to match(%r{<a href='.*\?John Doe Anonymous People'>Anonymous People</a>})
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
describe 'to_html' do
|
85
|
-
it 'should link the values when requested' do
|
86
|
-
html = mods_display_subject(@subject).to_html
|
87
|
-
expect(html).to match(%r{<a href='http://library.stanford.edu\?Jazz'>Jazz</a>})
|
88
|
-
expect(html).to match(%r{<a href='http://library.stanford.edu\?Japan'>Japan</a>})
|
89
|
-
expect(html).to match(%r{<a href='http://library.stanford.edu\?History and criticism'>History and criticism</a>})
|
90
|
-
end
|
91
|
-
it 'does something' do
|
92
|
-
html = mods_display_hierarchical_subject(@subject).to_html
|
93
|
-
expect(html).to match(%r{<a href='http://library.stanford.edu\?Jazz'>Jazz</a>})
|
94
|
-
expect(html).to match(%r{<a href='http://library.stanford.edu\?Jazz Japan'>Japan</a>})
|
95
|
-
expect(html).to match(
|
96
|
-
%r{<a href='http://library.stanford.edu\?Jazz Japan History and criticism'>History and criticism</a>}
|
97
|
-
)
|
98
|
-
end
|
99
|
-
it 'should collapse fields into the same label' do
|
100
|
-
html = mods_display_subject(@complex_subject).to_html
|
101
|
-
expect(html.scan(%r{<dt title='Subject'>Subject:</dt>}).length).to eq(1)
|
102
|
-
expect(html.scan(/<dd>/).length).to eq(1)
|
103
|
-
expect(html.scan(%r{<br/>}).length).to eq(1)
|
104
|
-
expect(html.scan(/ > /).length).to eq(3)
|
105
|
-
end
|
106
|
-
it 'should handle complex display labels' do
|
107
|
-
html = mods_display_subject(@display_label).to_html
|
108
|
-
expect(html.scan(%r{<dt title='Subject'>Subject:</dt>}).length).to eq 2
|
109
|
-
expect(html.scan(%r{<dt title='Subject Heading'>Subject Heading:</dt>}).length).to eq 1
|
110
|
-
expect(html.scan(/<dd>/).length).to eq(3)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
data/spec/fields/title_spec.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
def mods_display_title(mods_record)
|
4
|
-
ModsDisplay::Title.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
|
5
|
-
end
|
6
|
-
|
7
|
-
describe ModsDisplay::Title do
|
8
|
-
include TitleFixtures
|
9
|
-
before(:all) do
|
10
|
-
@title = Stanford::Mods::Record.new.from_str(simple_title_fixture, false).title_info
|
11
|
-
@title_parts = Stanford::Mods::Record.new.from_str(title_parts_fixture, false).title_info
|
12
|
-
@reverse_title_parts = Stanford::Mods::Record.new.from_str(reverse_title_parts_fixture, false).title_info
|
13
|
-
@display_label = Stanford::Mods::Record.new.from_str(display_label_fixture, false).title_info
|
14
|
-
@display_form = Stanford::Mods::Record.new.from_str(display_form_fixture, false).title_info
|
15
|
-
@multi_label = Stanford::Mods::Record.new.from_str(multi_label_fixture, false).title_info
|
16
|
-
@alt_title = Stanford::Mods::Record.new.from_str(alt_title_fixture, false).title_info
|
17
|
-
@title_punctuation = Stanford::Mods::Record.new.from_str(title_puncutation_fixture, false).title_info
|
18
|
-
end
|
19
|
-
describe 'labels' do
|
20
|
-
it 'should return a default label of Title if nothing else is available' do
|
21
|
-
expect(mods_display_title(@title).fields.first.label).to eq('Title:')
|
22
|
-
end
|
23
|
-
it 'should return an appropriate label from the type attribute' do
|
24
|
-
expect(mods_display_title(@alt_title).fields.first.label).to eq('Alternative title:')
|
25
|
-
end
|
26
|
-
it 'should return the label held in the displayLabel attribute of the titleInfo element when available' do
|
27
|
-
expect(mods_display_title(@display_label).fields.first.label).to eq('MyTitle:')
|
28
|
-
end
|
29
|
-
it 'should collapse adjacent identical labels' do
|
30
|
-
fields = mods_display_title(@multi_label).fields
|
31
|
-
expect(fields.length).to eq(4)
|
32
|
-
expect(fields[0].label).to eq('Title:')
|
33
|
-
expect(fields[1].label).to eq('Alternative title:')
|
34
|
-
expect(fields[2].label).to eq('Uniform title:')
|
35
|
-
expect(fields[3].label).to eq('Alternative title:')
|
36
|
-
expect(fields[3].values).to eq(['Another Alt Title', 'Yet Another Alt Title'])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
describe 'fields' do
|
40
|
-
it 'should return an array of label/value objects' do
|
41
|
-
values = mods_display_title(@display_label).fields
|
42
|
-
expect(values.length).to eq(1)
|
43
|
-
expect(values.first).to be_a ModsDisplay::Values
|
44
|
-
expect(values.first.label).to eq('MyTitle:')
|
45
|
-
expect(values.first.values).to eq(['Title'])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
describe 'text' do
|
49
|
-
it 'should construct all the elements in titleInfo' do
|
50
|
-
expect(mods_display_title(@title_parts).fields.first.values).to include 'The Title : For. Something. Part 62'
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should use the correct delimiter in the case that a partNumber comes before a partName' do
|
54
|
-
expect(mods_display_title(@reverse_title_parts).fields.first.values).to include(
|
55
|
-
'The Title : For. Part 62, Something'
|
56
|
-
)
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'should use the displayForm when available' do
|
60
|
-
expect(mods_display_title(@display_form).fields.first.values).to include 'The Title of This Item'
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should return the basic text held in a sub element of titleInfo' do
|
64
|
-
expect(mods_display_title(@title).fields.first.values).to include 'Title'
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should not duplicate delimiter punctuation' do
|
68
|
-
values = mods_display_title(@title_punctuation).fields.first.values
|
69
|
-
expect(values.length).to eq 1
|
70
|
-
expect(values.first).not_to include '..'
|
71
|
-
expect(values.first).to eq 'A title that ends in punctuation. 2015'
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module AccessConditionFixtures
|
2
|
-
def simple_access_condition_fixture
|
3
|
-
<<-XML
|
4
|
-
<mods>
|
5
|
-
<accessCondition>Access Condition Note</accessCondition>
|
6
|
-
</mods>
|
7
|
-
XML
|
8
|
-
end
|
9
|
-
|
10
|
-
def restricted_access_fixture
|
11
|
-
<<-XML
|
12
|
-
<mods>
|
13
|
-
<accessCondition type='restrictionOnAccess'>Restrict Access Note1</accessCondition>
|
14
|
-
<accessCondition type='restriction on access'>Restrict Access Note2</accessCondition>
|
15
|
-
</mods>
|
16
|
-
XML
|
17
|
-
end
|
18
|
-
|
19
|
-
def copyright_access_fixture
|
20
|
-
<<-XML
|
21
|
-
<mods>
|
22
|
-
<accessCondition type='copyright'>This is a (c) copyright Note. Single instances of (c) should also be replaced in these notes.</accessCondition>
|
23
|
-
</mods>
|
24
|
-
XML
|
25
|
-
end
|
26
|
-
|
27
|
-
def cc_license_fixture
|
28
|
-
<<-XML
|
29
|
-
<mods>
|
30
|
-
<accessCondition type='license'>CC by-sa: This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License</accessCondition>
|
31
|
-
</mods>
|
32
|
-
XML
|
33
|
-
end
|
34
|
-
|
35
|
-
def odc_license_fixture
|
36
|
-
<<-XML
|
37
|
-
<mods>
|
38
|
-
<accessCondition type='license'>ODC pddl: This work is licensed under a Open Data Commons Public Domain Dedication and License (PDDL)</accessCondition>
|
39
|
-
</mods>
|
40
|
-
XML
|
41
|
-
end
|
42
|
-
|
43
|
-
def no_license_fixture
|
44
|
-
<<-XML
|
45
|
-
<mods>
|
46
|
-
<accessCondition type='license'>Unknown something: This work is licensed under an Unknown License and will not be linked</accessCondition>
|
47
|
-
</mods>
|
48
|
-
XML
|
49
|
-
end
|
50
|
-
|
51
|
-
def garbage_license_fixture
|
52
|
-
<<-XML
|
53
|
-
<mods>
|
54
|
-
<accessCondition type='license'>Unknown garbage that does not look like a license</accessCondition>
|
55
|
-
</mods>
|
56
|
-
XML
|
57
|
-
end
|
58
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module CartographicsFixtures
|
2
|
-
def full_cartographic
|
3
|
-
<<-MODS
|
4
|
-
<mods>
|
5
|
-
<subject>
|
6
|
-
<cartographics>
|
7
|
-
<scale>The scale</scale>
|
8
|
-
<coordinates>the coordinates</coordinates>
|
9
|
-
<projection>the projection</projection>
|
10
|
-
</cartographics>
|
11
|
-
</subject>
|
12
|
-
</mods>
|
13
|
-
MODS
|
14
|
-
end
|
15
|
-
|
16
|
-
def no_scale_cartographic
|
17
|
-
<<-MODS
|
18
|
-
<mods>
|
19
|
-
<subject>
|
20
|
-
<cartographics>
|
21
|
-
<coordinates>the coordinates</coordinates>
|
22
|
-
<projection>the projection</projection>
|
23
|
-
</cartographics>
|
24
|
-
</subject>
|
25
|
-
</mods>
|
26
|
-
MODS
|
27
|
-
end
|
28
|
-
|
29
|
-
def coordinates_only
|
30
|
-
<<-MODS
|
31
|
-
<mods>
|
32
|
-
<subject>
|
33
|
-
<cartographics>
|
34
|
-
<coordinates>the coordinates</coordinates>
|
35
|
-
</cartographics>
|
36
|
-
</subject>
|
37
|
-
</mods>
|
38
|
-
MODS
|
39
|
-
end
|
40
|
-
|
41
|
-
def scale_only
|
42
|
-
<<-MODS
|
43
|
-
<mods>
|
44
|
-
<subject>
|
45
|
-
<cartographics>
|
46
|
-
<scale>The scale</scale>
|
47
|
-
</cartographics>
|
48
|
-
</subject>
|
49
|
-
</mods>
|
50
|
-
MODS
|
51
|
-
end
|
52
|
-
end
|