application_helper_test.rb
5.89 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
require File.dirname(__FILE__) + '/../test_helper'
class ApplicationHelperTest < Test::Unit::TestCase
include ApplicationHelper
should 'calculate correctly partial for object' do
self.stubs(:params).returns({:controller => 'test'})
File.expects(:exists?).with("#{RAILS_ROOT}/app/views/test/_float.rhtml").returns(false)
File.expects(:exists?).with("#{RAILS_ROOT}/app/views/test/_numeric.rhtml").returns(true).times(2)
File.expects(:exists?).with("#{RAILS_ROOT}/app/views/test/_runtime_error.rhtml").returns(true).at_least_once
assert_equal 'numeric', partial_for_class(Float)
assert_equal 'numeric', partial_for_class(Numeric)
assert_equal 'runtime_error', partial_for_class(RuntimeError)
end
should 'give error when there is no partial for class' do
assert_raises ArgumentError do
partial_for_class(nil)
end
end
should 'generate link to stylesheet' do
File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'stylesheets', 'something.css')).returns(true)
expects(:filename_for_stylesheet).with('something', nil).returns('/stylesheets/something.css')
assert_match '@import url(/stylesheets/something.css)', stylesheet_import('something')
end
should 'not generate link to unexisting stylesheet' do
File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', 'stylesheets', 'something.css')).returns(false)
expects(:filename_for_stylesheet).with('something', nil).returns('/stylesheets/something.css')
assert_no_match %r{@import url(/stylesheets/something.css)}, stylesheet_import('something')
end
should 'handle nil dates' do
assert_equal '', show_date(nil)
end
should 'translate time' do
time = mock
expects(:_).with('%d %B %Y, %H:%m').returns('the time')
time.expects(:strftime).with('the time').returns('translated time')
assert_equal 'translated time', show_time(time)
end
should 'handle nil time' do
assert_equal '', show_time(nil)
end
should 'append with-text class and keep existing classes' do
expects(:button_without_text).with('type', 'label', 'url', { :class => 'with-text class1'})
button('type', 'label', 'url', { :class => 'class1' })
end
should 'generate correct link to category' do
cat = mock
cat.expects(:path).returns('my-category/my-subcatagory')
cat.expects(:full_name).returns('category name')
result = "/cat/my-category/my-subcatagory"
expects(:link_to).with('category name', :controller => 'search', :action => 'category_index', :category_path => ['my-category', 'my-subcatagory']).returns(result)
assert_same result, link_to_category(cat)
end
should 'nil theme option when no exists theme' do
stubs(:current_theme).returns('something-very-unlikely')
File.expects(:exists?).returns(false)
assert_nil theme_option()
end
should 'not nil to ecosol theme option' do
expects(:current_theme).returns('ecosol')
assert_not_nil theme_option()
end
should 'not nil to zen3 theme option' do
expects(:current_theme).returns('zen3')
assert_not_nil theme_option()
end
should 'nil javascript theme when no exists theme' do
stubs(:current_theme).returns('something-very-unlikely')
File.expects(:exists?).returns(false)
assert_nil theme_javascript
end
should 'not nil javascript theme to ecosol theme' do
expects(:current_theme).returns('ecosol')
assert_not_nil theme_javascript
end
should 'role color for admin role' do
assert_equal 'blue', role_color(Profile::Roles.admin)
end
should 'role color for member role' do
assert_equal 'green', role_color(Profile::Roles.member)
end
should 'role color for moderator role' do
assert_equal 'gray', role_color(Profile::Roles.moderator)
end
should 'default role color' do
assert_equal 'black', role_color('none')
end
should 'rolename for' do
person = create_user('usertest').person
community = Community.create!(:name => 'new community', :identifier => 'new-community', :environment => Environment.default)
community.add_member(person)
assert_equal 'Profile Member', rolename_for(person, community)
end
should 'display categories' do
# FIXME implement this test!!!
assert true
#category = Category.create!(:name => 'parent category for testing', :environment_id => Environment.default)
#child = Category.create!(:name => 'child category for testing', :environment => Environment.default, :display_in_menu => true, :parent => category)
#owner = create_user('testuser').person
#@article = owner.articles.create!(:name => 'ytest')
#@article.add_category(category)
#expects(:environment).returns(Environment.default)
#result = select_categories(:article)
#assert_match /parent category/, result
end
should 'not display categories if has no child' do
# FIXME implement this test!!!
assert true
#category = Category.create!(:name => 'parent category for testing', :environment_id => Environment.default)
#owner = create_user('testuser').person
#@article = owner.articles.create!(:name => 'ytest')
#@article.add_category(category)
#expects(:environment).returns(Environment.default)
#result = select_categories(:article)
#assert_no_match /parent category/, result
end
should 'get theme from environment by default' do
@environment = mock
@environment.stubs(:theme).returns('my-environment-theme')
stubs(:profile).returns(nil)
assert_equal 'my-environment-theme', current_theme
end
should 'get theme from profile when profile is present' do
profile = mock
profile.stubs(:theme).returns('my-profile-theme')
stubs(:profile).returns(profile)
assert_equal 'my-profile-theme', current_theme
end
protected
def content_tag(tag, content, options = {})
content.strip
end
def javascript_tag(any)
''
end
def link_to(label, action, options = {})
label
end
def check_box_tag(name, value = 1, checked = false, options = {})
name
end
end