vendredi 18 mai 2018

How to test deleting in Rails

I am working in Rails and setting up automated testing. I am getting a " No route matches [DELETE] '/adjusters/1/edit' " when I test my delete method. I know the delete method works because I have gone to the website and tested it myself. Here is the code I am using to test my delete. Does anyone see a reason why my test would not pass?

  # creating an instance variable to test with
  def setup
    @adjuster = Adjuster.create(adjuster_name: "TestLastName", address_1: "4511 W 200 S", id: 1)
  end

  # Testing going to an already created adjuster and deleting them
  test "get edit adjuster form and delete adjuster" do
    delete edit_adjuster_path(@adjuster)
    follow_redirect!
    assert_nil(@adjuster)
  end

I raked the routes from the console to ensure the route existed too.

DELETE /adjusters/:id(.:format)      adjusters#destroy

I have successfully used get edit_adjuster_path(@adjuster) to update their information.

Aucun commentaire:

Enregistrer un commentaire