I'm not commenting on your testing methods but in most cases of your code examples, the syntax is more like JSON instead of ruby hashes. Use :player => { :player_name => "usman", ... }
. You can either use strings 'player'
or ruby symbols :player
as keys.
A more complete example with your render
call:
render :json => {:error => "Player name already exists."}, :status => :unprocessable_entity
Ruby will convert the hash to JSON itself. Or you can do it manually by calling .to_json
on it.