1
0
Fork 0
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:
Aaron Patterson 2013-08-01 10:53:56 -07:00
parent 92ab4d6a8a
commit 655953cd48
2 changed files with 11 additions and 9 deletions

View file

@ -12,7 +12,7 @@ module ActiveRecord::Associations::Builder
:after_add, :before_remove, :after_remove, :extend]
end
attr_reader :block_extension, :extension_module
attr_reader :block_extension
def initialize(*args, &extension)
super(*args)
@ -20,7 +20,7 @@ module ActiveRecord::Associations::Builder
end
def build
wrap_block_extension
define_extensions(model)
reflection = super
reflection
end
@ -30,7 +30,7 @@ module ActiveRecord::Associations::Builder
CALLBACKS.each { |callback_name| define_callback(model, callback_name) }
end
def wrap_block_extension
def define_extensions(model)
if block_extension
@extension_module = mod = Module.new(&block_extension)
silence_warnings do

View file

@ -59,9 +59,12 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
end
def test_extension_name
assert_equal 'DeveloperAssociationNameAssociationExtension', extension_name(Developer)
assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', extension_name(MyApplication::Business::Developer)
assert_equal 'MyApplication::Business::DeveloperAssociationNameAssociationExtension', extension_name(MyApplication::Business::Developer)
extend!(Developer)
extend!(MyApplication::Business::Developer)
extend!(MyApplication::Business::Developer)
assert Object.const_get 'DeveloperAssociationNameAssociationExtension'
assert MyApplication::Business.const_get 'DeveloperAssociationNameAssociationExtension'
end
def test_proxy_association_after_scoped
@ -72,9 +75,8 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
private
def extension_name(model)
def extend!(model)
builder = ActiveRecord::Associations::Builder::HasMany.new(model, :association_name, nil, {}) { }
builder.send(:wrap_block_extension)
builder.extension_module.name
builder.define_extensions(model)
end
end