shoulda-matchers icon indicating copy to clipboard operation
shoulda-matchers copied to clipboard

Wrong touches Class for STI test

Open helmiItsavirus opened this issue 4 years ago • 3 comments

I found an issue when I use the STI model on my apps

class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true
end

class ContentSource < ApplicationRecord
end

class Facebook < ContentSource
end

RSpec.describe Facebook, type: :model do
  it { should_not allow_values("https://facebook.com/admin").for(:url) }
end

expected the ContentSource to be invalid, but it was valid instead

The Rspec touch ContentSource instead of Facebook class, how it could be? or do I need to configure something?

helmiItsavirus avatar Dec 24 '20 06:12 helmiItsavirus

Hi, @helmiItsavirus, thank you for opening this issue. It seems to me that we probably have a bug with this matcher.

For now, I'll add the label Need to investigate, and as soon I have the time I'll take a look.

#1381 - saving for future references, probably the same problem.

vsppedro avatar Dec 28 '20 14:12 vsppedro

@helmiItsavirus I'm having trouble understanding why this is happening given your example. I cleaned up the formatting of your code so it's easier to read, but in your example both of your ContentSource and Facebook classes inherit from ApplicationRecord. You say that this involves STI, but neither of those are using STI. Are you sure that's accurate?

mcmire avatar Dec 28 '20 17:12 mcmire

@mcmire The example has been updated, sorry for my mistake, Facebook should inherent to ContentSource

The error message still touches ContentSource instead of Facebook. In my perception, Rspec should test subclass that I am defined

If you have time, you can try to create a spec using an STI model similar to mine, I guess the problem will happen to you as well

helmiItsavirus avatar Dec 30 '20 09:12 helmiItsavirus