简体   繁体   中英

What does this mean? *** “Delete” argument “:destroy,” needs to be a number (Rails)

I'm trying to run the following tests for destroying a model object.

Here is one of the tests:

  it 'admin destroy' do
    login_as(admin)
    assert_difference('Topic.count', -1) do
      debugger;
      delete :destroy, id: topic.id
    end
    must_redirect_to forums_path
  end

This test fails to destroy a Topic model object. Placing a debugger; in the cod produces this;

在此处输入图片说明

What is this 'Delete argument destroy needs to be a number?'

My forums destroy test works perfectly. I don't understand what the problem is. Does anyone know what this means. I placed the exact error on Google but it leads to a bunch of links with destroy argument error problems. Help would be appreciated, Thanks.

---------EDIT---------

*At the top of my controller_test file I have let let(:topic) { create(:topic) } from FactoryGirl if anyone was wondering.

Your test fails because your topic object is created when topic is first referenced, ie inside the assert_difference block: the overall count does not change because the topic is both created and destroyed within the block, so the net difference is 0.

If you change the let to let! then the topic will be created earlier and your test should pass.

Your problems at the byebug console are because byebug thinks you are trying to execute byebug's delete command (that removes a breakpoint). You can force what you enter to be evaluated as ruby code with the e command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM