aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMike Dillon <mike@embody.org>2013-05-16 11:11:27 -0700
committerMike Dillon <mike@embody.org>2013-05-16 11:28:31 -0700
commit2d7a86e17947e359cb65653b987c666b2d7e8efb (patch)
tree27c570e652cf25e6118b2894b6599b0dc81fb393 /activesupport
parentf96478369e0e01a00d1d6909814d388c49642b1a (diff)
downloadrails-2d7a86e17947e359cb65653b987c666b2d7e8efb.tar.gz
rails-2d7a86e17947e359cb65653b987c666b2d7e8efb.tar.bz2
rails-2d7a86e17947e359cb65653b987c666b2d7e8efb.zip
Raise when multiple included blocks are defined
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md6
-rw-r--r--activesupport/lib/active_support/concern.rb8
-rw-r--r--activesupport/test/concern_test.rb14
3 files changed, 28 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 493c169803..1982811500 100644
--- a/activesupport/CHANGELOG.md
+++ b/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,
diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb
index eeeba60839..b6ae86b583 100644
--- a/activesupport/lib/active_support/concern.rb
+++ b/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 @@ module ActiveSupport
def included(base = nil, &block)
if base.nil?
+ raise MultipleIncludedBlocks if instance_variable_defined?("@_included_block")
+
@_included_block = block
else
super
diff --git a/activesupport/test/concern_test.rb b/activesupport/test/concern_test.rb
index 912ce30c29..8e2c298fc6 100644
--- a/activesupport/test/concern_test.rb
+++ b/activesupport/test/concern_test.rb
@@ -91,4 +91,18 @@ class ConcernTest < ActiveSupport::TestCase
@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