Commit 90899ba

mo <mo.khan@gmail.com>
2019-01-08 00:03:16
add schemas
1 parent 95ec500
Changed files (3)
lib
spec
scim
lib/scim/kit/v2/templates/resource.json.jbuilder
@@ -1,6 +1,7 @@
 # frozen_string_literal: true
 
 json.key_format! camelize: :lower
+json.schemas schemas.map(&:id)
 json.id id
 json.external_id external_id
 json.meta do
lib/scim/kit/v2/resource.rb
@@ -10,9 +10,11 @@ module Scim
 
         attr_accessor :id, :external_id
         attr_reader :meta
+        attr_reader :schemas
 
         def initialize(schema:, location:)
-          @meta = Meta.new(schema.id, location)
+          @meta = Meta.new(schema.name, location)
+          @schemas = [schema]
           define_attributes_for(schema.attributes)
         end
       end
spec/scim/kit/v2/resource_spec.rb
@@ -3,7 +3,7 @@
 RSpec.describe Scim::Kit::V2::Resource do
   subject { described_class.new(schema: schema, location: resource_location) }
 
-  let(:schema) { Scim::Kit::V2::Schema.new(id: 'User', name: 'User', location: FFaker::Internet.uri('https')) }
+  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 'with common attributes' do
@@ -30,6 +30,7 @@ RSpec.describe Scim::Kit::V2::Resource do
     specify { expect(subject.meta.version).to eql(version) }
 
     describe '#as_json' do
+      specify { expect(subject.as_json[:schemas]).to match_array([schema.id]) }
       specify { expect(subject.as_json[:id]).to eql(id) }
       specify { expect(subject.as_json[:externalId]).to eql(external_id) }
       specify { expect(subject.as_json[:meta][:resourceType]).to eql('User') }