From 52320775175275379b1b215274dc26bed7f43634 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 16 Mar 2011 19:31:57 -0300 Subject: Add test for define_attr_method using as name an invalid identifier --- activemodel/test/cases/attribute_methods_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/activemodel/test/cases/attribute_methods_test.rb b/activemodel/test/cases/attribute_methods_test.rb index 4cfec66015..3df76295cf 100644 --- a/activemodel/test/cases/attribute_methods_test.rb +++ b/activemodel/test/cases/attribute_methods_test.rb @@ -41,6 +41,12 @@ class ModelWithWeirdNamesAttributes attribute_method_suffix '' + class << self + define_method(:'c?d') do + 'c?d' + end + end + def attributes { :'a?b' => 'value of a?b' } end @@ -86,6 +92,13 @@ class AttributeMethodsTest < ActiveModel::TestCase assert_equal "value of foo bar", ModelWithAttributesWithSpaces.new.send(:'foo bar') end + test '#define_attr_method generates attribute method with invalid identifier characters' do + ModelWithWeirdNamesAttributes.define_attr_method(:'c?d', 'c?d') + + assert_respond_to ModelWithWeirdNamesAttributes, :'c?d' + assert_equal "c?d", ModelWithWeirdNamesAttributes.send('c?d') + end + test '#alias_attribute works with attributes with spaces in their names' do ModelWithAttributesWithSpaces.define_attribute_methods([:'foo bar']) ModelWithAttributesWithSpaces.alias_attribute(:'foo_bar', :'foo bar') -- cgit v1.2.3