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.
Files changed (92) 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/location.rb +1 -1
  22. data/lib/mods_display/fields/name.rb +11 -20
  23. data/lib/mods_display/fields/nested_related_item.rb +7 -18
  24. data/lib/mods_display/fields/note.rb +4 -0
  25. data/lib/mods_display/fields/related_item.rb +4 -0
  26. data/lib/mods_display/fields/resource_type.rb +1 -1
  27. data/lib/mods_display/fields/sub_title.rb +3 -3
  28. data/lib/mods_display/fields/subject.rb +13 -39
  29. data/lib/mods_display/fields/title.rb +43 -32
  30. data/lib/mods_display/fields/values.rb +4 -4
  31. data/lib/mods_display/html.rb +55 -106
  32. data/lib/mods_display/version.rb +1 -1
  33. data/lib/mods_display.rb +2 -17
  34. data/mods_display.gemspec +15 -9
  35. metadata +45 -105
  36. data/.github/workflows/ruby.yml +0 -24
  37. data/.gitignore +0 -21
  38. data/lib/mods_display/configuration/access_condition.rb +0 -21
  39. data/lib/mods_display/configuration/base.rb +0 -34
  40. data/lib/mods_display/configuration/genre.rb +0 -9
  41. data/lib/mods_display/configuration/imprint.rb +0 -13
  42. data/lib/mods_display/configuration/name.rb +0 -9
  43. data/lib/mods_display/configuration/note.rb +0 -9
  44. data/lib/mods_display/configuration/related_item.rb +0 -9
  45. data/lib/mods_display/configuration/subject.rb +0 -13
  46. data/lib/mods_display/configuration/title.rb +0 -9
  47. data/lib/mods_display/configuration.rb +0 -93
  48. data/lib/mods_display/controller_extension.rb +0 -32
  49. data/lib/mods_display/helpers/record_helper.rb +0 -131
  50. data/lib/mods_display/model_extension.rb +0 -22
  51. data/lib/mods_display/railtie.rb +0 -10
  52. data/spec/configuration/access_condition_spec.rb +0 -10
  53. data/spec/configuration/base_spec.rb +0 -39
  54. data/spec/fake_app.rb +0 -18
  55. data/spec/fields/abstract_spec.rb +0 -39
  56. data/spec/fields/access_condition_spec.rb +0 -107
  57. data/spec/fields/audience_spec.rb +0 -24
  58. data/spec/fields/cartographics_spec.rb +0 -38
  59. data/spec/fields/collection_spec.rb +0 -77
  60. data/spec/fields/contact_spec.rb +0 -23
  61. data/spec/fields/contents_spec.rb +0 -39
  62. data/spec/fields/description_spec.rb +0 -55
  63. data/spec/fields/extent_spec.rb +0 -31
  64. data/spec/fields/form_spec.rb +0 -49
  65. data/spec/fields/genre_spec.rb +0 -34
  66. data/spec/fields/geo_spec.rb +0 -40
  67. data/spec/fields/identifier_spec.rb +0 -61
  68. data/spec/fields/imprint_spec.rb +0 -289
  69. data/spec/fields/language_spec.rb +0 -51
  70. data/spec/fields/location_spec.rb +0 -81
  71. data/spec/fields/name_spec.rb +0 -166
  72. data/spec/fields/nested_related_item_spec.rb +0 -89
  73. data/spec/fields/note_spec.rb +0 -72
  74. data/spec/fields/related_item_spec.rb +0 -72
  75. data/spec/fields/resource_type_spec.rb +0 -34
  76. data/spec/fields/sub_title_spec.rb +0 -20
  77. data/spec/fields/subject_spec.rb +0 -113
  78. data/spec/fields/title_spec.rb +0 -74
  79. data/spec/fixtures/access_condition_fixtures.rb +0 -58
  80. data/spec/fixtures/cartographics_fixtures.rb +0 -52
  81. data/spec/fixtures/imprint_fixtures.rb +0 -349
  82. data/spec/fixtures/name_fixtures.rb +0 -398
  83. data/spec/fixtures/nested_realted_items_fixtures.rb +0 -64
  84. data/spec/fixtures/related_item_fixtures.rb +0 -107
  85. data/spec/fixtures/subjects_fixtures.rb +0 -115
  86. data/spec/fixtures/title_fixtures.rb +0 -101
  87. data/spec/helpers/record_helper_spec.rb +0 -241
  88. data/spec/integration/configuration_spec.rb +0 -57
  89. data/spec/integration/html_spec.rb +0 -87
  90. data/spec/integration/installation_spec.rb +0 -26
  91. data/spec/spec_helper.rb +0 -46
  92. data/spec/test_fr.yml +0 -3
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ModsDisplay::Configuration::AccessCondition do
4
- it 'should default ignore? to true' do
5
- expect(ModsDisplay::Configuration::AccessCondition.new.ignore?).to be true
6
- end
7
- it 'should set ignore? to false when the display! configuration is set' do
8
- expect(ModsDisplay::Configuration::AccessCondition.new { display! }.ignore?).to be false
9
- end
10
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ModsDisplay::Configuration::Base do
4
- it 'should set config options w/ a block' do
5
- config = ModsDisplay::Configuration::Base.new do
6
- label_class 'testing_label_class'
7
- value_class 'testing_value_class'
8
- end
9
- expect(config.label_class).to eq('testing_label_class')
10
- expect(config.value_class).to eq('testing_value_class')
11
- end
12
- describe 'link' do
13
- it 'should return an array with a method name and params' do
14
- expect(ModsDisplay::Configuration::Base.new do
15
- link :my_url_generating_method, q: '"%value%"'
16
- end.link).to eq([:my_url_generating_method, { q: '"%value%"' }])
17
- end
18
- end
19
- describe 'delmiter' do
20
- it 'should override the default delimiter' do
21
- expect(ModsDisplay::Configuration::Base.new do
22
- delimiter '<br/>'
23
- end.delimiter).to eq('<br/>')
24
- end
25
- it "should default to ', '" do
26
- expect(ModsDisplay::Configuration::Base.new.delimiter).to eq(', ')
27
- end
28
- end
29
- describe 'ignore' do
30
- it 'should be set to true if the #ignore! method is called' do
31
- expect(ModsDisplay::Configuration::Base.new do
32
- ignore!
33
- end.ignore?).to be true
34
- end
35
- it 'should be false by default' do
36
- expect(ModsDisplay::Configuration::Base.new.ignore?).to be false
37
- end
38
- end
39
- end
data/spec/fake_app.rb DELETED
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'action_controller/railtie'
4
- require 'action_view/railtie'
5
-
6
- class ModsDisplayTestApp < Rails::Application
7
- end
8
-
9
- Rails.application.routes.draw do
10
- resources 'searches', only: :index
11
- end
12
-
13
- class ApplicationController < ActionController::Base; end
14
- class SearchesController < ApplicationController
15
- def index; end
16
- end
17
-
18
- Object.const_set(:ApplicationHelper, Module.new)
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
-
3
- def mods_display_abstract(mods_record)
4
- ModsDisplay::Abstract.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
- end
6
-
7
- describe ModsDisplay::Abstract do
8
- before(:all) do
9
- @link = Stanford::Mods::Record.new.from_str(
10
- '<mods><abstract>A link to the library (http://library.stanford.edu) should appear here</abstract></mods>', false
11
- ).abstract
12
- @email = Stanford::Mods::Record.new.from_str(
13
- '<mods><abstract>A link to an email address jdoe@example.com should appear here</abstract></mods>', false
14
- ).abstract
15
- end
16
-
17
- describe 'labels' do
18
- it "should get a default 'Abstract' label" do
19
- fields = mods_display_abstract(@link).fields
20
- expect(fields.length).to eq(1)
21
- expect(fields.first.label).to eq('Abstract:')
22
- end
23
- end
24
-
25
- describe 'links' do
26
- it 'should turn URLs into links' do
27
- expect(mods_display_abstract(@link).to_html).to match(/A link to the library \(<a href/)
28
- expect(mods_display_abstract(@link).to_html).to match(
29
- %r{\(<a href='http://library.stanford.edu'>http://library.stanford.edu</a>\)}
30
- )
31
- expect(mods_display_abstract(@link).to_html).to match(%r{</a>\) should appear here})
32
- end
33
- it 'should turn email addresses into mailto links' do
34
- expect(mods_display_abstract(@email).to_html).to match(
35
- %r{A link to an email address <a href='mailto:jdoe@example.com'>jdoe@example.com</a> should appear here}
36
- )
37
- end
38
- end
39
- end
@@ -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 &copy; Note. Single instances of &copy; 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