Refactors social meta tags spec
This commit is contained in:
@@ -56,7 +56,8 @@ section "Creating Settings" do
|
|||||||
Setting.create(key: 'mailer_from_name', value: 'CONSUL')
|
Setting.create(key: 'mailer_from_name', value: 'CONSUL')
|
||||||
Setting.create(key: 'mailer_from_address', value: 'noreply@consul.dev')
|
Setting.create(key: 'mailer_from_address', value: 'noreply@consul.dev')
|
||||||
Setting.create(key: 'meta_title', value: 'CONSUL')
|
Setting.create(key: 'meta_title', value: 'CONSUL')
|
||||||
Setting.create(key: 'meta_description', value: 'Citizen Participation & Open Gov Application')
|
Setting.create(key: 'meta_description', value: 'Citizen participation tool for an open, '\
|
||||||
|
'transparent and democratic government')
|
||||||
Setting.create(key: 'meta_keywords', value: 'citizen participation, open government')
|
Setting.create(key: 'meta_keywords', value: 'citizen participation, open government')
|
||||||
Setting.create(key: 'verification_offices_url', value: 'http://oficinas-atencion-ciudadano.url/')
|
Setting.create(key: 'verification_offices_url', value: 'http://oficinas-atencion-ciudadano.url/')
|
||||||
Setting.create(key: 'min_age_to_participate', value: '16')
|
Setting.create(key: 'min_age_to_participate', value: '16')
|
||||||
|
|||||||
@@ -5,16 +5,9 @@ feature 'Social media meta tags' do
|
|||||||
context 'Setting social media meta tags' do
|
context 'Setting social media meta tags' do
|
||||||
|
|
||||||
let(:meta_keywords) { 'citizen, participation, open government' }
|
let(:meta_keywords) { 'citizen, participation, open government' }
|
||||||
let(:meta_title) { 'CONSUL TEST' }
|
let(:meta_title) { 'CONSUL' }
|
||||||
let(:meta_description) do
|
let(:meta_description) { 'Citizen participation tool for an open, '\
|
||||||
"<p>Paragraph</p> <a href=\"http://google.es\">link</a> Lorem ipsum dolr"\
|
'transparent and democratic government.' }
|
||||||
" sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididt"\
|
|
||||||
" ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostud"\
|
|
||||||
end
|
|
||||||
let(:sanitized_truncated_meta_description) do
|
|
||||||
"Paragraph link Lorem ipsum dolr sit amet, consectetur adipisicing elit,"\
|
|
||||||
" sed do eiusmod tempor incididt ut labore et dolore magna aliqua. ..."
|
|
||||||
end
|
|
||||||
let(:twitter_handle) { '@consul_test' }
|
let(:twitter_handle) { '@consul_test' }
|
||||||
let(:url) { 'http://consul.dev' }
|
let(:url) { 'http://consul.dev' }
|
||||||
let(:facebook_handle) { 'consultest' }
|
let(:facebook_handle) { 'consultest' }
|
||||||
@@ -43,19 +36,21 @@ feature 'Social media meta tags' do
|
|||||||
scenario 'Social media meta tags partial render settings content' do
|
scenario 'Social media meta tags partial render settings content' do
|
||||||
|
|
||||||
visit root_path
|
visit root_path
|
||||||
|
expect(page).to have_meta "keywords", with: meta_keywords
|
||||||
|
expect(page).to have_meta "twitter:site", with: twitter_handle
|
||||||
|
expect(page).to have_meta "twitter:title", with: meta_title
|
||||||
|
expect(page).to have_meta "twitter:description", with: meta_description
|
||||||
|
expect(page).to have_meta "twitter:image",
|
||||||
|
with:'http://www.example.com/social_media_icon_twitter.png'
|
||||||
|
|
||||||
expect(page).to have_css 'meta[name="keywords"][content="' + meta_keywords + '"]', visible: false
|
expect(page).to have_property "og:title", with: meta_title
|
||||||
expect(page).to have_css 'meta[name="twitter:site"][content="' + twitter_handle + '"]', visible: false
|
expect(page).to have_property "article:publisher", with: url
|
||||||
expect(page).to have_css 'meta[name="twitter:title"][content="' + meta_title + '"]', visible: false
|
expect(page).to have_property "article:author", with: 'https://www.facebook.com/' +
|
||||||
expect(page).to have_css 'meta[name="twitter:description"][content="' + sanitized_truncated_meta_description + '"]', visible: false
|
facebook_handle
|
||||||
expect(page).to have_css 'meta[name="twitter:image"][content="http://www.example.com/social_media_icon_twitter.png"]', visible: false
|
expect(page).to have_property "og:url", with: 'http://www.example.com/'
|
||||||
expect(page).to have_css 'meta[property="og:title"][content="' + meta_title + '"]', visible: false
|
expect(page).to have_property "og:image", with: 'http://www.example.com/social_media_icon.png'
|
||||||
expect(page).to have_css 'meta[property="article:publisher"][content="' + url + '"]', visible: false
|
expect(page).to have_property "og:site_name", with: org_name
|
||||||
expect(page).to have_css 'meta[property="article:author"][content="https://www.facebook.com/' + facebook_handle + '"]', visible: false
|
expect(page).to have_property "og:description", with: meta_description
|
||||||
expect(page).to have_css 'meta[property="og:url"][content="http://www.example.com/"]', visible: false
|
|
||||||
expect(page).to have_css 'meta[property="og:image"][content="http://www.example.com/social_media_icon.png"]', visible: false
|
|
||||||
expect(page).to have_css 'meta[property="og:site_name"][content="' + org_name + '"]', visible: false
|
|
||||||
expect(page).to have_css 'meta[property="og:description"][content="' + sanitized_truncated_meta_description + '"]', visible: false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
15
spec/support/matchers/have_meta.rb
Normal file
15
spec/support/matchers/have_meta.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
RSpec::Matchers.define :have_meta do |name, with:|
|
||||||
|
match do
|
||||||
|
has_css?("meta[name='#{name}'][content='#{with}']", visible: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
failure_message do
|
||||||
|
meta = first("meta[name='#{name}']", visible: false)
|
||||||
|
|
||||||
|
if meta
|
||||||
|
"expected to find meta tag #{name} with '#{with}', but had '#{meta[:content]}'"
|
||||||
|
else
|
||||||
|
"expected to find meta tag #{name} but there were no matches."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
15
spec/support/matchers/have_property.rb
Normal file
15
spec/support/matchers/have_property.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
RSpec::Matchers.define :have_property do |property, with:|
|
||||||
|
match do
|
||||||
|
has_css?("meta[property='#{property}'][content='#{with}']", visible: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
failure_message do
|
||||||
|
meta = first("meta[property='#{property}']", visible: false)
|
||||||
|
|
||||||
|
if meta
|
||||||
|
"expected to find meta tag #{property} with '#{with}', but had '#{meta[:content]}'"
|
||||||
|
else
|
||||||
|
"expected to find meta tag #{property} but there were no matches."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user