noosfero | 8 new commits pushed to repository
Bráulio Bhavamitra
gitlab at gitlab.com
Tue Feb 10 17:20:07 BRST 2015
Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>
Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/922a26827b37228abde7a72da2bb310caa894c99">922a2682</a> by Braulio Bhavamitra
metadata: Make config file generic
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/ee532d1612a984eb33e439ad22a8d9fb3bfee5d1">ee532d16</a> by Braulio Bhavamitra
metadata: Move to gettext locales
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/8a1be65dea5b6df9a8122f498e2a82cb8ef9ff38">8a1be65d</a> by Braulio Bhavamitra
metadata: Support key attr specification (fix tests)
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/6569e61a1957414737d6754fa5401a77fe080dbf">6569e61a</a> by Braulio Bhavamitra
metadata: Use ALL_CAPS
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/041494a8fa882035a21951a5668d63da90b3574c">041494a8</a> by Braulio Bhavamitra
metadata: Use alternate languages from article
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/af30de84b9cfb5bd12bc52e7b5fb4f2472106a23">af30de84</a> by Braulio Bhavamitra
metadata: Don't rescue errors
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/e5021790c4c284deccd32dd2e21bc44a4606536a">e5021790</a> by Braulio Bhavamitra
metadata: fix application_controller test
- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/984386a416854d4b1e2993a0649043a04027cf65">984386a4</a> by Bráulio Bhavamitra
Merge branch 'metadata-plugin' into 'master'
Changes on metadata plugin
Discussed on !359
See merge request !444
- - - - -
Changes:
=====================================
app/helpers/layout_helper.rb
=====================================
--- a/app/helpers/layout_helper.rb
+++ b/app/helpers/layout_helper.rb
@@ -116,8 +116,5 @@ module LayoutHelper
end
end
- def meta_description_tag(article=nil)
- article ? CGI.escapeHTML(truncate(strip_tags(article.body.to_s), :length => 200)) : environment.name
- end
end
=====================================
app/models/article.rb
=====================================
--- a/app/models/article.rb
+++ b/app/models/article.rb
@@ -390,6 +390,10 @@ class Article < ActiveRecord::Base
{}
end
+ def alternate_languages
+ self.translations.map(&:language)
+ end
+
scope :native_translations, :conditions => { :translation_of_id => nil }
def translatable?
=====================================
app/views/layouts/application-ng.html.erb
=====================================
--- a/app/views/layouts/application-ng.html.erb
+++ b/app/views/layouts/application-ng.html.erb
@@ -7,11 +7,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="description" content="<%= @environment.name %>" />
- <!-- Twitter Card -->
- <meta name="twitter:card" value="summary">
- <meta name="twitter:title" content="<%= h page_title %>">
- <meta name="twitter:description" content="<%= meta_description_tag(@page) %>">
-
<!-- site root -->
<meta property="noosfero:root" content="<%= Noosfero.root %>"/>
=====================================
plugins/metadata/config.yml.dist
=====================================
--- a/plugins/metadata/config.yml.dist
+++ b/plugins/metadata/config.yml.dist
@@ -1,12 +1,12 @@
open_graph:
- domain: cirandas.net
- environment_logo: 'http://cirandas.net/designs/themes/cirandas-responsive/images/cirandas-logo-110.png'
+ domain: domainregisteredonfacebook.com
+ environment_logo: 'http://example.com/designs/themes/environmenttheme/images/logo.png'
types:
article: article
- product: app_cirandas:sse_product
- uploaded_file: app_cirandas:document
- image: app_cirandas:picture
- profile: app_cirandas:profile
- person: app_cirandas:user
- community: app_cirandas:community
- enterprise: app_cirandas:sse_initiative
+ product: facebook_app:sse_product
+ uploaded_file: facebook_app:document
+ image: facebook_app:picture
+ profile: facebook_app:profile
+ person: facebook_app:user
+ community: facebook_app:community
+ enterprise: facebook_app:sse_initiative
=====================================
plugins/metadata/lib/ext/article.rb
=====================================
--- a/plugins/metadata/lib/ext/article.rb
+++ b/plugins/metadata/lib/ext/article.rb
@@ -2,31 +2,42 @@ require_dependency 'article'
class Article
- Metadata = {
- 'og:type' => MetadataPlugin.og_types[:article],
- 'og:url' => proc{ |a, c| c.og_url_for a.url },
- 'og:title' => proc{ |a, c| a.title },
- 'og:image' => proc do |a, c|
- result = a.body_images_paths
- result = "#{a.profile.environment.top_url}#{a.profile.image.public_filename}" if a.profile.image if result.blank?
- result = MetadataPlugin.config[:open_graph][:environment_logo] if result.blank?
- result
- end,
- 'og:see_also' => [],
- 'og:site_name' => proc{ |a, c| a.profile.name },
- 'og:updated_time' => proc{ |a, c| a.updated_at.iso8601 },
- 'og:locale:locale' => proc{ |a, c| a.environment.default_language },
- 'og:locale:alternate' => proc{ |a, c| a.environment.languages - [a.environment.default_language] },
- 'twitter:image' => proc{ |a, c| a.body_images_paths },
- 'article:expiration_time' => "", # In the future we might want to populate this
- 'article:modified_time' => proc{ |a, c| a.updated_at.iso8601 },
- 'article:published_time' => proc{ |a, c| a.published_at.iso8601 },
- 'article:section' => "", # In the future we might want to populate this
- 'article:tag' => proc{ |a, c| a.tags.map &:name },
- 'og:description' => proc{ |a, c| ActionView::Base.full_sanitizer.sanitize a.body },
- 'og:rich_attachment' => "",
+ metadata_spec namespace: :og, key_attr: :property, tags: {
+ type: MetadataPlugin.og_types[:article] || :article,
+ url: proc{ |a, plugin| plugin.og_url_for a.url },
+ title: proc{ |a, plugin| "#{a.title} - #{a.profile.name}" },
+ image: proc do |a, plugin|
+ result = a.body_images_paths
+ result = "#{a.profile.environment.top_url}#{a.profile.image.public_filename}" if a.profile.image if result.blank?
+ result ||= MetadataPlugin.config[:open_graph][:environment_logo] rescue nil if result.blank?
+ result
+ end,
+ see_also: [],
+ site_name: proc{ |a, c| a.profile.name },
+ updated_time: proc{ |a, c| a.updated_at.iso8601 },
+ 'locale:locale' => proc{ |a, c| a.language || a.environment.default_language },
+ 'locale:alternate' => proc{ |a, c| a.alternate_languages },
+
+ description: proc{ |a, plugin| ActionView::Base.full_sanitizer.sanitize a.body },
+ rich_attachment: "",
}
+ metadata_spec namespace: :twitter, key_attr: :name, tags: {
+ card: 'summary',
+ description: proc do |a, plugin|
+ description = a.body.to_s || a.environment.name
+ CGI.escapeHTML(plugin.helpers.truncate(plugin.helpers.strip_tags(description), length: 200))
+ end,
+ title: proc{ |a, plugin| "#{a.title} - #{a.profile.name}" },
+ image: proc{ |a, plugin| a.body_images_paths },
+ }
+ metadata_spec namespace: :article, key_attr: :property, tags: {
+ expiration_time: "", # In the future we might want to populate this
+ modified_time: proc{ |a, plugin| a.updated_at.iso8601 },
+ published_time: proc{ |a, plugin| a.published_at.iso8601 },
+ section: "", # In the future we might want to populate this
+ tag: proc{ |a, plugin| a.tags.map &:name },
+ }
end
=====================================
plugins/metadata/lib/ext/community.rb
=====================================
--- a/plugins/metadata/lib/ext/community.rb
+++ b/plugins/metadata/lib/ext/community.rb
@@ -3,8 +3,8 @@ require_dependency "#{File.dirname __FILE__}/profile"
class Community
- Metadata = Metadata.merge({
- 'og:type' => MetadataPlugin.og_types[:community],
- })
+ metadata_spec namespace: :og, tags: {
+ type: MetadataPlugin.og_types[:community] || :community,
+ }
end
=====================================
plugins/metadata/lib/ext/enterprise.rb
=====================================
--- a/plugins/metadata/lib/ext/enterprise.rb
+++ b/plugins/metadata/lib/ext/enterprise.rb
@@ -3,16 +3,18 @@ require_dependency "#{File.dirname __FILE__}/profile"
class Enterprise
- Metadata = Metadata.merge({
- 'og:type' => MetadataPlugin.og_types[:enterprise],
- 'business:contact_data:email' => proc{ |e, c| e.contact_email },
- 'business:contact_data:phone_number' => proc{ |e, c| e.contact_phone },
- 'business:contact_data:street_address' => proc{ |e, c| e.address },
- 'business:contact_data:locality' => proc{ |e, c| e.city },
- 'business:contact_data:region' => proc{ |e, c| e.state },
- 'business:contact_data:postal_code' => proc{ |e, c| e.zip_code },
- 'business:contact_data:country_name' => proc{ |e| e.country },
- 'place:location:latitude' => proc{ |e, c| p.lat },
- 'place:location:longitude' => proc{ |e, c| p.lng },
- })
+ metadata_spec namespace: :og, tags: {
+ type: MetadataPlugin.og_types[:enterprise] || :enterprise,
+ }
+
+ metadata_spec namespace: 'business:contact_data', tags: {
+ email: proc{ |e, plugin| e.contact_email },
+ phone_number: proc{ |e, plugin| e.contact_phone },
+ street_address: proc{ |e, plugin| e.address },
+ locality: proc{ |e, plugin| e.city },
+ region: proc{ |e, plugin| e.state },
+ postal_code: proc{ |e, plugin| e.zip_code },
+ country_name: proc{ |e, plugin| e.country },
+ }
+
end
=====================================
plugins/metadata/lib/ext/environment.rb
=====================================
--- a/plugins/metadata/lib/ext/environment.rb
+++ b/plugins/metadata/lib/ext/environment.rb
@@ -2,12 +2,20 @@ require_dependency 'environment'
class Environment
- Metadata = {
- 'og:site_name' => proc{ |e, c| e.name },
- 'og:description' => proc{ |e, c| e.name },
- 'og:url' => proc{ |e, c| e.top_url },
- 'og:locale:locale' => proc{ |e, c| e.default_language },
- 'og:locale:alternate' => proc{ |e, c| e.languages - [e.default_language] }
+ metadata_spec namespace: :og, tags: {
+ type: 'website',
+ title: proc{ |e, plugin| e.name },
+ site_name: proc{ |e, plugin| e.name },
+ description: proc{ |e, plugin| e.name },
+ url: proc{ |e, plugin| e.top_url },
+ 'locale:locale' => proc{ |e, plugin| e.default_language },
+ 'locale:alternate' => proc{ |e, plugin| if e.default_language then e.languages - [e.default_language] else e.languages end },
+ }
+
+ metadata_spec namespace: :twitter, key_attr: :name, tags: {
+ card: 'summary',
+ title: proc{ |e, plugin| e.name },
+ description: proc{ |e, plugin| e.name },
}
end
=====================================
plugins/metadata/lib/ext/person.rb
=====================================
--- a/plugins/metadata/lib/ext/person.rb
+++ b/plugins/metadata/lib/ext/person.rb
@@ -3,8 +3,8 @@ require_dependency "#{File.dirname __FILE__}/profile"
class Person
- Metadata = Metadata.merge({
- 'og:type' => MetadataPlugin.og_types[:person],
- })
+ metadata_spec namespace: :og, tags: {
+ type: MetadataPlugin.og_types[:person] || :person,
+ }
end
=====================================
plugins/metadata/lib/ext/product.rb
=====================================
--- a/plugins/metadata/lib/ext/product.rb
+++ b/plugins/metadata/lib/ext/product.rb
@@ -2,24 +2,25 @@ require_dependency 'product'
class Product
- Metadata = {
- 'og:type' => MetadataPlugin.og_types[:product],
- 'og:url' => proc{ |p, c| c.og_url_for p.url },
- 'og:gr_hascurrencyvalue' => proc{ |p, c| p.price.to_f },
- 'og:gr_hascurrency' => proc{ |p, c| p.environment.currency_unit },
- 'og:title' => proc{ |p, c| p.name },
- 'og:description' => proc{ |p, c| ActionView::Base.full_sanitizer.sanitize p.description },
- 'og:image' => proc{ |p, c| "#{p.environment.top_url}#{p.image.public_filename}" if p.image },
- 'og:image:type' => proc{ |p, c| p.image.content_type if p.image },
- 'og:image:height' => proc{ |p, c| p.image.height if p.image },
- 'og:image:width' => proc{ |p, c| p.image.width if p.image },
- 'og:see_also' => [],
- 'og:site_name' => proc{ |p, c| c.og_url_for p.profile.url },
- 'og:updated_time' => proc{ |p, c| p.updated_at.iso8601 },
- 'og:locale:locale' => proc{ |p, c| p.environment.default_language },
- 'og:locale:alternate' => proc{ |p, c| p.environment.languages - [p.environment.default_language] },
- }
+ metadata_spec namespace: :og, tags: {
+ type: MetadataPlugin.og_types[:product] || :product,
+ url: proc{ |p, plugin| plugin.og_url_for p.url },
+ gr_hascurrencyvalue: proc{ |p, plugin| p.price.to_f },
+ gr_hascurrency: proc{ |p, plugin| p.environment.currency_unit },
+ title: proc{ |a, plugin| "#{p.name} - #{p.profile.name}" },
+ description: proc{ |p, plugin| ActionView::Base.full_sanitizer.sanitize p.description },
+
+ image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image },
+ 'image:type' => proc{ |p, plugin| p.image.content_type if p.image },
+ 'image:height' => proc{ |p, plugin| p.image.height if p.image },
+ 'image:width' => proc{ |p, plugin| p.image.width if p.image },
- protected
+ see_also: [],
+ site_name: proc{ |p, plugin| plugin.og_url_for p.profile.url },
+ updated_time: proc{ |p, plugin| p.updated_at.iso8601 },
+
+ 'locale:locale' => proc{ |p, plugin| p.environment.default_language },
+ 'locale:alternate' => proc{ |p, plugin| p.environment.languages - [p.environment.default_language] if p.environment.languages },
+ }
end
=====================================
plugins/metadata/lib/ext/profile.rb
=====================================
--- a/plugins/metadata/lib/ext/profile.rb
+++ b/plugins/metadata/lib/ext/profile.rb
@@ -2,23 +2,32 @@ require_dependency 'profile'
class Profile
- Metadata = {
- 'og:type' => MetadataPlugin.og_types[:profile],
- 'og:image' => proc{ |p, c| "#{p.environment.top_url}#{p.image.public_filename}" if p.image },
- 'og:title' => proc{ |p, c| p.short_name nil },
- 'og:url' => proc do |p, c|
+ metadata_spec namespace: :og, tags: {
+ type: MetadataPlugin.og_types[:profile] || :profile,
+ image: proc{ |p, plugin| "#{p.environment.top_url}#{p.image.public_filename}" if p.image },
+ title: proc{ |p, plugin| p.nickname || p.name },
+ url: proc do |p, plugin|
#force profile identifier for custom domains and fixed host. see og_url_for
- c.og_url_for p.url.merge(profile: p.identifier)
+ plugin.og_url_for p.url.merge(profile: p.identifier)
end,
- 'og:description' => proc{ |p, c| p.description },
- 'og:updated_time' => proc{ |p, c| p.updated_at.iso8601 },
- 'place:location:latitude' => proc{ |p, c| p.lat },
- 'place:location:longitude' => proc{ |p, c| p.lng },
- 'og:locale:locale' => proc{ |p, c| p.environment.default_language },
- 'og:locale:alternate' => proc{ |p, c| p.environment.languages - [p.environment.default_language] },
- 'og:site_name' => "",
- 'og:see_also' => "",
- 'og:rich_attachment' => "",
+ description: proc{ |p, plugin| p.description },
+ updated_time: proc{ |p, plugin| p.updated_at.iso8601 },
+ 'locale:locale' => proc{ |p, plugin| p.environment.default_language },
+ 'locale:alternate' => proc{ |p, plugin| p.environment.languages - [p.environment.default_language] if p.environment.languages },
+ site_name: "",
+ see_also: "",
+ rich_attachment: "",
+ }
+
+ metadata_spec namespace: 'place:location', tags: {
+ latitude: proc{ |p, plugin| p.lat },
+ longitude: proc{ |p, plugin| p.lng },
+ }
+
+ metadata_spec namespace: :twitter, key_attr: :name, tags: {
+ card: 'summary',
+ title: proc{ |p, plugin| p.name },
+ description: proc{ |p, plugin| p.description },
}
end
=====================================
plugins/metadata/lib/ext/uploaded_file.rb
=====================================
--- a/plugins/metadata/lib/ext/uploaded_file.rb
+++ b/plugins/metadata/lib/ext/uploaded_file.rb
@@ -3,15 +3,15 @@ require_dependency "#{File.dirname __FILE__}/article"
class UploadedFile
- Metadata = {
- 'og:type' => proc do |u, c|
+ metadata_spec namespace: :og, tags: {
+ type: proc do |u, plugin|
type = if u.image? then :image else :uploaded_file end
- MetadataPlugin.og_types[type]
+ MetadataPlugin.og_types[type] || type
end,
- 'og:url' => proc{ |u, c| c.og_url_for u.url.merge(view: true) },
- 'og:title' => proc{ |u, c| u.title },
- 'og:image' => proc{ |u, c| "#{u.environment.top_url}#{u.public_filename}" if u.image? },
- 'og:description' => proc{ |u, c| u.abstract || u.title },
+ url: proc{ |u, plugin| plugin.og_url_for u.url.merge(view: true) },
+ title: proc{ |u, plugin| u.title },
+ image: proc{ |u, plugin| "#{u.environment.top_url}#{u.public_filename}" if u.image? },
+ description: proc{ |u, plugin| u.abstract || u.title },
}
end
=====================================
plugins/metadata/lib/metadata_plugin.rb
=====================================
--- a/plugins/metadata/lib/metadata_plugin.rb
+++ b/plugins/metadata/lib/metadata_plugin.rb
@@ -2,11 +2,11 @@
class MetadataPlugin < Noosfero::Plugin
def self.plugin_name
- I18n.t 'metadata_plugin.lib.plugin.name'
+ _('Export metadata')
end
def self.plugin_description
- I18n.t 'metadata_plugin.lib.plugin.description'
+ _('Export metadata for models on meta tags')
end
def self.config
@@ -17,30 +17,64 @@ class MetadataPlugin < Noosfero::Plugin
@og_types ||= self.config[:open_graph][:types] rescue {}
end
+ CONTROLLERS = {
+ manage_products: {
+ variable: :@product,
+ },
+ content_viewer: {
+ variable: proc do
+ if profile and profile.home_page_id == @page.id
+ @profile
+ elsif @page.respond_to? :encapsulated_file
+ @page.encapsulated_file
+ else
+ @page
+ end
+ end,
+ },
+ profile: {
+ variable: :@profile,
+ },
+ # fallback
+ environment: {
+ variable: :@environment,
+ },
+ }
+
def head_ending
plugin = self
lambda do
- options = MetadataPlugin::Spec::Controllers[controller.controller_path.to_sym]
- options ||= MetadataPlugin::Spec::Controllers[:profile] if controller.is_a? ProfileController
- options ||= MetadataPlugin::Spec::Controllers[:environment]
+ options = MetadataPlugin::CONTROLLERS[controller.controller_path.to_sym]
+ options ||= MetadataPlugin::CONTROLLERS[:profile] if controller.is_a? ProfileController
+ options ||= MetadataPlugin::CONTROLLERS[:environment]
return unless options
return unless object = case variable = options[:variable]
- when Proc then instance_exec(&variable) rescue nil
+ when Proc then instance_exec(&variable)
else instance_variable_get variable
end
- return unless metadata = (object.class.const_get(:Metadata) rescue nil)
-
- metadata.map do |property, contents|
- contents = contents.call(object, plugin) rescue nil if contents.is_a? Proc
- next if contents.blank?
-
- Array(contents).map do |content|
- content = content.call(object, plugin) rescue nil if content.is_a? Proc
- next if content.blank?
- tag 'meta', property: property, content: content
- end.join
- end.join
+ return unless specs = (object.class.metadata_specs rescue nil)
+
+ r = []
+ specs.each do |namespace, spec|
+ namespace = "#{namespace}:" if namespace.present?
+ key_attr = spec[:key_attr] || :property
+ value_attr = spec[:value_attr] || :content
+ tags = spec[:tags]
+
+ tags.each do |key, values|
+ key = "#{namespace}#{key}"
+ values = values.call(object, plugin) if values.is_a? Proc
+ next if values.blank?
+
+ Array(values).each do |value|
+ value = value.call(object, plugin) if value.is_a? Proc
+ next if value.blank?
+ r << tag(:meta, key_attr => key, value_attr => value)
+ end
+ end
+ end
+ r.join
end
end
@@ -51,9 +85,16 @@ class MetadataPlugin < Noosfero::Plugin
Noosfero::Application.routes.url_helpers.url_for options
end
+ def helpers
+ self.context.class.helpers
+ end
+
protected
end
ActiveSupport.run_load_hooks :metadata_plugin, MetadataPlugin
+ActiveSupport.on_load :active_record do
+ ActiveRecord::Base.extend MetadataPlugin::Specs::ClassMethods
+end
=====================================
plugins/metadata/lib/metadata_plugin/spec.rb
=====================================
--- a/plugins/metadata/lib/metadata_plugin/spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-
-class MetadataPlugin::Spec
-
- Controllers = {
- manage_products: {
- variable: :@product,
- },
- content_viewer: {
- variable: proc do
- if profile and profile.home_page_id == @page.id
- @profile
- elsif @page.respond_to? :encapsulated_file
- @page.encapsulated_file
- else
- @page
- end
- end,
- },
- # fallback
- profile: {
- variable: :@profile,
- },
- # last fallback
- environment: {
- variable: :@environment,
- },
- }
-
-end
=====================================
plugins/metadata/lib/metadata_plugin/specs.rb
=====================================
--- /dev/null
+++ b/plugins/metadata/lib/metadata_plugin/specs.rb
@@ -0,0 +1,22 @@
+module MetadataPlugin::Specs
+
+ module ClassMethods
+
+ def self.extended base
+ base.class_attribute :metadata_specs
+ base.metadata_specs ||= {}
+ end
+
+ def metadata_spec spec = {}
+ namespace = spec[:namespace]
+ # setters are used to avoid propagation to super classes, see http://apidock.com/rails/Class/class_attribute
+ if _spec = self.metadata_specs[namespace]
+ self.metadata_specs = self.metadata_specs.deep_merge(namespace => _spec.deep_merge(spec))
+ else
+ self.metadata_specs = self.metadata_specs.deep_merge(namespace => spec)
+ end
+ end
+
+ end
+
+end
=====================================
plugins/metadata/locales/en.yml
=====================================
--- a/plugins/metadata/locales/en.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-"en-US": &en-US
-
- metadata_plugin:
- lib:
- plugin:
- name: 'Export metadata'
- description: 'Export metadata for models on meta tags'
-
-'en_US':
- <<: *en-US
-'en':
- <<: *en-US
-
=====================================
plugins/metadata/locales/pt.yml
=====================================
--- a/plugins/metadata/locales/pt.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-
-"pt-BR": &pt-BR
-
- metadata_plugin:
- lib:
- plugin:
- name: 'Exporta metadados'
- description: 'Exporta metadados de modelos em tags meta'
-
-'pt_BR':
- <<: *pt-BR
-'pt':
- <<: *pt-BR
-
=====================================
plugins/metadata/test/functional/content_viewer_controller_test.rb
=====================================
--- /dev/null
+++ b/plugins/metadata/test/functional/content_viewer_controller_test.rb
@@ -0,0 +1,51 @@
+require 'test_helper'
+require 'content_viewer_controller'
+
+# Re-raise errors caught by the controller.
+class ContentViewerController; def rescue_action(e) raise e end; end
+
+class ContentViewerControllerTest < ActionController::TestCase
+
+ def setup
+ @controller = ContentViewerController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ @profile = create_user('testinguser').person
+ @environment = @profile.environment
+ @environment.enabled_plugins += ['MetadataPlugin']
+ @environment.save!
+ end
+
+ attr_reader :profile, :environment
+
+ should 'produce meta tags for profile if on homepage' do
+ get :view_page, profile: profile.identifier, page: []
+ assert_tag tag: 'meta', attributes: {property: 'og:title', content: profile.name}
+ end
+
+ should 'add meta tags with article info' do
+ a = TinyMceArticle.create(name: 'Article to be shared', body: 'This article should be shared with all social networks', profile: profile)
+
+ get :view_page, profile: profile.identifier, page: [ a.name.to_slug ]
+
+ assert_tag tag: 'meta', attributes: { name: 'twitter:title', content: /#{a.name} - #{a.profile.name}/ }
+ assert_tag tag: 'meta', attributes: { name: 'twitter:description', content: a.body }
+ assert_no_tag tag: 'meta', attributes: { name: 'twitter:image' }
+ assert_tag tag: 'meta', attributes: { property: 'og:type', content: 'article' }
+ assert_tag tag: 'meta', attributes: { property: 'og:url', content: /\/#{profile.identifier}\/#{a.name.to_slug}/ }
+ assert_tag tag: 'meta', attributes: { property: 'og:title', content: /#{a.name} - #{a.profile.name}/ }
+ assert_tag tag: 'meta', attributes: { property: 'og:site_name', content: a.profile.name }
+ assert_tag tag: 'meta', attributes: { property: 'og:description', content: a.body }
+ assert_no_tag tag: 'meta', attributes: { property: 'og:image' }
+ end
+
+ should 'add meta tags with article images' do
+ 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)
+
+ get :view_page, profile: profile.identifier, page: [ a.name.to_slug ]
+ assert_tag tag: 'meta', attributes: { name: 'twitter:image', content: /\/images\/x.png/ }
+ assert_tag tag: 'meta', attributes: { property: 'og:image', content: /\/images\/x.png/ }
+ end
+
+end
=====================================
plugins/metadata/test/functional/home_controller_test.rb
=====================================
--- /dev/null
+++ b/plugins/metadata/test/functional/home_controller_test.rb
@@ -0,0 +1,33 @@
+require 'test_helper'
+require 'home_controller'
+
+# Re-raise errors caught by the controller.
+class HomeController; def rescue_action(e) raise e end; end
+
+class HomeControllerTest < ActionController::TestCase
+
+ def setup
+ @controller = HomeController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ Noosfero::Plugin.stubs(:all).returns([MetadataPlugin.name])
+ Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([MetadataPlugin.new])
+ end
+
+ should 'display meta tags for social media' do
+ get :index
+ assert_tag :tag => 'meta', :attributes => { :name => 'twitter:card', :content => 'summary' }
+ assert_tag :tag => 'meta', :attributes => { :name => 'twitter:title', :content => assigns(:environment).name }
+ assert_tag :tag => 'meta', :attributes => { :name => 'twitter:description', :content => assigns(:environment).name }
+ assert_no_tag :tag => 'meta', :attributes => { :name => 'twitter:image' }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:type', :content => 'website' }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:url', :content => assigns(:environment).top_url }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:title', :content => assigns(:environment).name }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:site_name', :content => assigns(:environment).name }
+ assert_tag :tag => 'meta', :attributes => { :property => 'og:description', :content => assigns(:environment).name }
+ assert_no_tag :tag => 'meta', :attributes => { :property => 'article:published_time' }
+ assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' }
+ end
+
+end
=====================================
test/functional/application_controller_test.rb
=====================================
--- a/test/functional/application_controller_test.rb
+++ b/test/functional/application_controller_test.rb
@@ -498,21 +498,6 @@ class ApplicationControllerTest < ActionController::TestCase
end
- should 'display meta tags for social media' do
- get :index
- assert_tag :tag => 'meta', :attributes => { :name => 'twitter:card', :value => 'summary' }
- assert_tag :tag => 'meta', :attributes => { :name => 'twitter:title', :content => assigns(:environment).name }
- assert_tag :tag => 'meta', :attributes => { :name => 'twitter:description', :content => assigns(:environment).name }
- assert_no_tag :tag => 'meta', :attributes => { :name => 'twitter:image' }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:type', :content => 'website' }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:url', :content => assigns(:environment).top_url }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:title', :content => assigns(:environment).name }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:site_name', :content => assigns(:environment).name }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:description', :content => assigns(:environment).name }
- assert_no_tag :tag => 'meta', :attributes => { :property => 'article:published_time' }
- assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' }
- end
-
should 'register search_term occurrence on find_by_contents' do
controller = ApplicationController.new
controller.stubs(:environment).returns(Environment.default)
=====================================
test/functional/content_viewer_controller_test.rb
=====================================
--- a/test/functional/content_viewer_controller_test.rb
+++ b/test/functional/content_viewer_controller_test.rb
@@ -1405,30 +1405,6 @@ class ContentViewerControllerTest < ActionController::TestCase
end
end
- should 'add meta tags with article info' do
- a = TinyMceArticle.create(:name => 'Article to be shared', :body => 'This article should be shared with all social networks', :profile => profile)
-
- get :view_page, :profile => profile.identifier, :page => [ a.name.to_slug ]
-
- assert_tag :tag => 'meta', :attributes => { :name => 'twitter:title', :content => /#{a.name} - #{a.profile.name}/ }
- assert_tag :tag => 'meta', :attributes => { :name => 'twitter:description', :content => a.body }
- assert_no_tag :tag => 'meta', :attributes => { :name => 'twitter:image' }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:type', :content => 'article' }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:url', :content => /\/#{profile.identifier}\/#{a.name.to_slug}/ }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:title', :content => /#{a.name} - #{a.profile.name}/ }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:site_name', :content => a.profile.name }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:description', :content => a.body }
- assert_no_tag :tag => 'meta', :attributes => { :property => 'og:image' }
- end
-
- should 'add meta tags with article images' do
- 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)
-
- get :view_page, :profile => profile.identifier, :page => [ a.name.to_slug ]
- assert_tag :tag => 'meta', :attributes => { :name => 'twitter:image', :content => /\/images\/x.png/ }
- assert_tag :tag => 'meta', :attributes => { :property => 'og:image', :content => /\/images\/x.png/ }
- end
-
should 'manage private article visualization' do
community = Community.create(:name => 'test-community')
community.add_member(@profile)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150210/17cf3431/attachment-0001.html>
More information about the Noosfero-dev
mailing list