Commit b2042d0

mokha <mokha@cisco.com>
2019-01-18 17:51:03
when the list of schemas is empty
1 parent ecb79b7
Changed files (3)
lib
spec
scim
lib/scim/kit/v2/meta.rb
@@ -12,7 +12,7 @@ module Scim
         attr_reader :resource_type
 
         def initialize(resource_type, location)
-          @resource_type = resource_type
+          @resource_type = resource_type || 'Unknown'
           @location = location
           @created = @last_modified = Time.now
           @version = @created.to_i
lib/scim/kit/v2/resource.rb
@@ -16,7 +16,7 @@ module Scim
         validate :schema_validations
 
         def initialize(schemas:, location: nil, attributes: {})
-          @meta = Meta.new(schemas[0].name, location)
+          @meta = Meta.new(schemas[0]&.name, location)
           @meta.disable_timestamps
           @schemas = schemas
           @raw_attributes = attributes
spec/scim/kit/v2/resource_spec.rb
@@ -7,6 +7,13 @@ RSpec.describe Scim::Kit::V2::Resource do
   let(:schema) { Scim::Kit::V2::Schema.new(id: Scim::Kit::V2::Schemas::USER, name: 'User', location: FFaker::Internet.uri('https')) }
   let(:resource_location) { FFaker::Internet.uri('https') }
 
+  context 'when the schemas is empty' do
+    let(:schemas) { [] }
+
+    specify { expect { subject }.not_to raise_error }
+    specify { expect(subject.meta.resource_type).to eql('Unknown') }
+  end
+
   context 'with common attributes' do
     let(:id) { SecureRandom.uuid }
     let(:external_id) { SecureRandom.uuid }