I'm working on a project that has required me to update the typical functionality of ApplicationRecord
to include a validation to check that every model included in the DB has a particular field. I've set this up in the following way:
class MyCustomApplicationRecordClass < ApplicationRecord
self.abstract_class = true
validate :custom_validation
def custom_validation
...
end
end
My models then inherit from this class in the following way:
class MyModel < MyCustomApplicationRecordClass
...
end
While the validation works as anticipated & I can write tests confirming the functionality is working for each of the classes that inherit from MyCustomApplicationRecordClass
, I'm struggling with how to write tests confirming that the validation on this class is behaving as anticipated. I've tried creating a "test" class, but receive an error that my test class doesn't correspond to a table in my db (which of course it doesn't'). What's the best way to test that this validation is performing as anticipated?
question from:
https://stackoverflow.com/questions/65928880/ruby-on-rails-write-rspec-tests-for-an-abstract-class 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…