cached_record 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.rdoc +5 -0
- data/Gemfile +13 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +391 -0
- data/Rakefile +90 -0
- data/VERSION +1 -0
- data/benchmark/setup.rb +77 -0
- data/cached_record.gemspec +26 -0
- data/config/database.yml +17 -0
- data/db/cached_record.sql +71 -0
- data/lib/cached_record/cache.rb +125 -0
- data/lib/cached_record/orm/active_record.rb +76 -0
- data/lib/cached_record/orm/data_mapper.rb +87 -0
- data/lib/cached_record/orm.rb +188 -0
- data/lib/cached_record/version.rb +7 -0
- data/lib/cached_record.rb +22 -0
- data/lib/gem_ext/redis.rb +25 -0
- data/log/.gitkeep +0 -0
- data/script/console +8 -0
- data/script/setup.rb +37 -0
- data/test/gem_ext/test_redis.rb +35 -0
- data/test/test_helper/coverage.rb +8 -0
- data/test/test_helper/db.rb +14 -0
- data/test/test_helper/minitest.rb +24 -0
- data/test/test_helper/setup.rb +16 -0
- data/test/test_helper.rb +17 -0
- data/test/unit/orm/test_active_record.rb +628 -0
- data/test/unit/orm/test_data_mapper.rb +616 -0
- data/test/unit/test_cache.rb +351 -0
- data/test/unit/test_cached_record.rb +34 -0
- data/test/unit/test_orm.rb +193 -0
- metadata +201 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
|
3
|
+
module GemExt
|
4
|
+
class TestRedis < MiniTest::Test
|
5
|
+
|
6
|
+
describe Redis do
|
7
|
+
describe "#set" do
|
8
|
+
describe "when passing TTL" do
|
9
|
+
it "invokes set, followed with expire" do
|
10
|
+
redis = Redis.new
|
11
|
+
redis.expects(:set_without_cached_record).with(:foo, :bar, {})
|
12
|
+
redis.expects(:expire).with(:foo, 10)
|
13
|
+
redis.set :foo, :bar, 10
|
14
|
+
end
|
15
|
+
end
|
16
|
+
describe "when passing options hash" do
|
17
|
+
it "invokes set" do
|
18
|
+
redis = Redis.new
|
19
|
+
redis.expects(:set_without_cached_record).with(:foo, :bar, {:ex => 5})
|
20
|
+
redis.set :foo, :bar, {:ex => 5}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#delete" do
|
26
|
+
it "calls del" do
|
27
|
+
redis = Redis.new
|
28
|
+
redis.expects(:del).with(:foo, :bar)
|
29
|
+
redis.delete :foo, :bar
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
if Dir.pwd == File.expand_path("../../..", __FILE__)
|
2
|
+
require "yaml"
|
3
|
+
config = YAML.load_file(File.expand_path("../../../config/database.yml", __FILE__))["test"]
|
4
|
+
host, port, user, password, database = config.values_at "host", "port", "username", "password", "database"
|
5
|
+
`#{
|
6
|
+
[
|
7
|
+
"mysqldump",
|
8
|
+
("-h #{host}" unless host.blank?), ("-P #{port}" unless port.blank?),
|
9
|
+
"-u #{user}", ("-p#{password}" unless password.blank?),
|
10
|
+
"--compact --no-create-db --add-drop-table --skip-lock-tables",
|
11
|
+
"#{database} > ./db/cached_record.sql"
|
12
|
+
].compact.join(" ")
|
13
|
+
}`
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class MiniTest::Test
|
2
|
+
def teardown
|
3
|
+
Redis.new.flushdb
|
4
|
+
Dalli::Client.new.flush
|
5
|
+
CachedRecord::Cache.clear!
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module MiniTest::Assertions
|
10
|
+
def assert_equal_hashes exp, act, msg = nil
|
11
|
+
msg = message(msg, "") { diff exp, act }
|
12
|
+
exp = JSON.parse(exp.gsub(/@\d+$/, "")) if exp.is_a?(String)
|
13
|
+
act = JSON.parse(act.gsub(/@\d+$/, "")) if act.is_a?(String)
|
14
|
+
assert(recursive_symbolize_keys(exp) == recursive_symbolize_keys(act), msg)
|
15
|
+
end
|
16
|
+
private
|
17
|
+
def recursive_symbolize_keys(hash)
|
18
|
+
return unless hash
|
19
|
+
hash.inject({}) do |hash, (key, value)|
|
20
|
+
hash[key.to_sym] = value.is_a?(Hash) ? recursive_symbolize_keys(hash) : value
|
21
|
+
hash
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "logger"
|
3
|
+
require "active_record"
|
4
|
+
|
5
|
+
dbconfig = YAML.load_file(path("config/database.yml"))["test"]
|
6
|
+
logger = Logger.new path("log/test.log")
|
7
|
+
|
8
|
+
ActiveRecord::Base.establish_connection dbconfig
|
9
|
+
ActiveRecord::Base.time_zone_aware_attributes = true
|
10
|
+
ActiveRecord::Base.default_timezone = :local
|
11
|
+
ActiveRecord::Base.logger = logger
|
12
|
+
|
13
|
+
DataMapper.setup :default, dbconfig.merge("adapter" => "mysql")
|
14
|
+
DataMapper.logger = logger
|
15
|
+
|
16
|
+
CachedRecord.setup
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require_relative "test_helper/coverage"
|
4
|
+
|
5
|
+
require "minitest/autorun"
|
6
|
+
require "mocha/setup"
|
7
|
+
|
8
|
+
def path(path)
|
9
|
+
File.expand_path "../../#{path}", __FILE__
|
10
|
+
end
|
11
|
+
|
12
|
+
require "bundler"
|
13
|
+
Bundler.require :default, :development, :test
|
14
|
+
|
15
|
+
require_relative "test_helper/setup"
|
16
|
+
require_relative "test_helper/minitest"
|
17
|
+
require_relative "test_helper/db"
|