Commit 167c05b

mo <mo.khan@gmail.com>
2019-02-03 21:41:29
fix some linter errors
1 parent 8d9b5fe
lib/scim/kit/v2/attribute.rb
@@ -14,9 +14,11 @@ module Scim
 
         validate :presence_of_value, if: proc { |x| x._type.required }
         validate :inclusion_of_value, if: proc { |x| x._type.canonical_values }
-        validate :validate_type, unless: proc { |x| x._type.complex? }
-        validate :validate_complex, if: proc { |x| x._type.complex? }
-        validate :validate_multiple, if: proc { |x| x._type.multi_valued && !x._type.complex? }
+        validate :validate_type, unless: proc { |x| x.complex? }
+        validate :validate_complex, if: proc { |x| x.complex? }
+        validate :multiple, if: proc { |x| x.multi_valued && !x.complex? }
+
+        delegate :complex?, :multi_valued, to: :_type
 
         def initialize(resource:, type:, value: nil)
           @_type = type
@@ -78,14 +80,15 @@ module Scim
         def validate_complex
           if _type.multi_valued
             each_value do |hash|
-              validated_attributes = hash.map do |key, value|
+              validated = hash.map do |key, value|
                 attribute = attribute_for(key)
                 attribute._assign(value)
                 errors.merge!(attribute.errors) unless attribute.valid?
 
                 key.to_sym
               end
-              (map { |x| x._type.name.to_sym } - validated_attributes).each do |key|
+              not_validated = map { |x| x._type.name.to_sym } - validated
+              not_validated.each do |key|
                 attribute = attribute_for(key)
                 attribute._assign(hash[key])
                 errors.merge!(attribute.errors) unless attribute.valid?
@@ -102,7 +105,7 @@ module Scim
           Array(_value).each(&block)
         end
 
-        def validate_multiple
+        def multiple
           return unless _value.respond_to?(:to_a)
 
           duped_type = _type.dup
lib/scim/kit/v2/unknown_attribute.rb
@@ -3,6 +3,7 @@
 module Scim
   module Kit
     module V2
+      # Represents an Unknown/Unrecognized Attribute
       class UnknownAttribute
         include ::ActiveModel::Validations
         validate :unknown
lib/scim/kit.rb
@@ -15,6 +15,7 @@ require 'scim/kit/v2'
 require 'scim/kit/version'
 
 module Scim
+  # @api
   module Kit
     class Error < StandardError; end
     class UnknownAttributeError < Error; end
spec/scim/kit/v2/resource_spec.rb
@@ -147,16 +147,24 @@ RSpec.describe Scim::Kit::V2::Resource do
     specify { expect(subject.emails).to match_array([{ value: email, primary: true }, { value: other_email, primary: false }]) }
     specify { expect(subject.as_json[:emails]).to match_array([{ value: email, primary: true }, { value: other_email, primary: false }]) }
 
-    specify do
-      subject.emails = [{ value: email, primary: 'q' }]
-      expect(subject).not_to be_valid
-      expect(subject.errors[:primary]).to be_present
+    context 'when one attribute has an invalid type' do
+      before do
+        subject.emails = [{ value: email, primary: 'q' }]
+        subject.valid?
+      end
+
+      specify { expect(subject).not_to be_valid }
+      specify { expect(subject.errors[:primary]).to be_present }
     end
 
-    specify do
-      subject.emails = [{ primary: true }]
-      expect(subject).not_to be_valid
-      expect(subject.errors[:value]).to be_present
+    context 'when a required attribute is missing' do
+      before do
+        subject.emails = [{ primary: true }]
+        subject.valid?
+      end
+
+      specify { expect(subject).not_to be_valid }
+      specify { expect(subject.errors[:value]).to be_present }
     end
   end
 
@@ -483,18 +491,16 @@ RSpec.describe Scim::Kit::V2::Resource do
           x.add_attribute(name: :primary, type: :boolean)
         end
         subject.assign_attributes(schemas: schemas.map(&:id), emails: [
-                                    { value: email, primary: true },
-                                    { value: other_email, primary: false }
-                                  ])
+          { value: email, primary: true },
+          { value: other_email, primary: false }
+        ])
       end
 
       specify do
-        expect(subject.emails).to match_array(
-          [
-            { value: email, primary: true },
-            { value: other_email, primary: false }
-          ]
-        )
+        expect(subject.emails).to match_array([
+          { value: email, primary: true },
+          { value: other_email, primary: false }
+        ])
       end
 
       specify { expect(subject.emails[0][:value]).to eql(email) }
.rubocop.yml
@@ -9,6 +9,9 @@ AllCops:
     - 'vendor/**/*'
   TargetRubyVersion: 2.5
 
+Layout/IndentArray:
+  EnforcedStyle: consistent
+
 Metrics/BlockLength:
   Exclude:
     - '*.gemspec'
@@ -24,3 +27,6 @@ Naming/FileName:
 
 RSpec/NamedSubject:
   Enabled: false
+
+RSpec/NestedGroups:
+  Max: 4