File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ * ` undefine_attribute_methods ` undefines alias attribute methods along with attribute methods.
2
+
3
+ * Nikita Vasilevsky*
4
+
1
5
* Error.full_message now strips ": base " from the message.
2
6
3
7
* zzak*
Original file line number Diff line number Diff line change @@ -215,6 +215,30 @@ def foo
215
215
assert_raises ( NoMethodError ) { ModelWithAttributes . new . foo }
216
216
end
217
217
218
+ test "#undefine_attribute_methods undefines alias attribute methods" do
219
+ topic_class = Class . new do
220
+ include ActiveModel ::AttributeMethods
221
+ define_attribute_methods :title
222
+ alias_attribute :subject_to_be_undefined , :title
223
+
224
+ def attributes
225
+ { title : "Active Model Topic" }
226
+ end
227
+
228
+ private
229
+ def attribute ( name )
230
+ attributes [ name . to_sym ]
231
+ end
232
+ end
233
+
234
+ assert_equal ( "Active Model Topic" , topic_class . new . subject_to_be_undefined )
235
+ topic_class . undefine_attribute_methods
236
+
237
+ assert_raises ( NoMethodError , match : /undefined method `subject_to_be_undefined'/ ) do
238
+ topic_class . new . subject_to_be_undefined
239
+ end
240
+ end
241
+
218
242
test "accessing a suffixed attribute" do
219
243
m = ModelWithAttributes2 . new
220
244
m . attributes = { "foo" => "bar" }
Original file line number Diff line number Diff line change @@ -1022,6 +1022,22 @@ def name
1022
1022
assert subklass . method_defined? ( :id ) , "subklass is missing id method"
1023
1023
end
1024
1024
1025
+ test "#undefine_attribute_methods undefines alias attribute methods" do
1026
+ topic_class = Class . new ( ActiveRecord ::Base ) do
1027
+ self . table_name = "topics"
1028
+
1029
+ alias_attribute :subject_to_be_undefined , :title
1030
+ end
1031
+
1032
+ topic = topic_class . new ( title : "New topic" )
1033
+ assert_equal ( "New topic" , topic . subject_to_be_undefined )
1034
+ topic_class . undefine_attribute_methods
1035
+
1036
+ assert_raises ( NoMethodError , match : /undefined method `subject_to_be_undefined'/ ) do
1037
+ topic . subject_to_be_undefined
1038
+ end
1039
+ end
1040
+
1025
1041
test "define_attribute_method works with both symbol and string" do
1026
1042
klass = Class . new ( ActiveRecord ::Base )
1027
1043
klass . table_name = "foo"
You can’t perform that action at this time.
0 commit comments