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.
@@ -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,8 @@
1
+ if Dir.pwd == File.expand_path("../../..", __FILE__)
2
+ require "simplecov"
3
+ SimpleCov.coverage_dir "test/coverage"
4
+ SimpleCov.start do
5
+ add_group "CachedRecord", "lib"
6
+ add_group "Test suite", "test"
7
+ end
8
+ 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
@@ -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"