Commit 1fcc324

mokha <mokha@cisco.com>
2019-01-13 04:12:42
do not overwrite dynamic_attributes instance variable
1 parent e6a3cbd
Changed files (3)
lib/scim/kit/v2/attributable.rb
@@ -8,7 +8,7 @@ module Scim
         attr_reader :dynamic_attributes
 
         def define_attributes_for(resource, types)
-          @dynamic_attributes = {}.with_indifferent_access
+          @dynamic_attributes ||= {}.with_indifferent_access
           types.each { |x| attribute(x, resource) }
         end
 
@@ -26,7 +26,8 @@ module Scim
         end
 
         def write_attribute(name, value)
-          attribute_for(name)._value = value
+          attribute = attribute_for(name)
+          attribute._value = value
         end
 
         def create_module_for(type)
spec/scim/kit/v2/attribute_spec.rb
@@ -278,6 +278,12 @@ RSpec.describe Scim::Kit::V2::Attribute do
 
       specify { expect(subject).not_to be_renderable }
     end
+
+    context 'when returned type is `never`' do
+      before { type.returned = :never }
+
+      xspecify { expect(subject).not_to be_renderable }
+    end
   end
 
   context 'when the resource is in client mode' do
spec/scim/kit/v2/resource_spec.rb
@@ -109,12 +109,16 @@ RSpec.describe Scim::Kit::V2::Resource do
     let(:extension_id) { 'urn:ietf:params:scim:schemas:extension:enterprise:2.0:User' }
 
     before do
-      extension.add_attribute(name: :department)
-      subject.department = 'voltron'
+      schema.add_attribute(name: :country)
+      extension.add_attribute(name: :province)
+      subject.country = 'canada'
+      subject.province = 'alberta'
     end
 
-    specify { expect(subject.department).to eql('voltron') }
-    specify { expect(subject.as_json[extension_id][:department]).to eql('voltron') }
+    specify { expect(subject.country).to eql('canada') }
+    specify { expect(subject.province).to eql('alberta') }
+    specify { expect(subject.as_json[:country]).to eql('canada') }
+    specify { expect(subject.as_json[extension_id][:province]).to eql('alberta') }
   end
 
   describe '#valid?' do