##// END OF EJS Templates
Changed assertions to make them work with Rails2/3 ruby1.8/1.9 different behaviours....
Jean-Philippe Lang -
r8988:aa9238912b97
parent child
Show More
@@ -1,120 +1,120
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class AuthSourceLdapTest < ActiveSupport::TestCase
20 class AuthSourceLdapTest < ActiveSupport::TestCase
21 include Redmine::I18n
21 include Redmine::I18n
22 fixtures :auth_sources
22 fixtures :auth_sources
23
23
24 def setup
24 def setup
25 end
25 end
26
26
27 def test_create
27 def test_create
28 a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName')
28 a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName')
29 assert a.save
29 assert a.save
30 end
30 end
31
31
32 def test_should_strip_ldap_attributes
32 def test_should_strip_ldap_attributes
33 a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName',
33 a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName',
34 :attr_firstname => 'givenName ')
34 :attr_firstname => 'givenName ')
35 assert a.save
35 assert a.save
36 assert_equal 'givenName', a.reload.attr_firstname
36 assert_equal 'givenName', a.reload.attr_firstname
37 end
37 end
38
38
39 def test_replace_port_zero_to_389
39 def test_replace_port_zero_to_389
40 a = AuthSourceLdap.new(
40 a = AuthSourceLdap.new(
41 :name => 'My LDAP', :host => 'ldap.example.net', :port => 0,
41 :name => 'My LDAP', :host => 'ldap.example.net', :port => 0,
42 :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName',
42 :base_dn => 'dc=example,dc=net', :attr_login => 'sAMAccountName',
43 :attr_firstname => 'givenName ')
43 :attr_firstname => 'givenName ')
44 assert a.save
44 assert a.save
45 assert_equal 389, a.port
45 assert_equal 389, a.port
46 end
46 end
47
47
48 def test_filter_should_be_validated
48 def test_filter_should_be_validated
49 set_language_if_valid 'en'
49 set_language_if_valid 'en'
50
50
51 a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :attr_login => 'sn')
51 a = AuthSourceLdap.new(:name => 'My LDAP', :host => 'ldap.example.net', :port => 389, :attr_login => 'sn')
52 a.filter = "(mail=*@redmine.org"
52 a.filter = "(mail=*@redmine.org"
53 assert !a.valid?
53 assert !a.valid?
54 assert_equal "is invalid", a.errors[:filter].to_s
54 assert_include "is invalid", a.errors[:filter]
55
55
56 a.filter = "(mail=*@redmine.org)"
56 a.filter = "(mail=*@redmine.org)"
57 assert a.valid?
57 assert a.valid?
58 end
58 end
59
59
60 if ldap_configured?
60 if ldap_configured?
61 context '#authenticate' do
61 context '#authenticate' do
62 setup do
62 setup do
63 @auth = AuthSourceLdap.find(1)
63 @auth = AuthSourceLdap.find(1)
64 @auth.update_attribute :onthefly_register, true
64 @auth.update_attribute :onthefly_register, true
65 end
65 end
66
66
67 context 'with a valid LDAP user' do
67 context 'with a valid LDAP user' do
68 should 'return the user attributes' do
68 should 'return the user attributes' do
69 attributes = @auth.authenticate('example1','123456')
69 attributes = @auth.authenticate('example1','123456')
70 assert attributes.is_a?(Hash), "An hash was not returned"
70 assert attributes.is_a?(Hash), "An hash was not returned"
71 assert_equal 'Example', attributes[:firstname]
71 assert_equal 'Example', attributes[:firstname]
72 assert_equal 'One', attributes[:lastname]
72 assert_equal 'One', attributes[:lastname]
73 assert_equal 'example1@redmine.org', attributes[:mail]
73 assert_equal 'example1@redmine.org', attributes[:mail]
74 assert_equal @auth.id, attributes[:auth_source_id]
74 assert_equal @auth.id, attributes[:auth_source_id]
75 attributes.keys.each do |attribute|
75 attributes.keys.each do |attribute|
76 assert User.new.respond_to?("#{attribute}="), "Unexpected :#{attribute} attribute returned"
76 assert User.new.respond_to?("#{attribute}="), "Unexpected :#{attribute} attribute returned"
77 end
77 end
78 end
78 end
79 end
79 end
80
80
81 context 'with an invalid LDAP user' do
81 context 'with an invalid LDAP user' do
82 should 'return nil' do
82 should 'return nil' do
83 assert_equal nil, @auth.authenticate('nouser','123456')
83 assert_equal nil, @auth.authenticate('nouser','123456')
84 end
84 end
85 end
85 end
86
86
87 context 'without a login' do
87 context 'without a login' do
88 should 'return nil' do
88 should 'return nil' do
89 assert_equal nil, @auth.authenticate('','123456')
89 assert_equal nil, @auth.authenticate('','123456')
90 end
90 end
91 end
91 end
92
92
93 context 'without a password' do
93 context 'without a password' do
94 should 'return nil' do
94 should 'return nil' do
95 assert_equal nil, @auth.authenticate('edavis','')
95 assert_equal nil, @auth.authenticate('edavis','')
96 end
96 end
97 end
97 end
98
98
99 context 'without filter' do
99 context 'without filter' do
100 should 'return any user' do
100 should 'return any user' do
101 assert @auth.authenticate('example1','123456')
101 assert @auth.authenticate('example1','123456')
102 assert @auth.authenticate('edavis', '123456')
102 assert @auth.authenticate('edavis', '123456')
103 end
103 end
104 end
104 end
105
105
106 context 'with filter' do
106 context 'with filter' do
107 setup do
107 setup do
108 @auth.filter = "(mail=*@redmine.org)"
108 @auth.filter = "(mail=*@redmine.org)"
109 end
109 end
110
110
111 should 'return user who matches the filter only' do
111 should 'return user who matches the filter only' do
112 assert @auth.authenticate('example1','123456')
112 assert @auth.authenticate('example1','123456')
113 assert_nil @auth.authenticate('edavis', '123456')
113 assert_nil @auth.authenticate('edavis', '123456')
114 end
114 end
115 end
115 end
116 end
116 end
117 else
117 else
118 puts '(Test LDAP server not configured)'
118 puts '(Test LDAP server not configured)'
119 end
119 end
120 end
120 end
@@ -1,194 +1,194
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class CustomFieldTest < ActiveSupport::TestCase
20 class CustomFieldTest < ActiveSupport::TestCase
21 fixtures :custom_fields
21 fixtures :custom_fields
22
22
23 def test_create
23 def test_create
24 field = UserCustomField.new(:name => 'Money money money', :field_format => 'float')
24 field = UserCustomField.new(:name => 'Money money money', :field_format => 'float')
25 assert field.save
25 assert field.save
26 end
26 end
27
27
28 def test_before_validation
28 def test_before_validation
29 field = CustomField.new(:name => 'test_before_validation', :field_format => 'int')
29 field = CustomField.new(:name => 'test_before_validation', :field_format => 'int')
30 field.searchable = true
30 field.searchable = true
31 assert field.save
31 assert field.save
32 assert_equal false, field.searchable
32 assert_equal false, field.searchable
33 field.searchable = true
33 field.searchable = true
34 assert field.save
34 assert field.save
35 assert_equal false, field.searchable
35 assert_equal false, field.searchable
36 end
36 end
37
37
38 def test_regexp_validation
38 def test_regexp_validation
39 field = IssueCustomField.new(:name => 'regexp', :field_format => 'text', :regexp => '[a-z0-9')
39 field = IssueCustomField.new(:name => 'regexp', :field_format => 'text', :regexp => '[a-z0-9')
40 assert !field.save
40 assert !field.save
41 assert_equal I18n.t('activerecord.errors.messages.invalid'),
41 assert_include I18n.t('activerecord.errors.messages.invalid'),
42 field.errors[:regexp].to_s
42 field.errors[:regexp]
43 field.regexp = '[a-z0-9]'
43 field.regexp = '[a-z0-9]'
44 assert field.save
44 assert field.save
45 end
45 end
46
46
47 def test_default_value_should_be_validated
47 def test_default_value_should_be_validated
48 field = CustomField.new(:name => 'Test', :field_format => 'int')
48 field = CustomField.new(:name => 'Test', :field_format => 'int')
49 field.default_value = 'abc'
49 field.default_value = 'abc'
50 assert !field.valid?
50 assert !field.valid?
51 field.default_value = '6'
51 field.default_value = '6'
52 assert field.valid?
52 assert field.valid?
53 end
53 end
54
54
55 def test_default_value_should_not_be_validated_when_blank
55 def test_default_value_should_not_be_validated_when_blank
56 field = CustomField.new(:name => 'Test', :field_format => 'list', :possible_values => ['a', 'b'], :is_required => true, :default_value => '')
56 field = CustomField.new(:name => 'Test', :field_format => 'list', :possible_values => ['a', 'b'], :is_required => true, :default_value => '')
57 assert field.valid?
57 assert field.valid?
58 end
58 end
59
59
60 def test_possible_values_should_accept_an_array
60 def test_possible_values_should_accept_an_array
61 field = CustomField.new
61 field = CustomField.new
62 field.possible_values = ["One value", ""]
62 field.possible_values = ["One value", ""]
63 assert_equal ["One value"], field.possible_values
63 assert_equal ["One value"], field.possible_values
64 end
64 end
65
65
66 def test_possible_values_should_accept_a_string
66 def test_possible_values_should_accept_a_string
67 field = CustomField.new
67 field = CustomField.new
68 field.possible_values = "One value"
68 field.possible_values = "One value"
69 assert_equal ["One value"], field.possible_values
69 assert_equal ["One value"], field.possible_values
70 end
70 end
71
71
72 def test_possible_values_should_accept_a_multiline_string
72 def test_possible_values_should_accept_a_multiline_string
73 field = CustomField.new
73 field = CustomField.new
74 field.possible_values = "One value\nAnd another one \r\n \n"
74 field.possible_values = "One value\nAnd another one \r\n \n"
75 assert_equal ["One value", "And another one"], field.possible_values
75 assert_equal ["One value", "And another one"], field.possible_values
76 end
76 end
77
77
78 def test_destroy
78 def test_destroy
79 field = CustomField.find(1)
79 field = CustomField.find(1)
80 assert field.destroy
80 assert field.destroy
81 end
81 end
82
82
83 def test_new_subclass_instance_should_return_an_instance
83 def test_new_subclass_instance_should_return_an_instance
84 f = CustomField.new_subclass_instance('IssueCustomField')
84 f = CustomField.new_subclass_instance('IssueCustomField')
85 assert_kind_of IssueCustomField, f
85 assert_kind_of IssueCustomField, f
86 end
86 end
87
87
88 def test_new_subclass_instance_should_set_attributes
88 def test_new_subclass_instance_should_set_attributes
89 f = CustomField.new_subclass_instance('IssueCustomField', :name => 'Test')
89 f = CustomField.new_subclass_instance('IssueCustomField', :name => 'Test')
90 assert_kind_of IssueCustomField, f
90 assert_kind_of IssueCustomField, f
91 assert_equal 'Test', f.name
91 assert_equal 'Test', f.name
92 end
92 end
93
93
94 def test_new_subclass_instance_with_invalid_class_name_should_return_nil
94 def test_new_subclass_instance_with_invalid_class_name_should_return_nil
95 assert_nil CustomField.new_subclass_instance('WrongClassName')
95 assert_nil CustomField.new_subclass_instance('WrongClassName')
96 end
96 end
97
97
98 def test_new_subclass_instance_with_non_subclass_name_should_return_nil
98 def test_new_subclass_instance_with_non_subclass_name_should_return_nil
99 assert_nil CustomField.new_subclass_instance('Project')
99 assert_nil CustomField.new_subclass_instance('Project')
100 end
100 end
101
101
102 def test_string_field_validation_with_blank_value
102 def test_string_field_validation_with_blank_value
103 f = CustomField.new(:field_format => 'string')
103 f = CustomField.new(:field_format => 'string')
104
104
105 assert f.valid_field_value?(nil)
105 assert f.valid_field_value?(nil)
106 assert f.valid_field_value?('')
106 assert f.valid_field_value?('')
107
107
108 f.is_required = true
108 f.is_required = true
109 assert !f.valid_field_value?(nil)
109 assert !f.valid_field_value?(nil)
110 assert !f.valid_field_value?('')
110 assert !f.valid_field_value?('')
111 end
111 end
112
112
113 def test_string_field_validation_with_min_and_max_lengths
113 def test_string_field_validation_with_min_and_max_lengths
114 f = CustomField.new(:field_format => 'string', :min_length => 2, :max_length => 5)
114 f = CustomField.new(:field_format => 'string', :min_length => 2, :max_length => 5)
115
115
116 assert f.valid_field_value?(nil)
116 assert f.valid_field_value?(nil)
117 assert f.valid_field_value?('')
117 assert f.valid_field_value?('')
118 assert f.valid_field_value?('a' * 2)
118 assert f.valid_field_value?('a' * 2)
119 assert !f.valid_field_value?('a')
119 assert !f.valid_field_value?('a')
120 assert !f.valid_field_value?('a' * 6)
120 assert !f.valid_field_value?('a' * 6)
121 end
121 end
122
122
123 def test_string_field_validation_with_regexp
123 def test_string_field_validation_with_regexp
124 f = CustomField.new(:field_format => 'string', :regexp => '^[A-Z0-9]*$')
124 f = CustomField.new(:field_format => 'string', :regexp => '^[A-Z0-9]*$')
125
125
126 assert f.valid_field_value?(nil)
126 assert f.valid_field_value?(nil)
127 assert f.valid_field_value?('')
127 assert f.valid_field_value?('')
128 assert f.valid_field_value?('ABC')
128 assert f.valid_field_value?('ABC')
129 assert !f.valid_field_value?('abc')
129 assert !f.valid_field_value?('abc')
130 end
130 end
131
131
132 def test_date_field_validation
132 def test_date_field_validation
133 f = CustomField.new(:field_format => 'date')
133 f = CustomField.new(:field_format => 'date')
134
134
135 assert f.valid_field_value?(nil)
135 assert f.valid_field_value?(nil)
136 assert f.valid_field_value?('')
136 assert f.valid_field_value?('')
137 assert f.valid_field_value?('1975-07-14')
137 assert f.valid_field_value?('1975-07-14')
138 assert !f.valid_field_value?('1975-07-33')
138 assert !f.valid_field_value?('1975-07-33')
139 assert !f.valid_field_value?('abc')
139 assert !f.valid_field_value?('abc')
140 end
140 end
141
141
142 def test_list_field_validation
142 def test_list_field_validation
143 f = CustomField.new(:field_format => 'list', :possible_values => ['value1', 'value2'])
143 f = CustomField.new(:field_format => 'list', :possible_values => ['value1', 'value2'])
144
144
145 assert f.valid_field_value?(nil)
145 assert f.valid_field_value?(nil)
146 assert f.valid_field_value?('')
146 assert f.valid_field_value?('')
147 assert f.valid_field_value?('value2')
147 assert f.valid_field_value?('value2')
148 assert !f.valid_field_value?('abc')
148 assert !f.valid_field_value?('abc')
149 end
149 end
150
150
151 def test_int_field_validation
151 def test_int_field_validation
152 f = CustomField.new(:field_format => 'int')
152 f = CustomField.new(:field_format => 'int')
153
153
154 assert f.valid_field_value?(nil)
154 assert f.valid_field_value?(nil)
155 assert f.valid_field_value?('')
155 assert f.valid_field_value?('')
156 assert f.valid_field_value?('123')
156 assert f.valid_field_value?('123')
157 assert f.valid_field_value?('+123')
157 assert f.valid_field_value?('+123')
158 assert f.valid_field_value?('-123')
158 assert f.valid_field_value?('-123')
159 assert !f.valid_field_value?('6abc')
159 assert !f.valid_field_value?('6abc')
160 end
160 end
161
161
162 def test_float_field_validation
162 def test_float_field_validation
163 f = CustomField.new(:field_format => 'float')
163 f = CustomField.new(:field_format => 'float')
164
164
165 assert f.valid_field_value?(nil)
165 assert f.valid_field_value?(nil)
166 assert f.valid_field_value?('')
166 assert f.valid_field_value?('')
167 assert f.valid_field_value?('11.2')
167 assert f.valid_field_value?('11.2')
168 assert f.valid_field_value?('-6.250')
168 assert f.valid_field_value?('-6.250')
169 assert f.valid_field_value?('5')
169 assert f.valid_field_value?('5')
170 assert !f.valid_field_value?('6abc')
170 assert !f.valid_field_value?('6abc')
171 end
171 end
172
172
173 def test_multi_field_validation
173 def test_multi_field_validation
174 f = CustomField.new(:field_format => 'list', :multiple => 'true', :possible_values => ['value1', 'value2'])
174 f = CustomField.new(:field_format => 'list', :multiple => 'true', :possible_values => ['value1', 'value2'])
175
175
176 assert f.valid_field_value?(nil)
176 assert f.valid_field_value?(nil)
177 assert f.valid_field_value?('')
177 assert f.valid_field_value?('')
178 assert f.valid_field_value?([])
178 assert f.valid_field_value?([])
179 assert f.valid_field_value?([nil])
179 assert f.valid_field_value?([nil])
180 assert f.valid_field_value?([''])
180 assert f.valid_field_value?([''])
181
181
182 assert f.valid_field_value?('value2')
182 assert f.valid_field_value?('value2')
183 assert !f.valid_field_value?('abc')
183 assert !f.valid_field_value?('abc')
184
184
185 assert f.valid_field_value?(['value2'])
185 assert f.valid_field_value?(['value2'])
186 assert !f.valid_field_value?(['abc'])
186 assert !f.valid_field_value?(['abc'])
187
187
188 assert f.valid_field_value?(['', 'value2'])
188 assert f.valid_field_value?(['', 'value2'])
189 assert !f.valid_field_value?(['', 'abc'])
189 assert !f.valid_field_value?(['', 'abc'])
190
190
191 assert f.valid_field_value?(['value1', 'value2'])
191 assert f.valid_field_value?(['value1', 'value2'])
192 assert !f.valid_field_value?(['value1', 'abc'])
192 assert !f.valid_field_value?(['value1', 'abc'])
193 end
193 end
194 end
194 end
@@ -1,191 +1,191
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class MemberTest < ActiveSupport::TestCase
20 class MemberTest < ActiveSupport::TestCase
21 fixtures :projects, :trackers, :issue_statuses, :issues,
21 fixtures :projects, :trackers, :issue_statuses, :issues,
22 :enumerations, :users, :issue_categories,
22 :enumerations, :users, :issue_categories,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :enabled_modules,
27 :enabled_modules,
28 :workflows,
28 :workflows,
29 :groups_users,
29 :groups_users,
30 :watchers,
30 :watchers,
31 :journals, :journal_details,
31 :journals, :journal_details,
32 :messages,
32 :messages,
33 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
33 :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions,
34 :boards
34 :boards
35
35
36 include Redmine::I18n
36 include Redmine::I18n
37
37
38 def setup
38 def setup
39 @jsmith = Member.find(1)
39 @jsmith = Member.find(1)
40 end
40 end
41
41
42 def test_create
42 def test_create
43 member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
43 member = Member.new(:project_id => 1, :user_id => 4, :role_ids => [1, 2])
44 assert member.save
44 assert member.save
45 member.reload
45 member.reload
46
46
47 assert_equal 2, member.roles.size
47 assert_equal 2, member.roles.size
48 assert_equal Role.find(1), member.roles.sort.first
48 assert_equal Role.find(1), member.roles.sort.first
49 end
49 end
50
50
51 def test_update
51 def test_update
52 assert_equal "eCookbook", @jsmith.project.name
52 assert_equal "eCookbook", @jsmith.project.name
53 assert_equal "Manager", @jsmith.roles.first.name
53 assert_equal "Manager", @jsmith.roles.first.name
54 assert_equal "jsmith", @jsmith.user.login
54 assert_equal "jsmith", @jsmith.user.login
55
55
56 @jsmith.mail_notification = !@jsmith.mail_notification
56 @jsmith.mail_notification = !@jsmith.mail_notification
57 assert @jsmith.save
57 assert @jsmith.save
58 end
58 end
59
59
60 def test_update_roles
60 def test_update_roles
61 assert_equal 1, @jsmith.roles.size
61 assert_equal 1, @jsmith.roles.size
62 @jsmith.role_ids = [1, 2]
62 @jsmith.role_ids = [1, 2]
63 assert @jsmith.save
63 assert @jsmith.save
64 assert_equal 2, @jsmith.reload.roles.size
64 assert_equal 2, @jsmith.reload.roles.size
65 end
65 end
66
66
67 def test_validate
67 def test_validate
68 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
68 member = Member.new(:project_id => 1, :user_id => 2, :role_ids => [2])
69 # same use can't have more than one membership for a project
69 # same use can't have more than one membership for a project
70 assert !member.save
70 assert !member.save
71
71
72 # must have one role at least
72 # must have one role at least
73 user = User.new(:firstname => "new1", :lastname => "user1", :mail => "test_validate@somenet.foo")
73 user = User.new(:firstname => "new1", :lastname => "user1", :mail => "test_validate@somenet.foo")
74 user.login = "test_validate"
74 user.login = "test_validate"
75 user.password, user.password_confirmation = "password", "password"
75 user.password, user.password_confirmation = "password", "password"
76 assert user.save
76 assert user.save
77
77
78 set_language_if_valid 'fr'
78 set_language_if_valid 'fr'
79 member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
79 member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [])
80 assert !member.save
80 assert !member.save
81 assert_equal I18n.translate('activerecord.errors.messages.empty'), member.errors[:role].to_s
81 assert_include I18n.translate('activerecord.errors.messages.empty'), member.errors[:role]
82 str = "R\xc3\xb4le doit \xc3\xaatre renseign\xc3\xa9(e)"
82 str = "R\xc3\xb4le doit \xc3\xaatre renseign\xc3\xa9(e)"
83 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
83 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
84 assert_equal str, [member.errors.full_messages].flatten.join
84 assert_equal str, [member.errors.full_messages].flatten.join
85 end
85 end
86
86
87 def test_validate_member_role
87 def test_validate_member_role
88 user = User.new(:firstname => "new1", :lastname => "user1", :mail => "test_validate@somenet.foo")
88 user = User.new(:firstname => "new1", :lastname => "user1", :mail => "test_validate@somenet.foo")
89 user.login = "test_validate_member_role"
89 user.login = "test_validate_member_role"
90 user.password, user.password_confirmation = "password", "password"
90 user.password, user.password_confirmation = "password", "password"
91 assert user.save
91 assert user.save
92 member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [5])
92 member = Member.new(:project_id => 1, :user_id => user.id, :role_ids => [5])
93 assert !member.save
93 assert !member.save
94 end
94 end
95
95
96 def test_destroy
96 def test_destroy
97 category1 = IssueCategory.find(1)
97 category1 = IssueCategory.find(1)
98 assert_equal @jsmith.user.id, category1.assigned_to_id
98 assert_equal @jsmith.user.id, category1.assigned_to_id
99 assert_difference 'Member.count', -1 do
99 assert_difference 'Member.count', -1 do
100 assert_difference 'MemberRole.count', -1 do
100 assert_difference 'MemberRole.count', -1 do
101 @jsmith.destroy
101 @jsmith.destroy
102 end
102 end
103 end
103 end
104 assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) }
104 assert_raise(ActiveRecord::RecordNotFound) { Member.find(@jsmith.id) }
105 category1.reload
105 category1.reload
106 assert_nil category1.assigned_to_id
106 assert_nil category1.assigned_to_id
107 end
107 end
108
108
109 def test_sort_without_roles
109 def test_sort_without_roles
110 a = Member.new(:roles => [Role.first])
110 a = Member.new(:roles => [Role.first])
111 b = Member.new
111 b = Member.new
112
112
113 assert_equal -1, a <=> b
113 assert_equal -1, a <=> b
114 assert_equal 1, b <=> a
114 assert_equal 1, b <=> a
115 end
115 end
116
116
117 def test_sort_without_principal
117 def test_sort_without_principal
118 role = Role.first
118 role = Role.first
119 a = Member.new(:roles => [role], :principal => User.first)
119 a = Member.new(:roles => [role], :principal => User.first)
120 b = Member.new(:roles => [role])
120 b = Member.new(:roles => [role])
121
121
122 assert_equal -1, a <=> b
122 assert_equal -1, a <=> b
123 assert_equal 1, b <=> a
123 assert_equal 1, b <=> a
124 end
124 end
125
125
126 context "removing permissions" do
126 context "removing permissions" do
127 setup do
127 setup do
128 Watcher.delete_all("user_id = 9")
128 Watcher.delete_all("user_id = 9")
129 user = User.find(9)
129 user = User.find(9)
130 # public
130 # public
131 Watcher.create!(:watchable => Issue.find(1), :user => user)
131 Watcher.create!(:watchable => Issue.find(1), :user => user)
132 # private
132 # private
133 Watcher.create!(:watchable => Issue.find(4), :user => user)
133 Watcher.create!(:watchable => Issue.find(4), :user => user)
134 Watcher.create!(:watchable => Message.find(7), :user => user)
134 Watcher.create!(:watchable => Message.find(7), :user => user)
135 Watcher.create!(:watchable => Wiki.find(2), :user => user)
135 Watcher.create!(:watchable => Wiki.find(2), :user => user)
136 Watcher.create!(:watchable => WikiPage.find(3), :user => user)
136 Watcher.create!(:watchable => WikiPage.find(3), :user => user)
137 end
137 end
138
138
139 context "of user" do
139 context "of user" do
140 setup do
140 setup do
141 @member = Member.create!(:project => Project.find(2), :principal => User.find(9), :role_ids => [1, 2])
141 @member = Member.create!(:project => Project.find(2), :principal => User.find(9), :role_ids => [1, 2])
142 end
142 end
143
143
144 context "by deleting membership" do
144 context "by deleting membership" do
145 should "prune watchers" do
145 should "prune watchers" do
146 assert_difference 'Watcher.count', -4 do
146 assert_difference 'Watcher.count', -4 do
147 @member.destroy
147 @member.destroy
148 end
148 end
149 end
149 end
150 end
150 end
151
151
152 context "by updating roles" do
152 context "by updating roles" do
153 should "prune watchers" do
153 should "prune watchers" do
154 Role.find(2).remove_permission! :view_wiki_pages
154 Role.find(2).remove_permission! :view_wiki_pages
155 member = Member.first(:order => 'id desc')
155 member = Member.first(:order => 'id desc')
156 assert_difference 'Watcher.count', -2 do
156 assert_difference 'Watcher.count', -2 do
157 member.role_ids = [2]
157 member.role_ids = [2]
158 member.save
158 member.save
159 end
159 end
160 assert !Message.find(7).watched_by?(@user)
160 assert !Message.find(7).watched_by?(@user)
161 end
161 end
162 end
162 end
163 end
163 end
164
164
165 context "of group" do
165 context "of group" do
166 setup do
166 setup do
167 group = Group.find(10)
167 group = Group.find(10)
168 @member = Member.create!(:project => Project.find(2), :principal => group, :role_ids => [1, 2])
168 @member = Member.create!(:project => Project.find(2), :principal => group, :role_ids => [1, 2])
169 group.users << User.find(9)
169 group.users << User.find(9)
170 end
170 end
171
171
172 context "by deleting membership" do
172 context "by deleting membership" do
173 should "prune watchers" do
173 should "prune watchers" do
174 assert_difference 'Watcher.count', -4 do
174 assert_difference 'Watcher.count', -4 do
175 @member.destroy
175 @member.destroy
176 end
176 end
177 end
177 end
178 end
178 end
179
179
180 context "by updating roles" do
180 context "by updating roles" do
181 should "prune watchers" do
181 should "prune watchers" do
182 Role.find(2).remove_permission! :view_wiki_pages
182 Role.find(2).remove_permission! :view_wiki_pages
183 assert_difference 'Watcher.count', -2 do
183 assert_difference 'Watcher.count', -2 do
184 @member.role_ids = [2]
184 @member.role_ids = [2]
185 @member.save
185 @member.save
186 end
186 end
187 end
187 end
188 end
188 end
189 end
189 end
190 end
190 end
191 end
191 end
@@ -1,321 +1,321
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class RepositoryTest < ActiveSupport::TestCase
20 class RepositoryTest < ActiveSupport::TestCase
21 fixtures :projects,
21 fixtures :projects,
22 :trackers,
22 :trackers,
23 :projects_trackers,
23 :projects_trackers,
24 :enabled_modules,
24 :enabled_modules,
25 :repositories,
25 :repositories,
26 :issues,
26 :issues,
27 :issue_statuses,
27 :issue_statuses,
28 :issue_categories,
28 :issue_categories,
29 :changesets,
29 :changesets,
30 :changes,
30 :changes,
31 :users,
31 :users,
32 :members,
32 :members,
33 :member_roles,
33 :member_roles,
34 :roles,
34 :roles,
35 :enumerations
35 :enumerations
36
36
37 include Redmine::I18n
37 include Redmine::I18n
38
38
39 def setup
39 def setup
40 @repository = Project.find(1).repository
40 @repository = Project.find(1).repository
41 end
41 end
42
42
43 def test_blank_log_encoding_error_message
43 def test_blank_log_encoding_error_message
44 set_language_if_valid 'en'
44 set_language_if_valid 'en'
45 repo = Repository::Bazaar.new(
45 repo = Repository::Bazaar.new(
46 :project => Project.find(3),
46 :project => Project.find(3),
47 :url => "/test",
47 :url => "/test",
48 :log_encoding => ''
48 :log_encoding => ''
49 )
49 )
50 assert !repo.save
50 assert !repo.save
51 assert_include "Commit messages encoding can't be blank",
51 assert_include "Commit messages encoding can't be blank",
52 repo.errors.full_messages
52 repo.errors.full_messages
53 end
53 end
54
54
55 def test_blank_log_encoding_error_message_fr
55 def test_blank_log_encoding_error_message_fr
56 set_language_if_valid 'fr'
56 set_language_if_valid 'fr'
57 str = "Encodage des messages de commit doit \xc3\xaatre renseign\xc3\xa9(e)"
57 str = "Encodage des messages de commit doit \xc3\xaatre renseign\xc3\xa9(e)"
58 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
58 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
59 repo = Repository::Bazaar.new(
59 repo = Repository::Bazaar.new(
60 :project => Project.find(3),
60 :project => Project.find(3),
61 :url => "/test"
61 :url => "/test"
62 )
62 )
63 assert !repo.save
63 assert !repo.save
64 assert_include str, repo.errors.full_messages
64 assert_include str, repo.errors.full_messages
65 end
65 end
66
66
67 def test_create
67 def test_create
68 repository = Repository::Subversion.new(:project => Project.find(3))
68 repository = Repository::Subversion.new(:project => Project.find(3))
69 assert !repository.save
69 assert !repository.save
70
70
71 repository.url = "svn://localhost"
71 repository.url = "svn://localhost"
72 assert repository.save
72 assert repository.save
73 repository.reload
73 repository.reload
74
74
75 project = Project.find(3)
75 project = Project.find(3)
76 assert_equal repository, project.repository
76 assert_equal repository, project.repository
77 end
77 end
78
78
79 def test_first_repository_should_be_set_as_default
79 def test_first_repository_should_be_set_as_default
80 repository1 = Repository::Subversion.new(
80 repository1 = Repository::Subversion.new(
81 :project => Project.find(3),
81 :project => Project.find(3),
82 :identifier => 'svn1',
82 :identifier => 'svn1',
83 :url => 'file:///svn1'
83 :url => 'file:///svn1'
84 )
84 )
85 assert repository1.save
85 assert repository1.save
86 assert repository1.is_default?
86 assert repository1.is_default?
87
87
88 repository2 = Repository::Subversion.new(
88 repository2 = Repository::Subversion.new(
89 :project => Project.find(3),
89 :project => Project.find(3),
90 :identifier => 'svn2',
90 :identifier => 'svn2',
91 :url => 'file:///svn2'
91 :url => 'file:///svn2'
92 )
92 )
93 assert repository2.save
93 assert repository2.save
94 assert !repository2.is_default?
94 assert !repository2.is_default?
95
95
96 assert_equal repository1, Project.find(3).repository
96 assert_equal repository1, Project.find(3).repository
97 assert_equal [repository1, repository2], Project.find(3).repositories.sort
97 assert_equal [repository1, repository2], Project.find(3).repositories.sort
98 end
98 end
99
99
100 def test_destroy
100 def test_destroy
101 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
101 changesets = Changeset.count(:all, :conditions => "repository_id = 10")
102 changes = Change.count(:all, :conditions => "repository_id = 10",
102 changes = Change.count(:all, :conditions => "repository_id = 10",
103 :joins => :changeset)
103 :joins => :changeset)
104 assert_difference 'Changeset.count', -changesets do
104 assert_difference 'Changeset.count', -changesets do
105 assert_difference 'Change.count', -changes do
105 assert_difference 'Change.count', -changes do
106 Repository.find(10).destroy
106 Repository.find(10).destroy
107 end
107 end
108 end
108 end
109 end
109 end
110
110
111 def test_destroy_should_delete_parents_associations
111 def test_destroy_should_delete_parents_associations
112 changeset = Changeset.find(102)
112 changeset = Changeset.find(102)
113 changeset.parents = Changeset.find_all_by_id([100, 101])
113 changeset.parents = Changeset.find_all_by_id([100, 101])
114
114
115 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do
115 assert_difference 'Changeset.connection.select_all("select * from changeset_parents").size', -2 do
116 Repository.find(10).destroy
116 Repository.find(10).destroy
117 end
117 end
118 end
118 end
119
119
120 def test_destroy_should_delete_issues_associations
120 def test_destroy_should_delete_issues_associations
121 changeset = Changeset.find(102)
121 changeset = Changeset.find(102)
122 changeset.issues = Issue.find_all_by_id([1, 2])
122 changeset.issues = Issue.find_all_by_id([1, 2])
123
123
124 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").size', -2 do
124 assert_difference 'Changeset.connection.select_all("select * from changesets_issues").size', -2 do
125 Repository.find(10).destroy
125 Repository.find(10).destroy
126 end
126 end
127 end
127 end
128
128
129 def test_should_not_create_with_disabled_scm
129 def test_should_not_create_with_disabled_scm
130 # disable Subversion
130 # disable Subversion
131 with_settings :enabled_scm => ['Darcs', 'Git'] do
131 with_settings :enabled_scm => ['Darcs', 'Git'] do
132 repository = Repository::Subversion.new(
132 repository = Repository::Subversion.new(
133 :project => Project.find(3), :url => "svn://localhost")
133 :project => Project.find(3), :url => "svn://localhost")
134 assert !repository.save
134 assert !repository.save
135 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
135 assert_include I18n.translate('activerecord.errors.messages.invalid'),
136 repository.errors[:type].to_s
136 repository.errors[:type]
137 end
137 end
138 end
138 end
139
139
140 def test_scan_changesets_for_issue_ids
140 def test_scan_changesets_for_issue_ids
141 Setting.default_language = 'en'
141 Setting.default_language = 'en'
142 Setting.notified_events = ['issue_added','issue_updated']
142 Setting.notified_events = ['issue_added','issue_updated']
143
143
144 # choosing a status to apply to fix issues
144 # choosing a status to apply to fix issues
145 Setting.commit_fix_status_id = IssueStatus.find(
145 Setting.commit_fix_status_id = IssueStatus.find(
146 :first,
146 :first,
147 :conditions => ["is_closed = ?", true]).id
147 :conditions => ["is_closed = ?", true]).id
148 Setting.commit_fix_done_ratio = "90"
148 Setting.commit_fix_done_ratio = "90"
149 Setting.commit_ref_keywords = 'refs , references, IssueID'
149 Setting.commit_ref_keywords = 'refs , references, IssueID'
150 Setting.commit_fix_keywords = 'fixes , closes'
150 Setting.commit_fix_keywords = 'fixes , closes'
151 Setting.default_language = 'en'
151 Setting.default_language = 'en'
152 ActionMailer::Base.deliveries.clear
152 ActionMailer::Base.deliveries.clear
153
153
154 # make sure issue 1 is not already closed
154 # make sure issue 1 is not already closed
155 fixed_issue = Issue.find(1)
155 fixed_issue = Issue.find(1)
156 assert !fixed_issue.status.is_closed?
156 assert !fixed_issue.status.is_closed?
157 old_status = fixed_issue.status
157 old_status = fixed_issue.status
158
158
159 Repository.scan_changesets_for_issue_ids
159 Repository.scan_changesets_for_issue_ids
160 assert_equal [101, 102], Issue.find(3).changeset_ids
160 assert_equal [101, 102], Issue.find(3).changeset_ids
161
161
162 # fixed issues
162 # fixed issues
163 fixed_issue.reload
163 fixed_issue.reload
164 assert fixed_issue.status.is_closed?
164 assert fixed_issue.status.is_closed?
165 assert_equal 90, fixed_issue.done_ratio
165 assert_equal 90, fixed_issue.done_ratio
166 assert_equal [101], fixed_issue.changeset_ids
166 assert_equal [101], fixed_issue.changeset_ids
167
167
168 # issue change
168 # issue change
169 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
169 journal = fixed_issue.journals.find(:first, :order => 'created_on desc')
170 assert_equal User.find_by_login('dlopper'), journal.user
170 assert_equal User.find_by_login('dlopper'), journal.user
171 assert_equal 'Applied in changeset r2.', journal.notes
171 assert_equal 'Applied in changeset r2.', journal.notes
172
172
173 # 2 email notifications
173 # 2 email notifications
174 assert_equal 2, ActionMailer::Base.deliveries.size
174 assert_equal 2, ActionMailer::Base.deliveries.size
175 mail = ActionMailer::Base.deliveries.first
175 mail = ActionMailer::Base.deliveries.first
176 assert_not_nil mail
176 assert_not_nil mail
177 assert mail.subject.starts_with?(
177 assert mail.subject.starts_with?(
178 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
178 "[#{fixed_issue.project.name} - #{fixed_issue.tracker.name} ##{fixed_issue.id}]")
179 assert_mail_body_match(
179 assert_mail_body_match(
180 "Status changed from #{old_status} to #{fixed_issue.status}", mail)
180 "Status changed from #{old_status} to #{fixed_issue.status}", mail)
181
181
182 # ignoring commits referencing an issue of another project
182 # ignoring commits referencing an issue of another project
183 assert_equal [], Issue.find(4).changesets
183 assert_equal [], Issue.find(4).changesets
184 end
184 end
185
185
186 def test_for_changeset_comments_strip
186 def test_for_changeset_comments_strip
187 repository = Repository::Mercurial.create(
187 repository = Repository::Mercurial.create(
188 :project => Project.find( 4 ),
188 :project => Project.find( 4 ),
189 :url => '/foo/bar/baz' )
189 :url => '/foo/bar/baz' )
190 comment = <<-COMMENT
190 comment = <<-COMMENT
191 This is a loooooooooooooooooooooooooooong comment
191 This is a loooooooooooooooooooooooooooong comment
192
192
193
193
194 COMMENT
194 COMMENT
195 changeset = Changeset.new(
195 changeset = Changeset.new(
196 :comments => comment, :commit_date => Time.now,
196 :comments => comment, :commit_date => Time.now,
197 :revision => 0, :scmid => 'f39b7922fb3c',
197 :revision => 0, :scmid => 'f39b7922fb3c',
198 :committer => 'foo <foo@example.com>',
198 :committer => 'foo <foo@example.com>',
199 :committed_on => Time.now, :repository => repository )
199 :committed_on => Time.now, :repository => repository )
200 assert( changeset.save )
200 assert( changeset.save )
201 assert_not_equal( comment, changeset.comments )
201 assert_not_equal( comment, changeset.comments )
202 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
202 assert_equal( 'This is a loooooooooooooooooooooooooooong comment',
203 changeset.comments )
203 changeset.comments )
204 end
204 end
205
205
206 def test_for_urls_strip_cvs
206 def test_for_urls_strip_cvs
207 repository = Repository::Cvs.create(
207 repository = Repository::Cvs.create(
208 :project => Project.find(4),
208 :project => Project.find(4),
209 :url => ' :pserver:login:password@host:/path/to/the/repository',
209 :url => ' :pserver:login:password@host:/path/to/the/repository',
210 :root_url => 'foo ',
210 :root_url => 'foo ',
211 :log_encoding => 'UTF-8')
211 :log_encoding => 'UTF-8')
212 assert repository.save
212 assert repository.save
213 repository.reload
213 repository.reload
214 assert_equal ':pserver:login:password@host:/path/to/the/repository',
214 assert_equal ':pserver:login:password@host:/path/to/the/repository',
215 repository.url
215 repository.url
216 assert_equal 'foo', repository.root_url
216 assert_equal 'foo', repository.root_url
217 end
217 end
218
218
219 def test_for_urls_strip_subversion
219 def test_for_urls_strip_subversion
220 repository = Repository::Subversion.create(
220 repository = Repository::Subversion.create(
221 :project => Project.find(4),
221 :project => Project.find(4),
222 :url => ' file:///dummy ')
222 :url => ' file:///dummy ')
223 assert repository.save
223 assert repository.save
224 repository.reload
224 repository.reload
225 assert_equal 'file:///dummy', repository.url
225 assert_equal 'file:///dummy', repository.url
226 end
226 end
227
227
228 def test_for_urls_strip_git
228 def test_for_urls_strip_git
229 repository = Repository::Git.create(
229 repository = Repository::Git.create(
230 :project => Project.find(4),
230 :project => Project.find(4),
231 :url => ' c:\dummy ')
231 :url => ' c:\dummy ')
232 assert repository.save
232 assert repository.save
233 repository.reload
233 repository.reload
234 assert_equal 'c:\dummy', repository.url
234 assert_equal 'c:\dummy', repository.url
235 end
235 end
236
236
237 def test_manual_user_mapping
237 def test_manual_user_mapping
238 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
238 assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do
239 c = Changeset.create!(
239 c = Changeset.create!(
240 :repository => @repository,
240 :repository => @repository,
241 :committer => 'foo',
241 :committer => 'foo',
242 :committed_on => Time.now,
242 :committed_on => Time.now,
243 :revision => 100,
243 :revision => 100,
244 :comments => 'Committed by foo.'
244 :comments => 'Committed by foo.'
245 )
245 )
246 assert_nil c.user
246 assert_nil c.user
247 @repository.committer_ids = {'foo' => '2'}
247 @repository.committer_ids = {'foo' => '2'}
248 assert_equal User.find(2), c.reload.user
248 assert_equal User.find(2), c.reload.user
249 # committer is now mapped
249 # committer is now mapped
250 c = Changeset.create!(
250 c = Changeset.create!(
251 :repository => @repository,
251 :repository => @repository,
252 :committer => 'foo',
252 :committer => 'foo',
253 :committed_on => Time.now,
253 :committed_on => Time.now,
254 :revision => 101,
254 :revision => 101,
255 :comments => 'Another commit by foo.'
255 :comments => 'Another commit by foo.'
256 )
256 )
257 assert_equal User.find(2), c.user
257 assert_equal User.find(2), c.user
258 end
258 end
259 end
259 end
260
260
261 def test_auto_user_mapping_by_username
261 def test_auto_user_mapping_by_username
262 c = Changeset.create!(
262 c = Changeset.create!(
263 :repository => @repository,
263 :repository => @repository,
264 :committer => 'jsmith',
264 :committer => 'jsmith',
265 :committed_on => Time.now,
265 :committed_on => Time.now,
266 :revision => 100,
266 :revision => 100,
267 :comments => 'Committed by john.'
267 :comments => 'Committed by john.'
268 )
268 )
269 assert_equal User.find(2), c.user
269 assert_equal User.find(2), c.user
270 end
270 end
271
271
272 def test_auto_user_mapping_by_email
272 def test_auto_user_mapping_by_email
273 c = Changeset.create!(
273 c = Changeset.create!(
274 :repository => @repository,
274 :repository => @repository,
275 :committer => 'john <jsmith@somenet.foo>',
275 :committer => 'john <jsmith@somenet.foo>',
276 :committed_on => Time.now,
276 :committed_on => Time.now,
277 :revision => 100,
277 :revision => 100,
278 :comments => 'Committed by john.'
278 :comments => 'Committed by john.'
279 )
279 )
280 assert_equal User.find(2), c.user
280 assert_equal User.find(2), c.user
281 end
281 end
282
282
283 def test_filesystem_avaialbe
283 def test_filesystem_avaialbe
284 klass = Repository::Filesystem
284 klass = Repository::Filesystem
285 assert klass.scm_adapter_class
285 assert klass.scm_adapter_class
286 assert_equal true, klass.scm_available
286 assert_equal true, klass.scm_available
287 end
287 end
288
288
289 def test_merge_extra_info
289 def test_merge_extra_info
290 repo = Repository::Subversion.new(:project => Project.find(3))
290 repo = Repository::Subversion.new(:project => Project.find(3))
291 assert !repo.save
291 assert !repo.save
292 repo.url = "svn://localhost"
292 repo.url = "svn://localhost"
293 assert repo.save
293 assert repo.save
294 repo.reload
294 repo.reload
295 project = Project.find(3)
295 project = Project.find(3)
296 assert_equal repo, project.repository
296 assert_equal repo, project.repository
297 assert_nil repo.extra_info
297 assert_nil repo.extra_info
298 h1 = {"test_1" => {"test_11" => "test_value_11"}}
298 h1 = {"test_1" => {"test_11" => "test_value_11"}}
299 repo.merge_extra_info(h1)
299 repo.merge_extra_info(h1)
300 assert_equal h1, repo.extra_info
300 assert_equal h1, repo.extra_info
301 h2 = {"test_2" => {
301 h2 = {"test_2" => {
302 "test_21" => "test_value_21",
302 "test_21" => "test_value_21",
303 "test_22" => "test_value_22",
303 "test_22" => "test_value_22",
304 }}
304 }}
305 repo.merge_extra_info(h2)
305 repo.merge_extra_info(h2)
306 assert_equal (h = {"test_11" => "test_value_11"}),
306 assert_equal (h = {"test_11" => "test_value_11"}),
307 repo.extra_info["test_1"]
307 repo.extra_info["test_1"]
308 assert_equal "test_value_21",
308 assert_equal "test_value_21",
309 repo.extra_info["test_2"]["test_21"]
309 repo.extra_info["test_2"]["test_21"]
310 h3 = {"test_2" => {
310 h3 = {"test_2" => {
311 "test_23" => "test_value_23",
311 "test_23" => "test_value_23",
312 "test_24" => "test_value_24",
312 "test_24" => "test_value_24",
313 }}
313 }}
314 repo.merge_extra_info(h3)
314 repo.merge_extra_info(h3)
315 assert_equal (h = {"test_11" => "test_value_11"}),
315 assert_equal (h = {"test_11" => "test_value_11"}),
316 repo.extra_info["test_1"]
316 repo.extra_info["test_1"]
317 assert_nil repo.extra_info["test_2"]["test_21"]
317 assert_nil repo.extra_info["test_2"]["test_21"]
318 assert_equal "test_value_23",
318 assert_equal "test_value_23",
319 repo.extra_info["test_2"]["test_23"]
319 repo.extra_info["test_2"]["test_23"]
320 end
320 end
321 end
321 end
General Comments 0
You need to be logged in to leave comments. Login now