From 2f79493ccad75f4d850771ad82743da15d75e45b Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 9 Aug 2011 15:48:46 -0700 Subject: [PATCH] [#6441] Block logging time on locked contracts and deliverables --- config/locales/en.yml | 2 ++ .../patches/time_entry_patch.rb | 2 ++ .../patches/time_entry_patch_test.rb | 30 ++++++++++++++----- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 5c260b7..85aaa5e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,6 +4,8 @@ en: messages: cant_create_time_on_closed_deliverable: "Can't create a time entry on a closed deliverable" cant_create_time_on_closed_contract: "Can't create a time entry on a closed contract" + cant_create_time_on_locked_deliverable: "Can't create a time entry on a locked deliverable" + cant_create_time_on_locked_contract: "Can't create a time entry on a locked contract" cant_assign_to_closed_deliverable: "Can't assign issue to a closed deliverable" cant_assign_to_locked_deliverable: "Can't assign issue to a locked deliverable" cant_update_locked_deliverable: "Can't update a locked deliverable" diff --git a/lib/redmine_contracts/patches/time_entry_patch.rb b/lib/redmine_contracts/patches/time_entry_patch.rb index 0a327b2..b3ce8a7 100644 --- a/lib/redmine_contracts/patches/time_entry_patch.rb +++ b/lib/redmine_contracts/patches/time_entry_patch.rb @@ -13,12 +13,14 @@ module RedmineContracts def validate_deliverable_status if issue.present? && issue.deliverable.present? + errors.add_to_base(:cant_create_time_on_locked_deliverable) if issue.deliverable.locked? errors.add_to_base(:cant_create_time_on_closed_deliverable) if issue.deliverable.closed? end end def validate_contract_status if issue.present? && issue.deliverable.present? && issue.deliverable.contract.present? + errors.add_to_base(:cant_create_time_on_locked_contract) if issue.deliverable.contract.locked? errors.add_to_base(:cant_create_time_on_closed_contract) if issue.deliverable.contract.closed? end end diff --git a/test/unit/lib/redmine_contracts/patches/time_entry_patch_test.rb b/test/unit/lib/redmine_contracts/patches/time_entry_patch_test.rb index d844c15..52c3d57 100644 --- a/test/unit/lib/redmine_contracts/patches/time_entry_patch_test.rb +++ b/test/unit/lib/redmine_contracts/patches/time_entry_patch_test.rb @@ -24,6 +24,14 @@ class RedmineContracts::Patches::TimeEntryTest < ActionController::TestCase :user => @user) end + def assert_error_about_locked_deliverable(time_entry) + assert_equal "Can't create a time entry on a locked deliverable", time_entry.errors.on_base + end + + def assert_error_about_locked_contract(time_entry) + assert_equal "Can't create a time entry on a locked contract", time_entry.errors.on_base + end + def assert_error_about_closed_deliverable(time_entry) assert_equal "Can't create a time entry on a closed deliverable", time_entry.errors.on_base end @@ -36,27 +44,31 @@ class RedmineContracts::Patches::TimeEntryTest < ActionController::TestCase assert_difference("TimeEntry.count") { create_time_entry } end - should "allow logging time to an issue on a locked deliverable, open contract" do + should "block logging time to an issue on a locked deliverable, open contract" do assert @deliverable.lock! assert @deliverable.locked? - assert_difference("TimeEntry.count") { create_time_entry } + assert_no_difference("TimeEntry.count") { create_time_entry } + assert_error_about_locked_deliverable(@time_entry) end - should "allow logging time to an issue on an open deliverable, locked contract" do + should "block logging time to an issue on an open deliverable, locked contract" do assert @contract.lock! assert @contract.locked? - assert_difference("TimeEntry.count") { create_time_entry } + assert_no_difference("TimeEntry.count") { create_time_entry } + assert_error_about_locked_contract(@time_entry) end - should "allow logging time to an issue on a locked deliverable, locked contract" do + should "block logging time to an issue on a locked deliverable, locked contract" do assert @deliverable.lock! assert @deliverable.locked? assert @contract.lock! assert @contract.locked? - assert_difference("TimeEntry.count") { create_time_entry } + assert_no_difference("TimeEntry.count") { create_time_entry } + assert @time_entry.errors.on_base.include?("Can't create a time entry on a locked deliverable") + assert @time_entry.errors.on_base.include?("Can't create a time entry on a locked contract") end should "block logging time to an issue on a closed deliverable, open contract" do @@ -74,7 +86,8 @@ class RedmineContracts::Patches::TimeEntryTest < ActionController::TestCase assert @contract.locked? assert_no_difference("TimeEntry.count") { create_time_entry } - assert_error_about_closed_deliverable(@time_entry) + assert @time_entry.errors.on_base.include?("Can't create a time entry on a closed deliverable") + assert @time_entry.errors.on_base.include?("Can't create a time entry on a locked contract") end should "block logging time to an issue on an open deliverable, closed contract" do @@ -92,7 +105,8 @@ class RedmineContracts::Patches::TimeEntryTest < ActionController::TestCase assert @contract.closed? assert_no_difference("TimeEntry.count") { create_time_entry } - assert_error_about_closed_contract(@time_entry) + assert @time_entry.errors.on_base.include?("Can't create a time entry on a locked deliverable") + assert @time_entry.errors.on_base.include?("Can't create a time entry on a closed contract") end should "block logging time to an issue on a closed deliverable, closed contract" do