Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. class User < ApplicationRecord
  2. has_secure_password
  3.  
  4. has_many :companies
  5. validates :password, length: {minimum:7}, allow_nil: true
  6. validate :current_password_is_ok, if: "!password.blank?", on: :update
  7.  
  8. validates :email, presence: true
  9.  
  10. attr_accessor :current_password
  11.  
  12. protected
  13.  
  14. def current_password_is_ok
  15. if !User.find(id).authenticate(current_password)
  16. errors.add(:current_password, "Contrasenya actual incorrecte")
  17. end
  18. end
  19.  
  20. end
  21.  
  22. user=User.create(name:"Admin",email:"cas***@gmail.com",password:"***",password_confirmation:"***")
  23.  
  24. require 'rails_helper'
  25.  
  26. RSpec.describe UsersController, type: :controller do
  27.  
  28. before do
  29.  
  30. # This User.create, executes the validate on: :update
  31. expect(user=User.create(name:"Admin",email:"cas...@gmail.com",password:"...",password_confirmation:"...")).to be_valid
  32. expect(company=Company.create(domain:"test.host",name:"test",user_id:user)).to be_valid
  33. expect(company.user_id).to eq(user.id)
  34. end
  35.  
  36. describe "GET #login" do
  37. it "returns http success" do
  38. # get :login
  39. # expect(response).to have_http_status(:success)
  40. end
  41. end
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement