Skip to content

Commit

Permalink
big changes to domain model, removed after commit logic, fixed spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Youch committed Mar 31, 2011
1 parent dff178d commit 4562dad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 45 deletions.
51 changes: 6 additions & 45 deletions app/models/domain_model.rb
Expand Up @@ -14,6 +14,12 @@ class DomainModel < ActiveRecord::Base

cattr_accessor :logger

before_save { self.post_handlers(self,:pre_save) }
after_commit { self.post_handlers(self,:post_save) }

before_destroy { self.post_handlers(self,:pre_destroy) }
after_destroy { self.post_handlers(self,:post_destroy) }

def self.not_me(id); id ? self.where('id != ?', id) : self; end

def self.process_id
Expand Down Expand Up @@ -499,26 +505,6 @@ def self.validate_on_update(meth)
validate Proc.new { |mdl| if !mdl.new_record?; mdl.send(meth); end }
end



alias_method :save_active_record, :save # :nodoc:

def save(validate=true) #:nodoc:
post_handlers(self,:pre_save)
if save_active_record(:validate => validate)
post_handlers(self,:post_save)
end
end

alias_method :destroy_active_record, :destroy # :nodoc:

def destroy #:nodoc:
post_handlers(self,:pre_destroy)
if destroy_active_record
post_handlers(self,:post_destroy)
end
end

def post_handlers(record,action) #:nodoc:
DomainModel.get_handlers(:model,record.class.to_s.underscore.to_sym).each do |handler|
if handler[1] && handler[1][:actions] && handler[1][:actions].include?(action)
Expand Down Expand Up @@ -739,29 +725,4 @@ def self.expire_site
def expire_site
self.class.expire_site
end


# http://gist.github.com/76868
# Need an after_commit for post-transaction actions
def save_with_after_commit(*args) #:nodoc:
previous_new_record = new_record?
if result = save_without_after_commit(*args)
_run_commit_callbacks
_run_commit_on_create_callbacks if previous_new_record
end
result
end

def save_with_after_commit!(*args)#:nodoc:
previous_new_record = new_record?
if result = save_without_after_commit!(*args)
_run_commit_callbacks
_run_commit_on_create_callbacks if previous_new_record
end
result
end

alias_method_chain :save, :after_commit
alias_method_chain :save!, :after_commit
define_model_callbacks :commit, :commit_on_create, :only => :after
end
1 change: 1 addition & 0 deletions spec/models/page_paragraph_spec.rb
Expand Up @@ -93,6 +93,7 @@ def url
"fake_url"
end
def new_record?; false; end
def destroyed?; false; end
end

class TestCanonicalParagraphType < HashModel
Expand Down

0 comments on commit 4562dad

Please sign in to comment.