Skip to content

Commit

Permalink
Do nothing when the same block is included again.
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
mjtko committed Nov 29, 2018
1 parent 4b5c4ca commit 8212dfc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 4 additions & 0 deletions 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`.

Expand Down
10 changes: 7 additions & 3 deletions activesupport/lib/active_support/concern.rb
Expand Up @@ -125,9 +125,13 @@ def append_features(base)

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
Expand Down
8 changes: 8 additions & 0 deletions activesupport/test/concern_test.rb
Expand Up @@ -128,4 +128,12 @@ def test_raise_on_multiple_included_calls
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 changes: 11 additions & 0 deletions 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

0 comments on commit 8212dfc

Please sign in to comment.