Commit d58990c

mo <mo.khan@gmail.com>
2018-12-26 19:39:36
provide a build interface
1 parent 161b5c1
Changed files (2)
lib
scim
spec
scim
lib/scim/kit/v2/schema.rb
@@ -26,6 +26,12 @@ module Scim
           yield attribute if block_given?
           @attributes << attribute
         end
+
+        def self.build(*args)
+          item = new(*args)
+          yield item
+          item
+        end
       end
     end
   end
spec/scim/kit/v2/schema_spec.rb
@@ -104,4 +104,18 @@ RSpec.describe Scim::Kit::V2::Schema do
     specify { expect(result[:attributes][0][:returned]).to eql('default') }
     specify { expect(result[:attributes][0][:uniqueness]).to eql('none') }
   end
+
+  describe '.build' do
+    subject do
+      described_class.build(id: id, name: name, location: location) do |x|
+        x.description = description
+      end
+    end
+
+    specify { expect(result[:id]).to eql(id) }
+    specify { expect(result[:name]).to eql(name) }
+    specify { expect(result[:description]).to eql(description) }
+    specify { expect(result[:meta][:resourceType]).to eql('Schema') }
+    specify { expect(result[:meta][:location]).to eql(location) }
+  end
 end