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:
Jean-Philippe Lang 2013-05-18 09:27:48 +00:00
parent 474c010746
commit 61dfab12fd
5 changed files with 143 additions and 172 deletions

View File

@ -99,6 +99,7 @@ module ObjectHelpers
@generated_version_name.succ!
version = Version.new(attributes)
version.name = @generated_version_name.dup if version.name.blank?
version.project ||= Project.find(1)
yield version if block_given?
version.save!
version

View File

@ -20,21 +20,19 @@ require File.expand_path('../../../test_helper', __FILE__)
class PatchesTest < ActiveSupport::TestCase
include Redmine::I18n
context "ActiveRecord::Base.human_attribute_name" do
setup do
def setup
Setting.default_language = 'en'
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')
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')
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')
end
end
end

View File

@ -18,20 +18,18 @@
require File.expand_path('../../../../../test_helper', __FILE__)
class Redmine::MenuManager::MapperTest < ActiveSupport::TestCase
context "Mapper#initialize" do
should "define a root MenuNode if menu is not present in items" do
test "Mapper#initialize should define a root MenuNode if menu is not present in items" do
menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})
node = menu_mapper.menu_items
assert_not_nil node
assert_equal :root, node.name
end
should "use existing MenuNode if present" do
test "Mapper#initialize should use existing MenuNode if present" do
node = "foo" # just an arbitrary reference
menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {:test_menu => node})
assert_equal node, menu_mapper.menu_items
end
end
def test_push_onto_root
menu_mapper = Redmine::MenuManager::Mapper.new(:test_menu, {})

View File

@ -404,14 +404,13 @@ class UserTest < ActiveSupport::TestCase
assert_not_nil u.errors[:mail_notification]
end
context "User#try_to_login" do
should "fall-back to case-insensitive if user login is not found as-typed." do
test "User#try_to_login should fall-back to case-insensitive if user login is not found as-typed" do
user = User.try_to_login("AdMin", "admin")
assert_kind_of User, user
assert_equal "admin", user.login
end
should "select the exact matching user first" do
test "User#try_to_login should select the exact matching user first" do
case_sensitive_user = User.generate! do |user|
user.password = "admin123"
end
@ -421,8 +420,6 @@ class UserTest < ActiveSupport::TestCase
user = User.try_to_login("ADMIN", "admin123")
assert_kind_of User, user
assert_equal "ADMIN", user.login
end
end
def test_password
@ -527,21 +524,15 @@ class UserTest < ActiveSupport::TestCase
assert_equal nil, user
end
context ".try_to_login" do
context "with good credentials" do
should "return the user" do
test ".try_to_login with good credentials should return the user" do
user = User.try_to_login("admin", "admin")
assert_kind_of User, user
assert_equal "admin", user.login
end
end
context "with wrong credentials" do
should "return nil" do
test ".try_to_login with wrong credentials should return nil" do
assert_nil User.try_to_login("admin", "foo")
end
end
end
if ldap_configured?
context "#try_to_login using LDAP" do
@ -684,8 +675,7 @@ class UserTest < ActiveSupport::TestCase
end
end
context "User#api_key" do
should "generate a new one if the user doesn't have one" do
test "#api_key should generate a new one if the user doesn't have one" do
user = User.generate!(:api_token => nil)
assert_nil user.api_token
@ -695,7 +685,7 @@ class UserTest < ActiveSupport::TestCase
assert_equal key, user.api_key
end
should "return the existing api token value" do
test "#api_key should return the existing api token value" do
user = User.generate!
token = Token.create!(:action => 'api')
user.api_token = token
@ -703,14 +693,12 @@ class UserTest < ActiveSupport::TestCase
assert_equal token.value, user.api_key
end
end
context "User#find_by_api_key" do
should "return nil if no matching key is found" do
test "#find_by_api_key should return nil if no matching key is found" do
assert_nil User.find_by_api_key('zzzzzzzzz')
end
should "return nil if the key is found for an inactive user" do
test "#find_by_api_key should return nil if the key is found for an inactive user" do
user = User.generate!
user.status = User::STATUS_LOCKED
token = Token.create!(:action => 'api')
@ -720,7 +708,7 @@ class UserTest < ActiveSupport::TestCase
assert_nil User.find_by_api_key(token.value)
end
should "return the user if the key is found for an active user" do
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
@ -728,7 +716,6 @@ class UserTest < ActiveSupport::TestCase
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
user = User.find_by_login("admin")
@ -880,13 +867,12 @@ class UserTest < ActiveSupport::TestCase
assert !u.password_confirmation.blank?
end
context "#change_password_allowed?" do
should "be allowed if no auth source is set" do
test "#change_password_allowed? should be allowed if no auth source is set" do
user = User.generate!
assert user.change_password_allowed?
end
should "delegate to the auth source" do
test "#change_password_allowed? should delegate to the auth source" do
user = User.generate!
allowed_auth_source = AuthSource.generate!
@ -903,7 +889,6 @@ class UserTest < ActiveSupport::TestCase
user.auth_source = denied_auth_source
assert !user.change_password_allowed?, "User allowed to change password, though auth source does not"
end
end
def test_own_account_deletable_should_be_true_with_unsubscrive_enabled
with_settings :unsubscribe => '1' do

View File

@ -132,75 +132,64 @@ class VersionTest < ActiveSupport::TestCase
assert_equal false, version.completed?
end
context "#behind_schedule?" do
setup do
ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
@project = Project.create!(:name => 'test0', :identifier => 'test0')
@project.trackers << Tracker.create!(:name => 'track')
@version = Version.create!(:project => @project, :effective_date => nil, :name => 'version')
test "#behind_schedule? should be false if there are no issues assigned" do
version = Version.generate!(:effective_date => Date.yesterday)
assert_equal false, version.behind_schedule?
end
should "be false if there are no issues assigned" do
@version.update_attribute(:effective_date, Date.yesterday)
assert_equal false, @version.behind_schedule?
test "#behind_schedule? should be false if there is no effective_date" do
version = Version.generate!(:effective_date => nil)
assert_equal false, version.behind_schedule?
end
should "be false if there is no effective_date" do
assert_equal false, @version.behind_schedule?
test "#behind_schedule? should be false if all of the issues are ahead of schedule" do
version = Version.generate!(: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 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?
test "#behind_schedule? should be true if any of the issues are behind schedule" do
version = Version.generate!(: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 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?
test "#behind_schedule? should be false if all of the issues are complete" do
version = Version.generate!(: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
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
test "#estimated_hours should return 0 with no assigned issues" do
version = Version.generate!
assert_equal 0, version.estimated_hours
end
context "#estimated_hours" do
setup do
@version = Version.create!(:project_id => 1, :name => '#estimated_hours')
test "#estimated_hours should return 0 with no estimated hours" do
version = Version.generate!
add_issue(version)
assert_equal 0, version.estimated_hours
end
should "return 0 with no assigned issues" do
assert_equal 0, @version.estimated_hours
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
should "return 0 with no estimated hours" do
add_issue(@version)
assert_equal 0, @version.estimated_hours
end
should "return the sum of estimated hours" do
add_issue(@version, :estimated_hours => 2.5)
add_issue(@version, :estimated_hours => 5)
assert_equal 7.5, @version.estimated_hours
end
should "return the sum of leaves estimated hours" do
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
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
test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do