mods_display 0.0.1.beta1
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.
- data/.gitignore +19 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +26 -0
- data/README.md +136 -0
- data/Rakefile +5 -0
- data/lib/mods_display.rb +30 -0
- data/lib/mods_display/configuration.rb +73 -0
- data/lib/mods_display/configuration/base.rb +23 -0
- data/lib/mods_display/configuration/subject.rb +11 -0
- data/lib/mods_display/controller_extension.rb +32 -0
- data/lib/mods_display/fields/abstract.rb +32 -0
- data/lib/mods_display/fields/audience.rb +7 -0
- data/lib/mods_display/fields/cartographics.rb +21 -0
- data/lib/mods_display/fields/collection.rb +21 -0
- data/lib/mods_display/fields/contents.rb +7 -0
- data/lib/mods_display/fields/description.rb +30 -0
- data/lib/mods_display/fields/field.rb +89 -0
- data/lib/mods_display/fields/format.rb +34 -0
- data/lib/mods_display/fields/identifier.rb +60 -0
- data/lib/mods_display/fields/imprint.rb +68 -0
- data/lib/mods_display/fields/language.rb +33 -0
- data/lib/mods_display/fields/location.rb +25 -0
- data/lib/mods_display/fields/name.rb +97 -0
- data/lib/mods_display/fields/note.rb +49 -0
- data/lib/mods_display/fields/related_item.rb +24 -0
- data/lib/mods_display/fields/related_location.rb +14 -0
- data/lib/mods_display/fields/subject.rb +103 -0
- data/lib/mods_display/fields/title.rb +49 -0
- data/lib/mods_display/fields/values.rb +11 -0
- data/lib/mods_display/html.rb +87 -0
- data/lib/mods_display/model_extension.rb +20 -0
- data/lib/mods_display/version.rb +3 -0
- data/mods_display.gemspec +24 -0
- data/spec/configuration/base_spec.rb +29 -0
- data/spec/fields/abstract_spec.rb +21 -0
- data/spec/fields/audience_spec.rb +21 -0
- data/spec/fields/cartographics_spec.rb +39 -0
- data/spec/fields/collection_spec.rb +31 -0
- data/spec/fields/contents_spec.rb +21 -0
- data/spec/fields/description_spec.rb +37 -0
- data/spec/fields/format_spec.rb +35 -0
- data/spec/fields/identifier_spec.rb +49 -0
- data/spec/fields/imprint_spec.rb +78 -0
- data/spec/fields/language_spec.rb +55 -0
- data/spec/fields/location_spec.rb +25 -0
- data/spec/fields/name_spec.rb +88 -0
- data/spec/fields/note_spec.rb +53 -0
- data/spec/fields/related_item_spec.rb +37 -0
- data/spec/fields/related_location_spec.rb +31 -0
- data/spec/fields/subject_spec.rb +89 -0
- data/spec/fields/title_spec.rb +47 -0
- data/spec/fixtures/cartographics_fixtures.rb +52 -0
- data/spec/fixtures/imprint_fixtures.rb +89 -0
- data/spec/fixtures/name_fixtures.rb +3 -0
- data/spec/fixtures/subjects_fixtures.rb +70 -0
- data/spec/integration/configuration_spec.rb +37 -0
- data/spec/integration/installation_spec.rb +26 -0
- data/spec/spec_helper.rb +35 -0
- metadata +182 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def mods_display_audience(mods_record)
|
4
|
+
ModsDisplay::Audience.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ModsDisplay::Contents do
|
8
|
+
before(:all) do
|
9
|
+
@audience = Stanford::Mods::Record.new.from_str("<mods><targetAudience>Audience Note</targetAudience></mods>", false).targetAudience
|
10
|
+
@display_label = Stanford::Mods::Record.new.from_str("<mods><targetAudience displayLabel='Special Label'>Audience Note</tableOfContents></mods>", false).targetAudience
|
11
|
+
end
|
12
|
+
describe "label" do
|
13
|
+
it "should have a default label" do
|
14
|
+
mods_display_audience(@audience).label.should == "Target audience"
|
15
|
+
end
|
16
|
+
it "should use the displayLabel attribute when one is available" do
|
17
|
+
mods_display_audience(@display_label).label.should == "Special Label"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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, mock("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
|
+
values.length.should == 1
|
20
|
+
values.first.values.should == ["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
|
+
values.length.should == 1
|
25
|
+
values.first.values.should == ["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
|
+
values.length.should == 1
|
30
|
+
values.first.values.should == ["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
|
+
values.length.should == 1
|
35
|
+
values.first.values.should == ["Scale not given ; the coordinates"]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def mods_display_collection(mods_record)
|
4
|
+
ModsDisplay::Collection.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ModsDisplay::Collection do
|
8
|
+
before(:all) do
|
9
|
+
@collection = Stanford::Mods::Record.new.from_str("<mods><relatedItem><titleInfo><title>The Collection</title></titleInfo><typeOfResource collection='yes' /></relatedItem></mods>", false).related_item
|
10
|
+
@non_collection = Stanford::Mods::Record.new.from_str("<mods><relatedItem><titleInfo><title>Not a Collection</title></titleInfo></relatedItem></mods>", false).related_item
|
11
|
+
@display_label = Stanford::Mods::Record.new.from_str("<mods><relatedItem displayLabel='Special Collection'><titleInfo><title>Not a Collection</title></titleInfo></relatedItem></mods>", false).related_item
|
12
|
+
end
|
13
|
+
describe "label" do
|
14
|
+
it "should default to Collection" do
|
15
|
+
mods_display_collection(@collection).label.should == "Collection"
|
16
|
+
end
|
17
|
+
it "should get the displayLabel if available" do
|
18
|
+
mods_display_collection(@display_label).label.should == "Special Collection"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
describe "fields" do
|
22
|
+
it "should get a collection title if there is an appropriate typeOfResource field with the collection attribute" do
|
23
|
+
fields = mods_display_collection(@collection).fields
|
24
|
+
fields.length.should == 1
|
25
|
+
fields.first.values.should == ["The Collection"]
|
26
|
+
end
|
27
|
+
it "should not return anything if the there is not an appropriate typeOfResource field with the collection attribute" do
|
28
|
+
mods_display_collection(@non_collection).fields.should == []
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def mods_display_contents(mods_record)
|
4
|
+
ModsDisplay::Contents.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ModsDisplay::Contents do
|
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
|
11
|
+
end
|
12
|
+
describe "label" do
|
13
|
+
it "should have a default label" do
|
14
|
+
mods_display_contents(@contents).label.should == "Table of Contents"
|
15
|
+
end
|
16
|
+
it "should use the displayLabel attribute when one is available" do
|
17
|
+
mods_display_contents(@display_label).label.should == "Special Label"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def mods_display_description(mods)
|
4
|
+
ModsDisplay::Description.new(mods, ModsDisplay::Configuration::Base.new, mock("controller"))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ModsDisplay::Description do
|
8
|
+
before(:all) do
|
9
|
+
@form = Stanford::Mods::Record.new.from_str("<mods><physicalDescription><form>Form Note</form></physicalDescription></mods>", false).physical_description
|
10
|
+
@display_label = Stanford::Mods::Record.new.from_str("<mods><physicalDescription displayLabel='SpecialLabel'><form>Form Note</form></physicalDescription></mods>", false).physical_description
|
11
|
+
@child_display_label = Stanford::Mods::Record.new.from_str("<mods><physicalDescription><form displayLabel='Form Label'>Form Note</form></physicalDescription></mods>", false).physical_description
|
12
|
+
@mixed = Stanford::Mods::Record.new.from_str("<mods><physicalDescription><form>Form Note</form><extent>Extent Note</extent></physicalDescription></mods>", false).physical_description
|
13
|
+
end
|
14
|
+
describe "labels" do
|
15
|
+
it "should use the dislayLabel if one is provided" do
|
16
|
+
mods_display_description(@display_label).fields.first.label.should == "SpecialLabel"
|
17
|
+
end
|
18
|
+
it "should get the default label for a child element" do
|
19
|
+
mods_display_description(@form).fields.first.label.should == "Form"
|
20
|
+
end
|
21
|
+
it "should get multiple lables for mixed content" do
|
22
|
+
mods_display_description(@mixed).fields.map{|v| v.label }.should == ["Form", "Extent"]
|
23
|
+
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 == ["Form Label"]
|
26
|
+
end
|
27
|
+
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 == ["Form Note"]
|
32
|
+
end
|
33
|
+
it "should get multiple values for mixed content" do
|
34
|
+
mods_display_description(@mixed).fields.map{|v| v.values }.should == [["Form Note"], ["Extent Note"]]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def mods_display_format(mods)
|
4
|
+
ModsDisplay::Format.new(mods, ModsDisplay::Configuration::Base.new, mock("controller"))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ModsDisplay::Format do
|
8
|
+
before(:all) do
|
9
|
+
@format = Stanford::Mods::Record.new.from_str("<mods><typeOfResource>Format</typeOfResource></mods>", false).typeOfResource
|
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
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "labels" do
|
16
|
+
it "should return the format label" do
|
17
|
+
mods_display_format(@format).to_html.should match(/<dt title='Format'>Format:<\/dt>/)
|
18
|
+
end
|
19
|
+
it "should return the displayLabel when available" do
|
20
|
+
mods_display_format(@display_label).to_html.should match(/<dt title='SpecialFormat'>SpecialFormat:<\/dt>/)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
describe "format_class" do
|
24
|
+
it "should wrap the format in a span w/ the format class in it" do
|
25
|
+
mods_display_format(@format).to_html.should match(/<span class='format'>Format<\/span>/)
|
26
|
+
end
|
27
|
+
it "should remove any spaces" do
|
28
|
+
ModsDisplay::Format.send(:format_class, "Mixed Materials").should == "mixed_materials"
|
29
|
+
end
|
30
|
+
it "should replace any slashes" do
|
31
|
+
ModsDisplay::Format.send(:format_class, "Manuscript/Archive").should == "manuscript_archive"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def mods_display_id(mods_record)
|
4
|
+
ModsDisplay::Identifier.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ModsDisplay::Note do
|
8
|
+
before(:all) do
|
9
|
+
@id = Stanford::Mods::Record.new.from_str("<mods><identifier>12345</identifier></mods>", false).identifier
|
10
|
+
@display_label = Stanford::Mods::Record.new.from_str("<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
|
14
|
+
end
|
15
|
+
describe "label" do
|
16
|
+
it "should have a default label" do
|
17
|
+
mods_display_id(@id).fields.first.label.should == "Identifier"
|
18
|
+
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"
|
21
|
+
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"
|
24
|
+
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"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "fields" do
|
31
|
+
it "should handle matching adjacent labels" do
|
32
|
+
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
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "fixtures/imprint_fixtures"
|
3
|
+
|
4
|
+
include ImprintFixtures
|
5
|
+
|
6
|
+
def mods_display_imprint(mods_record)
|
7
|
+
ModsDisplay::Imprint.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ModsDisplay::Imprint do
|
11
|
+
before(:all) do
|
12
|
+
@imprint = Stanford::Mods::Record.new.from_str(imprint_mods, false).origin_info
|
13
|
+
@edition_and_date = Stanford::Mods::Record.new.from_str(origin_info_mods, false).origin_info
|
14
|
+
@encoded_date = Stanford::Mods::Record.new.from_str(encoded_date, false).origin_info
|
15
|
+
@encoded_only = Stanford::Mods::Record.new.from_str(only_encoded_data, false).origin_info
|
16
|
+
@mixed = Stanford::Mods::Record.new.from_str(mixed_mods, false).origin_info
|
17
|
+
@display_form = Stanford::Mods::Record.new.from_str(display_form, false).origin_info
|
18
|
+
@display_form_with_label = Stanford::Mods::Record.new.from_str(display_form, false).origin_info
|
19
|
+
@display_label = Stanford::Mods::Record.new.from_str(display_label, false).origin_info
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "labels" do
|
23
|
+
it "should get the Imprint label by default" do
|
24
|
+
mods_display_imprint(@imprint).fields.first.label.should == "Imprint"
|
25
|
+
end
|
26
|
+
it "should get the label from non-imprint origin info fields" do
|
27
|
+
fields = mods_display_imprint(@edition_and_date).fields
|
28
|
+
fields.first.label.should == "Date Valid"
|
29
|
+
fields.last.label.should == "Edition"
|
30
|
+
end
|
31
|
+
it "should get multiple labels when we have mixed content" do
|
32
|
+
mods_display_imprint(@mixed).fields.map{|val| val.label }.should == ["Imprint", "Edition"]
|
33
|
+
end
|
34
|
+
it "should use the displayLabel when available" do
|
35
|
+
mods_display_imprint(@display_label).fields.map{|val| val.label }.should == ["TheLabel", "EditionLabel", "EditionLabel"]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "fields" do
|
40
|
+
it "should return various parts of the imprint" do
|
41
|
+
mods_display_imprint(@imprint).fields.map{|val| val.values }.join(" ").should == "A Place : A Publisher, A Create Date, An Issue Date, A Capture Date, Another Date"
|
42
|
+
end
|
43
|
+
it "should get the text for non-imprint origin info fields" do
|
44
|
+
fields = mods_display_imprint(@edition_and_date).fields
|
45
|
+
fields.first.values.should == ["A Valid Date"]
|
46
|
+
fields.last.values.should == ["The Edition"]
|
47
|
+
end
|
48
|
+
it "should omit dates with an encoding attribute" do
|
49
|
+
mods_display_imprint(@encoded_date).fields.map{|val| val.values }.join.should_not include("An Encoded Date")
|
50
|
+
end
|
51
|
+
it "should not try to return data w/ only encoded data" do
|
52
|
+
mods_display_imprint(@encoded_only).fields.should be_empty
|
53
|
+
end
|
54
|
+
it "should handle mixed mods properly" do
|
55
|
+
values = mods_display_imprint(@mixed).fields
|
56
|
+
values.length.should == 2
|
57
|
+
values.map{|val| val.values}.should include(["A Place : A Publisher"])
|
58
|
+
values.map{|val| val.values}.should include(["The Edition"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
describe "to_html" do
|
62
|
+
it "should return the display form if one is available" do
|
63
|
+
html = mods_display_imprint(@display_form).to_html
|
64
|
+
html.scan(/<dd>/).length.should == 2
|
65
|
+
html.scan(/<dd>The Display Form<\/dd>/).length.should == 2
|
66
|
+
end
|
67
|
+
it "should return the displayLabel when present if we're using the displayForm" do
|
68
|
+
mods_display_imprint(@display_form_with_label).to_html.should match(/<dt title='TheLabel'>TheLabel:<\/dt>/)
|
69
|
+
end
|
70
|
+
it "should have individual dt/dd pairs for mixed content" do
|
71
|
+
html = mods_display_imprint(@mixed).to_html
|
72
|
+
html.scan(/<dt title='Imprint'>Imprint:<\/dt>/).length.should == 1
|
73
|
+
html.scan(/<dt title='Edition'>Edition:<\/dt>/).length.should == 1
|
74
|
+
html.scan(/<dd>/).length.should == 2
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def mods_display_language(mods_record)
|
4
|
+
ModsDisplay::Language.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ModsDisplay::Language do
|
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
|
15
|
+
end
|
16
|
+
describe "label" do
|
17
|
+
it "should default to Language when no displayLabel is available" do
|
18
|
+
mods_display_language(@language).label.should == "Language"
|
19
|
+
end
|
20
|
+
it "should use the displayLabel attribute when present" do
|
21
|
+
mods_display_language(@display_label).label.should == "Lang"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
describe "fields" do
|
25
|
+
it "should return an array with a label/values object" do
|
26
|
+
values = mods_display_language(@display_label).fields
|
27
|
+
values.length.should == 1
|
28
|
+
values.first.should be_a ModsDisplay::Values
|
29
|
+
values.first.label.should == "Lang"
|
30
|
+
values.first.values.should == ["English"]
|
31
|
+
end
|
32
|
+
it "should not return any non type='code' languageTerms from the XML" do
|
33
|
+
values = mods_display_language(@mixed).fields
|
34
|
+
values.length.should == 1
|
35
|
+
values.first.values.should == ["English"]
|
36
|
+
end
|
37
|
+
it "should handle multiple languages correctly" do
|
38
|
+
values = mods_display_language(@multi).fields
|
39
|
+
values.length.should == 1
|
40
|
+
values.first.values.should == ["German", "English"]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
describe "text" do
|
44
|
+
it "should return the language code translation" do
|
45
|
+
mods_display_language(@language).text.should == "English"
|
46
|
+
end
|
47
|
+
it "should return the code if the languages table does not have a translation" do
|
48
|
+
mods_display_language(@no_lang).text.should == "zzzxxx"
|
49
|
+
end
|
50
|
+
it "should return a displayForm if there is one" do
|
51
|
+
mods_display_language(@display_form).text.should == "Klingon"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def mods_display_location(mods_record)
|
4
|
+
ModsDisplay::Location.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe ModsDisplay::Note do
|
8
|
+
before(:all) do
|
9
|
+
@location = Stanford::Mods::Record.new.from_str("<mods><location><physicalLocation>The Location</physicalLocation></location></mods>", false).location
|
10
|
+
@display_label = Stanford::Mods::Record.new.from_str("<mods><location displayLabel='Special Label'><shelfLocation>On Shelf A</shelfLocation></location></mods>", false).location
|
11
|
+
@repository_label = Stanford::Mods::Record.new.from_str("<mods><location type='repository'><physicalLocation>Location Field</physicalLocation></location></mods>", false).location
|
12
|
+
end
|
13
|
+
describe "label" do
|
14
|
+
it "should have a default label" do
|
15
|
+
mods_display_location(@location).fields.first.label.should == "Location"
|
16
|
+
end
|
17
|
+
it "should use the displayLabel attribute when one is available" do
|
18
|
+
mods_display_location(@display_label).fields.first.label.should == "Special Label"
|
19
|
+
end
|
20
|
+
it "should use get a label from a list of translations" do
|
21
|
+
mods_display_location(@repository_label).fields.first.label.should == "Repository"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "fixtures/name_fixtures"
|
3
|
+
include NameFixtures
|
4
|
+
|
5
|
+
def mods_display_name_link(mods_record)
|
6
|
+
config = ModsDisplay::Configuration::Base.new do
|
7
|
+
link :link_method, '%value%'
|
8
|
+
end
|
9
|
+
ModsDisplay::Name.new(mods_record, config, TestController.new)
|
10
|
+
end
|
11
|
+
|
12
|
+
def mods_display_name(mods_record)
|
13
|
+
ModsDisplay::Name.new(mods_record, ModsDisplay::Configuration::Base.new, mock("controller"))
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ModsDisplay::Language do
|
17
|
+
before(:all) do
|
18
|
+
@name = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name></mods>", false).plain_name
|
19
|
+
@conf_name = Stanford::Mods::Record.new.from_str("<mods><name type='conference'><namePart>John Doe</namePart></name></mods>", false).plain_name
|
20
|
+
@display_form = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart><displayForm>Mr. John Doe</displayForm></name></mods>", false).plain_name
|
21
|
+
@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
|
22
|
+
@complex_labels = Stanford::Mods::Record.new.from_str("<mods><name><namePart>John Doe</namePart></name><name><namePart>Jane Doe</namePart></name><name type='conference'><namePart>John Dough</namePart></name><name><namePart>Jane Dough</namePart></name></mods>", false).plain_name
|
23
|
+
@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
|
24
|
+
end
|
25
|
+
describe "label" do
|
26
|
+
it "should default Creator/Contributor when none is available" do
|
27
|
+
mods_display_name(@name).fields.first.label.should == "Creator/Contributor"
|
28
|
+
end
|
29
|
+
it "should derive the name from the type attribute if one is available" do
|
30
|
+
mods_display_name(@conf_name).fields.first.label.should == "Meeting"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "fields" do
|
35
|
+
it "should use the display form when available" do
|
36
|
+
fields = mods_display_name(@display_form).fields
|
37
|
+
fields.length.should == 1
|
38
|
+
fields.first.values.length.should == 1
|
39
|
+
fields.first.values.first.should be_a(ModsDisplay::Name::Person)
|
40
|
+
fields.first.values.first.name.should == "Mr. John Doe"
|
41
|
+
end
|
42
|
+
it "should get the role when present" do
|
43
|
+
fields = mods_display_name(@name_with_role).fields
|
44
|
+
fields.length.should == 1
|
45
|
+
fields.first.values.length.should == 1
|
46
|
+
fields.first.values.first.should be_a(ModsDisplay::Name::Person)
|
47
|
+
fields.first.values.first.role.should == "Depicted"
|
48
|
+
end
|
49
|
+
it "should collapse adjacent matching labels" do
|
50
|
+
fields = mods_display_name(@collapse_label).fields
|
51
|
+
fields.length.should == 1
|
52
|
+
fields.first.label.should == "Creator/Contributor"
|
53
|
+
fields.first.values.each do |val|
|
54
|
+
["John Doe", "Jane Doe"].should include val.to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
it "should perseve order and separation of non-adjesent matching labels" do
|
58
|
+
fields = mods_display_name(@complex_labels).fields
|
59
|
+
|
60
|
+
fields.length.should == 3
|
61
|
+
fields.first.label.should == "Creator/Contributor"
|
62
|
+
fields.first.values.length.should == 2
|
63
|
+
fields.first.values.each do |val|
|
64
|
+
["John Doe", "Jane Doe"].should include val.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
fields[1].label.should == "Meeting"
|
68
|
+
fields[1].values.length.should == 1
|
69
|
+
fields[1].values.first.to_s.should == "John Dough"
|
70
|
+
|
71
|
+
fields.last.label.should == "Creator/Contributor"
|
72
|
+
fields.last.values.length.should == 1
|
73
|
+
fields.last.values.first.to_s.should == "Jane Dough"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "to_html" do
|
78
|
+
it "should add the role to the name in parens" do
|
79
|
+
html = mods_display_name(@name_with_role).to_html
|
80
|
+
html.should match(/<dd>John Doe \(Depicted\)<\/dd>/)
|
81
|
+
end
|
82
|
+
it "should linke the name and not the role if requested" do
|
83
|
+
html = mods_display_name_link(@name_with_role).to_html
|
84
|
+
html.should match(/<dd><a href='.*\?John Doe'>John Doe<\/a> \(Depicted\)<\/dd>/)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|