0

I'm using Rails 4.2.5, I've written a controller test for the destroy action, an I'm using ajax call to destroy and using destroy.js.erb file. Please help me to solve the following issue to pass the test when it calls js format, I'm pasting error below.

  def destroy  
    @status = @song.destroy  
    respond_to do |format|  
      format.js  
    end  
  end  

SongsControllerTest#test_should_destroy_song:

ActionController::UnknownFormat: ActionController::UnknownFormat  
      app/controllers/songs_controller.rb:36:in `destroy' 


songs_controller_test.rb    
test "should destroy song" do  
    assert_difference('Song.count', -1) do  
      delete :destroy, id: @song  
    end  

    get :destroy, format:  'js'  
  end  

destroy.js.erb

var element = document.getElementById("<%="song#{@song.id}" %>");    
<%if @status%>  
element.parentNode.parentNode.remove();  
<%end%>  
Manoj Menon
  • 1,028
  • 8
  • 18

1 Answers1

3

The destroy controller action normally reacts to the DELETE HTTP method, so you should use the format option when calling delete:

test "should destroy song" do  
  assert_difference('Song.count', -1) do  
    delete :destroy, id: @song, format: :js
  end  
end  
Matouš Borák
  • 15,606
  • 1
  • 42
  • 53