mongo_doc 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  *.sw?
2
2
  .DS_Store
3
- .rvmrc
4
3
  coverage
5
4
  rdoc
6
5
  pkg
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm_gemset_create_on_use_flag=1
2
+ rvm gemset use mongo_doc
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ gem install activesupport -v ">= 3.0.0.beta"
2
+ gem install activemodel -v ">=3.0.0.beta"
3
+ gem install mongo -v "= 0.20.1"
4
+ gem install bson -v "= 0.20.1"
5
+ gem install bson_ext -v "= 0.20.1"
6
+ gem install leshill-will_paginate -v "= 2.3.11"
7
+ gem install rspec -v "= 1.3.0"
8
+ gem install cucumber -v ">= 0.6.2"
9
+
data/README.textile CHANGED
@@ -1,18 +1,16 @@
1
1
  h1. MongoDoc
2
2
 
3
- Version: Maelstrom (0.5.5) 2010/04/08
3
+ Version: Hurricane (0.6.0) 2010/05/14
4
4
 
5
5
  h2. Notes
6
6
 
7
- * 2010-03-12 Thanks to weather (in ATL, cleaned up attr_accessor and switched to embed association macros
8
- * 2010-03-10 Slides are out of date, use key instead of attr_accessor with MongoDoc::Document (implementation was way too hackish)
9
- * 2010-02-23 API is *changing* significantly
10
- * 2010-01-23 Tracking MongoDoc with @git@? *READ THIS NOTE*[1]
7
+ This version of MongoDoc works with Rails 3[1]
11
8
 
12
9
  h2. Quick Start
13
10
 
14
11
  * install MongoDB (at least 1.4.0)
15
12
  * install the Ruby driver @gem install mongo@
13
+ * install the native extensions for BSON @gem install bson_ext@
16
14
  * install MongoDoc @gem install mongo_doc@
17
15
  * run an example from this directory @ruby -Ilib examples/simple_object.rb@
18
16
 
@@ -24,7 +22,7 @@ MongoDoc is _also_ an extension of the "Mongo Ruby Driver":http://github.com/mon
24
22
 
25
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.
26
24
 
27
- MongoDoc *is* simple, easy-to-use, and fast. And it works with Rails (2.3.x at the moment, 3 soonish?).
25
+ MongoDoc *is* simple, easy-to-use, and fast. And it works with Rails 3.
28
26
 
29
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.
30
28
 
@@ -119,12 +117,6 @@ MongoDoc *requires* mongoDB v1.4.0 or later.
119
117
 
120
118
  bc. sudo gem install mongo_doc
121
119
 
122
- h2. Rails 3
123
-
124
- As of version 0.5.0, you can use the mongo_doc-rails gem to add Rails3 support.
125
-
126
- bc. sudo gem install mongo_doc-rails
127
-
128
120
  h2. Connecting
129
121
 
130
122
  By default, MongoDoc will read its configuration from @./mongodb.yml@. If that file does not exist, it will attempt to connect to a standard MongoDB local server setup and use a database name of @"mongodoc"@.
@@ -189,6 +181,6 @@ h2. Copyright
189
181
 
190
182
  Copyright (c) 2009 - 2010 Les Hill. See LICENSE for details.
191
183
 
192
- fn1. Building from @HEAD@? MongoDoc *requires* mongoDB v1.3.2 or later. That means you must be using the 1.3.x nightly build as of 2010-01-22 .
184
+ 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
193
185
 
194
186
  fn2. The Ruby driver exposes an API that understands JSON.
data/Rakefile CHANGED
@@ -9,11 +9,11 @@ begin
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", ">= 2.3.4"
12
+ gem.add_dependency "activesupport", ">= 3.0.0.beta"
13
+ gem.add_dependency "activemodel", ">=3.0.0.beta"
13
14
  gem.add_dependency "mongo", "= 0.20.1"
14
15
  gem.add_dependency "bson", "= 0.20.1"
15
16
  gem.add_dependency "bson_ext", "= 0.20.1"
16
- gem.add_dependency "durran-validatable", "= 2.0.1"
17
17
  gem.add_dependency "leshill-will_paginate", "= 2.3.11"
18
18
  gem.add_development_dependency "rspec", "= 1.3.0"
19
19
  gem.add_development_dependency "cucumber", ">= 0.6.2"
@@ -164,6 +164,12 @@ namespace :prof do
164
164
  runner.reads(10000)
165
165
  end
166
166
  end
167
+
168
+ Benchmark.bm do |bm|
169
+ bm.report(what + " query") do
170
+ runner.query_all
171
+ end
172
+ end
167
173
  end
168
174
 
169
175
  def profile(what, runner)
@@ -173,6 +179,7 @@ namespace :prof do
173
179
  runner.generate(1000)
174
180
  runner.writes(1000)
175
181
  runner.reads(1000)
182
+ runner.query_all
176
183
 
177
184
  result = RubyProf.stop
178
185
  printer = RubyProf::FlatPrinter.new(result)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.6.0
@@ -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,16 @@
1
1
  module MongoDoc
2
2
  module Validations
3
- class ValidatesEmbedded < ::Validatable::ValidationBase
4
- def valid?(instance)
5
- instance.send(attribute).valid?
3
+ module ValidatesEmbedded
4
+ def validates_embedded(*attr_names)
5
+ validates_with EmbeddedValidator, _merge_attributes(attr_names)
6
6
  end
7
7
 
8
- def message(instance)
9
- super || "is invalid"
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
@@ -1,16 +1,9 @@
1
+ require 'mongo_doc/validations/validates_embedded'
2
+
1
3
  module MongoDoc
2
4
  module Validations
3
- def self.included(klass)
4
- klass.class_eval do
5
- if MongoDoc.const_defined?('ActiveModel')
6
- include MongoDoc::ActiveModel::ActiveModelCompliance
7
- else
8
- require 'mongo_doc/validations/macros'
9
-
10
- include ::Validatable
11
- extend Macros
12
- end
13
- end
5
+ def self.extended(klass)
6
+ klass.extend MongoDoc::Validations::ValidatesEmbedded
14
7
  end
15
8
  end
16
9
  end
data/lib/mongo_doc.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'mongo'
2
2
  require 'active_support'
3
3
  require 'active_support/core_ext'
4
- require 'validatable'
5
4
  require 'will_paginate/collection'
6
5
 
7
6
  module MongoDoc
8
- VERSION = '0.5.4'
7
+ VERSION = '0.6.0'
9
8
  end
10
9
 
11
10
  require 'mongo_doc/connection'
data/mongo_doc.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_doc}
8
- s.version = "0.5.5"
8
+ s.version = "0.6.0"
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-04-08}
12
+ s.date = %q{2010-05-14}
13
13
  s.description = %q{ODM for MongoDB}
14
14
  s.email = %q{leshill@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.files = [
21
21
  ".document",
22
22
  ".gitignore",
23
+ ".rvmrc",
24
+ "Gemfile",
23
25
  "HISTORY.md",
24
26
  "LICENSE",
25
27
  "README.textile",
@@ -97,7 +99,6 @@ Gem::Specification.new do |s|
97
99
  "lib/mongo_doc/root.rb",
98
100
  "lib/mongo_doc/scope.rb",
99
101
  "lib/mongo_doc/validations.rb",
100
- "lib/mongo_doc/validations/macros.rb",
101
102
  "lib/mongo_doc/validations/validates_embedded.rb",
102
103
  "lib/mongoid/contexts/enumerable.rb",
103
104
  "lib/mongoid/contexts/paging.rb",
@@ -205,30 +206,30 @@ Gem::Specification.new do |s|
205
206
  s.specification_version = 3
206
207
 
207
208
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
208
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
209
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta"])
210
+ s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0.beta"])
209
211
  s.add_runtime_dependency(%q<mongo>, ["= 0.20.1"])
210
212
  s.add_runtime_dependency(%q<bson>, ["= 0.20.1"])
211
213
  s.add_runtime_dependency(%q<bson_ext>, ["= 0.20.1"])
212
- s.add_runtime_dependency(%q<durran-validatable>, ["= 2.0.1"])
213
214
  s.add_runtime_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
214
215
  s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
215
216
  s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
216
217
  else
217
- s.add_dependency(%q<activesupport>, [">= 2.3.4"])
218
+ s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
219
+ s.add_dependency(%q<activemodel>, [">= 3.0.0.beta"])
218
220
  s.add_dependency(%q<mongo>, ["= 0.20.1"])
219
221
  s.add_dependency(%q<bson>, ["= 0.20.1"])
220
222
  s.add_dependency(%q<bson_ext>, ["= 0.20.1"])
221
- s.add_dependency(%q<durran-validatable>, ["= 2.0.1"])
222
223
  s.add_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
223
224
  s.add_dependency(%q<rspec>, ["= 1.3.0"])
224
225
  s.add_dependency(%q<cucumber>, [">= 0.6.2"])
225
226
  end
226
227
  else
227
- s.add_dependency(%q<activesupport>, [">= 2.3.4"])
228
+ s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
229
+ s.add_dependency(%q<activemodel>, [">= 3.0.0.beta"])
228
230
  s.add_dependency(%q<mongo>, ["= 0.20.1"])
229
231
  s.add_dependency(%q<bson>, ["= 0.20.1"])
230
232
  s.add_dependency(%q<bson_ext>, ["= 0.20.1"])
231
- s.add_dependency(%q<durran-validatable>, ["= 2.0.1"])
232
233
  s.add_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
233
234
  s.add_dependency(%q<rspec>, ["= 1.3.0"])
234
235
  s.add_dependency(%q<cucumber>, [">= 0.6.2"])
@@ -75,4 +75,9 @@ class MongoDocObject
75
75
  end
76
76
  end
77
77
 
78
+ def query_all
79
+ collection.find.each do |obj|
80
+ given_name = obj.name.given
81
+ end
82
+ end
78
83
  end
@@ -75,4 +75,10 @@ class MongoDocument
75
75
  raise 'Not found' unless doc.name.given == documents[i].name.given
76
76
  end
77
77
  end
78
+
79
+ def query_all
80
+ collection.find.each do |doc|
81
+ given_name = doc.name.given
82
+ end
83
+ end
78
84
  end
data/perf/ruby_driver.rb CHANGED
@@ -40,4 +40,10 @@ class RubyDriver
40
40
  raise 'Not found' unless obj and obj['name']['given'] == objects[i][:name][:given]
41
41
  end
42
42
  end
43
+
44
+ def query_all
45
+ collection.find().each do |obj|
46
+ given_name = obj['name']['given']
47
+ end
48
+ end
43
49
  end
@@ -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
@@ -16,7 +16,7 @@ describe MongoDoc::Validations do
16
16
  it { should respond_to(:errors) }
17
17
 
18
18
  it "is included by Document" do
19
- MongoDoc::Validations.should === subject
19
+ ::ActiveModel::Validations.should === subject
20
20
  end
21
21
  end
22
22
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 5
8
- - 5
9
- version: 0.5.5
7
+ - 6
8
+ - 0
9
+ version: 0.6.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Les Hill
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-08 00:00:00 -04:00
17
+ date: 2010-05-14 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -25,28 +25,30 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
- - 2
29
28
  - 3
30
- - 4
31
- version: 2.3.4
29
+ - 0
30
+ - 0
31
+ - beta
32
+ version: 3.0.0.beta
32
33
  type: :runtime
33
34
  version_requirements: *id001
34
35
  - !ruby/object:Gem::Dependency
35
- name: mongo
36
+ name: activemodel
36
37
  prerelease: false
37
38
  requirement: &id002 !ruby/object:Gem::Requirement
38
39
  requirements:
39
- - - "="
40
+ - - ">="
40
41
  - !ruby/object:Gem::Version
41
42
  segments:
43
+ - 3
42
44
  - 0
43
- - 20
44
- - 1
45
- version: 0.20.1
45
+ - 0
46
+ - beta
47
+ version: 3.0.0.beta
46
48
  type: :runtime
47
49
  version_requirements: *id002
48
50
  - !ruby/object:Gem::Dependency
49
- name: bson
51
+ name: mongo
50
52
  prerelease: false
51
53
  requirement: &id003 !ruby/object:Gem::Requirement
52
54
  requirements:
@@ -60,7 +62,7 @@ dependencies:
60
62
  type: :runtime
61
63
  version_requirements: *id003
62
64
  - !ruby/object:Gem::Dependency
63
- name: bson_ext
65
+ name: bson
64
66
  prerelease: false
65
67
  requirement: &id004 !ruby/object:Gem::Requirement
66
68
  requirements:
@@ -74,17 +76,17 @@ dependencies:
74
76
  type: :runtime
75
77
  version_requirements: *id004
76
78
  - !ruby/object:Gem::Dependency
77
- name: durran-validatable
79
+ name: bson_ext
78
80
  prerelease: false
79
81
  requirement: &id005 !ruby/object:Gem::Requirement
80
82
  requirements:
81
83
  - - "="
82
84
  - !ruby/object:Gem::Version
83
85
  segments:
84
- - 2
85
86
  - 0
87
+ - 20
86
88
  - 1
87
- version: 2.0.1
89
+ version: 0.20.1
88
90
  type: :runtime
89
91
  version_requirements: *id005
90
92
  - !ruby/object:Gem::Dependency
@@ -142,6 +144,8 @@ extra_rdoc_files:
142
144
  files:
143
145
  - .document
144
146
  - .gitignore
147
+ - .rvmrc
148
+ - Gemfile
145
149
  - HISTORY.md
146
150
  - LICENSE
147
151
  - README.textile
@@ -219,7 +223,6 @@ files:
219
223
  - lib/mongo_doc/root.rb
220
224
  - lib/mongo_doc/scope.rb
221
225
  - lib/mongo_doc/validations.rb
222
- - lib/mongo_doc/validations/macros.rb
223
226
  - lib/mongo_doc/validations/validates_embedded.rb
224
227
  - lib/mongoid/contexts/enumerable.rb
225
228
  - lib/mongoid/contexts/paging.rb
@@ -1,11 +0,0 @@
1
- require 'mongo_doc/validations/validates_embedded'
2
-
3
- module MongoDoc
4
- module Validations
5
- module Macros
6
- def validates_embedded(*args)
7
- add_validations(args, MongoDoc::Validations::ValidatesEmbedded)
8
- end
9
- end
10
- end
11
- end