Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This contains the work of @hbpoison, updated to work with the current version of DatabaseCleaner. https://github.com/bmabey/database_cleaner/pull/87/files
- Loading branch information
James Conroy-Finn
committed
May 11, 2013
1 parent
ce1d162
commit b70f09a
Showing
23 changed files
with
559 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
test: | ||
url: 'redis://localhost:6379/0' | ||
|
||
one: | ||
url: 'redis://localhost:6379/1' | ||
|
||
two: | ||
url: 'redis://localhost:6379/2' |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'ohm' | ||
|
||
Ohm.connect :url => ENV['REDIS_URL'] | ||
|
||
class OhmWidget < Ohm::Model | ||
attribute :name | ||
|
||
def self.create!(attrs = {}) | ||
new({:name => 'some widget'}.merge(attrs)).save | ||
end | ||
|
||
def self.count | ||
all.count | ||
end | ||
|
||
end | ||
|
||
class OhmWidgetUsingDatabaseOne < Ohm::Model | ||
connect :url => ENV['REDIS_URL_ONE'] | ||
attribute :name | ||
|
||
def self.create!(attrs = {}) | ||
new({:name => 'a widget using database one'}.merge(attrs)).save | ||
end | ||
|
||
def self.count | ||
all.count | ||
end | ||
|
||
end | ||
|
||
class OhmWidgetUsingDatabaseTwo < Ohm::Model | ||
connect :url => ENV['REDIS_URL_TWO'] | ||
attribute :name | ||
|
||
def self.create!(attrs = {}) | ||
new({:name => 'a widget using database two'}.merge(attrs)).save | ||
end | ||
|
||
def self.count | ||
all.count | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
require 'redis' | ||
|
||
class RedisWidget | ||
|
||
def self.redis | ||
threaded ||= Redis.connect | ||
end | ||
|
||
def self.redis=(connection) | ||
threaded = connection | ||
end | ||
|
||
def self.threaded | ||
Thread.current[self.class.to_s] ||= {} | ||
end | ||
|
||
def initialize(options = {}) | ||
options = options.dup | ||
@name = options[:name] | ||
end | ||
|
||
def connection | ||
self.class.redis | ||
end | ||
|
||
def save | ||
unless connection.get(self.class.to_s + ':id') | ||
@id = 0 | ||
connection.set(self.class.to_s + ':id', @id) | ||
end | ||
@id = connection.incr(self.class.to_s + ':id') | ||
connection.set(self.class.to_s + ':%d:name' % @id, @name) | ||
end | ||
|
||
def self.count | ||
self.redis.keys(self.to_s + '*name').size | ||
end | ||
|
||
def self.create! | ||
new(:name => 'some widget').save | ||
|
||
end | ||
end | ||
|
||
class RedisWidgetUsingDatabaseOne < RedisWidget | ||
|
||
def self.redis | ||
threaded[self.class.to_s] ||= Redis.connect :url => ENV['REDIS_URL_ONE'] | ||
end | ||
|
||
def self.create! | ||
new(:name => 'a widget using database one').save | ||
end | ||
end | ||
|
||
class RedisWidgetUsingDatabaseTwo < RedisWidget | ||
|
||
def self.redis | ||
threaded[self.class.to_s] ||= Redis.connect :url => ENV['REDIS_URL_TWO'] | ||
end | ||
|
||
def self.create! | ||
new(:name => 'a widget using database two').save | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ Feature: database cleaning | |
| MongoMapper | | ||
| Mongoid | | ||
| CouchPotato | | ||
| Redis | | ||
| Ohm | |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Given /^I have setup database cleaner to clean multiple databases using ohm$/ do | ||
#DatabaseCleaner | ||
# require "#{File.dirname(__FILE__)}/../../../lib/ohm_models" | ||
# | ||
# DatabaseCleaner[:ohm, {:connection => ENV['REDIS_URL_ONE']} ].strategy = :truncation | ||
# DatabaseCleaner[:ohm, {:connection => ENV['REDIS_URL_TWO']} ].strategy = :truncation | ||
end | ||
|
||
When /^I create a widget using ohm$/ do | ||
OhmWidget.create! | ||
end | ||
|
||
Then /^I should see ([\d]+) widget using ohm$/ do |widget_count| | ||
OhmWidget.count.should == widget_count.to_i | ||
end | ||
|
||
When /^I create a widget in one db using ohm$/ do | ||
OhmWidgetUsingDatabaseOne.create! | ||
end | ||
|
||
When /^I create a widget in another db using ohm$/ do | ||
OhmWidgetUsingDatabaseTwo.create! | ||
end | ||
|
||
Then /^I should see ([\d]+) widget in one db using ohm$/ do |widget_count| | ||
OhmWidgetUsingDatabaseOne.count.should == widget_count.to_i | ||
end | ||
|
||
Then /^I should see ([\d]+) widget in another db using ohm$/ do |widget_count| | ||
OhmWidgetUsingDatabaseTwo.count.should == widget_count.to_i | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Given /^I have setup database cleaner to clean multiple databases using redis$/ do | ||
#DatabaseCleaner | ||
# require "#{File.dirname(__FILE__)}/../../../lib/redis_models" | ||
# | ||
# DatabaseCleaner[:redis, {:connection => ENV['REDIS_URL_ONE']} ].strategy = :truncation | ||
# DatabaseCleaner[:redis, {:connection => ENV['REDIS_URL_TWO']} ].strategy = :truncation | ||
end | ||
|
||
When /^I create a widget using redis$/ do | ||
RedisWidget.create! | ||
end | ||
|
||
Then /^I should see ([\d]+) widget using redis$/ do |widget_count| | ||
RedisWidget.count.should == widget_count.to_i | ||
end | ||
|
||
When /^I create a widget in one db using redis$/ do | ||
RedisWidgetUsingDatabaseOne.create! | ||
end | ||
|
||
When /^I create a widget in another db using redis$/ do | ||
RedisWidgetUsingDatabaseTwo.create! | ||
end | ||
|
||
Then /^I should see ([\d]+) widget in one db using redis$/ do |widget_count| | ||
RedisWidgetUsingDatabaseOne.count.should == widget_count.to_i | ||
end | ||
|
||
Then /^I should see ([\d]+) widget in another db using redis$/ do |widget_count| | ||
RedisWidgetUsingDatabaseTwo.count.should == widget_count.to_i | ||
end |
Oops, something went wrong.