mini_mongo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.travis.yml +15 -0
- data/LICENSE +2 -2
- data/README.md +64 -2
- data/Rakefile +22 -0
- data/examples/post.rb +30 -0
- data/lib/mini_mongo/attribute_assignment.rb +28 -0
- data/lib/mini_mongo/base.rb +7 -11
- data/lib/mini_mongo/comparable.rb +41 -0
- data/lib/mini_mongo/configuration.rb +34 -0
- data/lib/mini_mongo/connection.rb +17 -7
- data/lib/mini_mongo/core.rb +47 -0
- data/lib/mini_mongo/errors.rb +7 -0
- data/lib/mini_mongo/mapper.rb +47 -11
- data/lib/mini_mongo/serialization.rb +7 -0
- data/lib/mini_mongo/version.rb +1 -1
- data/lib/mini_mongo.rb +7 -0
- data/mini_mongo.gemspec +3 -0
- data/spec/base_spec.rb +33 -0
- data/spec/configutation_spec.rb +17 -0
- data/spec/mapper_spec.rb +55 -0
- data/spec/models/post.rb +4 -0
- data/spec/spec_helper.rb +20 -0
- metadata +70 -3
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
services: mongodb
|
3
|
+
rvm:
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- rbx
|
7
|
+
branches:
|
8
|
+
only:
|
9
|
+
- master
|
10
|
+
matrix:
|
11
|
+
include:
|
12
|
+
- rvm: jruby
|
13
|
+
env: JRUBY_OPTS="--1.9 --server -Xcext.enabled=true"
|
14
|
+
- rvm: jruby-head
|
15
|
+
env: JRUBY_OPTS="--1.9 --server -Xcext.enabled=true"
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 robertomiranda
|
1
|
+
Copyright (c) 2012-2013 robertomiranda
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,16 +1,25 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/robertomiranda/mini_mongo.png)](http://travis-ci.org/robertomiranda/mini_mongo)
|
1
2
|
# MiniMongo
|
2
3
|
|
3
4
|
A Ruby Object Mapper for Mongo
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
8
|
+
### Ruby Versions
|
9
|
+
|
10
|
+
This ODM works and is consistently tested on: CRuby 1.9.x, JRuby (in 1.9 mode) and Rubinius (in 1.9 mode). CRuby 2.0 isn't supported right now since bson_ext dependency is failing during install.
|
11
|
+
|
12
|
+
We don't have plans to support 1.8.x rubies
|
13
|
+
|
14
|
+
### Gems
|
15
|
+
|
7
16
|
Add this line to your application's Gemfile:
|
8
17
|
|
9
18
|
gem 'mini_mongo'
|
10
19
|
|
11
20
|
And then execute:
|
12
21
|
|
13
|
-
$ bundle
|
22
|
+
$ bundle install
|
14
23
|
|
15
24
|
Or install it yourself as:
|
16
25
|
|
@@ -18,7 +27,60 @@ Or install it yourself as:
|
|
18
27
|
|
19
28
|
## Usage
|
20
29
|
|
21
|
-
|
30
|
+
### Configuring
|
31
|
+
|
32
|
+
To get started configure the ODM with your db info using your database url
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
MiniMongo.configure do |config|
|
36
|
+
config.database_url = "mongodb://:@localhost:27017/posts"
|
37
|
+
config.slave_ok = true # by default is false
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
or passing directly all the params
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
MiniMongo.configure do |config|
|
45
|
+
config.db_name = "posts"
|
46
|
+
config.db_user = ""
|
47
|
+
config.db_password = ""
|
48
|
+
config.db_host = "localhost"
|
49
|
+
config.db_port = "27017"
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
### Mapping
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
require "mini_mongo"
|
57
|
+
MiniMongo.configure do|config|
|
58
|
+
config.database_url = "mongodb://:@localhost:27017/posts"
|
59
|
+
end
|
60
|
+
|
61
|
+
class Post < MiniMongo::Base
|
62
|
+
maps :posts
|
63
|
+
end
|
64
|
+
|
65
|
+
# Post.insert({:author => "Chuck Norris"})
|
66
|
+
# => #<Post:0x007fe5240f42c0 @id="5016af53bda74305f1000002", @author="Chuck Norris">
|
67
|
+
|
68
|
+
# Post.find("id" => "5016af53bda74305f1000002")
|
69
|
+
# => #<Post:0x007fe5240cc360 @id="5016af53bda74305f1000002", @author="Chuck Norris">
|
70
|
+
#
|
71
|
+
# Post.update("5016af53bda74305f1000002", "author" => "chuck norris")
|
72
|
+
# => #<Post:0x007fdc7c171c80 @author="chuck norris", @id="5016af53bda74305f1000002">
|
73
|
+
#
|
74
|
+
#Post.count
|
75
|
+
# => 1
|
76
|
+
#
|
77
|
+
#Post.remove("5016af53bda74305f1000002")
|
78
|
+
# => true
|
79
|
+
#
|
80
|
+
#Post.remove_all
|
81
|
+
# => true
|
82
|
+
```
|
83
|
+
|
22
84
|
|
23
85
|
## Contributing
|
24
86
|
|
data/Rakefile
CHANGED
@@ -1,2 +1,24 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require "bundler/gem_tasks"
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
task :console do
|
7
|
+
puts "Loading development console..."
|
8
|
+
system("irb -r mini_mongo")
|
9
|
+
end
|
10
|
+
|
11
|
+
task :help do
|
12
|
+
puts "Available rake tasks: "
|
13
|
+
puts "rake console - Run a IRB console with all enviroment loaded"
|
14
|
+
puts "rake spec - Run specs"
|
15
|
+
end
|
16
|
+
|
17
|
+
task :spec do
|
18
|
+
desc "Run all specs with rcov"
|
19
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
20
|
+
t.pattern = "spec/**/*_spec.rb"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default => [:spec]
|
data/examples/post.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "mini_mongo"
|
2
|
+
MiniMongo.configure do|config|
|
3
|
+
config.database_url = "mongodb://:@localhost:27017/posts"
|
4
|
+
end
|
5
|
+
|
6
|
+
class Post < MiniMongo::Base
|
7
|
+
maps :posts
|
8
|
+
end
|
9
|
+
|
10
|
+
# Post.insert({:author => "Chuck Norris"})
|
11
|
+
# => #<Post:0x007fe5240f42c0 @id="5016af53bda74305f1000002", @author="Chuck Norris">
|
12
|
+
|
13
|
+
# Post.find("id" => "5016af53bda74305f1000002")
|
14
|
+
# => #<Post:0x007fe5240cc360 @id="5016af53bda74305f1000002", @author="Chuck Norris">
|
15
|
+
#
|
16
|
+
# Post.update("5016af53bda74305f1000002", "author" => "chuck norris")
|
17
|
+
# => #<Post:0x007fdc7c171c80 @author="chuck norris", @id="5016af53bda74305f1000002">
|
18
|
+
#
|
19
|
+
#Post.count
|
20
|
+
# => 1
|
21
|
+
#
|
22
|
+
#Post.remove("5016af53bda74305f1000002")
|
23
|
+
# => true
|
24
|
+
#
|
25
|
+
#Post.remove_all
|
26
|
+
# => true
|
27
|
+
#
|
28
|
+
class Answer < MiniMongo::Base
|
29
|
+
maps :answers
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module MiniMongo
|
2
|
+
module AttributeAssignment
|
3
|
+
def assign_attributes(attributes)
|
4
|
+
@attributes["id"] = attributes.delete("_id").to_s || attributes.delete(:_id).to_s
|
5
|
+
attributes.each do |key, value|
|
6
|
+
@attributes[key] = value
|
7
|
+
define_accessors(key) unless self.respond_to? :key
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method :attributes=, :assign_attributes
|
12
|
+
|
13
|
+
def id
|
14
|
+
@attributes["id"]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def define_accessors(key)
|
19
|
+
define_singleton_method(key) do
|
20
|
+
@attributes[key]
|
21
|
+
end
|
22
|
+
|
23
|
+
define_singleton_method("#{key}=") do |value|
|
24
|
+
@attributes[key] = value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/mini_mongo/base.rb
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
instance_variable_set("@#{key}", value)
|
9
|
-
self.instance_eval("def #{key};@#{key};end")
|
10
|
-
self.instance_eval("def #{key}=(val);@#{key}=val;end")
|
11
|
-
end
|
1
|
+
module MiniMongo
|
2
|
+
class Base
|
3
|
+
include MiniMongo::Core
|
4
|
+
include MiniMongo::Mapper
|
5
|
+
include MiniMongo::AttributeAssignment
|
6
|
+
include MiniMongo::Comparable
|
7
|
+
include MiniMongo::Serialization
|
12
8
|
end
|
13
9
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module MiniMongo
|
2
|
+
module Comparable
|
3
|
+
include ::Comparable
|
4
|
+
|
5
|
+
# Default comparison is via the string version of the id.
|
6
|
+
#
|
7
|
+
# @example Compare two documents.
|
8
|
+
# person <=> other_person
|
9
|
+
#
|
10
|
+
# @param [ Document ] other The document to compare with.
|
11
|
+
#
|
12
|
+
# @return [ Integer ] -1, 0, 1.
|
13
|
+
def <=>(other)
|
14
|
+
attributes["id"] <=> other.attributes["id"]
|
15
|
+
end
|
16
|
+
|
17
|
+
# Performs class equality checking.
|
18
|
+
#
|
19
|
+
# @example Compare the classes.
|
20
|
+
# document === other
|
21
|
+
#
|
22
|
+
# @param [ Document, Object ] other The other object to compare with.
|
23
|
+
#
|
24
|
+
# @return [ true, false ] True if the classes are equal, false if not.
|
25
|
+
def ===(other)
|
26
|
+
other.class == Class ? self.class === other : self == other
|
27
|
+
end
|
28
|
+
|
29
|
+
# Delegates to ==. Used when needing checks in hashes.
|
30
|
+
#
|
31
|
+
# @example Perform equality checking.
|
32
|
+
# document.eql?(other)
|
33
|
+
#
|
34
|
+
# @param [ Document, Object ] other The object to check against.
|
35
|
+
#
|
36
|
+
# @return [ true, false ] True if equal, false if not.
|
37
|
+
def eql?(other)
|
38
|
+
self == (other)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module MiniMongo
|
2
|
+
# Stores runtime configuration information.
|
3
|
+
#
|
4
|
+
# @example Standard settings
|
5
|
+
# MiniMongo.configure do |config|
|
6
|
+
# config.database_url = "mongodb://user:pass@localhost:27017/posts"
|
7
|
+
# end
|
8
|
+
#
|
9
|
+
# @see MiniMongo.configure
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
self.configuration ||= Configuration.new
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
|
19
|
+
class Configuration
|
20
|
+
attr_accessor :slave_ok, :db_name, :db_user, :db_host, :db_port, :db_password
|
21
|
+
attr_reader :database_url
|
22
|
+
|
23
|
+
def database_url=(url)
|
24
|
+
@database_url = url
|
25
|
+
db_info = URI.parse(@database_url)
|
26
|
+
@db_name = db_info.path.gsub(/^\//, '')
|
27
|
+
@db_user = db_info.user
|
28
|
+
@db_password = db_info.password
|
29
|
+
@db_host = db_info.host
|
30
|
+
@db_port = db_info.port
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -1,17 +1,27 @@
|
|
1
1
|
require "uri"
|
2
2
|
require "mongo"
|
3
|
+
|
3
4
|
module MiniMongo
|
4
5
|
module Connection
|
5
|
-
def database_url=(url)
|
6
|
-
@@database_url = url
|
7
|
-
end
|
8
6
|
|
9
7
|
def db_connection
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
@@db_connection ||= Mongo::Connection.new(
|
9
|
+
MiniMongo.configuration.db_host,
|
10
|
+
MiniMongo.configuration.db_port,
|
11
|
+
:slave_ok => MiniMongo.configuration.slave_ok)
|
12
|
+
.db(MiniMongo.configuration.db_name)
|
13
|
+
authenticate_user
|
14
14
|
@@db_connection
|
15
15
|
end
|
16
|
+
|
17
|
+
def drop
|
18
|
+
self.db_connection.drop_database(@@db_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def authenticate_user
|
22
|
+
@@db_connection.authenticate(
|
23
|
+
MiniMongo.configuration.db_user,
|
24
|
+
MiniMongo.configuration.db_password)if MiniMongo.configuration.db_user&& !MiniMongo.configuration.db_user.empty?
|
25
|
+
end
|
16
26
|
end
|
17
27
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module MiniMongo
|
2
|
+
module Core
|
3
|
+
|
4
|
+
attr_reader :attributes
|
5
|
+
|
6
|
+
alias_method :to_hash, :attributes
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
@attributes = {}
|
10
|
+
assign_attributes(attributes.dup)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return an array with this +Document+ only in it.
|
14
|
+
#
|
15
|
+
# @example Return the document in an array.
|
16
|
+
# document.to_a
|
17
|
+
#
|
18
|
+
def to_a
|
19
|
+
attributes.to_a
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def inspect
|
24
|
+
inspection = if attributes
|
25
|
+
attributes.collect { |key, value|
|
26
|
+
"#{key}: #{value_for_inspect(value)}"
|
27
|
+
}.compact.join(", ")
|
28
|
+
else
|
29
|
+
"not initialized"
|
30
|
+
end
|
31
|
+
"#<#{self.class} #{inspection}>"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def value_for_inspect(value)
|
37
|
+
if value.is_a?(String) && value.length > 50
|
38
|
+
"#{value[0..50]}...".inspect
|
39
|
+
elsif value.is_a?(Date) || value.is_a?(Time)
|
40
|
+
%("#{value.to_s(:db)}")
|
41
|
+
else
|
42
|
+
value.inspect
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/mini_mongo/mapper.rb
CHANGED
@@ -1,36 +1,72 @@
|
|
1
1
|
require "uri"
|
2
2
|
require "mongo"
|
3
|
+
|
3
4
|
module MiniMongo
|
4
5
|
module Mapper
|
5
6
|
def self.included(base)
|
6
7
|
base.send :extend, ClassMethods
|
7
8
|
end
|
8
9
|
|
9
|
-
|
10
10
|
module ClassMethods
|
11
|
-
def find(
|
12
|
-
|
13
|
-
|
11
|
+
def find(attrs={})
|
12
|
+
attrs["_id"] = BSON::ObjectId(attrs["id"]) if attrs["id"]
|
13
|
+
attrs.delete("id")
|
14
|
+
docs = self.collection.find(attrs).to_a
|
15
|
+
if docs.empty?
|
16
|
+
raise DocumentNotFound, "Couldn't find #{self.collection_name.capitalize}, with #{attrs.to_a.collect {|p| p.join(' = ')}.join(', ')}"
|
17
|
+
else
|
18
|
+
result = []
|
19
|
+
docs.each do |doc|
|
20
|
+
result << self.class_eval("new(#{doc})") if doc
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|
14
24
|
end
|
15
25
|
|
16
26
|
def insert(attrs={})
|
17
|
-
doc =
|
18
|
-
self.
|
27
|
+
doc = {}
|
28
|
+
doc["_id"] = self.collection.insert(attrs).to_s
|
29
|
+
doc.merge!(attrs)
|
30
|
+
self.new(doc)
|
19
31
|
end
|
20
32
|
|
21
33
|
def update(id, attrs={})
|
22
|
-
|
23
|
-
self.class_eval("new(#{doc})")
|
34
|
+
self.collection.update({"_id" => BSON::ObjectId(id)}, attrs)
|
24
35
|
end
|
25
36
|
|
26
37
|
def remove(id)
|
27
|
-
|
38
|
+
self.collection.remove("_id" => BSON::ObjectId(id))
|
39
|
+
end
|
40
|
+
|
41
|
+
def count
|
42
|
+
self.collection.count
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove_all
|
46
|
+
self.collection.remove
|
28
47
|
end
|
29
48
|
|
30
49
|
def maps(name)
|
31
|
-
|
32
|
-
|
50
|
+
self.collection_name = name.to_s
|
51
|
+
self.collection = MiniMongo.db_connection.collection(name.to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
def collection
|
55
|
+
@@collection
|
33
56
|
end
|
57
|
+
|
58
|
+
def collection=(collection)
|
59
|
+
@@collection = collection
|
60
|
+
end
|
61
|
+
|
62
|
+
def collection_name
|
63
|
+
@@collection_name
|
64
|
+
end
|
65
|
+
|
66
|
+
def collection_name=(collection_name)
|
67
|
+
@@collection_name = collection_name
|
68
|
+
end
|
69
|
+
|
34
70
|
end
|
35
71
|
end
|
36
72
|
end
|
data/lib/mini_mongo/version.rb
CHANGED
data/lib/mini_mongo.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
require "mini_mongo/configuration"
|
1
2
|
module MiniMongo
|
2
3
|
autoload :Connection, 'mini_mongo/connection'
|
4
|
+
autoload :MiniMongoError, 'mini_mongo/errors'
|
5
|
+
autoload :DocumentNotFound, 'mini_mongo/errors'
|
3
6
|
autoload :Mapper, 'mini_mongo/mapper'
|
4
7
|
autoload :Base, 'mini_mongo/base'
|
8
|
+
autoload :Core, 'mini_mongo/core'
|
9
|
+
autoload :AttributeAssignment, 'mini_mongo/attribute_assignment'
|
10
|
+
autoload :Comparable, 'mini_mongo/comparable'
|
11
|
+
autoload :Serialization, 'mini_mongo/serialization'
|
5
12
|
extend Connection
|
6
13
|
end
|
data/mini_mongo.gemspec
CHANGED
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Base" do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@post1 = Post.insert({:author => "Chuck Norris"})
|
7
|
+
@post2 = Post.find(:author => "Chuck Norris").first
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "<=>" do
|
11
|
+
it "return Integer -1, 0, 1" do
|
12
|
+
(@post1 <=> @post2).should == 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "==" do
|
17
|
+
it "return True if the ids are equal, false if not" do
|
18
|
+
@post1.should == @post2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "===" do
|
23
|
+
it "return True if the classes are equal, false if not" do
|
24
|
+
@post1.should === @post2
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "eql?" do
|
29
|
+
it "return True if equal, false if not" do
|
30
|
+
@post1.eql?(@post2).should == true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Configuration" do
|
4
|
+
it "should set the configuration vars from database url" do
|
5
|
+
MiniMongo.configure do |config|
|
6
|
+
config.database_url = "mongodb://:@localhost:27017/posts"
|
7
|
+
end
|
8
|
+
MiniMongo.configuration.db_name.should == "posts"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should set configuration vars" do
|
12
|
+
MiniMongo.configure do |config|
|
13
|
+
config.db_user = "roberto"
|
14
|
+
end
|
15
|
+
MiniMongo.configuration.db_user.should == "roberto"
|
16
|
+
end
|
17
|
+
end
|
data/spec/mapper_spec.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe "Mapper" do
|
3
|
+
def post_attributes
|
4
|
+
{:author => "Chuck Norris"}
|
5
|
+
end
|
6
|
+
|
7
|
+
let!(:post){ Post.insert(post_attributes) }
|
8
|
+
|
9
|
+
describe "#insert" do
|
10
|
+
it "create a new Document" do
|
11
|
+
expect do
|
12
|
+
post = Post.insert(post_attributes)
|
13
|
+
end.to change(Post, :count).by(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#find" do
|
18
|
+
it "returns the document" do
|
19
|
+
Post.find(:author => "Chuck Norris").should == [post]
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raise Document not found" do
|
23
|
+
proc { Post.find(:author => "Chuck Norri") }.should raise_error(MiniMongo::DocumentNotFound)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#update" do
|
28
|
+
pending
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#remove" do
|
32
|
+
it "destroy the document" do
|
33
|
+
expect do
|
34
|
+
Post.remove(post.id)
|
35
|
+
end.to change(Post, :count).by(-1)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "count" do
|
40
|
+
it "return the number of document" do
|
41
|
+
post
|
42
|
+
Post.count.should == 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "remove_all" do
|
47
|
+
it "destroy all the documents" do
|
48
|
+
post
|
49
|
+
expect do
|
50
|
+
Post.remove_all
|
51
|
+
end.to change(Post, :count).by(-1)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/spec/models/post.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$: << File.dirname(__FILE__)
|
2
|
+
ENV['RACK_ENV'] = "test"
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
Dir["./lib/*.rb"].each {|file| require file }
|
8
|
+
|
9
|
+
MiniMongo.configure do |config|
|
10
|
+
config.database_url = "mongodb://:@localhost:27017/posts"
|
11
|
+
end
|
12
|
+
|
13
|
+
Dir["./spec/models/*.rb"].each {|file| require file }
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
|
17
|
+
config.before(:each) do
|
18
|
+
Post.remove_all
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mongo
|
@@ -44,6 +44,54 @@ dependencies:
|
|
44
44
|
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 1.6.4
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: simplecov
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: rake
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
47
95
|
description: Basics Object Mapper for Mongo
|
48
96
|
email:
|
49
97
|
- rjmaltamar@gmail.com
|
@@ -53,17 +101,31 @@ extensions: []
|
|
53
101
|
extra_rdoc_files: []
|
54
102
|
files:
|
55
103
|
- .gitignore
|
104
|
+
- .rspec
|
56
105
|
- .rvmrc
|
106
|
+
- .travis.yml
|
57
107
|
- Gemfile
|
58
108
|
- LICENSE
|
59
109
|
- README.md
|
60
110
|
- Rakefile
|
111
|
+
- examples/post.rb
|
61
112
|
- lib/mini_mongo.rb
|
113
|
+
- lib/mini_mongo/attribute_assignment.rb
|
62
114
|
- lib/mini_mongo/base.rb
|
115
|
+
- lib/mini_mongo/comparable.rb
|
116
|
+
- lib/mini_mongo/configuration.rb
|
63
117
|
- lib/mini_mongo/connection.rb
|
118
|
+
- lib/mini_mongo/core.rb
|
119
|
+
- lib/mini_mongo/errors.rb
|
64
120
|
- lib/mini_mongo/mapper.rb
|
121
|
+
- lib/mini_mongo/serialization.rb
|
65
122
|
- lib/mini_mongo/version.rb
|
66
123
|
- mini_mongo.gemspec
|
124
|
+
- spec/base_spec.rb
|
125
|
+
- spec/configutation_spec.rb
|
126
|
+
- spec/mapper_spec.rb
|
127
|
+
- spec/models/post.rb
|
128
|
+
- spec/spec_helper.rb
|
67
129
|
homepage: https://github.com/robertomiranda/mini_mongo
|
68
130
|
licenses: []
|
69
131
|
post_install_message:
|
@@ -88,4 +150,9 @@ rubygems_version: 1.8.21
|
|
88
150
|
signing_key:
|
89
151
|
specification_version: 3
|
90
152
|
summary: A Ruby Object Mapper for Mongo
|
91
|
-
test_files:
|
153
|
+
test_files:
|
154
|
+
- spec/base_spec.rb
|
155
|
+
- spec/configutation_spec.rb
|
156
|
+
- spec/mapper_spec.rb
|
157
|
+
- spec/models/post.rb
|
158
|
+
- spec/spec_helper.rb
|