From e5021790c4c284deccd32dd2e21bc44a4606536a Mon Sep 17 00:00:00 2001 From: Braulio Bhavamitra Date: Tue, 10 Feb 2015 15:17:06 -0300 Subject: [PATCH] metadata: fix application_controller test --- plugins/metadata/lib/ext/environment.rb | 10 +++++++++- plugins/metadata/lib/ext/profile.rb | 6 ++++++ plugins/metadata/test/functional/home_controller_test.rb | 33 +++++++++++++++++++++++++++++++++ test/functional/application_controller_test.rb | 15 --------------- 4 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 plugins/metadata/test/functional/home_controller_test.rb diff --git a/plugins/metadata/lib/ext/environment.rb b/plugins/metadata/lib/ext/environment.rb index 55fb380..31b5ff5 100644 --- a/plugins/metadata/lib/ext/environment.rb +++ b/plugins/metadata/lib/ext/environment.rb @@ -3,11 +3,19 @@ require_dependency 'environment' class Environment 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| e.languages - [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 diff --git a/plugins/metadata/lib/ext/profile.rb b/plugins/metadata/lib/ext/profile.rb index 016ae09..2deef3e 100644 --- a/plugins/metadata/lib/ext/profile.rb +++ b/plugins/metadata/lib/ext/profile.rb @@ -24,4 +24,10 @@ class Profile 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 diff --git a/plugins/metadata/test/functional/home_controller_test.rb b/plugins/metadata/test/functional/home_controller_test.rb new file mode 100644 index 0000000..4cd69f9 --- /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 diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index f0fb7b0..1c4ca48 100644 --- 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) -- libgit2 0.21.2