Permalink
Browse files

Don't generate read methods for columns whose names are not valid rub…

…y method names. References #2946.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3089 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
jeremy committed Nov 19, 2005
1 parent b3c65bc commit b51c3399eb0cbf07e64bd7a33d176eae3010d5c0
Showing with 19 additions and 1 deletion.
  1. +2 −0 activerecord/CHANGELOG
  2. +10 −1 activerecord/lib/active_record/base.rb
  3. +7 −0 activerecord/test/base_test.rb
View
@@ -1,5 +1,7 @@
*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]
@@ -1563,7 +1563,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")

0 comments on commit b51c339

Please sign in to comment.