Commit 6e25b32

mokha <mokha@cisco.com>
2019-01-14 23:04:16
remove id validation and call to_s on schema
1 parent 64f79d6
Changed files (3)
lib/scim/kit/v2/attributable.rb
@@ -14,14 +14,12 @@ module Scim
 
         def assign_attributes(attributes = {})
           attributes.each do |key, value|
-            next if key == :schemas
+            next if key.to_sym == :schemas
 
-            if key.to_s.start_with?('urn:ietf:params:scim:schemas:extension:')
+            if key.to_s.start_with?(Schemas::EXTENSION)
               assign_attributes(value)
-            elsif value.is_a?(Hash)
-              public_send(key.to_s.underscore.to_sym).assign_attributes(value)
             else
-              public_send(:"#{key.to_s.underscore}=", value)
+              write_attribute(key, value)
             end
           end
         end
@@ -29,7 +27,7 @@ module Scim
         private
 
         def attribute_for(name)
-          dynamic_attributes[name]
+          dynamic_attributes[name.to_s.underscore]
         end
 
         def read_attribute(name)
@@ -40,8 +38,11 @@ module Scim
         end
 
         def write_attribute(name, value)
-          attribute = attribute_for(name)
-          attribute._value = value
+          if value.is_a?(Hash)
+            attribute_for(name)&.assign_attributes(value)
+          else
+            attribute_for(name)&._value = value
+          end
         end
 
         def create_module_for(type)
lib/scim/kit/v2/resource.rb
@@ -13,7 +13,6 @@ module Scim
         attr_reader :meta
         attr_reader :schemas
 
-        validates_presence_of :id
         validate :schema_validations
 
         def initialize(schemas:, location: nil)
spec/scim/kit/v2/resource_spec.rb
@@ -147,13 +147,6 @@ RSpec.describe Scim::Kit::V2::Resource do
   end
 
   describe '#valid?' do
-    context 'when invalid' do
-      before { subject.valid? }
-
-      specify { expect(subject).not_to be_valid }
-      specify { expect(subject.errors[:id]).to be_present }
-    end
-
     context 'when valid' do
       before { subject.id = SecureRandom.uuid }
 
@@ -351,7 +344,7 @@ RSpec.describe Scim::Kit::V2::Resource do
 
       before do
         schema.add_attribute(name: 'userName')
-        subject.assign_attributes(schemas: schemas.map(&:id), userName: user_name)
+        subject.assign_attributes('schemas' => schemas.map(&:id), userName: user_name)
       end
 
       specify { expect(subject.user_name).to eql(user_name) }