Commit 0a97f32

mo <mo.khan@gmail.com>
2019-01-04 23:48:59
add bulk support
1 parent 2d40104
lib/scim/kit/v2/templates/service_provider_configuration.json.jbuilder
@@ -7,7 +7,7 @@ json.patch do
   render patch, json: json
 end
 json.bulk do
-  json.supported false
+  render bulk, json: json
 end
 json.filter do
   json.supported false
lib/scim/kit/v2/templates/supportable.json.jbuilder
@@ -1,3 +1,8 @@
 # frozen_string_literal: true
 
+json.key_format! camelize: :lower
 json.supported supported
+@custom_attributes.each do |key, value|
+  json.set! key, value
+end
+
lib/scim/kit/v2/service_provider_configuration.rb
@@ -11,6 +11,7 @@ module Scim
         attr_accessor :created, :last_modified, :version
         attr_reader :authentication_schemes
         attr_reader :etag, :sort, :change_password, :patch
+        attr_reader :bulk
 
         def initialize(location:)
           @location = location
@@ -20,6 +21,7 @@ module Scim
           @sort = Supportable.new
           @change_password = Supportable.new
           @patch = Supportable.new
+          @bulk = Supportable.new(:max_operations, :max_payload_size)
         end
 
         def add_authentication(type)
lib/scim/kit/v2/supportable.rb
@@ -8,9 +8,19 @@ module Scim
 
         attr_accessor :supported
 
-        def initialize
+        def initialize(*custom_attributes)
+          @custom_attributes = Hash[custom_attributes.map { |x| [x, nil] }]
           @supported = false
         end
+
+        def method_missing(method, *args)
+          target = method.to_s.gsub(/=/, '').to_sym
+          if @custom_attributes.key?(target)
+            @custom_attributes[target] = args[0]
+          else
+            super
+          end
+        end
       end
     end
   end
spec/scim/kit/v2/service_provider_configuration_spec.rb
@@ -92,5 +92,17 @@ RSpec.describe Scim::Kit::V2::ServiceProviderConfiguration do
 
       specify { expect(result[:patch][:supported]).to be(true) }
     end
+
+    context "with bulk support" do
+      before do
+        subject.bulk.supported = true
+        subject.bulk.max_operations = 1000
+        subject.bulk.max_payload_size = 1048576
+      end
+
+      specify { expect(result[:bulk][:supported]).to be(true) }
+      specify { expect(result[:bulk][:maxOperations]).to eql(1000) }
+      specify { expect(result[:bulk][:maxPayloadSize]).to eql(1048576) }
+    end
   end
 end