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,35 +1,51 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  def mods_display_language(mods_record)
4
- ModsDisplay::Language.new(mods_record, ModsDisplay::Configuration::Base.new, double("controller"))
4
+ ModsDisplay::Language.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
5
5
  end
6
6
 
7
7
  describe ModsDisplay::Language do
8
8
  before(:all) do
9
- @language = Stanford::Mods::Record.new.from_str("<mods><language><languageTerm type='code'>eng</languageTerm></language></mods>", false).language
10
- @display_label = Stanford::Mods::Record.new.from_str("<mods><language displayLabel='Lang'><languageTerm type='code'>eng</languageTerm></language></mods>", false).language
11
- @no_lang = Stanford::Mods::Record.new.from_str("<mods><language displayLabel='Lang'><languageTerm type='code'>zzzxxx</languageTerm></language></mods>", false).language
12
- @mixed = Stanford::Mods::Record.new.from_str("<mods><language><languageTerm type='text'>ger</languageTerm><languageTerm type='code'>eng</languageTerm></language></mods>", false).language
13
- @multi = Stanford::Mods::Record.new.from_str("<mods><language><languageTerm type='code'>ger</languageTerm><languageTerm type='code'>eng</languageTerm></language></mods>", false).language
14
- @display_form = Stanford::Mods::Record.new.from_str("<mods><language><languageTerm>zzzxxx</languageTerm><displayForm>Klingon</displayForm></language></mods>", false).language
9
+ @language = Stanford::Mods::Record.new.from_str(
10
+ "<mods><language><languageTerm type='code'>eng</languageTerm></language></mods>", false
11
+ ).language
12
+ @display_label = Stanford::Mods::Record.new.from_str(
13
+ "<mods><language displayLabel='Lang'><languageTerm type='code'>eng</languageTerm></language></mods>", false
14
+ ).language
15
+ @no_lang = Stanford::Mods::Record.new.from_str(
16
+ "<mods><language displayLabel='Lang'><languageTerm type='code'>zzzxxx</languageTerm></language></mods>", false
17
+ ).language
18
+ @mixed = Stanford::Mods::Record.new.from_str(
19
+ "<mods>
20
+ <language><languageTerm type='text'>ger</languageTerm><languageTerm type='code'>eng</languageTerm></language>
21
+ </mods>", false
22
+ ).language
23
+ @multi = Stanford::Mods::Record.new.from_str(
24
+ "<mods>
25
+ <language><languageTerm type='code'>ger</languageTerm><languageTerm type='code'>eng</languageTerm></language>
26
+ </mods>", false
27
+ ).language
28
+ @display_form = Stanford::Mods::Record.new.from_str(
29
+ '<mods><language><languageTerm>zzzxxx</languageTerm><displayForm>Klingon</displayForm></language></mods>', false
30
+ ).language
15
31
  end
16
- describe "fields" do
17
- it "should return an array with a label/values object" do
32
+ describe 'fields' do
33
+ it 'should return an array with a label/values object' do
18
34
  values = mods_display_language(@display_label).fields
19
- values.length.should == 1
20
- values.first.should be_a ModsDisplay::Values
21
- values.first.label.should == "Lang:"
22
- values.first.values.should == ["English"]
35
+ expect(values.length).to eq(1)
36
+ expect(values.first).to be_a ModsDisplay::Values
37
+ expect(values.first.label).to eq('Lang:')
38
+ expect(values.first.values).to eq(['English'])
23
39
  end
24
40
  it "should not return any non type='code' languageTerms from the XML" do
25
41
  values = mods_display_language(@mixed).fields
26
- values.length.should == 1
27
- values.first.values.should == ["English"]
42
+ expect(values.length).to eq(1)
43
+ expect(values.first.values).to eq(['English'])
28
44
  end
29
- it "should handle multiple languages correctly" do
45
+ it 'should handle multiple languages correctly' do
30
46
  values = mods_display_language(@multi).fields
31
- values.length.should == 1
32
- values.first.values.should == ["German", "English"]
47
+ expect(values.length).to eq(1)
48
+ expect(values.first.values).to eq(%w(German English))
33
49
  end
34
50
  end
35
- end
51
+ end
@@ -1,44 +1,60 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  def mods_display_location(mods_record)
4
- ModsDisplay::Location.new(mods_record, ModsDisplay::Configuration::Base.new, double("controller"))
4
+ ModsDisplay::Location.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
- @location = Stanford::Mods::Record.new.from_str("<mods><location><physicalLocation>The Location</physicalLocation></location></mods>", false).location
10
- @urls = Stanford::Mods::Record.new.from_str("<mods><location><url displayLabel='Stanford University Library'>http://library.stanford.edu</url></location><location displayLabel='PURL'><url>http://purl.stanford.edu</url></location></mods>", false).location
11
- @display_label = Stanford::Mods::Record.new.from_str("<mods><location displayLabel='Special Label'><shelfLocation>On Shelf A</shelfLocation></location></mods>", false).location
12
- @repository_label = Stanford::Mods::Record.new.from_str("<mods><location><physicalLocation type='repository'>Location Field</physicalLocation></location></mods>", false).location
9
+ @location = Stanford::Mods::Record.new.from_str(
10
+ '<mods><location><physicalLocation>The Location</physicalLocation></location></mods>', false
11
+ ).location
12
+ @urls = Stanford::Mods::Record.new.from_str(
13
+ "<mods>
14
+ <location>
15
+ <url displayLabel='Stanford University Library'>http://library.stanford.edu</url>
16
+ </location>
17
+ <location displayLabel='PURL'>
18
+ <url>http://purl.stanford.edu</url>
19
+ </location>
20
+ </mods>",
21
+ false
22
+ ).location
23
+ @display_label = Stanford::Mods::Record.new.from_str(
24
+ "<mods><location displayLabel='Special Label'><shelfLocation>On Shelf A</shelfLocation></location></mods>", false
25
+ ).location
26
+ @repository_label = Stanford::Mods::Record.new.from_str(
27
+ "<mods><location><physicalLocation type='repository'>Location Field</physicalLocation></location></mods>", false
28
+ ).location
13
29
  end
14
- describe "label" do
15
- it "should have a default label" do
16
- mods_display_location(@location).fields.first.label.should == "Location:"
30
+ describe 'label' do
31
+ it 'should have a default label' do
32
+ expect(mods_display_location(@location).fields.first.label).to eq('Location:')
17
33
  end
18
- it "should use the displayLabel attribute when one is available" do
19
- mods_display_location(@display_label).fields.first.label.should == "Special Label:"
34
+ it 'should use the displayLabel attribute when one is available' do
35
+ expect(mods_display_location(@display_label).fields.first.label).to eq('Special Label:')
20
36
  end
21
- it "should handle the URL labels correctly" do
22
- mods_display_location(@urls).fields.map{|f| f.label}.should == ["Location:", "PURL:"]
37
+ it 'should handle the URL labels correctly' do
38
+ expect(mods_display_location(@urls).fields.map(&:label)).to eq(['Location:', 'PURL:'])
23
39
  end
24
- it "should use get a label from a list of translations" do
25
- mods_display_location(@repository_label).fields.first.label.should == "Repository:"
40
+ it 'should use get a label from a list of translations' do
41
+ expect(mods_display_location(@repository_label).fields.first.label).to eq('Repository:')
26
42
  end
27
- end
28
- describe "fields" do
29
- describe "URLs" do
30
- it "should link and use the displayLabel as text" do
43
+ end
44
+ describe 'fields' do
45
+ describe 'URLs' do
46
+ it 'should link and use the displayLabel as text' do
31
47
  fields = mods_display_location(@urls).fields
32
- fields.length.should == 2
33
- field = fields.find{|f| f.label == "Location:"}
34
- field.values.should == ["<a href='http://library.stanford.edu'>Stanford University Library</a>"]
48
+ expect(fields.length).to eq(2)
49
+ field = fields.find { |f| f.label == 'Location:' }
50
+ expect(field.values).to eq(["<a href='http://library.stanford.edu'>Stanford University Library</a>"])
35
51
  end
36
- it "should link the URL itself in the absence of a displayLabel on the url element" do
52
+ it 'should link the URL itself in the absence of a displayLabel on the url element' do
37
53
  fields = mods_display_location(@urls).fields
38
- fields.length.should == 2
39
- field = fields.find{|f| f.label == "PURL:"}
40
- field.values.should == ["<a href='http://purl.stanford.edu'>http://purl.stanford.edu</a>"]
54
+ expect(fields.length).to eq(2)
55
+ field = fields.find { |f| f.label == 'PURL:' }
56
+ expect(field.values).to eq(["<a href='http://purl.stanford.edu'>http://purl.stanford.edu</a>"])
41
57
  end
42
58
  end
43
59
  end
44
- end
60
+ end
@@ -1,5 +1,5 @@
1
- require "spec_helper"
2
- require "fixtures/name_fixtures"
1
+ require 'spec_helper'
2
+ require 'fixtures/name_fixtures'
3
3
  include NameFixtures
4
4
 
5
5
  def mods_display_name_link(mods_record)
@@ -10,140 +10,140 @@ def mods_display_name_link(mods_record)
10
10
  end
11
11
 
12
12
  def mods_display_name(mods_record)
13
- ModsDisplay::Name.new(mods_record, ModsDisplay::Configuration::Base.new, double("controller"))
13
+ ModsDisplay::Name.new(mods_record, ModsDisplay::Configuration::Base.new, double('controller'))
14
14
  end
15
15
 
16
16
  describe ModsDisplay::Language do
17
+ include NameFixtures
17
18
  before(:all) do
18
- @name = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name></mods>", false).plain_name
19
- @blank_name = Stanford::Mods::Record.new.from_str("<mods><name><namePart/><role><roleTerm></roleTerm></role></name></mods>", false).plain_name
20
- @primary_name = Stanford::Mods::Record.new.from_str("<mods><name usage='primary'><namePart>John Doe</namePart><role><roleTerm>lithographer</roleTerm></role></name></mods>", false).plain_name
21
- @contributor = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm>lithographer</roleTerm></role></name></mods>", false).plain_name
22
- @encoded_role = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm type='code' authority='marcrelator'>ltg</roleTerm></role></name></mods>", false).plain_name
23
- @mixed_role = Stanford::Mods::Record.new.from_str("<mods><name><role><roleTerm>publisher</roleTerm></role><namePart>John Doe</namePart><role><roleTerm type='text' authority='marcrelator'>engraver</roleTerm></role></name></mods>", false).plain_name
24
- @numeral_toa = Stanford::Mods::Record.new.from_str("<mods><name><namePart>Unqualfieid</namePart><namePart type='termsOfAddress'>XVII, ToA</namePart><namePart type='date'>date1-date2</namePart><namePart type='given'>Given Name</namePart><namePart type='family'>Family Name</namePart></name></mods>", false).plain_name
25
- @simple_toa = Stanford::Mods::Record.new.from_str("<mods><name><namePart>Unqualfieid</namePart><namePart type='termsOfAddress'>Ier, empereur</namePart><namePart type='date'>date1-date2</namePart><namePart type='given'>Given Name</namePart><namePart type='family'>Family Name</namePart></name></mods>", false).plain_name
26
- @display_form = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><displayForm>Mr. John Doe</displayForm></name></mods>", false).plain_name
27
- @collapse_label = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name><name><namePart>Jane Doe</namePart></name></mods>", false).plain_name
28
- @complex_labels = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name><name><namePart>Jane Doe</namePart><role><roleTerm>lithographer</roleTerm></role></name><name><namePart>John Dough</namePart></name><name><namePart>Jane Dough</namePart></name></mods>", false).plain_name
29
- @complex_roles = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm type='text'>Depicted</roleTerm><roleTerm type='code'>dpt</roleTerm></role></name></mods>", false).plain_name
30
- @name_with_role = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm type='text'>Depicted</roleTerm></role></name></mods>", false).plain_name
31
- @multiple_roles = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><role><roleTerm type='text'>Depicted</roleTerm></role><role><roleTerm type='text'>Artist</roleTerm></role></name></mods>", false).plain_name
19
+ @name = Stanford::Mods::Record.new.from_str(simple_name_fixture, false).plain_name
20
+ @blank_name = Stanford::Mods::Record.new.from_str(blank_name_fixture, false).plain_name
21
+ @primary_name = Stanford::Mods::Record.new.from_str(primary_name_fixture, false).plain_name
22
+ @contributor = Stanford::Mods::Record.new.from_str(contributor_fixture, false).plain_name
23
+ @encoded_role = Stanford::Mods::Record.new.from_str(encoded_role_fixture, false).plain_name
24
+ @mixed_role = Stanford::Mods::Record.new.from_str(mixed_role_fixture, false).plain_name
25
+ @numeral_toa = Stanford::Mods::Record.new.from_str(numural_toa_fixture, false).plain_name
26
+ @simple_toa = Stanford::Mods::Record.new.from_str(simple_toa_fixture, false).plain_name
27
+ @display_form = Stanford::Mods::Record.new.from_str(display_form_name_fixture, false).plain_name
28
+ @collapse_label = Stanford::Mods::Record.new.from_str(collapse_label_name_fixture, false).plain_name
29
+ @complex_labels = Stanford::Mods::Record.new.from_str(complex_name_label_fixture, false).plain_name
30
+ @complex_roles = Stanford::Mods::Record.new.from_str(complex_role_name_fixture, false).plain_name
31
+ @name_with_role = Stanford::Mods::Record.new.from_str(name_with_role_fixture, false).plain_name
32
+ @multiple_roles = Stanford::Mods::Record.new.from_str(multiple_roles_fixture, false).plain_name
32
33
  end
33
- describe "label" do
34
- it "should default Author/Creator when no role is available" do
35
- mods_display_name(@name).fields.first.label.should == "Author/Creator:"
34
+ describe 'label' do
35
+ it 'should default Author/Creator when no role is available' do
36
+ expect(mods_display_name(@name).fields.first.label).to eq('Author/Creator:')
36
37
  end
37
38
  it "should label 'Author/Creator' for primary authors" do
38
- mods_display_name(@primary_name).fields.first.label.should == "Author/Creator:"
39
+ expect(mods_display_name(@primary_name).fields.first.label).to eq('Author/Creator:')
39
40
  end
40
- it "should apply contributor labeling to all non blank/author/creator roles" do
41
- mods_display_name(@contributor).fields.first.label.should == "Contributor:"
41
+ it 'should apply contributor labeling to all non blank/author/creator roles' do
42
+ expect(mods_display_name(@contributor).fields.first.label).to eq('Contributor:')
42
43
  end
43
44
  end
44
-
45
- describe "fields" do
46
- it "should use the display form when available" do
45
+
46
+ describe 'fields' do
47
+ it 'should use the display form when available' do
47
48
  fields = mods_display_name(@display_form).fields
48
- fields.length.should == 1
49
- fields.first.values.length.should == 1
50
- fields.first.values.first.should be_a(ModsDisplay::Name::Person)
51
- fields.first.values.first.name.should == "Mr. John Doe"
49
+ expect(fields.length).to eq(1)
50
+ expect(fields.first.values.length).to eq(1)
51
+ expect(fields.first.values.first).to be_a(ModsDisplay::Name::Person)
52
+ expect(fields.first.values.first.name).to eq('Mr. John Doe')
52
53
  end
53
- it "should not add blank names" do
54
- mods_display_name(@blank_name).fields.should == []
54
+ it 'should not add blank names' do
55
+ expect(mods_display_name(@blank_name).fields).to eq([])
55
56
  end
56
- it "should not delimit given name and termsOfAddress (that begin w/ roman numerals) with a comma" do
57
+ it 'should not delimit given name and termsOfAddress (that begin w/ roman numerals) with a comma' do
57
58
  fields = mods_display_name(@numeral_toa).fields
58
- fields.length.should == 1
59
- fields.first.values.length.should == 1
60
- fields.first.values.first.to_s.should_not match /Given Name, XVII/
61
- fields.first.values.first.to_s.should match /Given Name XVII/
59
+ expect(fields.length).to eq(1)
60
+ expect(fields.first.values.length).to eq(1)
61
+ expect(fields.first.values.first.to_s).not_to match(/Given Name, XVII/)
62
+ expect(fields.first.values.first.to_s).to match(/Given Name XVII/)
62
63
  end
63
- it "should delimit given name and termsOfAddress (that DO NOT begin w/ roman numerals) with a comma" do
64
+ it 'should delimit given name and termsOfAddress (that DO NOT begin w/ roman numerals) with a comma' do
64
65
  fields = mods_display_name(@simple_toa).fields
65
- fields.length.should == 1
66
- fields.first.values.length.should == 1
67
- fields.first.values.first.to_s.should match /Given Name, Ier, empereur/
68
- fields.first.values.first.to_s.should_not match /Given Name Ier, empereur/
66
+ expect(fields.length).to eq(1)
67
+ expect(fields.first.values.length).to eq(1)
68
+ expect(fields.first.values.first.to_s).to match(/Given Name, Ier, empereur/)
69
+ expect(fields.first.values.first.to_s).not_to match(/Given Name Ier, empereur/)
69
70
  end
70
- it "should collapse adjacent matching labels" do
71
+ it 'should collapse adjacent matching labels' do
71
72
  fields = mods_display_name(@collapse_label).fields
72
- fields.length.should == 1
73
- fields.first.label.should == "Author/Creator:"
73
+ expect(fields.length).to eq(1)
74
+ expect(fields.first.label).to eq('Author/Creator:')
74
75
  fields.first.values.each do |val|
75
- ["John Doe", "Jane Doe"].should include val.to_s
76
+ expect(['John Doe', 'Jane Doe']).to include val.to_s
76
77
  end
77
78
  end
78
- it "should perseve order and separation of non-adjesent matching labels" do
79
+ it 'should perseve order and separation of non-adjesent matching labels' do
79
80
  fields = mods_display_name(@complex_labels).fields
80
81
 
81
- fields.length.should == 3
82
- fields.first.label.should == "Author/Creator:"
83
- fields.first.values.length.should == 1
84
- fields.first.values.first.to_s.should == "John Doe"
85
-
86
- fields[1].label.should == "Contributor:"
87
- fields[1].values.length.should == 1
88
- fields[1].values.first.name.should == "Jane Doe"
89
- fields[1].values.first.roles.should == ["lithographer"]
82
+ expect(fields.length).to eq(3)
83
+ expect(fields.first.label).to eq('Author/Creator:')
84
+ expect(fields.first.values.length).to eq(1)
85
+ expect(fields.first.values.first.to_s).to eq('John Doe')
86
+
87
+ expect(fields[1].label).to eq('Contributor:')
88
+ expect(fields[1].values.length).to eq(1)
89
+ expect(fields[1].values.first.name).to eq('Jane Doe')
90
+ expect(fields[1].values.first.roles).to eq(['lithographer'])
90
91
 
91
- fields.last.label.should == "Author/Creator:"
92
- fields.last.values.length.should == 2
92
+ expect(fields.last.label).to eq('Author/Creator:')
93
+ expect(fields.last.values.length).to eq(2)
93
94
  fields.last.values.each do |val|
94
- ["Jane Dough", "John Dough"].should include val.to_s
95
+ expect(['Jane Dough', 'John Dough']).to include val.to_s
95
96
  end
96
97
  end
97
- describe "roles" do
98
- it "should get the role when present" do
98
+ describe 'roles' do
99
+ it 'should get the role when present' do
99
100
  fields = mods_display_name(@name_with_role).fields
100
- fields.length.should == 1
101
- fields.first.values.length.should == 1
102
- fields.first.values.first.should be_a(ModsDisplay::Name::Person)
103
- fields.first.values.first.roles.should == ["Depicted"]
101
+ expect(fields.length).to eq(1)
102
+ expect(fields.first.values.length).to eq(1)
103
+ expect(fields.first.values.first).to be_a(ModsDisplay::Name::Person)
104
+ expect(fields.first.values.first.roles).to eq(['Depicted'])
104
105
  end
105
- it "should decode encoded roleTerms when no text (or non-typed) roleTerm is available" do
106
+ it 'should decode encoded roleTerms when no text (or non-typed) roleTerm is available' do
106
107
  fields = mods_display_name(@encoded_role).fields
107
- fields.length.should == 1
108
- fields.first.values.length.should == 1
109
- fields.first.values.first.to_s.should == "John Doe (Lithographer)"
108
+ expect(fields.length).to eq(1)
109
+ expect(fields.first.values.length).to eq(1)
110
+ expect(fields.first.values.first.to_s).to eq('John Doe (Lithographer)')
110
111
  end
111
112
  it "should get the type='text' role before an untyped role" do
112
113
  fields = mods_display_name(@mixed_role).fields
113
- fields.length.should == 1
114
- fields.first.values.length.should == 1
115
- fields.first.values.first.roles.should == ["engraver"]
114
+ expect(fields.length).to eq(1)
115
+ expect(fields.first.values.length).to eq(1)
116
+ expect(fields.first.values.first.roles).to eq(['engraver'])
116
117
  end
117
- it "should be handled correctly when there are more than one" do
118
+ it 'should be handled correctly when there are more than one' do
118
119
  fields = mods_display_name(@multiple_roles).fields
119
- fields.length.should == 1
120
- fields.first.values.length.should == 1
121
- fields.first.values.first.roles.should == ["Depicted", "Artist"]
120
+ expect(fields.length).to eq(1)
121
+ expect(fields.first.values.length).to eq(1)
122
+ expect(fields.first.values.first.roles).to eq(%w(Depicted Artist))
122
123
  end
123
- it "should handle code and text roleTerms together correctly" do
124
+ it 'should handle code and text roleTerms together correctly' do
124
125
  fields = mods_display_name(@complex_roles).fields
125
- fields.length.should == 1
126
- fields.first.values.length.should == 1
127
- fields.first.values.first.roles.should == ["Depicted"]
126
+ expect(fields.length).to eq(1)
127
+ expect(fields.first.values.length).to eq(1)
128
+ expect(fields.first.values.first.roles).to eq(['Depicted'])
128
129
  end
129
- it "should comma seperate multiple roles" do
130
+ it 'should comma seperate multiple roles' do
130
131
  fields = mods_display_name(@multiple_roles).fields
131
- fields.length.should == 1
132
- fields.first.values.length.should == 1
133
- fields.first.values.first.to_s.should == "John Doe (Depicted, Artist)"
132
+ expect(fields.length).to eq(1)
133
+ expect(fields.first.values.length).to eq(1)
134
+ expect(fields.first.values.first.to_s).to eq('John Doe (Depicted, Artist)')
134
135
  end
135
136
  end
136
137
  end
137
-
138
- describe "to_html" do
139
- it "should add the role to the name in parens" do
138
+
139
+ describe 'to_html' do
140
+ it 'should add the role to the name in parens' do
140
141
  html = mods_display_name(@name_with_role).to_html
141
- html.should match(/<dd>John Doe \(Depicted\)<\/dd>/)
142
+ expect(html).to match(%r{<dd>John Doe \(Depicted\)</dd>})
142
143
  end
143
- it "should linke the name and not the role if requested" do
144
+ it 'should linke the name and not the role if requested' do
144
145
  html = mods_display_name_link(@name_with_role).to_html
145
- html.should match(/<dd><a href='.*\?John Doe'>John Doe<\/a> \(Depicted\)<\/dd>/)
146
+ expect(html).to match(%r{<dd><a href='.*\?John Doe'>John Doe</a> \(Depicted\)</dd>})
146
147
  end
147
148
  end
148
-
149
- end
149
+ end
@@ -1,59 +1,72 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  def mods_display_note(mods_record)
4
- ModsDisplay::Note.new(mods_record, ModsDisplay::Configuration::Base.new, double("controller"))
4
+ ModsDisplay::Note.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
- @note = Stanford::Mods::Record.new.from_str("<mods><note>Note Field</note></mods>", false).note
10
- @display_label = Stanford::Mods::Record.new.from_str("<mods><note displayLabel='Special Label'>Note Field</note></mods>", false).note
11
- @sor_label = Stanford::Mods::Record.new.from_str("<mods><note type='statement of responsibility'>Note Field</note></mods>", false).note
12
- @contact_note = Stanford::Mods::Record.new.from_str("<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false).note
13
- @type_label = Stanford::Mods::Record.new.from_str("<mods><note type='some other Type'>Note Field</note></mods>", false).note
14
- @complex_label = Stanford::Mods::Record.new.from_str("<mods><note>Note Field</note><note>2nd Note Field</note><note type='statement of responsibility'>SoR</note><note>Another Note</note></mods>", false).note
9
+ @note = Stanford::Mods::Record.new.from_str('<mods><note>Note Field</note></mods>', false).note
10
+ @display_label = Stanford::Mods::Record.new.from_str(
11
+ "<mods><note displayLabel='Special Label'>Note Field</note></mods>", false
12
+ ).note
13
+ @sor_label = Stanford::Mods::Record.new.from_str(
14
+ "<mods><note type='statement of responsibility'>Note Field</note></mods>", false
15
+ ).note
16
+ @contact_note = Stanford::Mods::Record.new.from_str(
17
+ "<mods><note type='contact'>jdoe@example.com</note><note>Note Field</note></mods>", false
18
+ ).note
19
+ @type_label = Stanford::Mods::Record.new.from_str(
20
+ "<mods><note type='some other Type'>Note Field</note></mods>", false
21
+ ).note
22
+ @complex_label = Stanford::Mods::Record.new.from_str(
23
+ "<mods>
24
+ <note>Note Field</note><note>2nd Note Field</note>
25
+ <note type='statement of responsibility'>SoR</note>
26
+ <note>Another Note</note>
27
+ </mods>", false
28
+ ).note
15
29
  end
16
- describe "label" do
17
- it "should have a default label" do
18
- mods_display_note(@note).fields.first.label.should == "Note:"
30
+ describe 'label' do
31
+ it 'should have a default label' do
32
+ expect(mods_display_note(@note).fields.first.label).to eq('Note:')
19
33
  end
20
- it "should use the displayLabel attribute when one is available" do
21
- mods_display_note(@display_label).fields.first.label.should == "Special Label:"
34
+ it 'should use the displayLabel attribute when one is available' do
35
+ expect(mods_display_note(@display_label).fields.first.label).to eq('Special Label:')
22
36
  end
23
- it "should use get a label from a list of translations" do
24
- mods_display_note(@sor_label).fields.first.label.should == "Statement of responsibility:"
37
+ it 'should use get a label from a list of translations' do
38
+ expect(mods_display_note(@sor_label).fields.first.label).to eq('Statement of responsibility:')
25
39
  end
26
- it "should use use the capitalized type attribute if one is present" do
27
- mods_display_note(@type_label).fields.first.label.should == "Some other type:"
40
+ it 'should use use the capitalized type attribute if one is present' do
41
+ expect(mods_display_note(@type_label).fields.first.label).to eq('Some other type:')
28
42
  end
29
43
  end
30
-
31
- describe "fields" do
32
- it "should handle single values" do
44
+
45
+ describe 'fields' do
46
+ it 'should handle single values' do
33
47
  fields = mods_display_note(@note).fields
34
- fields.length.should == 1
35
- fields.first.values.should == ["Note Field"]
48
+ expect(fields.length).to eq(1)
49
+ expect(fields.first.values).to eq(['Note Field'])
36
50
  end
37
- it "should handle complex grouping" do
51
+ it 'should handle complex grouping' do
38
52
  fields = mods_display_note(@complex_label).fields
39
- fields.length.should == 3
40
- fields.first.label.should == "Note:"
41
- fields.first.values.length == 2
42
- fields.first.values.should == ["Note Field", "2nd Note Field"]
43
-
44
- fields[1].label == "Statement of responsibility"
45
- fields[1].values.length == 1
46
- fields[1].values.should == ["SoR"]
47
-
48
- fields.last.label.should == "Note:"
49
- fields.last.values.length == 1
50
- fields.last.values.should == ["Another Note"]
53
+ expect(fields.length).to eq(3)
54
+ expect(fields.first.label).to eq('Note:')
55
+ expect(fields.first.values.length).to eq 2
56
+ expect(fields.first.values).to eq(['Note Field', '2nd Note Field'])
57
+
58
+ expect(fields[1].label).to eq 'Statement of responsibility:'
59
+ expect(fields[1].values.length).to eq 1
60
+ expect(fields[1].values).to eq(['SoR'])
61
+
62
+ expect(fields.last.label).to eq('Note:')
63
+ expect(fields.last.values.length).to eq 1
64
+ expect(fields.last.values).to eq(['Another Note'])
51
65
  end
52
- it "should not include any contact fields" do
66
+ it 'should not include any contact fields' do
53
67
  fields = mods_display_note(@contact_note).fields
54
- fields.length.should == 1
55
- fields.first.values.should == ["Note Field"]
68
+ expect(fields.length).to eq(1)
69
+ expect(fields.first.values).to eq(['Note Field'])
56
70
  end
57
71
  end
58
-
59
- end
72
+ end