Commit 2c68eefb65304097a2133ea097d7fe23e6a7ee89
Committed by
Daniela Feitosa
1 parent
7590a7c4
Exists in
master
and in
29 other branches
Merging web2.0.yml and mail.yml into noosfero.yml
- new config entry: addthis_enabled - new Rails initializer to load config file (ActionItem1820)
Showing
14 changed files
with
69 additions
and
105 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -30,17 +30,6 @@ module ApplicationHelper | @@ -30,17 +30,6 @@ module ApplicationHelper | ||
30 | (@page && !@page.language.blank?) ? @page.language : FastGettext.locale | 30 | (@page && !@page.language.blank?) ? @page.language : FastGettext.locale |
31 | end | 31 | end |
32 | 32 | ||
33 | - def load_web2_conf | ||
34 | - if File.exists?( RAILS_ROOT + '/config/web2.0.yml') | ||
35 | - YAML.load_file( RAILS_ROOT + '/config/web2.0.yml' ) | ||
36 | - else | ||
37 | - {} | ||
38 | - end | ||
39 | - end | ||
40 | - def web2_conf | ||
41 | - @web_conf ||= load_web2_conf | ||
42 | - end | ||
43 | - | ||
44 | # Displays context help. You can pass the content of the help message as the | 33 | # Displays context help. You can pass the content of the help message as the |
45 | # first parameter or using template code inside a block passed to this | 34 | # first parameter or using template code inside a block passed to this |
46 | # method. *Note*: the block is ignored if <tt>content</tt> is not | 35 | # method. *Note*: the block is ignored if <tt>content</tt> is not |
@@ -570,12 +559,12 @@ module ApplicationHelper | @@ -570,12 +559,12 @@ module ApplicationHelper | ||
570 | :protocol => 'http://', | 559 | :protocol => 'http://', |
571 | :only_path => false, | 560 | :only_path => false, |
572 | :controller => 'avatar.php', | 561 | :controller => 'avatar.php', |
573 | - :d => web2_conf['gravatar'] ? web2_conf['gravatar']['default'] : nil | 562 | + :d => NOOSFERO_CONF['gravatar'] ? NOOSFERO_CONF['gravatar'] : nil |
574 | }.merge(options) ) | 563 | }.merge(options) ) |
575 | end | 564 | end |
576 | 565 | ||
577 | def str_gravatar_url_for(email, options = {}) | 566 | def str_gravatar_url_for(email, options = {}) |
578 | - default = web2_conf['gravatar'] ? web2_conf['gravatar']['default'] : nil | 567 | + default = NOOSFERO_CONF['gravatar'] ? NOOSFERO_CONF['gravatar'] : nil |
579 | url = 'http://www.gravatar.com/avatar.php?gravatar_id=' + | 568 | url = 'http://www.gravatar.com/avatar.php?gravatar_id=' + |
580 | Digest::MD5.hexdigest(email) | 569 | Digest::MD5.hexdigest(email) |
581 | { | 570 | { |
app/models/google_maps.rb
@@ -6,14 +6,6 @@ class GoogleMaps | @@ -6,14 +6,6 @@ class GoogleMaps | ||
6 | 6 | ||
7 | include ApplicationHelper | 7 | include ApplicationHelper |
8 | 8 | ||
9 | - def erase_config | ||
10 | - @config = nil | ||
11 | - end | ||
12 | - | ||
13 | - def config | ||
14 | - @config ||= (web2_conf['googlemaps'] || {}) | ||
15 | - end | ||
16 | - | ||
17 | def enabled?(domain) | 9 | def enabled?(domain) |
18 | domain = Domain.find_by_name(domain) | 10 | domain = Domain.find_by_name(domain) |
19 | domain ? !domain.google_maps_key.nil? : false | 11 | domain ? !domain.google_maps_key.nil? : false |
@@ -25,7 +17,7 @@ class GoogleMaps | @@ -25,7 +17,7 @@ class GoogleMaps | ||
25 | end | 17 | end |
26 | 18 | ||
27 | def initial_zoom | 19 | def initial_zoom |
28 | - config['initial_zoom'] || 4 | 20 | + NOOSFERO_CONF['googlemaps_initial_zoom'] || 4 |
29 | end | 21 | end |
30 | 22 | ||
31 | def api_url(domain) | 23 | def api_url(domain) |
app/models/mail_conf.rb
1 | class MailConf | 1 | class MailConf |
2 | class << self | 2 | class << self |
3 | 3 | ||
4 | - def config_file | ||
5 | - File.join(RAILS_ROOT, 'config', 'mail.yml') | ||
6 | - end | ||
7 | - | ||
8 | - def config | ||
9 | - if File.exists?(config_file) | ||
10 | - YAML.load_file(config_file) | ||
11 | - else | ||
12 | - { 'webmail_url' => 'http://webmail.example.com' } | ||
13 | - end | 4 | + def default_webmail_url |
5 | + 'http://webmail.example.com' | ||
14 | end | 6 | end |
15 | 7 | ||
16 | def enabled? | 8 | def enabled? |
17 | - config['enabled'] || false | 9 | + NOOSFERO_CONF['mail_enabled'] || false |
18 | end | 10 | end |
19 | 11 | ||
20 | def webmail_url(username, domain) | 12 | def webmail_url(username, domain) |
21 | - config['webmail_url'] % [username, domain] | 13 | + (NOOSFERO_CONF['webmail_url'] || default_webmail_url) % [username, domain] |
22 | end | 14 | end |
23 | 15 | ||
24 | end | 16 | end |
app/views/content_viewer/view_page.rhtml
@@ -101,21 +101,14 @@ | @@ -101,21 +101,14 @@ | ||
101 | 101 | ||
102 | <%= display_source_info(@page) %> | 102 | <%= display_source_info(@page) %> |
103 | 103 | ||
104 | -<% | ||
105 | - # AddThis Button | ||
106 | - if block_given? && web2_conf['addthis'] | ||
107 | - opts = web2_conf['addthis'] | ||
108 | -%> | 104 | +<% if NOOSFERO_CONF['addthis_enabled'] %> |
109 | <div id="addThis"> | 105 | <div id="addThis"> |
110 | <script type="text/javascript"> | 106 | <script type="text/javascript"> |
111 | addthis_brand = '<%= escape_javascript( @environment.name ) %>'; | 107 | addthis_brand = '<%= escape_javascript( @environment.name ) %>'; |
112 | -<%= | ||
113 | - str = '' | ||
114 | - opts.each { |k, v| | ||
115 | - str += ' addthis_'+ k +' = "'+ escape_javascript( v ) +"\";\n" | ||
116 | - } | ||
117 | - str | ||
118 | -%></script> | 108 | + addthis_pub = '<%= escape_javascript( NOOSFERO_CONF['addthis_pub'] ) %>'; |
109 | + addthis_logo = '<%= escape_javascript( NOOSFERO_CONF['addthis_logo'] ) %>'; | ||
110 | + addthis_options = '<%= escape_javascript( NOOSFERO_CONF['addthis_options'] ) %>'; | ||
111 | +</script> | ||
119 | <a href="http://www.addthis.com/bookmark.php" id="bt_addThis" target="_blank" onmouseover="return addthis_open(this, '', '[URL]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/images/bt-bookmark.gif" width="53" height="16" border="0" alt="" /></a><script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script> | 112 | <a href="http://www.addthis.com/bookmark.php" id="bt_addThis" target="_blank" onmouseover="return addthis_open(this, '', '[URL]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/images/bt-bookmark.gif" width="53" height="16" border="0" alt="" /></a><script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script> |
120 | </div> | 113 | </div> |
121 | <% end %> | 114 | <% end %> |
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +NOOSFERO_CONF = YAML.load_file("#{RAILS_ROOT}/config/noosfero.yml")[RAILS_ENV] |
config/mail.yml.dist
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +development: &DEVELOPMENT | ||
2 | + mail_enabled: true | ||
3 | + webmail_url: "http://localhost.localdomain/" | ||
4 | + addthis_enabled: true | ||
5 | + addthis_pub: your-user-name | ||
6 | + addthis_logo: http://localhost:3000/images/logo-200x50.png | ||
7 | + addthis_options: favorites, email, digg, delicious, technorati, slashdot, twitter, more | ||
8 | + gravatar: wavatar | ||
9 | + googlemaps_initial_zoom: 4 | ||
10 | + | ||
11 | +test: &TEST | ||
12 | + <<: *DEVELOPMENT | ||
13 | + | ||
14 | +production: |
config/web2.0.yml.dist
@@ -1,12 +0,0 @@ | @@ -1,12 +0,0 @@ | ||
1 | -# This file configures all Web 2.0 services used by this noosfero instalation | ||
2 | - | ||
3 | -# You can add (or remove) any addthis option here. | ||
4 | -# Know more: http://www.addthis.com/customization.php | ||
5 | -addthis: | ||
6 | - pub: your-user-name | ||
7 | - logo: http://localhost:3000/images/logo-200x50.png | ||
8 | - options: favorites, email, digg, delicious, technorati, slashdot, twitter, more | ||
9 | -googlemaps: | ||
10 | - key: <id google> | ||
11 | -gravatar: | ||
12 | - default: wavatar |
gitignore.example
@@ -5,7 +5,7 @@ doc/plugins | @@ -5,7 +5,7 @@ doc/plugins | ||
5 | tmp | 5 | tmp |
6 | config/database.yml | 6 | config/database.yml |
7 | config/session.secret | 7 | config/session.secret |
8 | -config/mail.yml | 8 | +config/noosfero.yml |
9 | config/ferret_server.yml | 9 | config/ferret_server.yml |
10 | config/mongrel_cluster.yml | 10 | config/mongrel_cluster.yml |
11 | index | 11 | index |
test/test_helper.rb
@@ -250,4 +250,16 @@ class ActionController::IntegrationTest | @@ -250,4 +250,16 @@ class ActionController::IntegrationTest | ||
250 | 250 | ||
251 | end | 251 | end |
252 | 252 | ||
253 | +def with_constants(constants, &block) | ||
254 | + old_constants = Hash.new | ||
255 | + constants.each do |constant, val| | ||
256 | + old_constants[constant] = Object.const_get(constant) | ||
257 | + silence_stderr{ Object.const_set(constant, val) } | ||
258 | + end | ||
259 | + block.call | ||
260 | + old_constants.each do |constant, val| | ||
261 | + silence_stderr{ Object.const_set(constant, val) } | ||
262 | + end | ||
263 | +end | ||
264 | + | ||
253 | Profile | 265 | Profile |
test/unit/application_helper_test.rb
@@ -8,17 +8,6 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -8,17 +8,6 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
8 | self.stubs(:session).returns({}) | 8 | self.stubs(:session).returns({}) |
9 | end | 9 | end |
10 | 10 | ||
11 | - should 'retrieve conf from "web2.0" config file' do | ||
12 | - yml = RAILS_ROOT + '/config/web2.0.yml' | ||
13 | - conf = { | ||
14 | - 'addthis'=>{'pub'=>'mylogin', 'options'=>'favorites, email'}, | ||
15 | - 'gravatar'=>{'default'=>'wavatar'} | ||
16 | - } | ||
17 | - File.expects(:exists?).with(yml).returns(true) | ||
18 | - YAML.expects(:load_file).with(yml).returns(conf) | ||
19 | - assert_equal conf, web2_conf | ||
20 | - end | ||
21 | - | ||
22 | should 'calculate correctly partial for object' do | 11 | should 'calculate correctly partial for object' do |
23 | self.stubs(:params).returns({:controller => 'test'}) | 12 | self.stubs(:params).returns({:controller => 'test'}) |
24 | 13 | ||
@@ -436,12 +425,13 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -436,12 +425,13 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
436 | end | 425 | end |
437 | 426 | ||
438 | should 'generate a gravatar url' do | 427 | should 'generate a gravatar url' do |
439 | - stubs(:web2_conf).returns({"gravatar" => {"default" => "wavatar"}}) | ||
440 | - url = str_gravatar_url_for( 'rms@gnu.org', :size => 50 ) | ||
441 | - assert_match(/^http:\/\/www\.gravatar\.com\/avatar\.php\?/, url) | ||
442 | - assert_match(/(\?|&)gravatar_id=ed5214d4b49154ba0dc397a28ee90eb7(&|$)/, url) | ||
443 | - assert_match(/(\?|&)d=wavatar(&|$)/, url) | ||
444 | - assert_match(/(\?|&)size=50(&|$)/, url) | 428 | + with_constants :NOOSFERO_CONF => {'gravatar' => 'crazyvatar'} do |
429 | + url = str_gravatar_url_for( 'rms@gnu.org', :size => 50 ) | ||
430 | + assert_match(/^http:\/\/www\.gravatar\.com\/avatar\.php\?/, url) | ||
431 | + assert_match(/(\?|&)gravatar_id=ed5214d4b49154ba0dc397a28ee90eb7(&|$)/, url) | ||
432 | + assert_match(/(\?|&)d=crazyvatar(&|$)/, url) | ||
433 | + assert_match(/(\?|&)size=50(&|$)/, url) | ||
434 | + end | ||
445 | end | 435 | end |
446 | 436 | ||
447 | should 'use theme passed via param when in development mode' do | 437 | should 'use theme passed via param when in development mode' do |
test/unit/google_maps_test.rb
@@ -4,8 +4,6 @@ class GoogleMapsTest < Test::Unit::TestCase | @@ -4,8 +4,6 @@ class GoogleMapsTest < Test::Unit::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @domain = fast_create(Domain, :name => 'example-domain', :google_maps_key => 'DOMAIN_KEY') | 6 | @domain = fast_create(Domain, :name => 'example-domain', :google_maps_key => 'DOMAIN_KEY') |
7 | - # force loading of config at every test | ||
8 | - GoogleMaps.erase_config | ||
9 | end | 7 | end |
10 | 8 | ||
11 | attr_reader :domain | 9 | attr_reader :domain |
@@ -19,18 +17,14 @@ class GoogleMapsTest < Test::Unit::TestCase | @@ -19,18 +17,14 @@ class GoogleMapsTest < Test::Unit::TestCase | ||
19 | assert !GoogleMaps.enabled?('domain-without-key') | 17 | assert !GoogleMaps.enabled?('domain-without-key') |
20 | end | 18 | end |
21 | 19 | ||
22 | - should 'not crash if config not informed' do | ||
23 | - GoogleMaps.stubs(:config).returns({}) | ||
24 | - assert_equal({}, GoogleMaps.config) | ||
25 | - end | ||
26 | - | ||
27 | should 'point correctly to google maps' do | 20 | should 'point correctly to google maps' do |
28 | assert_equal 'http://maps.google.com/maps?file=api&v=2&key=DOMAIN_KEY', GoogleMaps.api_url(domain.name) | 21 | assert_equal 'http://maps.google.com/maps?file=api&v=2&key=DOMAIN_KEY', GoogleMaps.api_url(domain.name) |
29 | end | 22 | end |
30 | 23 | ||
31 | should 'provide initial_zoom setting' do | 24 | should 'provide initial_zoom setting' do |
32 | - GoogleMaps.stubs(:config).returns({'initial_zoom' => 2}) | ||
33 | - assert_equal 2, GoogleMaps.initial_zoom | 25 | + with_constants :NOOSFERO_CONF => {'googlemaps_initial_zoom' => 2} do |
26 | + assert_equal 2, GoogleMaps.initial_zoom | ||
27 | + end | ||
34 | end | 28 | end |
35 | 29 | ||
36 | should 'use 4 as default initial_zoom' do | 30 | should 'use 4 as default initial_zoom' do |
@@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class LoadConfigTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + should 'ensure YAML file exists' do | ||
6 | + assert File.exists?("#{RAILS_ROOT}/config/noosfero.yml") | ||
7 | + end | ||
8 | + | ||
9 | + should 'ensure YAML file was loaded' do | ||
10 | + assert NOOSFERO_CONF | ||
11 | + assert_kind_of Hash, NOOSFERO_CONF | ||
12 | + end | ||
13 | + | ||
14 | +end |
test/unit/mail_conf_test.rb
@@ -2,36 +2,23 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -2,36 +2,23 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
2 | 2 | ||
3 | class MailConfTest < ActiveSupport::TestCase | 3 | class MailConfTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | - CONFIG_FILE = '/not/existing.yml' | ||
6 | - | ||
7 | - should 'use config/mail.yml as config' do | ||
8 | - assert_equal RAILS_ROOT + '/config/mail.yml', MailConf.config_file | ||
9 | - end | ||
10 | - | ||
11 | should 'enable if told to' do | 5 | should 'enable if told to' do |
12 | - MailConf.stubs(:config_file).returns(CONFIG_FILE) | ||
13 | - File.expects(:exists?).with(CONFIG_FILE).returns(true) | ||
14 | - YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => true}) | 6 | + NOOSFERO_CONF['mail_enabled'] = true |
15 | assert_equal true, MailConf.enabled? | 7 | assert_equal true, MailConf.enabled? |
16 | end | 8 | end |
17 | 9 | ||
18 | should 'disable if told to' do | 10 | should 'disable if told to' do |
19 | - MailConf.stubs(:config_file).returns(CONFIG_FILE) | ||
20 | - File.expects(:exists?).with(CONFIG_FILE).returns(true) | ||
21 | - YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => false }) | 11 | + NOOSFERO_CONF['mail_enabled'] = false |
22 | assert_equal false, MailConf.enabled? | 12 | assert_equal false, MailConf.enabled? |
23 | end | 13 | end |
24 | 14 | ||
25 | - should 'disable if config file not present' do | ||
26 | - MailConf.stubs(:config_file).returns(CONFIG_FILE) | ||
27 | - File.expects(:exists?).with(CONFIG_FILE).returns(false) | 15 | + should 'disable by default' do |
16 | + NOOSFERO_CONF['mail_enabled'] = nil | ||
28 | assert_equal false, MailConf.enabled? | 17 | assert_equal false, MailConf.enabled? |
29 | end | 18 | end |
30 | 19 | ||
31 | should 'provide webmail url preference' do | 20 | should 'provide webmail url preference' do |
32 | - MailConf.stubs(:config_file).returns(CONFIG_FILE) | ||
33 | - File.expects(:exists?).with(CONFIG_FILE).returns(true) | ||
34 | - YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => false, 'webmail_url' => 'http://some.url/webmail/%s/%s' }) | 21 | + NOOSFERO_CONF['webmail_url'] = 'http://some.url/webmail/%s/%s' |
35 | assert_equal 'http://some.url/webmail/login/example.com', MailConf.webmail_url('login', 'example.com') | 22 | assert_equal 'http://some.url/webmail/login/example.com', MailConf.webmail_url('login', 'example.com') |
36 | end | 23 | end |
37 | 24 |