mods_display 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +16 -0
  3. data/.rubocop_todo.yml +60 -0
  4. data/.travis.yml +2 -2
  5. data/Rakefile +10 -2
  6. data/lib/mods_display.rb +42 -42
  7. data/lib/mods_display/configuration.rb +69 -67
  8. data/lib/mods_display/configuration/access_condition.rb +17 -13
  9. data/lib/mods_display/configuration/base.rb +27 -24
  10. data/lib/mods_display/configuration/format.rb +8 -4
  11. data/lib/mods_display/configuration/genre.rb +8 -4
  12. data/lib/mods_display/configuration/imprint.rb +12 -7
  13. data/lib/mods_display/configuration/name.rb +8 -4
  14. data/lib/mods_display/configuration/note.rb +8 -4
  15. data/lib/mods_display/configuration/related_item.rb +8 -4
  16. data/lib/mods_display/configuration/subject.rb +11 -9
  17. data/lib/mods_display/configuration/title.rb +8 -4
  18. data/lib/mods_display/controller_extension.rb +24 -24
  19. data/lib/mods_display/country_codes.rb +385 -384
  20. data/lib/mods_display/fields/abstract.rb +7 -6
  21. data/lib/mods_display/fields/access_condition.rb +55 -55
  22. data/lib/mods_display/fields/audience.rb +7 -6
  23. data/lib/mods_display/fields/cartographics.rb +15 -14
  24. data/lib/mods_display/fields/collection.rb +32 -17
  25. data/lib/mods_display/fields/contact.rb +15 -13
  26. data/lib/mods_display/fields/contents.rb +7 -6
  27. data/lib/mods_display/fields/description.rb +21 -21
  28. data/lib/mods_display/fields/field.rb +164 -109
  29. data/lib/mods_display/fields/format.rb +36 -33
  30. data/lib/mods_display/fields/genre.rb +12 -11
  31. data/lib/mods_display/fields/identifier.rb +34 -34
  32. data/lib/mods_display/fields/imprint.rb +258 -214
  33. data/lib/mods_display/fields/language.rb +18 -16
  34. data/lib/mods_display/fields/location.rb +27 -26
  35. data/lib/mods_display/fields/name.rb +113 -118
  36. data/lib/mods_display/fields/note.rb +33 -34
  37. data/lib/mods_display/fields/related_item.rb +64 -66
  38. data/lib/mods_display/fields/resource_type.rb +13 -11
  39. data/lib/mods_display/fields/sub_title.rb +6 -4
  40. data/lib/mods_display/fields/subject.rb +92 -90
  41. data/lib/mods_display/fields/title.rb +54 -49
  42. data/lib/mods_display/fields/values.rb +7 -8
  43. data/lib/mods_display/html.rb +117 -96
  44. data/lib/mods_display/model_extension.rb +17 -16
  45. data/lib/mods_display/relator_codes.rb +269 -267
  46. data/lib/mods_display/version.rb +1 -1
  47. data/mods_display.gemspec +13 -12
  48. data/spec/configuration/access_condition_spec.rb +5 -5
  49. data/spec/configuration/base_spec.rb +24 -24
  50. data/spec/fields/abstract_spec.rb +24 -14
  51. data/spec/fields/access_condition_spec.rb +80 -55
  52. data/spec/fields/audience_spec.rb +15 -12
  53. data/spec/fields/cartographics_spec.rb +17 -18
  54. data/spec/fields/collection_spec.rb +65 -19
  55. data/spec/fields/contact_spec.rb +11 -9
  56. data/spec/fields/contents_spec.rb +15 -12
  57. data/spec/fields/description_spec.rb +40 -22
  58. data/spec/fields/format_spec.rb +28 -18
  59. data/spec/fields/genre_spec.rb +18 -16
  60. data/spec/fields/identifier_spec.rb +46 -34
  61. data/spec/fields/imprint_spec.rb +151 -125
  62. data/spec/fields/language_spec.rb +36 -20
  63. data/spec/fields/location_spec.rb +43 -27
  64. data/spec/fields/name_spec.rb +92 -92
  65. data/spec/fields/note_spec.rb +53 -40
  66. data/spec/fields/related_item_spec.rb +42 -40
  67. data/spec/fields/resource_type_spec.rb +20 -14
  68. data/spec/fields/sub_title_spec.rb +11 -9
  69. data/spec/fields/subject_spec.rb +61 -56
  70. data/spec/fields/title_spec.rb +53 -40
  71. data/spec/fixtures/access_condition_fixtures.rb +50 -0
  72. data/spec/fixtures/cartographics_fixtures.rb +1 -1
  73. data/spec/fixtures/imprint_fixtures.rb +49 -1
  74. data/spec/fixtures/name_fixtures.rb +195 -2
  75. data/spec/fixtures/related_item_fixtures.rb +107 -0
  76. data/spec/fixtures/subjects_fixtures.rb +15 -2
  77. data/spec/fixtures/title_fixtures.rb +101 -0
  78. data/spec/integration/configuration_spec.rb +23 -20
  79. data/spec/integration/html_spec.rb +40 -29
  80. data/spec/integration/installation_spec.rb +14 -14
  81. data/spec/spec_helper.rb +5 -8
  82. metadata +25 -3
@@ -1,21 +1,23 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  def mods_display_contact(mods_record)
4
- ModsDisplay::Contact.new(mods_record, ModsDisplay::Configuration::Base.new, double("controller"))
4
+ ModsDisplay::Contact.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
5
  end
6
6
 
7
7
  describe ModsDisplay::Contact do
8
8
  before(:all) do
9
- @contact_note = Stanford::Mods::Record.new.from_str("<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false).note
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
10
12
  end
11
- it "should only get contact fields" do
13
+ it 'should only get contact fields' do
12
14
  fields = mods_display_contact(@contact_note).fields
13
- fields.length.should == 1
14
- fields.first.values.should include("jdoe@example.com")
15
+ expect(fields.length).to eq(1)
16
+ expect(fields.first.values).to include('jdoe@example.com')
15
17
  end
16
- it "should not get any non-contact fields" do
18
+ it 'should not get any non-contact fields' do
17
19
  fields = mods_display_contact(@contact_note).fields
18
- fields.length.should == 1
19
- fields.first.values.should_not include("Note Field")
20
+ expect(fields.length).to eq(1)
21
+ expect(fields.first.values).not_to include('Note Field')
20
22
  end
21
23
  end
@@ -1,21 +1,24 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  def mods_display_contents(mods_record)
4
- ModsDisplay::Contents.new(mods_record, ModsDisplay::Configuration::Base.new, double("controller"))
4
+ ModsDisplay::Contents.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
5
  end
6
6
 
7
7
  describe ModsDisplay::Contents do
8
8
  before(:all) do
9
- @contents = Stanford::Mods::Record.new.from_str("<mods><tableOfContents>Content Note</tableOfContents></mods>", false).tableOfContents
10
- @display_label = Stanford::Mods::Record.new.from_str("<mods><tableOfContents displayLabel='Special Label'>Content Note</tableOfContents></mods>", false).tableOfContents
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
11
15
  end
12
- describe "label" do
13
- it "should have a default label" do
14
- mods_display_contents(@contents).label.should == "Table of contents:"
16
+ describe 'label' do
17
+ it 'should have a default label' do
18
+ expect(mods_display_contents(@contents).label).to eq('Table of contents:')
15
19
  end
16
- it "should use the displayLabel attribute when one is available" do
17
- mods_display_contents(@display_label).label.should == "Special Label:"
20
+ it 'should use the displayLabel attribute when one is available' do
21
+ expect(mods_display_contents(@display_label).label).to eq('Special Label:')
18
22
  end
19
- end
20
-
21
- end
23
+ end
24
+ end
@@ -1,37 +1,55 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  def mods_display_description(mods)
4
- ModsDisplay::Description.new(mods, ModsDisplay::Configuration::Base.new, double("controller"))
4
+ ModsDisplay::Description.new(mods, ModsDisplay::Configuration::Base.new, double('controller'))
5
5
  end
6
6
 
7
7
  describe ModsDisplay::Description do
8
8
  before(:all) do
9
- @form = Stanford::Mods::Record.new.from_str("<mods><physicalDescription><note>Description Note</note></physicalDescription></mods>", false).physical_description
10
- @display_label = Stanford::Mods::Record.new.from_str("<mods><physicalDescription displayLabel='SpecialLabel'><note>Description Note</note></physicalDescription></mods>", false).physical_description
11
- @child_display_label = Stanford::Mods::Record.new.from_str("<mods><physicalDescription><note displayLabel='Note Label'>Description Note</note></physicalDescription></mods>", false).physical_description
12
- @mixed = Stanford::Mods::Record.new.from_str("<mods><physicalDescription><note>Description Note</note><digitalOrigin>Digital Origin Note</digitalOrigin></physicalDescription></mods>", false).physical_description
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
13
29
  end
14
- describe "labels" do
15
- it "should use the displayLabel if one is provided" do
16
- mods_display_description(@display_label).fields.first.label.should == "SpecialLabel:"
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:')
17
33
  end
18
- it "should get the default label for a child element" do
19
- mods_display_description(@form).fields.first.label.should == "Note:"
34
+ it 'should get the default label for a child element' do
35
+ expect(mods_display_description(@form).fields.first.label).to eq('Note:')
20
36
  end
21
- it "should get multiple lables for mixed content" do
22
- mods_display_description(@mixed).fields.map{|v| v.label }.should == ["Note:", "Digital origin:"]
37
+ it 'should get multiple lables for mixed content' do
38
+ expect(mods_display_description(@mixed).fields.map(&:label)).to eq(['Note:', 'Digital origin:'])
23
39
  end
24
- it "should get the display label from child elements" do
25
- mods_display_description(@child_display_label).fields.map{|f| f.label }.should == ["Note Label:"]
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:'])
26
42
  end
27
43
  end
28
-
29
- describe "fields" do
30
- it "should get the value from a field in physicalDescription" do
31
- mods_display_description(@form).fields.first.values.should == ["Description Note"]
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'])
32
48
  end
33
- it "should get multiple values for mixed content" do
34
- mods_display_description(@mixed).fields.map{|v| v.values }.should == [["Description Note"], ["Digital Origin Note"]]
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
+ )
35
53
  end
36
54
  end
37
- end
55
+ end
@@ -1,31 +1,41 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
  def mods_display_format(mods)
3
- ModsDisplay::Format.new(mods, ModsDisplay::Configuration::Base.new, double("controller"))
3
+ ModsDisplay::Format.new(mods, ModsDisplay::Configuration::Base.new, double('controller'))
4
4
  end
5
5
 
6
6
  describe ModsDisplay::Format do
7
7
  before(:all) do
8
- @format = Stanford::Mods::Record.new.from_str("<mods><typeOfResource>Format</typeOfResource></mods>", false).typeOfResource
9
- @duplicate_forms = Stanford::Mods::Record.new.from_str("<mods><physicalDescription><form>Map</form><form>Map</form></physicalDescription></mods>", false)
10
- @display_label = Stanford::Mods::Record.new.from_str("<mods><typeOfResource displayLabel='SpecialFormat'>Mixed Materials</typeOfResource></mods>", false).typeOfResource
11
- @space_format = Stanford::Mods::Record.new.from_str("<mods><typeOfResource>Mixed Materials</typeOfResource></mods>", false).typeOfResource
12
- @slash_format = Stanford::Mods::Record.new.from_str("<mods><typeOfResource>Manuscript/Archive</typeOfResource></mods>", false).typeOfResource
8
+ @format = Stanford::Mods::Record.new.from_str(
9
+ '<mods><typeOfResource>Format</typeOfResource></mods>', false
10
+ ).typeOfResource
11
+ @duplicate_forms = Stanford::Mods::Record.new.from_str(
12
+ '<mods><physicalDescription><form>Map</form><form>Map</form></physicalDescription></mods>', false
13
+ )
14
+ @display_label = Stanford::Mods::Record.new.from_str(
15
+ "<mods><typeOfResource displayLabel='SpecialFormat'>Mixed Materials</typeOfResource></mods>", false
16
+ ).typeOfResource
17
+ @space_format = Stanford::Mods::Record.new.from_str(
18
+ '<mods><typeOfResource>Mixed Materials</typeOfResource></mods>', false
19
+ ).typeOfResource
20
+ @slash_format = Stanford::Mods::Record.new.from_str(
21
+ '<mods><typeOfResource>Manuscript/Archive</typeOfResource></mods>', false
22
+ ).typeOfResource
13
23
  end
14
- describe "format_class" do
15
- it "should remove any spaces" do
16
- ModsDisplay::Format.send(:format_class, "Mixed Materials").should == "mixed_materials"
24
+ describe 'format_class' do
25
+ it 'should remove any spaces' do
26
+ expect(ModsDisplay::Format.send(:format_class, 'Mixed Materials')).to eq('mixed_materials')
17
27
  end
18
- it "should replace any slashes" do
19
- ModsDisplay::Format.send(:format_class, "Manuscript/Archive").should == "manuscript_archive"
28
+ it 'should replace any slashes' do
29
+ expect(ModsDisplay::Format.send(:format_class, 'Manuscript/Archive')).to eq('manuscript_archive')
20
30
  end
21
31
  end
22
- describe "fields" do
23
- describe "form" do
24
- it "should remove duplicate values" do
32
+ describe 'fields' do
33
+ describe 'form' do
34
+ it 'should remove duplicate values' do
25
35
  fields = mods_display_format(@duplicate_forms).fields
26
- fields.length.should == 1
27
- fields.first.values.should == ["Map"]
36
+ expect(fields.length).to eq(1)
37
+ expect(fields.first.values).to eq(['Map'])
28
38
  end
29
39
  end
30
40
  end
31
- end
41
+ end
@@ -1,32 +1,34 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  def mods_display_genre(mods_record)
4
- ModsDisplay::Genre.new(mods_record, ModsDisplay::Configuration::Base.new, double("controller"))
4
+ ModsDisplay::Genre.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
5
  end
6
6
 
7
7
  describe ModsDisplay::Abstract do
8
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("<mods><genre displayLabel='Special label'>Catographic</genre></mods>", false).genre
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
12
14
  end
13
- describe "labels" do
15
+ describe 'labels' do
14
16
  it "should return a default 'Genre' label" do
15
17
  fields = mods_display_genre(@genre).fields
16
- fields.length.should == 1
17
- fields.first.label.should == "Genre:"
18
+ expect(fields.length).to eq(1)
19
+ expect(fields.first.label).to eq('Genre:')
18
20
  end
19
- it "should use a display label when one is available" do
21
+ it 'should use a display label when one is available' do
20
22
  fields = mods_display_genre(@display_label).fields
21
- fields.length.should == 1
22
- fields.first.label.should == "Special label:"
23
+ expect(fields.length).to eq(1)
24
+ expect(fields.first.label).to eq('Special label:')
23
25
  end
24
26
  end
25
- describe "fields" do
26
- it "should capitalize the first letter in a genre" do
27
+ describe 'fields' do
28
+ it 'should capitalize the first letter in a genre' do
27
29
  fields = mods_display_genre(@downcase).fields
28
- fields.length.should == 1
29
- fields.first.values.should == ["Map data"]
30
+ expect(fields.length).to eq(1)
31
+ expect(fields.first.values).to eq(['Map data'])
30
32
  end
31
33
  end
32
- end
34
+ end
@@ -1,49 +1,61 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  def mods_display_id(mods_record)
4
- ModsDisplay::Identifier.new(mods_record, ModsDisplay::Configuration::Base.new, double("controller"))
4
+ ModsDisplay::Identifier.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
5
  end
6
6
 
7
7
  describe ModsDisplay::Note do
8
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("<mods><identifier displayLabel='Special Label'>54321</identifier></mods>", false).identifier
11
- @issue_label = Stanford::Mods::Record.new.from_str("<mods><identifier type='issue number'>Issue 1</identifier></mods>", false).identifier
12
- @type_label = Stanford::Mods::Record.new.from_str("<mods><identifier type='Some other Type'>98765</identifier></mods>", false).identifier
13
- @complex_label = Stanford::Mods::Record.new.from_str("<mods><identifier>12345</identifier><identifier>54321</identifier><identifier type='issue number'>12345</identifier><identifier>98765</identifier></mods>", false).identifier
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
14
27
  end
15
- describe "label" do
16
- it "should have a default label" do
17
- mods_display_id(@id).fields.first.label.should == "Identifier:"
28
+ describe 'label' do
29
+ it 'should have a default label' do
30
+ expect(mods_display_id(@id).fields.first.label).to eq('Identifier:')
18
31
  end
19
- it "should use the displayLabel attribute when one is available" do
20
- mods_display_id(@display_label).fields.first.label.should == "Special Label:"
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:')
21
34
  end
22
- it "should use get a label from a list of translations" do
23
- mods_display_id(@issue_label).fields.first.label.should == "Issue number:"
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:')
24
37
  end
25
- it "should use use the raw type attribute if one is present" do
26
- mods_display_id(@type_label).fields.first.label.should == "Some other Type:"
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:')
27
40
  end
28
41
  end
29
-
30
- describe "fields" do
31
- it "should handle matching adjacent labels" do
42
+
43
+ describe 'fields' do
44
+ it 'should handle matching adjacent labels' do
32
45
  fields = mods_display_id(@complex_label).fields
33
- fields.length.should == 3
34
-
35
- fields.first.label.should == "Identifier:"
36
- fields.first.values.length.should == 2
37
- fields.first.values.should == ["12345", "54321"]
38
-
39
- fields[1].label.should == "Issue number:"
40
- fields[1].values.length.should == 1
41
- fields[1].values.should == ["12345"]
42
-
43
- fields.last.label.should == "Identifier:"
44
- fields.last.values.length.should == 1
45
- fields.last.values.should == ["98765"]
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'])
46
59
  end
47
60
  end
48
-
49
- end
61
+ end
@@ -1,13 +1,21 @@
1
- require "spec_helper"
2
- require "fixtures/imprint_fixtures"
1
+ require 'spec_helper'
2
+ require 'fixtures/imprint_fixtures'
3
3
 
4
4
  include ImprintFixtures
5
5
 
6
6
  def mods_display_imprint(mods_record)
7
- ModsDisplay::Imprint.new(mods_record, ModsDisplay::Configuration::Imprint.new, double("controller"))
7
+ ModsDisplay::Imprint.new(mods_record, ModsDisplay::Configuration::Imprint.new, double('controller'))
8
8
  end
9
+
9
10
  def mods_display_format_date_imprint(mods_record)
10
- ModsDisplay::Imprint.new(mods_record, ModsDisplay::Configuration::Imprint.new{full_date_format "(%Y) %B, %d"; short_date_format "%B (%Y)"}, double("controller"))
11
+ ModsDisplay::Imprint.new(
12
+ mods_record,
13
+ ModsDisplay::Configuration::Imprint.new do
14
+ full_date_format('(%Y) %B, %d')
15
+ short_date_format('%B (%Y)')
16
+ end,
17
+ double('controller')
18
+ )
11
19
  end
12
20
 
13
21
  describe ModsDisplay::Imprint do
@@ -37,209 +45,227 @@ describe ModsDisplay::Imprint do
37
45
  @encoded_dates = Stanford::Mods::Record.new.from_str(encoded_dates, false).origin_info
38
46
  @bad_dates = Stanford::Mods::Record.new.from_str(bad_dates, false).origin_info
39
47
  @invalid_dates = Stanford::Mods::Record.new.from_str(invalid_dates, false).origin_info
48
+ @punctuation_imprint = Stanford::Mods::Record.new.from_str(punctuation_imprint_fixture, false).origin_info
49
+ @bc_ad_dates = Stanford::Mods::Record.new.from_str(bc_ad_imprint_date_fixture, false).origin_info
40
50
  end
41
51
 
42
- describe "labels" do
43
- it "should get the Imprint label by default" do
44
- mods_display_imprint(@imprint).fields.first.label.should == "Imprint:"
52
+ describe 'labels' do
53
+ it 'should get the Imprint label by default' do
54
+ expect(mods_display_imprint(@imprint).fields.first.label).to eq('Imprint:')
45
55
  end
46
- it "should get the label from non-imprint origin info fields" do
56
+ it 'should get the label from non-imprint origin info fields' do
47
57
  fields = mods_display_imprint(@edition_and_date).fields
48
- fields.first.label.should == "Date valid:"
49
- fields.last.label.should == "Issuance:"
58
+ expect(fields.first.label).to eq('Date valid:')
59
+ expect(fields.last.label).to eq('Issuance:')
50
60
  end
51
- it "should get multiple labels when we have mixed content" do
52
- mods_display_imprint(@mixed).fields.map{|val| val.label }.should == ["Imprint:", "Date captured:", "Issuance:"]
61
+ it 'should get multiple labels when we have mixed content' do
62
+ expect(mods_display_imprint(@mixed).fields.map(&:label)).to eq(['Imprint:', 'Date captured:', 'Issuance:'])
53
63
  end
54
- it "should use the displayLabel when available" do
55
- mods_display_imprint(@display_label).fields.map{|val| val.label }.should == ["TheLabel:", "IssuanceLabel:"]
64
+ it 'should use the displayLabel when available' do
65
+ expect(mods_display_imprint(@display_label).fields.map(&:label)).to eq(['TheLabel:', 'IssuanceLabel:'])
56
66
  end
57
67
  end
58
68
 
59
- describe "fields" do
60
- it "should return various parts of the imprint" do
61
- mods_display_imprint(@imprint).fields.map{|val| val.values }.join(" ").should == "An edition - A Place : A Publisher, An Issue Date, Another Date"
69
+ describe 'fields' do
70
+ it 'should return various parts of the imprint' do
71
+ expect(mods_display_imprint(@imprint).fields.map(&:values).join(' ')).to eq(
72
+ 'An edition - A Place : A Publisher, An Issue Date, Another Date'
73
+ )
62
74
  end
63
- it "should handle the punctuation when the edition is missing" do
64
- values = mods_display_imprint(@no_edition).fields.map{|val| val.values }.join(" ")
65
- values.strip.should_not match(/^-/)
66
- values.should match(/^A Place/)
75
+ it 'should handle the punctuation when the edition is missing' do
76
+ values = mods_display_imprint(@no_edition).fields.map(&:values).join(' ')
77
+ expect(values.strip).not_to match(/^-/)
78
+ expect(values).to match(/^A Place/)
67
79
  end
68
- it "should get the text for non-imprint origin info fields" do
80
+ it 'should get the text for non-imprint origin info fields' do
69
81
  fields = mods_display_imprint(@edition_and_date).fields
70
- fields.first.values.should == ["A Valid Date"]
71
- fields.last.values.should == ["The Issuance"]
82
+ expect(fields.first.values).to eq(['A Valid Date'])
83
+ expect(fields.last.values).to eq(['The Issuance'])
72
84
  end
73
- it "should handle mixed mods properly" do
85
+ it 'should handle mixed mods properly' do
74
86
  values = mods_display_imprint(@mixed).fields
75
- values.length.should == 3
76
- values.map{|val| val.values}.should include(["A Place : A Publisher"])
77
- values.map{|val| val.values}.should include(["The Issuance"])
78
- values.map{|val| val.values}.should include(["The Capture Date"])
87
+ expect(values.length).to eq(3)
88
+ expect(values.map(&:values)).to include(['A Place : A Publisher'])
89
+ expect(values.map(&:values)).to include(['The Issuance'])
90
+ expect(values.map(&:values)).to include(['The Capture Date'])
79
91
  end
80
92
  end
81
- describe "date processing" do
82
- describe "ranges" do
93
+ describe 'date processing' do
94
+ describe 'ranges' do
83
95
  it "should join start and end point ranges with a '-'" do
84
96
  fields = mods_display_imprint(@date_range).fields
85
- fields.length.should == 1
86
- fields.first.values.should == ["1820-1825"]
97
+ expect(fields.length).to eq(1)
98
+ expect(fields.first.values).to eq(['1820-1825'])
87
99
  end
88
- it "should handle open ranges properly" do
100
+ it 'should handle open ranges properly' do
89
101
  fields = mods_display_imprint(@open_date_range).fields
90
- fields.length.should == 1
91
- fields.first.values.should == ["1820-"]
102
+ expect(fields.length).to eq(1)
103
+ expect(fields.first.values).to eq(['1820-'])
92
104
  end
93
- it "should handle when there are more than 3 of the same date w/i a range" do
105
+ it 'should handle when there are more than 3 of the same date w/i a range' do
94
106
  fields = mods_display_imprint(@three_imprint_dates).fields
95
- fields.length.should == 1
96
- fields.first.values.should == ["[1820-1825?]"]
107
+ expect(fields.length).to eq(1)
108
+ expect(fields.first.values).to eq(['[1820-1825?]'])
97
109
  end
98
- it "should apply the qualifier decoration in the imprints" do
110
+ it 'should apply the qualifier decoration in the imprints' do
99
111
  fields = mods_display_imprint(@qualified_imprint_date).fields
100
- fields.length.should == 1
101
- fields.first.values.should == ["[1820?]"]
112
+ expect(fields.length).to eq(1)
113
+ expect(fields.first.values).to eq(['[1820?]'])
102
114
  end
103
- it "should handle date ranges in imprints" do
115
+ it 'should handle date ranges in imprints' do
104
116
  fields = mods_display_imprint(@imprint_date_range).fields
105
- fields.length.should == 1
106
- fields.first.values.should == ["1820-1825"]
117
+ expect(fields.length).to eq(1)
118
+ expect(fields.first.values).to eq(['1820-1825'])
107
119
  end
108
- it "should handle encoded dates properly" do
120
+ it 'should handle encoded dates properly' do
109
121
  fields = mods_display_imprint(@encoded_date_range).fields
110
- fields.length.should eq 1
111
- fields.first.values.should eq ["February 01, 2008-December 02, 2009"]
122
+ expect(fields.length).to eq 1
123
+ expect(fields.first.values).to eq ['February 01, 2008-December 02, 2009']
124
+ end
125
+
126
+ it 'should handle B.C. and A.D. dates appropriately' do
127
+ fields = mods_display_imprint(@bc_ad_dates).fields
128
+ expect(fields.length).to eq 1
129
+ expect(fields.first.values).to eq ['12 B.C.-44 A.D.']
112
130
  end
113
131
  end
114
- describe "duplication" do
115
- it "should only return the qualified date when present" do
132
+ describe 'duplication' do
133
+ it 'should only return the qualified date when present' do
116
134
  fields = mods_display_imprint(@dup_qualified_date).fields
117
- fields.length.should == 1
118
- fields.first.values.should == ["[1820?]"]
135
+ expect(fields.length).to eq(1)
136
+ expect(fields.first.values).to eq(['[1820?]'])
119
137
  end
120
- it "should use the non-encoded date when prsent" do
138
+ it 'should use the non-encoded date when prsent' do
121
139
  fields = mods_display_imprint(@dup_unencoded_date).fields
122
- fields.length.should == 1
123
- fields.first.values.should == ["[ca. 1820]"]
140
+ expect(fields.length).to eq(1)
141
+ expect(fields.first.values).to eq(['[ca. 1820]'])
124
142
  end
125
- it "should handle copyright dates correctly" do
143
+ it 'should handle copyright dates correctly' do
126
144
  fields = mods_display_imprint(@dup_copyright_date).fields
127
- fields.length.should == 1
128
- fields.first.values.should == ["c1820"]
145
+ expect(fields.length).to eq(1)
146
+ expect(fields.first.values).to eq(['c1820'])
129
147
  end
130
- it "should only return one when no attributes are present" do
148
+ it 'should only return one when no attributes are present' do
131
149
  fields = mods_display_imprint(@dup_date).fields
132
- fields.length.should == 1
133
- fields.first.values.should == ["1820"]
150
+ expect(fields.length).to eq(1)
151
+ expect(fields.first.values).to eq(['1820'])
134
152
  end
135
153
  end
136
- describe "qualifier decoration" do
154
+ describe 'qualifier decoration' do
137
155
  it "should prepend a 'c' to approximate dates" do
138
156
  fields = mods_display_imprint(@approximate_date).fields
139
- fields.length.should == 1
140
- fields.first.values.should == ["[ca. 1820]"]
157
+ expect(fields.length).to eq(1)
158
+ expect(fields.first.values).to eq(['[ca. 1820]'])
141
159
  end
142
160
  it "should append a '?' to a questionable dates and wrap them in square-brackets" do
143
161
  fields = mods_display_imprint(@questionable_date).fields
144
- fields.length.should == 1
145
- fields.first.values.should == ["[1820?]"]
162
+ expect(fields.length).to eq(1)
163
+ expect(fields.first.values).to eq(['[1820?]'])
146
164
  end
147
- it "should wrap inferred dates in square-brackets" do
165
+ it 'should wrap inferred dates in square-brackets' do
148
166
  fields = mods_display_imprint(@inferred_date).fields
149
- fields.length.should == 1
150
- fields.first.values.should == ["[1820]"]
167
+ expect(fields.length).to eq(1)
168
+ expect(fields.first.values).to eq(['[1820]'])
151
169
  end
152
170
  end
153
- describe "encoded dates" do
154
- describe "W3CDTF" do
155
- it "should handle single year dates properly" do
171
+ describe 'encoded dates' do
172
+ describe 'W3CDTF' do
173
+ it 'should handle single year dates properly' do
156
174
  fields = mods_display_imprint(@encoded_dates).fields
157
- fields.length.should == 4
158
- fields.find do |field|
159
- field.label == "Imprint:"
160
- end.values.should == ["2013"]
175
+ expect(fields.length).to eq(4)
176
+ expect(fields.find do |field|
177
+ field.label == 'Imprint:'
178
+ end.values).to eq(['2013'])
161
179
  end
162
- it "should handle month+year dates properly" do
180
+ it 'should handle month+year dates properly' do
163
181
  fields = mods_display_imprint(@encoded_dates).fields
164
- fields.length.should == 4
165
- fields.find do |field|
166
- field.label == "Date captured:"
167
- end.values.should == ["July 2013"]
182
+ expect(fields.length).to eq(4)
183
+ expect(fields.find do |field|
184
+ field.label == 'Date captured:'
185
+ end.values).to eq(['July 2013'])
168
186
  end
169
- it "should handle full dates properly" do
187
+ it 'should handle full dates properly' do
170
188
  fields = mods_display_imprint(@encoded_dates).fields
171
- fields.length.should == 4
172
- fields.find do |field|
173
- field.label == "Date created:"
174
- end.values.should == ["July 10, 2013"]
189
+ expect(fields.length).to eq(4)
190
+ expect(fields.find do |field|
191
+ field.label == 'Date created:'
192
+ end.values).to eq(['July 10, 2013'])
175
193
  end
176
194
  it "should not try to handle dates we can't parse" do
177
195
  fields = mods_display_imprint(@encoded_dates).fields
178
- fields.length.should == 4
179
- fields.find do |field|
180
- field.label == "Date modified:"
181
- end.values.should == ["Jul. 22, 2013"]
196
+ expect(fields.length).to eq(4)
197
+ expect(fields.find do |field|
198
+ field.label == 'Date modified:'
199
+ end.values).to eq(['Jul. 22, 2013'])
182
200
  end
183
- it "should accept date configurations" do
201
+ it 'should accept date configurations' do
184
202
  fields = mods_display_format_date_imprint(@encoded_dates).fields
185
- fields.length.should == 4
186
- fields.find do |field|
187
- field.label == "Date created:"
188
- end.values.should == ["(2013) July, 10"]
189
- fields.find do |field|
190
- field.label == "Date captured:"
191
- end.values.should == ["July (2013)"]
203
+ expect(fields.length).to eq(4)
204
+ expect(fields.find do |field|
205
+ field.label == 'Date created:'
206
+ end.values).to eq(['(2013) July, 10'])
207
+ expect(fields.find do |field|
208
+ field.label == 'Date captured:'
209
+ end.values).to eq(['July (2013)'])
192
210
  end
193
211
  end
194
212
  end
195
- describe "bad dates" do
196
- it "should ignore date values" do
213
+ describe 'bad dates' do
214
+ it 'should ignore date values' do
197
215
  fields = mods_display_imprint(@bad_dates).fields
198
- fields.length.should == 2
216
+ expect(fields.length).to eq(2)
199
217
  fields.each do |field|
200
- field.values.join.should_not include "9999"
218
+ expect(field.values.join).not_to include '9999'
201
219
  end
202
220
  end
203
- it "should handle invalid dates by returning the original value" do
221
+ it 'should handle invalid dates by returning the original value' do
204
222
  fields = mods_display_imprint(@invalid_dates).fields
205
- fields.length.should == 2
206
- fields.last.values.should == ["1920-09-00"]
223
+ expect(fields.length).to eq(2)
224
+ expect(fields.last.values).to eq(['1920-09-00'])
207
225
  end
208
226
  end
209
227
  end
210
- describe "place processing" do
211
- it "should exclude encoded places" do
228
+
229
+ describe 'punctuation' do
230
+ it 'should not duplicate punctuation' do
231
+ fields = mods_display_imprint(@punctuation_imprint).fields
232
+ expect(fields.length).to eq 1
233
+ expect(fields.first.values).to eq ['San Francisco : Chronicle Books, 2015.']
234
+ end
235
+ end
236
+
237
+ describe 'place processing' do
238
+ it 'should exclude encoded places' do
212
239
  fields = mods_display_imprint(@encoded_place).fields
213
- fields.length.should == 1
214
- fields.first.values.should == ["[Amsterdam]", "[United States]", "Netherlands"]
240
+ expect(fields.length).to eq(1)
241
+ expect(fields.first.values).to eq(['[Amsterdam]', '[United States]', 'Netherlands'])
215
242
  end
216
243
  it "should translate encoded place if there isn't a text (or non-typed) value available" do
217
244
  fields = mods_display_imprint(@encoded_place).fields
218
- fields.length.should == 1
219
- fields.first.values.should include "Netherlands"
245
+ expect(fields.length).to eq(1)
246
+ expect(fields.first.values).to include 'Netherlands'
220
247
  end
221
248
  it "should ignore 'xx' country codes" do
222
249
  fields = mods_display_imprint(@xx_country_code).fields
223
- fields.length.should == 1
224
- fields.first.values.should == ["1994"]
250
+ expect(fields.length).to eq(1)
251
+ expect(fields.first.values).to eq(['1994'])
225
252
  end
226
253
  end
227
- describe "to_html" do
228
- it "should return the display form if one is available" do
254
+ describe 'to_html' do
255
+ it 'should return the display form if one is available' do
229
256
  html = mods_display_imprint(@display_form).to_html
230
- html.scan(/<dd>/).length.should == 2
231
- html.scan(/<dd>The Display Form<\/dd>/).length.should == 2
257
+ expect(html.scan(/<dd>/).length).to eq(2)
258
+ expect(html.scan(%r{<dd>The Display Form</dd>}).length).to eq(2)
232
259
  end
233
260
  it "should return the displayLabel when present if we're using the displayForm" do
234
- mods_display_imprint(@display_form_with_label).to_html.should match(/<dt title='TheLabel'>TheLabel:<\/dt>/)
261
+ expect(mods_display_imprint(@display_form_with_label).to_html).to match(%r{<dt title='TheLabel'>TheLabel:</dt>})
235
262
  end
236
- it "should have individual dt/dd pairs for mixed content" do
263
+ it 'should have individual dt/dd pairs for mixed content' do
237
264
  html = mods_display_imprint(@mixed).to_html
238
- html.scan(/<dt title='Imprint'>Imprint:<\/dt>/).length.should == 1
239
- html.scan(/<dt title='Issuance'>Issuance:<\/dt>/).length.should == 1
240
- html.scan(/<dt title='Date captured'>Date captured:<\/dt>/).length.should == 1
241
- html.scan(/<dd>/).length.should == 3
265
+ expect(html.scan(%r{<dt title='Imprint'>Imprint:</dt>}).length).to eq(1)
266
+ expect(html.scan(%r{<dt title='Issuance'>Issuance:</dt>}).length).to eq(1)
267
+ expect(html.scan(%r{<dt title='Date captured'>Date captured:</dt>}).length).to eq(1)
268
+ expect(html.scan(/<dd>/).length).to eq(3)
242
269
  end
243
270
  end
244
-
245
- end
271
+ end