Skip to content

More helpful error message when instantiating an abstract class#9474

Merged
rafaelfranca merged 1 commit into
rails:masterfrom
HonoreDB:master
Mar 7, 2013
Merged

More helpful error message when instantiating an abstract class#9474
rafaelfranca merged 1 commit into
rails:masterfrom
HonoreDB:master

Conversation

@HonoreDB

Copy link
Copy Markdown
Contributor

Calling a literal ActiveRecord::Base.new raises NoMethodError,
since it ends up calling Class.abstract_class? which does not exist.
Similarly, instantiating an actual abstract class hits the database,
when conventionally it should immediately throw NotImplementedError.

ActiveRecord::Base can't be made abstract without breaking many,
many things, so check for it separately.

@senny

senny commented Feb 28, 2013

Copy link
Copy Markdown
Member

can you write two test cases to verify that AR::Base cant be instantiated and that an abstract class can't be instantiated?

Also we would need a CHANGELOG entry explaining the change.

@schneems

schneems commented Mar 3, 2013

Copy link
Copy Markdown
Member

@HonoreDB comment-ors don't get notified when you push, you have to reply to the thread for them to know. @senny care to take a second look?

Comment thread activerecord/CHANGELOG.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a nitpick but it would be nice to put the constant name inside .

@senny

senny commented Mar 3, 2013

Copy link
Copy Markdown
Member

added a few minor comments.

@HonoreDB

HonoreDB commented Mar 3, 2013

Copy link
Copy Markdown
Contributor Author

Thanks, comments addressed in HonoreDB@f128e79.

Comment thread activerecord/test/cases/base_test.rb Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should assign the exception to check the message:

e = assert_raises(XX) {}

assert_equals "<expected>", e.message

@senny

senny commented Mar 3, 2013

Copy link
Copy Markdown
Member

the PR does no longer cleanly apply to master. Can you push a rebased version?

Calling a literal ActiveRecord::Base.new raises NoMethodError,
since it ends up calling Class.abstract_class? which does not exist.
Similarly, instantiating an actual abstract class hits the database,
when conventionally it should immediately throw NotImplementedError.

ActiveRecord::Base can't be made abstract without breaking many,
many things, so check for it separately.
@HonoreDB

HonoreDB commented Mar 3, 2013

Copy link
Copy Markdown
Contributor Author

Rebased, tests now check the error message in addition to the type.

@senny

senny commented Mar 3, 2013

Copy link
Copy Markdown
Member

@HonoreDB amazing! thanks for the fast update. 💛

@carlosantoniodasilva @rafaelfranca can you take a final look?

rafaelfranca added a commit that referenced this pull request Mar 7, 2013
More helpful error message when instantiating an abstract class

Conflicts:
	activerecord/CHANGELOG.md
@rafaelfranca rafaelfranca merged commit 53f18f2 into rails:master Mar 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants