Commit c83b9fb

mokha <mokha@cisco.com>
2018-01-24 02:21:26
move .search to separate controller.
1 parent 6085a69
Changed files (4)
app
controllers
config
spec
app/controllers/scim/v2/search_controller.rb
@@ -0,0 +1,16 @@
+module Scim
+  module V2
+    class SearchController < ::Scim::Controller
+      def index
+        response.headers['Content-Type'] = 'application/scim+json'
+        render json: {
+          schemas: [Scim::Shady::Messages::LIST_RESPONSE],
+          totalResults: 0,
+          itemsPerPage: 0,
+          startIndex: 1,
+          Resources: [],
+        }.to_json, status: :ok
+      end
+    end
+  end
+end
config/routes.rb
@@ -9,11 +9,8 @@ Rails.application.routes.draw do
 
   namespace :scim do
     namespace :v2, defaults: { format: 'json' } do
-      resources :users, only: [:index, :show, :create, :update, :destroy] do
-        collection do
-          post ".search", to: "users#index"
-        end
-      end
+      post ".search", to: "search#index"
+      resources :users, only: [:index, :show, :create, :update, :destroy]
       get :ServiceProviderConfig, to: "service_providers#index"
       #resources :groups
       resources :resource_types, only: [:index]
spec/requests/scim/v2/search_spec.rb
@@ -0,0 +1,36 @@
+require 'rails_helper'
+
+describe '/scim/v1/.search' do
+  let(:token) { SecureRandom.uuid }
+  let(:headers) do
+    {
+      'Authorization' => "Bearer #{token}",
+      'Accept' => 'application/scim+json',
+      'Content-Type' => 'application/scim+json',
+    }
+  end
+
+  describe "POST /scim/v2/.search" do
+    it 'returns an empty set of results' do
+      body = {
+        "schemas": [Scim::Shady::Messages::SEARCH_REQUEST],
+        "attributes": ["displayName", "userName"],
+        "filter": "displayName sw \"smith\"",
+        "startIndex": 1,
+        "count": 10
+      }
+      post "/scim/v2/.search", headers: headers, params: body.to_json
+
+      expect(response).to have_http_status(:ok)
+      expect(response.headers['Content-Type']).to eql('application/scim+json')
+      expect(response.body).to be_present
+
+      json = JSON.parse(response.body, symbolize_names: true)
+      expect(json[:schemas]).to match_array([Scim::Shady::Messages::LIST_RESPONSE])
+      expect(json[:totalResults]).to be_zero
+      expect(json[:itemsPerPage]).to be_zero
+      expect(json[:startIndex]).to eql(1)
+      expect(json[:Resources]).to be_empty
+    end
+  end
+end
spec/requests/scim/v2/users_spec.rb
@@ -72,26 +72,4 @@ describe '/scim/v2/users' do
       expect(json[:Resources]).to be_empty
     end
   end
-
-  describe "POST /scim/v2/users/.search" do
-    it 'returns an empty set of results' do
-      body = {
-        "schemas": [Scim::Shady::Messages::SEARCH_REQUEST],
-        "attributes": ["displayName", "userName"],
-        "filter": "displayName sw \"smith\"",
-        "startIndex": 1,
-        "count": 10
-      }
-      post "/scim/v2/users/.search", headers: headers, params: body.to_json
-
-      expect(response).to have_http_status(:ok)
-      expect(response.headers['Content-Type']).to eql('application/scim+json')
-      expect(response.body).to be_present
-
-      json = JSON.parse(response.body, symbolize_names: true)
-      expect(json[:schemas]).to match_array([Scim::Shady::Messages::LIST_RESPONSE])
-      expect(json[:totalResults]).to be_zero
-      expect(json[:Resources]).to be_empty
-    end
-  end
 end