Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ApplicationRecord
- has_secure_password
- has_many :companies
- validates :password, length: {minimum:7}, allow_nil: true
- validate :current_password_is_ok, if: "!password.blank?", on: :update
- validates :email, presence: true
- attr_accessor :current_password
- protected
- def current_password_is_ok
- if !User.find(id).authenticate(current_password)
- errors.add(:current_password, "Contrasenya actual incorrecte")
- end
- end
- end
- user=User.create(name:"Admin",email:"cas***@gmail.com",password:"***",password_confirmation:"***")
- require 'rails_helper'
- RSpec.describe UsersController, type: :controller do
- before do
- # This User.create, executes the validate on: :update
- expect(user=User.create(name:"Admin",email:"cas...@gmail.com",password:"...",password_confirmation:"...")).to be_valid
- expect(company=Company.create(domain:"test.host",name:"test",user_id:user)).to be_valid
- expect(company.user_id).to eq(user.id)
- end
- describe "GET #login" do
- it "returns http success" do
- # get :login
- # expect(response).to have_http_status(:success)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement