Permalink
Browse files

Deprecating restore_all, improving specs

  • Loading branch information...
1 parent 7fb0e60 commit 1b16ce8b332d300e16707278103856434e0802da @winton committed Jan 3, 2011
View
@@ -12,15 +12,6 @@ class <<self
attr_accessor :configuration, :disabled
- def disable(&block)
- mutex.synchronize do
- self.disabled = true
- block.call
- end
- ensure
- self.disabled = false
- end
-
def deprecate(msg)
if defined?(::ActiveSupport::Deprecation)
::ActiveSupport::Deprecation.warn msg
@@ -29,6 +20,16 @@ def deprecate(msg)
end
end
+ def disable(&block)
+ @mutex ||= Mutex.new
+ @mutex.synchronize do
+ self.disabled = true
+ block.call
+ end
+ ensure
+ self.disabled = false
+ end
+
def find(from)
from = [ from ] unless from.is_a?(::Array)
(@configuration || []).select do |hash|
@@ -52,12 +53,8 @@ def move(config, where, merge_options={})
end
end
- def mutex
- @mutex ||= Mutex.new
- end
-
def update(*args)
- deprecate "ActsAsArchive.update is depracated and no longer necessary."
+ deprecate "ActsAsArchive.update is deprecated and no longer necessary."
end
end
@@ -141,6 +138,13 @@ def migrate_from_acts_as_paranoid
$stdout.puts "-- #{self.class}.migrate_from_acts_as_paranoid"
$stdout.puts " -> #{"%.4fs" % time.real}"
end
+
+ def restore_all(*args)
+ ActsAsArchive.deprecate "#{self}.restore_all is deprecated, please use #{self}::Archive.delete_all."
+ if defined?(self::Archive)
+ self::Archive.delete_all *args
+ end
+ end
end
module InstanceMethods
@@ -18,7 +18,7 @@
end
it "should move records back to original tables" do
- should_move_records_back_to_original_tables
+ should_move_records_back_to_original_tables(type)
end
end
end
@@ -56,7 +56,7 @@ def app
end
it "should move records back to original tables" do
- get "/should_move_records_back_to_original_tables_action"
+ get "/should_move_records_back_to_original_tables_action", :type => type
last_response.body.should == '1'
end
end
@@ -22,7 +22,7 @@ def should_create_records_action
def should_move_records_back_to_original_tables_action
before_each false, true
- should_move_records_back_to_original_tables
+ should_move_records_back_to_original_tables(params[:type])
render :text => '1'
end
@@ -15,7 +15,7 @@ def should_create_records_action
def should_move_records_back_to_original_tables_action
before_each false, true
- should_move_records_back_to_original_tables
+ should_move_records_back_to_original_tables(params[:type])
render :text => '1'
end
@@ -22,7 +22,7 @@ class Application < Sinatra::Base
get "/should_move_records_back_to_original_tables_action" do
before_each false, true
- should_move_records_back_to_original_tables
+ should_move_records_back_to_original_tables(params[:type])
'1'
end
@@ -72,9 +72,15 @@ def should_create_records
verify_attributes original
end
- def should_move_records_back_to_original_tables
- @record.destroy
- Record::Archive.first.destroy
+ def should_move_records_back_to_original_tables(type)
+ case type
+ when 'delete', 'destroy'
+ @record.send type
+ Record::Archive.first.send type
+ when 'delete_all', 'destroy_all'
+ Record.send type
+ Record::Archive.send type
+ end
original, archive = all_records

0 comments on commit 1b16ce8

Please sign in to comment.