Commit 5cf3023

mokha <mokha@cisco.com>
2018-01-24 17:19:57
extract method to apply scim content type.
1 parent 6995550
Changed files (2)
app/controllers/scim/v2/users_controller.rb
@@ -2,7 +2,6 @@ module Scim
   module V2
     class UsersController < ::Scim::Controller
       def index
-        response.headers['Content-Type'] = 'application/scim+json'
         render json: {
           schemas: [Scim::Shady::Messages::LIST_RESPONSE],
           totalResults: 0,
@@ -12,7 +11,6 @@ module Scim
 
       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
@@ -22,22 +20,20 @@ module Scim
           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
       end
 
       def update
-        user = User.find_by(uuid: params[:id])
+        user = User.find_by!(uuid: params[:id])
         user.update!(email: user_params[:userName])
 
-        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 destroy
-        user = User.find_by(uuid: params[:id])
+        user = User.find_by!(uuid: params[:id])
         user.destroy!
       end
 
app/controllers/scim/controller.rb
@@ -2,6 +2,7 @@ module Scim
   class Controller < ApplicationController
     protect_from_forgery with: :null_session
     rescue_from ActiveRecord::RecordNotFound, with: :not_found
+    before_action :apply_scim_content_type
 
     private
 
@@ -15,5 +16,9 @@ module Scim
         status: "404",
       }.to_json, status: :not_found
     end
+
+    def apply_scim_content_type
+      response.headers['Content-Type'] = Mime[:scim].to_s
+    end
   end
 end