Commit a91ba23d160ea5e23047cc28592198c82e3a9f7c
1 parent
13b88959
Exists in
staging
and in
42 other branches
Removed unused method
Also included tests for meta tags and removed not-needed tests (ActionItem2610)
Showing
5 changed files
with
53 additions
and
48 deletions
Show diff stats
app/helpers/content_viewer_helper.rb
... | ... | @@ -52,15 +52,6 @@ module ContentViewerHelper |
52 | 52 | end |
53 | 53 | end |
54 | 54 | |
55 | - def addthis_facebook_url(article) | |
56 | - "http://www.facebook.com/sharer.php?s=100&p[title]=%{title}&p[summary]=%{summary}&p[url]=%{url}&p[images][0]=%{image}" % { | |
57 | - :title => CGI.escape(article.title), | |
58 | - :url => CGI.escape(url_for(article.url)), | |
59 | - :summary => CGI.escape(truncate(strip_tags(article.body.to_s), :length => 300)), | |
60 | - :image => CGI.escape(article.body_images_paths.first.to_s) | |
61 | - } | |
62 | - end | |
63 | - | |
64 | 55 | def addthis_image_tag |
65 | 56 | if File.exists?(File.join(Rails.root, 'public', theme_path, 'images', 'addthis.gif')) |
66 | 57 | image_tag(File.join(theme_path, 'images', 'addthis.gif'), :border => 0, :alt => '') | ... | ... |
app/views/layouts/application-ng.rhtml
... | ... | @@ -11,7 +11,6 @@ |
11 | 11 | <meta name="twitter:card" value="summary"> |
12 | 12 | <meta name="twitter:title" content="<%= h page_title %>"> |
13 | 13 | <meta name="twitter:description" content="<%= meta_description_tag(@page) %>"> |
14 | - <meta name="twitter:image" content="<%= @page.body_images_paths.first.to_s if @page %>"> | |
15 | 14 | |
16 | 15 | <!-- Open Graph --> |
17 | 16 | <meta property="og:type" content="<%= @page ? 'article' : 'website' %>"> |
... | ... | @@ -23,6 +22,7 @@ |
23 | 22 | <% if @page %> |
24 | 23 | <meta property="article:published_time" content="<%= show_date(@page.published_at) %>"> |
25 | 24 | <% @page.body_images_paths.each do |img| %> |
25 | + <meta name="twitter:image" content="<%= img.to_s %>"> | |
26 | 26 | <meta property="og:image" content="<%= img.to_s %>"> |
27 | 27 | <% end %> |
28 | 28 | <% end %> | ... | ... |
test/functional/application_controller_test.rb
... | ... | @@ -263,7 +263,7 @@ class ApplicationControllerTest < ActionController::TestCase |
263 | 263 | assert_no_tag :tag => 'a', :content => /Category 2/ |
264 | 264 | end |
265 | 265 | |
266 | - should 'show name of article as title of page' do | |
266 | + should 'show name of article as title of page without environment' do | |
267 | 267 | p = create_user('test_user').person |
268 | 268 | a = p.articles.create!(:name => 'test article') |
269 | 269 | |
... | ... | @@ -271,17 +271,22 @@ class ApplicationControllerTest < ActionController::TestCase |
271 | 271 | @controller.instance_variable_set('@page', a) |
272 | 272 | |
273 | 273 | get :index |
274 | - assert_tag 'title', :content => 'test article - ' + p.name + ' - ' + p.environment.name | |
274 | + assert_tag 'title', :content => 'test article - ' + p.name | |
275 | 275 | end |
276 | 276 | |
277 | - should 'diplay name of profile in the title' do | |
277 | + should 'diplay name of profile in the title without environment' do | |
278 | 278 | p = create_user('test_user').person |
279 | 279 | p.name = 'Some Test User' |
280 | 280 | p.save! |
281 | 281 | @controller.instance_variable_set('@profile', p) |
282 | 282 | |
283 | 283 | get :index, :profile => p.identifier |
284 | - assert_tag 'title', :content => p.name + ' - ' + p.environment.name | |
284 | + assert_tag 'title', :content => p.name | |
285 | + end | |
286 | + | |
287 | + should 'display environment name in title when profile and page are not defined' do | |
288 | + get :index | |
289 | + assert_tag 'title', :content => assigns(:environment).name | |
285 | 290 | end |
286 | 291 | |
287 | 292 | should 'display menu links for my environment when logged in other environment' do |
... | ... | @@ -324,7 +329,8 @@ class ApplicationControllerTest < ActionController::TestCase |
324 | 329 | end |
325 | 330 | |
326 | 331 | should 'set html lang as the article language if an article is present and has a language' do |
327 | - a = fast_create(Article, :name => 'test article', :language => 'fr') | |
332 | + p = create_user('test_user').person | |
333 | + a = fast_create(Article, :name => 'test article', :language => 'fr', :profile_id => p.id ) | |
328 | 334 | @controller.instance_variable_set('@page', a) |
329 | 335 | FastGettext.stubs(:locale).returns('es') |
330 | 336 | get :index |
... | ... | @@ -338,7 +344,9 @@ class ApplicationControllerTest < ActionController::TestCase |
338 | 344 | end |
339 | 345 | |
340 | 346 | should 'set html lang as locale if page has no language' do |
341 | - a = fast_create(Article, :name => 'test article', :language => nil) | |
347 | + p = create_user('test_user').person | |
348 | + a = fast_create(Article, :name => 'test article', :language => nil, :profile_id => p.id ) | |
349 | + | |
342 | 350 | @controller.instance_variable_set('@page', a) |
343 | 351 | FastGettext.stubs(:locale).returns('es') |
344 | 352 | get :index |
... | ... | @@ -542,4 +550,18 @@ class ApplicationControllerTest < ActionController::TestCase |
542 | 550 | assert_equal nil, @controller.application_controller_test_other_filter_plugin_filter_plugin |
543 | 551 | end |
544 | 552 | |
553 | + should 'display meta tags for social media' do | |
554 | + get :index | |
555 | + assert_tag :tag => 'meta', :attributes => { :name => 'twitter:card', :value => 'summary' } | |
556 | + assert_tag :tag => 'meta', :attributes => { :name => 'twitter:title', :content => assigns(:environment).name } | |
557 | + assert_tag :tag => 'meta', :attributes => { :name => 'twitter:description', :content => assigns(:environment).name } | |
558 | + assert_no_tag :tag => 'meta', :attributes => { :name => 'twitter:image' } | |
559 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:type', :content => 'website' } | |
560 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:url', :content => assigns(:environment).top_url } | |
561 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:title', :content => assigns(:environment).name } | |
562 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:site_name', :content => assigns(:environment).name } | |
563 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:description', :content => assigns(:environment).name } | |
564 | + assert_no_tag :tag => 'meta', :attributes => { :property => 'article:published_time' } | |
565 | + assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' } | |
566 | + end | |
545 | 567 | end | ... | ... |
test/functional/content_viewer_controller_test.rb
... | ... | @@ -1369,4 +1369,28 @@ class ContentViewerControllerTest < ActionController::TestCase |
1369 | 1369 | assert_match /this is a sample text file/, @response.body |
1370 | 1370 | end |
1371 | 1371 | |
1372 | + should 'add meta tags with article info' do | |
1373 | + a = TinyMceArticle.create(:name => 'Article to be shared', :body => 'This article should be shared with all social networks', :profile => profile) | |
1374 | + | |
1375 | + get :view_page, :profile => profile.identifier, :page => [ a.name.to_slug ] | |
1376 | + | |
1377 | + assert_tag :tag => 'meta', :attributes => { :name => 'twitter:title', :content => /#{a.name} - #{a.profile.name}/ } | |
1378 | + assert_tag :tag => 'meta', :attributes => { :name => 'twitter:description', :content => a.body } | |
1379 | + assert_no_tag :tag => 'meta', :attributes => { :name => 'twitter:image' } | |
1380 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:type', :content => 'article' } | |
1381 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:url', :content => /\/#{profile.identifier}\/#{a.name.to_slug}/ } | |
1382 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:title', :content => /#{a.name} - #{a.profile.name}/ } | |
1383 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:site_name', :content => a.profile.name } | |
1384 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:description', :content => a.body } | |
1385 | + assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' } | |
1386 | + end | |
1387 | + | |
1388 | + should 'add meta tags with article images' do | |
1389 | + a = TinyMceArticle.create(:name => 'Article to be shared with images', :body => 'This article should be shared with all social networks <img src="/images/x.png" />', :profile => profile) | |
1390 | + | |
1391 | + get :view_page, :profile => profile.identifier, :page => [ a.name.to_slug ] | |
1392 | + assert_tag :tag => 'meta', :attributes => { :name => 'twitter:image', :content => /\/images\/x.png/ } | |
1393 | + assert_tag :tag => 'meta', :attributes => { :property => 'og:image', :content => /\/images\/x.png/ } | |
1394 | + end | |
1395 | + | |
1372 | 1396 | end | ... | ... |
test/unit/content_viewer_helper_test.rb
... | ... | @@ -89,38 +89,6 @@ class ContentViewerHelperTest < ActiveSupport::TestCase |
89 | 89 | assert_no_match /feed/, result |
90 | 90 | end |
91 | 91 | |
92 | - should 'generate facebook addthis url for article' do | |
93 | - Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | |
94 | - [TextileArticle, Blog, Folder, Gallery, UploadedFile, Forum, Event, TextArticle, TinyMceArticle].each do |model| | |
95 | - a = model.new(:name => 'Some title', :body => 'Some text here.', :profile => profile) | |
96 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=Some+text+here.&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a) | |
97 | - end | |
98 | - end | |
99 | - | |
100 | - should 'generate facebook addthis url without body' do | |
101 | - Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | |
102 | - a = TinyMceArticle.new(:name => 'Test', :body => nil, :profile => profile) | |
103 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Test&p[summary]=&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Ftest&p[images][0]=", addthis_facebook_url(a) | |
104 | - end | |
105 | - | |
106 | - should 'generate facebook addthis url without tags in body' do | |
107 | - Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | |
108 | - a = TinyMceArticle.new(:name => 'Some title', :body => '<p>This <b class="bold">is</b> a test</p>', :profile => profile) | |
109 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=This+is+a+test&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a) | |
110 | - end | |
111 | - | |
112 | - should 'generate facebook addthis url with truncated body' do | |
113 | - Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | |
114 | - a = TinyMceArticle.new(:name => 'Some title', :body => 'test' * 76, :profile => profile) | |
115 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=#{'test' * 74}t...&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a) | |
116 | - end | |
117 | - | |
118 | - should 'generate facebook addthis url for tinymce article with images' do | |
119 | - Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | |
120 | - a = TinyMceArticle.new(:name => 'Some title', :body => '<p>This <b class="bold">is</b> a <img src="/images/x.png" />test</p>', :profile => profile) | |
121 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=This+is+a+test&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=http%3A%2F%2Fnoosfero.org%2Fimages%2Fx.png", addthis_facebook_url(a) | |
122 | - end | |
123 | - | |
124 | 92 | should 'theme provides addthis custom icon' do |
125 | 93 | stubs(:session).returns({:theme => 'base'}) |
126 | 94 | File.expects(:exists?).with(anything).returns(true) | ... | ... |