mercredi 24 octobre 2018

How to get a controller test to process an action as JS, rather than HTML?

Whenever I try to test the update action for a controller, I receive the following error message:

ArgumentError: wrong number of arguments (given 2, expected 0)

Here's the spot in the controller that receives the error:

def update 
  ...
  # \/ This line causing the error \/
  if @image.update(image_params.except(:image_tags_attributes))
    if image_params[:crop_x].present?
    ...

As far as I can tell, I'm passing everything in for the test in the same manner as I do on the development side. However, there's one things I've noticed. The test attempts to process the update action as HTML whereas the development server rightly processes the action as JS (see log outputs below). Is that possibly what's causing the issue? If so, how can I instruct it to process the action as JS?

UPDATE: I should also say that in this test, I'm not concerned with the view output, I'm only trying to test what happens in the back-end on the database side of things.

This is my first foray into attempting to test code that in some way, shape, or form involves Javascript so this is admittedly new territory for me. Thank you in advance for any help and insights you can offer!

test.log

Processing by ImagesController#update as HTML
  Parameters: {"image"=>{"crop_x"=>"100", "crop_y"=>"100", "crop_w"=>"100", "crop_h"=>"100", "crop_rotation_angle"=>"0", "image_tags_attributes"=>{"tag_title_attributes"=>{"title"=>"MyTitle1"}, "tag_content_attributes"=>{"content"=>""}}}, "id"=>"249799255"}

development.log

Processing by ImagesController#update as JS
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"IUXYLsxSoD/OYdnm5TH/3jNbaG+7bkwZJL39p/vePkEXrnNk3J+1nrFkgIT3rsQeFmzRdt5kRMO+Vpjo7F5BCg==", "image"=>{"image_tags_attributes"=>{"tag_title_attributes"=>{"title"=>"page number"}, "tag_content_attributes"=>{"content"=>""}}, "crop_x"=>"42.73287586330139", "crop_y"=>"45.58570767432143", "crop_w"=>"123.71134020618558", "crop_h"=>"117.08396046432024", "crop_rotation_angle"=>"0"}, "button"=>"", "id"=>"2"}

Aucun commentaire:

Enregistrer un commentaire