Commit b227074

mo <mo@mokhan.ca>
2017-11-29 21:12:19
add build api.
1 parent 89a5b29
Changed files (2)
lib/saml/kit/builders/service_provider_metadata.rb
@@ -66,6 +66,12 @@ module Saml
           ServiceProviderMetadata.new(to_xml)
         end
 
+        def self.build
+          builder = new
+          yield builder
+          builder.build
+        end
+
         private
 
         def entity_descriptor_options
spec/saml/builders/service_provider_metadata_spec.rb
@@ -36,4 +36,17 @@ RSpec.describe Saml::Kit::ServiceProviderMetadata::Builder do
       Saml::Kit.configuration.stripped_encryption_certificate,
     ])
   end
+
+  describe ".build" do
+    it 'provides a nice API for building metadata' do
+      result = described_class.build do |builder|
+        builder.entity_id = entity_id
+        builder.add_assertion_consumer_service(acs_url, binding: :http_post)
+      end
+
+      expect(result).to be_instance_of(Saml::Kit::ServiceProviderMetadata)
+      expect(result.entity_id).to eql(entity_id)
+      expect(result.assertion_consumer_service_for(binding: :http_post).location).to eql(acs_url)
+    end
+  end
 end