{"action":"closed","issue":{"url":"https://api.github.com/repos/rspec/rspec-rails/issues/1618","repository_url":"https://api.github.com/repos/rspec/rspec-rails","labels_url":"https://api.github.com/repos/rspec/rspec-rails/issues/1618/labels{/name}","comments_url":"https://api.github.com/repos/rspec/rspec-rails/issues/1618/comments","events_url":"https://api.github.com/repos/rspec/rspec-rails/issues/1618/events","html_url":"https://github.com/rspec/rspec-rails/issues/1618","id":154603560,"number":1618,"title":"expect(response).to redirect_to(document_path(assigns(:document))) fails with missing [:id]","user":{"login":"mbmasuda","id":1646132,"avatar_url":"https://avatars.githubusercontent.com/u/1646132?v=3","gravatar_id":"","url":"https://api.github.com/users/mbmasuda","html_url":"https://github.com/mbmasuda","followers_url":"https://api.github.com/users/mbmasuda/followers","following_url":"https://api.github.com/users/mbmasuda/following{/other_user}","gists_url":"https://api.github.com/users/mbmasuda/gists{/gist_id}","starred_url":"https://api.github.com/users/mbmasuda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbmasuda/subscriptions","organizations_url":"https://api.github.com/users/mbmasuda/orgs","repos_url":"https://api.github.com/users/mbmasuda/repos","events_url":"https://api.github.com/users/mbmasuda/events{/privacy}","received_events_url":"https://api.github.com/users/mbmasuda/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-12T23:28:37Z","updated_at":"2016-05-12T23:44:24Z","closed_at":"2016-05-12T23:44:24Z","body":"Hi,\r\n\r\nI have a couple of similar controller tests.  One is passing and the other is not, and I can't figure out what the difference is or where I've gone wrong.  I am using RSpec-Rails 3.4 and Rails 4.2.6.\r\n\r\nThe passing test:\r\n\r\n```\r\n  describe \"POST #create as devcomm\" do\r\n    it \"returns http success\" do\r\n      devcomm_user\r\n      expect { post :create, project: {parent_id: nil, name: \"Test\", is_secret: false, disclosed_user_ids: []} }.to change(Project, :count).by(1)\r\n      expect(response).to redirect_to(project_path(assigns(:project)))\r\n    end\r\n  end\r\n```\r\n\r\nThe passing test controller:\r\n\r\n```\r\n  def create\r\n    @project = Project.new(project_params)\r\n\r\n    if @project.save\r\n      redirect_to @project, notice: 'Project successfully created.'\r\n    else\r\n      render \"new\"\r\n    end\r\n  end\r\n```\r\n\r\nThe failing test:\r\n\r\n```\r\n  describe \"POST #create\" do\r\n    it \"as devcomm returns http success\" do\r\n      devcomm_user\r\n      expect { post :create, document: {project_id: projects(:nonsecretproject1), name: \"Test Document\", is_secret: false, owner_ids: [users(:devcomm1)], reviewer_ids: [users(:nondevcomm1)]} }.to change(Document, :count).by(1)\r\n      expect(response).to redirect_to(document_path(assigns(:document)))  ### fails here\r\n    end\r\n  end\r\n```\r\n\r\nThe failing test controller:\r\n\r\n```\r\n  def create\r\n    @doc = Document.new(document_params)\r\n\r\n    if @doc.save\r\n      redirect_to @doc, notice: 'Document successfully created.'\r\n    else\r\n      render \"new\"\r\n    end\r\n  end\r\n```\r\n\r\nThe error:\r\n\r\n```\r\n  2) DocumentsController POST #create as devcomm returns http success\r\n     Failure/Error: expect(response).to redirect_to(document_path(assigns(:document)))\r\n     \r\n     ActionController::UrlGenerationError:\r\n       No route matches {:action=>\"show\", :controller=>\"documents\", :id=>nil} missing required keys: [:id]\r\n     # ./spec/controllers/documents_controller_spec.rb:38:in `block (3 levels) in <top (required)>'\r\n```\r\n\r\n\r\nMy routes:\r\n\r\n```\r\n                                 Prefix Verb   URI Pattern                                                                                  Controller#Action\r\n                                   root GET    /                                                                                            index#dashboard\r\n                  create_user_from_ajax POST   /create_user_from_ajax(.:format)                                                             users#create_user_from_ajax\r\n        populate_document_reviewer_list GET    /populate_document_reviewer_list(.:format)                                                   documents#populate_document_reviewer_list\r\n                                  users GET    /users(.:format)                                                                             users#index\r\n                                        POST   /users(.:format)                                                                             users#create\r\n                               new_user GET    /users/new(.:format)                                                                         users#new\r\n                              edit_user GET    /users/:id/edit(.:format)                                                                    users#edit\r\n                                   user GET    /users/:id(.:format)                                                                         users#show\r\n                                        PATCH  /users/:id(.:format)                                                                         users#update\r\n                                        PUT    /users/:id(.:format)                                                                         users#update\r\n                                        DELETE /users/:id(.:format)                                                                         users#destroy\r\n                               projects GET    /projects(.:format)                                                                          projects#index\r\n                                        POST   /projects(.:format)                                                                          projects#create\r\n                            new_project GET    /projects/new(.:format)                                                                      projects#new\r\n                           edit_project GET    /projects/:id/edit(.:format)                                                                 projects#edit\r\n                                project GET    /projects/:id(.:format)                                                                      projects#show\r\n                                        PATCH  /projects/:id(.:format)                                                                      projects#update\r\n                                        PUT    /projects/:id(.:format)                                                                      projects#update\r\n                                        DELETE /projects/:id(.:format)                                                                      projects#destroy\r\n    document_document_revision_comments GET    /documents/:document_id/document_revisions/:document_revision_id/comments(.:format)          comments#index\r\n                                        POST   /documents/:document_id/document_revisions/:document_revision_id/comments(.:format)          comments#create\r\n new_document_document_revision_comment GET    /documents/:document_id/document_revisions/:document_revision_id/comments/new(.:format)      comments#new\r\nedit_document_document_revision_comment GET    /documents/:document_id/document_revisions/:document_revision_id/comments/:id/edit(.:format) comments#edit\r\n     document_document_revision_comment GET    /documents/:document_id/document_revisions/:document_revision_id/comments/:id(.:format)      comments#show\r\n                                        PATCH  /documents/:document_id/document_revisions/:document_revision_id/comments/:id(.:format)      comments#update\r\n                                        PUT    /documents/:document_id/document_revisions/:document_revision_id/comments/:id(.:format)      comments#update\r\n                                        DELETE /documents/:document_id/document_revisions/:document_revision_id/comments/:id(.:format)      comments#destroy\r\n            document_document_revisions GET    /documents/:document_id/document_revisions(.:format)                                         document_revisions#index\r\n                                        POST   /documents/:document_id/document_revisions(.:format)                                         document_revisions#create\r\n         new_document_document_revision GET    /documents/:document_id/document_revisions/new(.:format)                                     document_revisions#new\r\n        edit_document_document_revision GET    /documents/:document_id/document_revisions/:id/edit(.:format)                                document_revisions#edit\r\n             document_document_revision GET    /documents/:document_id/document_revisions/:id(.:format)                                     document_revisions#show\r\n                                        PATCH  /documents/:document_id/document_revisions/:id(.:format)                                     document_revisions#update\r\n                                        PUT    /documents/:document_id/document_revisions/:id(.:format)                                     document_revisions#update\r\n                                        DELETE /documents/:document_id/document_revisions/:id(.:format)                                     document_revisions#destroy\r\n                              documents GET    /documents(.:format)                                                                         documents#index\r\n                                        POST   /documents(.:format)                                                                         documents#create\r\n                           new_document GET    /documents/new(.:format)                                                                     documents#new\r\n                          edit_document GET    /documents/:id/edit(.:format)                                                                documents#edit\r\n                               document GET    /documents/:id(.:format)                                                                     documents#show\r\n                                        PATCH  /documents/:id(.:format)                                                                     documents#update\r\n                                        PUT    /documents/:id(.:format)                                                                     documents#update\r\n                                        DELETE /documents/:id(.:format)                                                                     documents#destroy\r\n```\r\n\r\n\r\nAccording to https://www.relishapp.com/rspec/rspec-rails/v/3-4/docs/matchers/redirect-to-matcher I believe my failing test is written correctly.  However, when I change the failing line to `expect(response).to redirect_to(assigns(:document))` I get a different error message:\r\n\r\n```\r\n  3) DocumentsController POST #create as devcomm returns http success\r\n     Failure/Error: expect(response).to redirect_to(assigns(:document))\r\n     \r\n       Expected response to be a redirect to <http://test.host/documents> but was a redirect to <http://test.host/documents/319073037>.\r\n       Expected \"http://test.host/documents\" to be === \"http://test.host/documents/319073037\".\r\n     # ./spec/controllers/documents_controller_spec.rb:38:in `block (3 levels) in <top (required)>'\r\n```"}}