Advertisement
Guest User

Untitled

a guest
Nov 24th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. class Users::RegistrationsController < Devise::RegistrationsController
  2.  
  3. ...
  4.  
  5. def update_resource(resource, params)
  6. if params[:password].blank? && params[:password_confirmation].blank?
  7. resource.update_without_password(params)
  8. else
  9. super
  10. end
  11. end
  12.  
  13. end
  14.  
  15. require "rails_helper"
  16.  
  17. RSpec.describe Users::RegistrationsController, type: :controller do
  18.  
  19. describe "update password" do
  20. before do
  21. @request.env['devise.mapping'] = Devise.mappings[:user]
  22. end
  23. let(:user){ FactoryGirl.create(:user, password: 'current_password', password_confirmation: 'current_password') }
  24.  
  25. context "with a valid password parameter" do
  26. it "updates user in the database" do
  27.  
  28. put :update, params: { id: user, user: FactoryGirl.attributes_for(:user, password: '12', password_confirmation: '12') }
  29. user.reload
  30.  
  31. expect(user.password).to eq("newpassword12")
  32. end
  33. end
  34. end
  35.  
  36. end
  37.  
  38. 2) Users::RegistrationsController update password with a valid password parameter updates user in the database
  39. Failure/Error: expect(user.password).to eq("newpassword12")
  40.  
  41. expected: "newpassword12"
  42. got: "current_password"
  43.  
  44. (compared using ==)
  45. # ./spec/controller/users/registrations_controller_spec.rb:75:in `block (4 levels) in <top (required)>'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement