Commit e82ad11

mokha <mokha@cisco.com>
2019-01-14 20:05:33
assign attributes with a single complex type.
1 parent 9e0e667
Changed files (3)
lib/scim/kit/v2/attributable.rb
@@ -12,6 +12,16 @@ module Scim
           types.each { |x| attribute(x, resource) }
         end
 
+        def assign_attributes(attributes = {})
+          attributes.each do |key, value|
+            if value.is_a?(Hash)
+              public_send(key.to_s.underscore.to_sym).assign_attributes(value)
+            else
+              public_send(:"#{key.to_s.underscore}=", value)
+            end
+          end
+        end
+
         private
 
         def attribute_for(name)
lib/scim/kit/v2/resource.rb
@@ -35,12 +35,6 @@ module Scim
           end
         end
 
-        def assign_attributes(attributes = {})
-          attributes.each do |key, value|
-            public_send(:"#{key.to_s.underscore}=", value)
-          end
-        end
-
         private
 
         def schema_validations
spec/scim/kit/v2/resource_spec.rb
@@ -376,5 +376,18 @@ RSpec.describe Scim::Kit::V2::Resource do
 
       specify { expect(subject.colours).to match_array(['red', 'green', 'blue']) }
     end
+
+    context "with a single complex attribute" do
+      before do
+        schema.add_attribute(name: :name) do |x|
+          x.add_attribute(name: :given_name)
+          x.add_attribute(name: :family_name)
+        end
+        subject.assign_attributes(name: { givenName: 'Tsuyoshi', familyName: 'Garrett' })
+      end
+
+      specify { expect(subject.name.given_name).to eql('Tsuyoshi') }
+      specify { expect(subject.name.family_name).to eql('Garrett') }
+    end
   end
 end