Skip to content
Browse files

Raise a better error if anyone wants to create your own ActionView::H…

…elpers::Tags::Base child and do not implement the render method
  • Loading branch information...
1 parent fcfe1fa commit 930245ef12fbbb0628c332d36bf09a33050d5b65 @rafaelfranca rafaelfranca committed Jan 23, 2012
Showing with 11 additions and 2 deletions.
  1. +3 −2 actionpack/lib/action_view/helpers/tags/base.rb
  2. +8 −0 actionpack/test/template/form_helper_test.rb
View
5 actionpack/lib/action_view/helpers/tags/base.rb
@@ -19,8 +19,9 @@ def initialize(object_name, method_name, template_object, options = {})
@auto_index = retrieve_autoindex(Regexp.last_match.pre_match) if Regexp.last_match
end
- def render(&block)
- raise "Abstract Method called"
+ # This is what child classes implement.
+ def render
+ raise NotImplementedError, "Subclasses must implement a render method"
end
private
View
8 actionpack/test/template/form_helper_test.rb
@@ -115,6 +115,14 @@ def url_for(object)
super
end
+ class FooTag < ActionView::Helpers::Tags::Base
+ def initialize; end
+ end
+
+ def test_tags_base_child_without_render_method
+ assert_raise(NotImplementedError) { FooTag.new.render }
+ end
+
def test_label
assert_dom_equal('<label for="post_title">Title</label>', label("post", "title"))
assert_dom_equal('<label for="post_title">The title goes here</label>', label("post", "title", "The title goes here"))

0 comments on commit 930245e

Please sign in to comment.
Something went wrong with that request. Please try again.