validate :ensure_pdh_matches_manifest_text
validate :ensure_storage_classes_desired_is_not_empty
validate :ensure_storage_classes_contain_non_empty_strings
- validate :old_versions_cannot_be_updated, on: :update
+ validate :past_versions_cannot_be_updated, on: :update
before_save :set_file_names
around_update :prepare_for_versioning
after_update :save_old_version, if: Proc.new { |c| c.should_preserve_version? }
end
end
- def old_versions_cannot_be_updated
+ def past_versions_cannot_be_updated
# We check for the '_was' values just in case the update operation
# includes a change on current_version_uuid or uuid.
if current_version_uuid_was != uuid_was
- raise ArvadosModel::PermissionDeniedError.new("previous versions cannot be updated")
+ errors.add(:base, "past versions cannot be updated")
+ false
end
end
c_old = Collection.where(current_version_uuid: c.uuid, version: 1).first
assert_not_nil c_old
# With collection versioning still being enabled, try to update
- assert_raises ArvadosModel::PermissionDeniedError do
- c_old.update_attributes(name: 'this was foo')
- end
+ c_old.name = 'this was foo'
+ assert c_old.invalid?
c_old.reload
- assert_equal 'foo', c_old.name
# Try to fool the validator attempting to make c_old to look like a
# current version, it should also fail.
- assert_raises ArvadosModel::PermissionDeniedError do
- c_old.update_attributes(current_version_uuid: c_old.uuid)
- end
+ c_old.current_version_uuid = c_old.uuid
+ assert c_old.invalid?
c_old.reload
- assert_equal c.uuid, c_old.current_version_uuid
# Now disable collection versioning, it should behave the same way
Rails.configuration.collection_versioning = false
- assert_raises ArvadosModel::PermissionDeniedError do
- c_old.update_attributes(name: 'this was foo')
- end
- c_old.reload
- assert_equal 'foo', c_old.name
+ c_old.name = 'this was foo'
+ assert c_old.invalid?
end
end