mongo_doc_rails2 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/.rvmrc +2 -0
- data/README.textile +19 -7
- data/Rakefile +17 -34
- data/VERSION +1 -1
- data/features/support/support.rb +2 -1
- data/lib/mongo_doc.rb +4 -3
- data/lib/mongo_doc/attributes.rb +1 -0
- data/lib/mongo_doc/connection.rb +7 -27
- data/lib/mongo_doc/document.rb +13 -1
- data/lib/mongo_doc/ext/numeric.rb +2 -2
- data/lib/mongo_doc/validations.rb +3 -6
- data/lib/mongo_doc/validations/validates_embedded.rb +9 -5
- data/mongo_doc_rails2.gemspec +14 -17
- data/spec/array_including_argument_matcher.rb +1 -1
- data/spec/associations/collection_proxy_spec.rb +1 -1
- data/spec/associations/document_proxy_spec.rb +1 -1
- data/spec/associations/hash_proxy_spec.rb +1 -1
- data/spec/attributes_spec.rb +14 -1
- data/spec/bson_spec.rb +1 -1
- data/spec/collection_spec.rb +2 -2
- data/spec/connection_spec.rb +16 -9
- data/spec/contexts_spec.rb +1 -1
- data/spec/cursor_spec.rb +1 -1
- data/spec/document_spec.rb +127 -0
- data/spec/embedded_save_spec.rb +1 -1
- data/spec/ext_spec.rb +6 -6
- data/spec/finders_spec.rb +1 -1
- data/spec/index_spec.rb +1 -1
- data/spec/matchers_spec.rb +1 -1
- data/spec/new_record_spec.rb +1 -1
- data/spec/scope_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- data/spec/validations_spec.rb +1 -1
- metadata +29 -11
- data/data/.gitignore +0 -2
- data/lib/mongo_doc/validations/macros.rb +0 -11
- data/mongod.example.yml +0 -2
- data/spec/spec.opts +0 -2
data/.gitignore
CHANGED
data/.rvmrc
ADDED
data/README.textile
CHANGED
@@ -1,27 +1,28 @@
|
|
1
1
|
h1. MongoDoc
|
2
2
|
|
3
|
-
Version: Hurricane (0.6.
|
3
|
+
Version: Hurricane (0.6.2) 2010/06/25
|
4
4
|
|
5
5
|
h2. Notes
|
6
6
|
|
7
|
-
This version of MongoDoc
|
7
|
+
This version of MongoDoc works with Rails 3[1]
|
8
8
|
|
9
9
|
h2. Quick Start
|
10
10
|
|
11
11
|
* install MongoDB (at least 1.4.0)
|
12
12
|
* install the Ruby driver @gem install mongo@
|
13
|
-
* install
|
13
|
+
* install the native extensions for BSON @gem install bson_ext@
|
14
|
+
* install MongoDoc @gem install mongo_doc@
|
14
15
|
* run an example from this directory @ruby -Ilib examples/simple_object.rb@
|
15
16
|
|
16
17
|
h2. Introduction
|
17
18
|
|
18
19
|
MongoDoc is a simple and easy to use ActiveRecord-like object mapper for "mongoDB":http://www.mongodb.org in Ruby.
|
19
20
|
|
20
|
-
MongoDoc is _also_ an extension of the "Mongo Ruby Driver":http://github.com/mongodb/mongo-ruby-driver making it a
|
21
|
+
MongoDoc is _also_ an extension of the "Mongo Ruby Driver":http://github.com/mongodb/mongo-ruby-driver making it a snap to get Ruby in and out of mongoDB.
|
21
22
|
|
22
23
|
MongoDoc is *not* ActiveRecord for mongoDB. We do not have callbacks, nor do we have dynamic finders. We do have associations, named scopes, and other features.
|
23
24
|
|
24
|
-
MongoDoc *is* simple, easy-to-use, and fast.
|
25
|
+
MongoDoc *is* simple, easy-to-use, and fast. And it works with Rails 3.
|
25
26
|
|
26
27
|
MongoDoc is designed to work with document data, if you are looking to map relational data in mongoDB, you will have to look elsewhere.
|
27
28
|
|
@@ -114,7 +115,7 @@ h2. Installation
|
|
114
115
|
|
115
116
|
MongoDoc *requires* mongoDB v1.4.0 or later.
|
116
117
|
|
117
|
-
bc. gem install
|
118
|
+
bc. % gem install mongo_doc
|
118
119
|
|
119
120
|
h2. Connecting
|
120
121
|
|
@@ -155,6 +156,17 @@ Finally, if you do not want to use the database configuration file, you can also
|
|
155
156
|
|
156
157
|
bc. MongoDoc::Connection.name = 'stats'
|
157
158
|
|
159
|
+
h2. Cleaning the database during testing
|
160
|
+
|
161
|
+
When testing you may need to clean up and return the database to an empty state. @MongoDoc::DatabaseCleaner.clean_database@ is a helper that can be used to do this, for example with @RSpec@ (note the @require@):
|
162
|
+
|
163
|
+
bc. require 'mongo_doc/database_cleaner'
|
164
|
+
RSpec.configure do |config|
|
165
|
+
config.before(:each) do
|
166
|
+
MongoDoc::DatabaseCleaner.clean_database
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
158
170
|
h2. Credits
|
159
171
|
|
160
172
|
Les Hill, leshill on github
|
@@ -180,6 +192,6 @@ h2. Copyright
|
|
180
192
|
|
181
193
|
Copyright (c) 2009 - 2010 Les Hill. See LICENSE for details.
|
182
194
|
|
183
|
-
fn1. If you are using Rails 3.x you need to be using the @
|
195
|
+
fn1. If you are using Rails 2.3.x you need to be using the @mongo_doc_rails2@ gem from the rails2 branch on "github":http://github.com/leshill/mongodoc/tree/rails2
|
184
196
|
|
185
197
|
fn2. The Ruby driver exposes an API that understands JSON.
|
data/Rakefile
CHANGED
@@ -3,20 +3,20 @@ require 'rake'
|
|
3
3
|
begin
|
4
4
|
require 'jeweler'
|
5
5
|
Jeweler::Tasks.new do |gem|
|
6
|
-
gem.name = "
|
7
|
-
gem.summary = %Q{ODM for MongoDB
|
8
|
-
gem.description = %Q{ODM for MongoDB
|
6
|
+
gem.name = "mongo_doc"
|
7
|
+
gem.summary = %Q{ODM for MongoDB}
|
8
|
+
gem.description = %Q{ODM for MongoDB}
|
9
9
|
gem.email = "leshill@gmail.com"
|
10
10
|
gem.homepage = "http://github.com/leshill/mongodoc"
|
11
11
|
gem.authors = ["Les Hill"]
|
12
|
-
gem.add_dependency "activesupport", ">=
|
13
|
-
gem.add_dependency "
|
14
|
-
gem.add_dependency "
|
15
|
-
gem.add_dependency "
|
16
|
-
gem.add_dependency "
|
17
|
-
gem.
|
18
|
-
gem.add_development_dependency "
|
19
|
-
gem
|
12
|
+
gem.add_dependency "activesupport", ">= 3.0.0.beta.4"
|
13
|
+
gem.add_dependency "activemodel", ">=3.0.0.beta.4"
|
14
|
+
gem.add_dependency "mongo", ">= 1.0.0"
|
15
|
+
gem.add_dependency "bson", ">= 1.0.0"
|
16
|
+
gem.add_dependency "bson_ext", ">= 1.0.0"
|
17
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.12"
|
18
|
+
gem.add_development_dependency "cucumber", ">= 0.8.3"
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
20
|
end
|
21
21
|
Jeweler::GemcutterTasks.new
|
22
22
|
rescue LoadError
|
@@ -34,16 +34,14 @@ namespace :cucumber do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
require '
|
38
|
-
|
39
|
-
spec.
|
40
|
-
spec.
|
41
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
37
|
+
require 'rspec/core/rake_task'
|
38
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
39
|
+
spec.ruby_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
|
40
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
42
41
|
end
|
43
42
|
|
44
|
-
|
45
|
-
spec.
|
46
|
-
spec.libs << 'lib' << 'spec'
|
43
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
44
|
+
spec.ruby_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
|
47
45
|
spec.pattern = 'spec/**/*_spec.rb'
|
48
46
|
spec.rcov = true
|
49
47
|
end
|
@@ -66,21 +64,6 @@ Rake::RDocTask.new do |rdoc|
|
|
66
64
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
67
65
|
end
|
68
66
|
|
69
|
-
namespace :mongo do
|
70
|
-
desc 'Start mongod'
|
71
|
-
task :start do
|
72
|
-
default_config = { "dbpath" => "/data/db" }
|
73
|
-
config = begin
|
74
|
-
YAML.load_file(File.join(File.dirname(__FILE__), 'mongod.yml'))
|
75
|
-
rescue Exception => e
|
76
|
-
{}
|
77
|
-
end
|
78
|
-
config = default_config.merge(config)
|
79
|
-
sh("nohup #{config['mongod'] || 'mongod'} --dbpath #{config['dbpath']} &")
|
80
|
-
puts "\n"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
67
|
namespace :mongoid do
|
85
68
|
desc 'Sync criteria from Mongoid'
|
86
69
|
task :sync do
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.3
|
data/features/support/support.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
2
2
|
require 'cucumber'
|
3
|
-
require '
|
3
|
+
require 'rspec/expectations'
|
4
4
|
require 'spec/bson_matchers'
|
5
5
|
require 'mongo_doc'
|
6
|
+
require 'active_support/json'
|
6
7
|
|
7
8
|
MongoDoc::Connection.env = 'cucumber'
|
8
9
|
MongoDoc::Connection.config_path = './features/mongodb.yml'
|
data/lib/mongo_doc.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'mongo'
|
2
2
|
require 'active_support'
|
3
|
-
require '
|
4
|
-
require 'will_paginate/collection'
|
3
|
+
require 'active_support/core_ext'
|
5
4
|
|
6
5
|
module MongoDoc
|
7
|
-
VERSION = '0.6.
|
6
|
+
VERSION = '0.6.2'
|
8
7
|
end
|
9
8
|
|
10
9
|
require 'mongo_doc/connection'
|
11
10
|
require 'mongo_doc/collection'
|
12
11
|
require 'mongo_doc/document'
|
12
|
+
|
13
|
+
require 'mongo_doc/railtie' if defined?(Rails)
|
data/lib/mongo_doc/attributes.rb
CHANGED
data/lib/mongo_doc/connection.rb
CHANGED
@@ -6,10 +6,10 @@ module MongoDoc
|
|
6
6
|
|
7
7
|
extend self
|
8
8
|
|
9
|
-
attr_writer :config_path, :env, :host, :name, :options, :port, :strict
|
9
|
+
attr_writer :config_path, :default_name, :env, :host, :name, :options, :port, :strict
|
10
10
|
|
11
11
|
def config_path
|
12
|
-
@config_path ||
|
12
|
+
@config_path || './mongodb.yml'
|
13
13
|
end
|
14
14
|
|
15
15
|
def configuration
|
@@ -24,12 +24,12 @@ module MongoDoc
|
|
24
24
|
@database ||= connection.db(name, :strict => strict)
|
25
25
|
end
|
26
26
|
|
27
|
+
def default_name
|
28
|
+
@default_name ||= "mongo_doc"
|
29
|
+
end
|
30
|
+
|
27
31
|
def env
|
28
|
-
|
29
|
-
Rails.env
|
30
|
-
else
|
31
|
-
@env ||= 'development'
|
32
|
-
end
|
32
|
+
@env ||= 'development'
|
33
33
|
end
|
34
34
|
|
35
35
|
def host
|
@@ -61,26 +61,6 @@ module MongoDoc
|
|
61
61
|
connection
|
62
62
|
end
|
63
63
|
|
64
|
-
def default_name
|
65
|
-
if rails?
|
66
|
-
"#{Rails.root.basename}_#{Rails.env}"
|
67
|
-
else
|
68
|
-
"mongo_doc"
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def default_path
|
73
|
-
if rails?
|
74
|
-
Rails.root + 'config/mongodb.yml'
|
75
|
-
else
|
76
|
-
'./mongodb.yml'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def rails?
|
81
|
-
Object.const_defined?("Rails")
|
82
|
-
end
|
83
|
-
|
84
64
|
def verify_server_version(connection)
|
85
65
|
raise UnsupportedServerVersionError.new('MongoDoc requires at least mongoDB version 1.4.0') unless connection.server_version >= "1.4.0"
|
86
66
|
end
|
data/lib/mongo_doc/document.rb
CHANGED
@@ -6,6 +6,12 @@ require 'mongo_doc/criteria'
|
|
6
6
|
require 'mongo_doc/finders'
|
7
7
|
require 'mongo_doc/index'
|
8
8
|
require 'mongo_doc/scope'
|
9
|
+
require 'active_model/naming'
|
10
|
+
require 'active_model/translation'
|
11
|
+
require 'active_model/deprecated_error_methods'
|
12
|
+
require 'active_model/errors'
|
13
|
+
require 'active_model/validator'
|
14
|
+
require 'active_model/validations'
|
9
15
|
require 'mongo_doc/validations'
|
10
16
|
|
11
17
|
module MongoDoc
|
@@ -25,7 +31,9 @@ module MongoDoc
|
|
25
31
|
extend Finders
|
26
32
|
extend Index
|
27
33
|
extend Scope
|
28
|
-
include Validations
|
34
|
+
include ::ActiveModel::Validations
|
35
|
+
extend ::ActiveModel::Naming
|
36
|
+
extend Validations
|
29
37
|
|
30
38
|
alias id _id
|
31
39
|
end
|
@@ -44,6 +52,10 @@ module MongoDoc
|
|
44
52
|
self.class._attributes.all? {|var| self.send(var) == other.send(var)}
|
45
53
|
end
|
46
54
|
|
55
|
+
def destroyed?
|
56
|
+
_id.nil?
|
57
|
+
end
|
58
|
+
|
47
59
|
def new_record?
|
48
60
|
_id.nil?
|
49
61
|
end
|
@@ -1,12 +1,9 @@
|
|
1
|
-
require 'mongo_doc/validations/
|
1
|
+
require 'mongo_doc/validations/validates_embedded'
|
2
2
|
|
3
3
|
module MongoDoc
|
4
4
|
module Validations
|
5
|
-
def self.
|
6
|
-
klass.
|
7
|
-
include ::Validatable
|
8
|
-
extend Macros
|
9
|
-
end
|
5
|
+
def self.extended(klass)
|
6
|
+
klass.extend MongoDoc::Validations::ValidatesEmbedded
|
10
7
|
end
|
11
8
|
end
|
12
9
|
end
|
@@ -1,12 +1,16 @@
|
|
1
1
|
module MongoDoc
|
2
2
|
module Validations
|
3
|
-
|
4
|
-
def
|
5
|
-
|
3
|
+
module ValidatesEmbedded
|
4
|
+
def validates_embedded(*attr_names)
|
5
|
+
validates_with EmbeddedValidator, _merge_attributes(attr_names)
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
class EmbeddedValidator < ::ActiveModel::EachValidator
|
9
|
+
def validate(record)
|
10
|
+
attributes.each do |attr|
|
11
|
+
record.errors.add(attr) unless record.send(attr).valid?
|
12
|
+
end
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
data/mongo_doc_rails2.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongo_doc_rails2}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Les Hill"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-06-30}
|
13
13
|
s.description = %q{ODM for MongoDB - for Rails 2.3.x}
|
14
14
|
s.email = %q{leshill@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -20,13 +20,13 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.files = [
|
21
21
|
".document",
|
22
22
|
".gitignore",
|
23
|
+
".rvmrc",
|
23
24
|
"HISTORY.md",
|
24
25
|
"LICENSE",
|
25
26
|
"README.textile",
|
26
27
|
"Rakefile",
|
27
28
|
"TODO",
|
28
29
|
"VERSION",
|
29
|
-
"data/.gitignore",
|
30
30
|
"examples/simple_document.rb",
|
31
31
|
"examples/simple_object.rb",
|
32
32
|
"features/collections.feature",
|
@@ -97,7 +97,6 @@ Gem::Specification.new do |s|
|
|
97
97
|
"lib/mongo_doc/root.rb",
|
98
98
|
"lib/mongo_doc/scope.rb",
|
99
99
|
"lib/mongo_doc/validations.rb",
|
100
|
-
"lib/mongo_doc/validations/macros.rb",
|
101
100
|
"lib/mongo_doc/validations/validates_embedded.rb",
|
102
101
|
"lib/mongoid/contexts/enumerable.rb",
|
103
102
|
"lib/mongoid/contexts/paging.rb",
|
@@ -120,7 +119,6 @@ Gem::Specification.new do |s|
|
|
120
119
|
"lib/mongoid/matchers/nin.rb",
|
121
120
|
"lib/mongoid/matchers/size.rb",
|
122
121
|
"mongo_doc_rails2.gemspec",
|
123
|
-
"mongod.example.yml",
|
124
122
|
"mongodb.example.yml",
|
125
123
|
"perf/mongo_doc_object.rb",
|
126
124
|
"perf/mongo_document.rb",
|
@@ -156,14 +154,13 @@ Gem::Specification.new do |s|
|
|
156
154
|
"spec/new_record_spec.rb",
|
157
155
|
"spec/root_spec.rb",
|
158
156
|
"spec/scope_spec.rb",
|
159
|
-
"spec/spec.opts",
|
160
157
|
"spec/spec_helper.rb",
|
161
158
|
"spec/validations_spec.rb"
|
162
159
|
]
|
163
160
|
s.homepage = %q{http://github.com/leshill/mongodoc}
|
164
161
|
s.rdoc_options = ["--charset=UTF-8"]
|
165
162
|
s.require_paths = ["lib"]
|
166
|
-
s.rubygems_version = %q{1.3.
|
163
|
+
s.rubygems_version = %q{1.3.7}
|
167
164
|
s.summary = %q{ODM for MongoDB - for Rails 2.3.x}
|
168
165
|
s.test_files = [
|
169
166
|
"spec/array_including_argument_matcher.rb",
|
@@ -204,20 +201,20 @@ Gem::Specification.new do |s|
|
|
204
201
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
205
202
|
s.specification_version = 3
|
206
203
|
|
207
|
-
if Gem::Version.new(Gem::
|
204
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
208
205
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
|
209
|
-
s.add_runtime_dependency(%q<mongo>, ["
|
210
|
-
s.add_runtime_dependency(%q<bson>, ["
|
211
|
-
s.add_runtime_dependency(%q<bson_ext>, ["
|
206
|
+
s.add_runtime_dependency(%q<mongo>, [">= 1.0.1"])
|
207
|
+
s.add_runtime_dependency(%q<bson>, [">= 1.0.1"])
|
208
|
+
s.add_runtime_dependency(%q<bson_ext>, [">= 1.0.1"])
|
212
209
|
s.add_runtime_dependency(%q<durran-validatable>, ["= 2.0.1"])
|
213
210
|
s.add_runtime_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
|
214
211
|
s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
|
215
212
|
s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
|
216
213
|
else
|
217
214
|
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
218
|
-
s.add_dependency(%q<mongo>, ["
|
219
|
-
s.add_dependency(%q<bson>, ["
|
220
|
-
s.add_dependency(%q<bson_ext>, ["
|
215
|
+
s.add_dependency(%q<mongo>, [">= 1.0.1"])
|
216
|
+
s.add_dependency(%q<bson>, [">= 1.0.1"])
|
217
|
+
s.add_dependency(%q<bson_ext>, [">= 1.0.1"])
|
221
218
|
s.add_dependency(%q<durran-validatable>, ["= 2.0.1"])
|
222
219
|
s.add_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
|
223
220
|
s.add_dependency(%q<rspec>, ["= 1.3.0"])
|
@@ -225,9 +222,9 @@ Gem::Specification.new do |s|
|
|
225
222
|
end
|
226
223
|
else
|
227
224
|
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
228
|
-
s.add_dependency(%q<mongo>, ["
|
229
|
-
s.add_dependency(%q<bson>, ["
|
230
|
-
s.add_dependency(%q<bson_ext>, ["
|
225
|
+
s.add_dependency(%q<mongo>, [">= 1.0.1"])
|
226
|
+
s.add_dependency(%q<bson>, [">= 1.0.1"])
|
227
|
+
s.add_dependency(%q<bson_ext>, [">= 1.0.1"])
|
231
228
|
s.add_dependency(%q<durran-validatable>, ["= 2.0.1"])
|
232
229
|
s.add_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
|
233
230
|
s.add_dependency(%q<rspec>, ["= 1.3.0"])
|
data/spec/attributes_spec.rb
CHANGED
@@ -27,10 +27,23 @@ describe "MongoDoc::Attributes" do
|
|
27
27
|
include MongoDoc::Attributes
|
28
28
|
|
29
29
|
attr_accessor :attr1, :attr2
|
30
|
+
attr_accessor :validation_context
|
30
31
|
end
|
31
32
|
|
32
33
|
it "adds its arguments to _keys" do
|
33
|
-
TestKeys._keys.should
|
34
|
+
TestKeys._keys.should include(:attr1, :attr2)
|
35
|
+
end
|
36
|
+
|
37
|
+
context "the :validation_context attribute from ActiveModel" do
|
38
|
+
|
39
|
+
it "is an attribute" do
|
40
|
+
TestKeys.new.should respond_to(:validation_context)
|
41
|
+
TestKeys.new.should respond_to(:validation_context=)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "is not in _keys" do
|
45
|
+
TestKeys._keys.should_not include(:validation_context)
|
46
|
+
end
|
34
47
|
end
|
35
48
|
|
36
49
|
describe "accessors" do
|
data/spec/bson_spec.rb
CHANGED
data/spec/collection_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "MongoDoc::Collection" do
|
4
4
|
|
@@ -85,9 +85,9 @@ describe "MongoDoc::Collection" do
|
|
85
85
|
|
86
86
|
context "#insert" do
|
87
87
|
let(:doc) { {'sample' => 'data'} }
|
88
|
+
let(:options) { {:safe => false} }
|
88
89
|
|
89
90
|
it "delegates to the Mongo::Collection" do
|
90
|
-
options = {:safe => false}
|
91
91
|
mongo_collection.should_receive(:insert).with(doc, options)
|
92
92
|
collection.insert(doc, options)
|
93
93
|
end
|
data/spec/connection_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
# Resets for testing
|
4
4
|
module MongoDoc
|
@@ -53,23 +53,30 @@ describe "MongoDoc::Connection.Connections" do
|
|
53
53
|
|
54
54
|
context "Rails environment" do
|
55
55
|
|
56
|
+
class FauxApp
|
57
|
+
def root
|
58
|
+
Pathname.new('faux_app')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
56
62
|
module FauxRails
|
57
63
|
extend self
|
58
64
|
|
59
65
|
def env
|
60
|
-
'
|
66
|
+
'staging'
|
61
67
|
end
|
68
|
+
end
|
62
69
|
|
63
|
-
|
64
|
-
|
65
|
-
|
70
|
+
before(:all) do
|
71
|
+
Object.const_set('Rails', FauxRails)
|
72
|
+
require 'mongo_doc/railties/config'
|
66
73
|
end
|
67
74
|
|
68
75
|
before do
|
69
|
-
|
76
|
+
MongoDoc::Railties::Config.config(FauxApp.new)
|
70
77
|
end
|
71
78
|
|
72
|
-
after do
|
79
|
+
after(:all) do
|
73
80
|
Object.send(:remove_const, 'Rails')
|
74
81
|
end
|
75
82
|
|
@@ -78,7 +85,7 @@ describe "MongoDoc::Connection.Connections" do
|
|
78
85
|
end
|
79
86
|
|
80
87
|
it "default the configuration location to Rails.root + '/config/mongodb.yml'" do
|
81
|
-
MongoDoc::Connection.config_path.should ==
|
88
|
+
MongoDoc::Connection.config_path.to_s.should == 'faux_app/config/mongodb.yml'
|
82
89
|
end
|
83
90
|
|
84
91
|
context "without a configuration" do
|
@@ -95,7 +102,7 @@ describe "MongoDoc::Connection.Connections" do
|
|
95
102
|
end
|
96
103
|
|
97
104
|
it "creates a default database with strict false" do
|
98
|
-
connection.should_receive(:db).with("
|
105
|
+
connection.should_receive(:db).with("faux_app_staging", :strict => false)
|
99
106
|
MongoDoc::Connection.database
|
100
107
|
end
|
101
108
|
end
|
data/spec/contexts_spec.rb
CHANGED
data/spec/cursor_spec.rb
CHANGED
data/spec/document_spec.rb
CHANGED
@@ -550,4 +550,131 @@ describe "MongoDoc::Document" do
|
|
550
550
|
MongoDoc::Collection.should === ClassMethods.collection
|
551
551
|
end
|
552
552
|
end
|
553
|
+
|
554
|
+
context "ActiveModel compliance" do
|
555
|
+
class ActiveModelComplianceTest
|
556
|
+
include MongoDoc::Document
|
557
|
+
end
|
558
|
+
|
559
|
+
let(:model) { ActiveModelComplianceTest.new }
|
560
|
+
|
561
|
+
describe "#to_param" do
|
562
|
+
let(:string_id) { mock }
|
563
|
+
|
564
|
+
before(:each) do
|
565
|
+
model.instance_variable_set(:@_id, mock(:oid, :to_s => string_id))
|
566
|
+
end
|
567
|
+
|
568
|
+
it "returns the string form of the document id" do
|
569
|
+
model.to_param.should == string_id
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
describe "#valid?" do
|
574
|
+
subject { model }
|
575
|
+
it "responds to #valid?" do
|
576
|
+
should respond_to(:valid?)
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
describe "#new_record?" do
|
581
|
+
subject { model }
|
582
|
+
it "responds to #new_record?" do
|
583
|
+
should respond_to(:new_record?)
|
584
|
+
end
|
585
|
+
|
586
|
+
context "when the object has an id" do
|
587
|
+
before(:each) do
|
588
|
+
model.instance_variable_set(:@_id, mock(:id))
|
589
|
+
end
|
590
|
+
|
591
|
+
it "is false" do
|
592
|
+
should_not be_new_record
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
context "when the object has no id" do
|
597
|
+
before(:each) do
|
598
|
+
model.instance_variable_set(:@_id, nil)
|
599
|
+
end
|
600
|
+
|
601
|
+
it "is true" do
|
602
|
+
should be_new_record
|
603
|
+
end
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
describe "#destroyed?" do
|
608
|
+
subject { model }
|
609
|
+
|
610
|
+
it "responds to #destroyed?" do
|
611
|
+
should respond_to(:destroyed?)
|
612
|
+
end
|
613
|
+
|
614
|
+
context "when the object has an id" do
|
615
|
+
before(:each) do
|
616
|
+
model.instance_variable_set(:@_id, mock(:id))
|
617
|
+
end
|
618
|
+
|
619
|
+
it "is false" do
|
620
|
+
should_not be_destroyed
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
context "when the object has no id" do
|
625
|
+
before(:each) do
|
626
|
+
model.instance_variable_set(:@_id, nil)
|
627
|
+
end
|
628
|
+
|
629
|
+
it "is true" do
|
630
|
+
should be_destroyed
|
631
|
+
end
|
632
|
+
end
|
633
|
+
end
|
634
|
+
|
635
|
+
describe "#errors" do
|
636
|
+
subject { model }
|
637
|
+
it "responds to errors" do
|
638
|
+
should respond_to(:errors)
|
639
|
+
end
|
640
|
+
|
641
|
+
describe "#[]" do
|
642
|
+
it "returns an array on a missing key lookup" do
|
643
|
+
model.errors[:does_not_exist].should be_an(Array)
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
describe "#full_messages" do
|
648
|
+
it "returns an array" do
|
649
|
+
model.errors.full_messages.should be_an(Array)
|
650
|
+
end
|
651
|
+
end
|
652
|
+
end
|
653
|
+
|
654
|
+
describe ".model_name" do
|
655
|
+
it "responds to model_name" do
|
656
|
+
ActiveModelComplianceTest.should respond_to(:model_name)
|
657
|
+
end
|
658
|
+
|
659
|
+
it "is a string" do
|
660
|
+
ActiveModelComplianceTest.model_name.should be_a(String)
|
661
|
+
end
|
662
|
+
|
663
|
+
it "has a human inflector" do
|
664
|
+
ActiveModelComplianceTest.model_name.human.should be_a(String)
|
665
|
+
end
|
666
|
+
|
667
|
+
it "has a partial path inflector" do
|
668
|
+
ActiveModelComplianceTest.model_name.partial_path.should be_a(String)
|
669
|
+
end
|
670
|
+
|
671
|
+
it "has a singular inflector" do
|
672
|
+
ActiveModelComplianceTest.model_name.singular.should be_a(String)
|
673
|
+
end
|
674
|
+
|
675
|
+
it "has a plural inflector" do
|
676
|
+
ActiveModelComplianceTest.model_name.plural.should be_a(String)
|
677
|
+
end
|
678
|
+
end
|
679
|
+
end
|
553
680
|
end
|
data/spec/embedded_save_spec.rb
CHANGED
data/spec/ext_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'spec_helper
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "Ruby Object Extensions" do
|
4
4
|
context "Rails3 support" do
|
@@ -46,15 +46,15 @@ describe "Ruby Object Extensions" do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
context "
|
50
|
-
context "
|
49
|
+
context "Numbers" do
|
50
|
+
context "Float" do
|
51
51
|
it "returns nil for a blank string" do
|
52
|
-
|
52
|
+
Float.cast_from_string('').should be_nil
|
53
53
|
end
|
54
54
|
|
55
55
|
it "converts from a string to a BigDecimal" do
|
56
|
-
|
57
|
-
|
56
|
+
float = "12345.6789".to_f
|
57
|
+
Float.cast_from_string(float.to_s).should == float
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
data/spec/finders_spec.rb
CHANGED
data/spec/index_spec.rb
CHANGED
data/spec/matchers_spec.rb
CHANGED
data/spec/new_record_spec.rb
CHANGED
data/spec/scope_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
3
|
require 'mongo_doc'
|
4
|
-
require '
|
5
|
-
require '
|
4
|
+
require 'rspec'
|
5
|
+
require 'rspec/autorun'
|
6
6
|
require 'bson_matchers'
|
7
7
|
require 'hash_matchers'
|
8
8
|
require 'array_including_argument_matcher'
|
9
9
|
require 'document_ext'
|
10
10
|
|
11
|
-
|
11
|
+
RSpec.configure do |config|
|
12
12
|
config.include(BsonMatchers)
|
13
13
|
config.include(HashMatchers)
|
14
14
|
end
|
data/spec/validations_spec.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_doc_rails2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 6
|
8
|
-
-
|
9
|
-
version: 0.6.
|
9
|
+
- 2
|
10
|
+
version: 0.6.2
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Les Hill
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-30 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: activesupport
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 11
|
27
30
|
segments:
|
28
31
|
- 2
|
29
32
|
- 3
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: mongo
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
|
-
- - "
|
43
|
+
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 21
|
41
46
|
segments:
|
42
47
|
- 1
|
43
48
|
- 0
|
@@ -49,9 +54,11 @@ dependencies:
|
|
49
54
|
name: bson
|
50
55
|
prerelease: false
|
51
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
52
58
|
requirements:
|
53
|
-
- - "
|
59
|
+
- - ">="
|
54
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 21
|
55
62
|
segments:
|
56
63
|
- 1
|
57
64
|
- 0
|
@@ -63,9 +70,11 @@ dependencies:
|
|
63
70
|
name: bson_ext
|
64
71
|
prerelease: false
|
65
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
66
74
|
requirements:
|
67
|
-
- - "
|
75
|
+
- - ">="
|
68
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 21
|
69
78
|
segments:
|
70
79
|
- 1
|
71
80
|
- 0
|
@@ -77,9 +86,11 @@ dependencies:
|
|
77
86
|
name: durran-validatable
|
78
87
|
prerelease: false
|
79
88
|
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
80
90
|
requirements:
|
81
91
|
- - "="
|
82
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 13
|
83
94
|
segments:
|
84
95
|
- 2
|
85
96
|
- 0
|
@@ -91,9 +102,11 @@ dependencies:
|
|
91
102
|
name: leshill-will_paginate
|
92
103
|
prerelease: false
|
93
104
|
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
94
106
|
requirements:
|
95
107
|
- - "="
|
96
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 21
|
97
110
|
segments:
|
98
111
|
- 2
|
99
112
|
- 3
|
@@ -105,9 +118,11 @@ dependencies:
|
|
105
118
|
name: rspec
|
106
119
|
prerelease: false
|
107
120
|
requirement: &id007 !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
108
122
|
requirements:
|
109
123
|
- - "="
|
110
124
|
- !ruby/object:Gem::Version
|
125
|
+
hash: 27
|
111
126
|
segments:
|
112
127
|
- 1
|
113
128
|
- 3
|
@@ -119,9 +134,11 @@ dependencies:
|
|
119
134
|
name: cucumber
|
120
135
|
prerelease: false
|
121
136
|
requirement: &id008 !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
122
138
|
requirements:
|
123
139
|
- - ">="
|
124
140
|
- !ruby/object:Gem::Version
|
141
|
+
hash: 3
|
125
142
|
segments:
|
126
143
|
- 0
|
127
144
|
- 6
|
@@ -142,13 +159,13 @@ extra_rdoc_files:
|
|
142
159
|
files:
|
143
160
|
- .document
|
144
161
|
- .gitignore
|
162
|
+
- .rvmrc
|
145
163
|
- HISTORY.md
|
146
164
|
- LICENSE
|
147
165
|
- README.textile
|
148
166
|
- Rakefile
|
149
167
|
- TODO
|
150
168
|
- VERSION
|
151
|
-
- data/.gitignore
|
152
169
|
- examples/simple_document.rb
|
153
170
|
- examples/simple_object.rb
|
154
171
|
- features/collections.feature
|
@@ -219,7 +236,6 @@ files:
|
|
219
236
|
- lib/mongo_doc/root.rb
|
220
237
|
- lib/mongo_doc/scope.rb
|
221
238
|
- lib/mongo_doc/validations.rb
|
222
|
-
- lib/mongo_doc/validations/macros.rb
|
223
239
|
- lib/mongo_doc/validations/validates_embedded.rb
|
224
240
|
- lib/mongoid/contexts/enumerable.rb
|
225
241
|
- lib/mongoid/contexts/paging.rb
|
@@ -242,7 +258,6 @@ files:
|
|
242
258
|
- lib/mongoid/matchers/nin.rb
|
243
259
|
- lib/mongoid/matchers/size.rb
|
244
260
|
- mongo_doc_rails2.gemspec
|
245
|
-
- mongod.example.yml
|
246
261
|
- mongodb.example.yml
|
247
262
|
- perf/mongo_doc_object.rb
|
248
263
|
- perf/mongo_document.rb
|
@@ -278,7 +293,6 @@ files:
|
|
278
293
|
- spec/new_record_spec.rb
|
279
294
|
- spec/root_spec.rb
|
280
295
|
- spec/scope_spec.rb
|
281
|
-
- spec/spec.opts
|
282
296
|
- spec/spec_helper.rb
|
283
297
|
- spec/validations_spec.rb
|
284
298
|
has_rdoc: true
|
@@ -291,23 +305,27 @@ rdoc_options:
|
|
291
305
|
require_paths:
|
292
306
|
- lib
|
293
307
|
required_ruby_version: !ruby/object:Gem::Requirement
|
308
|
+
none: false
|
294
309
|
requirements:
|
295
310
|
- - ">="
|
296
311
|
- !ruby/object:Gem::Version
|
312
|
+
hash: 3
|
297
313
|
segments:
|
298
314
|
- 0
|
299
315
|
version: "0"
|
300
316
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
317
|
+
none: false
|
301
318
|
requirements:
|
302
319
|
- - ">="
|
303
320
|
- !ruby/object:Gem::Version
|
321
|
+
hash: 3
|
304
322
|
segments:
|
305
323
|
- 0
|
306
324
|
version: "0"
|
307
325
|
requirements: []
|
308
326
|
|
309
327
|
rubyforge_project:
|
310
|
-
rubygems_version: 1.3.
|
328
|
+
rubygems_version: 1.3.7
|
311
329
|
signing_key:
|
312
330
|
specification_version: 3
|
313
331
|
summary: ODM for MongoDB - for Rails 2.3.x
|
data/data/.gitignore
DELETED
data/mongod.example.yml
DELETED
data/spec/spec.opts
DELETED