From 6548e2f29cce9e671523abcc00422a11789ccd21 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Sat, 4 Apr 2009 11:14:45 -0300 Subject: [PATCH] ActionItem980: removing unused code --- lib/noosfero/url.rb | 62 -------------------------------------------------------------- test/unit/noosfero_url_test.rb | 49 ------------------------------------------------- 2 files changed, 0 insertions(+), 111 deletions(-) delete mode 100644 lib/noosfero/url.rb delete mode 100644 test/unit/noosfero_url_test.rb diff --git a/lib/noosfero/url.rb b/lib/noosfero/url.rb deleted file mode 100644 index 9fe14dd..0000000 --- a/lib/noosfero/url.rb +++ /dev/null @@ -1,62 +0,0 @@ -require 'noosfero' - -# This module defines utility methods for generating URL's in contexts where -# one does not have a request (i.e. ActionMailer classes like TaskMailer). -# -# TODO: document the use of config/web.yml in a INSTALL document -module Noosfero::URL - - include ActionController::UrlWriter - - class << self - - def config - if @config.nil? - config_file = File.join(RAILS_ROOT, 'config', 'web.yml') - if File.exists?(config_file) - @config = YAML::load_file(config_file) - else - if ENV['RAILS_ENV'] == 'production' - @config = { - } - else - @config = { - 'path' => '', - 'port' => 3000 - } - end - end - end - - @config - end - - def included(other_module) - other_module.send(:include, ActionController::UrlWriter) - end - - end - - def port - Noosfero::URL.config['port'] - end - - def path - Noosfero::URL.config['path'] - end - - def generate_url(options) - local_options = {} - local_options[:port] = self.port unless self.port.nil? - - url = url_for(local_options.merge(options)) - - if self.path.blank? - url - else - url.sub(/(http:\/\/[^\/]+(:\d+)?)\//, "\\1#{self.path}/") - end - end - - -end diff --git a/test/unit/noosfero_url_test.rb b/test/unit/noosfero_url_test.rb deleted file mode 100644 index 1574eab..0000000 --- a/test/unit/noosfero_url_test.rb +++ /dev/null @@ -1,49 +0,0 @@ - -require File.dirname(__FILE__) + '/../test_helper' - -require 'noosfero/url' - -class NoosferoURLTest < Test::Unit::TestCase - - include Noosfero::URL - - def setup - Noosfero::URL.instance_variable_set('@config', nil) - end - - should 'read the config file' do - file = "#{RAILS_ROOT}/config/web.yml" - File.expects(:exists?).with(file).returns(true) - YAML.expects(:load_file).with(file).returns('path' => '/mypath', 'port' => 9999) - assert_equal({'path' => '/mypath', 'port' => 9999}, Noosfero::URL.config) - end - - should 'fallback correcly' do - file = "#{RAILS_ROOT}/config/web.yml" - File.expects(:exists?).with(file).returns(false) - assert_equal({'path' => '', 'port' => 3000}, Noosfero::URL.config) - end - - should 'read the correct path' do - Noosfero::URL.stubs(:config).returns('path' => '/mypath') - assert_equal '/mypath', self.path - end - - should 'read the correct port' do - Noosfero::URL.stubs(:config).returns('port' => 9999) - assert_equal 9999, self.port - end - - should 'add path when needed' do - self.stubs(:path).returns('/somepath') - self.stubs(:port).returns(nil) - assert_equal('http://example.com/somepath/', generate_url(:host => 'example.com', :controller => 'home')) - end - - should 'not add path when it is not needed' do - self.stubs(:path).returns(nil) - self.stubs(:port).returns(nil) - assert_equal('http://example.com/', generate_url(:host => 'example.com', :controller => 'home')) - end - -end -- libgit2 0.21.2