diff options
| author | mo khan <mo@mokhan.ca> | 2022-12-12 10:04:16 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2022-12-12 10:04:16 -0700 |
| commit | dee6ab41b3412ff9c00c010cd0a89d337fafc614 (patch) | |
| tree | 096dded8256f0fddf8fa68cad7f0ca7f7d55d59a | |
| parent | 2323a94966475ff54c7b892fa5428d9f5916a698 (diff) | |
| parent | 8fbcb1eaa7fa2ae0d25d76e1b9f19334e9236336 (diff) | |
Merge https://github.com/xlgmokha/scim-kit/pull/60v0.7.1
| -rw-r--r-- | CHANGELOG.md | 10 | ||||
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | lib/scim/kit/v2/attributable.rb | 13 | ||||
| -rw-r--r-- | lib/scim/kit/v2/attribute_type.rb | 9 | ||||
| -rw-r--r-- | lib/scim/kit/v2/schema.rb | 2 | ||||
| -rw-r--r-- | lib/scim/kit/v2/templates/resource.json.jbuilder | 3 | ||||
| -rw-r--r-- | lib/scim/kit/version.rb | 2 | ||||
| -rw-r--r-- | spec/scim/kit/v2/resource_spec.rb | 31 |
8 files changed, 48 insertions, 24 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d779a5..0275e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -Version 0.7.0 +Version 0.7.1 # Changelog All notable changes to this project will be documented in this file. @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.7.1] - 2022-12-12 +### Fixed +- Add support for duplicate attribute names + ## [0.7.0] - 2022-09-28 ### Added - Add constant for 'urn:ietf:params:scim:api:messages:2.0:BulkRequest' [RFC-7644](https://www.rfc-editor.org/rfc/rfc7644.html#section-3.7) @@ -15,7 +19,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add constant for 'urn:ietf:params:scim:api:messages:2.0:PatchOp' [RFC-7644](https://www.rfc-editor.org/rfc/rfc7644.html#section-3.5.2) - Add constant for 'urn:ietf:params:scim:schemas:core:2.0:Schema' [RFC-7643](https://www.rfc-editor.org/rfc/rfc7643.html#section-7) - ## [0.6.0] - 2022-05-23 ### Added - Add support for Ruby 3.1 @@ -82,7 +85,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - \_assign does not coerce values by default. - errors are merged together instead of overwritten during attribute validation. -[Unreleased]: https://github.com/xlgmokha/scim-kit/compare/v0.7.0...HEAD +[Unreleased]: https://github.com/xlgmokha/scim-kit/compare/v0.7.1...HEAD +[0.7.1]: https://github.com/xlgmokha/scim-kit/compare/v0.7.0...v0.7.1 [0.7.0]: https://github.com/xlgmokha/scim-kit/compare/v0.6.0...v0.7.0 [0.6.0]: https://github.com/xlgmokha/scim-kit/compare/v0.5.3...v0.6.0 [0.5.3]: https://github.com/xlgmokha/scim-kit/compare/v0.5.2...v0.5.3 diff --git a/Gemfile.lock b/Gemfile.lock index 0b6184c..47b7fee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - scim-kit (0.7.0) + scim-kit (0.7.1) activemodel (>= 6.1, < 8.0) net-hippie (~> 1.0) parslet (~> 2.0) diff --git a/lib/scim/kit/v2/attributable.rb b/lib/scim/kit/v2/attributable.rb index 8584962..21d6431 100644 --- a/lib/scim/kit/v2/attributable.rb +++ b/lib/scim/kit/v2/attributable.rb @@ -38,7 +38,9 @@ module Scim # @param name [String] the name of the attribute to return # @return [Scim::Kit::V2::Attribute] the attribute or {Scim::Kit::V2::UnknownAttribute} def attribute_for(name) - dynamic_attributes[name.to_s.underscore] || UnknownAttribute.new(name) + dynamic_attributes[name.to_s.underscore] || + dynamic_attributes[name] || + UnknownAttribute.new(name) end # Returns the value associated with the attribute name @@ -86,11 +88,10 @@ module Scim end def attribute(type, resource) - dynamic_attributes[type.name] = Attribute.new( - type: type, - resource: resource - ) - extend(create_module_for(type)) + previously_defined = dynamic_attributes.key?(type.name) + dynamic_attributes[previously_defined ? type.fully_qualified_name : type.name] = + Attribute.new(type: type, resource: resource) + extend(create_module_for(type)) unless previously_defined end end end diff --git a/lib/scim/kit/v2/attribute_type.rb b/lib/scim/kit/v2/attribute_type.rb index a389281..b27a3a0 100644 --- a/lib/scim/kit/v2/attribute_type.rb +++ b/lib/scim/kit/v2/attribute_type.rb @@ -8,16 +8,15 @@ module Scim include Templatable attr_accessor :canonical_values, :case_exact, :description attr_accessor :multi_valued, :required - attr_reader :mutability, :name, :type, :attributes + attr_reader :mutability, :name, :fully_qualified_name, :type, :attributes attr_reader :reference_types, :returned, :uniqueness - def initialize(name:, type: :string) + def initialize(name:, type: :string, schema: nil) @name = name.to_s.underscore + @fully_qualified_name = [schema&.id, @name].compact.join('#') @type = DATATYPES[type.to_sym] ? type.to_sym : (raise TYPE_ERROR) @description = name.to_s.camelize(:lower) - @multi_valued = false - @required = false - @case_exact = false + @multi_valued = @required = @case_exact = false @mutability = Mutability::READ_WRITE @returned = Returned::DEFAULT @uniqueness = Uniqueness::NONE diff --git a/lib/scim/kit/v2/schema.rb b/lib/scim/kit/v2/schema.rb index 0cd6365..64576c4 100644 --- a/lib/scim/kit/v2/schema.rb +++ b/lib/scim/kit/v2/schema.rb @@ -21,7 +21,7 @@ module Scim end def add_attribute(name:, type: :string) - attribute = AttributeType.new(name: name, type: type) + attribute = AttributeType.new(name: name, type: type, schema: self) yield attribute if block_given? attributes << attribute end diff --git a/lib/scim/kit/v2/templates/resource.json.jbuilder b/lib/scim/kit/v2/templates/resource.json.jbuilder index 9545b26..3f8dfde 100644 --- a/lib/scim/kit/v2/templates/resource.json.jbuilder +++ b/lib/scim/kit/v2/templates/resource.json.jbuilder @@ -18,7 +18,8 @@ schemas.each do |schema| else json.set! schema.id do schema.attributes.each do |type| - attribute = dynamic_attributes[type.name] + attribute = dynamic_attributes[type.fully_qualified_name] || + dynamic_attributes[type.name] render attribute, json: json end end diff --git a/lib/scim/kit/version.rb b/lib/scim/kit/version.rb index 5ae9219..ba92e60 100644 --- a/lib/scim/kit/version.rb +++ b/lib/scim/kit/version.rb @@ -2,6 +2,6 @@ module Scim module Kit - VERSION = '0.7.0' + VERSION = '0.7.1' end end diff --git a/spec/scim/kit/v2/resource_spec.rb b/spec/scim/kit/v2/resource_spec.rb index 10d1bcc..d4bbdbf 100644 --- a/spec/scim/kit/v2/resource_spec.rb +++ b/spec/scim/kit/v2/resource_spec.rb @@ -176,14 +176,33 @@ RSpec.describe Scim::Kit::V2::Resource do before do schema.add_attribute(name: :country) extension.add_attribute(name: :province) - subject.country = 'canada' - subject.province = 'alberta' end - 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') } + context 'without any collisions' do + before do + subject.country = 'canada' + subject.province = 'alberta' + end + + 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 + + context 'with an extension attribute with the same name as a core attribute' do + before do + extension.add_attribute(name: :country) + + subject.country = 'canada' + subject.write_attribute("#{extension_id}#country", 'usa') + end + + specify { expect(subject.country).to eql('canada') } + specify { expect(subject.read_attribute("#{extension_id}#country")).to eql('usa') } + specify { expect(subject.as_json[:country]).to eql('canada') } + specify { expect(subject.as_json[extension_id][:country]).to eql('usa') } + end end describe '#valid?' do |
