views:

86

answers:

0

So, I'm using Authlogic to manage my users and I've recently added in the act_as_soft_deletable plugin. For various reasons, I would like to be able to "undestroy!" users, but I'm getting a failure in my assert_model_soft_deletes. Here's the unit test:

 def test_soft_delete_works
    # will run the model through a destroy and undestroy while making sure all values were saved
    assert_model_soft_deletes( users(:example_plain_user) )
  end

And here's my error:

Started
.........E
Finished in 3.48433 seconds.

  1) Error:
test_soft_delete_works(UserTest): ActiveRecord::RecordInvalid: Validation failed: Password is too short (minimum is 4 characters), Password confirmation is too short (minimum is 4 characters)
    /test/unit/user_test.rb:7:in `test_soft_delete_works'

10 tests, 53 assertions, 0 failures, 1 errors

I assume my problem is that once the record gets deleted, it's moved to the deleted_users table, and then when the record is recreated to be 'undestroy!'ed, the password field is blank (since there's no such real column) and fails this validation. I'd really like to be able to skip password validation on create if the crypt_password and password_salt are not blank, but I can't figure out if this is possible with Authlogic in its current state. I couldn't find much help in customizing the password validation in the Authlogic documentation, but perhaps I'm just too much of a newbie.

Anybody have any tips or ideas?


Update:

I was able to get around this by adding the following to my model:

acts_as_authentic do |c|

    c.validates_length_of_password_field_options({:minimum => 6, :if => :password_needed?})
  end

def password_needed?
    if self.new_record? && self.password.blank? && !self.crypted_password.blank?
      false
    else 
      require_password?
    end
  end

I hope this helps anyone else with this problem. The basic idea was that the undestroy! creates a new model with a blank password but a non-blank crypted password. A lot easier than I was thinking it would be.