LoginEngine - transaction test oddness


#1

I’ve just adapted the original salted hashed login generator tests for
the login engine, such that we can now run tests against it and verify
that it behaves nicely, in the same way that you might test any Rails
plugin:

$ rake test_plugins # ensuring your test database it set up, etc etc

All the tests pass except one - “test_change_password_with_bad_email”.
This test is meant to simulate a user who is trying to change their
password, but where the email to notify them cannot be sent. From what
I can tell, despite the password update being wrapped in a transaction
(user_controller.rb, line 69 in the latest revision) which should get
rolled back upon the mail-related exception, the password when the
controller action exits has actually been changed! I can’t replicate
this behaviour in the console, so I’m throwing it out to some
entreprising plugin debugger out there on the interwebs.

Anyone got any ideas?

  • james

------ code snippet follows -----

def change_password_for(user, params)
  begin
    User.transaction(user) do
      user.change_password(params[:user][:password],

params[:user][:password_confirmation])
if user.save
#@user.reload
#puts “changed password: #{@user.salted_password}”
if LoginEngine.config(:use_email_notification)

—> the exception gets thrown on the next line

          UserNotify.deliver_change_password(user, 

params[:user][:password])
flash[:notice] = “Updated password emailed to
#{@user.email}”
else
flash[:notice] = “Password updated.”
end
# since sometimes we’re changing the password from within
another action/template…
redirect_to :action => params[:back_to] if params[:back_to]
else
end
end
rescue

—> this is where we should land after the exception, and the

transaction should roll back

—> but the password seems to be changed.

    flash[:warning] = 'Password could not be changed at this time.

Please retry.’
end
end


#2

James,

Here's an an obvious question, but are you using InnoDB tables

(assuming you are using MySQL)?

Joe


#3

On 11/9/05, Joseph H. removed_email_address@domain.invalid wrote:

the login engine, such that we can now run tests against it and verify
(user_controller.rb, line 69 in the latest revision) which should get
rolled back upon the mail-related exception, the password when the
controller action exits has actually been changed! I can’t replicate
this behaviour in the console, so I’m throwing it out to some
entreprising plugin debugger out there on the interwebs.

Anyone got any ideas?

  • james

Postgresql doesn’t allow nested transactions, so you have to disable
transactional fixtures for methods using transactions themselves.

class MyTest < Test::Unit::TestCase
uses_transaction :test_foo

def test_foo
end

tests…

end

I discovered this ages ago (in Rails time), so does anyone know if
there is a better way to do this?


rick
http://techno-weenie.net


#4

To the best of my knowledge the schema.rb file is creating InnoDB
tables, yes - that was one of the first things I checked. What struck
me as most odd is that the method appears to work from the console…

Any other ideas? It would be great to see all tests passing…


#5

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 9, 2005, at 11:34 AM, Rick O. wrote:

end

I discovered this ages ago (in Rails time), so does anyone know if
there is a better way to do this?

You nailed it. Another way is to segregate the tests which
specifically need to check the results of a rollback into another
test case which has disabled transactional fixtures.

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDcmaUAQHALep9HFYRAlIdAKChZBQty9B4Px59iOWrRbHDPJCo2gCfaayt
pGgJDQYAsPtxkett1lYIvSo=
=4Cgw
-----END PGP SIGNATURE-----