X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7182964d1d475f77a4ae72424c06ebb447b7a14f..041378345708e781b5b3a4a618e9c4848e465218:/services/api/test/unit/collection_test.rb?ds=sidebyside diff --git a/services/api/test/unit/collection_test.rb b/services/api/test/unit/collection_test.rb index d8cb469d67..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 @@ -343,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