Hi i am working on RoR project with ruby-2.5.0 and rails 5.0. I have a model forgot_password where a class method is defined to create a record as follows:-
forgot_password.rb
# frozen_string_literal: true
class ForgotPassword < ApplicationRecord
before_create :create_token
def self.create_record
self.create!(expiry: Time.zone.now +
ENV['VALIDITY_PERIOD'].to_i.hours)
end
private
def create_token
self.token = SecureRandom.urlsafe_base64(nil, false)
end
end
I want to write unit testing for it using stub or factory_girl gem.
spec/models/forgot_password_spec.rb
# frozen_string_literal: true
require 'rails_helper'
describe ForgotPassword do
let(:forgot_password) do
described_class.new()
end
describe 'create_record' do
context 'with forgot_password class' do
subject { forgot_password.create_record.class }
it { is_expected.to eq ForgotPassword }
end
end
end
But its throwing error undefined method create_record for #<ForgotPassword:0x000000000622bc98> Please help me how can i test my model. Thanks in advance.