app/models/ddr/batch/batch_object_attribute.rb in ddr-batch-2.0.0.alpha.2 vs app/models/ddr/batch/batch_object_attribute.rb in ddr-batch-2.0.0.alpha.3

- old
+ new

@@ -14,16 +14,25 @@ VALUE_TYPES = [ VALUE_TYPE_STRING ] validates :operation, inclusion: { in: OPERATIONS } validates :datastream, presence: true + validate :valid_datastream_operation with_options if: :operation_requires_name? do |obj| obj.validates :name, presence: true end validate :valid_datastream_and_attribute_name, if: [ 'batch_object.model', 'datastream', 'name' ] with_options if: :operation_requires_value? do |obj| obj.validates :value, presence: true obj.validates :value_type, inclusion: { in: VALUE_TYPES } + end + + def valid_datastream_operation + if operation == OPERATION_CLEAR_ALL + unless datastream == 'descMetadata' + errors.add(:operation, "Operation #{operation} is not valid for #{datastream}") + end + end end def operation_requires_name? [ OPERATION_ADD, OPERATION_DELETE, OPERATION_CLEAR ].include? operation end