views:

370

answers:

3

Since a short time my rails applications yields the following runtime error in the test suite:

RuntimeError: Declare either attr_protected or attr_accessible for User, but not both.

This was probably introduced by an update to restful_authentication. But scanning the code for "attr_protected" only shows me it is never called. So why this error message?

My user model only has the following code:

attr_accessible :login, :email, :name, :password, :password_confirmation, :identity_url

So it should be perfectly okay? Any clues where to look for the problem? Searching google shows a few clueless people who also see this problem only in test environment and sporadically in the development environment.

A: 

You might have included modules into the User class that declare attr_protected. Maybe some kind of testing functionality does that.

Pavel Shved
I grepped the whole source tree for "attr_protected" - nothing there (at least nowhere related to the user model).
hurikhan77
A: 

This could be due to a plugin adding attr_protected. This might be helpful.

Sam Soffes
Indeed a plugin added attr_protected to my User model (it was RestfulAuthentication itself as far as I traced it but I'm not going to look into that further as I'm going to dump RA in favor of AuthLogic).
hurikhan77
+1  A: 

If you are using RestfulAuthentication with friendly_id, the latest version of friendly_id can bring this error as indicated on the github page:

Also, this feature uses attr_protected to protect the cached_slug column, unless you have already invoked attr_accessible. So if you wish to use attr_accessible, you must invoke it BEFORE you invoke has_friendly_id in your class. github page

Also, when using grep to find occurences of keywords, don't forget to grep also in gems as you may have installed some plugins as gem archive.

Fabrice.

clarif
This is indeed the answer!
hurikhan77