mongodoc 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -23,7 +23,7 @@ Here is an example:
23
23
  has_many :addresses
24
24
  end
25
25
 
26
- MongoDoc.connect
26
+ MongoDoc.connect_to_database 'test'
27
27
  contact = Contact.new(:name => 'Joe Strummer', :interests => ['music', 'art', 'acting'])
28
28
  contact.addresses << Address.new(:street => '1 Main Street', :city => 'Anywhere', :state => 'ID', :zip_code => '56789')
29
29
  contact.save
@@ -33,6 +33,22 @@ Here is an example:
33
33
 
34
34
  == Installation
35
35
 
36
+ sudo gem install mongodoc
37
+
38
+ == Configuration
39
+
40
+ Configure your database connection in ./mongodb.yml, you do not need one if you are running on localhost with the default port
41
+
42
+ name: test
43
+ host: localhost
44
+ port: 27017
45
+ options:
46
+ auto_reconnect: true
47
+
48
+ You can change the location of the configuration file:
49
+
50
+ MongoDoc.config_path = './config/mongodb.yml'
51
+
36
52
  == Credits
37
53
 
38
54
  Les Hill, leshill on github
data/Rakefile CHANGED
@@ -10,11 +10,12 @@ begin
10
10
  gem.email = "leshill@gmail.com"
11
11
  gem.homepage = "http://github.com/leshill/mongodoc"
12
12
  gem.authors = ["Les Hill"]
13
- gem.add_dependency "mongo", "= 0.16"
14
- gem.add_dependency "durran-validatable", "= 1.8.2"
13
+ gem.add_dependency "mongo", "= 0.18.1"
14
+ gem.add_dependency "mongo_ext", "= 0.18.1"
15
+ gem.add_dependency "durran-validatable", "= 1.8.3"
15
16
  gem.add_dependency "leshill-will_paginate", "= 2.3.11"
16
- gem.add_development_dependency "rspec"
17
- gem.add_development_dependency "cucumber"
17
+ gem.add_development_dependency "rspec", "= 1.2.9"
18
+ gem.add_development_dependency "cucumber", "= 0.4.4"
18
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
20
  end
20
21
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -0,0 +1,6 @@
1
+ name: test
2
+ host: localhost
3
+ port: 27017
4
+ options:
5
+ auto_reconnect: true
6
+
@@ -1,8 +1,7 @@
1
1
  Feature: MongoDoc::Base
2
2
 
3
3
  Scenario: creating a simple document
4
- Given a valid connection to the 'test' database
5
- And an empty Address document collection
4
+ Given an empty Address document collection
6
5
  And a hash named 'hashrocket':
7
6
  | Street | City | State | Zip Code |
8
7
  | 320 First Street North | Jacksonville Beach | FL | 32250 |
@@ -12,8 +11,7 @@ Feature: MongoDoc::Base
12
11
  And the document 'address' roundtrips
13
12
 
14
13
  Scenario: saving a simple document
15
- Given a valid connection to the 'test' database
16
- And an empty Address document collection
14
+ Given an empty Address document collection
17
15
  And an Address document named 'hashrocket' :
18
16
  | Street | City | State | Zip Code |
19
17
  | 320 First Street North | Jacksonville Beach | FL | 32250 |
@@ -23,8 +21,7 @@ Feature: MongoDoc::Base
23
21
  And the document 'hashrocket' roundtrips
24
22
 
25
23
  Scenario: updating an attribute of a simple document
26
- Given a valid connection to the 'test' database
27
- And an empty Address document collection
24
+ Given an empty Address document collection
28
25
  And an Address document named 'hashrocket' :
29
26
  | Street | City | State | Zip Code |
30
27
  | 320 First Street North | Jacksonville Beach | FL | 32250 |
@@ -37,8 +34,7 @@ Feature: MongoDoc::Base
37
34
  Then the attribute 'street' of 'hashrocket' is '320 First St N'
38
35
 
39
36
  Scenario: failing to update an attribute of a simple document
40
- Given a valid connection to the 'test' database
41
- And an empty Address document collection
37
+ Given an empty Address document collection
42
38
  And an Address document named 'hashrocket' :
43
39
  | Street | City | State | Zip Code |
44
40
  | 320 First Street North | Jacksonville Beach | FL | 32250 |
@@ -51,8 +47,7 @@ Feature: MongoDoc::Base
51
47
  Then the last return value is false
52
48
 
53
49
  Scenario: saving a has_many document
54
- Given a valid connection to the 'test' database
55
- And an empty Contact document collection
50
+ Given an empty Contact document collection
56
51
  And a Contact document named 'hashrocket' :
57
52
  | Name |
58
53
  | Hashrocket |
@@ -66,8 +61,7 @@ Feature: MongoDoc::Base
66
61
  And the document 'hashrocket' roundtrips
67
62
 
68
63
  Scenario: saving from a child document
69
- Given a valid connection to the 'test' database
70
- And an empty Contact document collection
64
+ Given an empty Contact document collection
71
65
  And a Contact document named 'hashrocket' :
72
66
  | Name |
73
67
  | Hashrocket |
@@ -81,8 +75,7 @@ Feature: MongoDoc::Base
81
75
  And the document 'hashrocket' roundtrips
82
76
 
83
77
  Scenario: failing to update attributes from a has_many child document
84
- Given a valid connection to the 'test' database
85
- And an empty Contact document collection
78
+ Given an empty Contact document collection
86
79
  And a Contact document named 'hashrocket' :
87
80
  | Name |
88
81
  | Hashrocket |
@@ -99,8 +92,7 @@ Feature: MongoDoc::Base
99
92
  Then the last return value is false
100
93
 
101
94
  Scenario: update attributes from a has_one child document
102
- Given a valid connection to the 'test' database
103
- And an empty Place document collection
95
+ Given an empty Place document collection
104
96
  And a Place document named 'hashrocket' :
105
97
  | Name |
106
98
  | Hashrocket |
@@ -114,4 +106,4 @@ Feature: MongoDoc::Base
114
106
  | 320 1st St. N. | Jax Bch |
115
107
  When I update the document 'address' with the hash named 'street'
116
108
  Then the Place collection should have 1 document
117
- And the document 'hashrocket' roundtrips
109
+ And the document 'hashrocket' roundtrips
@@ -1,17 +1,15 @@
1
1
  Feature: saving an object
2
2
 
3
3
  Scenario: saving simple json
4
- Given a valid connection to the 'test' database
5
- And a new collection named 'test'
4
+ Given a new collection named 'test'
6
5
  When I save the json '{"name":"name"}'
7
6
  Then the collection should have 1 document
8
7
  And the json '{"name":"name"}' roundtrips
9
-
8
+
10
9
  Scenario: saving a ruby object
11
- Given a valid connection to the 'test' database
12
- And a new collection named 'test'
10
+ Given a new collection named 'test'
13
11
  And an object 'movie'
14
12
  When I save the object 'movie'
15
13
  Then the collection should have 1 document
16
14
  And the object 'movie' roundtrips
17
-
15
+
@@ -1,11 +1,11 @@
1
1
  Given /a new collection named '(.*)'/ do |name|
2
- @db.drop_collection(name)
2
+ MongoDoc.database.drop_collection(name)
3
3
  @collection = MongoDoc::Collection.new(name)
4
4
  end
5
5
 
6
6
  Given /^an empty (\w+) collection$/ do |name|
7
- @db.drop_collection(name)
8
- @db.create_collection(name, :strict => true)
7
+ MongoDoc.database.drop_collection(name)
8
+ MongoDoc.database.create_collection(name, :strict => true)
9
9
  end
10
10
 
11
11
  Then /the collection should have (\d+) documents?/ do |count|
@@ -4,4 +4,7 @@ require 'spec/expectations'
4
4
  require 'spec/bson_matchers'
5
5
  require 'mongodoc'
6
6
 
7
- World(BsonMatchers)
7
+ MongoDoc.config_path = './features/mongodb.yml'
8
+ MongoDoc.connect_to_database
9
+
10
+ World(BsonMatchers)
@@ -1,8 +1,7 @@
1
1
  Feature: MongoDoc::Base
2
2
 
3
3
  Background:
4
- Given a valid connection to the 'test' database
5
- And an empty Contact document collection
4
+ Given an empty Contact document collection
6
5
  And a Contact document named 'hashrocket' :
7
6
  | Name | Type |
8
7
  | Hashrocket | company |
@@ -1,20 +1,25 @@
1
1
  module MongoDoc
2
- def self.database(name = nil)
3
- if name
4
- @@database = connection.db(name)
5
- else
6
- raise NoDatabaseError unless defined? @@database and @@database
7
- @@database
8
- end
2
+ mattr_accessor :config, :config_path, :connection, :database
3
+ self.config_path = './mongodb.yml'
4
+
5
+ def self.connect_to_database(name = nil, host = nil, port = nil, options = nil, force_connect = false)
6
+ name ||= configuration['name']
7
+ self.database = ((!force_connect && connection)|| connect(host, port, options)).db(name)
8
+ raise NoDatabaseError unless database
9
+ database
9
10
  end
10
-
11
- def self.connection
12
- raise NoConnectionError unless defined? @@connection and @@connection
13
- @@connection
14
- end
15
-
11
+
16
12
  def self.connect(*args)
17
13
  opts = args.extract_options!
18
- @@connection = Mongo::Connection.new(args[0], args[1], opts)
14
+ host = args[0] || configuration['host'] || configuration['host_pairs']
15
+ port = args[1] || configuration['port']
16
+ options = opts.empty? ? configuration['options'] || {} : opts
17
+ self.connection = Mongo::Connection.new(host, port, options)
18
+ raise NoConnectionError unless connection
19
+ connection
20
+ end
21
+
22
+ def self.configuration
23
+ self.config ||= File.exists?(config_path || '') ? YAML.load_file(config_path) : {}
19
24
  end
20
- end
25
+ end
@@ -457,7 +457,7 @@ module MongoDoc #:nodoc:
457
457
  #
458
458
  # Returns either a cursor or an empty array.
459
459
  def execute
460
- cursor = @klass.collection.find(selector, options.dup)
460
+ cursor = klass.collection.find(selector, options.dup)
461
461
  if cursor
462
462
  @count = cursor.count
463
463
  cursor
data/lib/mongodoc.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'rubygems'
2
2
 
3
- gem 'mongo', '0.16'
4
- gem 'durran-validatable', '1.8.2'
5
- gem "leshill-will_paginate", "2.3.11"
3
+ gem 'mongo', '0.18.1'
4
+ gem 'mongo_ext', '0.18.1'
5
+ gem 'durran-validatable', '1.8.3'
6
+ gem 'leshill-will_paginate', '2.3.11'
6
7
 
7
8
  require 'mongo'
8
9
  require 'activesupport'
@@ -10,8 +11,8 @@ require 'validatable'
10
11
  require 'will_paginate/collection'
11
12
 
12
13
  module MongoDoc
13
- VERSION = '0.1'
14
-
14
+ VERSION = '0.1.2'
15
+
15
16
  class NoConnectionError < RuntimeError; end
16
17
  class NoDatabaseError < RuntimeError; end
17
18
  end
@@ -0,0 +1,6 @@
1
+ name: test
2
+ host: localhost
3
+ port: 27017
4
+ options:
5
+ auto_reconnect: true
6
+
data/mongodoc.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongodoc}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.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{2009-12-07}
12
+ s.date = %q{2009-12-10}
13
13
  s.description = %q{ODM for MongoDB}
14
14
  s.email = %q{leshill@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -24,10 +24,10 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "data/.gitignore",
27
+ "features/mongodb.yml",
27
28
  "features/mongodoc_base.feature",
28
29
  "features/saving_an_object.feature",
29
30
  "features/step_definitions/collection_steps.rb",
30
- "features/step_definitions/connect_steps.rb",
31
31
  "features/step_definitions/criteria_steps.rb",
32
32
  "features/step_definitions/document_steps.rb",
33
33
  "features/step_definitions/documents.rb",
@@ -64,6 +64,7 @@ Gem::Specification.new do |s|
64
64
  "lib/mongodoc/proxy.rb",
65
65
  "lib/mongodoc/query.rb",
66
66
  "mongod.example.yml",
67
+ "mongodb.example.yml",
67
68
  "mongodoc.gemspec",
68
69
  "script/console",
69
70
  "spec/attributes_spec.rb",
@@ -75,6 +76,8 @@ Gem::Specification.new do |s|
75
76
  "spec/cursor_spec.rb",
76
77
  "spec/document_ext.rb",
77
78
  "spec/document_spec.rb",
79
+ "spec/mongodb.yml",
80
+ "spec/mongodb_pairs.yml",
78
81
  "spec/parent_proxy_spec.rb",
79
82
  "spec/query_spec.rb",
80
83
  "spec/spec.opts",
@@ -105,24 +108,27 @@ Gem::Specification.new do |s|
105
108
  s.specification_version = 3
106
109
 
107
110
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
108
- s.add_runtime_dependency(%q<mongo>, ["= 0.16"])
109
- s.add_runtime_dependency(%q<durran-validatable>, ["= 1.8.2"])
111
+ s.add_runtime_dependency(%q<mongo>, ["= 0.18.1"])
112
+ s.add_runtime_dependency(%q<mongo_ext>, ["= 0.18.1"])
113
+ s.add_runtime_dependency(%q<durran-validatable>, ["= 1.8.3"])
110
114
  s.add_runtime_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
111
- s.add_development_dependency(%q<rspec>, [">= 0"])
112
- s.add_development_dependency(%q<cucumber>, [">= 0"])
115
+ s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
116
+ s.add_development_dependency(%q<cucumber>, ["= 0.4.4"])
113
117
  else
114
- s.add_dependency(%q<mongo>, ["= 0.16"])
115
- s.add_dependency(%q<durran-validatable>, ["= 1.8.2"])
118
+ s.add_dependency(%q<mongo>, ["= 0.18.1"])
119
+ s.add_dependency(%q<mongo_ext>, ["= 0.18.1"])
120
+ s.add_dependency(%q<durran-validatable>, ["= 1.8.3"])
116
121
  s.add_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
117
- s.add_dependency(%q<rspec>, [">= 0"])
118
- s.add_dependency(%q<cucumber>, [">= 0"])
122
+ s.add_dependency(%q<rspec>, ["= 1.2.9"])
123
+ s.add_dependency(%q<cucumber>, ["= 0.4.4"])
119
124
  end
120
125
  else
121
- s.add_dependency(%q<mongo>, ["= 0.16"])
122
- s.add_dependency(%q<durran-validatable>, ["= 1.8.2"])
126
+ s.add_dependency(%q<mongo>, ["= 0.18.1"])
127
+ s.add_dependency(%q<mongo_ext>, ["= 0.18.1"])
128
+ s.add_dependency(%q<durran-validatable>, ["= 1.8.3"])
123
129
  s.add_dependency(%q<leshill-will_paginate>, ["= 2.3.11"])
124
- s.add_dependency(%q<rspec>, [">= 0"])
125
- s.add_dependency(%q<cucumber>, [">= 0"])
130
+ s.add_dependency(%q<rspec>, ["= 1.2.9"])
131
+ s.add_dependency(%q<cucumber>, ["= 0.4.4"])
126
132
  end
127
133
  end
128
134
 
@@ -2,90 +2,198 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "MongoDoc Connections" do
4
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
- it ".connection raises a no connection error when the connection has failed" do
10
- MongoDoc.send(:class_variable_set, :@@connection, nil)
11
- lambda {MongoDoc.connection}.should raise_error(MongoDoc::NoConnectionError)
5
+ it "default the configuration location to './mongodb.yml'" do
6
+ MongoDoc.config_path.should == './mongodb.yml'
12
7
  end
13
8
 
14
9
  describe ".connect" do
10
+ before do
11
+ MongoDoc.config_path = nil
12
+ MongoDoc.connection = nil
13
+ MongoDoc.config = nil
14
+ @connection = stub('connection')
15
+ end
16
+
15
17
  it "when called with no params just connects" do
16
- Mongo::Connection.should_receive(:new)
18
+ Mongo::Connection.should_receive(:new).and_return(@connection)
19
+ MongoDoc.connect
20
+ end
21
+
22
+ it "sets the connection" do
23
+ Mongo::Connection.stub(:new).and_return(@connection)
17
24
  MongoDoc.connect
25
+ MongoDoc.connection.should == @connection
26
+ end
27
+
28
+ it "raises NoConnectionError if the connection fails" do
29
+ Mongo::Connection.stub(:new).and_return(nil)
30
+ lambda { MongoDoc.connect }.should raise_error(MongoDoc::NoConnectionError)
18
31
  end
19
-
20
- describe "mimics the Mongo::Connection API" do
32
+
33
+ context "mimics the Mongo::Connection API" do
21
34
  it "accepts the host param" do
22
35
  host = 'localhost'
23
- Mongo::Connection.should_receive(:new).with(host, nil, {})
36
+ Mongo::Connection.should_receive(:new).with(host, nil, {}).and_return(@connection)
24
37
  MongoDoc.connect(host)
25
38
  end
26
39
 
27
40
  it "accepts the port param" do
28
41
  host = 'localhost'
29
42
  port = 3000
30
- Mongo::Connection.should_receive(:new).with(host, 3000, {})
43
+ Mongo::Connection.should_receive(:new).with(host, 3000, {}).and_return(@connection)
31
44
  MongoDoc.connect(host, port)
32
45
  end
33
-
46
+
34
47
  it "accepts an options hash" do
35
48
  opts = {:slave_ok => true}
36
- Mongo::Connection.should_receive(:new).with(nil, nil, opts)
49
+ Mongo::Connection.should_receive(:new).with(nil, nil, opts).and_return(@connection)
37
50
  MongoDoc.connect(opts)
38
51
  end
39
-
52
+
40
53
  it "accepts host, port, and options" do
41
54
  host = 'localhost'
42
55
  port = 3000
43
56
  opts = {:slave_ok => true}
44
- Mongo::Connection.should_receive(:new).with(host, 3000, opts)
57
+ Mongo::Connection.should_receive(:new).with(host, 3000, opts).and_return(@connection)
45
58
  MongoDoc.connect(host, port, opts)
46
59
  end
47
60
  end
48
-
49
- it "sets the connection" do
50
- cnx = 'connection'
51
- Mongo::Connection.should_receive(:new).and_return(cnx)
52
- MongoDoc.connect
53
- MongoDoc.connection.should == cnx
61
+
62
+ context "when there is a config file" do
63
+ before do
64
+ MongoDoc.config_path = './spec/mongodb.yml'
65
+ config = YAML.load_file(MongoDoc.config_path)
66
+ @host = config['host']
67
+ @port = config['port']
68
+ @db_options = config['options']
69
+ end
70
+
71
+ context "with a host config file" do
72
+
73
+ it "and no params connects to the database with the values from the file" do
74
+ Mongo::Connection.should_receive(:new).with(@host, @port, @db_options).and_return(@connection)
75
+ MongoDoc.connect
76
+ end
77
+
78
+ it "and params connects to the database with the params" do
79
+ host = 'p_host'
80
+ port = 890
81
+ options = {:option => 'p_opt'}
82
+ Mongo::Connection.should_receive(:new).with(host, port, options).and_return(@connection)
83
+ MongoDoc.connect(host, port, options)
84
+ end
85
+ end
86
+
87
+ context "with a host pairs config file" do
88
+ before do
89
+ MongoDoc.config_path = './spec/mongodb_pairs.yml'
90
+ config = YAML.load_file(MongoDoc.config_path)
91
+ @host_pairs = config['host_pairs']
92
+ @port = config['port']
93
+ @db_options = config['options']
94
+ end
95
+
96
+ it "connects to the database with the host pairs value from the file" do
97
+ Mongo::Connection.should_receive(:new).with(@host_pairs, @port, @db_options).and_return(@connection)
98
+ MongoDoc.connect
99
+ end
100
+ end
54
101
  end
55
102
  end
56
-
57
- describe ".database" do
58
- it "raises a no database error when the database has not been initialized" do
59
- lambda {MongoDoc.database}.should raise_error(MongoDoc::NoDatabaseError)
103
+
104
+ describe ".connect_to_database" do
105
+ before do
106
+ MongoDoc.database = nil
107
+ MongoDoc.connection = nil
108
+ MongoDoc.config = nil
60
109
  end
61
110
 
62
111
  it "raises a no database error when the database connect failed" do
63
- MongoDoc.send(:class_variable_set, :@@database, nil)
64
- lambda {MongoDoc.database}.should raise_error(MongoDoc::NoDatabaseError)
112
+ connection = stub("connection", :db => nil)
113
+ MongoDoc.stub(:connect).and_return(connection)
114
+ lambda {MongoDoc.connect_to_database}.should raise_error(MongoDoc::NoDatabaseError)
65
115
  end
66
116
 
67
- it "returns the current database when not given any arguments" do
117
+ it "returns the database" do
68
118
  db = 'db'
69
- MongoDoc.send(:class_variable_set, :@@database, db)
70
- MongoDoc.database.should == db
119
+ connection = stub("connection", :db => db)
120
+ MongoDoc.stub(:connect).and_return(connection)
121
+ MongoDoc.connect_to_database.should == db
71
122
  end
72
-
73
- it "connects to the database when no passed any additional arguments" do
74
- name = 'name'
75
- cnx = stub('connection')
76
- cnx.should_receive(:db).with(name)
77
- MongoDoc.should_receive(:connection).and_return(cnx)
78
- MongoDoc.database(name)
123
+
124
+ context "when a connection exists" do
125
+ before do
126
+ @db = 'db'
127
+ @connection = stub("connection", :db => @db)
128
+ end
129
+
130
+ it "uses the exsiting connection if already connected" do
131
+ MongoDoc.should_receive(:connection).and_return(@connection)
132
+ MongoDoc.should_not_receive(:connect)
133
+ MongoDoc.connect_to_database.should == @db
134
+ end
135
+
136
+ it "connects if force connect is true" do
137
+ MongoDoc.should_not_receive(:connection)
138
+ MongoDoc.should_receive(:connect).and_return(@connection)
139
+ MongoDoc.connect_to_database(nil, nil, nil, nil, true).should == @db
140
+ end
79
141
  end
80
-
81
- it "sets the database when called with the name parameter" do
82
- db = 'db'
83
- name = 'name'
84
- cnx = stub('connection')
85
- cnx.should_receive(:db).with(name).and_return(db)
86
- MongoDoc.should_receive(:connection).and_return(cnx)
87
- MongoDoc.database(name)
88
- MongoDoc.database.should == db
142
+
143
+ context "when there is no config file" do
144
+ before do
145
+ MongoDoc.config_path = nil
146
+ @db = 'db'
147
+ @name = 'name'
148
+ @connection = stub('connection')
149
+ end
150
+
151
+ it "connects with defaults when not given parameters" do
152
+ @connection.should_receive(:db).with(@name).and_return(@db)
153
+ MongoDoc.should_receive(:connect).and_return(@connection)
154
+ MongoDoc.connect_to_database(@name)
155
+ end
156
+
157
+ it "connects with the given parameters" do
158
+ host = 'host'
159
+ port = 123
160
+ options = { :auto_reconnect => true }
161
+ @connection.should_receive(:db).with(@name).and_return(@db)
162
+ MongoDoc.should_receive(:connect).with(host, port, options).and_return(@connection)
163
+ MongoDoc.connect_to_database(@name, host, port, options)
164
+ end
165
+ end
166
+
167
+ context "when there is a config file" do
168
+ before do
169
+ @db = 'db'
170
+ MongoDoc.config_path = './spec/mongodb.yml'
171
+ config = YAML.load_file(MongoDoc.config_path)
172
+ @database = config['name']
173
+ @host = config['host']
174
+ @port = config['port']
175
+ @db_options = config['options']
176
+ @connection = stub('connection')
177
+ end
178
+
179
+ context "with a host config file" do
180
+
181
+ it "without a name uses configured name" do
182
+ @connection.should_receive(:db).with(@database).and_return(@db)
183
+ MongoDoc.stub(:connect).and_return(@connection)
184
+ MongoDoc.connect_to_database
185
+ end
186
+
187
+ it "and params connects to the database with the params" do
188
+ database = 'p_database'
189
+ host = 'p_host'
190
+ port = 890
191
+ options = {:option => 'p_opt'}
192
+ @connection.should_receive(:db).with(database).and_return(@db)
193
+ MongoDoc.should_receive(:connect).with(host, port, options).and_return(@connection)
194
+ MongoDoc.connect_to_database(database, host, port, options)
195
+ end
196
+ end
89
197
  end
90
198
  end
91
- end
199
+ end
data/spec/mongodb.yml ADDED
@@ -0,0 +1,6 @@
1
+ name: database_name
2
+ host: localhost
3
+ port: 27017
4
+ options:
5
+ auto_reconnect: true
6
+
@@ -0,0 +1,8 @@
1
+ name: database_name
2
+ host_pairs:
3
+ first:
4
+ ['localhost', 27017]
5
+ port: 27017
6
+ options:
7
+ auto_reconnect: true
8
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Hill
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-07 00:00:00 -05:00
12
+ date: 2009-12-10 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,17 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: "0.16"
23
+ version: 0.18.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: mongo_ext
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.18.1
24
34
  version:
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: durran-validatable
@@ -30,7 +40,7 @@ dependencies:
30
40
  requirements:
31
41
  - - "="
32
42
  - !ruby/object:Gem::Version
33
- version: 1.8.2
43
+ version: 1.8.3
34
44
  version:
35
45
  - !ruby/object:Gem::Dependency
36
46
  name: leshill-will_paginate
@@ -48,9 +58,9 @@ dependencies:
48
58
  version_requirement:
49
59
  version_requirements: !ruby/object:Gem::Requirement
50
60
  requirements:
51
- - - ">="
61
+ - - "="
52
62
  - !ruby/object:Gem::Version
53
- version: "0"
63
+ version: 1.2.9
54
64
  version:
55
65
  - !ruby/object:Gem::Dependency
56
66
  name: cucumber
@@ -58,9 +68,9 @@ dependencies:
58
68
  version_requirement:
59
69
  version_requirements: !ruby/object:Gem::Requirement
60
70
  requirements:
61
- - - ">="
71
+ - - "="
62
72
  - !ruby/object:Gem::Version
63
- version: "0"
73
+ version: 0.4.4
64
74
  version:
65
75
  description: ODM for MongoDB
66
76
  email: leshill@gmail.com
@@ -79,10 +89,10 @@ files:
79
89
  - Rakefile
80
90
  - VERSION
81
91
  - data/.gitignore
92
+ - features/mongodb.yml
82
93
  - features/mongodoc_base.feature
83
94
  - features/saving_an_object.feature
84
95
  - features/step_definitions/collection_steps.rb
85
- - features/step_definitions/connect_steps.rb
86
96
  - features/step_definitions/criteria_steps.rb
87
97
  - features/step_definitions/document_steps.rb
88
98
  - features/step_definitions/documents.rb
@@ -119,6 +129,7 @@ files:
119
129
  - lib/mongodoc/proxy.rb
120
130
  - lib/mongodoc/query.rb
121
131
  - mongod.example.yml
132
+ - mongodb.example.yml
122
133
  - mongodoc.gemspec
123
134
  - script/console
124
135
  - spec/attributes_spec.rb
@@ -130,6 +141,8 @@ files:
130
141
  - spec/cursor_spec.rb
131
142
  - spec/document_ext.rb
132
143
  - spec/document_spec.rb
144
+ - spec/mongodb.yml
145
+ - spec/mongodb_pairs.yml
133
146
  - spec/parent_proxy_spec.rb
134
147
  - spec/query_spec.rb
135
148
  - spec/spec.opts
@@ -1,4 +0,0 @@
1
- Given /a valid connection to the '(.*)' database/ do |db|
2
- MongoDoc.connect
3
- @db = MongoDoc.database(db)
4
- end