mods_display 0.9.1 → 1.0.0.alpha2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -1
- data/.rubocop_todo.yml +433 -35
- data/README.md +0 -95
- data/app/components/mods_display/field_component.html.erb +13 -0
- data/app/components/mods_display/field_component.rb +27 -0
- data/app/components/mods_display/list_field_component.html.erb +11 -0
- data/app/components/mods_display/list_field_component.rb +10 -0
- data/app/components/mods_display/record_component.html.erb +5 -0
- data/app/components/mods_display/record_component.rb +39 -0
- data/app/helpers/mods_display/record_helper.rb +106 -0
- data/app/models/mods_display/record.rb +26 -0
- data/config/locales/en.yml +1 -1
- data/config.ru +9 -0
- data/lib/mods_display/engine.rb +13 -0
- data/lib/mods_display/fields/access_condition.rb +4 -0
- data/lib/mods_display/fields/contents.rb +14 -15
- data/lib/mods_display/fields/field.rb +13 -149
- data/lib/mods_display/fields/genre.rb +4 -0
- data/lib/mods_display/fields/imprint.rb +52 -3
- data/lib/mods_display/fields/location.rb +1 -1
- data/lib/mods_display/fields/name.rb +11 -20
- data/lib/mods_display/fields/nested_related_item.rb +7 -18
- data/lib/mods_display/fields/note.rb +4 -0
- data/lib/mods_display/fields/related_item.rb +4 -0
- data/lib/mods_display/fields/resource_type.rb +1 -1
- data/lib/mods_display/fields/sub_title.rb +3 -3
- data/lib/mods_display/fields/subject.rb +13 -39
- data/lib/mods_display/fields/title.rb +43 -32
- data/lib/mods_display/fields/values.rb +4 -4
- data/lib/mods_display/html.rb +55 -106
- data/lib/mods_display/version.rb +1 -1
- data/lib/mods_display.rb +2 -17
- data/mods_display.gemspec +15 -9
- metadata +45 -105
- data/.github/workflows/ruby.yml +0 -24
- data/.gitignore +0 -21
- data/lib/mods_display/configuration/access_condition.rb +0 -21
- data/lib/mods_display/configuration/base.rb +0 -34
- data/lib/mods_display/configuration/genre.rb +0 -9
- data/lib/mods_display/configuration/imprint.rb +0 -13
- data/lib/mods_display/configuration/name.rb +0 -9
- data/lib/mods_display/configuration/note.rb +0 -9
- data/lib/mods_display/configuration/related_item.rb +0 -9
- data/lib/mods_display/configuration/subject.rb +0 -13
- data/lib/mods_display/configuration/title.rb +0 -9
- data/lib/mods_display/configuration.rb +0 -93
- data/lib/mods_display/controller_extension.rb +0 -32
- data/lib/mods_display/helpers/record_helper.rb +0 -131
- data/lib/mods_display/model_extension.rb +0 -22
- data/lib/mods_display/railtie.rb +0 -10
- data/spec/configuration/access_condition_spec.rb +0 -10
- data/spec/configuration/base_spec.rb +0 -39
- data/spec/fake_app.rb +0 -18
- data/spec/fields/abstract_spec.rb +0 -39
- data/spec/fields/access_condition_spec.rb +0 -107
- data/spec/fields/audience_spec.rb +0 -24
- data/spec/fields/cartographics_spec.rb +0 -38
- data/spec/fields/collection_spec.rb +0 -77
- data/spec/fields/contact_spec.rb +0 -23
- data/spec/fields/contents_spec.rb +0 -39
- data/spec/fields/description_spec.rb +0 -55
- data/spec/fields/extent_spec.rb +0 -31
- data/spec/fields/form_spec.rb +0 -49
- data/spec/fields/genre_spec.rb +0 -34
- data/spec/fields/geo_spec.rb +0 -40
- data/spec/fields/identifier_spec.rb +0 -61
- data/spec/fields/imprint_spec.rb +0 -289
- data/spec/fields/language_spec.rb +0 -51
- data/spec/fields/location_spec.rb +0 -81
- data/spec/fields/name_spec.rb +0 -166
- data/spec/fields/nested_related_item_spec.rb +0 -89
- data/spec/fields/note_spec.rb +0 -72
- data/spec/fields/related_item_spec.rb +0 -72
- data/spec/fields/resource_type_spec.rb +0 -34
- data/spec/fields/sub_title_spec.rb +0 -20
- data/spec/fields/subject_spec.rb +0 -113
- data/spec/fields/title_spec.rb +0 -74
- data/spec/fixtures/access_condition_fixtures.rb +0 -58
- data/spec/fixtures/cartographics_fixtures.rb +0 -52
- data/spec/fixtures/imprint_fixtures.rb +0 -349
- data/spec/fixtures/name_fixtures.rb +0 -398
- data/spec/fixtures/nested_realted_items_fixtures.rb +0 -64
- data/spec/fixtures/related_item_fixtures.rb +0 -107
- data/spec/fixtures/subjects_fixtures.rb +0 -115
- data/spec/fixtures/title_fixtures.rb +0 -101
- data/spec/helpers/record_helper_spec.rb +0 -241
- data/spec/integration/configuration_spec.rb +0 -57
- data/spec/integration/html_spec.rb +0 -87
- data/spec/integration/installation_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -46
- data/spec/test_fr.yml +0 -3
@@ -1,101 +0,0 @@
|
|
1
|
-
module TitleFixtures
|
2
|
-
def simple_title_fixture
|
3
|
-
<<-XML
|
4
|
-
<mods>
|
5
|
-
<titleInfo><title>Title</title></titleInfo>
|
6
|
-
</mods>
|
7
|
-
XML
|
8
|
-
end
|
9
|
-
|
10
|
-
def title_parts_fixture
|
11
|
-
<<-XML
|
12
|
-
<mods>
|
13
|
-
<titleInfo>
|
14
|
-
<nonSort>The</nonSort>
|
15
|
-
<title>Title</title>
|
16
|
-
<subTitle>For</subTitle>
|
17
|
-
<partName>Something</partName>
|
18
|
-
<partNumber>Part 62</partNumber>
|
19
|
-
</titleInfo>
|
20
|
-
</mods>
|
21
|
-
XML
|
22
|
-
end
|
23
|
-
|
24
|
-
def reverse_title_parts_fixture
|
25
|
-
<<-XML
|
26
|
-
<mods>
|
27
|
-
<titleInfo>
|
28
|
-
<nonSort>The</nonSort>
|
29
|
-
<title>Title : </title>
|
30
|
-
<subTitle>For</subTitle>
|
31
|
-
<partNumber>Part 62</partNumber>
|
32
|
-
<partName>Something</partName>
|
33
|
-
</titleInfo>
|
34
|
-
</mods>
|
35
|
-
XML
|
36
|
-
end
|
37
|
-
|
38
|
-
def display_label_fixture
|
39
|
-
<<-XML
|
40
|
-
<mods>
|
41
|
-
<titleInfo displayLabel='MyTitle'>
|
42
|
-
<title>Title</title>
|
43
|
-
</titleInfo>
|
44
|
-
</mods>
|
45
|
-
XML
|
46
|
-
end
|
47
|
-
|
48
|
-
def display_form_fixture
|
49
|
-
<<-XML
|
50
|
-
<mods>
|
51
|
-
<titleInfo>
|
52
|
-
<title>Title</title>
|
53
|
-
<displayForm>The Title of This Item</displayForm>
|
54
|
-
</titleInfo>
|
55
|
-
</mods>
|
56
|
-
XML
|
57
|
-
end
|
58
|
-
|
59
|
-
def multi_label_fixture
|
60
|
-
<<-XML
|
61
|
-
<mods>
|
62
|
-
<titleInfo>
|
63
|
-
<title>Main Title</title>
|
64
|
-
</titleInfo>
|
65
|
-
<titleInfo type='alternative'>
|
66
|
-
<title>Alt Title</title>
|
67
|
-
</titleInfo>
|
68
|
-
<titleInfo type='uniform'>
|
69
|
-
<title>Uniform Title</title>
|
70
|
-
</titleInfo>
|
71
|
-
<titleInfo type='alternative'>
|
72
|
-
<title>Another Alt Title</title>
|
73
|
-
</titleInfo>
|
74
|
-
<titleInfo type='alternative'>
|
75
|
-
<title>Yet Another Alt Title</title>
|
76
|
-
</titleInfo>
|
77
|
-
</mods>
|
78
|
-
XML
|
79
|
-
end
|
80
|
-
|
81
|
-
def alt_title_fixture
|
82
|
-
<<-XML
|
83
|
-
<mods>
|
84
|
-
<titleInfo type='alternative'>
|
85
|
-
<title>Title</title>
|
86
|
-
</titleInfo>
|
87
|
-
</mods>
|
88
|
-
XML
|
89
|
-
end
|
90
|
-
|
91
|
-
def title_puncutation_fixture
|
92
|
-
<<-XML
|
93
|
-
<mods>
|
94
|
-
<titleInfo>
|
95
|
-
<title>A title that ends in punctuation.</title>
|
96
|
-
<partNumber>2015</partNumber>
|
97
|
-
</titleInfo>
|
98
|
-
</mods>
|
99
|
-
XML
|
100
|
-
end
|
101
|
-
end
|
@@ -1,241 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'byebug'
|
5
|
-
|
6
|
-
describe ModsDisplay::Helpers::RecordHelper, type: :helper do
|
7
|
-
let(:empty_field) { OpenStruct.new(label: 'test', values: ['']) }
|
8
|
-
|
9
|
-
describe 'display_content_field' do
|
10
|
-
let(:values) { ['guitar (1)', 'solo cowbell, trombone (2)'] }
|
11
|
-
let(:content) { OpenStruct.new(label: 'Instrumentation', values: values) }
|
12
|
-
|
13
|
-
it 'should return dt with label and dd with values' do
|
14
|
-
expect(helper.display_content_field(content)).to have_css('dt', text: 'Instrumentation')
|
15
|
-
expect(helper.display_content_field(content)).to have_css('dd', count: 2)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'display_content_label' do
|
20
|
-
it 'should return correct dt' do
|
21
|
-
expect(helper.display_content_label('test')).to have_css('dt', text: 'test')
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'display_content_values' do
|
26
|
-
let(:values) { ['guitar (1)', 'solo cowbell, trombone (2)'] }
|
27
|
-
|
28
|
-
it 'should return dds of values' do
|
29
|
-
expect(helper.display_content_values(values)).to have_css('dd', count: 2)
|
30
|
-
expect(helper.display_content_values(values)).to have_css('dd', text: 'guitar (1)')
|
31
|
-
expect(helper.display_content_values(values)).to have_css('dd', text: 'solo cowbell, trombone (2)')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe 'mods_display_label' do
|
36
|
-
it 'should return correct label' do
|
37
|
-
expect(helper.mods_display_label('test:')).not_to have_content ':'
|
38
|
-
expect(helper.mods_display_label('test:')).to have_css('dt', text: 'test')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'mods_display_content' do
|
43
|
-
it 'should return correct content' do
|
44
|
-
expect(helper.mods_display_content('hello, there')).to have_css('dd', text: 'hello, there')
|
45
|
-
end
|
46
|
-
it 'should return multiple dd elements when a multi-element array is passed' do
|
47
|
-
expect(helper.mods_display_content(%w(hello there))).to have_css('dd', count: 2)
|
48
|
-
end
|
49
|
-
it 'should handle nil values correctly' do
|
50
|
-
expect(helper.mods_display_content(['something', nil])).to have_css('dd', count: 1)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'mods_record_field' do
|
55
|
-
let(:mods_field) { OpenStruct.new(label: 'test', values: ['hello, there']) }
|
56
|
-
let(:url_field) { OpenStruct.new(label: 'test', values: ['https://library.stanford.edu']) }
|
57
|
-
let(:multi_values) { double(label: 'test', values: %w(123 321)) }
|
58
|
-
|
59
|
-
it 'should return correct content' do
|
60
|
-
expect(helper.mods_record_field(mods_field)).to have_css('dt', text: 'test')
|
61
|
-
expect(helper.mods_record_field(mods_field)).to have_css('dd', text: 'hello, there')
|
62
|
-
end
|
63
|
-
it 'should link fields with URLs' do
|
64
|
-
expect(mods_record_field(url_field)).to have_css("a[href='https://library.stanford.edu']", text: 'https://library.stanford.edu')
|
65
|
-
end
|
66
|
-
it 'should not print empty labels' do
|
67
|
-
expect(helper.mods_record_field(empty_field)).not_to be_present
|
68
|
-
end
|
69
|
-
it 'should join values with a <dd> by default' do
|
70
|
-
expect(helper.mods_record_field(multi_values)).to have_css('dd', count: 2)
|
71
|
-
end
|
72
|
-
it 'should join values with a supplied delimiter' do
|
73
|
-
expect(helper.mods_record_field(multi_values, 'DELIM')).to have_css('dd', count: 1)
|
74
|
-
expect(helper.mods_record_field(multi_values, 'DELIM')).to have_css('dd', text: '123DELIM321')
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'names' do
|
79
|
-
let(:name_field) do
|
80
|
-
OpenStruct.new(
|
81
|
-
label: 'Contributor',
|
82
|
-
values: [
|
83
|
-
OpenStruct.new(name: 'Winefrey, Oprah', roles: %w(Host Producer)),
|
84
|
-
OpenStruct.new(name: 'Kittenz, Emergency')
|
85
|
-
]
|
86
|
-
)
|
87
|
-
end
|
88
|
-
|
89
|
-
describe '#mods_name_field' do
|
90
|
-
it 'should join the label and values' do
|
91
|
-
name = mods_name_field(name_field) do |name|
|
92
|
-
link_to(name, searches_path(q: "\"#{name}\"", search_field: 'search_author'))
|
93
|
-
end
|
94
|
-
expect(name).to match /<dt>Contributor<\/dt>/
|
95
|
-
expect(name).to match /<dd><a href.*<\/dd>/
|
96
|
-
end
|
97
|
-
it 'should not print empty labels' do
|
98
|
-
expect(mods_name_field(empty_field)).not_to be_present
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe '#mods_display_name' do
|
103
|
-
let(:name) do
|
104
|
-
mods_display_name(name_field.values) do |name|
|
105
|
-
link_to(name, searches_path(q: "\"#{name}\"", search_field: 'search_author'))
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should link to the name' do
|
110
|
-
expect(name).to match /<a href=.*%22Winefrey%2C\+Oprah%22.*>Winefrey, Oprah<\/a>/
|
111
|
-
expect(name).to match /<a href=.*%22Kittenz%2C\+Emergency%22.*>Kittenz, Emergency<\/a>/
|
112
|
-
end
|
113
|
-
it 'should link to an author search' do
|
114
|
-
expect(name).to match /<a href.*search_field=search_author.*>/
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '#sanitize_mods_name_label' do
|
119
|
-
it 'removes a ":" at the end of label if present' do
|
120
|
-
expect(sanitize_mods_name_label('Test String:')).to eq 'Test String'
|
121
|
-
expect(sanitize_mods_name_label('Test String')).to eq 'Test String'
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe 'subjects' do
|
127
|
-
let(:subjects) { [OpenStruct.new(label: 'Subjects', values: [%w(Subject1a Subject1b), %w(Subject2a Subject2b Subject2c)])] }
|
128
|
-
let(:name_subjects) { [OpenStruct.new(label: 'Subjects', values: [OpenStruct.new(name: 'Person Name', roles: %w(Role1 Role2))])] }
|
129
|
-
let(:genres) { [OpenStruct.new(label: 'Genres', values: %w(Genre1 Genre2 Genre3))] }
|
130
|
-
|
131
|
-
describe '#mods_subject_field' do
|
132
|
-
let(:subject) do
|
133
|
-
mods_subject_field(subjects.first) do |subject_text|
|
134
|
-
link_to(
|
135
|
-
subject_text,
|
136
|
-
searches_path(
|
137
|
-
q: "\"#{[[], subject_text.strip].flatten.join(' ')}\"",
|
138
|
-
search_field: 'subject_terms'
|
139
|
-
)
|
140
|
-
)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
it 'should join the subject fields in a dd' do
|
144
|
-
expect(subject).to match /<dd><a href=*.*\">Subject1a*.*Subject1b<\/a><\/dd><dd><a/
|
145
|
-
end
|
146
|
-
it "should join the individual subjects with a '>'" do
|
147
|
-
expect(subject).to match /Subject2b<\/a> > <a href/
|
148
|
-
end
|
149
|
-
it 'should not print empty labels' do
|
150
|
-
expect(mods_subject_field(empty_field)).not_to be_present
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
describe '#mods_genre_field' do
|
155
|
-
it 'should join the genre fields with a dd' do
|
156
|
-
expect(mods_genre_field(genres.first) do |text|
|
157
|
-
link_to(text, searches_path(q: text))
|
158
|
-
end).to match /<dd><a href=*.*>Genre1*.*<\/a><\/dd><dd><a*.*Genre2<\/a><\/dd>/
|
159
|
-
end
|
160
|
-
it 'should not print empty labels' do
|
161
|
-
expect(mods_genre_field(empty_field)).not_to be_present
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
describe '#link_mods_subjects' do
|
166
|
-
let(:linked_subjects) do
|
167
|
-
link_mods_subjects(subjects.first.values.last) do |subject_text, buffer|
|
168
|
-
link_to(
|
169
|
-
subject_text,
|
170
|
-
searches_path(
|
171
|
-
q: "\"#{[buffer, subject_text.strip].flatten.join(' ')}\"",
|
172
|
-
search_field: 'subject_terms'
|
173
|
-
)
|
174
|
-
)
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should return all subjects' do
|
179
|
-
expect(linked_subjects.length).to eq 3
|
180
|
-
end
|
181
|
-
it 'should link to the subject hierarchically' do
|
182
|
-
expect(linked_subjects[0]).to match /^<a href=.*q=%22Subject2a%22.*>Subject2a<\/a>$/
|
183
|
-
expect(linked_subjects[1]).to match /^<a href=.*q=%22Subject2a\+Subject2b%22.*>Subject2b<\/a>$/
|
184
|
-
expect(linked_subjects[2]).to match /^<a href=.*q=%22Subject2a\+Subject2b\+Subject2c%22.*>Subject2c<\/a>$/
|
185
|
-
end
|
186
|
-
it 'should link to subject terms search field' do
|
187
|
-
linked_subjects.each do |subject|
|
188
|
-
expect(subject).to match /search_field=subject_terms/
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe '#link_mods_genres' do
|
194
|
-
let(:linked_genres) do
|
195
|
-
link_mods_genres(genres.first.values.last) do |text|
|
196
|
-
link_to(
|
197
|
-
text,
|
198
|
-
searches_path(
|
199
|
-
q: "\"#{[[], text.strip].flatten.join(' ')}\"",
|
200
|
-
search_field: 'subject_terms'
|
201
|
-
)
|
202
|
-
)
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'should return correct link' do
|
207
|
-
expect(linked_genres).to match /<a href=*.*Genre3*.*<\/a>/
|
208
|
-
end
|
209
|
-
it 'should link to subject terms search field' do
|
210
|
-
expect(linked_genres).to match /search_field=subject_terms/
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe '#link_to_mods_subject' do
|
215
|
-
it 'should handle subjects that behave like names' do
|
216
|
-
name_subject = link_to_mods_subject(name_subjects.first.values.first, []) do |subject_text|
|
217
|
-
link_to(
|
218
|
-
subject_text,
|
219
|
-
searches_path(
|
220
|
-
q: "\"#{[[], subject_text.strip].flatten.join(' ')}\"",
|
221
|
-
search_field: 'subject_terms'
|
222
|
-
)
|
223
|
-
)
|
224
|
-
end
|
225
|
-
expect(name_subject).to match /<a href=.*%22Person\+Name%22.*>Person Name<\/a> \(Role1, Role2\)/
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
describe '#link_urls_and_email' do
|
231
|
-
let(:url) { 'This is a field that contains an https://library.stanford.edu URL' }
|
232
|
-
let(:email) { 'This is a field that contains an email@email.com address' }
|
233
|
-
|
234
|
-
it 'should link URLs' do
|
235
|
-
expect(link_urls_and_email(url)).to eq "This is a field that contains an <a href='https://library.stanford.edu'>https://library.stanford.edu</a> URL"
|
236
|
-
end
|
237
|
-
it 'should link email addresses' do
|
238
|
-
expect(link_urls_and_email(email)).to eq "This is a field that contains an <a href='mailto:email@email.com'>email@email.com</a> address"
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class TestNoConfigController
|
4
|
-
include ModsDisplay::ControllerExtension
|
5
|
-
end
|
6
|
-
|
7
|
-
class TestConfigController
|
8
|
-
include ModsDisplay::ControllerExtension
|
9
|
-
|
10
|
-
configure_mods_display do
|
11
|
-
title do
|
12
|
-
label_class 'label-class'
|
13
|
-
value_class 'value-class'
|
14
|
-
link :link_to_title, '%value%'
|
15
|
-
end
|
16
|
-
contact do
|
17
|
-
ignore!
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def link_to_title(title)
|
22
|
-
"/path/to/title?#{title}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'Configuration' do
|
27
|
-
before(:all) do
|
28
|
-
xml = "<mods>
|
29
|
-
<titleInfo><title>The Title of this Item</title></titleInfo>
|
30
|
-
<note type='contact'>jdoe@example.com</note>
|
31
|
-
</mods>"
|
32
|
-
model = TestModel.new
|
33
|
-
model.modsxml = xml
|
34
|
-
@no_config_controller = TestNoConfigController.new
|
35
|
-
@config_controller = TestConfigController.new
|
36
|
-
@html = @config_controller.render_mods_display(model)
|
37
|
-
end
|
38
|
-
it 'should apply the label class' do
|
39
|
-
expect(@html).to match(/<dt class='label-class' title=/)
|
40
|
-
end
|
41
|
-
it 'should apply the value class' do
|
42
|
-
expect(@html.scan(/<dd class='value-class'>/).length).to eq(1)
|
43
|
-
end
|
44
|
-
it 'should apply the link' do
|
45
|
-
@html.scan(%r{<a href='/path/to/title\?The Title of this Item'>The Title of this Item</a>})
|
46
|
-
end
|
47
|
-
it 'should ignore fields if requested' do
|
48
|
-
expect(@html.scan(/jdoe@example\.com/).length).to eq(0)
|
49
|
-
end
|
50
|
-
it 'should get overriden configurations' do
|
51
|
-
expect(@no_config_controller.mods_display_config.contact.ignore?).to be false
|
52
|
-
expect(@config_controller.mods_display_config.contact.ignore?).to be true
|
53
|
-
end
|
54
|
-
it 'should get default configurations when no controller configuration is supplied' do
|
55
|
-
expect(@no_config_controller.mods_display_config.note.delimiter).to eq('<br/>')
|
56
|
-
end
|
57
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
def html_from_mods(xml, locale = nil)
|
5
|
-
model = TestModel.new
|
6
|
-
model.modsxml = xml
|
7
|
-
I18n.locale = locale if locale
|
8
|
-
I18n.fallbacks[:fr] = [:fr, :en]
|
9
|
-
TestController.new.render_mods_display(model)
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'HTML Output' do
|
13
|
-
before(:all) do
|
14
|
-
@multiple_titles = html_from_mods(
|
15
|
-
<<-MODS
|
16
|
-
<mods>
|
17
|
-
<titleInfo>
|
18
|
-
<title>Main Title</title>
|
19
|
-
</titleInfo>
|
20
|
-
<titleInfo type='alternative'>
|
21
|
-
<title>Alternate Title</title>
|
22
|
-
</titleInfo>
|
23
|
-
</mods>
|
24
|
-
MODS
|
25
|
-
)
|
26
|
-
@abstract = html_from_mods("<mods><abstract>Hey. I'm an abstract.</abstract></mods>")
|
27
|
-
mods = "<mods><titleInfo><title>Main Title</title></titleInfo><abstract>Hey. I'm an abstract.</abstract></mods>"
|
28
|
-
@mods = html_from_mods(mods)
|
29
|
-
@fr_mods = html_from_mods(mods, :fr)
|
30
|
-
end
|
31
|
-
after(:all) do
|
32
|
-
I18n.locale = :en
|
33
|
-
end
|
34
|
-
describe 'i18n' do
|
35
|
-
it 'should get the default english translations' do
|
36
|
-
expect(@mods.to_html).to match(%r{<dt title='Title'>Title:</dt>})
|
37
|
-
end
|
38
|
-
it 'should internationalize the labels when translations are available' do
|
39
|
-
expect(@fr_mods.to_html).to match(%r{<dt title='Résumé'>Résumé :</dt>})
|
40
|
-
end
|
41
|
-
it 'should get fallback to the default english translations if a translation is missing' do
|
42
|
-
expect(@fr_mods.to_html).to match(%r{<dt title='Title'>Title:</dt>})
|
43
|
-
end
|
44
|
-
end
|
45
|
-
describe 'titles' do
|
46
|
-
it 'should include both titles it regular display' do
|
47
|
-
expect(@multiple_titles.to_html).to include('<dd>Main Title</dd>')
|
48
|
-
expect(@multiple_titles.to_html).to include('<dd>Alternate Title</dd>')
|
49
|
-
end
|
50
|
-
it 'should return just the first title in the #title method' do
|
51
|
-
expect(@multiple_titles.title).to eq(['Main Title'])
|
52
|
-
end
|
53
|
-
it 'should omit the first title and return any remaining titles in the #body' do
|
54
|
-
expect(@multiple_titles.body).not_to include('<dd>Main Title</dd>')
|
55
|
-
expect(@multiple_titles.body).to include('<dd>Alternate Title</dd>')
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should allow access to the subTitle independently from the title (for use with #body or fields)' do
|
59
|
-
sub_title = @multiple_titles.subTitle
|
60
|
-
expect(sub_title.length).to eq 1
|
61
|
-
expect(sub_title.first).to be_a ModsDisplay::Values
|
62
|
-
expect(sub_title.first.label).to match(/^Alternative title/i)
|
63
|
-
expect(sub_title.first.values).to eq(['Alternate Title'])
|
64
|
-
end
|
65
|
-
end
|
66
|
-
describe 'individual fields' do
|
67
|
-
it 'should return ModsDispaly::Values for the specefied field' do
|
68
|
-
fields = @abstract.abstract
|
69
|
-
fields.each do |field|
|
70
|
-
expect(field).to be_a ModsDisplay::Values
|
71
|
-
end
|
72
|
-
expect(fields.length).to eq 1
|
73
|
-
expect(fields.first.values).to eq ["Hey. I'm an abstract."]
|
74
|
-
end
|
75
|
-
it 'should return a blank array if no data is available for a specific field' do
|
76
|
-
expect(@abstract.genre).to eq []
|
77
|
-
end
|
78
|
-
it "should not return a field that doesn't exist (and isn't a string)" do
|
79
|
-
expect { @abstract.not_a_real_field }.to raise_error NoMethodError
|
80
|
-
end
|
81
|
-
end
|
82
|
-
describe 'individual fields' do
|
83
|
-
it 'should return ModsDispaly::Class when raw is specified' do
|
84
|
-
expect(@abstract.abstract(raw: true)).to be_a ModsDisplay::Abstract
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Installation' do
|
4
|
-
before(:all) do
|
5
|
-
@pieces_of_data = 1
|
6
|
-
title_xml = '<mods><titleInfo><title>The Title of this Item</title></titleInfo></mods>'
|
7
|
-
model = TestModel.new
|
8
|
-
model.modsxml = title_xml
|
9
|
-
controller = TestController.new
|
10
|
-
@html = controller.render_mods_display(model)
|
11
|
-
end
|
12
|
-
it 'should return a single <dl>' do
|
13
|
-
expect(@html.scan(/<dl>/).length).to eq(1)
|
14
|
-
expect(@html.scan(%r{</dl>}).length).to eq(1)
|
15
|
-
end
|
16
|
-
it 'should return a dt/dd pair for each piece of metadata in the mods' do
|
17
|
-
expect(@html.scan(/<dt/).length).to eq(@pieces_of_data)
|
18
|
-
expect(@html.scan(/<dd>/).length).to eq(@pieces_of_data)
|
19
|
-
end
|
20
|
-
it 'should return a proper label' do
|
21
|
-
expect(@html.scan(%r{<dt title='Title'>Title:</dt>}).length).to eq(1)
|
22
|
-
end
|
23
|
-
it 'should return a proper value' do
|
24
|
-
expect(@html.scan(%r{<dd>The Title of this Item</dd>}).length).to eq(1)
|
25
|
-
end
|
26
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
ENV['RAILS_ENV'] ||= 'test'
|
2
|
-
require 'mods_display'
|
3
|
-
require 'stanford-mods'
|
4
|
-
require 'capybara'
|
5
|
-
require 'rails'
|
6
|
-
require 'fake_app'
|
7
|
-
require 'rspec/rails'
|
8
|
-
require 'mods_display/helpers/record_helper'
|
9
|
-
|
10
|
-
Dir["#{File.expand_path('..', __FILE__)}/fixtures/*.rb"].each { |file| require file }
|
11
|
-
# Load i18n test file.
|
12
|
-
# We don't have any reliable translations yet so this
|
13
|
-
# just make sure that we're handling i18n properly.
|
14
|
-
I18n.load_path += Dir["#{File.expand_path('../..', __FILE__)}/spec/test_fr.yml"]
|
15
|
-
I18n.backend.load_translations
|
16
|
-
|
17
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
18
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
19
|
-
# Require this file using `require "spec_helper"` to ensure that it is only
|
20
|
-
# loaded once.
|
21
|
-
#
|
22
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
23
|
-
RSpec.configure do |config|
|
24
|
-
config.run_all_when_everything_filtered = true
|
25
|
-
config.filter_run :focus
|
26
|
-
|
27
|
-
# Run specs in random order to surface order dependencies. If you find an
|
28
|
-
# order dependency and want to debug it, you can fix the order by providing
|
29
|
-
# the seed, which is printed after each run.
|
30
|
-
# --seed 1234
|
31
|
-
config.order = 'random'
|
32
|
-
config.include Rails.application.routes.url_helpers
|
33
|
-
end
|
34
|
-
class TestModel
|
35
|
-
attr_accessor :modsxml
|
36
|
-
include ModsDisplay::ModelExtension
|
37
|
-
mods_xml_source(&:modsxml)
|
38
|
-
end
|
39
|
-
|
40
|
-
class TestController
|
41
|
-
include ModsDisplay::ControllerExtension
|
42
|
-
|
43
|
-
def link_method(val)
|
44
|
-
"http://library.stanford.edu?#{val}"
|
45
|
-
end
|
46
|
-
end
|
data/spec/test_fr.yml
DELETED