-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix verified partial doubles with abstract classes. #1396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -11,7 +11,7 @@ def self.initialize_activerecord_configuration(config) | |||
::RSpec::Mocks.configuration.when_declaring_verifying_double do |possible_model| | |||
target = possible_model.target | |||
|
|||
if target.respond_to?(:define_attribute_methods) && ActiveRecord::Base != target | |||
if target.respond_to?(:define_attribute_methods) && ActiveRecord::Base != target && !target.abstract_class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why abstract_class
instead of abstract_class?
Also, I don't think that you can assume target
will respond to abstract_class
just because it responds to define_attribute_methods
. Consider that ActiveModel providesdefine_attribute_methods
as well:
So this needs a respond_to?(:abstract_class)
check.
On a side note, I was hoping that ActiveRecord::Base.abstract_class?
would return true
(it is abstract after all...) so that we could do away with the explicit ActiveRecord::Base != target
check but sadly, it doesn't :(.
LGTM besides the concerns raised in my comment above. |
@@ -1,4 +1,4 @@ | |||
tmp | |||
pmp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to change this?
LGTM. I agree with Myron's comment. |
bd7bf67
to
eeb450b
Compare
Changed and added a spec for active model based classes |
eeb450b
to
2ebc177
Compare
LGTM |
@JonRowe, before merging this, take a look at the conversation here: rspec/rspec-core#1994 (comment) I think it could be worthwhile to make further changes to the check in the callback here. |
Fix verified partial doubles with abstract classes.
Possibly but I think there might be further discussion needed given a more complex interaction, this will allow the original issue to be solved in master (possivly even released if it takes us a while) while we do that |
As reported in rspec/rspec-mocks#975 abstract classes can't be verified currently due to the callback for defining attribute methods. This corrects that.
Fixes rspec/rspec-mocks#975.