File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -169,9 +169,9 @@ def to_xml(options={})
169
169
to_a . to_xml options . reverse_merge ( :root => "errors" , :skip_types => true )
170
170
end
171
171
172
- # Returns an array as JSON representation for this object.
172
+ # Returns an ActiveSupport::OrderedHash that can be used as the JSON representation for this object.
173
173
def as_json ( options = nil )
174
- to_a
174
+ self
175
175
end
176
176
177
177
# Adds +message+ to the error messages on +attribute+, which will be returned on a call to
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ def setup
89
89
assert_match %r{"preferences":\{ "shows":"anime"\} } , json
90
90
end
91
91
92
- test "methds are called on object" do
92
+ test "methods are called on object" do
93
93
# Define methods on fixture.
94
94
def @contact . label ; "Has cheezburger" ; end
95
95
def @contact . favorite_quote ; "Constraints are liberating" ; end
@@ -102,4 +102,18 @@ def @contact.favorite_quote; "Constraints are liberating"; end
102
102
assert_match %r{"label":"Has cheezburger"} , methods_json
103
103
assert_match %r{"favorite_quote":"Constraints are liberating"} , methods_json
104
104
end
105
+
106
+ test "should return OrderedHash for errors" do
107
+ car = Automobile . new
108
+
109
+ # run the validation
110
+ car . valid?
111
+
112
+ hash = ActiveSupport ::OrderedHash . new
113
+ hash [ :make ] = "can't be blank"
114
+ hash [ :model ] = "is too short (minimum is 2 characters)"
115
+ assert_equal hash . to_json , car . errors . to_json
116
+ end
117
+
118
+
105
119
end
Original file line number Diff line number Diff line change @@ -170,9 +170,11 @@ def test_errors_conversions
170
170
assert_match %r{<errors>} , xml
171
171
assert_match %r{<error>Title can't be blank</error>} , xml
172
172
assert_match %r{<error>Content can't be blank</error>} , xml
173
-
174
- json = t . errors . to_json
175
- assert_equal t . errors . to_a . to_json , json
173
+
174
+ hash = ActiveSupport ::OrderedHash . new
175
+ hash [ :title ] = "can't be blank"
176
+ hash [ :content ] = "can't be blank"
177
+ assert_equal t . errors . to_json , hash . to_json
176
178
end
177
179
178
180
def test_validation_order
You can’t perform that action at this time.
0 commit comments