Comparing changes

v0.2.18 v0.3.0
3 commits 3 files changed

Commits

a72e50e bump version. mo 2017-12-24 23:50:18
88ceddd implement each on registry mo 2017-12-24 23:49:17
a901f1d fix link to example. mo 2017-12-24 05:25:25
lib/saml/kit/default_registry.rb
@@ -27,8 +27,10 @@ module Saml
     #     configuration.logger = Rails.logger
     #   end
     #
-    # {include:file:spec/saml/default_registry.rb}
+    # {include:file:spec/saml/default_registry_spec.rb}
     class DefaultRegistry
+      include Enumerable
+
       def initialize(items = {})
         @items = items
       end
@@ -58,6 +60,13 @@ module Saml
         @items[entity_id]
       end
 
+      # Yields each registered [Saml::Kit::Metadata] to the block.
+      def each
+        @items.each do |key, value|
+          yield value
+        end
+      end
+
       class HttpApi # :nodoc:
         def initialize(url, verify_ssl: true)
           @uri = URI.parse(url)
lib/saml/kit/version.rb
@@ -1,5 +1,5 @@
 module Saml
   module Kit
-    VERSION = "0.2.18"
+    VERSION = "0.3.0"
   end
 end
spec/saml/default_registry_spec.rb
@@ -74,4 +74,20 @@ RSpec.describe Saml::Kit::DefaultRegistry do
       expect(result).to be_instance_of(Saml::Kit::CompositeMetadata)
     end
   end
+
+  describe "#each" do
+    it 'yields each registered metadata' do
+      idp = Saml::Kit::IdentityProviderMetadata.build do |config|
+        config.entity_id = "idp"
+      end
+      sp = Saml::Kit::ServiceProviderMetadata.build do |config|
+        config.entity_id = "sp"
+      end
+
+      subject.register(idp)
+      subject.register(sp)
+
+      expect(subject.map(&:to_xml)).to match_array([idp.to_xml, sp.to_xml])
+    end
+  end
 end