mongodoc 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +18 -0
  5. data/Rakefile +80 -0
  6. data/VERSION +1 -0
  7. data/data/.gitignore +2 -0
  8. data/features/mongodoc_base.feature +117 -0
  9. data/features/saving_an_object.feature +17 -0
  10. data/features/step_definitions/collection_steps.rb +14 -0
  11. data/features/step_definitions/connect_steps.rb +4 -0
  12. data/features/step_definitions/document_steps.rb +88 -0
  13. data/features/step_definitions/json_steps.rb +9 -0
  14. data/features/step_definitions/object_steps.rb +43 -0
  15. data/features/step_definitions/util_steps.rb +7 -0
  16. data/features/support/support.rb +9 -0
  17. data/lib/mongodoc.rb +17 -0
  18. data/lib/mongodoc/attributes.rb +97 -0
  19. data/lib/mongodoc/base.rb +163 -0
  20. data/lib/mongodoc/bson.rb +45 -0
  21. data/lib/mongodoc/connection.rb +20 -0
  22. data/lib/mongodoc/ext/array.rb +5 -0
  23. data/lib/mongodoc/ext/binary.rb +7 -0
  24. data/lib/mongodoc/ext/boolean_class.rb +11 -0
  25. data/lib/mongodoc/ext/date.rb +16 -0
  26. data/lib/mongodoc/ext/date_time.rb +13 -0
  27. data/lib/mongodoc/ext/dbref.rb +7 -0
  28. data/lib/mongodoc/ext/hash.rb +7 -0
  29. data/lib/mongodoc/ext/nil_class.rb +5 -0
  30. data/lib/mongodoc/ext/numeric.rb +17 -0
  31. data/lib/mongodoc/ext/object.rb +17 -0
  32. data/lib/mongodoc/ext/object_id.rb +7 -0
  33. data/lib/mongodoc/ext/regexp.rb +5 -0
  34. data/lib/mongodoc/ext/string.rb +5 -0
  35. data/lib/mongodoc/ext/symbol.rb +5 -0
  36. data/lib/mongodoc/ext/time.rb +5 -0
  37. data/lib/mongodoc/parent_proxy.rb +37 -0
  38. data/lib/mongodoc/proxy.rb +76 -0
  39. data/lib/mongodoc/query.rb +7 -0
  40. data/lib/mongodoc/value_equals.rb +8 -0
  41. data/mongod.example.yml +2 -0
  42. data/mongodoc.gemspec +117 -0
  43. data/script/console +8 -0
  44. data/spec/attributes_spec.rb +159 -0
  45. data/spec/base_ext.rb +9 -0
  46. data/spec/base_spec.rb +273 -0
  47. data/spec/bson_matchers.rb +54 -0
  48. data/spec/bson_spec.rb +316 -0
  49. data/spec/connection_spec.rb +81 -0
  50. data/spec/parent_proxy_spec.rb +42 -0
  51. data/spec/query_spec.rb +12 -0
  52. data/spec/spec.opts +2 -0
  53. data/spec/spec_helper.rb +13 -0
  54. data/spec/test_classes.rb +19 -0
  55. data/spec/test_documents.rb +35 -0
  56. metadata +159 -0
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "MongoDoc Connections" do
4
+
5
+ it ".connection raises a no connection error when connect has not been called" do
6
+ lambda {MongoDoc.connection}.should raise_error(MongoDoc::NoConnectionError)
7
+ end
8
+
9
+ describe ".connect" do
10
+ it "when called with no params just connects" do
11
+ Mongo::Connection.should_receive(:new)
12
+ MongoDoc.connect
13
+ end
14
+
15
+ describe "mimics the Mongo::Connection API" do
16
+ it "accepts the host param" do
17
+ host = 'localhost'
18
+ Mongo::Connection.should_receive(:new).with(host, nil, {})
19
+ MongoDoc.connect(host)
20
+ end
21
+
22
+ it "accepts the port param" do
23
+ host = 'localhost'
24
+ port = 3000
25
+ Mongo::Connection.should_receive(:new).with(host, 3000, {})
26
+ MongoDoc.connect(host, port)
27
+ end
28
+
29
+ it "accepts an options hash" do
30
+ opts = {:slave_ok => true}
31
+ Mongo::Connection.should_receive(:new).with(nil, nil, opts)
32
+ MongoDoc.connect(opts)
33
+ end
34
+
35
+ it "accepts host, port, and options" do
36
+ host = 'localhost'
37
+ port = 3000
38
+ opts = {:slave_ok => true}
39
+ Mongo::Connection.should_receive(:new).with(host, 3000, opts)
40
+ MongoDoc.connect(host, port, opts)
41
+ end
42
+ end
43
+
44
+ it "sets the connection" do
45
+ cnx = 'connection'
46
+ Mongo::Connection.should_receive(:new).and_return(cnx)
47
+ MongoDoc.connect
48
+ MongoDoc.connection.should == cnx
49
+ end
50
+ end
51
+
52
+ describe ".database" do
53
+ it "raises a no database error when the database has not been initialized" do
54
+ lambda {MongoDoc.database}.should raise_error(MongoDoc::NoDatabaseError)
55
+ end
56
+
57
+ it "returns the current database when not given any arguments" do
58
+ db = 'db'
59
+ MongoDoc.send(:class_variable_set, :@@database, db)
60
+ MongoDoc.database.should == db
61
+ end
62
+
63
+ it "connects to the database when no passed any additional arguments" do
64
+ name = 'name'
65
+ cnx = stub('connection')
66
+ cnx.should_receive(:db).with(name)
67
+ MongoDoc.should_receive(:connection).and_return(cnx)
68
+ MongoDoc.database(name)
69
+ end
70
+
71
+ it "sets the database when called with the name parameter" do
72
+ db = 'db'
73
+ name = 'name'
74
+ cnx = stub('connection')
75
+ cnx.should_receive(:db).with(name).and_return(db)
76
+ MongoDoc.should_receive(:connection).and_return(cnx)
77
+ MongoDoc.database(name)
78
+ MongoDoc.database.should == db
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "MongoDoc::Document::ParentProxy" do
4
+ class Parent
5
+ def path_to_root(attrs)
6
+ attrs
7
+ end
8
+ end
9
+
10
+ before do
11
+ @parent = Parent.new
12
+ @assoc_name = 'association'
13
+ end
14
+
15
+ subject do
16
+ MongoDoc::Document::ParentProxy.new(@parent, @assoc_name)
17
+ end
18
+
19
+ it "has the association name" do
20
+ should respond_to(:assoc_name)
21
+ end
22
+
23
+ it "has a parent" do
24
+ should respond_to(:_parent)
25
+ end
26
+
27
+ it "requires a parent" do
28
+ expect do
29
+ MongoDoc::Document::ParentProxy.new(nil, @assoc_name)
30
+ end.should raise_error
31
+ end
32
+
33
+ it "requires an association name" do
34
+ expect do
35
+ MongoDoc::Document::ParentProxy.new(@parent, nil)
36
+ end.should raise_error
37
+ end
38
+
39
+ it "inserts the association name the path_to_root" do
40
+ subject.path_to_root({:name1 => 'value1', :name2 => 'value2'}).should == {"#{@assoc_name}.name1" => 'value1', "#{@assoc_name}.name2" => "value2"}
41
+ end
42
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Query support for MongoDoc" do
4
+ describe "#set_modifier" do
5
+ it "modifies all simple key/values of the hash to a set modifier" do
6
+ key = 'key'
7
+ value = 'value'
8
+ hash = {key => value}
9
+ MongoDoc::Query.set_modifier(hash).should == {'$set' => hash}
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mongodoc'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'bson_matchers'
7
+ require 'test_classes'
8
+ require 'test_documents'
9
+ require 'base_ext'
10
+
11
+ Spec::Runner.configure do |config|
12
+ config.include(BsonMatchers)
13
+ end
@@ -0,0 +1,19 @@
1
+ require 'mongodoc/value_equals'
2
+
3
+ class Movie
4
+ include MongoDoc::ValueEquals
5
+
6
+ attr_accessor :title, :director, :writers
7
+ end
8
+
9
+ class Director
10
+ include MongoDoc::ValueEquals
11
+
12
+ attr_accessor :name, :awards
13
+ end
14
+
15
+ class AcademyAward
16
+ include MongoDoc::ValueEquals
17
+
18
+ attr_accessor :year, :category
19
+ end
@@ -0,0 +1,35 @@
1
+ class Address < MongoDoc::Base
2
+ key :street
3
+ key :city
4
+ key :state
5
+ key :zip_code
6
+ end
7
+
8
+ class Place < MongoDoc::Base
9
+ key :name
10
+ has_one :address
11
+ end
12
+
13
+ class Location < MongoDoc::Base
14
+ has_one :address
15
+ key :website
16
+ end
17
+
18
+ class WifiAccessible < Location
19
+ key :network_name
20
+ end
21
+
22
+ class WebSite
23
+ attr_accessor :url
24
+ end
25
+
26
+ module Automobile
27
+ class Ariel < MongoDoc::Base
28
+ key :name
29
+ end
30
+ end
31
+
32
+ class Contact < MongoDoc::Base
33
+ key :name
34
+ has_many :addresses
35
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongodoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Les Hill
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-22 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongo
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: "0.16"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: durran-validatable
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.2
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: cucumber
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ description: ODM for MongoDB
56
+ email: leshill@gmail.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ files:
65
+ - .document
66
+ - .gitignore
67
+ - LICENSE
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - data/.gitignore
72
+ - features/mongodoc_base.feature
73
+ - features/saving_an_object.feature
74
+ - features/step_definitions/collection_steps.rb
75
+ - features/step_definitions/connect_steps.rb
76
+ - features/step_definitions/document_steps.rb
77
+ - features/step_definitions/json_steps.rb
78
+ - features/step_definitions/object_steps.rb
79
+ - features/step_definitions/util_steps.rb
80
+ - features/support/support.rb
81
+ - lib/mongodoc.rb
82
+ - lib/mongodoc/attributes.rb
83
+ - lib/mongodoc/base.rb
84
+ - lib/mongodoc/bson.rb
85
+ - lib/mongodoc/connection.rb
86
+ - lib/mongodoc/ext/array.rb
87
+ - lib/mongodoc/ext/binary.rb
88
+ - lib/mongodoc/ext/boolean_class.rb
89
+ - lib/mongodoc/ext/date.rb
90
+ - lib/mongodoc/ext/date_time.rb
91
+ - lib/mongodoc/ext/dbref.rb
92
+ - lib/mongodoc/ext/hash.rb
93
+ - lib/mongodoc/ext/nil_class.rb
94
+ - lib/mongodoc/ext/numeric.rb
95
+ - lib/mongodoc/ext/object.rb
96
+ - lib/mongodoc/ext/object_id.rb
97
+ - lib/mongodoc/ext/regexp.rb
98
+ - lib/mongodoc/ext/string.rb
99
+ - lib/mongodoc/ext/symbol.rb
100
+ - lib/mongodoc/ext/time.rb
101
+ - lib/mongodoc/parent_proxy.rb
102
+ - lib/mongodoc/proxy.rb
103
+ - lib/mongodoc/query.rb
104
+ - lib/mongodoc/value_equals.rb
105
+ - mongod.example.yml
106
+ - mongodoc.gemspec
107
+ - script/console
108
+ - spec/attributes_spec.rb
109
+ - spec/base_ext.rb
110
+ - spec/base_spec.rb
111
+ - spec/bson_matchers.rb
112
+ - spec/bson_spec.rb
113
+ - spec/connection_spec.rb
114
+ - spec/parent_proxy_spec.rb
115
+ - spec/query_spec.rb
116
+ - spec/spec.opts
117
+ - spec/spec_helper.rb
118
+ - spec/test_classes.rb
119
+ - spec/test_documents.rb
120
+ has_rdoc: true
121
+ homepage: http://github.com/leshill/mongodoc
122
+ licenses: []
123
+
124
+ post_install_message:
125
+ rdoc_options:
126
+ - --charset=UTF-8
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: "0"
134
+ version:
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: "0"
140
+ version:
141
+ requirements: []
142
+
143
+ rubyforge_project:
144
+ rubygems_version: 1.3.5
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: ODM for MongoDB
148
+ test_files:
149
+ - spec/attributes_spec.rb
150
+ - spec/base_ext.rb
151
+ - spec/base_spec.rb
152
+ - spec/bson_matchers.rb
153
+ - spec/bson_spec.rb
154
+ - spec/connection_spec.rb
155
+ - spec/parent_proxy_spec.rb
156
+ - spec/query_spec.rb
157
+ - spec/spec_helper.rb
158
+ - spec/test_classes.rb
159
+ - spec/test_documents.rb