Skip to content

Commit

Permalink
Spec destroy_all respects paranoid
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
unimatrixZxero committed Oct 16, 2015
1 parent 1fc916b commit ce7670c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/paranoia_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,34 @@ def test_delete_all_for_non_paranoid_model
assert_equal 0, model.unscoped.count
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
if ActiveRecord::VERSION::STRING !~ /\A4\.1/
def test_counter_cache_column_update_on_really_destroy
Expand Down

0 comments on commit ce7670c

Please sign in to comment.