##// END OF EJS Templates
Removed some shoulda context....
Jean-Philippe Lang -
r11635:61dfab12fd72
parent child
Show More
@@ -99,6 +99,7 module ObjectHelpers
99 99 @generated_version_name.succ!
100 100 version = Version.new(attributes)
101 101 version.name = @generated_version_name.dup if version.name.blank?
102 version.project ||= Project.find(1)
102 103 yield version if block_given?
103 104 version.save!
104 105 version
@@ -20,21 +20,19 require File.expand_path('../../../test_helper', __FILE__)
20 20 class PatchesTest < ActiveSupport::TestCase
21 21 include Redmine::I18n
22 22
23 context "ActiveRecord::Base.human_attribute_name" do
24 setup do
23 def setup
25 24 Setting.default_language = 'en'
26 25 end
27 26
28 should "transform name to field_name" do
27 test "ActiveRecord::Base.human_attribute_name should transform name to field_name" do
29 28 assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on')
30 29 end
31 30
32 should "cut extra _id suffix for better validation" do
31 test "ActiveRecord::Base.human_attribute_name should cut extra _id suffix for better validation" do
33 32 assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on_id')
34 33 end
35 34
36 should "default to humanized value if no translation has been found (useful for custom fields)" do
35 test "ActiveRecord::Base.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
37 36 assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name')
38 37 end
39 38 end
40 end
@@ -18,20 +18,18
18 18 require File.expand_path('../../../../../test_helper', __FILE__)
19 19
20 20 class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
21 context "Mapper#initialize" do
22 should "define a root MenuNode if menu is not present in items" do
21 test "Mapper#initialize should define a root MenuNode if menu is not present in items" do
23 22 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
24 23 node = menu_mapper.menu_items
25 24 assert_not_nil node
26 25 assert_equal :root, node.name
27 26 end
28 27
29 should "use existing MenuNode if present" do
28 test "Mapper#initialize should use existing MenuNode if present" do
30 29 node = "foo" # just an arbitrary reference
31 30 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {:test_menu => node})
32 31 assert_equal node, menu_mapper.menu_items
33 32 end
34 end
35 33
36 34 def test_push_onto_root
37 35 menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
@@ -404,14 +404,13 class UserTest < ActiveSupport::TestCase
404 404 assert_not_nil u.errors[:mail_notification]
405 405 end
406 406
407 context "User#try_to_login" do
408 should "fall-back to case-insensitive if user login is not found as-typed." do
407 test "User#try_to_login should fall-back to case-insensitive if user login is not found as-typed" do
409 408 user = User.try_to_login("AdMin", "admin")
410 409 assert_kind_of User, user
411 410 assert_equal "admin", user.login
412 411 end
413 412
414 should "select the exact matching user first" do
413 test "User#try_to_login should select the exact matching user first" do
415 414 case_sensitive_user = User.generate! do |user|
416 415 user.password = "admin123"
417 416 end
@@ -421,8 +420,6 class UserTest < ActiveSupport::TestCase
421 420 user = User.try_to_login("ADMIN", "admin123")
422 421 assert_kind_of User, user
423 422 assert_equal "ADMIN", user.login
424
425 end
426 423 end
427 424
428 425 def test_password
@@ -527,21 +524,15 class UserTest < ActiveSupport::TestCase
527 524 assert_equal nil, user
528 525 end
529 526
530 context ".try_to_login" do
531 context "with good credentials" do
532 should "return the user" do
527 test ".try_to_login with good credentials should return the user" do
533 528 user = User.try_to_login("admin", "admin")
534 529 assert_kind_of User, user
535 530 assert_equal "admin", user.login
536 531 end
537 end
538 532
539 context "with wrong credentials" do
540 should "return nil" do
533 test ".try_to_login with wrong credentials should return nil" do
541 534 assert_nil User.try_to_login("admin", "foo")
542 535 end
543 end
544 end
545 536
546 537 if ldap_configured?
547 538 context "#try_to_login using LDAP" do
@@ -684,8 +675,7 class UserTest < ActiveSupport::TestCase
684 675 end
685 676 end
686 677
687 context "User#api_key" do
688 should "generate a new one if the user doesn't have one" do
678 test "#api_key should generate a new one if the user doesn't have one" do
689 679 user = User.generate!(:api_token => nil)
690 680 assert_nil user.api_token
691 681
@@ -695,7 +685,7 class UserTest < ActiveSupport::TestCase
695 685 assert_equal key, user.api_key
696 686 end
697 687
698 should "return the existing api token value" do
688 test "#api_key should return the existing api token value" do
699 689 user = User.generate!
700 690 token = Token.create!(:action => 'api')
701 691 user.api_token = token
@@ -703,14 +693,12 class UserTest < ActiveSupport::TestCase
703 693
704 694 assert_equal token.value, user.api_key
705 695 end
706 end
707 696
708 context "User#find_by_api_key" do
709 should "return nil if no matching key is found" do
697 test "#find_by_api_key should return nil if no matching key is found" do
710 698 assert_nil User.find_by_api_key('zzzzzzzzz')
711 699 end
712 700
713 should "return nil if the key is found for an inactive user" do
701 test "#find_by_api_key should return nil if the key is found for an inactive user" do
714 702 user = User.generate!
715 703 user.status = User::STATUS_LOCKED
716 704 token = Token.create!(:action => 'api')
@@ -720,7 +708,7 class UserTest < ActiveSupport::TestCase
720 708 assert_nil User.find_by_api_key(token.value)
721 709 end
722 710
723 should "return the user if the key is found for an active user" do
711 test "#find_by_api_key should return the user if the key is found for an active user" do
724 712 user = User.generate!
725 713 token = Token.create!(:action => 'api')
726 714 user.api_token = token
@@ -728,7 +716,6 class UserTest < ActiveSupport::TestCase
728 716
729 717 assert_equal user, User.find_by_api_key(token.value)
730 718 end
731 end
732 719
733 720 def test_default_admin_account_changed_should_return_false_if_account_was_not_changed
734 721 user = User.find_by_login("admin")
@@ -880,13 +867,12 class UserTest < ActiveSupport::TestCase
880 867 assert !u.password_confirmation.blank?
881 868 end
882 869
883 context "#change_password_allowed?" do
884 should "be allowed if no auth source is set" do
870 test "#change_password_allowed? should be allowed if no auth source is set" do
885 871 user = User.generate!
886 872 assert user.change_password_allowed?
887 873 end
888 874
889 should "delegate to the auth source" do
875 test "#change_password_allowed? should delegate to the auth source" do
890 876 user = User.generate!
891 877
892 878 allowed_auth_source = AuthSource.generate!
@@ -903,7 +889,6 class UserTest < ActiveSupport::TestCase
903 889 user.auth_source = denied_auth_source
904 890 assert !user.change_password_allowed?, "User allowed to change password, though auth source does not"
905 891 end
906 end
907 892
908 893 def test_own_account_deletable_should_be_true_with_unsubscrive_enabled
909 894 with_settings :unsubscribe => '1' do
@@ -132,75 +132,64 class VersionTest < ActiveSupport::TestCase
132 132 assert_equal false, version.completed?
133 133 end
134 134
135 context "#behind_schedule?" do
136 setup do
137 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
138 @project = Project.create!(:name => 'test0', :identifier => 'test0')
139 @project.trackers << Tracker.create!(:name => 'track')
140
141 @version = Version.create!(:project => @project, :effective_date => nil, :name => 'version')
142 end
143
144 should "be false if there are no issues assigned" do
145 @version.update_attribute(:effective_date, Date.yesterday)
146 assert_equal false, @version.behind_schedule?
135 test "#behind_schedule? should be false if there are no issues assigned" do
136 version = Version.generate!(:effective_date => Date.yesterday)
137 assert_equal false, version.behind_schedule?
147 138 end
148 139
149 should "be false if there is no effective_date" do
150 assert_equal false, @version.behind_schedule?
140 test "#behind_schedule? should be false if there is no effective_date" do
141 version = Version.generate!(:effective_date => nil)
142 assert_equal false, version.behind_schedule?
151 143 end
152 144
153 should "be false if all of the issues are ahead of schedule" do
154 @version.update_attribute(:effective_date, 7.days.from_now.to_date)
155 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
156 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
157 assert_equal 60, @version.completed_percent
158 assert_equal false, @version.behind_schedule?
145 test "#behind_schedule? should be false if all of the issues are ahead of schedule" do
146 version = Version.generate!(:effective_date => 7.days.from_now.to_date)
147 add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
148 add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
149 assert_equal 60, version.completed_percent
150 assert_equal false, version.behind_schedule?
159 151 end
160 152
161 should "be true if any of the issues are behind schedule" do
162 @version.update_attribute(:effective_date, 7.days.from_now.to_date)
163 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
164 add_issue(@version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left
165 assert_equal 40, @version.completed_percent
166 assert_equal true, @version.behind_schedule?
153 test "#behind_schedule? should be true if any of the issues are behind schedule" do
154 version = Version.generate!(:effective_date => 7.days.from_now.to_date)
155 add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
156 add_issue(version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left
157 assert_equal 40, version.completed_percent
158 assert_equal true, version.behind_schedule?
167 159 end
168 160
169 should "be false if all of the issues are complete" do
170 @version.update_attribute(:effective_date, 7.days.from_now.to_date)
171 add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
172 add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
173 assert_equal 100, @version.completed_percent
174 assert_equal false, @version.behind_schedule?
175 end
161 test "#behind_schedule? should be false if all of the issues are complete" do
162 version = Version.generate!(:effective_date => 7.days.from_now.to_date)
163 add_issue(version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
164 add_issue(version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
165 assert_equal 100, version.completed_percent
166 assert_equal false, version.behind_schedule?
176 167 end
177 168
178 context "#estimated_hours" do
179 setup do
180 @version = Version.create!(:project_id => 1, :name => '#estimated_hours')
169 test "#estimated_hours should return 0 with no assigned issues" do
170 version = Version.generate!
171 assert_equal 0, version.estimated_hours
181 172 end
182 173
183 should "return 0 with no assigned issues" do
184 assert_equal 0, @version.estimated_hours
174 test "#estimated_hours should return 0 with no estimated hours" do
175 version = Version.generate!
176 add_issue(version)
177 assert_equal 0, version.estimated_hours
185 178 end
186 179
187 should "return 0 with no estimated hours" do
188 add_issue(@version)
189 assert_equal 0, @version.estimated_hours
180 test "#estimated_hours should return return the sum of estimated hours" do
181 version = Version.generate!
182 add_issue(version, :estimated_hours => 2.5)
183 add_issue(version, :estimated_hours => 5)
184 assert_equal 7.5, version.estimated_hours
190 185 end
191 186
192 should "return the sum of estimated hours" do
193 add_issue(@version, :estimated_hours => 2.5)
194 add_issue(@version, :estimated_hours => 5)
195 assert_equal 7.5, @version.estimated_hours
196 end
197
198 should "return the sum of leaves estimated hours" do
199 parent = add_issue(@version)
200 add_issue(@version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
201 add_issue(@version, :estimated_hours => 5, :parent_issue_id => parent.id)
202 assert_equal 7.5, @version.estimated_hours
203 end
187 test "#estimated_hours should return the sum of leaves estimated hours" do
188 version = Version.generate!
189 parent = add_issue(version)
190 add_issue(version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
191 add_issue(version, :estimated_hours => 5, :parent_issue_id => parent.id)
192 assert_equal 7.5, version.estimated_hours
204 193 end
205 194
206 195 test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
General Comments 0
You need to be logged in to leave comments. Login now