Commit 5fdc32c
Changed files (2)
lib
scim
kit
spec
scim
kit
lib/scim/kit/v2/attribute_type.rb
@@ -5,7 +5,7 @@ module Scim
module V2
# Represents a scim Attribute type
class AttributeType
- VALID = {
+ DATATYPES = {
string: 'string',
boolean: 'boolean',
decimal: 'decimal',
@@ -35,6 +35,8 @@ module Scim
@returned = Returned::DEFAULT
@uniqueness = Uniqueness::NONE
@attributes = []
+
+ raise ArgumentError.new(:type) unless DATATYPES[type]
end
def mutability=(value)
@@ -76,15 +78,19 @@ module Scim
private
def complex?
- type.to_sym == :complex
+ type_is?(:complex)
end
def string?
- type.to_sym == :string
+ type_is?(:string)
end
def reference?
- type.to_sym == :reference
+ type_is?(:reference)
+ end
+
+ def type_is?(expected_type)
+ type.to_sym == expected_type
end
end
end
spec/scim/kit/v2/attribute_type_spec.rb
@@ -1,6 +1,15 @@
# frozen_string_literal: true
RSpec.describe Scim::Kit::V2::AttributeType do
+ specify { expect { described_class.new(name: 'displayName', type: :string) }.not_to raise_error }
+ specify { expect { described_class.new(name: 'primary', type: :boolean) }.not_to raise_error }
+ specify { expect { described_class.new(name: 'salary', type: :decimal) }.not_to raise_error }
+ specify { expect { described_class.new(name: 'age', type: :integer) }.not_to raise_error }
+ specify { expect { described_class.new(name: 'birthdate', type: :datetime) }.not_to raise_error }
+ specify { expect { described_class.new(name: '$ref', type: :reference) }.not_to raise_error }
+ specify { expect { described_class.new(name: 'emails', type: :complex) }.not_to raise_error }
+ specify { expect { described_class.new(name: 'invalid', type: :invalid) }.to raise_error(ArgumentError) }
+
describe 'String Attribute' do
describe 'defaults' do
subject { described_class.new(name: 'displayName') }