diff --git a/app/views/proposals/_social_share.html.erb b/app/views/proposals/_social_share.html.erb new file mode 100644 index 000000000..b675fe192 --- /dev/null +++ b/app/views/proposals/_social_share.html.erb @@ -0,0 +1,10 @@ +<%= render 'shared/social_share', + share_title: share_title, + title: proposal.title, + url: proposal_url(proposal), + description: t("proposals.share.message", + summary: proposal.summary, + org: setting['org_name']), + mobile: t("proposals.share.message_mobile", + summary: proposal.summary, + handle: setting['twitter_handle']) %> diff --git a/app/views/proposals/_votes.html.erb b/app/views/proposals/_votes.html.erb index 92b680493..6624448fe 100644 --- a/app/views/proposals/_votes.html.erb +++ b/app/views/proposals/_votes.html.erb @@ -10,7 +10,8 @@ <%= t("proposals.proposal.supports", count: proposal.total_votes) %>  - <%= t("proposals.proposal.supports_necessary", number: number_with_delimiter(Proposal.votes_needed_for_success)) %> + <%= t("proposals.proposal.supports_necessary", + number: number_with_delimiter(Proposal.votes_needed_for_success)) %> @@ -60,11 +61,7 @@ <% if voted_for?(@proposal_votes, proposal) && setting['twitter_handle'] %>
- <%= render partial: 'shared/social_share', locals: { - title: proposal.title, - url: proposal_url(proposal), - description: proposal.summary - } %> + <%= render 'proposals/social_share', proposal: proposal, share_title: false %>
<% end %> diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index 9794c0365..2c40a7075 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -192,12 +192,8 @@ { proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: 'yes') } %> <% end %> - <%= render partial: 'shared/social_share', locals: { - share_title: t("proposals.show.share"), - title: @proposal.title, - url: proposal_url(@proposal), - description: @proposal.summary - } %> + + <%= render 'proposals/social_share', proposal: @proposal, share_title: t("proposals.show.share") %> <% if current_user %> diff --git a/app/views/shared/_social_share.html.erb b/app/views/shared/_social_share.html.erb index 7148f4f0a..f2346c30c 100644 --- a/app/views/shared/_social_share.html.erb +++ b/app/views/shared/_social_share.html.erb @@ -1,13 +1,17 @@ +<% description = local_assigns.fetch(:description, '') %> +<% description = truncate(ActionView::Base.full_sanitizer.sanitize(description), length: 140) %> <% if local_assigns[:share_title].present? %> <% end %>
- <%= social_share_button_tag("#{title} #{setting['twitter_hashtag']}", - :url => local_assigns[:url], - :image => local_assigns[:image_url].present? ? local_assigns[:image_url] : '', - :desc => local_assigns[:description].present? ? local_assigns[:description] : '' ) %> - + <%= t("social.whatsapp") %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 5de10978f..096fbc83e 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -450,6 +450,9 @@ en: update: form: submit_button: Save changes + share: + message: "I supported the proposal %{summary} in %{org}. If you're interested, support it too!" + message_mobile: "I supported the proposal %{summary} in %{handle}. If you're interested, support it too!" polls: all: "All" no_dates: "no date assigned" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index e1f86a487..1f5f06630 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -450,6 +450,9 @@ es: update: form: submit_button: Guardar cambios + share: + message: "He apoyado la propuesta %{summary} en %{org}. Si te interesa, ¡apoya tú también!" + message_mobile: "He apoyado la propuesta %{summary} en %{handle}. Si te interesa, ¡apoya tú también!" polls: all: "Todas" no_dates: "sin fecha asignada" diff --git a/db/dev_seeds/settings.rb b/db/dev_seeds/settings.rb index 756ba9785..388742217 100644 --- a/db/dev_seeds/settings.rb +++ b/db/dev_seeds/settings.rb @@ -56,7 +56,8 @@ section "Creating Settings" do Setting.create(key: 'mailer_from_name', value: 'CONSUL') Setting.create(key: 'mailer_from_address', value: 'noreply@consul.dev') 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: 'verification_offices_url', value: 'http://oficinas-atencion-ciudadano.url/') Setting.create(key: 'min_age_to_participate', value: '16') diff --git a/spec/features/social_media_meta_tags_spec.rb b/spec/features/social_media_meta_tags_spec.rb index dcaef7aee..0eb1d30f6 100644 --- a/spec/features/social_media_meta_tags_spec.rb +++ b/spec/features/social_media_meta_tags_spec.rb @@ -5,16 +5,9 @@ feature 'Social media meta tags' do context 'Setting social media meta tags' do let(:meta_keywords) { 'citizen, participation, open government' } - let(:meta_title) { 'CONSUL TEST' } - let(:meta_description) do - "

Paragraph

link Lorem ipsum dolr"\ - " 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(:meta_title) { 'CONSUL' } + let(:meta_description) { 'Citizen participation tool for an open, '\ + 'transparent and democratic government.' } let(:twitter_handle) { '@consul_test' } let(:url) { 'http://consul.dev' } let(:facebook_handle) { 'consultest' } @@ -43,19 +36,21 @@ feature 'Social media meta tags' do scenario 'Social media meta tags partial render settings content' do 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_css 'meta[name="twitter:site"][content="' + twitter_handle + '"]', visible: false - expect(page).to have_css 'meta[name="twitter:title"][content="' + meta_title + '"]', visible: false - expect(page).to have_css 'meta[name="twitter:description"][content="' + sanitized_truncated_meta_description + '"]', visible: false - 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_css 'meta[property="og:title"][content="' + meta_title + '"]', visible: false - expect(page).to have_css 'meta[property="article:publisher"][content="' + url + '"]', visible: false - expect(page).to have_css 'meta[property="article:author"][content="https://www.facebook.com/' + facebook_handle + '"]', visible: false - 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 + expect(page).to have_property "og:title", with: meta_title + expect(page).to have_property "article:publisher", with: url + expect(page).to have_property "article:author", with: 'https://www.facebook.com/' + + facebook_handle + expect(page).to have_property "og:url", with: 'http://www.example.com/' + expect(page).to have_property "og:image", with: 'http://www.example.com/social_media_icon.png' + expect(page).to have_property "og:site_name", with: org_name + expect(page).to have_property "og:description", with: meta_description end end diff --git a/spec/support/matchers/have_meta.rb b/spec/support/matchers/have_meta.rb new file mode 100644 index 000000000..cdee080a1 --- /dev/null +++ b/spec/support/matchers/have_meta.rb @@ -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 diff --git a/spec/support/matchers/have_property.rb b/spec/support/matchers/have_property.rb new file mode 100644 index 000000000..17d83ccd0 --- /dev/null +++ b/spec/support/matchers/have_property.rb @@ -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