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/lib/meta_tags/version.rb
CHANGED
@@ -20,8 +20,8 @@ module MetaTags
|
|
20
20
|
# for allowed options.
|
21
21
|
#
|
22
22
|
# @example
|
23
|
-
# set_meta_tags :
|
24
|
-
# set_meta_tags :
|
23
|
+
# set_meta_tags title: 'Login Page', description: 'Here you can login'
|
24
|
+
# set_meta_tags keywords: 'authorization, login'
|
25
25
|
#
|
26
26
|
# @see #display_meta_tags
|
27
27
|
#
|
@@ -47,14 +47,14 @@ module MetaTags
|
|
47
47
|
# @example Set HTML title to "Login Page", return "Please login"
|
48
48
|
# title 'Login Page', 'Please login'
|
49
49
|
# @example Set title as array of strings
|
50
|
-
# title :
|
50
|
+
# title title: ['part1', 'part2'] # => "part1 | part2"
|
51
51
|
# @example Get current title
|
52
52
|
# title
|
53
53
|
#
|
54
54
|
# @see #display_meta_tags
|
55
55
|
#
|
56
56
|
def title(title = nil, headline = '')
|
57
|
-
set_meta_tags(:
|
57
|
+
set_meta_tags(title: title) unless title.nil?
|
58
58
|
headline.blank? ? meta_tags[:title] : headline
|
59
59
|
end
|
60
60
|
|
@@ -71,7 +71,7 @@ module MetaTags
|
|
71
71
|
# @see #display_meta_tags
|
72
72
|
#
|
73
73
|
def keywords(keywords)
|
74
|
-
set_meta_tags(:
|
74
|
+
set_meta_tags(keywords: keywords)
|
75
75
|
keywords
|
76
76
|
end
|
77
77
|
|
@@ -89,7 +89,7 @@ module MetaTags
|
|
89
89
|
# @see #display_meta_tags
|
90
90
|
#
|
91
91
|
def description(description)
|
92
|
-
set_meta_tags(:
|
92
|
+
set_meta_tags(description: description)
|
93
93
|
description
|
94
94
|
end
|
95
95
|
|
@@ -105,7 +105,7 @@ module MetaTags
|
|
105
105
|
# @see #display_meta_tags
|
106
106
|
#
|
107
107
|
def noindex(noindex = true)
|
108
|
-
set_meta_tags(:
|
108
|
+
set_meta_tags(noindex: noindex)
|
109
109
|
noindex
|
110
110
|
end
|
111
111
|
|
@@ -121,7 +121,7 @@ module MetaTags
|
|
121
121
|
# @see #display_meta_tags
|
122
122
|
#
|
123
123
|
def nofollow(nofollow = true)
|
124
|
-
set_meta_tags(:
|
124
|
+
set_meta_tags(nofollow: nofollow)
|
125
125
|
nofollow
|
126
126
|
end
|
127
127
|
|
@@ -137,7 +137,7 @@ module MetaTags
|
|
137
137
|
# @see #display_meta_tags
|
138
138
|
#
|
139
139
|
def refresh(refresh)
|
140
|
-
set_meta_tags(:
|
140
|
+
set_meta_tags(refresh: refresh)
|
141
141
|
refresh
|
142
142
|
end
|
143
143
|
|
@@ -164,12 +164,13 @@ module MetaTags
|
|
164
164
|
# @option default [String] :publisher (nil) add publisher link tag.
|
165
165
|
# @option default [String, Integer] :refresh (nil) meta refresh tag;
|
166
166
|
# @option default [Hash] :open_graph ({}) add Open Graph meta tags.
|
167
|
+
# @option default [Hash] :open_search ({}) add Open Search link tag.
|
167
168
|
# @return [String] HTML meta tags to render in HEAD section of the
|
168
169
|
# HTML document.
|
169
170
|
#
|
170
171
|
# @example
|
171
172
|
# <head>
|
172
|
-
# <%= display_meta_tags :
|
173
|
+
# <%= display_meta_tags site: 'My website' %>
|
173
174
|
# </head>
|
174
175
|
#
|
175
176
|
def display_meta_tags(defaults = {})
|
@@ -193,7 +194,7 @@ module MetaTags
|
|
193
194
|
# @option default [Boolean] :reverse (false) when true, the page and site names will be reversed;
|
194
195
|
#
|
195
196
|
# @example
|
196
|
-
# <div data-page-container="true" title="<%= display_title :
|
197
|
+
# <div data-page-container="true" title="<%= display_title title: 'My Page', site: 'PJAX Site' %>">
|
197
198
|
#
|
198
199
|
def display_title(defaults = {})
|
199
200
|
@meta_tags.full_title(defaults)
|
data/meta-tags.gemspec
CHANGED
@@ -15,7 +15,8 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.add_dependency 'actionpack', '>= 3.0.0'
|
16
16
|
|
17
17
|
s.add_development_dependency 'rake'
|
18
|
-
s.add_development_dependency 'rspec'
|
18
|
+
s.add_development_dependency 'rspec', '~> 3.3.0'
|
19
|
+
s.add_development_dependency 'rspec-html-matchers'
|
19
20
|
s.add_development_dependency 'yard'
|
20
21
|
s.add_development_dependency 'bluecloth'
|
21
22
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::Configuration do
|
4
|
+
it 'should be returned by MetaTags.config' do
|
5
|
+
expect(MetaTags.config).to be_instance_of(MetaTags::Configuration)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should be yielded by MetaTags.configure' do
|
9
|
+
MetaTags.configure do |c|
|
10
|
+
expect(c).to be_instance_of(MetaTags::Configuration)
|
11
|
+
expect(c).to be(MetaTags.config)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -22,19 +22,19 @@ describe MetaTags::ControllerHelper do
|
|
22
22
|
|
23
23
|
context 'module' do
|
24
24
|
it 'should be mixed into ActionController::Base' do
|
25
|
-
ActionController::Base.included_modules.
|
25
|
+
expect(ActionController::Base.included_modules).to include(MetaTags::ControllerHelper)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should respond to "set_meta_tags" helper' do
|
29
|
-
subject.
|
29
|
+
expect(subject).to respond_to(:set_meta_tags)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe '.render' do
|
34
34
|
it 'should set meta tags from instance variables' do
|
35
35
|
subject.index
|
36
|
-
subject.rendered.
|
37
|
-
subject.meta_tags.meta_tags.
|
36
|
+
expect(subject.rendered).to be_truthy
|
37
|
+
expect(subject.meta_tags.meta_tags).to eq('title' => 'title', 'keywords' => 'key1, key2, key3', 'description' => 'description')
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,28 +1,84 @@
|
|
1
|
-
|
1
|
+
if ENV['CODECLIMATE_REPO_TOKEN'] && RUBY_VERSION > '1.8.7'
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
end
|
5
|
+
|
2
6
|
require 'meta_tags'
|
7
|
+
require 'rspec-html-matchers'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
if config.files_to_run.one?
|
11
|
+
# RSpec filters the backtrace by default so as not to be so noisy.
|
12
|
+
# This causes the full backtrace to be printed when running a single
|
13
|
+
# spec file (e.g. to troubleshoot a particular spec failure).
|
14
|
+
config.full_backtrace = true
|
15
|
+
|
16
|
+
# Use the documentation formatter for detailed output,
|
17
|
+
# unless a formatter has already been configured
|
18
|
+
# (e.g. via a command-line flag).
|
19
|
+
config.formatter = 'doc' if config.formatters.none?
|
20
|
+
end
|
21
|
+
|
22
|
+
# Run specs in random order to surface order dependencies. If you find an
|
23
|
+
# order dependency and want to debug it, you can fix the order by providing
|
24
|
+
# the seed, which is printed after each run.
|
25
|
+
# --seed 1234
|
26
|
+
config.order = :random
|
27
|
+
|
28
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
29
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
30
|
+
# test failures related to randomization by passing the same `--seed` value
|
31
|
+
# as the one that triggered the failure.
|
32
|
+
Kernel.srand config.seed
|
33
|
+
|
34
|
+
config.include RSpecHtmlMatchers
|
35
|
+
|
36
|
+
# rspec-expectations config goes here. You can use an alternate
|
37
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
38
|
+
# assertions if you prefer.
|
39
|
+
config.expect_with :rspec do |expectations|
|
40
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
41
|
+
# For more details, see:
|
42
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
43
|
+
expectations.syntax = :expect
|
44
|
+
end
|
45
|
+
|
46
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
47
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
48
|
+
config.mock_with :rspec do |mocks|
|
49
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
50
|
+
# For more details, see:
|
51
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
52
|
+
mocks.syntax = :expect
|
53
|
+
|
54
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
55
|
+
# a real object. This is generally recommended.
|
56
|
+
mocks.verify_partial_doubles = true
|
57
|
+
end
|
58
|
+
end
|
3
59
|
|
4
60
|
shared_examples_for '.set_meta_tags' do
|
5
61
|
it 'should update meta tags' do
|
6
|
-
subject.set_meta_tags(:
|
7
|
-
subject.meta_tags[:title].
|
62
|
+
subject.set_meta_tags(title: 'hello')
|
63
|
+
expect(subject.meta_tags[:title]).to eq('hello')
|
8
64
|
|
9
|
-
subject.set_meta_tags(:
|
10
|
-
subject.meta_tags[:title].
|
65
|
+
subject.set_meta_tags(title: 'world')
|
66
|
+
expect(subject.meta_tags[:title]).to eq('world')
|
11
67
|
end
|
12
68
|
|
13
69
|
it 'should use deep merge when updating meta tags' do
|
14
|
-
subject.set_meta_tags(:
|
15
|
-
subject.meta_tags[:og].
|
70
|
+
subject.set_meta_tags(og: { title: 'hello' })
|
71
|
+
expect(subject.meta_tags[:og]).to eq('title' => 'hello')
|
16
72
|
|
17
|
-
subject.set_meta_tags(:
|
18
|
-
subject.meta_tags[:og].
|
73
|
+
subject.set_meta_tags(og: { description: 'world' })
|
74
|
+
expect(subject.meta_tags[:og]).to eq('title' => 'hello', 'description' => 'world')
|
19
75
|
|
20
|
-
subject.set_meta_tags(:
|
21
|
-
subject.meta_tags[:og].
|
76
|
+
subject.set_meta_tags(og: { admin: { id: 1 } } )
|
77
|
+
expect(subject.meta_tags[:og]).to eq('title' => 'hello', 'description' => 'world', 'admin' => { 'id' => 1 })
|
22
78
|
end
|
23
79
|
|
24
80
|
it 'should normalize :open_graph to :og' do
|
25
|
-
subject.set_meta_tags(:
|
26
|
-
subject.meta_tags[:og].
|
81
|
+
subject.set_meta_tags(open_graph: { title: 'hello' })
|
82
|
+
expect(subject.meta_tags[:og]).to eq('title' => 'hello')
|
27
83
|
end
|
28
84
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::TextNormalizer, '.normalize_title' do
|
4
|
+
context 'when site_title is blank' do
|
5
|
+
it 'should return title when site_title is blank' do
|
6
|
+
expect(subject.normalize_title(nil, 'title', '-')).to eq('title')
|
7
|
+
expect(subject.normalize_title('', 'title', '-')).to eq('title')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should join title parts with separator' do
|
11
|
+
expect(subject.normalize_title('', %w[title subtitle], '-')).to eq('title-subtitle')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should reverse title parts when reverse is true' do
|
15
|
+
expect(subject.normalize_title('', %w[title subtitle], '-', true)).to eq('subtitle-title')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when site_title is specified' do
|
20
|
+
it 'should join title and site_title with separator' do
|
21
|
+
expect(subject.normalize_title('site', 'title', '-')).to eq('site-title')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should join title parts and site_title with separator' do
|
25
|
+
expect(subject.normalize_title('site', %w[title subtitle], '-')).to eq('site-title-subtitle')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should reverse title parts when reverse is true' do
|
29
|
+
expect(subject.normalize_title('site', %w[title subtitle], '-', true)).to eq('subtitle-title-site')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not add title when site title is longer than limit' do
|
33
|
+
site_title = 'a' * (MetaTags.config.title_limit - 2)
|
34
|
+
expect(subject.normalize_title(site_title, 'title', '---')).to eq(site_title[0..-2])
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should truncate title when limit is reached' do
|
38
|
+
site_title = 'a' * 20
|
39
|
+
title = 'b' * (MetaTags.config.title_limit + 10)
|
40
|
+
expect(subject.normalize_title(site_title, title, '-')).to eq("#{site_title}-#{'b' * (MetaTags.config.title_limit - 21)}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::TextNormalizer, '.truncate_array' do
|
4
|
+
it 'should return array as is when limit is not specified' do
|
5
|
+
arr = %w[a]
|
6
|
+
expect(subject.truncate_array(arr, nil)).to be(arr)
|
7
|
+
expect(subject.truncate_array(arr, 0)).to be(arr)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return a new array when limit is specified' do
|
11
|
+
arr = %w[a]
|
12
|
+
expect(subject.truncate_array(arr, 1)).to_not be(arr)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when separator is empty string' do
|
16
|
+
it 'should return the whole array when total size is less than or equal to limit' do
|
17
|
+
arr = %w[a a]
|
18
|
+
expect(subject.truncate_array(arr, 5)).to eq(arr)
|
19
|
+
expect(subject.truncate_array(arr, 2)).to eq(arr)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should truncate array to specified limit' do
|
23
|
+
arr = %w[a a a a a]
|
24
|
+
expect(subject.truncate_array(arr, 3)).to eq(%w[a a a])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should truncate last word to match the limit' do
|
28
|
+
arr = %w[a a aaaa aa]
|
29
|
+
expect(subject.truncate_array(arr, 4)).to eq(%w[a a aa])
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should use natural separator when truncating a long word' do
|
33
|
+
arr = ['a', 'aa aaaa', 'aa']
|
34
|
+
expect(subject.truncate_array(arr, 7)).to eq(%w[a aa])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when separator is specified' do
|
39
|
+
it 'should return the whole array when total size is less than or equal to limit' do
|
40
|
+
arr = %w[a a]
|
41
|
+
expect(subject.truncate_array(arr, 5, '-')).to eq(arr)
|
42
|
+
expect(subject.truncate_array(arr, 3, '-')).to eq(arr)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should truncate array to specified limit' do
|
46
|
+
arr = %w[a a a a a]
|
47
|
+
expect(subject.truncate_array(arr, 3, '-')).to eq(%w[a a])
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should truncate last word to match the limit' do
|
51
|
+
arr = %w[a a aaaa aa]
|
52
|
+
expect(subject.truncate_array(arr, 5, '-')).to eq(%w[a a a])
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should use natural separator when truncating a long word' do
|
56
|
+
arr = ['a', 'aa aaaa', 'aa']
|
57
|
+
expect(subject.truncate_array(arr, 7, '-')).to eq(%w[a aa])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::ViewHelper, 'displaying charset' do
|
4
|
+
subject { ActionView::Base.new }
|
5
|
+
|
6
|
+
it 'should not display charset if blank' do
|
7
|
+
expect(subject.display_meta_tags).to eq('')
|
8
|
+
expect(subject.display_meta_tags(charset: '')).to eq('')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should display charset' do
|
12
|
+
subject.display_meta_tags(charset: 'UTF-8').tap do |meta|
|
13
|
+
expect(meta).to eq('<meta charset="UTF-8" />')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::ViewHelper do
|
4
|
+
subject { ActionView::Base.new }
|
5
|
+
|
6
|
+
context 'display any named meta tag that you want to' do
|
7
|
+
it 'should display testing meta tag' do
|
8
|
+
subject.display_meta_tags(testing: 'this is a test').tap do |meta|
|
9
|
+
expect(meta).to have_tag('meta', with: { content: "this is a test", name: "testing" })
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should support Array values' do
|
14
|
+
subject.display_meta_tags(testing: ['test1', 'test2']).tap do |meta|
|
15
|
+
expect(meta).to have_tag('meta', with: { content: "test1", name: "testing" })
|
16
|
+
expect(meta).to have_tag('meta', with: { content: "test2", name: "testing" })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should support Hash values' do
|
21
|
+
subject.display_meta_tags(testing: { tag: 'value' }).tap do |meta|
|
22
|
+
expect(meta).to have_tag('meta', with: { content: "value", name: "testing:tag" })
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should support symbolic references in Hash values' do
|
27
|
+
subject.display_meta_tags(title: 'my title', testing: { tag: :title }).tap do |meta|
|
28
|
+
expect(meta).to have_tag('meta', with: { content: "my title", name: "testing:tag" })
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not render when value is nil' do
|
33
|
+
subject.display_meta_tags(testing: nil).tap do |meta|
|
34
|
+
expect(meta).to eq('')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should display meta tags with hashes and arrays' do
|
39
|
+
subject.set_meta_tags(foo: {
|
40
|
+
bar: "lorem",
|
41
|
+
baz: {
|
42
|
+
qux: ["lorem", "ipsum"]
|
43
|
+
},
|
44
|
+
quux: [
|
45
|
+
{
|
46
|
+
corge: "lorem",
|
47
|
+
grault: "ipsum"
|
48
|
+
},
|
49
|
+
{
|
50
|
+
corge: "dolor",
|
51
|
+
grault: "sit"
|
52
|
+
}
|
53
|
+
]
|
54
|
+
})
|
55
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
56
|
+
expect(meta).to have_tag('meta', with: { content: "lorem", name: "foo:bar" })
|
57
|
+
expect(meta).to have_tag('meta', with: { content: "lorem", name: "foo:baz:qux" })
|
58
|
+
expect(meta).to have_tag('meta', with: { content: "ipsum", name: "foo:baz:qux" })
|
59
|
+
expect(meta).to have_tag('meta', with: { content: "lorem", name: "foo:quux:corge" })
|
60
|
+
expect(meta).to have_tag('meta', with: { content: "ipsum", name: "foo:quux:grault" })
|
61
|
+
expect(meta).to have_tag('meta', with: { content: "dolor", name: "foo:quux:corge" })
|
62
|
+
expect(meta).to have_tag('meta', with: { content: "sit", name: "foo:quux:grault" })
|
63
|
+
expect(meta).to_not have_tag('meta', with: { name: "foo:quux" })
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::ViewHelper, 'displaying description' do
|
4
|
+
subject { ActionView::Base.new }
|
5
|
+
|
6
|
+
it 'should not display description if blank' do
|
7
|
+
subject.description('')
|
8
|
+
expect(subject.display_meta_tags).to eq('')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should display description when "description" used' do
|
12
|
+
subject.description('someDescription')
|
13
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
14
|
+
expect(meta).to have_tag('meta', with: { content: "someDescription", name: "description" })
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should display description when "set_meta_tags" used' do
|
19
|
+
subject.set_meta_tags(description: 'someDescription')
|
20
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
21
|
+
expect(meta).to have_tag('meta', with: { content: "someDescription", name: "description" })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should display default description' do
|
26
|
+
subject.display_meta_tags(site: 'someSite', description: 'someDescription').tap do |meta|
|
27
|
+
expect(meta).to have_tag('meta', with: { content: "someDescription", name: "description" })
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should use custom description if given' do
|
32
|
+
subject.description('someDescription')
|
33
|
+
subject.display_meta_tags(site: 'someSite', description: 'defaultDescription').tap do |meta|
|
34
|
+
expect(meta).to have_tag('meta', with: { content: "someDescription", name: "description" })
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should strip multiple spaces' do
|
39
|
+
subject.display_meta_tags(site: 'someSite', description: "some \n\r\t description").tap do |meta|
|
40
|
+
expect(meta).to have_tag('meta', with: { content: "some description", name: "description" })
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should strip HTML' do
|
45
|
+
subject.display_meta_tags(site: 'someSite', description: "<p>some <b>description</b></p>").tap do |meta|
|
46
|
+
expect(meta).to have_tag('meta', with: { content: "some description", name: "description" })
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should change escape double quotes' do
|
51
|
+
subject.display_meta_tags(site: 'someSite', description: 'some "description"').tap do |meta|
|
52
|
+
expect(meta).to have_tag('meta', with: { content: "some \"description\"", name: "description" })
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should truncate correctly' do
|
57
|
+
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.").tap do |meta|
|
58
|
+
expect(meta).to have_tag('meta', with: { 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", name: "description" })
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|