Testing, Attachment Fu, and Restful Authentication

Posted by mikong on June 18, 2008

You’re writing a test that involves photo uploading. You use the fixture_file_upload method to generate the data of your :uploaded_data field. Running the test that includes creating a photo object, you get an error:

  wrong number of arguments (0 for 1)

  /vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:line=351 :in 'content_type'
  /vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:line=351 :in 'send'
  /vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:line=351 :in 'attachment_attributes_valid?'
  ...

The error means you called the content_type method of your object with no arguments, when it was expecting 1. It was expecting 1, even though content_type should have been an attribute reader method with no arguments.

Why?

Because when you generated the users_controller_spec.rb using the generator of the Restful Authentication plugin, the comment said you should move the include AuthenticatedTestHelper to spec_helper.rb. And you did. And the AuthenticatedTestHelper module defines a content_type method with 1 argument that gets added to the Object class.

And this is why some people warn you about monkey patching.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

Comments