@@ -2159,11 +2159,8 @@ def test_create_simple_namespaced
21592159end
21602160
21612161class FactsControllerTest < ActionController ::TestCase
2162- def setup
2163- JSONAPI . configuration . json_key_format = :camelized_key
2164- end
2165-
21662162 def test_type_formatting
2163+ JSONAPI . configuration . json_key_format = :camelized_key
21672164 get :show , { id : '1' }
21682165 assert_response :success
21692166 assert json_response [ 'data' ] . is_a? ( Hash )
@@ -2177,6 +2174,40 @@ def test_type_formatting
21772174 assert_equal 'abc' , json_response [ 'data' ] [ 'attributes' ] [ 'photo' ]
21782175 assert_equal false , json_response [ 'data' ] [ 'attributes' ] [ 'cool' ]
21792176 end
2177+
2178+ def test_create_with_invalid_data
2179+ JSONAPI . configuration . json_key_format = :dasherized_key
2180+ set_content_type_header!
2181+ post :create ,
2182+ {
2183+ data : {
2184+ type : 'facts' ,
2185+ attributes : {
2186+ bio : '' ,
2187+ :"quality-rating" => '' ,
2188+ :"spouse-name" => '' ,
2189+ salary : 100000 ,
2190+ :"date-time-joined" => '' ,
2191+ birthday : '' ,
2192+ bedtime : '' ,
2193+ photo : 'abc' ,
2194+ cool : false
2195+ } ,
2196+ relationships : {
2197+ }
2198+ }
2199+ }
2200+
2201+ assert_response :unprocessable_entity
2202+
2203+ assert_equal "/data/attributes/spouse-name" , json_response [ 'errors' ] [ 0 ] [ 'source' ] [ 'pointer' ]
2204+ assert_equal "can't be blank" , json_response [ 'errors' ] [ 0 ] [ 'detail' ]
2205+ assert_equal "spouse-name - can't be blank" , json_response [ 'errors' ] [ 0 ] [ 'title' ]
2206+
2207+ assert_equal "/data/attributes/bio" , json_response [ 'errors' ] [ 1 ] [ 'source' ] [ 'pointer' ]
2208+ assert_equal "can't be blank" , json_response [ 'errors' ] [ 1 ] [ 'detail' ]
2209+ assert_equal "bio - can't be blank" , json_response [ 'errors' ] [ 1 ] [ 'title' ]
2210+ end
21802211end
21812212
21822213class Api ::V2 ::BooksControllerTest < ActionController ::TestCase
0 commit comments