noosfero_url_test.rb
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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