Sha256: 372ae19f06b6318371d48957bd50012f05ffea28ed3d58e499f9007fe00af99b

Contents?: true

Size: 1.47 KB

Versions: 12

Compression:

Stored size: 1.47 KB

Contents

# encoding: UTF-8

require File.expand_path("./helper", File.dirname(__FILE__))

class Person < Ohm::Model
  include Ohm::SoftDelete

  attribute :name
  index :name

  attribute :age
  index :age
end

test "deleted?" do
  person = Person.create

  assert !person.deleted?

  person.delete

  assert person.deleted?
end

test "all excludes deleted records" do
  person = Person.create(:name => "matz")

  assert Person.all.first == person

  person.delete

  assert Person.all.empty?
end

test "find does not exclude deleted records" do
  person = Person.create(:name => "matz")

  assert Person.find(:name => "matz").first == person

  person.delete

  assert Person.find(:name => "matz").include?(person)
end

test "find with many criteria doesn't exclude deleted records" do
  person = Person.create(:name => "matz", :age => 38)

  assert Person.find(:name => "matz", :age => 38).first == person

  person.delete

  assert Person.find(:name => "matz", :age => 38).include?(person)
end

test "exists? returns true for deleted records" do
  person = Person.create(:name => "matz")

  person.delete

  assert Person.exists?(person.id)
end

test "Model[n] can be used to retrieve deleted records" do
  person = Person.create(:name => "matz")

  person.delete

  assert Person[person.id].deleted?
  assert Person[person.id].name == "matz"
end

test "restoring" do
  person = Person.create(:name => "matz")
  person.delete

  assert Person.all.empty?

  person.restore
  assert Person.all.include?(person)
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ohm-contrib-2.0.0.alpha5 test/soft_delete.rb
ohm-contrib-2.0.0.alpha4 test/soft_delete.rb
ohm-contrib-2.0.0.alpha3 test/soft_delete.rb
ohm-contrib-2.0.0.alpha2 test/soft_delete.rb
ohm-contrib-1.2 test/soft_delete.rb
ohm-contrib-1.1.0 test/soft_delete.rb
ohm-contrib-1.0.1 test/soft_delete.rb
ohm-contrib-1.0.0 test/soft_delete.rb
ohm-contrib-1.0.0.rc5 test/soft_delete.rb
ohm-contrib-1.0.0.rc4 test/soft_delete.rb
ohm-contrib-1.0.0.rc3 test/soft_delete.rb
ohm-contrib-1.0.0.rc2 test/soft_delete.rb