X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f0a85e273056d0ad440084c11a37c73ce25fb4f6..d63756d4e3c12c637c34cebe6208e582e67f1924:/services/api/test/unit/collection_test.rb diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb index a1008eec4d..9797ed63dc 100644 --- a/services/api/test/unit/collection_test.rb +++ b/services/api/test/unit/collection_test.rb @@ -173,6 +173,26 @@ class CollectionTest < ActiveSupport::TestCase 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 @@ -230,10 +250,10 @@ class CollectionTest < ActiveSupport::TestCase 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? @@ -245,25 +265,18 @@ class CollectionTest < ActiveSupport::TestCase 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 @@ -350,6 +363,31 @@ class CollectionTest < ActiveSupport::TestCase 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