mods_display 0.10.1 → 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/.rubocop_todo.yml +433 -35
  4. data/README.md +0 -95
  5. data/app/components/mods_display/field_component.html.erb +13 -0
  6. data/app/components/mods_display/field_component.rb +27 -0
  7. data/app/components/mods_display/list_field_component.html.erb +11 -0
  8. data/app/components/mods_display/list_field_component.rb +10 -0
  9. data/app/components/mods_display/record_component.html.erb +5 -0
  10. data/app/components/mods_display/record_component.rb +39 -0
  11. data/app/helpers/mods_display/record_helper.rb +106 -0
  12. data/app/models/mods_display/record.rb +26 -0
  13. data/config/locales/en.yml +1 -1
  14. data/config.ru +9 -0
  15. data/lib/mods_display/engine.rb +13 -0
  16. data/lib/mods_display/fields/access_condition.rb +4 -0
  17. data/lib/mods_display/fields/contents.rb +14 -15
  18. data/lib/mods_display/fields/field.rb +13 -149
  19. data/lib/mods_display/fields/genre.rb +4 -0
  20. data/lib/mods_display/fields/imprint.rb +52 -3
  21. data/lib/mods_display/fields/name.rb +11 -20
  22. data/lib/mods_display/fields/nested_related_item.rb +7 -18
  23. data/lib/mods_display/fields/note.rb +4 -0
  24. data/lib/mods_display/fields/related_item.rb +4 -0
  25. data/lib/mods_display/fields/sub_title.rb +3 -3
  26. data/lib/mods_display/fields/subject.rb +13 -39
  27. data/lib/mods_display/fields/title.rb +4 -0
  28. data/lib/mods_display/fields/values.rb +4 -4
  29. data/lib/mods_display/html.rb +54 -107
  30. data/lib/mods_display/version.rb +1 -1
  31. data/lib/mods_display.rb +2 -23
  32. data/mods_display.gemspec +15 -9
  33. metadata +45 -105
  34. data/.github/workflows/ruby.yml +0 -24
  35. data/.gitignore +0 -21
  36. data/lib/mods_display/configuration/access_condition.rb +0 -21
  37. data/lib/mods_display/configuration/base.rb +0 -34
  38. data/lib/mods_display/configuration/genre.rb +0 -9
  39. data/lib/mods_display/configuration/imprint.rb +0 -13
  40. data/lib/mods_display/configuration/name.rb +0 -9
  41. data/lib/mods_display/configuration/note.rb +0 -9
  42. data/lib/mods_display/configuration/related_item.rb +0 -9
  43. data/lib/mods_display/configuration/subject.rb +0 -13
  44. data/lib/mods_display/configuration/title.rb +0 -9
  45. data/lib/mods_display/configuration.rb +0 -93
  46. data/lib/mods_display/controller_extension.rb +0 -32
  47. data/lib/mods_display/helpers/record_helper.rb +0 -131
  48. data/lib/mods_display/model_extension.rb +0 -22
  49. data/lib/mods_display/railtie.rb +0 -10
  50. data/spec/configuration/access_condition_spec.rb +0 -10
  51. data/spec/configuration/base_spec.rb +0 -39
  52. data/spec/fake_app.rb +0 -18
  53. data/spec/fields/abstract_spec.rb +0 -39
  54. data/spec/fields/access_condition_spec.rb +0 -107
  55. data/spec/fields/audience_spec.rb +0 -24
  56. data/spec/fields/cartographics_spec.rb +0 -38
  57. data/spec/fields/collection_spec.rb +0 -77
  58. data/spec/fields/contact_spec.rb +0 -23
  59. data/spec/fields/contents_spec.rb +0 -39
  60. data/spec/fields/description_spec.rb +0 -55
  61. data/spec/fields/extent_spec.rb +0 -31
  62. data/spec/fields/form_spec.rb +0 -49
  63. data/spec/fields/genre_spec.rb +0 -34
  64. data/spec/fields/geo_spec.rb +0 -40
  65. data/spec/fields/identifier_spec.rb +0 -61
  66. data/spec/fields/imprint_spec.rb +0 -289
  67. data/spec/fields/language_spec.rb +0 -51
  68. data/spec/fields/location_spec.rb +0 -81
  69. data/spec/fields/name_spec.rb +0 -166
  70. data/spec/fields/nested_related_item_spec.rb +0 -89
  71. data/spec/fields/note_spec.rb +0 -72
  72. data/spec/fields/related_item_spec.rb +0 -72
  73. data/spec/fields/resource_type_spec.rb +0 -34
  74. data/spec/fields/sub_title_spec.rb +0 -20
  75. data/spec/fields/subject_spec.rb +0 -113
  76. data/spec/fields/title_spec.rb +0 -82
  77. data/spec/fixtures/access_condition_fixtures.rb +0 -58
  78. data/spec/fixtures/cartographics_fixtures.rb +0 -52
  79. data/spec/fixtures/imprint_fixtures.rb +0 -349
  80. data/spec/fixtures/name_fixtures.rb +0 -398
  81. data/spec/fixtures/nested_realted_items_fixtures.rb +0 -64
  82. data/spec/fixtures/related_item_fixtures.rb +0 -107
  83. data/spec/fixtures/subjects_fixtures.rb +0 -115
  84. data/spec/fixtures/title_fixtures.rb +0 -115
  85. data/spec/helpers/record_helper_spec.rb +0 -241
  86. data/spec/integration/configuration_spec.rb +0 -57
  87. data/spec/integration/html_spec.rb +0 -87
  88. data/spec/integration/installation_spec.rb +0 -26
  89. data/spec/spec_helper.rb +0 -46
  90. data/spec/test_fr.yml +0 -3
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_access_condition(mods_record)
4
- ModsDisplay::AccessCondition.new(
5
- mods_record,
6
- ModsDisplay::Configuration::AccessCondition.new,
7
- double('controller')
8
- )
9
- end
10
-
11
- def mods_display_non_ignore_access_condition(mods_record)
12
- ModsDisplay::AccessCondition.new(
13
- mods_record,
14
- ModsDisplay::Configuration::AccessCondition.new { display! },
15
- double('controller')
16
- )
17
- end
18
-
19
- describe ModsDisplay::AccessCondition do
20
- include AccessConditionFixtures
21
- before :all do
22
- @access_condition = Stanford::Mods::Record.new.from_str(simple_access_condition_fixture, false).accessCondition
23
- @restrict_condition = Stanford::Mods::Record.new.from_str(restricted_access_fixture, false).accessCondition
24
- @copyright_note = Stanford::Mods::Record.new.from_str(copyright_access_fixture, false).accessCondition
25
- @cc_license_note = Stanford::Mods::Record.new.from_str(cc_license_fixture, false).accessCondition
26
- @odc_license_note = Stanford::Mods::Record.new.from_str(odc_license_fixture, false).accessCondition
27
- @no_link_license_note = Stanford::Mods::Record.new.from_str(no_license_fixture, false).accessCondition
28
- @garbage_license_fixture = Stanford::Mods::Record.new.from_str(garbage_license_fixture, false).accessCondition
29
- end
30
- describe 'labels' do
31
- it 'should normalize types and assign proper labels' do
32
- fields = mods_display_access_condition(@restrict_condition).fields
33
- expect(fields.length).to eq(1)
34
- expect(fields.first.label).to eq('Restriction on access:')
35
- fields.first.values.each_with_index do |value, index|
36
- expect(value).to match(/^Restrict Access Note#{index + 1}/)
37
- end
38
- end
39
- end
40
- describe 'fields' do
41
- describe 'copyright' do
42
- it "should replace instances of '(c) copyright' with the HTML copyright entity" do
43
- fields = mods_display_access_condition(@copyright_note).fields
44
- expect(fields.length).to eq(1)
45
- expect(fields.first.values.length).to eq(1)
46
- expect(fields.first.values.first).to eq(
47
- 'This is a © Note. Single instances of © should also be replaced in these notes.'
48
- )
49
- end
50
- end
51
- describe 'licenses' do
52
- it 'should add the appropriate classes to the html around the license' do
53
- fields = mods_display_access_condition(@no_link_license_note).fields
54
- expect(fields.length).to eq(1)
55
- expect(fields.first.values.length).to eq(1)
56
- expect(fields.first.values.first).to match(%r{^<div class='unknown-something'>.*</div>$})
57
- end
58
- it 'should identify and link CreativeCommons licenses properly' do
59
- fields = mods_display_access_condition(@cc_license_note).fields
60
- expect(fields.length).to eq(1)
61
- expect(fields.first.values.length).to eq(1)
62
- expect(fields.first.values.first).to include("<a href='http://creativecommons.org/licenses/by-sa/3.0/'>")
63
- expect(fields.first.values.first).to include(
64
- 'This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License'
65
- )
66
- end
67
- it 'should identify and link OpenDataCommons licenses properly' do
68
- fields = mods_display_access_condition(@odc_license_note).fields
69
- expect(fields.length).to eq(1)
70
- expect(fields.first.values.length).to eq(1)
71
- expect(fields.first.values.first).to include("<a href='http://opendatacommons.org/licenses/pddl/'>")
72
- expect(fields.first.values.first).to include(
73
- 'This work is licensed under a Open Data Commons Public Domain Dedication and License (PDDL)'
74
- )
75
- end
76
-
77
- it 'should not attempt unknown license types' do
78
- fields = mods_display_access_condition(@no_link_license_note).fields
79
- expect(fields.length).to eq(1)
80
- expect(fields.first.values.length).to eq(1)
81
- expect(fields.first.values.first).to include(
82
- 'This work is licensed under an Unknown License and will not be linked'
83
- )
84
- expect(fields.first.values.first).not_to include('<a.*>')
85
- end
86
-
87
- it 'returns the license text if it does not look like our expected format' do
88
- fields = mods_display_access_condition(@garbage_license_fixture).fields
89
- expect(fields.length).to eq(1)
90
- expect(fields.first.values.length).to eq(1)
91
- expect(fields.first.values.first).to include(
92
- 'Unknown garbage that does not look like a license'
93
- )
94
- expect(fields.first.values.first).not_to include('<a.*>')
95
- end
96
- end
97
- end
98
- describe 'to_html' do
99
- it 'should ignore access conditions by default' do
100
- expect(mods_display_access_condition(@access_condition).to_html).to be_nil
101
- end
102
- it 'should not ignore the access condition when ignore is set to false' do
103
- html = mods_display_non_ignore_access_condition(@access_condition).to_html
104
- expect(html).to match %r{<dt.*>Access condition:</dt><dd>Access Condition Note</dd>}
105
- end
106
- end
107
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_audience(mods_record)
4
- ModsDisplay::Audience.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Contents do
8
- before(:all) do
9
- @audience = Stanford::Mods::Record.new.from_str(
10
- '<mods><targetAudience>Audience Note</targetAudience></mods>', false
11
- ).targetAudience
12
- @display_label = Stanford::Mods::Record.new.from_str(
13
- "<mods><targetAudience displayLabel='Special Label'>Audience Note</tableOfContents></mods>", false
14
- ).targetAudience
15
- end
16
- describe 'label' do
17
- it 'should have a default label' do
18
- expect(mods_display_audience(@audience).label).to eq('Target audience:')
19
- end
20
- it 'should use the displayLabel attribute when one is available' do
21
- expect(mods_display_audience(@display_label).label).to eq('Special Label:')
22
- end
23
- end
24
- end
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- require 'fixtures/cartographics_fixtures'
3
- include CartographicsFixtures
4
-
5
- def mods_display_cartographics(mods)
6
- ModsDisplay::Cartographics.new(mods, ModsDisplay::Configuration::Base.new, double('controller'))
7
- end
8
-
9
- describe ModsDisplay::Cartographics do
10
- before(:all) do
11
- @cart = Stanford::Mods::Record.new.from_str(full_cartographic, false).subject
12
- @scale_only = Stanford::Mods::Record.new.from_str(scale_only, false).subject
13
- @no_scale = Stanford::Mods::Record.new.from_str(no_scale_cartographic, false).subject
14
- @coordinates = Stanford::Mods::Record.new.from_str(coordinates_only, false).subject
15
- end
16
- describe 'values' do
17
- it 'should get the full cartographic note' do
18
- values = mods_display_cartographics(@cart).fields
19
- expect(values.length).to eq(1)
20
- expect(values.first.values).to eq(['The scale ; the projection the coordinates'])
21
- end
22
- it 'should put a scale not given note if no scale is present' do
23
- values = mods_display_cartographics(@no_scale).fields
24
- expect(values.length).to eq(1)
25
- expect(values.first.values).to eq(['Scale not given ; the projection the coordinates'])
26
- end
27
- it 'should handle when there is only a scale note' do
28
- values = mods_display_cartographics(@scale_only).fields
29
- expect(values.length).to eq(1)
30
- expect(values.first.values).to eq(['The scale'])
31
- end
32
- it 'should handle when only one post-scale piece of the data is available' do
33
- values = mods_display_cartographics(@coordinates).fields
34
- expect(values.length).to eq(1)
35
- expect(values.first.values).to eq(['Scale not given ; the coordinates'])
36
- end
37
- end
38
- end
@@ -1,77 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_collection(mods_record)
4
- ModsDisplay::Collection.new(
5
- mods_record,
6
- ModsDisplay::Configuration::Base.new,
7
- double('controller')
8
- )
9
- end
10
-
11
- describe ModsDisplay::Collection do
12
- let(:collection) do
13
- Stanford::Mods::Record.new.from_str(
14
- '<mods>
15
- <relatedItem>
16
- <titleInfo><title>The Collection</title></titleInfo><typeOfResource collection="yes" />
17
- </relatedItem>
18
- </mods>',
19
- false
20
- ).related_item
21
- end
22
- let(:non_collection) do
23
- Stanford::Mods::Record.new.from_str(
24
- '<mods><relatedItem><titleInfo><title>Not a Collection</title></titleInfo></relatedItem></mods>',
25
- false
26
- ).related_item
27
- end
28
- let(:display_label) do
29
- Stanford::Mods::Record.new.from_str(
30
- '<mods>
31
- <relatedItem displayLabel="Special Collection">
32
- <titleInfo><title>Not a Collection</title></titleInfo>
33
- </relatedItem>
34
- </mods>',
35
- false
36
- ).related_item
37
- end
38
- let(:multiple_related_items) do
39
- Stanford::Mods::Record.new.from_str(
40
- '<mods>
41
- <relatedItem displayLabel="Special Collection">
42
- <titleInfo><title>Not a Collection</title></titleInfo>
43
- </relatedItem>
44
- <relatedItem>
45
- <titleInfo><title>The Collection</title></titleInfo><typeOfResource collection="yes" />
46
- </relatedItem>
47
- </mods>',
48
- false
49
- ).related_item
50
- end
51
-
52
- describe 'label' do
53
- it 'should default to Collection' do
54
- expect(mods_display_collection(collection).fields.first.label).to eq('Collection:')
55
- end
56
-
57
- it 'should get the displayLabel if available' do
58
- expect(mods_display_collection(display_label).label).to eq('Special Collection:')
59
- end
60
-
61
- it 'should get the proper titles of all items when there is a displayLabel present' do
62
- expect(mods_display_collection(multiple_related_items).fields.first.label).to eq 'Collection:'
63
- end
64
- end
65
-
66
- describe 'fields' do
67
- it 'should get a collection title if there is an appropriate typeOfResource field with the collection attribute' do
68
- fields = mods_display_collection(collection).fields
69
- expect(fields.length).to eq(1)
70
- expect(fields.first.values).to eq(['The Collection'])
71
- end
72
-
73
- it 'should be blank if the there is not an appropriate typeOfResource field with the collection attribute' do
74
- expect(mods_display_collection(non_collection).fields).to eq([])
75
- end
76
- end
77
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_contact(mods_record)
4
- ModsDisplay::Contact.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Contact do
8
- before(:all) do
9
- @contact_note = Stanford::Mods::Record.new.from_str(
10
- "<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false
11
- ).note
12
- end
13
- it 'should only get contact fields' do
14
- fields = mods_display_contact(@contact_note).fields
15
- expect(fields.length).to eq(1)
16
- expect(fields.first.values).to include('jdoe@example.com')
17
- end
18
- it 'should not get any non-contact fields' do
19
- fields = mods_display_contact(@contact_note).fields
20
- expect(fields.length).to eq(1)
21
- expect(fields.first.values).not_to include('Note Field')
22
- end
23
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_contents(mods_record)
4
- ModsDisplay::Contents.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Contents do
8
- before(:all) do
9
- @contents = Stanford::Mods::Record.new.from_str(
10
- '<mods><tableOfContents>Content Note</tableOfContents></mods>', false
11
- ).tableOfContents
12
- @display_label = Stanford::Mods::Record.new.from_str(
13
- "<mods><tableOfContents displayLabel='Special Label'>Content Note</tableOfContents></mods>", false
14
- ).tableOfContents
15
- end
16
- describe 'label' do
17
- it 'should have a default label' do
18
- expect(mods_display_contents(@contents).label).to eq('Table of contents:')
19
- end
20
- it 'should use the displayLabel attribute when one is available' do
21
- expect(mods_display_contents(@display_label).label).to eq('Special Label:')
22
- end
23
- end
24
- context 'multi-valued contents' do
25
- let(:toc) do
26
- Stanford::Mods::Record.new.from_str(
27
- '<mods><tableOfContents>Content Note 1 -- Content Note 2</tableOfContents></mods>', false
28
- ).tableOfContents
29
- end
30
- it 'should have one value with "--" marker' do
31
- mdc = mods_display_contents(toc)
32
- expect(mdc.fields.first.values).to eq ['Content Note 1 -- Content Note 2']
33
- end
34
- it 'should render as a list' do
35
- html = mods_display_contents(toc).to_html
36
- expect(html).to include '<dd><ul><li>Content Note 1</li><li>Content Note 2</li></ul></dd>'
37
- end
38
- end
39
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_description(mods)
4
- ModsDisplay::Description.new(mods, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Description do
8
- before(:all) do
9
- @form = Stanford::Mods::Record.new.from_str(
10
- '<mods><physicalDescription><note>Description Note</note></physicalDescription></mods>', false
11
- ).physical_description
12
- @display_label = Stanford::Mods::Record.new.from_str(
13
- "<mods>
14
- <physicalDescription displayLabel='SpecialLabel'><note>Description Note</note></physicalDescription>
15
- </mods>", false
16
- ).physical_description
17
- @child_display_label = Stanford::Mods::Record.new.from_str(
18
- "<mods><physicalDescription><note displayLabel='Note Label'>Description Note</note></physicalDescription></mods>",
19
- false
20
- ).physical_description
21
- @mixed = Stanford::Mods::Record.new.from_str(
22
- '<mods>
23
- <physicalDescription>
24
- <note>Description Note</note>
25
- <digitalOrigin>Digital Origin Note</digitalOrigin>
26
- </physicalDescription>
27
- </mods>', false
28
- ).physical_description
29
- end
30
- describe 'labels' do
31
- it 'should use the displayLabel if one is provided' do
32
- expect(mods_display_description(@display_label).fields.first.label).to eq('SpecialLabel:')
33
- end
34
- it 'should get the default label for a child element' do
35
- expect(mods_display_description(@form).fields.first.label).to eq('Note:')
36
- end
37
- it 'should get multiple lables for mixed content' do
38
- expect(mods_display_description(@mixed).fields.map(&:label)).to eq(['Note:', 'Digital origin:'])
39
- end
40
- it 'should get the display label from child elements' do
41
- expect(mods_display_description(@child_display_label).fields.map(&:label)).to eq(['Note Label:'])
42
- end
43
- end
44
-
45
- describe 'fields' do
46
- it 'should get the value from a field in physicalDescription' do
47
- expect(mods_display_description(@form).fields.first.values).to eq(['Description Note'])
48
- end
49
- it 'should get multiple values for mixed content' do
50
- expect(mods_display_description(@mixed).fields.map(&:values)).to eq(
51
- [['Description Note'], ['Digital Origin Note']]
52
- )
53
- end
54
- end
55
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ModsDisplay::Extent do
4
- let(:mods) do
5
- <<-XML
6
- <mods>
7
- <physicalDescription>
8
- <extent>Extent Value</extent>
9
- <extent>Extent Value 2</extent>
10
- </physicalDescription>
11
- </mods>
12
- XML
13
- end
14
-
15
- subject do
16
- parsed_mods = Stanford::Mods::Record.new.from_str(mods, false).physical_description
17
- described_class.new(parsed_mods, ModsDisplay::Configuration::Base.new, double('controller')).fields
18
- end
19
-
20
- describe 'label' do
21
- it 'is "Extent"' do
22
- expect(subject.first.label).to eq 'Extent:'
23
- end
24
- end
25
-
26
- describe 'values' do
27
- it 'returns the text of the extent element' do
28
- expect(subject.first.values).to eq ['Extent Value', 'Extent Value 2']
29
- end
30
- end
31
- end
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ModsDisplay::Form do
4
- let(:mods) do
5
- <<-XML
6
- <mods>
7
- <physicalDescription>
8
- <form>Form Value</form>
9
- <form>Form Value 2</form>
10
- </physicalDescription>
11
- </mods>
12
- XML
13
- end
14
-
15
- subject do
16
- parsed_mods = Stanford::Mods::Record.new.from_str(mods, false).physical_description
17
- described_class.new(parsed_mods, ModsDisplay::Configuration::Base.new, double('controller')).fields
18
- end
19
-
20
- describe 'label' do
21
- it 'is "Form"' do
22
- expect(subject.first.label).to eq 'Form:'
23
- end
24
- end
25
-
26
- describe 'values' do
27
- it 'returns the text of the form element' do
28
- expect(subject.first.values).to eq ['Form Value', 'Form Value 2']
29
- end
30
-
31
- context 'duplicated data' do
32
- let(:mods) do
33
- <<-XML
34
- <mods>
35
- <physicalDescription>
36
- <form authority="gmd">electronic resource.</form>
37
- <form authority="zxy">electronicresource!</form>
38
- <form authority="marccategory">electronic Resource</form>
39
- </physicalDescription>
40
- </mods>
41
- XML
42
- end
43
-
44
- it 'uses only unique form values, ignore differences in case, punctuation or whitespace' do
45
- expect(subject.first.values).to match_array ['electronic resource.']
46
- end
47
- end
48
- end
49
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_genre(mods_record)
4
- ModsDisplay::Genre.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Abstract do
8
- before(:all) do
9
- @genre = Stanford::Mods::Record.new.from_str('<mods><genre>Map Data</genre></mods>', false).genre
10
- @downcase = Stanford::Mods::Record.new.from_str('<mods><genre>map data</genre></mods>', false).genre
11
- @display_label = Stanford::Mods::Record.new.from_str(
12
- "<mods><genre displayLabel='Special label'>Catographic</genre></mods>", false
13
- ).genre
14
- end
15
- describe 'labels' do
16
- it "should return a default 'Genre' label" do
17
- fields = mods_display_genre(@genre).fields
18
- expect(fields.length).to eq(1)
19
- expect(fields.first.label).to eq('Genre:')
20
- end
21
- it 'should use a display label when one is available' do
22
- fields = mods_display_genre(@display_label).fields
23
- expect(fields.length).to eq(1)
24
- expect(fields.first.label).to eq('Special label:')
25
- end
26
- end
27
- describe 'fields' do
28
- it 'should capitalize the first letter in a genre' do
29
- fields = mods_display_genre(@downcase).fields
30
- expect(fields.length).to eq(1)
31
- expect(fields.first.values).to eq(['Map data'])
32
- end
33
- end
34
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_geo(mods_record)
4
- ModsDisplay::Geo.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Geo do
8
- let(:mods) do
9
- <<-XML
10
- <mods>
11
- <extension displayLabel="geo">
12
- <rdf:RDF xmlns:gml="http://www.opengis.net/gml/3.2/" xmlns:dc="http://purl.org/dc/elements/1.1/">
13
- <rdf:Description>
14
- <dc:format>image/tiff; format=ArcGRID</dc:format>
15
- <dc:type>Dataset#Raster</dc:type>
16
- </rdf:Description>
17
- </rdf:RDF>
18
- </extension>
19
- </mods>
20
- XML
21
- end
22
-
23
- subject do
24
- mods_display_geo(Stanford::Mods::Record.new.from_str(mods, false).extension).fields
25
- end
26
-
27
- describe 'labels' do
28
- it 'is Format' do
29
- expect(subject.length).to eq(1)
30
- expect(subject.first.label).to eq('Format:')
31
- end
32
- end
33
-
34
- describe 'fields' do
35
- it 'joins the normalized format and type with a semicolon' do
36
- expect(subject.length).to eq(1)
37
- expect(subject.first.values).to eq(['ArcGRID; Raster'])
38
- end
39
- end
40
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_id(mods_record)
4
- ModsDisplay::Identifier.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Note do
8
- before(:all) do
9
- @id = Stanford::Mods::Record.new.from_str('<mods><identifier>12345</identifier></mods>', false).identifier
10
- @display_label = Stanford::Mods::Record.new.from_str(
11
- "<mods><identifier displayLabel='Special Label'>54321</identifier></mods>", false
12
- ).identifier
13
- @issue_label = Stanford::Mods::Record.new.from_str(
14
- "<mods><identifier type='issue number'>Issue 1</identifier></mods>", false
15
- ).identifier
16
- @type_label = Stanford::Mods::Record.new.from_str(
17
- "<mods><identifier type='Some other Type'>98765</identifier></mods>", false
18
- ).identifier
19
- @complex_label = Stanford::Mods::Record.new.from_str(
20
- "<mods>
21
- <identifier>12345</identifier>
22
- <identifier>54321</identifier>
23
- <identifier type='issue number'>12345</identifier>
24
- <identifier>98765</identifier>
25
- </mods>", false
26
- ).identifier
27
- end
28
- describe 'label' do
29
- it 'should have a default label' do
30
- expect(mods_display_id(@id).fields.first.label).to eq('Identifier:')
31
- end
32
- it 'should use the displayLabel attribute when one is available' do
33
- expect(mods_display_id(@display_label).fields.first.label).to eq('Special Label:')
34
- end
35
- it 'should use get a label from a list of translations' do
36
- expect(mods_display_id(@issue_label).fields.first.label).to eq('Issue number:')
37
- end
38
- it 'should use use the raw type attribute if one is present' do
39
- expect(mods_display_id(@type_label).fields.first.label).to eq('Some other Type:')
40
- end
41
- end
42
-
43
- describe 'fields' do
44
- it 'should handle matching adjacent labels' do
45
- fields = mods_display_id(@complex_label).fields
46
- expect(fields.length).to eq(3)
47
-
48
- expect(fields.first.label).to eq('Identifier:')
49
- expect(fields.first.values.length).to eq(2)
50
- expect(fields.first.values).to eq(%w(12345 54321))
51
-
52
- expect(fields[1].label).to eq('Issue number:')
53
- expect(fields[1].values.length).to eq(1)
54
- expect(fields[1].values).to eq(['12345'])
55
-
56
- expect(fields.last.label).to eq('Identifier:')
57
- expect(fields.last.values.length).to eq(1)
58
- expect(fields.last.values).to eq(['98765'])
59
- end
60
- end
61
- end