[#6441] Refactor: only call validation on updates
This commit is contained in:
1 parent
5c1e254181
commit
62cdfd35de
1 file changed
+2
-4
@@ -20,7 +20,7 @@ class Deliverable < ActiveRecord::Base
|
|||||||
validates_presence_of :type
|
validates_presence_of :type
|
||||||
validates_presence_of :manager
|
validates_presence_of :manager
|
||||||
validates_inclusion_of :status, :in => ["open","locked","closed"], :allow_blank => true, :allow_nil => true
|
validates_inclusion_of :status, :in => ["open","locked","closed"], :allow_blank => true, :allow_nil => true
|
||||||
validate :validate_update_allowed
|
validate_on_update :validate_status_changes
|
||||||
|
|
||||||
# Accessors
|
# Accessors
|
||||||
include DollarizedAttribute
|
include DollarizedAttribute
|
||||||
@@ -80,8 +80,7 @@ class Deliverable < ActiveRecord::Base
|
|||||||
(new_record? || open?)
|
(new_record? || open?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_update_allowed
|
def validate_status_changes
|
||||||
unless new_record?
|
|
||||||
if changes.keys == ["status"]
|
if changes.keys == ["status"]
|
||||||
noop("Allow changes to the status only")
|
noop("Allow changes to the status only")
|
||||||
elsif changes["status"].present? && changes["status"].second == "open"
|
elsif changes["status"].present? && changes["status"].second == "open"
|
||||||
@@ -93,7 +92,6 @@ class Deliverable < ActiveRecord::Base
|
|||||||
errors.add_to_base(:cant_update_closed_deliverable) if closed?
|
errors.add_to_base(:cant_update_closed_deliverable) if closed?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
# No operation method, useful to clean up logic with an optional message
|
# No operation method, useful to clean up logic with an optional message
|
||||||
# for documentation
|
# for documentation
|
||||||
|
|||||||
Reference in new issue
Block a user