mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
assert that constants have been set rather than the names
This commit is contained in:
parent
92ab4d6a8a
commit
655953cd48
2 changed files with 11 additions and 9 deletions
|
@ -12,7 +12,7 @@ module ActiveRecord::Associations::Builder
|
||||||
:after_add, :before_remove, :after_remove, :extend]
|
:after_add, :before_remove, :after_remove, :extend]
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :block_extension, :extension_module
|
attr_reader :block_extension
|
||||||
|
|
||||||
def initialize(*args, &extension)
|
def initialize(*args, &extension)
|
||||||
super(*args)
|
super(*args)
|
||||||
|
@ -20,7 +20,7 @@ module ActiveRecord::Associations::Builder
|
||||||
end
|
end
|
||||||
|
|
||||||
def build
|
def build
|
||||||
wrap_block_extension
|
define_extensions(model)
|
||||||
reflection = super
|
reflection = super
|
||||||
reflection
|
reflection
|
||||||
end
|
end
|
||||||
|
@ -30,7 +30,7 @@ module ActiveRecord::Associations::Builder
|
||||||
CALLBACKS.each { |callback_name| define_callback(model, callback_name) }
|
CALLBACKS.each { |callback_name| define_callback(model, callback_name) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_block_extension
|
def define_extensions(model)
|
||||||
if block_extension
|
if block_extension
|
||||||
@extension_module = mod = Module.new(&block_extension)
|
@extension_module = mod = Module.new(&block_extension)
|
||||||
silence_warnings do
|
silence_warnings do
|
||||||
|
|
|
@ -59,9 +59,12 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_extension_name
|
def test_extension_name
|
||||||
assert_equal 'DeveloperAssociationNameAssociationExtension', extension_name(Developer)
|
extend!(Developer)
|
||||||
assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', extension_name(MyApplication::Business::Developer)
|
extend!(MyApplication::Business::Developer)
|
||||||
assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', extension_name(MyApplication::Business::Developer)
|
extend!(MyApplication::Business::Developer)
|
||||||
|
|
||||||
|
assert Object.const_get 'DeveloperAssociationNameAssociationExtension'
|
||||||
|
assert MyApplication::Business.const_get 'DeveloperAssociationNameAssociationExtension'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_proxy_association_after_scoped
|
def test_proxy_association_after_scoped
|
||||||
|
@ -72,9 +75,8 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def extension_name(model)
|
def extend!(model)
|
||||||
builder = ActiveRecord::Associations::Builder::HasMany.new(model, :association_name, nil, {}) { }
|
builder = ActiveRecord::Associations::Builder::HasMany.new(model, :association_name, nil, {}) { }
|
||||||
builder.send(:wrap_block_extension)
|
builder.define_extensions(model)
|
||||||
builder.extension_module.name
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue