mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #34553 from mjtko/fix/issue-14802
Do nothing when the same block is included again
This commit is contained in:
commit
c8e4d5a1e3
4 changed files with 30 additions and 3 deletions
|
@ -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`.
|
||||
|
||||
|
|
|
@ -125,9 +125,13 @@ module ActiveSupport
|
|||
|
||||
def included(base = nil, &block)
|
||||
if base.nil?
|
||||
raise MultipleIncludedBlocks if instance_variable_defined?(:@_included_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
|
||||
|
|
|
@ -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
|
||||
|
|
11
activesupport/test/fixtures/concern/some_concern.rb
vendored
Normal file
11
activesupport/test/fixtures/concern/some_concern.rb
vendored
Normal file
|
@ -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
|
Loading…
Reference in a new issue