[Bps-public-commit] rt-extension-rest2 branch, master, updated. 287f9bac8a4e3679392e07f0121f9a8371832f3a

Shawn Moore shawn at bestpractical.com
Thu Sep 28 10:16:36 EDT 2017


The branch, master has been updated
       via  287f9bac8a4e3679392e07f0121f9a8371832f3a (commit)
       via  24aa7818f1e1bc9c5b0ba1fa1f91c794163f0eda (commit)
      from  54644d5efc09d41d086db7a6569a2824b459bef5 (commit)

Summary of changes:
 lib/RT/Extension/REST2/Resource/Record/Writable.pm |  2 +-
 t/asset-customfields.t                             | 30 ++++++++++------------
 2 files changed, 15 insertions(+), 17 deletions(-)

- Log -----------------------------------------------------------------
commit 24aa7818f1e1bc9c5b0ba1fa1f91c794163f0eda
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Sep 28 14:13:17 2017 +0000

    Remove 4.2.x version tests in 4.4 test files
    
    These were copied from t/ticket-customfields.t, but are not appropriate
    for assets, cored in 4.4

diff --git a/t/asset-customfields.t b/t/asset-customfields.t
index fe6bc8c..254a22d 100644
--- a/t/asset-customfields.t
+++ b/t/asset-customfields.t
@@ -47,11 +47,6 @@ my ($asset_url, $asset_id);
         },
     };
 
-    # 4.2.3 introduced a bug (e092e23) in CFs fixed in 4.2.9 (ab7ea15)
-    delete $payload->{CustomFields}
-        if RT::Handle::cmp_version($RT::VERSION, '4.2.3') >= 0
-        && RT::Handle::cmp_version($RT::VERSION, '4.2.8') <= 0;
-
     # Rights Test - No CreateAsset
     my $res = $mech->post_json("$rest_base_path/asset",
         $payload,
@@ -366,17 +361,10 @@ for my $value (
     modify_multi_ok('replace all', ['replace all added as a value for Multi', 'multiple is no longer a value for custom field Multi', 'new is no longer a value for custom field Multi'], ['replace all'], 'replaced all values');
     modify_multi_ok([], ['replace all is no longer a value for custom field Multi'], [], 'removed all values');
 
-    if (RT::Handle::cmp_version($RT::VERSION, '4.2.5') >= 0) {
-        modify_multi_ok(['foo', 'foo', 'bar'], ['foo added as a value for Multi', undef, 'bar added as a value for Multi'], ['bar', 'foo'], 'multiple values with the same name');
-        modify_multi_ok(['foo', 'bar'], [], ['bar', 'foo'], 'multiple values with the same name');
-        modify_multi_ok(['bar'], ['foo is no longer a value for custom field Multi'], ['bar'], 'multiple values with the same name');
-        modify_multi_ok(['bar', 'bar', 'bar'], [undef, undef], ['bar'], 'multiple values with the same name');
-    } else {
-        modify_multi_ok(['foo', 'foo', 'bar'], ['foo added as a value for Multi', 'foo added as a value for Multi', 'bar added as a value for Multi'], ['bar', 'foo', 'foo'], 'multiple values with the same name');
-        modify_multi_ok(['foo', 'bar'], ['foo is no longer a value for custom field Multi'], ['bar', 'foo'], 'multiple values with the same name');
-        modify_multi_ok(['bar'], ['foo is no longer a value for custom field Multi'], ['bar'], 'multiple values with the same name');
-        modify_multi_ok(['bar', 'bar', 'bar'], ['bar added as a value for Multi', 'bar added as a value for Multi'], ['bar', 'bar', 'bar'], 'multiple values with the same name');
-    }
+    modify_multi_ok(['foo', 'foo', 'bar'], ['foo added as a value for Multi', undef, 'bar added as a value for Multi'], ['bar', 'foo'], 'multiple values with the same name');
+    modify_multi_ok(['foo', 'bar'], [], ['bar', 'foo'], 'multiple values with the same name');
+    modify_multi_ok(['bar'], ['foo is no longer a value for custom field Multi'], ['bar'], 'multiple values with the same name');
+    modify_multi_ok(['bar', 'bar', 'bar'], [undef, undef], ['bar'], 'multiple values with the same name');
 }
 
 done_testing;

commit 287f9bac8a4e3679392e07f0121f9a8371832f3a
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Thu Sep 28 14:16:00 2017 +0000

    RT::Asset->Create handles CFs, so specify them there
    
    This improves error diagnostics for situations such as invalid custom
    field values.

diff --git a/lib/RT/Extension/REST2/Resource/Record/Writable.pm b/lib/RT/Extension/REST2/Resource/Record/Writable.pm
index 3621faf..e0d1128 100644
--- a/lib/RT/Extension/REST2/Resource/Record/Writable.pm
+++ b/lib/RT/Extension/REST2/Resource/Record/Writable.pm
@@ -274,7 +274,7 @@ sub create_record {
     # if a record class handles CFs in ->Create, use it (so it doesn't generate
     # spurious transactions and interfere with default values, etc). Otherwise,
     # add OCFVs after ->Create
-    if ($record->isa('RT::Ticket')) {
+    if ($record->isa('RT::Ticket') || $record->isa('RT::Asset')) {
         if ($cfs) {
             while (my ($id, $value) = each(%$cfs)) {
                 delete $cfs->{id};
diff --git a/t/asset-customfields.t b/t/asset-customfields.t
index 254a22d..a90f2e1 100644
--- a/t/asset-customfields.t
+++ b/t/asset-customfields.t
@@ -53,6 +53,8 @@ my ($asset_url, $asset_id);
         'Authorization' => $auth,
     );
     is($res->code, 403);
+    my $content = $mech->json_response;
+    is($content->{message}, 'Permission Denied', "can't create Asset with custom fields you can't set");
 
     # Rights Test - With CreateAsset
     $user->PrincipalObj->GrantRight( Right => 'CreateAsset' );
@@ -60,6 +62,14 @@ my ($asset_url, $asset_id);
         $payload,
         'Authorization' => $auth,
     );
+    is($res->code, 400);
+
+    delete $payload->{CustomFields};
+
+    $res = $mech->post_json("$rest_base_path/asset",
+        $payload,
+        'Authorization' => $auth,
+    );
     is($res->code, 201);
     ok($asset_url = $res->header('location'));
     ok(($asset_id) = $asset_url =~ qr[/asset/(\d+)]);

-----------------------------------------------------------------------


More information about the Bps-public-commit mailing list