@@ -215,6 +215,48 @@ def test_can_handle_parameter_error
215215 assert_equal "include" , error . source_parameter
216216 end
217217
218+ describe 'custom error_msg_key' do
219+ class CustomErrorArticle < TestResource
220+ def error_message_for ( error )
221+ error . detail
222+ end
223+ end
224+
225+ def test_can_handle_custom_parameter_error
226+ stub_request ( :post , "http://example.com/custom_error_articles" )
227+ . with ( headers : { content_type : "application/vnd.api+json" , accept : "application/vnd.api+json" } , body : {
228+ data : {
229+ type : "custom_error_articles" ,
230+ attributes : {
231+ title : "Rails is Omakase" ,
232+ email_address : "bar"
233+ }
234+ }
235+ } . to_json )
236+ . to_return ( headers : { content_type : "application/vnd.api+json" } , body : {
237+ errors : [
238+ {
239+ id : "1234-abcd" ,
240+ status : "400" ,
241+ code : "1337" ,
242+ title : "bar is required" ,
243+ detail : "bar include is required for creation" ,
244+ source : {
245+ parameter : "include"
246+ }
247+ }
248+ ]
249+ } . to_json )
250+
251+ article = CustomErrorArticle . create ( {
252+ title : "Rails is Omakase" ,
253+ email_address : "bar"
254+ } )
255+
256+ assert_equal [ "bar include is required for creation" ] , article . errors [ :base ]
257+ end
258+ end
259+
218260 def test_can_handle_explicit_null_error_values
219261 stub_request ( :post , "http://example.com/articles" )
220262 . with ( headers : { content_type : "application/vnd.api+json" , accept : "application/vnd.api+json" } , body : {
0 commit comments