+ assert_equal 'zzzzz-j7d0g-rew6elm53kancon', resp['owner_uuid']
+ end
+
+ test "create fails with duplicate name" do
+ permit_unsigned_manifests
+ authorize_with :admin
+ manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
+ post :create, {
+ collection: {
+ owner_uuid: 'zzzzz-tpzed-000000000000000',
+ manifest_text: manifest_text,
+ portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
+ name: "foo_file"
+ }
+ }
+ assert_response 422
+ response_errors = json_response['errors']
+ assert_not_nil response_errors, 'Expected error in response'
+ assert(response_errors.first.include?('duplicate key'),
+ "Expected 'duplicate key' error in #{response_errors.first}")
+ end
+
+ [false, true].each do |unsigned|
+ test "create with duplicate name, ensure_unique_name, unsigned=#{unsigned}" do
+ permit_unsigned_manifests unsigned
+ authorize_with :active
+ manifest_text = ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:0:foo.txt\n"
+ if !unsigned
+ manifest_text = Collection.sign_manifest manifest_text, api_token(:active)
+ end
+ post :create, {
+ collection: {
+ owner_uuid: users(:active).uuid,
+ manifest_text: manifest_text,
+ name: "owned_by_active"
+ },
+ ensure_unique_name: true
+ }
+ assert_response :success
+ assert_equal 'owned_by_active (2)', json_response['name']
+ end