0

I am trying to test the model class method. here's how model looks like

class Abc
  class Dbc < ActiveRecord::Base
    self.table_name = 'vSomeView'

    def self.class_method(user_id)
      Dbc
      .select('vSomeView.column')
      .where("vSomeView.UserID = #{user_id}")
      .first
    end
  end
end

factory

FactoryGirl.define do
  factory :dbc, class: Abc::Dbc do
  column { 'value' }
  ...
  end
end

Rspec

RSpec.describe Abc::Dbc, type: :model do
  let(:user) { create(:user) }
  let(:dbc) { build_stubbed(:dbc, user: user) }

  describe '.class_method' do
    it 'returns column value' do
      response = dbc.class_method(user.user_id)
      expect(response.column). to eq('value')
    end
  end
end

But i am getting error class_method when i run rspec. What is it i am doing wrong?

1 Answer 1

1

When you use factory girl to build an instance, it will build you an instance instantiated from that class.

What you want is

Abc::Dbc.class_method(...)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.