spec/redis_spec.rb in barnyard_harvester-0.0.1 vs spec/redis_spec.rb in barnyard_harvester-0.0.2
- old
+ new
@@ -5,145 +5,149 @@
require "json"
# TODO.. Move the flush to the backend object, not here!!!!!!!!!
+CROP_NUMBER = 1
+
+REDIS_SETTINGS = {
+ :host => "localhost",
+ :port => 6379,
+ :db => CROP_NUMBER
+}
+
describe BarnyardHarvester do
def load_and_process_file(file, backend)
data = YAML::load_file file
- redis_settings = {
- :host => "localhost",
- :port => 6379,
- }
-
my_logger = Logger.new(STDOUT)
my_logger.level = Logger::INFO
- h = BarnyardHarvester::Sync.new(:backend => backend, :debug => false, :crop_number => 1, :redis_settings => redis_settings, :logger => my_logger)
+ h = BarnyardHarvester::Sync.new(:backend => backend, :debug => false, :crop_number => CROP_NUMBER, :redis_settings => REDIS_SETTINGS, :logger => my_logger)
h.run do
data.each do |primary_key, value|
h.process primary_key, value
end
end
h
end
- def flush
+ def flush
- r = Redis.new(:db => 1)
+ r = Redis.new(REDIS_SETTINGS)
- r.keys.each do |k|
- r.del k
- end
-
+ r.keys.each do |k|
+ r.del k
+ #puts "deleted #{k}"
end
- before(:each) do
+ end
- flush
+ before(:each) do
- @crop_number = 1
+ flush
- file = "spec/fixtures/data-init.yml"
+ @crop_number = 1
- data = YAML::load_file file
+ file = "spec/fixtures/data-init.yml"
- h = load_and_process_file(file, :redis)
+ data = YAML::load_file file
- h.add_count.should eq(data.count)
- h.delete_count.should eq(0)
- h.change_count.should eq(0)
- h.source_count.should eq(data.count)
- h.cache_count.should eq(data.count)
+ h = load_and_process_file(file, :redis)
- end
+ h.add_count.should eq(data.count)
+ h.delete_count.should eq(0)
+ h.change_count.should eq(0)
+ h.source_count.should eq(data.count)
+ h.cache_count.should eq(data.count)
- it "test initial load of records" do
+ end
- data = YAML::load_file "spec/fixtures/data-init.yml"
+ it "test initial load of records" do
- redis = Redis.new(:db => 1)
+ data = YAML::load_file "spec/fixtures/data-init.yml"
- data.each do |primary_key, value|
- value.to_json.should eq(redis.get(primary_key))
- end
+ redis = Redis.new(REDIS_SETTINGS)
+ data.each do |primary_key, value|
+ value.to_json.should eq(redis.get(primary_key))
end
- it "test add one record" do
+ end
- file = "spec/fixtures/data-add.yml"
- data = YAML::load_file file
+ it "test add one record" do
- h = load_and_process_file(file, :redis)
+ file = "spec/fixtures/data-add.yml"
+ data = YAML::load_file file
- h.add_count.should eq(1)
- h.delete_count.should eq(0)
- h.change_count.should eq(0)
- h.source_count.should eq(data.count)
- h.cache_count.should eq(data.count)
+ h = load_and_process_file(file, :redis)
- end
+ h.add_count.should eq(1)
+ h.delete_count.should eq(0)
+ h.change_count.should eq(0)
+ h.source_count.should eq(data.count)
+ h.cache_count.should eq(data.count)
- it "test change one record" do
+ end
- file = "spec/fixtures/data-change.yml"
+ it "test change one record" do
- data = YAML::load_file file
+ file = "spec/fixtures/data-change.yml"
- h = load_and_process_file(file, :redis)
+ data = YAML::load_file file
- h.add_count.should eq(0)
- h.delete_count.should eq(0)
- h.change_count.should eq(1)
- h.source_count.should eq(data.count)
- h.cache_count.should eq(data.count)
+ h = load_and_process_file(file, :redis)
- end
+ h.add_count.should eq(0)
+ h.delete_count.should eq(0)
+ h.change_count.should eq(1)
+ h.source_count.should eq(data.count)
+ h.cache_count.should eq(data.count)
- it "test delete one record" do
+ end
- file = "spec/fixtures/data-delete.yml"
+ it "test delete one record" do
- data = YAML::load_file file
+ file = "spec/fixtures/data-delete.yml"
- h = load_and_process_file(file, :redis)
+ data = YAML::load_file file
+ h = load_and_process_file(file, :redis)
- h.add_count.should eq(0)
- h.delete_count.should eq(1)
- h.change_count.should eq(0)
- h.source_count.should eq(data.count)
- h.cache_count.should eq(data.count + 1)
- end
+ h.add_count.should eq(0)
+ h.delete_count.should eq(1)
+ h.change_count.should eq(0)
+ h.source_count.should eq(data.count)
+ h.cache_count.should eq(data.count + 1)
- it "test delete all records and add one" do
+ end
- init_file = "spec/fixtures/data-init.yml"
- init_data = YAML::load_file init_file
+ it "test delete all records and add one" do
- file = "spec/fixtures/data-delete-all-records-add-one.yml"
- #data = YAML::load_file file
+ init_file = "spec/fixtures/data-init.yml"
+ init_data = YAML::load_file init_file
- h = load_and_process_file(file, :redis)
+ file = "spec/fixtures/data-delete-all-records-add-one.yml"
+ #data = YAML::load_file file
- h.add_count.should eq(1)
- h.delete_count.should eq(5)
- h.change_count.should eq(0)
- h.source_count.should eq(1)
- h.cache_count.should eq(init_data.count + 1)
+ h = load_and_process_file(file, :redis)
- end
+ h.add_count.should eq(1)
+ h.delete_count.should eq(5)
+ h.change_count.should eq(0)
+ h.source_count.should eq(1)
+ h.cache_count.should eq(init_data.count + 1)
+ end
- after(:each) do
- end
+
+ after(:each) do
+ end
end
\ No newline at end of file