Commit 6548e2f29cce9e671523abcc00422a11789ccd21

Authored by Antonio Terceiro
1 parent 0ca9cda3

ActionItem980: removing unused code

lib/noosfero/url.rb
@@ -1,62 +0,0 @@ @@ -1,62 +0,0 @@
1 -require 'noosfero'  
2 -  
3 -# This module defines utility methods for generating URL's in contexts where  
4 -# one does not have a request (i.e. ActionMailer classes like TaskMailer).  
5 -#  
6 -# TODO: document the use of config/web.yml in a INSTALL document  
7 -module Noosfero::URL  
8 -  
9 - include ActionController::UrlWriter  
10 -  
11 - class << self  
12 -  
13 - def config  
14 - if @config.nil?  
15 - config_file = File.join(RAILS_ROOT, 'config', 'web.yml')  
16 - if File.exists?(config_file)  
17 - @config = YAML::load_file(config_file)  
18 - else  
19 - if ENV['RAILS_ENV'] == 'production'  
20 - @config = {  
21 - }  
22 - else  
23 - @config = {  
24 - 'path' => '',  
25 - 'port' => 3000  
26 - }  
27 - end  
28 - end  
29 - end  
30 -  
31 - @config  
32 - end  
33 -  
34 - def included(other_module)  
35 - other_module.send(:include, ActionController::UrlWriter)  
36 - end  
37 -  
38 - end  
39 -  
40 - def port  
41 - Noosfero::URL.config['port']  
42 - end  
43 -  
44 - def path  
45 - Noosfero::URL.config['path']  
46 - end  
47 -  
48 - def generate_url(options)  
49 - local_options = {}  
50 - local_options[:port] = self.port unless self.port.nil?  
51 -  
52 - url = url_for(local_options.merge(options))  
53 -  
54 - if self.path.blank?  
55 - url  
56 - else  
57 - url.sub(/(http:\/\/[^\/]+(:\d+)?)\//, "\\1#{self.path}/")  
58 - end  
59 - end  
60 -  
61 -  
62 -end  
test/unit/noosfero_url_test.rb
@@ -1,49 +0,0 @@ @@ -1,49 +0,0 @@
1 -  
2 -require File.dirname(__FILE__) + '/../test_helper'  
3 -  
4 -require 'noosfero/url'  
5 -  
6 -class NoosferoURLTest < Test::Unit::TestCase  
7 -  
8 - include Noosfero::URL  
9 -  
10 - def setup  
11 - Noosfero::URL.instance_variable_set('@config', nil)  
12 - end  
13 -  
14 - should 'read the config file' do  
15 - file = "#{RAILS_ROOT}/config/web.yml"  
16 - File.expects(:exists?).with(file).returns(true)  
17 - YAML.expects(:load_file).with(file).returns('path' => '/mypath', 'port' => 9999)  
18 - assert_equal({'path' => '/mypath', 'port' => 9999}, Noosfero::URL.config)  
19 - end  
20 -  
21 - should 'fallback correcly' do  
22 - file = "#{RAILS_ROOT}/config/web.yml"  
23 - File.expects(:exists?).with(file).returns(false)  
24 - assert_equal({'path' => '', 'port' => 3000}, Noosfero::URL.config)  
25 - end  
26 -  
27 - should 'read the correct path' do  
28 - Noosfero::URL.stubs(:config).returns('path' => '/mypath')  
29 - assert_equal '/mypath', self.path  
30 - end  
31 -  
32 - should 'read the correct port' do  
33 - Noosfero::URL.stubs(:config).returns('port' => 9999)  
34 - assert_equal 9999, self.port  
35 - end  
36 -  
37 - should 'add path when needed' do  
38 - self.stubs(:path).returns('/somepath')  
39 - self.stubs(:port).returns(nil)  
40 - assert_equal('http://example.com/somepath/', generate_url(:host => 'example.com', :controller => 'home'))  
41 - end  
42 -  
43 - should 'not add path when it is not needed' do  
44 - self.stubs(:path).returns(nil)  
45 - self.stubs(:port).returns(nil)  
46 - assert_equal('http://example.com/', generate_url(:host => 'example.com', :controller => 'home'))  
47 - end  
48 -  
49 -end