Skip to content

Commit 2df5279

Browse files
committed
Merge branch '6.0/add-json-serializer-sort-id-tiebreak' into 6.0-trunk
2 parents 939874c + c791e44 commit 2df5279

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

lib/RT/Migrate/Serializer/JSON.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ sub _CanonicalizeManyToMany {
275275
= grep defined,
276276
map &$canonicalize_object,
277277
sort { ($a->{SortOrder}||0) <=> ($b->{SortOrder}||0)
278-
|| ($object_sorter ? $a->{$object_sorter} cmp $b->{$object_sorter} : 0) }
278+
|| ($object_sorter ? $a->{$object_sorter} cmp $b->{$object_sorter} : 0)
279+
|| ($a->{id}||0) <=> ($b->{id}||0) }
279280
@{ $primary->{$primary_key} || [] };
280281

281282
if ($sort_uniq) {

t/api/initialdata_copy_queue.t

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@ my $custom_field = RT::Test->load_or_create_custom_field(
4646
);
4747
ok( $custom_field->SetDefaultValues( Object => $queue, Values => 'review, merge' ) );
4848

49+
my $select_cf = RT::CustomField->new( RT->SystemUser );
50+
ok(
51+
$select_cf->Create(
52+
Name => 'Priority Level',
53+
Type => 'Select',
54+
LookupType => 'RT::Queue-RT::Ticket',
55+
MaxValues => 0,
56+
),
57+
'Created Select CF'
58+
);
59+
60+
# Add values with duplicate SortOrder and Name (but different Category) to exercise id tiebreaker
61+
for my $val (
62+
{ Name => 'High', SortOrder => 10, Category => 'External' },
63+
{ Name => 'High', SortOrder => 10, Category => 'Internal' },
64+
{ Name => 'Medium', SortOrder => 5, Category => 'External' },
65+
{ Name => 'Medium', SortOrder => 5, Category => 'Internal' },
66+
{ Name => 'Low', SortOrder => 5, Category => 'Internal' },
67+
) {
68+
my ( $vid, $vmsg ) = $select_cf->AddValue( %$val );
69+
ok( $vid, "Added CF value $val->{Name}: $vmsg" );
70+
}
71+
72+
my $select_ocf = RT::ObjectCustomField->new( RT->SystemUser );
73+
ok( $select_ocf->Create( CustomField => $select_cf->Id, ObjectId => $queue->Id ), 'Applied Select CF to Test queue' );
4974

5075
RT::Test->add_rights(
5176
{ Principal => 'Everyone', Right => 'SeeQueue', Object => RT->System },
@@ -168,6 +193,49 @@ my $expected_changes = JSON::decode_json(<<'EOF');
168193
"Type" : "Freeform"
169194
},
170195
"_Updated" : 1
196+
},
197+
{
198+
"ApplyTo" : [
199+
"Test"
200+
],
201+
"_Original" : {
202+
"ApplyTo" : [],
203+
"Description" : "",
204+
"EntryHint" : "Select multiple values",
205+
"LookupType" : "RT::Queue-RT::Ticket",
206+
"MaxValues" : 0,
207+
"Name" : "Priority Level",
208+
"SortOrder" : 0,
209+
"Type" : "Select",
210+
"Values" : [
211+
{
212+
"Category" : "Internal",
213+
"Name" : "Low",
214+
"SortOrder" : 5
215+
},
216+
{
217+
"Category" : "External",
218+
"Name" : "Medium",
219+
"SortOrder" : 5
220+
},
221+
{
222+
"Category" : "Internal",
223+
"Name" : "Medium",
224+
"SortOrder" : 5
225+
},
226+
{
227+
"Category" : "External",
228+
"Name" : "High",
229+
"SortOrder" : 10
230+
},
231+
{
232+
"Category" : "Internal",
233+
"Name" : "High",
234+
"SortOrder" : 10
235+
}
236+
]
237+
},
238+
"_Updated" : 1
171239
}
172240
],
173241
"CustomRoles" : [
@@ -278,4 +346,28 @@ my $new_changes;
278346

279347
is_deeply( JSON::decode_json($new_changes), JSON::decode_json($changes), 'Generated changes look good' );
280348

349+
diag "Verify repeated dumps produce no false changes";
350+
351+
my $baseline_dir = File::Spec->catdir( $parent_dir, 'baseline' );
352+
ok(
353+
RT::Test->run_singleton_command(
354+
'sbin/rt-dump-initialdata', '--quiet', '--dir', $baseline_dir, '--sync',
355+
),
356+
'Dump baseline initialdata'
357+
);
358+
359+
for my $run ( 1 .. 3 ) {
360+
my $run_dir = File::Spec->catdir( $parent_dir, "run$run" );
361+
ok(
362+
RT::Test->run_singleton_command(
363+
'sbin/rt-dump-initialdata', '--quiet', '--dir', $run_dir, '--sync', '--base',
364+
File::Spec->catfile( $baseline_dir, 'initialdata.json' ),
365+
),
366+
"Dump run $run with --base"
367+
);
368+
369+
my $changes_file = File::Spec->catfile( $run_dir, 'changes.json' );
370+
ok( !-e $changes_file, "Run $run: no changes.json generated (no false changes)" );
371+
}
372+
281373
done_testing;

0 commit comments

Comments
 (0)