1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Do not in place modify what table_name returns

This commit is contained in:
Santiago Pastorino 2011-03-18 13:35:57 -03:00
parent e06c448002
commit da6c7bd4b4
3 changed files with 2 additions and 13 deletions

View file

@ -107,7 +107,7 @@ module ActiveModel
sing.send :define_method, name, &block sing.send :define_method, name, &block
else else
value = value.to_s if value value = value.to_s if value
sing.send(:define_method, name) { value && value.dup } sing.send(:define_method, name) { value }
end end
end end

View file

@ -9,10 +9,6 @@ class ModelWithAttributes
define_method(:bar) do define_method(:bar) do
'original bar' 'original bar'
end end
define_method(:zomg) do
'original zomg'
end
end end
def attributes def attributes
@ -102,13 +98,6 @@ class AttributeMethodsTest < ActiveModel::TestCase
assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.send(:'foo bar') assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.send(:'foo bar')
end end
def test_defined_methods_always_return_duped_string
ModelWithAttributes.define_attr_method(:zomg, 'lol')
assert_equal 'lol', ModelWithAttributes.zomg
ModelWithAttributes.zomg << 'bbq'
assert_equal 'lol', ModelWithAttributes.zomg
end
test '#define_attr_method generates attribute method' do test '#define_attr_method generates attribute method' do
ModelWithAttributes.define_attr_method(:bar, 'bar') ModelWithAttributes.define_attr_method(:bar, 'bar')

View file

@ -995,7 +995,7 @@ module ActiveRecord #:nodoc:
if parent < ActiveRecord::Base && !parent.abstract_class? if parent < ActiveRecord::Base && !parent.abstract_class?
contained = parent.table_name contained = parent.table_name
contained = contained.singularize if parent.pluralize_table_names contained = contained.singularize if parent.pluralize_table_names
contained << '_' contained += '_'
end end
"#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}" "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}"
else else