Created
October 11, 2009 16:31
-
-
Save kaichen/207748 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fix ParanoidDateTime doesn't respect Resource.with_deleted | |
# Ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/883-paranoiddatetime-doesnt-respect-resourcewith_deleted | |
# Patch: http://github.com/kaichen/dm-core/commit/5117be5ebcc261225b0aae8c9c0fd45568c7eb3d | |
# setup load path | |
extlib = File.expand_path("~/Git/extlib/lib") | |
dm_core = File.expand_path("~/workspace/dm-core/lib") | |
data_objects = File.expand_path("~/Git/do/data_objects/lib") | |
$LOAD_PATH.unshift(extlib, dm_core, data_objects) | |
require "dm-core" | |
require "spec" | |
DataMapper::Logger.new(STDOUT, :debug) | |
DataMapper.setup(:default, "sqlite3::memory:") | |
class Person | |
include DataMapper::Resource | |
property :id, Serial | |
property :deleted_at, ParanoidDateTime | |
end | |
describe "ParanoidDateTime" do | |
describe "when wrapped in Resource.with_deleted {}" do | |
before(:all) do | |
DataMapper.auto_migrate! | |
Person.create | |
Person.create | |
Person.get(1).destroy | |
end | |
it "should return all resources (deleted ones included)" do | |
Person.all.size.should == 1 | |
Person.with_deleted { Person.all.size.should == 2 } | |
end | |
end | |
describe "when wrapped in Resource.only_deleted {}" do | |
before(:all) do | |
DataMapper.auto_migrate! | |
Person.create | |
Person.create | |
Person.get(1).destroy | |
end | |
it "should return only deleted resources" do | |
Person.all.size.should == 1 | |
Person.only_deleted { Person.all.size.should == 1 } | |
end | |
end | |
describe "when not wrapped in Resource.with_deleted {}" do | |
before(:all) do | |
DataMapper.auto_migrate! | |
Person.create | |
Person.create | |
Person.get(1).destroy | |
end | |
it "should return all existing resources (deleted ones NOT included)" do | |
Person.all.size.should == 1 | |
end | |
end | |
end | |
#~ (0.000069) SELECT sqlite_version(*) | |
#~ (0.000107) DROP TABLE IF EXISTS "people" | |
#~ (0.000012) PRAGMA table_info("people") | |
#~ (0.000302) CREATE TABLE "people" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "deleted_at" TIMESTAMP) | |
#~ (0.000036) INSERT INTO "people" DEFAULT VALUES | |
#~ (0.000032) INSERT INTO "people" DEFAULT VALUES | |
#~ (0.000034) SELECT "id" FROM "people" WHERE ("id" = 1 AND "deleted_at" IS NULL) ORDER BY "id" LIMIT 1 | |
#~ (0.000045) UPDATE "people" SET "deleted_at" = '2009-10-12T00:26:09+08:00' WHERE "id" = 1 | |
#~ (0.000028) SELECT "id" FROM "people" WHERE "deleted_at" IS NULL ORDER BY "id" | |
#~ (0.000021) SELECT "id" FROM "people" ORDER BY "id" | |
#. ~ (0.000084) DROP TABLE IF EXISTS "people" | |
#~ (0.000010) PRAGMA table_info("people") | |
#~ (0.000111) CREATE TABLE "people" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "deleted_at" TIMESTAMP) | |
#~ (0.000032) INSERT INTO "people" DEFAULT VALUES | |
#~ (0.000031) INSERT INTO "people" DEFAULT VALUES | |
#~ (0.000030) SELECT "id" FROM "people" WHERE ("id" = 1 AND "deleted_at" IS NULL) ORDER BY "id" LIMIT 1 | |
#~ (0.000039) UPDATE "people" SET "deleted_at" = '2009-10-12T00:26:09+08:00' WHERE "id" = 1 | |
#~ (0.000026) SELECT "id" FROM "people" WHERE "deleted_at" IS NULL ORDER BY "id" | |
#~ (0.000024) SELECT "id" FROM "people" WHERE "deleted_at" IS NOT NULL ORDER BY "id" | |
#. ~ (0.000084) DROP TABLE IF EXISTS "people" | |
#~ (0.000010) PRAGMA table_info("people") | |
#~ (0.000108) CREATE TABLE "people" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "deleted_at" TIMESTAMP) | |
#~ (0.000031) INSERT INTO "people" DEFAULT VALUES | |
#~ (0.000029) INSERT INTO "people" DEFAULT VALUES | |
#~ (0.000029) SELECT "id" FROM "people" WHERE ("id" = 1 AND "deleted_at" IS NULL) ORDER BY "id" LIMIT 1 | |
#~ (0.000041) UPDATE "people" SET "deleted_at" = '2009-10-12T00:26:09+08:00' WHERE "id" = 1 | |
#~ (0.000027) SELECT "id" FROM "people" WHERE "deleted_at" IS NULL ORDER BY "id" | |
#. | |
#Finished in 0.016483 seconds | |
#3 examples, 0 failures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment