Commit b7fac703addabc1077dd6b50e8cfcdbdf17611cd

Authored by Spencer Alan
Committed by GitHub
2 parents e7dfbe7a 63eb6e56
Exists in master

Merge pull request #4 from lessonly/spenceralan/ch20969/scim-gem-put-deprovisioning-bug-fix

fix PUT deprovisioning bug
app/controllers/scim_rails/scim_users_controller.rb
@@ -98,7 +98,9 @@ module ScimRails @@ -98,7 +98,9 @@ module ScimRails
98 end 98 end
99 99
100 def active? 100 def active?
101 - active = put_active_param || patch_active_param 101 + active = put_active_param
  102 + active = patch_active_param if active.nil?
  103 +
102 case active 104 case active
103 when true, "true", 1 105 when true, "true", 1
104 true 106 true
spec/controllers/scim_rails/scim_users_controller_spec.rb
@@ -382,41 +382,33 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -382,41 +382,33 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
382 end 382 end
383 383
384 it "returns scim+json content type" do 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 - } 385 + put :put_update, params: put_params
399 386
400 expect(response.content_type).to eq "application/scim+json, application/json" 387 expect(response.content_type).to eq "application/scim+json, application/json"
401 end 388 end
402 389
403 it "is successful with with valid credentials" do 390 it "is successful with with valid credentials" do
404 - put :put_update, params: {  
405 - id: 1,  
406 - userName: "test@example.com",  
407 - name: {  
408 - givenName: "Test",  
409 - familyName: "User"  
410 - },  
411 - emails: [  
412 - {  
413 - value: "test@example.com"  
414 - },  
415 - ],  
416 - active: "true"  
417 - } 391 + put :put_update, params: put_params
  392 +
  393 + expect(response.status).to eq 200
  394 + end
  395 +
  396 + it "deprovisions an active record" do
  397 + request.content_type = "application/scim+json"
  398 + put :put_update, params: put_params(active: false)
  399 +
  400 + expect(response.status).to eq 200
  401 + expect(user.reload.active?).to eq false
  402 + end
  403 +
  404 + it "reprovisions an inactive record" do
  405 + user.archive!
  406 + expect(user.reload.active?).to eq false
  407 + request.content_type = "application/scim+json"
  408 + put :put_update, params: put_params(active: true)
418 409
419 expect(response.status).to eq 200 410 expect(response.status).to eq 200
  411 + expect(user.reload.active?).to eq true
420 end 412 end
421 413
422 it "returns :not_found for id that cannot be found" do 414 it "returns :not_found for id that cannot be found" do
@@ -572,4 +564,21 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do @@ -572,4 +564,21 @@ RSpec.describe ScimRails::ScimUsersController, type: :controller do
572 ] 564 ]
573 } 565 }
574 end 566 end
  567 +
  568 + def put_params(active: true)
  569 + {
  570 + id: 1,
  571 + userName: "test@example.com",
  572 + name: {
  573 + givenName: "Test",
  574 + familyName: "User"
  575 + },
  576 + emails: [
  577 + {
  578 + value: "test@example.com"
  579 + },
  580 + ],
  581 + active: active
  582 + }
  583 + end
575 end 584 end