end
end
+ [
+ ['version', 10],
+ ['current_version_uuid', 'zzzzz-4zz18-bv31uwvy3neko21'],
+ ].each do |name, new_value|
+ test "'#{name}' updates on current version collections are not allowed" do
+ act_as_user users(:active) do
+ # Set up initial collection
+ c = create_collection 'foo', Encoding::US_ASCII
+ assert c.valid?
+ assert_equal 1, c.version
+
+ assert_raises(ActiveRecord::RecordInvalid) do
+ c.update_attributes!({
+ name => new_value
+ })
+ end
+ end
+ end
+ end
+
test "uuid updates on current version make older versions update their pointers" do
Rails.configuration.collection_versioning = true
Rails.configuration.preserve_version_if_idle = 0
end
end
- test "older versions should no be directly updatable" do
+ test "past versions should not be directly updatable" do
Rails.configuration.collection_versioning = true
Rails.configuration.preserve_version_if_idle = 0
- act_as_user users(:active) do
+ act_as_system_user do
# Set up initial collection
c = create_collection 'foo', Encoding::US_ASCII
assert c.valid?
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
end
end
+ test 'current_version_uuid is ignored during update' do
+ Rails.configuration.collection_versioning = true
+ Rails.configuration.preserve_version_if_idle = 0
+ act_as_user users(:active) do
+ # Create 1st collection
+ col1 = create_collection 'foo', Encoding::US_ASCII
+ assert col1.valid?
+ assert_equal 1, col1.version
+
+ # Create 2nd collection, update it so it becomes version:2
+ # (to avoid unique index violation)
+ col2 = create_collection 'bar', Encoding::US_ASCII
+ assert col2.valid?
+ assert_equal 1, col2.version
+ col2.update_attributes({name: 'baz'})
+ assert_equal 2, col2.version
+
+ # Try to make col2 a past version of col1. It shouldn't be possible
+ col2.update_attributes({current_version_uuid: col1.uuid})
+ assert col2.invalid?
+ col2.reload
+ assert_not_equal col1.uuid, col2.current_version_uuid
+ end
+ end
+
test 'with versioning enabled, simultaneous updates increment version correctly' do
Rails.configuration.collection_versioning = true
Rails.configuration.preserve_version_if_idle = 0