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%>  
5
  • Please format the code in the question accordingly and show the test code too. Commented Mar 27, 2016 at 6:26
  • Possible duplicate of In Rails, how do you functional test a Javascript response format? Commented Mar 27, 2016 at 6:28
  • Already before asking question ive tried above link, it didnt solve the error Commented Mar 27, 2016 at 6:34
  • Please post the code of your test as well. Commented Mar 27, 2016 at 7:43
  • @ThomasR.Koll updated code, pls have a look Commented Mar 27, 2016 at 8:04

1 Answer 1

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  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.