Commit 5cb2c8b6b0d4f3e87b664b5cb2980fa3490b4e6d

Authored by Spencer Alan
1 parent 6f55bd04
Exists in master

• add content type to error responses

• add spec coverage for content type
app/controllers/concerns/scim_rails/response.rb
@@ -5,7 +5,8 @@ module ScimRails @@ -5,7 +5,8 @@ module ScimRails
5 def json_response(object, status = :ok) 5 def json_response(object, status = :ok)
6 render \ 6 render \
7 json: object, 7 json: object,
8 - status: status 8 + status: status,
  9 + content_type: CONTENT_TYPE
9 end 10 end
10 11
11 def json_scim_response(object:, status: :ok, counts: nil) 12 def json_scim_response(object:, status: :ok, counts: nil)
spec/controllers/scim_rails/scim_users_controller_spec.rb
@@ -9,6 +9,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -9,6 +9,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
9 let(:company) { create(:company) } 9 let(:company) { create(:company) }
10 10
11 context "when unauthorized" do 11 context "when unauthorized" do
  12 + it "returns scim+json content type" do
  13 + get :index
  14 +
  15 + expect(response.content_type).to eq "application/scim+json, application/json"
  16 + end
  17 +
12 it "fails with no credentials" do 18 it "fails with no credentials" do
13 get :index 19 get :index
14 20
@@ -29,6 +35,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -29,6 +35,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
29 http_login(company) 35 http_login(company)
30 end 36 end
31 37
  38 + it "returns scim+json content type" do
  39 + get :index
  40 +
  41 + expect(response.content_type).to eq "application/scim+json, application/json"
  42 + end
  43 +
32 it "is successful with valid credentials" do 44 it "is successful with valid credentials" do
33 get :index 45 get :index
34 46
@@ -134,6 +146,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -134,6 +146,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
134 let(:company) { create(:company) } 146 let(:company) { create(:company) }
135 147
136 context "when unauthorized" do 148 context "when unauthorized" do
  149 + it "returns scim+json content type" do
  150 + get :show, params: { id: 1 }
  151 +
  152 + expect(response.content_type).to eq "application/scim+json, application/json"
  153 + end
  154 +
137 it "fails with no credentials" do 155 it "fails with no credentials" do
138 get :show, params: { id: 1 } 156 get :show, params: { id: 1 }
139 157
@@ -154,6 +172,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -154,6 +172,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
154 http_login(company) 172 http_login(company)
155 end 173 end
156 174
  175 + it "returns scim+json content type" do
  176 + get :show, params: { id: 1 }
  177 +
  178 + expect(response.content_type).to eq "application/scim+json, application/json"
  179 + end
  180 +
157 it "is successful with valid credentials" do 181 it "is successful with valid credentials" do
158 create(:user, id: 1, company: company) 182 create(:user, id: 1, company: company)
159 get :show, params: { id: 1 } 183 get :show, params: { id: 1 }
@@ -183,6 +207,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -183,6 +207,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
183 let(:company) { create(:company) } 207 let(:company) { create(:company) }
184 208
185 context "when unauthorized" do 209 context "when unauthorized" do
  210 + it "returns scim+json content type" do
  211 + post :create
  212 +
  213 + expect(response.content_type).to eq "application/scim+json, application/json"
  214 + end
  215 +
186 it "fails with no credentials" do 216 it "fails with no credentials" do
187 post :create 217 post :create
188 218
@@ -203,6 +233,22 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -203,6 +233,22 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
203 http_login(company) 233 http_login(company)
204 end 234 end
205 235
  236 + it "returns scim+json content type" do
  237 + post :create, params: {
  238 + name: {
  239 + givenName: "New",
  240 + familyName: "User"
  241 + },
  242 + emails: [
  243 + {
  244 + value: "new@example.com"
  245 + }
  246 + ]
  247 + }
  248 +
  249 + expect(response.content_type).to eq "application/scim+json, application/json"
  250 + end
  251 +
206 it "is successful with valid credentials" do 252 it "is successful with valid credentials" do
207 post :create, params: { 253 post :create, params: {
208 name: { 254 name: {
@@ -307,6 +353,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -307,6 +353,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
307 let(:company) { create(:company) } 353 let(:company) { create(:company) }
308 354
309 context "when unauthorized" do 355 context "when unauthorized" do
  356 + it "returns scim+json content type" do
  357 + put :put_update, params: { id: 1 }
  358 +
  359 + expect(response.content_type).to eq "application/scim+json, application/json"
  360 + end
  361 +
310 it "fails with no credentials" do 362 it "fails with no credentials" do
311 put :put_update, params: { id: 1 } 363 put :put_update, params: { id: 1 }
312 364
@@ -329,6 +381,25 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -329,6 +381,25 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
329 http_login(company) 381 http_login(company)
330 end 382 end
331 383
  384 + it "returns scim+json content type" do
  385 + put :put_update, params: {
  386 + id: 1,
  387 + userName: "test@example.com",
  388 + name: {
  389 + givenName: "Test",
  390 + familyName: "User"
  391 + },
  392 + emails: [
  393 + {
  394 + value: "test@example.com"
  395 + },
  396 + ],
  397 + active: "true"
  398 + }
  399 +
  400 + expect(response.content_type).to eq "application/scim+json, application/json"
  401 + end
  402 +
332 it "is successful with with valid credentials" do 403 it "is successful with with valid credentials" do
333 put :put_update, params: { 404 put :put_update, params: {
334 id: 1, 405 id: 1,
@@ -385,6 +456,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -385,6 +456,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
385 let(:company) { create(:company) } 456 let(:company) { create(:company) }
386 457
387 context "when unauthorized" do 458 context "when unauthorized" do
  459 + it "returns scim+json content type" do
  460 + patch :patch_update, params: { id: 1 }
  461 +
  462 + expect(response.content_type).to eq "application/scim+json, application/json"
  463 + end
  464 +
388 it "fails with no credentials" do 465 it "fails with no credentials" do
389 patch :patch_update, params: { id: 1 } 466 patch :patch_update, params: { id: 1 }
390 467
@@ -407,6 +484,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -407,6 +484,12 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
407 http_login(company) 484 http_login(company)
408 end 485 end
409 486
  487 + it "returns scim+json content type" do
  488 + patch :patch_update, params: { id: 1 }
  489 +
  490 + expect(response.content_type).to eq "application/scim+json, application/json"
  491 + end
  492 +
410 it "is successful with valid credentials" do 493 it "is successful with valid credentials" do
411 patch :patch_update, params: { id: 1 } 494 patch :patch_update, params: { id: 1 }
412 495