Skip to content
Browse files

Raise when multiple included blocks are defined

  • Loading branch information...
1 parent f964783 commit 2d7a86e17947e359cb65653b987c666b2d7e8efb @md5 md5 committed May 16, 2013
Showing with 28 additions and 0 deletions.
  1. +6 −0 activesupport/CHANGELOG.md
  2. +8 −0 activesupport/lib/active_support/concern.rb
  3. +14 −0 activesupport/test/concern_test.rb
View
6 activesupport/CHANGELOG.md
@@ -1,3 +1,9 @@
+* Raise an error when multiple `included` blocks are defined for a Concern.
+ The old behavior would silently discard previously defined blocks, running
+ only the last one.
+
+ *Mike Dillon*
+
* Replace `multi_json` with `json`.
Since Rails requires Ruby 1.9 and since Ruby 1.9 includes `json` in the standard library,
View
8 activesupport/lib/active_support/concern.rb
@@ -98,6 +98,12 @@ module ActiveSupport
# include Bar # works, Bar takes care now of its dependencies
# end
module Concern
+ class MultipleIncludedBlocks < StandardError #:nodoc:
+ def initialize
+ super "Cannot define multiple 'included' blocks for a Concern"
+ end
+ end
+
def self.extended(base) #:nodoc:
base.instance_variable_set("@_dependencies", [])
end
@@ -117,6 +123,8 @@ def append_features(base)
def included(base = nil, &block)
if base.nil?
+ raise MultipleIncludedBlocks if instance_variable_defined?("@_included_block")
+
@_included_block = block
else
super
View
14 activesupport/test/concern_test.rb
@@ -91,4 +91,18 @@ def test_dependencies_with_multiple_modules
@klass.send(:include, Foo)
assert_equal [ConcernTest::Foo, ConcernTest::Bar, ConcernTest::Baz], @klass.included_modules[0..2]
end
+
+ def test_raise_on_multiple_included_calls
+ assert_raises(ActiveSupport::Concern::MultipleIncludedBlocks) do
+ Module.new do
+ extend ActiveSupport::Concern
+
+ included do
+ end
+
+ included do
+ end
+ end
+ end
+ end
end

0 comments on commit 2d7a86e

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