-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from iRonin/master
Added support for Moped (when used without Mongoid)
- Loading branch information
Showing
10 changed files
with
223 additions
and
32 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,35 @@ | ||
require 'database_cleaner/generic/base' | ||
|
||
module DatabaseCleaner | ||
module Moped | ||
def self.available_strategies | ||
%w[truncation] | ||
end | ||
|
||
module Base | ||
include ::DatabaseCleaner::Generic::Base | ||
|
||
def db=(desired_db) | ||
@db = desired_db | ||
end | ||
|
||
def db | ||
@db || :default | ||
end | ||
|
||
def host_port=(desired_host) | ||
@host = desired_host | ||
end | ||
|
||
def host | ||
@host || '127.0.0.1:27017' | ||
end | ||
|
||
private | ||
|
||
def session | ||
::Moped::Session.new([host], database: db) | ||
end | ||
end | ||
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 |
---|---|---|
@@ -1,29 +1,9 @@ | ||
require 'database_cleaner/moped/truncation_base' | ||
|
||
module DatabaseCleaner | ||
module Moped | ||
module Truncation | ||
|
||
def clean | ||
if @only | ||
collections.each { |c| session[c].find.remove_all if @only.include?(c) } | ||
else | ||
collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) } | ||
end | ||
true | ||
end | ||
|
||
private | ||
|
||
def collections | ||
if db != :default | ||
session.use(db) | ||
end | ||
|
||
session['system.namespaces'].find(:name => { '$not' => /system|\$/ }).to_a.map do |collection| | ||
_, name = collection['name'].split('.', 2) | ||
name | ||
end | ||
end | ||
|
||
class Truncation | ||
include ::DatabaseCleaner::Moped::TruncationBase | ||
end | ||
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,34 @@ | ||
require 'database_cleaner/moped/base' | ||
require 'database_cleaner/generic/truncation' | ||
|
||
module DatabaseCleaner | ||
module Moped | ||
module TruncationBase | ||
include ::DatabaseCleaner::Moped::Base | ||
include ::DatabaseCleaner::Generic::Truncation | ||
|
||
def clean | ||
if @only | ||
collections.each { |c| session[c].find.remove_all if @only.include?(c) } | ||
else | ||
collections.each { |c| session[c].find.remove_all unless @tables_to_exclude.include?(c) } | ||
end | ||
true | ||
end | ||
|
||
private | ||
|
||
def collections | ||
if db != :default | ||
session.use(db) | ||
end | ||
|
||
session['system.namespaces'].find(:name => { '$not' => /system|\$/ }).to_a.map do |collection| | ||
_, name = collection['name'].split('.', 2) | ||
name | ||
end | ||
end | ||
|
||
end | ||
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
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,26 @@ | ||
module MopedTest | ||
class ThingBase | ||
def self.collection | ||
@db ||= 'database_cleaner_specs' | ||
@session ||= ::Moped::Session.new(['127.0.0.1:27017'], database: @db) | ||
@collection ||= @session[name] | ||
end | ||
|
||
def self.count | ||
@collection.find.count | ||
end | ||
|
||
def initialize(attrs={}) | ||
@attrs = attrs | ||
end | ||
|
||
def save! | ||
self.class.collection.insert(@attrs) | ||
end | ||
end | ||
|
||
class Widget < ThingBase | ||
end | ||
class Gadget < ThingBase | ||
end | ||
end |
Oops, something went wrong.