aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMark J. Titorenko <mark@titorenko.net>2018-11-29 18:36:20 +0000
committerMark J. Titorenko <mark@titorenko.net>2018-11-29 18:37:06 +0000
commit8212dfcf14c63c006b9e1c37595f3d62eab052cf (patch)
tree0b01f51e99b36d1eaa57b3d86d3217bf01f79357 /activesupport
parent4b5c4ca377a9b5c75d2c4b4d4f63f53866553b40 (diff)
downloadrails-8212dfcf14c63c006b9e1c37595f3d62eab052cf.tar.gz
rails-8212dfcf14c63c006b9e1c37595f3d62eab052cf.tar.bz2
rails-8212dfcf14c63c006b9e1c37595f3d62eab052cf.zip
Do nothing when the same block is included again.
If the same block is included multiple times, we no longer raise an exception or overwrite the included block instance variable. Fixes #14802. [Mark J. Titorenko + Vlad Bokov]
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md4
-rw-r--r--activesupport/lib/active_support/concern.rb10
-rw-r--r--activesupport/test/concern_test.rb8
-rw-r--r--activesupport/test/fixtures/concern/some_concern.rb11
4 files changed, 30 insertions, 3 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 98d232da33..ba8aaf47f9 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,7 @@
+* If the same block is `included` multiple times for a Concern, an exception is no longer raised.
+
+ *Mark J. Titorenko*, *Vlad Bokov*
+
* Fix bug where `#to_options` for `ActiveSupport::HashWithIndifferentAccess`
would not act as alias for `#symbolize_keys`.
diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb
index b0a0d845e5..5d356a0ab6 100644
--- a/activesupport/lib/active_support/concern.rb
+++ b/activesupport/lib/active_support/concern.rb
@@ -125,9 +125,13 @@ module ActiveSupport
def included(base = nil, &block)
if base.nil?
- raise MultipleIncludedBlocks if instance_variable_defined?(:@_included_block)
-
- @_included_block = block
+ if instance_variable_defined?(:@_included_block)
+ if @_included_block.source_location != block.source_location
+ raise MultipleIncludedBlocks
+ end
+ else
+ @_included_block = block
+ end
else
super
end
diff --git a/activesupport/test/concern_test.rb b/activesupport/test/concern_test.rb
index 98d8f3ee0d..4b3cfcd1d2 100644
--- a/activesupport/test/concern_test.rb
+++ b/activesupport/test/concern_test.rb
@@ -128,4 +128,12 @@ class ConcernTest < ActiveSupport::TestCase
end
end
end
+
+ def test_no_raise_on_same_included_call
+ assert_nothing_raised do
+ 2.times do
+ load File.expand_path("../fixtures/concern/some_concern.rb", __FILE__)
+ end
+ end
+ end
end
diff --git a/activesupport/test/fixtures/concern/some_concern.rb b/activesupport/test/fixtures/concern/some_concern.rb
new file mode 100644
index 0000000000..87f660a81e
--- /dev/null
+++ b/activesupport/test/fixtures/concern/some_concern.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+require "active_support/concern"
+
+module SomeConcern
+ extend ActiveSupport::Concern
+
+ included do
+ # shouldn't raise when module is loaded more than once
+ end
+end