[#6441] Block deleting deliverables on closed or locked contracts
This commit is contained in:
1 parent
bf1339fc61
commit
5e50eb7558
3 files changed
+34
-1
No files matched your search
@@ -33,6 +33,9 @@ class Deliverable < ActiveRecord::Base
|
|||||||
delegate "locked?", :to => :contract, :prefix => true, :allow_nil => true
|
delegate "locked?", :to => :contract, :prefix => true, :allow_nil => true
|
||||||
|
|
||||||
# Callbacks
|
# Callbacks
|
||||||
|
before_destroy :block_on_locked_contracts
|
||||||
|
before_destroy :block_on_closed_contracts
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
self.status = "open" unless self.status.present?
|
self.status = "open" unless self.status.present?
|
||||||
end
|
end
|
||||||
@@ -139,6 +142,14 @@ class Deliverable < ActiveRecord::Base
|
|||||||
def noop(message="")
|
def noop(message="")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def block_on_locked_contracts
|
||||||
|
!contract_locked?
|
||||||
|
end
|
||||||
|
|
||||||
|
def block_on_closed_contracts
|
||||||
|
!contract_closed?
|
||||||
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
title
|
title
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<div class="info">
|
<div class="info">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<%= link_to(l(:button_edit), edit_contract_deliverable_path(@project, contract, deliverable), :class => 'icon icon-edit') %>
|
<%= link_to(l(:button_edit), edit_contract_deliverable_path(@project, contract, deliverable), :class => 'icon icon-edit') %>
|
||||||
<%= link_to(l(:button_delete), contract_deliverable_path(@project, contract, deliverable), :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %>
|
<%= link_to(l(:button_delete), contract_deliverable_path(@project, contract, deliverable), :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') if contract.open? %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= textilizable(deliverable, :notes) %>
|
<%= textilizable(deliverable, :notes) %>
|
||||||
|
|||||||
@@ -50,6 +50,17 @@ class DeliverableTest < ActiveSupport::TestCase
|
|||||||
assert !deliverable.valid?
|
assert !deliverable.valid?
|
||||||
assert deliverable.errors.on_base.include?("Can't create a deliverable on a locked contract")
|
assert deliverable.errors.on_base.include?("Can't create a deliverable on a locked contract")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "block deleting a deliverable" do
|
||||||
|
contract = Contract.generate!
|
||||||
|
deliverable = FixedDeliverable.generate!(:contract => contract).reload
|
||||||
|
assert contract.lock!
|
||||||
|
|
||||||
|
assert_no_difference("Deliverable.count") do
|
||||||
|
deliverable.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with a closed contract" do
|
context "with a closed contract" do
|
||||||
@@ -60,5 +71,16 @@ class DeliverableTest < ActiveSupport::TestCase
|
|||||||
assert !deliverable.valid?
|
assert !deliverable.valid?
|
||||||
assert deliverable.errors.on_base.include?("Can't create a deliverable on a closed contract")
|
assert deliverable.errors.on_base.include?("Can't create a deliverable on a closed contract")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "block deleting a deliverable" do
|
||||||
|
contract = Contract.generate!
|
||||||
|
deliverable = FixedDeliverable.generate!(:contract => contract).reload
|
||||||
|
assert contract.close!
|
||||||
|
|
||||||
|
assert_no_difference("Deliverable.count") do
|
||||||
|
deliverable.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user