@@ -296,5 +296,68 @@ module LaunchDarkly
296296 end
297297 end
298298 end
299+
300+ describe "equality comparisons" do
301+ it "single kind contexts are equal" do
302+ original_context = subject . create (
303+ { key : 'context-key' , kind : 'user' , name : 'Example name' , groups : [ 'test' , 'it' , 'here' ] , address : { street : '123 Easy St' , city : 'Every Town' } ,
304+ _meta : { privateAttributes : [ 'name' , 'out of order attribute' ] }
305+ } )
306+ duplicate_context = subject . create (
307+ { key : 'context-key' , kind : 'user' , name : 'Example name' , groups : [ 'test' , 'it' , 'here' ] , address : { street : '123 Easy St' , city : 'Every Town' } ,
308+ _meta : { privateAttributes : [ 'out of order attribute' , 'name' ] }
309+ } )
310+ expect ( original_context ) . to eq ( duplicate_context )
311+ end
312+
313+ it "multi kind contexts are equal" do
314+ org_context = subject . create ( { key : 'org-key' , kind : 'org' } )
315+ user_context = subject . create ( { key : 'user-key' , kind : 'user' } )
316+ device_context = subject . create ( { key : 'device-key' , kind : 'device' } )
317+
318+ original_context = subject . create_multi ( [ org_context , user_context ] )
319+ duplicate_context = subject . create_multi ( [ user_context , org_context ] )
320+
321+ expect ( original_context ) . to eq ( duplicate_context )
322+
323+ superset_context = subject . create_multi ( [ org_context , user_context , device_context ] )
324+ expect ( superset_context ) . not_to eq ( duplicate_context )
325+ end
326+
327+ it "mixed size contexts are not equal" do
328+ org_context = subject . create ( { key : 'org-key' , kind : 'org' } )
329+ user_context = subject . create ( { key : 'user-key' , kind : 'user' } )
330+
331+ flattened_multi = subject . create_multi ( [ org_context ] )
332+
333+ expect ( flattened_multi ) . to eq ( org_context )
334+
335+ multi = subject . create_multi ( [ org_context , user_context ] )
336+ expect ( multi ) . not_to eq ( org_context )
337+ expect ( multi ) . not_to eq ( user_context )
338+ end
339+
340+ it "failed contexts can be equal" do
341+ invalid_hash = subject . create ( true )
342+ invalid_kind = subject . create ( { kind : 'this is not valid' } )
343+ invalid_key = subject . create ( { key : nil } )
344+ invalid_name = subject . create ( { key : 'user-key' , name : true } )
345+ invalid_anonymous = subject . create ( { key : 'user-key' , anonymous : 'this is no boolean' } )
346+ invalid_private_attributes = subject . create ( { key : 'user-key' , _meta : { privateAttributes : 'this is no array' } } )
347+
348+ expect ( invalid_hash ) . not_to eq ( invalid_kind )
349+ expect ( invalid_hash ) . not_to eq ( invalid_key )
350+ expect ( invalid_hash ) . not_to eq ( invalid_name )
351+ expect ( invalid_hash ) . not_to eq ( invalid_anonymous )
352+ expect ( invalid_hash ) . not_to eq ( invalid_private_attributes )
353+
354+ expect ( invalid_hash ) . to eq ( subject . create ( true ) )
355+ expect ( invalid_kind ) . to eq ( subject . create ( { kind : 'this is not valid' } ) )
356+ expect ( invalid_key ) . to eq ( subject . create ( { key : nil } ) )
357+ expect ( invalid_name ) . to eq ( subject . create ( { key : 'user-key' , name : true } ) )
358+ expect ( invalid_anonymous ) . to eq ( subject . create ( { key : 'user-key' , anonymous : 'this is no boolean' } ) )
359+ expect ( invalid_private_attributes ) . to eq ( subject . create ( { key : 'user-key' , _meta : { privateAttributes : 'this is no array' } } ) )
360+ end
361+ end
299362 end
300363end
0 commit comments