I haven't found a good way to test ApplicationRecord methods.
Let's say I have a simple method named one
:
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def one
1
end
end
And I want to test it:
describe ApplicationRecord do
let(:it) { described_class.new }
it 'works' do
expect(it.one).to eq 1
end
end
This dies, unsurprisingly, with NotImplementedError: ApplicationRecord is an abstract class and cannot be instantiated.
So I tried the anonymous class suggestion in Testing abstract classes in Rspec:
let(:it) { Class.new(described_class).new }
And this dies with TypeError: no implicit conversion of nil into String
, presumably because the record's table name is nil.
Can anyone suggest a nice, simple way to test ApplicationRecord methods? Hopefully one that doesn't introduce dependencies on other classes in my application and doesn't root around in ActiveRecord internals?
abstract_class
on ActiveRecord. – Geraldgeralda