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.
@@ -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
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe MetaTags::ViewHelper, 'module' do
4
+ subject { ActionView::Base.new }
5
+
6
+ it 'should be mixed into ActionView::Base' do
7
+ expect(ActionView::Base.included_modules).to include(MetaTags::ViewHelper)
8
+ end
9
+
10
+ it 'should respond to "title" helper' do
11
+ expect(subject).to respond_to(:title)
12
+ end
13
+
14
+ it 'should respond to "description" helper' do
15
+ expect(subject).to respond_to(:description)
16
+ end
17
+
18
+ it 'should respond to "keywords" helper' do
19
+ expect(subject).to respond_to(:keywords)
20
+ end
21
+
22
+ it 'should respond to "noindex" helper' do
23
+ expect(subject).to respond_to(:noindex)
24
+ end
25
+
26
+ it 'should respond to "nofollow" helper' do
27
+ expect(subject).to respond_to(:nofollow)
28
+ end
29
+
30
+ it 'should respond to "set_meta_tags" helper' do
31
+ expect(subject).to respond_to(:set_meta_tags)
32
+ end
33
+
34
+ it 'should respond to "display_meta_tags" helper' do
35
+ expect(subject).to respond_to(:display_meta_tags)
36
+ end
37
+
38
+ it 'should respond to "display_title" helper' do
39
+ expect(subject).to respond_to(:display_title)
40
+ end
41
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe MetaTags::ViewHelper do
4
+ subject { ActionView::Base.new }
5
+
6
+ context 'displaying noindex' do
7
+ it 'should display noindex when "noindex" used' do
8
+ subject.noindex(true)
9
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
10
+ expect(meta).to have_tag('meta', with: { content: "noindex", name: "robots" })
11
+ end
12
+ end
13
+
14
+ it 'should display noindex when "set_meta_tags" used' do
15
+ subject.set_meta_tags(noindex: true)
16
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
17
+ expect(meta).to have_tag('meta', with: { content: "noindex", name: "robots" })
18
+ end
19
+ end
20
+
21
+ it 'should use custom noindex if given' do
22
+ subject.noindex('some-noindex')
23
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
24
+ expect(meta).to have_tag('meta', with: { content: "noindex", name: "some-noindex" })
25
+ end
26
+ end
27
+
28
+ it 'should display nothing by default' do
29
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
30
+ expect(meta).to_not have_tag('meta', with: { content: "noindex" })
31
+ end
32
+ end
33
+
34
+ it "should display nothing if given false" do
35
+ subject.set_meta_tags(noindex: false)
36
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
37
+ expect(meta).to_not have_tag('meta', with: { content: "robots" })
38
+ end
39
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
40
+ expect(meta).to_not have_tag('meta', with: { content: "noindex" })
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'displaying nofollow' do
46
+ it 'should display nofollow when "nofollow" used' do
47
+ subject.nofollow(true)
48
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
49
+ expect(meta).to have_tag('meta', with: { content: "nofollow", name: "robots" })
50
+ end
51
+ end
52
+
53
+ it 'should display nofollow when "set_meta_tags" used' do
54
+ subject.set_meta_tags(nofollow: true)
55
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
56
+ expect(meta).to have_tag('meta', with: { content: "nofollow", name: "robots" })
57
+ end
58
+ end
59
+
60
+ it 'should use custom nofollow if given' do
61
+ subject.nofollow('some-nofollow')
62
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
63
+ expect(meta).to have_tag('meta', with: { content: "nofollow", name: "some-nofollow" })
64
+ end
65
+ end
66
+
67
+ it 'should display nothing by default' do
68
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
69
+ expect(meta).to_not have_tag('meta', with: { content: "nofollow" })
70
+ end
71
+ end
72
+ end
73
+
74
+ context 'displaying both nofollow and noindex' do
75
+ it 'should be displayed when set using helpers' do
76
+ subject.noindex(true)
77
+ subject.nofollow(true)
78
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
79
+ expect(meta).to have_tag('meta', with: { content: "noindex, nofollow", name: "robots" })
80
+ end
81
+ end
82
+
83
+ it 'should be displayed when "set_meta_tags" used' do
84
+ subject.set_meta_tags(nofollow: true, noindex: true)
85
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
86
+ expect(meta).to have_tag('meta', with: { content: "noindex, nofollow", name: "robots" })
87
+ end
88
+ end
89
+
90
+ it 'should use custom name if string is used' do
91
+ subject.noindex('some-name')
92
+ subject.nofollow('some-name')
93
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
94
+ expect(meta).to have_tag('meta', with: { content: "noindex, nofollow", name: "some-name" })
95
+ end
96
+ end
97
+
98
+ it 'should display two meta tags when different names used' do
99
+ subject.noindex('some-noindex')
100
+ subject.nofollow('some-nofollow')
101
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
102
+ expect(meta).to have_tag('meta', with: { content: "noindex", name: "some-noindex" })
103
+ expect(meta).to have_tag('meta', with: { content: "nofollow", name: "some-nofollow" })
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe MetaTags::ViewHelper, 'displaying Open Graph meta tags' do
4
+ subject { ActionView::Base.new }
5
+
6
+ it 'should display meta tags specified with :open_graph' do
7
+ subject.set_meta_tags(open_graph: {
8
+ title: 'Facebook Share Title',
9
+ description: 'Facebook Share Description'
10
+ })
11
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
12
+ expect(meta).to have_tag('meta', with: { content: "Facebook Share Title", property: "og:title" })
13
+ expect(meta).to have_tag('meta', with: { content: "Facebook Share Description", property: "og:description" })
14
+ end
15
+ end
16
+
17
+ it 'should display meta tags specified with :og' do
18
+ subject.set_meta_tags(og: {
19
+ title: 'Facebook Share Title',
20
+ description: 'Facebook Share Description'
21
+ })
22
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
23
+ expect(meta).to have_tag('meta', with: { content: "Facebook Share Title", property: "og:title" })
24
+ expect(meta).to have_tag('meta', with: { content: "Facebook Share Description", property: "og:description" })
25
+ end
26
+ end
27
+
28
+ it 'should use deep merge when displaying open graph meta tags' do
29
+ subject.set_meta_tags(og: { title: 'Facebook Share Title' })
30
+ subject.display_meta_tags(og: { description: 'Facebook Share Description' }).tap do |meta|
31
+ expect(meta).to have_tag('meta', with: { content: "Facebook Share Title", property: "og:title" })
32
+ expect(meta).to have_tag('meta', with: { content: "Facebook Share Description", property: "og:description" })
33
+ end
34
+ end
35
+
36
+ it "should not display meta tags without content" do
37
+ subject.set_meta_tags(open_graph: {
38
+ title: '',
39
+ description: ''
40
+ })
41
+ subject.display_meta_tags(site: 'someSite').tap do |meta|
42
+ expect(meta).to_not have_tag('meta', with: { content: "", property: "og:title" })
43
+ expect(meta).to_not have_tag('meta', with: { content: "", property: "og:description" })
44
+ end
45
+ end
46
+
47
+ it "should display locale meta tags" do
48
+ subject.display_meta_tags(open_graph: { locale: { _: 'en_GB', alternate: ['fr_FR', 'es_ES'] } }).tap do |meta|
49
+ expect(meta).to have_tag('meta', with: { content: "en_GB", property: "og:locale" })
50
+ expect(meta).to have_tag('meta', with: { content: "fr_FR", property: "og:locale:alternate" })
51
+ expect(meta).to have_tag('meta', with: { content: "es_ES", property: "og:locale:alternate" })
52
+ end
53
+ end
54
+
55
+ it "should display mirrored content" do
56
+ subject.set_meta_tags(title: 'someTitle')
57
+ subject.display_meta_tags(open_graph: { title: :title }).tap do |meta|
58
+ expect(meta).to have_tag('meta', with: { content: "someTitle", property: "og:title" })
59
+ end
60
+ end
61
+
62
+ it "should display open graph meta tags with an array of images" do
63
+ subject.set_meta_tags(open_graph: {
64
+ title: 'someTitle',
65
+ image: [{
66
+ _: 'http://example.com/1.png',
67
+ width: 75,
68
+ height: 75,
69
+ },
70
+ {
71
+ _: 'http://example.com/2.png',
72
+ width: 50,
73
+ height: 50,
74
+ }]
75
+ })
76
+ subject.display_meta_tags(site: 'someTitle').tap do |meta|
77
+ expect(meta).to have_tag('meta', with: { content: "someTitle", property: "og:title" })
78
+ expect(meta).to have_tag('meta', with: { content: "http://example.com/1.png", property: "og:image" })
79
+ expect(meta).to have_tag('meta', with: { content: "75", property: "og:image:width" })
80
+ expect(meta).to have_tag('meta', with: { content: "75", property: "og:image:height" })
81
+ expect(meta).to have_tag('meta', with: { content: "http://example.com/2.png", property: "og:image" })
82
+ expect(meta).to have_tag('meta', with: { content: "50", property: "og:image:width" })
83
+ expect(meta).to have_tag('meta', with: { content: "50", property: "og:image:height" })
84
+ end
85
+ end
86
+ end