Skip to content

Commit

Permalink
Merge branch 'topic/complex-values-replace'
Browse files Browse the repository at this point in the history
  • Loading branch information
wooly committed Oct 6, 2023
2 parents e684359 + 4a3d837 commit d368362
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/models/scimitar/resources/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,10 @@ def from_patch_backend_apply!(nature:, path:, value:, altering_hash:)

when 'replace'
if path_component == 'root'
altering_hash[path_component].merge!(value)
dot_pathed_value = value.inject({}) do |hsh, (k, v)|
hsh.deep_merge!(dot_path(k.split('.'), v))
end
altering_hash[path_component].deep_merge!(dot_pathed_value)
else
altering_hash[path_component] = value
end
Expand Down Expand Up @@ -1105,6 +1108,13 @@ def all_matching_filter(filter:, within_array:, &block)
end
end

def dot_path(arr, value)
return value if arr.empty?

{}.tap do |hash|
hash[arr.shift] = dot_path(arr, value)
end
end
end # "included do"
end # "module Mixin"
end # "module Resources"
Expand Down
22 changes: 22 additions & 0 deletions spec/models/scimitar/resources/mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,28 @@ def self.scim_queryable_attributes
expect(@instance.username).to eql('1234')
end

it 'which updates nested values using root syntax' do
@instance.update!(first_name: 'Foo', last_name: 'Bar')

path = 'name.givenName'
path = path.upcase if force_upper_case

patch = {
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:PatchOp'],
'Operations' => [
{
'op' => 'replace',
'value' => {
path => 'Baz'
}
}
]
}

@instance.from_scim_patch!(patch_hash: patch)
expect(@instance.first_name).to eql('Baz')
end

it 'which updates nested values' do
@instance.update!(first_name: 'Foo', last_name: 'Bar')

Expand Down

0 comments on commit d368362

Please sign in to comment.