Commit cdb0a6d

mokha <mokha@cisco.com>
2018-01-22 18:48:51
get all tests passing.
1 parent 2a02023
lib/scim/shady/metadata.rb
@@ -1,11 +1,23 @@
 module Scim
   module Shady
-    module Metadata
+    class Metadata
+      def initialize(hash)
+        @hash = hash
+      end
+
       def created
+        created_at
+      end
+
+      def created_at
         DateTime.parse(to_h['meta']['created'])
       end
 
       def last_modified
+        updated_at
+      end
+
+      def updated_at
         DateTime.parse(to_h['meta']['lastModified'])
       end
 
@@ -16,6 +28,18 @@ module Scim
       def location
         to_h['meta']['location']
       end
+
+      def resource_type
+        to_h['meta']['resourceType']
+      end
+
+      def user?
+        resource_type == 'User'
+      end
+
+      def to_h
+        @hash
+      end
     end
   end
 end
lib/scim/shady/resource.rb
@@ -1,12 +1,14 @@
 module Scim
   module Shady
     class Resource
-      include Metadata
-
       def initialize(json)
         @json = json
       end
 
+      def meta
+        Metadata.new(to_h)
+      end
+
       def id
         to_h['id']
       end
lib/scim/shady/service_provider_configuration.rb
@@ -1,12 +1,14 @@
 module Scim
   module Shady
     class ServiceProviderConfiguration
-      include Metadata
-
       def initialize(json)
         @json = json
       end
 
+      def meta
+        Metadata.new(to_h)
+      end
+
       def documentation_uri
         to_h['documentationUri']
       end
lib/scim/shady/user.rb
@@ -214,8 +214,6 @@ module Scim
         to_h['x509Certificates'].map { |x| X509Certificate.new(x) }
       end
 
-      def meta
-      end
 
       class << self
         def build
spec/scim/builders/service_provider_configuration_spec.rb
@@ -88,10 +88,10 @@ RSpec.describe Scim::Shady::Builders::ServiceProviderConfiguration do
 
       result = subject.build
 
-      expect(result.location).to eql(subject.location)
-      expect(result.created).to eql(DateTime.parse(subject.created_at.iso8601))
-      expect(result.last_modified).to eql(DateTime.parse(subject.updated_at.iso8601))
-      expect(result.version).to eql(subject.version)
+      expect(result.meta.location).to eql(subject.location)
+      expect(result.meta.created).to eql(DateTime.parse(subject.created_at.iso8601))
+      expect(result.meta.last_modified).to eql(DateTime.parse(subject.updated_at.iso8601))
+      expect(result.meta.version).to eql(subject.version)
     end
   end
 end
spec/scim/builders/user_spec.rb
@@ -23,10 +23,10 @@ RSpec.describe Scim::Shady::Builders::User do
 
       expect(result.id).to eql(id)
       expect(result.username).to eql(username)
-      expect(result.created).to eql(DateTime.parse(created_at.utc.iso8601))
-      expect(result.last_modified).to eql(DateTime.parse(updated_at.utc.iso8601))
-      expect(result.version).to eql(user_version)
-      expect(result.location).to eql(user_url)
+      expect(result.meta.created).to eql(DateTime.parse(created_at.utc.iso8601))
+      expect(result.meta.last_modified).to eql(DateTime.parse(updated_at.utc.iso8601))
+      expect(result.meta.version).to eql(user_version)
+      expect(result.meta.location).to eql(user_url)
     end
 
     it 'builds a full representation' do
@@ -95,7 +95,7 @@ RSpec.describe Scim::Shady::Builders::User do
       subject.meta do |x|
         x.created_at = created_at
         x.updated_at = updated_at
-        x.version = "a330bc54f0671c9"
+        x.version = "W\/\"a330bc54f0671c9\""
         x.location = "https://example.com/v2/Users/2819c223-7f76-453a-919d-413861904646"
       end
       result = subject.build
spec/scim/user_spec.rb
@@ -73,10 +73,10 @@ RSpec.describe Scim::Shady::User do
 
       expect(subject.id).to eql(id)
       expect(subject.username).to eql(username)
-      expect(subject.created.iso8601).to eql(created_at.iso8601)
-      expect(subject.last_modified.iso8601).to eql(updated_at.iso8601)
-      expect(subject.version).to eql(user_version)
-      expect(subject.location).to eql(user_url)
+      expect(subject.meta.created.iso8601).to eql(created_at.iso8601)
+      expect(subject.meta.last_modified.iso8601).to eql(updated_at.iso8601)
+      expect(subject.meta.version).to eql(user_version)
+      expect(subject.meta.location).to eql(user_url)
     end
   end
 end