Permalink
Browse files

Merge branch 'master' of git://github.com/stipple/acts_as_archive

Conflicts:
	config/gemsets.yml
  • Loading branch information...
2 parents ca66407 + ba1c21e commit 260b7640a29fc0958d6d79cf9161ef475b4f2cb6 @fojas committed Jun 4, 2012
Showing with 23 additions and 21 deletions.
  1. +7 −8 config/gemsets.yml
  2. +12 −9 lib/acts_as_archive.rb
  3. +4 −4 spec/fixtures/frameworks/rails3/Gemfile
View
@@ -1,10 +1,9 @@
acts_as_archive:
- rake: ">=0.8.7"
- rspec: "~>1.0"
+ rspec: ~>1.0
default:
- active_wrapper-solo: "=0.4.4"
- also_migrate: "=0.3.5"
- externals: "=1.0.2"
- framework_fixture: "=0.1.3"
- mover: "=0.3.6"
- rack-test: "=0.5.6"
+ active_wrapper-solo: =0.4.4
+ also_migrate: ~>0.3
+ externals: =1.0.2
+ framework_fixture: =0.1.3
+ mover: =0.3.6
+ rack-test: ~>0
View
@@ -113,11 +113,11 @@ def acts_as_archive(options={})
klass = eval(options[:class]) rescue nil
if klass
- klass.send :set_table_name, options[:table]
+ klass.send :table_name=, options[:table]
else
eval <<-EVAL
class ::#{options[:class]} < ActiveRecord::Base
- set_table_name "#{options[:table]}"
+ self.table_name = "#{options[:table]}"
end
EVAL
klass = eval("::#{options[:class]}")
@@ -127,10 +127,10 @@ class ::#{options[:class]} < ActiveRecord::Base
klass.acts_as_archive(:class => self, :archive => true)
self.reflect_on_all_associations.each do |association|
- if !ActsAsArchive.find(association.klass).empty? && association.options[:dependent]
+ if association.options[:dependent] && !association.options[:polymorphic] && !ActsAsArchive.find(association.klass).empty?
opts = association.options.dup
opts[:class_name] = "::#{association.class_name}::Archive"
- opts[:foreign_key] = association.primary_key_name
+ opts[:foreign_key] = association.respond_to?(:foreign_key) ? association.foreign_key : association.primary_key_name
klass.send association.macro, association.name, opts
end
end
@@ -194,19 +194,22 @@ def self.included(base)
unless base.included_modules.include?(InstanceMethods)
base.send :include, InstanceMethods
base.class_eval do
- unless method_defined?(:delete_sql_without_archive)
- alias_method :delete_sql_without_archive, :delete_sql
- alias_method :delete_sql, :delete_sql_with_archive
+ unless method_defined?(:delete_without_archive)
+ alias_method :delete_without_archive, :delete
+ alias_method :delete, :delete_with_archive
end
end
end
end
module InstanceMethods
- def delete_sql_with_archive(sql, name = nil)
+ def delete_with_archive(arel, name=nil, binds=[])
@mutex ||= Mutex.new
@mutex.synchronize do
unless ActsAsArchive.disabled
+ bdup = binds.dup
+ sql = to_sql(arel, bdup)
+
from, where = /DELETE FROM (.+)/i.match(sql)[1].split(/\s+WHERE\s+/i, 2)
from = from.strip.gsub(/[`"]/, '').split(/\s*,\s*/)
@@ -216,7 +219,7 @@ def delete_sql_with_archive(sql, name = nil)
end
end
- delete_sql_without_archive(sql, name)
+ delete_without_archive(arel, name, binds)
end
end
end
@@ -1,9 +1,9 @@
source 'http://rubygems.org'
gem 'active_wrapper-solo'
-gem 'mysql2'
-gem 'rails', '3.0.3'
-gem 'rspec'
+gem 'mysql2', '~> 0.3'
+gem 'rails', '~> 3.1'
+gem 'rspec', '~> 1'
gem 'also_migrate', :path => "../../../../vendor/also_migrate"
gem 'mover', :path => "../../../../vendor/mover"
@@ -34,4 +34,4 @@ gem 'acts_as_archive', :path => "../../../../"
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
-# end
+# end

0 comments on commit 260b764

Please sign in to comment.