Commit 9cba162

mo <mo.khan@gmail.com>
2018-12-24 20:08:03
start to define the attribute builder api.
1 parent 4640818
Changed files (2)
lib
scim
spec
scim
lib/scim/kit/v2/schema.rb
@@ -17,6 +17,11 @@ module Scim
           @id = id
           @name = name
           @location = location
+          @attributes = []
+        end
+
+        def add_attribute(name:)
+          @attributes << AttributeType.new(name: name)
         end
 
         def to_json
@@ -31,7 +36,8 @@ module Scim
             meta: {
               location: location,
               resourceType: 'Schema'
-            }
+            },
+            attributes: @attributes.map(&:to_h)
           }
         end
       end
spec/scim/kit/v2/schema_spec.rb
@@ -18,4 +18,20 @@ RSpec.describe Scim::Kit::V2::Schema do
   specify { expect(result[:description]).to eql(description) }
   specify { expect(result[:meta][:resourceType]).to eql('Schema') }
   specify { expect(result[:meta][:location]).to eql(location) }
+
+  context "with a single simple attribute" do
+    before do
+      subject.add_attribute(name: 'displayName')
+    end
+
+    specify { expect(result[:attributes][0][:name]).to eql('displayName') }
+    specify { expect(result[:attributes][0][:type]).to eql('string') }
+    specify { expect(result[:attributes][0][:multiValued]).to be(false) }
+    specify { expect(result[:attributes][0][:description]).to eql('') }
+    specify { expect(result[:attributes][0][:required]).to be(false) }
+    specify { expect(result[:attributes][0][:caseExact]).to be(false) }
+    specify { expect(result[:attributes][0][:mutability]).to eql('readWrite') }
+    specify { expect(result[:attributes][0][:returned]).to eql('default') }
+    specify { expect(result[:attributes][0][:uniqueness]).to eql('none') }
+  end
 end