Commit 7bdb077
Changed files (6)
lib
scim
kit
v2
spec
scim
lib/scim/kit/v2/templates/attribute.json.jbuilder
@@ -7,6 +7,6 @@ if type.complex? && !type.multi_valued
render attribute, json: json
end
end
-else
- json.set! type.name, _value if renderable?
+elsif renderable?
+ json.set! type.name, _value
end
lib/scim/kit/v2/attributable.rb
@@ -43,7 +43,10 @@ module Scim
end
def attribute(type, resource)
- dynamic_attributes[type.name] = Attribute.new(type: type, resource: resource)
+ dynamic_attributes[type.name] = Attribute.new(
+ type: type,
+ resource: resource
+ )
extend(create_module_for(type))
end
end
lib/scim/kit/v2/attribute.rb
@@ -32,8 +32,9 @@ module Scim
end
def renderable?
- return false if type.mutability == Mutability::READ_ONLY && _resource.mode?(:client)
- return false if type.mutability == Mutability::WRITE_ONLY && _resource.mode?(:server)
+ return false if read_only? && _resource.mode?(:client)
+ return false if write_only? && _resource.mode?(:server)
+
true
end
@@ -56,6 +57,14 @@ module Scim
errors.add(type.name, I18n.t('errors.messages.invalid'))
end
+
+ def read_only?
+ type.mutability == Mutability::READ_ONLY
+ end
+
+ def write_only?
+ type.mutability == Mutability::WRITE_ONLY
+ end
end
end
end
lib/scim/kit/v2/mutability.rb
@@ -16,7 +16,7 @@ module Scim
readonly: READ_ONLY,
readwrite: READ_WRITE,
write_only: WRITE_ONLY,
- writeonly: WRITE_ONLY,
+ writeonly: WRITE_ONLY
}.freeze
def self.find(value)
spec/scim/kit/v2/attribute_spec.rb
@@ -2,6 +2,7 @@
RSpec.describe Scim::Kit::V2::Attribute do
subject { described_class.new(type: type, resource: resource) }
+
let(:resource) { Scim::Kit::V2::Resource.new(schemas: [schema], location: FFaker::Internet.uri('https')) }
let(:schema) { Scim::Kit::V2::Schema.new(id: Scim::Kit::V2::Schemas::USER, name: 'User', location: FFaker::Internet.uri('https')) }
@@ -256,46 +257,47 @@ RSpec.describe Scim::Kit::V2::Attribute do
end
end
- describe "#renderable?" do
+ context 'when the resource is in server mode' do
let(:type) { Scim::Kit::V2::AttributeType.new(name: 'userName', type: :string) }
let(:resource) { instance_double(Scim::Kit::V2::Resource) }
- context "when the resource is in server mode" do
- before do
- allow(resource).to receive(:mode?).with(:server).and_return(true)
- allow(resource).to receive(:mode?).with(:client).and_return(false)
- end
+ before do
+ allow(resource).to receive(:mode?).with(:server).and_return(true)
+ allow(resource).to receive(:mode?).with(:client).and_return(false)
+ end
- context "when the type is read only" do
- before { type.mutability = :read_only }
+ context 'when the type is read only' do
+ before { type.mutability = :read_only }
- specify { expect(subject).to be_renderable }
- end
+ specify { expect(subject).to be_renderable }
+ end
- context "when the type is write only" do
- before { type.mutability = :write_only }
+ context 'when the type is write only' do
+ before { type.mutability = :write_only }
- specify { expect(subject).not_to be_renderable }
- end
+ specify { expect(subject).not_to be_renderable }
end
+ end
- context "when the resource is in client mode" do
- before do
- allow(resource).to receive(:mode?).with(:server).and_return(false)
- allow(resource).to receive(:mode?).with(:client).and_return(true)
- end
+ context 'when the resource is in client mode' do
+ let(:type) { Scim::Kit::V2::AttributeType.new(name: 'userName', type: :string) }
+ let(:resource) { instance_double(Scim::Kit::V2::Resource) }
- context "when the type is read only" do
- before { type.mutability = :read_only }
+ before do
+ allow(resource).to receive(:mode?).with(:server).and_return(false)
+ allow(resource).to receive(:mode?).with(:client).and_return(true)
+ end
- specify { expect(subject).not_to be_renderable }
- end
+ context 'when the type is read only' do
+ before { type.mutability = :read_only }
+
+ specify { expect(subject).not_to be_renderable }
+ end
- context "when the type is write only" do
- before { type.mutability = :write_only }
+ context 'when the type is write only' do
+ before { type.mutability = :write_only }
- specify { expect(subject).to be_renderable }
- end
+ specify { expect(subject).to be_renderable }
end
end
end
spec/scim/kit/v2/resource_spec.rb
@@ -167,7 +167,7 @@ RSpec.describe Scim::Kit::V2::Resource do
attribute.required = true
attribute.uniqueness = :server
end
- schema.add_attribute(name: 'name') do | attribute|
+ schema.add_attribute(name: 'name') do |attribute|
attribute.add_attribute(name: 'formatted') do |x|
x.mutability = :read_only
end
@@ -182,7 +182,7 @@ RSpec.describe Scim::Kit::V2::Resource do
schema.add_attribute(name: 'active', type: :boolean)
schema.add_attribute(name: 'password') do |attribute|
attribute.mutability = :write_only
- attribute.returned = :never
+ attribute.returned = :never
end
schema.add_attribute(name: 'emails') do |attribute|
attribute.multi_valued = true
@@ -196,7 +196,7 @@ RSpec.describe Scim::Kit::V2::Resource do
x.mutability = :read_only
end
attribute.add_attribute(name: '$ref') do |x|
- x.reference_types = ['User', 'Group']
+ x.reference_types = %w[User Group]
x.mutability = :read_only
end
attribute.add_attribute(name: 'display') do |x|
@@ -249,8 +249,9 @@ RSpec.describe Scim::Kit::V2::Resource do
specify { expect(resource.to_h.key?(:external_id)).to be(false) }
end
- context "when building in client mode" do
+ context 'when building in client mode' do
subject { described_class.new(schemas: schemas) }
+
let(:external_id) { SecureRandom.uuid }
before { subject.external_id = external_id }
@@ -272,7 +273,7 @@ RSpec.describe Scim::Kit::V2::Resource do
specify { expect(subject.to_h.key?(:groups)).to be(false) }
end
- context "when building in server mode" do
+ context 'when building in server mode' do
subject { described_class.new(schemas: schemas, location: resource_location) }
before do
@@ -296,15 +297,15 @@ RSpec.describe Scim::Kit::V2::Resource do
end
end
- describe "#mode?" do
- context "when server mode" do
+ describe '#mode?' do
+ context 'when server mode' do
subject { described_class.new(schemas: schemas, location: resource_location) }
specify { expect(subject).to be_mode(:server) }
specify { expect(subject).not_to be_mode(:client) }
end
- context "when client mode" do
+ context 'when client mode' do
subject { described_class.new(schemas: schemas) }
specify { expect(subject).not_to be_mode(:server) }