Removed some shoulda context.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11865 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
474c010746
commit
61dfab12fd
|
@ -99,6 +99,7 @@ module ObjectHelpers
|
||||||
@generated_version_name.succ!
|
@generated_version_name.succ!
|
||||||
version = Version.new(attributes)
|
version = Version.new(attributes)
|
||||||
version.name = @generated_version_name.dup if version.name.blank?
|
version.name = @generated_version_name.dup if version.name.blank?
|
||||||
|
version.project ||= Project.find(1)
|
||||||
yield version if block_given?
|
yield version if block_given?
|
||||||
version.save!
|
version.save!
|
||||||
version
|
version
|
||||||
|
|
|
@ -20,21 +20,19 @@ require File.expand_path('../../../test_helper', __FILE__)
|
||||||
class PatchesTest < ActiveSupport::TestCase
|
class PatchesTest < ActiveSupport::TestCase
|
||||||
include Redmine::I18n
|
include Redmine::I18n
|
||||||
|
|
||||||
context "ActiveRecord::Base.human_attribute_name" do
|
def setup
|
||||||
setup do
|
Setting.default_language = 'en'
|
||||||
Setting.default_language = 'en'
|
end
|
||||||
end
|
|
||||||
|
|
||||||
should "transform name to field_name" do
|
test "ActiveRecord::Base.human_attribute_name should transform name to field_name" do
|
||||||
assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on')
|
assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "cut extra _id suffix for better validation" do
|
test "ActiveRecord::Base.human_attribute_name should cut extra _id suffix for better validation" do
|
||||||
assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on_id')
|
assert_equal l('field_last_login_on'), ActiveRecord::Base.human_attribute_name('last_login_on_id')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "default to humanized value if no translation has been found (useful for custom fields)" do
|
test "ActiveRecord::Base.human_attribute_name should default to humanized value if no translation has been found (useful for custom fields)" do
|
||||||
assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name')
|
assert_equal 'Patch name', ActiveRecord::Base.human_attribute_name('Patch name')
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,19 +18,17 @@
|
||||||
require File.expand_path('../../../../../test_helper', __FILE__)
|
require File.expand_path('../../../../../test_helper', __FILE__)
|
||||||
|
|
||||||
class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
|
class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
|
||||||
context "Mapper#initialize" do
|
test "Mapper#initialize should define a root MenuNode if menu is not present in items" do
|
||||||
should "define a root MenuNode if menu is not present in items" do
|
menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
||||||
menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
|
node = menu_mapper.menu_items
|
||||||
node = menu_mapper.menu_items
|
assert_not_nil node
|
||||||
assert_not_nil node
|
assert_equal :root, node.name
|
||||||
assert_equal :root, node.name
|
end
|
||||||
end
|
|
||||||
|
|
||||||
should "use existing MenuNode if present" do
|
test "Mapper#initialize should use existing MenuNode if present" do
|
||||||
node = "foo" # just an arbitrary reference
|
node = "foo" # just an arbitrary reference
|
||||||
menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {:test_menu => node})
|
menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {:test_menu => node})
|
||||||
assert_equal node, menu_mapper.menu_items
|
assert_equal node, menu_mapper.menu_items
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_push_onto_root
|
def test_push_onto_root
|
||||||
|
|
|
@ -404,25 +404,22 @@ class UserTest < ActiveSupport::TestCase
|
||||||
assert_not_nil u.errors[:mail_notification]
|
assert_not_nil u.errors[:mail_notification]
|
||||||
end
|
end
|
||||||
|
|
||||||
context "User#try_to_login" do
|
test "User#try_to_login should fall-back to case-insensitive if user login is not found as-typed" do
|
||||||
should "fall-back to case-insensitive if user login is not found as-typed." do
|
user = User.try_to_login("AdMin", "admin")
|
||||||
user = User.try_to_login("AdMin", "admin")
|
assert_kind_of User, user
|
||||||
assert_kind_of User, user
|
assert_equal "admin", user.login
|
||||||
assert_equal "admin", user.login
|
end
|
||||||
|
|
||||||
|
test "User#try_to_login should select the exact matching user first" do
|
||||||
|
case_sensitive_user = User.generate! do |user|
|
||||||
|
user.password = "admin123"
|
||||||
end
|
end
|
||||||
|
# bypass validations to make it appear like existing data
|
||||||
|
case_sensitive_user.update_attribute(:login, 'ADMIN')
|
||||||
|
|
||||||
should "select the exact matching user first" do
|
user = User.try_to_login("ADMIN", "admin123")
|
||||||
case_sensitive_user = User.generate! do |user|
|
assert_kind_of User, user
|
||||||
user.password = "admin123"
|
assert_equal "ADMIN", user.login
|
||||||
end
|
|
||||||
# bypass validations to make it appear like existing data
|
|
||||||
case_sensitive_user.update_attribute(:login, 'ADMIN')
|
|
||||||
|
|
||||||
user = User.try_to_login("ADMIN", "admin123")
|
|
||||||
assert_kind_of User, user
|
|
||||||
assert_equal "ADMIN", user.login
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_password
|
def test_password
|
||||||
|
@ -527,20 +524,14 @@ class UserTest < ActiveSupport::TestCase
|
||||||
assert_equal nil, user
|
assert_equal nil, user
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".try_to_login" do
|
test ".try_to_login with good credentials should return the user" do
|
||||||
context "with good credentials" do
|
user = User.try_to_login("admin", "admin")
|
||||||
should "return the user" do
|
assert_kind_of User, user
|
||||||
user = User.try_to_login("admin", "admin")
|
assert_equal "admin", user.login
|
||||||
assert_kind_of User, user
|
end
|
||||||
assert_equal "admin", user.login
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with wrong credentials" do
|
test ".try_to_login with wrong credentials should return nil" do
|
||||||
should "return nil" do
|
assert_nil User.try_to_login("admin", "foo")
|
||||||
assert_nil User.try_to_login("admin", "foo")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ldap_configured?
|
if ldap_configured?
|
||||||
|
@ -684,50 +675,46 @@ class UserTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "User#api_key" do
|
test "#api_key should generate a new one if the user doesn't have one" do
|
||||||
should "generate a new one if the user doesn't have one" do
|
user = User.generate!(:api_token => nil)
|
||||||
user = User.generate!(:api_token => nil)
|
assert_nil user.api_token
|
||||||
assert_nil user.api_token
|
|
||||||
|
|
||||||
key = user.api_key
|
key = user.api_key
|
||||||
assert_equal 40, key.length
|
assert_equal 40, key.length
|
||||||
user.reload
|
user.reload
|
||||||
assert_equal key, user.api_key
|
assert_equal key, user.api_key
|
||||||
end
|
|
||||||
|
|
||||||
should "return the existing api token value" do
|
|
||||||
user = User.generate!
|
|
||||||
token = Token.create!(:action => 'api')
|
|
||||||
user.api_token = token
|
|
||||||
assert user.save
|
|
||||||
|
|
||||||
assert_equal token.value, user.api_key
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "User#find_by_api_key" do
|
test "#api_key should return the existing api token value" do
|
||||||
should "return nil if no matching key is found" do
|
user = User.generate!
|
||||||
assert_nil User.find_by_api_key('zzzzzzzzz')
|
token = Token.create!(:action => 'api')
|
||||||
end
|
user.api_token = token
|
||||||
|
assert user.save
|
||||||
|
|
||||||
should "return nil if the key is found for an inactive user" do
|
assert_equal token.value, user.api_key
|
||||||
user = User.generate!
|
end
|
||||||
user.status = User::STATUS_LOCKED
|
|
||||||
token = Token.create!(:action => 'api')
|
|
||||||
user.api_token = token
|
|
||||||
user.save
|
|
||||||
|
|
||||||
assert_nil User.find_by_api_key(token.value)
|
test "#find_by_api_key should return nil if no matching key is found" do
|
||||||
end
|
assert_nil User.find_by_api_key('zzzzzzzzz')
|
||||||
|
end
|
||||||
|
|
||||||
should "return the user if the key is found for an active user" do
|
test "#find_by_api_key should return nil if the key is found for an inactive user" do
|
||||||
user = User.generate!
|
user = User.generate!
|
||||||
token = Token.create!(:action => 'api')
|
user.status = User::STATUS_LOCKED
|
||||||
user.api_token = token
|
token = Token.create!(:action => 'api')
|
||||||
user.save
|
user.api_token = token
|
||||||
|
user.save
|
||||||
|
|
||||||
assert_equal user, User.find_by_api_key(token.value)
|
assert_nil User.find_by_api_key(token.value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "#find_by_api_key should return the user if the key is found for an active user" do
|
||||||
|
user = User.generate!
|
||||||
|
token = Token.create!(:action => 'api')
|
||||||
|
user.api_token = token
|
||||||
|
user.save
|
||||||
|
|
||||||
|
assert_equal user, User.find_by_api_key(token.value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_default_admin_account_changed_should_return_false_if_account_was_not_changed
|
def test_default_admin_account_changed_should_return_false_if_account_was_not_changed
|
||||||
|
@ -880,29 +867,27 @@ class UserTest < ActiveSupport::TestCase
|
||||||
assert !u.password_confirmation.blank?
|
assert !u.password_confirmation.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#change_password_allowed?" do
|
test "#change_password_allowed? should be allowed if no auth source is set" do
|
||||||
should "be allowed if no auth source is set" do
|
user = User.generate!
|
||||||
user = User.generate!
|
assert user.change_password_allowed?
|
||||||
assert user.change_password_allowed?
|
end
|
||||||
end
|
|
||||||
|
|
||||||
should "delegate to the auth source" do
|
test "#change_password_allowed? should delegate to the auth source" do
|
||||||
user = User.generate!
|
user = User.generate!
|
||||||
|
|
||||||
allowed_auth_source = AuthSource.generate!
|
allowed_auth_source = AuthSource.generate!
|
||||||
def allowed_auth_source.allow_password_changes?; true; end
|
def allowed_auth_source.allow_password_changes?; true; end
|
||||||
|
|
||||||
denied_auth_source = AuthSource.generate!
|
denied_auth_source = AuthSource.generate!
|
||||||
def denied_auth_source.allow_password_changes?; false; end
|
def denied_auth_source.allow_password_changes?; false; end
|
||||||
|
|
||||||
assert user.change_password_allowed?
|
assert user.change_password_allowed?
|
||||||
|
|
||||||
user.auth_source = allowed_auth_source
|
user.auth_source = allowed_auth_source
|
||||||
assert user.change_password_allowed?, "User not allowed to change password, though auth source does"
|
assert user.change_password_allowed?, "User not allowed to change password, though auth source does"
|
||||||
|
|
||||||
user.auth_source = denied_auth_source
|
user.auth_source = denied_auth_source
|
||||||
assert !user.change_password_allowed?, "User allowed to change password, though auth source does not"
|
assert !user.change_password_allowed?, "User allowed to change password, though auth source does not"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_own_account_deletable_should_be_true_with_unsubscrive_enabled
|
def test_own_account_deletable_should_be_true_with_unsubscrive_enabled
|
||||||
|
|
|
@ -132,75 +132,64 @@ class VersionTest < ActiveSupport::TestCase
|
||||||
assert_equal false, version.completed?
|
assert_equal false, version.completed?
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#behind_schedule?" do
|
test "#behind_schedule? should be false if there are no issues assigned" do
|
||||||
setup do
|
version = Version.generate!(:effective_date => Date.yesterday)
|
||||||
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
|
assert_equal false, version.behind_schedule?
|
||||||
@project = Project.create!(:name => 'test0', :identifier => 'test0')
|
|
||||||
@project.trackers << Tracker.create!(:name => 'track')
|
|
||||||
|
|
||||||
@version = Version.create!(:project => @project, :effective_date => nil, :name => 'version')
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be false if there are no issues assigned" do
|
|
||||||
@version.update_attribute(:effective_date, Date.yesterday)
|
|
||||||
assert_equal false, @version.behind_schedule?
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be false if there is no effective_date" do
|
|
||||||
assert_equal false, @version.behind_schedule?
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be false if all of the issues are ahead of schedule" do
|
|
||||||
@version.update_attribute(:effective_date, 7.days.from_now.to_date)
|
|
||||||
add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
|
|
||||||
add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
|
|
||||||
assert_equal 60, @version.completed_percent
|
|
||||||
assert_equal false, @version.behind_schedule?
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be true if any of the issues are behind schedule" do
|
|
||||||
@version.update_attribute(:effective_date, 7.days.from_now.to_date)
|
|
||||||
add_issue(@version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
|
|
||||||
add_issue(@version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left
|
|
||||||
assert_equal 40, @version.completed_percent
|
|
||||||
assert_equal true, @version.behind_schedule?
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be false if all of the issues are complete" do
|
|
||||||
@version.update_attribute(:effective_date, 7.days.from_now.to_date)
|
|
||||||
add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
|
|
||||||
add_issue(@version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
|
|
||||||
assert_equal 100, @version.completed_percent
|
|
||||||
assert_equal false, @version.behind_schedule?
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#estimated_hours" do
|
test "#behind_schedule? should be false if there is no effective_date" do
|
||||||
setup do
|
version = Version.generate!(:effective_date => nil)
|
||||||
@version = Version.create!(:project_id => 1, :name => '#estimated_hours')
|
assert_equal false, version.behind_schedule?
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return 0 with no assigned issues" do
|
test "#behind_schedule? should be false if all of the issues are ahead of schedule" do
|
||||||
assert_equal 0, @version.estimated_hours
|
version = Version.generate!(:effective_date => 7.days.from_now.to_date)
|
||||||
end
|
add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
|
||||||
|
add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
|
||||||
|
assert_equal 60, version.completed_percent
|
||||||
|
assert_equal false, version.behind_schedule?
|
||||||
|
end
|
||||||
|
|
||||||
should "return 0 with no estimated hours" do
|
test "#behind_schedule? should be true if any of the issues are behind schedule" do
|
||||||
add_issue(@version)
|
version = Version.generate!(:effective_date => 7.days.from_now.to_date)
|
||||||
assert_equal 0, @version.estimated_hours
|
add_issue(version, :start_date => 7.days.ago, :done_ratio => 60) # 14 day span, 60% done, 50% time left
|
||||||
end
|
add_issue(version, :start_date => 7.days.ago, :done_ratio => 20) # 14 day span, 20% done, 50% time left
|
||||||
|
assert_equal 40, version.completed_percent
|
||||||
|
assert_equal true, version.behind_schedule?
|
||||||
|
end
|
||||||
|
|
||||||
should "return the sum of estimated hours" do
|
test "#behind_schedule? should be false if all of the issues are complete" do
|
||||||
add_issue(@version, :estimated_hours => 2.5)
|
version = Version.generate!(:effective_date => 7.days.from_now.to_date)
|
||||||
add_issue(@version, :estimated_hours => 5)
|
add_issue(version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
|
||||||
assert_equal 7.5, @version.estimated_hours
|
add_issue(version, :start_date => 14.days.ago, :done_ratio => 100, :status => IssueStatus.find(5)) # 7 day span
|
||||||
end
|
assert_equal 100, version.completed_percent
|
||||||
|
assert_equal false, version.behind_schedule?
|
||||||
|
end
|
||||||
|
|
||||||
should "return the sum of leaves estimated hours" do
|
test "#estimated_hours should return 0 with no assigned issues" do
|
||||||
parent = add_issue(@version)
|
version = Version.generate!
|
||||||
add_issue(@version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
|
assert_equal 0, version.estimated_hours
|
||||||
add_issue(@version, :estimated_hours => 5, :parent_issue_id => parent.id)
|
end
|
||||||
assert_equal 7.5, @version.estimated_hours
|
|
||||||
end
|
test "#estimated_hours should return 0 with no estimated hours" do
|
||||||
|
version = Version.generate!
|
||||||
|
add_issue(version)
|
||||||
|
assert_equal 0, version.estimated_hours
|
||||||
|
end
|
||||||
|
|
||||||
|
test "#estimated_hours should return return the sum of estimated hours" do
|
||||||
|
version = Version.generate!
|
||||||
|
add_issue(version, :estimated_hours => 2.5)
|
||||||
|
add_issue(version, :estimated_hours => 5)
|
||||||
|
assert_equal 7.5, version.estimated_hours
|
||||||
|
end
|
||||||
|
|
||||||
|
test "#estimated_hours should return the sum of leaves estimated hours" do
|
||||||
|
version = Version.generate!
|
||||||
|
parent = add_issue(version)
|
||||||
|
add_issue(version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
|
||||||
|
add_issue(version, :estimated_hours => 5, :parent_issue_id => parent.id)
|
||||||
|
assert_equal 7.5, version.estimated_hours
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
|
test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
|
||||||
|
|
Loading…
Reference in New Issue