end
end
+ # This test exposes a bug related to JSONB attributes, see #15725.
+ test "recently loaded collection shouldn't list changed attributes" do
+ col = Collection.where("properties != '{}'::jsonb").limit(1).first
+ refute col.properties_changed?, 'Properties field should not be seen as changed'
+ end
+
+ [
+ [
+ true,
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ {:foo=>:bar, :lst=>[1, 3, 5, 7], :hsh=>{'baz'=>'qux', :foobar=>true, 'hsh'=>{:nested=>true}}, :delete_at=>nil},
+ ],
+ [
+ true,
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ {'delete_at'=>nil, 'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}},
+ ],
+ [
+ true,
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ {'delete_at'=>nil, 'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'foobar'=>true, 'hsh'=>{'nested'=>true}, 'baz'=>'qux'}},
+ ],
+ [
+ false,
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 42], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ ],
+ [
+ false,
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ {'foo'=>'bar', 'lst'=>[1, 3, 7, 5], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ ],
+ [
+ false,
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>false}}, 'delete_at'=>nil},
+ ],
+ [
+ false,
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>nil},
+ {'foo'=>'bar', 'lst'=>[1, 3, 5, 7], 'hsh'=>{'baz'=>'qux', 'foobar'=>true, 'hsh'=>{'nested'=>true}}, 'delete_at'=>1234567890},
+ ],
+ ].each do |should_be_equal, value_1, value_2|
+ test "JSONB properties #{value_1} is#{should_be_equal ? '' : ' not'} equal to #{value_2}" do
+ act_as_user users(:active) do
+ # Set up initial collection
+ c = create_collection 'foo', Encoding::US_ASCII
+ assert c.valid?
+ c.update_attributes!({'properties' => value_1})
+ c.reload
+ assert c.changes.keys.empty?
+ c.properties = value_2
+ if should_be_equal
+ assert c.changes.keys.empty?, "Properties #{value_1.inspect} should be equal to #{value_2.inspect}"
+ else
+ refute c.changes.keys.empty?, "Properties #{value_1.inspect} should not be equal to #{value_2.inspect}"
+ end
+ end
+ end
+ end
+
test "older versions' modified_at indicate when they're created" do
Rails.configuration.Collections.CollectionVersioning = true
Rails.configuration.Collections.PreserveVersionIfIdle = 0
['owner_uuid', 'zzzzz-tpzed-d9tiejq69daie8f', 'zzzzz-tpzed-xurymjxw79nv3jz'],
['replication_desired', 2, 3],
['storage_classes_desired', ['hot'], ['archive']],
- ['is_trashed', true, false],
].each do |attr, first_val, second_val|
test "sync #{attr} with older versions" do
Rails.configuration.Collections.CollectionVersioning = true
SweepTrashedObjects.sweep_now
assert_empty Collection.where(uuid: uuid)
end
+
+ test "create collections with default properties" do
+ Rails.configuration.Collections.DefaultProperties = {
+ 'default_prop1' => {'value' => 'prop1_value'},
+ 'responsible_person_uuid' => {'function' => 'original_owner'}
+ }
+ # Test collection without initial properties
+ act_as_user users(:active) do
+ c = create_collection 'foo', Encoding::US_ASCII
+ assert c.valid?
+ assert_not_empty c.properties
+ assert_equal 'prop1_value', c.properties['default_prop1']
+ assert_equal users(:active).uuid, c.properties['responsible_person_uuid']
+ end
+ # Test collection with default_prop1 property already set
+ act_as_user users(:active) do
+ c = Collection.create(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n",
+ properties: {'default_prop1' => 'custom_value'})
+ assert c.valid?
+ assert_not_empty c.properties
+ assert_equal 'custom_value', c.properties['default_prop1']
+ assert_equal users(:active).uuid, c.properties['responsible_person_uuid']
+ end
+ # Test collection inside a sub project
+ act_as_user users(:active) do
+ c = Collection.create(manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:34:foo.txt\n",
+ owner_uuid: groups(:asubproject).uuid)
+ assert c.valid?
+ assert_not_empty c.properties
+ assert_equal users(:active).uuid, c.properties['responsible_person_uuid']
+ end
+ end
+
+ test "update collection with protected default properties" do
+ Rails.configuration.Collections.DefaultProperties = {
+ 'default_prop1' => {'value' => 'prop1_value', 'protected' => true},
+ }
+ act_as_user users(:active) do
+ c = create_collection 'foo', Encoding::US_ASCII
+ assert c.valid?
+ assert_not_empty c.properties
+ assert_equal 'prop1_value', c.properties['default_prop1']
+ # Add new property
+ c.properties['prop2'] = 'value2'
+ c.save!
+ assert_equal 'value2', c.properties['prop2']
+ # Try to change protected property's value
+ c.properties['default_prop1'] = 'new_value'
+ assert_raises(ArvadosModel::PermissionDeniedError) do
+ c.save!
+ end
+ # Admins are allowed to change protected properties
+ act_as_system_user do
+ c.properties['default_prop1'] = 'new_value'
+ c.save!
+ assert_equal 'new_value', c.properties['default_prop1']
+ end
+ end
+ end
end