meta_tags-rails 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +21 -0
- data/CHANGELOG.md +135 -0
- data/Gemfile +13 -0
- data/MIT-LICENSE +22 -0
- data/README.md +627 -0
- data/Rakefile +28 -0
- data/lib/meta_tags-rails.rb +37 -0
- data/lib/meta_tags-rails/configuration.rb +21 -0
- data/lib/meta_tags-rails/content_tag.rb +14 -0
- data/lib/meta_tags-rails/controller_helper.rb +44 -0
- data/lib/meta_tags-rails/meta_tags_collection.rb +176 -0
- data/lib/meta_tags-rails/renderer.rb +253 -0
- data/lib/meta_tags-rails/tag.rb +25 -0
- data/lib/meta_tags-rails/text_normalizer.rb +148 -0
- data/lib/meta_tags-rails/version.rb +4 -0
- data/lib/meta_tags-rails/view_helper.rb +205 -0
- data/meta-tags.gemspec +30 -0
- data/spec/configuration_spec.rb +14 -0
- data/spec/controller_helper_spec.rb +42 -0
- data/spec/spec_helper.rb +84 -0
- 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 +172 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
if ENV['CODECLIMATE_REPO_TOKEN'] && RUBY_VERSION > '1.8.7'
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'meta_tags-rails'
|
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
|
59
|
+
|
60
|
+
shared_examples_for '.set_meta_tags' do
|
61
|
+
it 'should update meta tags' do
|
62
|
+
subject.set_meta_tags(title: 'hello')
|
63
|
+
expect(subject.meta_tags[:title]).to eq('hello')
|
64
|
+
|
65
|
+
subject.set_meta_tags(title: 'world')
|
66
|
+
expect(subject.meta_tags[:title]).to eq('world')
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should use deep merge when updating meta tags' do
|
70
|
+
subject.set_meta_tags(og: { title: 'hello' })
|
71
|
+
expect(subject.meta_tags[:og]).to eq('title' => 'hello')
|
72
|
+
|
73
|
+
subject.set_meta_tags(og: { description: 'world' })
|
74
|
+
expect(subject.meta_tags[:og]).to eq('title' => 'hello', 'description' => 'world')
|
75
|
+
|
76
|
+
subject.set_meta_tags(og: { admin: { id: 1 } } )
|
77
|
+
expect(subject.meta_tags[:og]).to eq('title' => 'hello', 'description' => 'world', 'admin' => { 'id' => 1 })
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should normalize :open_graph to :og' do
|
81
|
+
subject.set_meta_tags(open_graph: { title: 'hello' })
|
82
|
+
expect(subject.meta_tags[:og]).to eq('title' => 'hello')
|
83
|
+
end
|
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
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::ViewHelper do
|
4
|
+
subject { ActionView::Base.new }
|
5
|
+
|
6
|
+
it 'should not display icon by default' do
|
7
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
8
|
+
expect(meta).to_not have_tag('link', with: { rel: 'icon' })
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should display icon when "set_meta_tags" used' do
|
13
|
+
subject.set_meta_tags(icon: '/favicon.ico')
|
14
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
15
|
+
expect(meta).to have_tag('link', with: { href: '/favicon.ico', rel: 'icon', type: 'image/x-icon' })
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should display default canonical url' do
|
20
|
+
subject.display_meta_tags(site: 'someSite', icon: '/favicon.ico').tap do |meta|
|
21
|
+
expect(meta).to have_tag('link', with: { href: '/favicon.ico', rel: 'icon', type: 'image/x-icon' })
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should allow to specify hash as an icon' do
|
26
|
+
subject.set_meta_tags(icon: { href: '/favicon.png', type: 'image/png' })
|
27
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
28
|
+
expect(meta).to have_tag('link', with: { href: '/favicon.png', rel: 'icon', type: 'image/png' })
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should allow to specify multiple icons' do
|
33
|
+
subject.set_meta_tags(icon: [
|
34
|
+
{ href: '/images/icons/icon_96.png', sizes: '32x32 96x96', type: 'image/png' },
|
35
|
+
{ href: '/images/icons/icon_itouch_precomp_32.png', rel: 'apple-touch-icon-precomposed', sizes: '32x32', type: 'image/png' },
|
36
|
+
])
|
37
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
38
|
+
expect(meta).to have_tag('link', with: { href: '/images/icons/icon_96.png', rel: 'icon', type: 'image/png', sizes: '32x32 96x96' })
|
39
|
+
expect(meta).to have_tag('link', with: { href: '/images/icons/icon_itouch_precomp_32.png', rel: 'apple-touch-icon-precomposed', type: 'image/png', sizes: '32x32' })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::ViewHelper, 'displaying keywords' do
|
4
|
+
subject { ActionView::Base.new }
|
5
|
+
|
6
|
+
it 'should not display keywords if blank' do
|
7
|
+
subject.keywords('')
|
8
|
+
expect(subject.display_meta_tags).to eq('')
|
9
|
+
|
10
|
+
subject.keywords([])
|
11
|
+
expect(subject.display_meta_tags).to eq('')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should display keywords when "keywords" used' do
|
15
|
+
subject.keywords('some-keywords')
|
16
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
17
|
+
expect(meta).to have_tag('meta', with: { content: "some-keywords", name: "keywords" })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should display keywords when "set_meta_tags" used' do
|
22
|
+
subject.set_meta_tags(keywords: 'some-keywords')
|
23
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
24
|
+
expect(meta).to have_tag('meta', with: { content: "some-keywords", name: "keywords" })
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should display default keywords' do
|
29
|
+
subject.display_meta_tags(site: 'someSite', keywords: 'some-keywords').tap do |meta|
|
30
|
+
expect(meta).to have_tag('meta', with: { content: "some-keywords", name: "keywords" })
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should use custom keywords if given' do
|
35
|
+
subject.keywords('some-keywords')
|
36
|
+
subject.display_meta_tags(site: 'someSite', keywords: 'default_keywords').tap do |meta|
|
37
|
+
expect(meta).to have_tag('meta', with: { content: "some-keywords", name: "keywords" })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should lowercase keywords' do
|
42
|
+
subject.display_meta_tags(site: 'someSite', keywords: 'someKeywords').tap do |meta|
|
43
|
+
expect(meta).to have_tag('meta', with: { content: "somekeywords", name: "keywords" })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should join keywords from Array' do
|
48
|
+
subject.display_meta_tags(site: 'someSite', keywords: %w(keyword1 keyword2)).tap do |meta|
|
49
|
+
expect(meta).to have_tag('meta', with: { content: "keyword1, keyword2", name: "keywords" })
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should join keywords from nested Arrays' do
|
54
|
+
subject.display_meta_tags(site: 'someSite', keywords: [%w(keyword1 keyword2), 'keyword3']).tap do |meta|
|
55
|
+
expect(meta).to have_tag('meta', with: { content: "keyword1, keyword2, keyword3", name: "keywords" })
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaTags::ViewHelper do
|
4
|
+
subject { ActionView::Base.new }
|
5
|
+
|
6
|
+
context 'displaying canonical url' do
|
7
|
+
it 'should not display canonical url by default' do
|
8
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
9
|
+
expect(meta).to_not have_tag('link', with: { href: "http://example.com/base/url", rel: "canonical" })
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should display canonical url when "set_meta_tags" used' do
|
14
|
+
subject.set_meta_tags(canonical: 'http://example.com/base/url')
|
15
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
16
|
+
expect(meta).to have_tag('link', with: { href: "http://example.com/base/url", rel: "canonical" })
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should display default canonical url' do
|
21
|
+
subject.display_meta_tags(site: 'someSite', canonical: 'http://example.com/base/url').tap do |meta|
|
22
|
+
expect(meta).to have_tag('link', with: { href: "http://example.com/base/url", rel: "canonical" })
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'displaying alternate url' do
|
28
|
+
it 'should not display alternate url by default' do
|
29
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
30
|
+
expect(meta).to_not have_tag('link', with: { href: "http://example.fr/base/url", hreflang: "fr", rel: "alternate" })
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should display alternate url when "set_meta_tags" used' do
|
35
|
+
subject.set_meta_tags(alternate: { 'fr' => 'http://example.fr/base/url' })
|
36
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
37
|
+
expect(meta).to have_tag('link', with: { href: "http://example.fr/base/url", hreflang: "fr", rel: "alternate" })
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should display default alternate url' do
|
42
|
+
subject.display_meta_tags(site: 'someSite', alternate: { 'fr' => 'http://example.fr/base/url' }).tap do |meta|
|
43
|
+
expect(meta).to have_tag('link', with: { href: "http://example.fr/base/url", hreflang: "fr", rel: "alternate" })
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should not display alternate without content" do
|
48
|
+
subject.display_meta_tags(site: 'someSite', alternate: {'zh-Hant' => ''}).tap do |meta|
|
49
|
+
expect(meta).to_not have_tag('link', with: { href: "", hreflang: "zh-Hant", rel: "alternate" })
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should allow to specify an array of alternate links' do
|
54
|
+
subject.display_meta_tags(site: 'someSite', alternate: [
|
55
|
+
{ href: 'http://example.fr/base/url', hreflang: 'fr' },
|
56
|
+
{ href: 'http://example.com/feed.rss', type: 'application/rss+xml', title: 'RSS' },
|
57
|
+
{ href: 'http://m.example.com/page-1', media: 'only screen and (max-width: 640px)'},
|
58
|
+
]).tap do |meta|
|
59
|
+
expect(meta).to have_tag('link', with: { href: "http://example.fr/base/url", hreflang: "fr", rel: "alternate" })
|
60
|
+
expect(meta).to have_tag('link', with: { href: "http://example.com/feed.rss", type: "application/rss+xml", title: 'RSS', rel: "alternate" })
|
61
|
+
expect(meta).to have_tag('link', with: { href: "http://m.example.com/page-1", media: 'only screen and (max-width: 640px)', rel: "alternate" })
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'displaying author link' do
|
67
|
+
it 'should display author link when "set_meta_tags" used' do
|
68
|
+
subject.set_meta_tags(author: 'http://plus.google.com/profile/url')
|
69
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
70
|
+
expect(meta).to have_tag('link', with: { href: "http://plus.google.com/profile/url", rel: "author" })
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'displaying publisher link' do
|
76
|
+
it 'should display publisher link when "set_meta_tags" used' do
|
77
|
+
subject.set_meta_tags(publisher: 'http://plus.google.com/myprofile_url')
|
78
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
79
|
+
expect(meta).to have_tag('link', with: { href: "http://plus.google.com/myprofile_url", rel: "publisher" })
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'displaying prev url' do
|
85
|
+
it 'should not display prev url by default' do
|
86
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
87
|
+
expect(meta).to_not have_tag('link', with: { href: "http://example.com/base/url", rel: "prev" })
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should display prev url when "set_meta_tags" used' do
|
92
|
+
subject.set_meta_tags(prev: 'http://example.com/base/url')
|
93
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
94
|
+
expect(meta).to have_tag('link', with: { href: "http://example.com/base/url", rel: "prev" })
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should display default prev url' do
|
99
|
+
subject.display_meta_tags(site: 'someSite', prev: 'http://example.com/base/url').tap do |meta|
|
100
|
+
expect(meta).to have_tag('link', with: { href: "http://example.com/base/url", rel: "prev" })
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'displaying next url' do
|
106
|
+
it 'should not display next url by default' do
|
107
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
108
|
+
expect(meta).to_not have_tag('link', with: { href: "http://example.com/base/url", rel: "next" })
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should display next url when "set_meta_tags" used' do
|
113
|
+
subject.set_meta_tags(next: 'http://example.com/base/url')
|
114
|
+
subject.display_meta_tags(site: 'someSite').tap do |meta|
|
115
|
+
expect(meta).to have_tag('link', with: { href: "http://example.com/base/url", rel: "next" })
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should display default next url' do
|
120
|
+
subject.display_meta_tags(site: 'someSite', next: 'http://example.com/base/url').tap do |meta|
|
121
|
+
expect(meta).to have_tag('link', with: { href: "http://example.com/base/url", rel: "next" })
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|