I'm trying to instantiate an object of abstract AR class for testing purposes. The model's defined like this:
class Basic < ActiveRecord::Base
self.abstract_class = true
def stuff
raise NotImplementedError
end
end
When I try to Basic.new
, I get:
"Mysql2::Error: Table 'project_development.basics' doesn't exist"
Is it normal behavior? Do abstract AR classes are not intended to be instantiated even without (obviously impossible) persistence?
Using 1.9.2-p136 with Rails 3.0.4 / Mysql2 0.2.6
Edit:
It turns out that the error is caused by column definitions, which in the case of an abstract model cannot be fetched from the database.
class Basic < ActiveRecord::Base
self.abstract_class = true
@columns = []
end
Works like a charm.
This is normal behaviour. Abstract classes are not supposed to be instantiated. You should test the classes which inherit from the abstract class, not the abstract class itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With