noosfero_test.rb
3.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require File.dirname(__FILE__) + '/../test_helper'
require 'noosfero'
class NoosferoTest < ActiveSupport::TestCase
def test_should_list_controllers_in_directory
Dir.expects(:glob).with("#{RAILS_ROOT}/app/controllers/lala/*_controller.rb").returns(["app/controllers/lala/system_admin_controller.rb", "app/controllers/lala/environment_admin_controller.rb", "app/controllers/lala/public_controller.rb", "app/controllers/lala/profile_admin_controller.rb"]).once
assert_equal ["system_admin", "environment_admin", "public", "profile_admin"], Noosfero.controllers_in_directory('lala')
end
def test_should_generate_pattern_for_controllers_in_directory
Dir.expects(:glob).with("#{RAILS_ROOT}/app/controllers/lala/*_controller.rb").returns(["app/controllers/lala/system_admin_controller.rb", "app/controllers/lala/environment_admin_controller.rb", "app/controllers/lala/public_controller.rb", "app/controllers/lala/profile_admin_controller.rb"]).once
assert_equal(/(system_admin|environment_admin|public|profile_admin)/, Noosfero.pattern_for_controllers_in_directory('lala'))
end
def test_should_generate_empty_pattern_for_empty_dir
Dir.stubs(:glob).returns([])
assert_equal(//, Noosfero.pattern_for_controllers_in_directory('lala'))
end
should 'support setting default locale' do
Noosfero.default_locale = 'pt_BR'
assert_equal 'pt_BR', Noosfero.default_locale
end
should 'identifier format' do
assert_match /^#{Noosfero.identifier_format}$/, 'bli-bla'
assert_no_match /^#{Noosfero.identifier_format}$/, 'UPPER'
assert_match /^#{Noosfero.identifier_format}$/, 'with~tilde'
assert_match /^#{Noosfero.identifier_format}$/, 'with.dot'
end
should 'delegate terminology' do
Noosfero.terminology.expects(:get).with('lalala').returns('lelele')
assert_equal 'lelele', Noosfero.term('lalala')
end
should 'use default terminology by default' do
assert_equal 'lalalalala', Noosfero.term('lalalalala')
end
should 'provide url options to identify development environment' do
ENV.expects(:[]).with('RAILS_ENV').returns('development')
Noosfero.expects(:development_url_options).returns({ :port => 9999 })
assert_equal({:port => 9999}, Noosfero.url_options)
end
should 'allow identifier starting with number' do
assert_match /^#{Noosfero.identifier_format}$/, '129812startingwithnumber'
end
should 'change locale temporarily' do
Noosfero.with_locale('pt') do
assert_equal 'pt', FastGettext.locale
end
assert_equal 'en', FastGettext.locale
end
should 'use terminology with ngettext' do
Noosfero.stubs(:terminology).returns(UnifreireTerminology.instance)
Noosfero.with_locale('en') do
assert_equal 'One institution', n__('One enterprise', '%{num} enterprises', 1)
end
Noosfero.with_locale('pt') do
stubs(:ngettext).with('One institution', '%{num} institutions', 1).returns('Uma instituição')
assert_equal 'Uma instituição', n__('One enterprise', '%{num} enterprises', 1)
end
end
should "use default hostname of default environment as hostname of Noosfero instance" do
Environment.default.domains << Domain.new(:name => 'thisisdefaulthostname.com', :is_default => true)
assert_equal 'thisisdefaulthostname.com', Noosfero.default_hostname
end
should "use 'localhost' as default hostname of Noosfero instance when has no environments in database" do
Environment.stubs(:default).returns(nil)
assert_equal 'localhost', Noosfero.default_hostname
end
should "use 'localhost' as default hostname of Noosfero instance when environments table doesn't exists" do
Environment.stubs(:table_exists?).returns(false)
assert_equal 'localhost', Noosfero.default_hostname
end
should 'be able to override locales' do
original_locales = Noosfero.locales
english_only = { 'en' => 'English' }
Noosfero.locales = english_only
assert_equal english_only, Noosfero.locales
# cleanup
Noosfero.locales = original_locales
end
end