File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change
1
+ * Raise ` NoMethodError ` in ` ActiveModel::Type::Value#as_json ` to avoid unpredictable
2
+ results.
3
+
4
+ * Vasiliy Ermolovich*
5
+
1
6
* Custom attribute types that inherit from Active Model built-in types and do
2
7
not override the ` serialize ` method will now benefit from an optimization
3
8
when serializing attribute values for the database.
Original file line number Diff line number Diff line change @@ -135,6 +135,10 @@ def immutable_value(value) # :nodoc:
135
135
value
136
136
end
137
137
138
+ def as_json ( *)
139
+ raise NoMethodError
140
+ end
141
+
138
142
private
139
143
# Convenience method for types which do not need separate type casting
140
144
# behavior for user and database inputs. Called by Value#cast for
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require "cases/helper"
4
+ require "active_support/core_ext/object/json"
4
5
5
6
module ActiveModel
6
7
module Type
@@ -10,6 +11,12 @@ def test_type_equality
10
11
assert_not_equal Type ::Value . new , Type ::Integer . new
11
12
assert_not_equal Type ::Value . new ( precision : 1 ) , Type ::Value . new ( precision : 2 )
12
13
end
14
+
15
+ def test_as_json_not_defined
16
+ assert_raises NoMethodError do
17
+ Type ::Value . new . as_json
18
+ end
19
+ end
13
20
end
14
21
end
15
22
end
You can’t perform that action at this time.
0 commit comments