提交 b8ea04f8 编写于 作者: J Jeremy Kemper

r3167@asus: jeremy | 2005-11-18 22:47:31 -0800

 Apply [3089] to stable.  Don't generate read methods for columns whose names are not valid ruby method names.  Closes #2946.


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3090 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 beddd968
*SVN*
* Don't generate read methods for columns whose names are not valid ruby method names. #2946 [Stefan Kaes]
* Document :force option to create_table. #2921 [Blair Zajac <blair@orcaware.com>]
* Don't add the same conditions twice in has_one finder sql. #2916 [Jeremy Evans]
......
......@@ -1556,7 +1556,16 @@ def define_read_method(symbol, attr_name, column)
self.class.read_methods << attr_name
end
self.class.class_eval("def #{symbol}; #{access_code}; end")
begin
self.class.class_eval("def #{symbol}; #{access_code}; end")
rescue SyntaxError => err
self.class.read_methods.delete(attr_name)
if logger
logger.warn "Exception occured during reader method compilation."
logger.warn "Maybe #{attr_name} is not a valid Ruby identifier?"
logger.warn "#{err.message}"
end
end
end
# Returns true if the attribute is of a text column and marked for serialization.
......
......@@ -221,6 +221,13 @@ def test_reader_generation
end
end
def test_reader_for_invalid_column_names
# column names which aren't legal ruby ids
topic = Topic.find(:first)
topic.send(:define_read_method, "mumub-jumbo".to_sym, "mumub-jumbo", nil)
assert !Topic.read_methods.include?("mumub-jumbo")
end
def test_non_attribute_access_and_assignment
topic = Topic.new
assert !topic.respond_to?("mumbo")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册