Skip to content

Commit

Permalink
Only run after callbacks if the result is successful
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Oct 25, 2008
1 parent 3691177 commit 07e724b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/authgasm/session/base.rb
Expand Up @@ -189,6 +189,7 @@ def destroy
@record = nil
cookies.delete cookie_key
session[session_key] = nil
true
end

# Errors when authentication fails, just like ActiveRecord errors. In fact it uses the same exact class.
Expand Down
8 changes: 4 additions & 4 deletions lib/authgasm/session/callbacks.rb
Expand Up @@ -18,28 +18,28 @@ def self.included(base) #:nodoc:
def create_with_callbacks(updating = false) # :nodoc:
run_callbacks(:before_create)
result = create_without_callbacks(updating)
run_callbacks(:after_create)
run_callbacks(:after_create) if result
result
end

def destroy_with_callbacks # :nodoc:
run_callbacks(:before_destroy)
result = destroy_without_callbacks
run_callbacks(:after_destroy)
run_callbacks(:after_destroy) if result
result
end

def update_with_callbacks # :nodoc:
run_callbacks(:before_update)
result = update_without_callbacks
run_callbacks(:after_update)
run_callbacks(:after_update) if result
result
end

def valid_with_callbacks?(set_session = false) # :nodoc:
run_callbacks(:before_validation)
result = valid_without_callbacks?(set_session)
run_callbacks(:after_validation)
run_callbacks(:after_validation) if result
result
end
end
Expand Down

0 comments on commit 07e724b

Please sign in to comment.