Rails problem using Authlogic + acts_as_soft_deletable

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.

Answers


Need Your Help

Routing with regex condition in Rails 2

ruby-on-rails ruby regex rest

In my routes.rb file, I've defined these routes:

Algorithm to create a vector based puzzle

algorithm random linear-algebra

I am working on a little puzzle-game-project. The basic idea is built around projecting multi-dimensonal data down to 2D. My only problem is how to generate the randomized scenario data. Here is the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.