@@ -19,6 +19,10 @@ def attributes
19
19
def attribute ( name )
20
20
attributes [ name . to_sym ]
21
21
end
22
+
23
+ def attribute_method? ( name )
24
+ attributes . include? ( name . to_sym )
25
+ end
22
26
end
23
27
24
28
class ModelWithAttributes2
@@ -236,11 +240,11 @@ def foo
236
240
end
237
241
238
242
test "#undefine_attribute_methods removes attribute methods" do
239
- ModelWithAttributes . define_attribute_methods ( :foo )
240
- ModelWithAttributes . undefine_attribute_methods
243
+ ModelWithoutAttributesMethod . define_attribute_methods ( :foo )
244
+ assert_respond_to ModelWithoutAttributesMethod . new , :foo
241
245
242
- assert_not_respond_to ModelWithAttributes . new , :foo
243
- assert_raises ( NoMethodError ) { ModelWithAttributes . new . foo }
246
+ ModelWithoutAttributesMethod . undefine_attribute_methods
247
+ assert_not_respond_to ModelWithoutAttributesMethod . new , :foo
244
248
end
245
249
246
250
test "#undefine_attribute_methods undefines alias attribute methods" do
@@ -341,6 +345,25 @@ def m.attribute_missing(match, *args, &block)
341
345
assert_equal "attribute_test" , match . proxy_target
342
346
end
343
347
348
+ test "should use attribute_missing to dispatch a missing attribute alias" do
349
+ klass = Class . new ( ModelWithAttributes ) do
350
+ define_attribute_method ( :foo )
351
+ alias_attribute :foo2 , :foo
352
+ end
353
+
354
+ m = klass . new
355
+ def m . attribute_missing ( match , ...)
356
+ match
357
+ end
358
+ klass . undef_method :foo
359
+ klass . undef_method :foo2
360
+
361
+ match = m . foo2
362
+
363
+ assert_equal "foo" , match . attr_name
364
+ assert_equal "attribute" , match . proxy_target
365
+ end
366
+
344
367
module NameClash
345
368
class Model1
346
369
include ActiveModel ::AttributeMethods
0 commit comments