Commit ce7670ce by Sam Figueroa

Spec destroy_all respects paranoid

- Add a spec to ensure that paranoid models don’t get  deleted by
  destroy_all call.
- ActiveRecords current implementation enumerates over the
  relation and calls &:destroy on each element. If that happens to
change
  sometime in the future this test should notice it.
parent 1fc916b9
...@@ -909,6 +909,34 @@ class ParanoiaTest < test_framework ...@@ -909,6 +909,34 @@ class ParanoiaTest < test_framework
assert_equal 0, model.unscoped.count assert_equal 0, model.unscoped.count
end end
def test_destroy_all
model = ParanoidModel
count = 3
models = count.times.map { model.new }
assert_equal 0, model.count
models.each(&:save!)
assert_equal count, model.count
model.destroy_all
assert_equal 0, model.count
assert_equal 3, model.unscoped.count
end
def test_destroy_all_for_non_paranoid_model
model = PlainModel
count = 3
models = count.times.map { model.new }
assert_equal 0, model.count
models.each(&:save!)
assert_equal count, model.count
model.destroy_all
assert_equal 0, model.count
assert_equal 0, model.unscoped.count
end
# TODO: find a fix for Rails 4.1 # TODO: find a fix for Rails 4.1
if ActiveRecord::VERSION::STRING !~ /\A4\.1/ if ActiveRecord::VERSION::STRING !~ /\A4\.1/
def test_counter_cache_column_update_on_really_destroy def test_counter_cache_column_update_on_really_destroy
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment