diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 11 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 7 |
3 files changed, 19 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 1196065110..1ca945b8d3 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 550b657102..2f7812d17b 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1563,7 +1563,16 @@ module ActiveRecord #:nodoc: 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. diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index e66c90c7fe..1ad6e6c3ee 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -221,6 +221,13 @@ class BasicsTest < Test::Unit::TestCase 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") |