Commit 96b0c6e
Changed files (7)
app
controllers
scim
spec
app/controllers/scim/v2/users_controller.rb
@@ -1,14 +1,21 @@
module Scim
module V2
class UsersController < ::Scim::Controller
+ def show
+ user = User.find_by(uuid: params[:id])
+ response.headers['Content-Type'] = 'application/scim+json'
+ response.headers['Location'] = scim_v2_users_url(user)
+ render json: user.to_scim(self).to_json, status: :ok
+ end
+
def create
- @user = User.create!(
+ user = User.create!(
email: user_params[:userName],
password: SecureRandom.hex(32),
)
response.headers['Content-Type'] = 'application/scim+json'
- response.headers['Location'] = scim_v2_users_url(@user)
- render json: @user.to_scim(self).to_json, status: :created
+ response.headers['Location'] = scim_v2_users_url(user)
+ render json: user.to_scim(self).to_json, status: :created
end
private
spec/requests/scim/v2/users_spec.rb
@@ -1,16 +1,17 @@
require 'rails_helper'
describe '/scim/v2/users' do
+ let(:token) { SecureRandom.uuid }
+ let(:headers) do
+ {
+ 'Authorization' => "Bearer #{token}",
+ 'Accept' => 'application/json',
+ 'Content-Type' => 'application/json',
+ }
+ end
+
describe "POST /scim/v2/users" do
- let(:token) { SecureRandom.uuid }
let(:email) { FFaker::Internet.email }
- let(:headers) do
- {
- 'Authorization' => "Bearer #{token}",
- 'Accept' => 'application/json',
- 'Content-Type' => 'application/json',
- }
- end
it 'creates a new user' do
body = { schemas: [Scim::Shady::Schemas::USER], userName: email }
@@ -33,4 +34,27 @@ describe '/scim/v2/users' do
expect(json[:meta][:location]).to be_present
end
end
+
+ describe "GET /scim/v2/users" do
+ let(:user) { create(:user) }
+
+ it 'returns the requested resource' do
+ get "/scim/v2/users/#{user.uuid}"
+
+ expect(response).to have_http_status(:ok)
+ expect(response.headers['Content-Type']).to eql('application/scim+json')
+ expect(response.headers['Location']).to be_present
+ expect(response.body).to be_present
+
+ json = JSON.parse(response.body, symbolize_names: true)
+ expect(json[:schemas]).to match_array([Scim::Shady::Schemas::USER])
+ expect(json[:id]).to eql(user.uuid)
+ expect(json[:userName]).to eql(user.email)
+ expect(json[:meta][:resourceType]).to eql('User')
+ expect(json[:meta][:created]).to eql(user.created_at.iso8601)
+ expect(json[:meta][:lastModified]).to eql(user.updated_at.iso8601)
+ expect(json[:meta][:version]).to eql(user.lock_version)
+ expect(json[:meta][:location]).to eql(scim_v2_users_url(user))
+ end
+ end
end
spec/support/factory_bot.rb
@@ -0,0 +1,3 @@
+RSpec.configure do |config|
+ config.include FactoryBot::Syntax::Methods
+end
spec/factories.rb
@@ -0,0 +1,7 @@
+FactoryBot.define do
+ factory :user do
+ email FFaker::Internet.email
+ uuid SecureRandom.uuid
+ password FFaker::Internet.password
+ end
+end
spec/rails_helper.rb
@@ -20,7 +20,7 @@ require 'rspec/rails'
# directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary.
#
-# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
+Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations and applies them before tests are run.
# If you are not using ActiveRecord, you can remove this line.
Gemfile
@@ -42,6 +42,7 @@ group :development, :test do
gem 'webmock'
gem 'rails-controller-testing'
gem 'sqlite3'
+ gem 'factory_bot_rails'
end
group :development do
Gemfile.lock
@@ -87,6 +87,11 @@ GEM
activemodel
erubi (1.7.0)
execjs (2.7.0)
+ factory_bot (4.8.2)
+ activesupport (>= 3.0.0)
+ factory_bot_rails (4.8.2)
+ factory_bot (~> 4.8.2)
+ railties (>= 3.0.0)
ffaker (2.7.0)
ffi (1.9.18)
globalid (0.4.0)
@@ -263,6 +268,7 @@ DEPENDENCIES
coffee-rails (~> 4.2)
dotenv-rails
email_validator
+ factory_bot_rails
ffaker
jbuilder (~> 2.5)
jwt