meta-tags 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -1
- data/.travis.yml +7 -13
- data/CHANGELOG.md +18 -0
- data/Gemfile +5 -0
- data/README.md +163 -71
- data/Rakefile +2 -2
- data/lib/meta_tags.rb +18 -0
- data/lib/meta_tags/configuration.rb +21 -0
- data/lib/meta_tags/meta_tags_collection.rb +5 -10
- data/lib/meta_tags/renderer.rb +114 -37
- data/lib/meta_tags/text_normalizer.rb +71 -6
- data/lib/meta_tags/version.rb +1 -1
- data/lib/meta_tags/view_helper.rb +12 -11
- data/meta-tags.gemspec +2 -1
- data/spec/configuration_spec.rb +14 -0
- data/spec/controller_helper_spec.rb +4 -4
- data/spec/spec_helper.rb +69 -13
- data/spec/text_normalizer/normalize_title_spec.rb +43 -0
- data/spec/text_normalizer/truncate_array_spec.rb +60 -0
- data/spec/view_helper/charset_spec.rb +16 -0
- data/spec/view_helper/custom_spec.rb +67 -0
- data/spec/view_helper/description_spec.rb +61 -0
- data/spec/view_helper/icon_spec.rb +42 -0
- data/spec/view_helper/keywords_spec.rb +58 -0
- data/spec/view_helper/links_spec.rb +125 -0
- data/spec/view_helper/module_spec.rb +41 -0
- data/spec/view_helper/noindex_spec.rb +107 -0
- data/spec/view_helper/open_graph_spec.rb +86 -0
- data/spec/view_helper/open_search_spec.rb +33 -0
- data/spec/view_helper/refresh_spec.rb +32 -0
- data/spec/view_helper/title_spec.rb +155 -0
- data/spec/view_helper/twitter_spec.rb +31 -0
- data/spec/view_helper_spec.rb +57 -0
- metadata +53 -21
- data/spec/meta_tags_spec.rb +0 -570
data/spec/meta_tags_spec.rb
DELETED
@@ -1,570 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MetaTags::ViewHelper do
|
4
|
-
subject { ActionView::Base.new }
|
5
|
-
|
6
|
-
context 'module' do
|
7
|
-
it 'should be mixed into ActionView::Base' do
|
8
|
-
ActionView::Base.included_modules.should include(MetaTags::ViewHelper)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should respond to "title" helper' do
|
12
|
-
subject.should respond_to(:title)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should respond to "description" helper' do
|
16
|
-
subject.should respond_to(:description)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should respond to "keywords" helper' do
|
20
|
-
subject.should respond_to(:keywords)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should respond to "noindex" helper' do
|
24
|
-
subject.should respond_to(:noindex)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should respond to "nofollow" helper' do
|
28
|
-
subject.should respond_to(:nofollow)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should respond to "set_meta_tags" helper' do
|
32
|
-
subject.should respond_to(:set_meta_tags)
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should respond to "display_meta_tags" helper' do
|
36
|
-
subject.should respond_to(:display_meta_tags)
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should respond to "display_title" helper' do
|
40
|
-
subject.should respond_to(:display_title)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'returning values' do
|
45
|
-
it 'should return title' do
|
46
|
-
subject.title('some-title').should eq('some-title')
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'should return headline if specified' do
|
50
|
-
subject.title('some-title', 'some-headline').should eq('some-headline')
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should return title' do
|
54
|
-
subject.title('some-title').should eq('some-title')
|
55
|
-
subject.title.should eq('some-title')
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should return description' do
|
59
|
-
subject.description('some-description').should eq('some-description')
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should return keywords' do
|
63
|
-
subject.keywords('some-keywords').should eq('some-keywords')
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should return noindex' do
|
67
|
-
subject.noindex('some-noindex').should eq('some-noindex')
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should return nofollow' do
|
71
|
-
subject.noindex('some-nofollow').should eq('some-nofollow')
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'displaying title' do
|
76
|
-
it 'should not display title if blank' do
|
77
|
-
subject.display_meta_tags.should eq('')
|
78
|
-
subject.title('')
|
79
|
-
subject.display_meta_tags.should eq('')
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'should use website name if title is empty' do
|
83
|
-
subject.display_meta_tags(:site => 'someSite').should eq('<title>someSite</title>')
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should display title when "title" used' do
|
87
|
-
subject.title('someTitle')
|
88
|
-
subject.display_meta_tags(:site => 'someSite').should eq('<title>someSite | someTitle</title>')
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should display title only when "site" is empty' do
|
92
|
-
subject.title('someTitle')
|
93
|
-
subject.display_meta_tags.should eq('<title>someTitle</title>')
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'should display title when "set_meta_tags" used' do
|
97
|
-
subject.set_meta_tags(:title => 'someTitle')
|
98
|
-
subject.display_meta_tags(:site => 'someSite').should eq('<title>someSite | someTitle</title>')
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should display custom title if given' do
|
102
|
-
subject.title('someTitle')
|
103
|
-
subject.display_meta_tags(:site => 'someSite', :title => 'defaultTitle').should eq('<title>someSite | someTitle</title>')
|
104
|
-
end
|
105
|
-
|
106
|
-
it 'should use website before page by default' do
|
107
|
-
subject.display_meta_tags(:site => 'someSite', :title => 'someTitle').should eq('<title>someSite | someTitle</title>')
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should only use markup in titles in the view' do
|
111
|
-
subject.title('<b>someTitle</b>').should eq('<b>someTitle</b>')
|
112
|
-
subject.display_meta_tags(:site => 'someSite').should eq('<title>someSite | someTitle</title>')
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'should use page before website if :reverse' do
|
116
|
-
subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :reverse => true).should eq('<title>someTitle | someSite</title>')
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'should be lowercase if :lowercase' do
|
120
|
-
subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :lowercase => true).should eq('<title>someSite | sometitle</title>')
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should use custom separator if :separator' do
|
124
|
-
subject.title('someTitle')
|
125
|
-
subject.display_meta_tags(:site => 'someSite', :separator => '-').should eq('<title>someSite - someTitle</title>')
|
126
|
-
subject.display_meta_tags(:site => 'someSite', :separator => ':').should eq('<title>someSite : someTitle</title>')
|
127
|
-
subject.display_meta_tags(:site => 'someSite', :separator => '—').should eq('<title>someSite &mdash; someTitle</title>')
|
128
|
-
subject.display_meta_tags(:site => 'someSite', :separator => '—'.html_safe).should eq('<title>someSite — someTitle</title>')
|
129
|
-
subject.display_meta_tags(:site => 'someSite: ', :separator => false).should eq('<title>someSite: someTitle</title>')
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should use custom prefix and suffix if available' do
|
133
|
-
subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => ' -', :suffix => '- ').should eq('<title>someSite -|- someTitle</title>')
|
134
|
-
end
|
135
|
-
|
136
|
-
it 'should collapse prefix if false' do
|
137
|
-
subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :prefix => false).should eq('<title>someSite| someTitle</title>')
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should collapse suffix if false' do
|
141
|
-
subject.display_meta_tags(:site => 'someSite', :title => 'someTitle', :suffix => false).should eq('<title>someSite |someTitle</title>')
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'should use all custom options if available' do
|
145
|
-
subject.display_meta_tags(:site => 'someSite',
|
146
|
-
:title => 'someTitle',
|
147
|
-
:prefix => ' -',
|
148
|
-
:suffix => '+ ',
|
149
|
-
:separator => ':',
|
150
|
-
:lowercase => true,
|
151
|
-
:reverse => true).should eq('<title>sometitle -:+ someSite</title>')
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'should allow Arrays in title' do
|
155
|
-
subject.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle']).should eq('<title>someSite | someTitle | anotherTitle</title>')
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'should allow Arrays in title with :lowercase' do
|
159
|
-
subject.display_meta_tags(:site => 'someSite', :title => ['someTitle', 'anotherTitle'], :lowercase => true).should eq('<title>someSite | sometitle | anothertitle</title>')
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should build title in reverse order if :reverse' do
|
163
|
-
subject.display_meta_tags(:site => 'someSite',
|
164
|
-
:title => ['someTitle', 'anotherTitle'],
|
165
|
-
:prefix => ' -',
|
166
|
-
:suffix => '+ ',
|
167
|
-
:separator => ':',
|
168
|
-
:reverse => true).should eq('<title>anotherTitle -:+ someTitle -:+ someSite</title>')
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
context 'displaying description' do
|
173
|
-
it 'should not display description if blank' do
|
174
|
-
subject.description('')
|
175
|
-
subject.display_meta_tags.should eq('')
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'should display description when "description" used' do
|
179
|
-
subject.description('someDescription')
|
180
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="someDescription" name="description" />')
|
181
|
-
end
|
182
|
-
|
183
|
-
it 'should display description when "set_meta_tags" used' do
|
184
|
-
subject.set_meta_tags(:description => 'someDescription')
|
185
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="someDescription" name="description" />')
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'should display default description' do
|
189
|
-
subject.display_meta_tags(:site => 'someSite', :description => 'someDescription').should include('<meta content="someDescription" name="description" />')
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'should use custom description if given' do
|
193
|
-
subject.description('someDescription')
|
194
|
-
subject.display_meta_tags(:site => 'someSite', :description => 'defaultDescription').should include('<meta content="someDescription" name="description" />')
|
195
|
-
end
|
196
|
-
|
197
|
-
it 'should strip multiple spaces' do
|
198
|
-
subject.display_meta_tags(:site => 'someSite', :description => "some \n\r\t description").should include('<meta content="some description" name="description" />')
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'should strip HTML' do
|
202
|
-
subject.display_meta_tags(:site => 'someSite', :description => "<p>some <b>description</b></p>").should include('<meta content="some description" name="description" />')
|
203
|
-
end
|
204
|
-
|
205
|
-
it 'should truncate correctly' do
|
206
|
-
subject.display_meta_tags(:site => 'someSite', :description => "Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.").should include('<meta content="Lorem ipsum dolor sit amet, consectetuer sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dol..." name="description" />')
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
context 'displaying keywords' do
|
211
|
-
it 'should not display keywords if blank' do
|
212
|
-
subject.keywords('')
|
213
|
-
subject.display_meta_tags.should eq('')
|
214
|
-
|
215
|
-
subject.keywords([])
|
216
|
-
subject.display_meta_tags.should eq('')
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'should display keywords when "keywords" used' do
|
220
|
-
subject.keywords('some-keywords')
|
221
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="some-keywords" name="keywords" />')
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'should display keywords when "set_meta_tags" used' do
|
225
|
-
subject.set_meta_tags(:keywords => 'some-keywords')
|
226
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="some-keywords" name="keywords" />')
|
227
|
-
end
|
228
|
-
|
229
|
-
it 'should display default keywords' do
|
230
|
-
subject.display_meta_tags(:site => 'someSite', :keywords => 'some-keywords').should include('<meta content="some-keywords" name="keywords" />')
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'should use custom keywords if given' do
|
234
|
-
subject.keywords('some-keywords')
|
235
|
-
subject.display_meta_tags(:site => 'someSite', :keywords => 'default_keywords').should include('<meta content="some-keywords" name="keywords" />')
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'should lowercase keywords' do
|
239
|
-
subject.display_meta_tags(:site => 'someSite', :keywords => 'someKeywords').should include('<meta content="somekeywords" name="keywords" />')
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'should join keywords from Array' do
|
243
|
-
subject.display_meta_tags(:site => 'someSite', :keywords => %w(keyword1 keyword2)).should include('<meta content="keyword1, keyword2" name="keywords" />')
|
244
|
-
end
|
245
|
-
|
246
|
-
it 'should join keywords from nested Arrays' do
|
247
|
-
subject.display_meta_tags(:site => 'someSite', :keywords => [%w(keyword1 keyword2), 'keyword3']).should include('<meta content="keyword1, keyword2, keyword3" name="keywords" />')
|
248
|
-
end
|
249
|
-
end
|
250
|
-
|
251
|
-
context 'displaying refresh' do
|
252
|
-
it 'displays refresh when "refresh" is used' do
|
253
|
-
subject.refresh(5)
|
254
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="5" http-equiv="refresh" />')
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'displays refresh when "set_meta_tags" used' do
|
258
|
-
subject.set_meta_tags(:refresh => 5)
|
259
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="5" http-equiv="refresh" />')
|
260
|
-
end
|
261
|
-
|
262
|
-
it 'should use custom refresh if given' do
|
263
|
-
subject.refresh("5;url=http://example.com/")
|
264
|
-
subject.display_meta_tags(:site => 'someSite').should include(%Q{<meta content="5;url=http://example.com/" http-equiv="refresh" />})
|
265
|
-
end
|
266
|
-
|
267
|
-
it 'should display nothing by default' do
|
268
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('http-equiv="refresh"')
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
context 'displaying noindex' do
|
273
|
-
it 'should display noindex when "noindex" used' do
|
274
|
-
subject.noindex(true)
|
275
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex" name="robots" />')
|
276
|
-
end
|
277
|
-
|
278
|
-
it 'should display noindex when "set_meta_tags" used' do
|
279
|
-
subject.set_meta_tags(:noindex => true)
|
280
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex" name="robots" />')
|
281
|
-
end
|
282
|
-
|
283
|
-
it 'should use custom noindex if given' do
|
284
|
-
subject.noindex('some-noindex')
|
285
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex" name="some-noindex" />')
|
286
|
-
end
|
287
|
-
|
288
|
-
it 'should display nothing by default' do
|
289
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('<meta content="noindex"')
|
290
|
-
end
|
291
|
-
|
292
|
-
it "should display nothing if given false" do
|
293
|
-
subject.set_meta_tags(:noindex => false)
|
294
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('<meta content="robots"')
|
295
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('<meta content="noindex"')
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
context 'displaying nofollow' do
|
300
|
-
it 'should display nofollow when "nofollow" used' do
|
301
|
-
subject.nofollow(true)
|
302
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="nofollow" name="robots" />')
|
303
|
-
end
|
304
|
-
|
305
|
-
it 'should display nofollow when "set_meta_tags" used' do
|
306
|
-
subject.set_meta_tags(:nofollow => true)
|
307
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="nofollow" name="robots" />')
|
308
|
-
end
|
309
|
-
|
310
|
-
it 'should use custom nofollow if given' do
|
311
|
-
subject.nofollow('some-nofollow')
|
312
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="nofollow" name="some-nofollow" />')
|
313
|
-
end
|
314
|
-
|
315
|
-
it 'should display nothing by default' do
|
316
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('<meta content="nofollow"')
|
317
|
-
end
|
318
|
-
end
|
319
|
-
|
320
|
-
context 'displaying both nofollow and noindex' do
|
321
|
-
it 'should be displayed when set using helpers' do
|
322
|
-
subject.noindex(true)
|
323
|
-
subject.nofollow(true)
|
324
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex, nofollow" name="robots" />')
|
325
|
-
end
|
326
|
-
|
327
|
-
it 'should be displayed when "set_meta_tags" used' do
|
328
|
-
subject.set_meta_tags(:nofollow => true, :noindex => true)
|
329
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex, nofollow" name="robots" />')
|
330
|
-
end
|
331
|
-
|
332
|
-
it 'should use custom name if string is used' do
|
333
|
-
subject.noindex('some-name')
|
334
|
-
subject.nofollow('some-name')
|
335
|
-
subject.display_meta_tags(:site => 'someSite').should include('<meta content="noindex, nofollow" name="some-name" />')
|
336
|
-
end
|
337
|
-
|
338
|
-
it 'should display two meta tags when different names used' do
|
339
|
-
subject.noindex('some-noindex')
|
340
|
-
subject.nofollow('some-nofollow')
|
341
|
-
subject.display_meta_tags(:site => 'someSite').tap do |content|
|
342
|
-
content.should include('<meta content="noindex" name="some-noindex" />')
|
343
|
-
content.should include('<meta content="nofollow" name="some-nofollow" />')
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
context 'displaying canonical url' do
|
349
|
-
it 'should not display canonical url by default' do
|
350
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('<link href="http://example.com/base/url" rel="canonical" />')
|
351
|
-
end
|
352
|
-
|
353
|
-
it 'should display canonical url when "set_meta_tags" used' do
|
354
|
-
subject.set_meta_tags(:canonical => 'http://example.com/base/url')
|
355
|
-
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://example.com/base/url" rel="canonical" />')
|
356
|
-
end
|
357
|
-
|
358
|
-
it 'should display default canonical url' do
|
359
|
-
subject.display_meta_tags(:site => 'someSite', :canonical => 'http://example.com/base/url').should include('<link href="http://example.com/base/url" rel="canonical" />')
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
context 'displaying alternate url' do
|
364
|
-
it 'should not display alternate url by default' do
|
365
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('<link href="http://example.fr/base/url" hreflang="fr" rel="alternate" />')
|
366
|
-
end
|
367
|
-
|
368
|
-
it 'should display alternate url when "set_meta_tags" used' do
|
369
|
-
subject.set_meta_tags(:alternate => { 'fr' => 'http://example.fr/base/url' })
|
370
|
-
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://example.fr/base/url" hreflang="fr" rel="alternate" />')
|
371
|
-
end
|
372
|
-
|
373
|
-
it 'should display default alternate url' do
|
374
|
-
subject.display_meta_tags(:site => 'someSite', :alternate => { 'fr' => 'http://example.fr/base/url' }).should include('<link href="http://example.fr/base/url" hreflang="fr" rel="alternate" />')
|
375
|
-
end
|
376
|
-
|
377
|
-
it "should not display alternate without content" do
|
378
|
-
subject.display_meta_tags(:site => 'someSite', :alternate => {'zh-Hant' => ''}).should_not include('<link href="" hreflang="zh-Hant" rel="alternate" />')
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
context 'displaying author link' do
|
383
|
-
it 'should display author link when "set_meta_tags" used' do
|
384
|
-
subject.set_meta_tags(:author => 'http://plus.google.com/profile/url')
|
385
|
-
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://plus.google.com/profile/url" rel="author" />')
|
386
|
-
end
|
387
|
-
end
|
388
|
-
|
389
|
-
context 'displaying publisher link' do
|
390
|
-
it 'should display publisher link when "set_meta_tags" used' do
|
391
|
-
subject.set_meta_tags(:publisher => 'http://plus.google.com/myprofile_url')
|
392
|
-
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://plus.google.com/myprofile_url" rel="publisher" />')
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
context 'displaying prev url' do
|
397
|
-
it 'should not display prev url by default' do
|
398
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('<link href="http://example.com/base/url" rel="prev" />')
|
399
|
-
end
|
400
|
-
|
401
|
-
it 'should display prev url when "set_meta_tags" used' do
|
402
|
-
subject.set_meta_tags(:prev => 'http://example.com/base/url')
|
403
|
-
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://example.com/base/url" rel="prev" />')
|
404
|
-
end
|
405
|
-
|
406
|
-
it 'should display default prev url' do
|
407
|
-
subject.display_meta_tags(:site => 'someSite', :prev => 'http://example.com/base/url').should include('<link href="http://example.com/base/url" rel="prev" />')
|
408
|
-
end
|
409
|
-
end
|
410
|
-
|
411
|
-
context 'displaying next url' do
|
412
|
-
it 'should not display next url by default' do
|
413
|
-
subject.display_meta_tags(:site => 'someSite').should_not include('<link href="http://example.com/base/url" rel="next" />')
|
414
|
-
end
|
415
|
-
|
416
|
-
it 'should display next url when "set_meta_tags" used' do
|
417
|
-
subject.set_meta_tags(:next => 'http://example.com/base/url')
|
418
|
-
subject.display_meta_tags(:site => 'someSite').should include('<link href="http://example.com/base/url" rel="next" />')
|
419
|
-
end
|
420
|
-
|
421
|
-
it 'should display default next url' do
|
422
|
-
subject.display_meta_tags(:site => 'someSite', :next => 'http://example.com/base/url').should include('<link href="http://example.com/base/url" rel="next" />')
|
423
|
-
end
|
424
|
-
end
|
425
|
-
|
426
|
-
context 'displaying Open Graph meta tags' do
|
427
|
-
it 'should display meta tags specified with :open_graph' do
|
428
|
-
subject.set_meta_tags(:open_graph => {
|
429
|
-
:title => 'Facebook Share Title',
|
430
|
-
:description => 'Facebook Share Description'
|
431
|
-
})
|
432
|
-
subject.display_meta_tags(:site => 'someSite').tap do |content|
|
433
|
-
content.should include('<meta content="Facebook Share Title" property="og:title" />')
|
434
|
-
content.should include('<meta content="Facebook Share Description" property="og:description" />')
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
438
|
-
it 'should display meta tags specified with :og' do
|
439
|
-
subject.set_meta_tags(:og => {
|
440
|
-
:title => 'Facebook Share Title',
|
441
|
-
:description => 'Facebook Share Description'
|
442
|
-
})
|
443
|
-
subject.display_meta_tags(:site => 'someSite').tap do |content|
|
444
|
-
content.should include('<meta content="Facebook Share Title" property="og:title" />')
|
445
|
-
content.should include('<meta content="Facebook Share Description" property="og:description" />')
|
446
|
-
end
|
447
|
-
end
|
448
|
-
|
449
|
-
it 'should display meta tags with hashes and arrays' do
|
450
|
-
subject.set_meta_tags(:foo => {
|
451
|
-
:bar => "lorem",
|
452
|
-
:baz => {
|
453
|
-
:qux => ["lorem", "ipsum"]
|
454
|
-
},
|
455
|
-
:quux => [ {
|
456
|
-
:corge => "lorem",
|
457
|
-
:grault => "ipsum"
|
458
|
-
},
|
459
|
-
{
|
460
|
-
:corge => "dolor",
|
461
|
-
:grault => "sit"
|
462
|
-
} ]
|
463
|
-
})
|
464
|
-
subject.display_meta_tags(:site => 'someSite').tap do |content|
|
465
|
-
content.should include('<meta content="lorem" property="foo:bar" />')
|
466
|
-
content.should include('<meta content="lorem" property="foo:baz:qux" />')
|
467
|
-
content.should include('<meta content="ipsum" property="foo:baz:qux" />')
|
468
|
-
content.should include('<meta content="lorem" property="foo:quux:corge"')
|
469
|
-
content.should include('<meta content="ipsum" property="foo:quux:grault"')
|
470
|
-
content.should include('<meta content="dolor" property="foo:quux:corge"')
|
471
|
-
content.should include('<meta content="sit" property="foo:quux:grault"')
|
472
|
-
content.should_not include('property="foo:quux"')
|
473
|
-
end
|
474
|
-
end
|
475
|
-
|
476
|
-
it 'should use deep merge when displaying open graph meta tags' do
|
477
|
-
subject.set_meta_tags(:og => { :title => 'Facebook Share Title' })
|
478
|
-
subject.display_meta_tags(:og => { :description => 'Facebook Share Description' }).tap do |content|
|
479
|
-
content.should include('<meta content="Facebook Share Title" property="og:title" />')
|
480
|
-
content.should include('<meta content="Facebook Share Description" property="og:description" />')
|
481
|
-
end
|
482
|
-
end
|
483
|
-
|
484
|
-
it "should not display meta tags without content" do
|
485
|
-
subject.set_meta_tags(:open_graph => {
|
486
|
-
:title => '',
|
487
|
-
:description => ''
|
488
|
-
})
|
489
|
-
subject.display_meta_tags(:site => 'someSite').tap do |content|
|
490
|
-
content.should_not include('<meta content="" property="og:title" />')
|
491
|
-
content.should_not include('<meta content="" property="og:description" />')
|
492
|
-
end
|
493
|
-
end
|
494
|
-
|
495
|
-
it "should display mirrored content" do
|
496
|
-
subject.set_meta_tags(:title => 'someTitle')
|
497
|
-
subject.display_meta_tags(:open_graph => { :title => :title }).tap do |content|
|
498
|
-
content.should include('<meta content="someTitle" property="og:title" />')
|
499
|
-
end
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
context 'displaying Twitter meta tags' do
|
504
|
-
it 'should display meta tags specified with :twitter' do
|
505
|
-
subject.set_meta_tags(:twitter => {
|
506
|
-
:title => 'Twitter Share Title',
|
507
|
-
:card => 'photo',
|
508
|
-
:image => {
|
509
|
-
:_ => 'http://example.com/1.png',
|
510
|
-
:width => 123,
|
511
|
-
:height => 321,
|
512
|
-
}
|
513
|
-
})
|
514
|
-
subject.display_meta_tags(:site => 'someSite').tap do |content|
|
515
|
-
content.should include('<meta content="Twitter Share Title" name="twitter:title" />')
|
516
|
-
content.should include('<meta content="photo" name="twitter:card" />')
|
517
|
-
content.should include('<meta content="http://example.com/1.png" name="twitter:image" />')
|
518
|
-
content.should include('<meta content="123" name="twitter:image:width" />')
|
519
|
-
content.should include('<meta content="321" name="twitter:image:height" />')
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
it "should display mirrored content" do
|
524
|
-
subject.set_meta_tags(:title => 'someTitle')
|
525
|
-
subject.display_meta_tags(:twitter => { :title => :title }).tap do |content|
|
526
|
-
content.should include('<meta content="someTitle" name="twitter:title" />')
|
527
|
-
end
|
528
|
-
end
|
529
|
-
end
|
530
|
-
|
531
|
-
context 'while handling string meta tag names' do
|
532
|
-
it 'should work with common parameters' do
|
533
|
-
subject.display_meta_tags('site' => 'someSite', 'title' => 'someTitle').should eq('<title>someSite | someTitle</title>')
|
534
|
-
end
|
535
|
-
|
536
|
-
it 'should work with open graph parameters' do
|
537
|
-
subject.set_meta_tags('og' => {
|
538
|
-
'title' => 'facebook title',
|
539
|
-
'description' => 'facebook description'
|
540
|
-
})
|
541
|
-
subject.display_meta_tags(:site => 'someSite').tap do |content|
|
542
|
-
content.should include('<meta content="facebook title" property="og:title" />')
|
543
|
-
content.should include('<meta content="facebook description" property="og:description" />')
|
544
|
-
end
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
|
-
context '.display_title' do
|
549
|
-
it 'should display custom title if given' do
|
550
|
-
subject.title('someTitle')
|
551
|
-
subject.display_title(:site => 'someSite', :title => 'defaultTitle').should eq('someSite | someTitle')
|
552
|
-
end
|
553
|
-
end
|
554
|
-
|
555
|
-
context 'display any named meta tag that you want to' do
|
556
|
-
it 'should display testing meta tag' do
|
557
|
-
subject.display_meta_tags(:testing => 'this is a test').should eq('<meta content="this is a test" name="testing" />')
|
558
|
-
end
|
559
|
-
|
560
|
-
it 'should support Array values' do
|
561
|
-
subject.display_meta_tags(:testing => ['test1', 'test2']).should eq("<meta content=\"test1\" name=\"testing\" />\n<meta content=\"test2\" name=\"testing\" />")
|
562
|
-
end
|
563
|
-
|
564
|
-
it 'should not render when value is nil' do
|
565
|
-
subject.display_meta_tags(:testing => nil).should eq('')
|
566
|
-
end
|
567
|
-
end
|
568
|
-
|
569
|
-
it_behaves_like '.set_meta_tags'
|
570
|
-
end
|