Commit 2593103

mokha <mokha@cisco.com>
2019-01-29 23:24:39
add support for $ref attribute name
1 parent 43109e3
Changed files (2)
lib
scim
spec
scim
lib/scim/kit/v2/attributable.rb
@@ -25,12 +25,6 @@ module Scim
           end
         end
 
-        private
-
-        def attribute_for(name)
-          dynamic_attributes[name.to_s.underscore]
-        end
-
         def read_attribute(name)
           attribute = attribute_for(name)
           return attribute._value if attribute._type.multi_valued
@@ -49,6 +43,12 @@ module Scim
           end
         end
 
+        private
+
+        def attribute_for(name)
+          dynamic_attributes[name.to_s.underscore]
+        end
+
         def create_module_for(type)
           name = type.name.to_sym
           Module.new do
spec/scim/kit/v2/resource_spec.rb
@@ -96,6 +96,17 @@ RSpec.describe Scim::Kit::V2::Resource do
     specify { expect(subject.send(:attribute_for, :type)._type).to be_instance_of(Scim::Kit::V2::AttributeType) }
   end
 
+  context 'with attribute named $ref' do
+    before do
+      schema.add_attribute(name: '$ref')
+      subject.write_attribute('$ref', 'User')
+    end
+
+    specify { expect(subject.read_attribute('$ref')).to eql('User') }
+    specify { expect(subject.as_json['$ref']).to eql('User') }
+    specify { expect(subject.send(:attribute_for, '$ref')._type).to be_instance_of(Scim::Kit::V2::AttributeType) }
+  end
+
   context 'with a complex attribute' do
     before do
       schema.add_attribute(name: 'name') do |x|