{"action":"opened","issue":{"url":"https://api.github.com/repos/rails/rails/issues/21545","labels_url":"https://api.github.com/repos/rails/rails/issues/21545/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/21545/comments","events_url":"https://api.github.com/repos/rails/rails/issues/21545/events","html_url":"https://github.com/rails/rails/issues/21545","id":105341866,"number":21545,"title":"Rails 4.1 ActionController::TestCase::Behavior strange behaviour while sending the JSON data","user":{"login":"DreamWalker87","id":7327013,"avatar_url":"https://avatars.githubusercontent.com/u/7327013?v=3","gravatar_id":"","url":"https://api.github.com/users/DreamWalker87","html_url":"https://github.com/DreamWalker87","followers_url":"https://api.github.com/users/DreamWalker87/followers","following_url":"https://api.github.com/users/DreamWalker87/following{/other_user}","gists_url":"https://api.github.com/users/DreamWalker87/gists{/gist_id}","starred_url":"https://api.github.com/users/DreamWalker87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DreamWalker87/subscriptions","organizations_url":"https://api.github.com/users/DreamWalker87/orgs","repos_url":"https://api.github.com/users/DreamWalker87/repos","events_url":"https://api.github.com/users/DreamWalker87/events{/privacy}","received_events_url":"https://api.github.com/users/DreamWalker87/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-08T09:45:59Z","updated_at":"2015-09-08T09:45:59Z","closed_at":null,"body":"Hello.\r\n\r\nI've discovered a strange behavior: Rails, seems, is unable to properly parse the JSON data if it was send by methods from ActionController::TestCase::Behavior. \r\n\r\nIn the doc it'is mentioned that sending an entire JSON document is possible:\r\n>  # You can also send a real document in the simulated HTTP request.\r\n>  #\r\n>  #   def test_create\r\n>  #     json = {book: { title: \"Love Hina\" }}.to_json\r\n>  #     post :create, json\r\n>  #   end\r\n\r\nbut this causes **param is missing or vlue is empty** error, though the request body contains the proper JSON document, e. g. ```\"{\\\"book\\\":{\\\"title\\\":\\\"Love Hina\\\"}}\"```. So, **request.params** would return ```{\"controller\"=>\"api/books\", \"action\"=>\"create\", \"book\"=>{}}``` in this case. But this doesn't happen if:\r\n* I don't send the JSON data\r\n\r\n  E. g. ```post :create, book: {title: 'Love Hina'}``` would be properly parsed and  **request.params** would return ```{\"controller\"=>\"api/books\", \"action\"=>\"create\", \"book\"=>{\"title\"=>\"Love Hina\"}}```\r\n* I send the same JSON data with curl:\r\n```\r\ncurl -i -X POST -d '{\\\"book\\\":{\\\"title\\\":\\\"Love Hina\\\"}}' \\\r\n-H \"Accept: application/json\" \\ \r\n-H \"Content-Type: application/json\" http://api.example.com:3000/books\r\n```\r\n  The request body would contain the *same* JSON, but this time it would be parsed properly. Bizarre!\r\n \r\nController and test scenarios examples are [here](http://stackoverflow.com/questions/32203124/rails-4-1-1-param-is-missing-or-value-is-empty-while-sending-json-with-rspec).\r\n\r\nP. S.: In the first case I also cared about setting the proper content type."}}