shoulda-matchers
shoulda-matchers copied to clipboard
Wrong touches Class for STI test
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?
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.
@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 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