mordor 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mordor.rb +0 -9
- data/lib/mordor/resource.rb +5 -2
- data/mordor.gemspec +1 -1
- data/spec/mordor/connection_spec.rb +10 -0
- data/spec/mordor/resource_spec.rb +4 -8
- metadata +3 -3
data/lib/mordor.rb
CHANGED
@@ -81,12 +81,3 @@ class Time
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
85
|
-
module Mordor
|
86
|
-
def connection
|
87
|
-
@connection ||= Mongo::Connection.new(Mordor::Config[:hostname], Mordor::Config[:port])
|
88
|
-
@connection.autenticate(Mordor::Config[:username], Mordor::Config[:password]) if Mordor::Config[:username]
|
89
|
-
@connection.db(Mordor::Config[:database])
|
90
|
-
end
|
91
|
-
module_function :connection
|
92
|
-
end
|
data/lib/mordor/resource.rb
CHANGED
@@ -142,10 +142,13 @@ module Mordor
|
|
142
142
|
end
|
143
143
|
|
144
144
|
def connection
|
145
|
-
@connection
|
145
|
+
unless @connection
|
146
|
+
@connection = Mongo::Connection.new(Mordor::Config[:hostname], Mordor::Config[:port])
|
147
|
+
@connection.autenticate(Mordor::Config[:username], Mordor::Config[:password]) if Mordor::Config[:username]
|
148
|
+
end
|
149
|
+
@connection.db(Mordor::Config[:database])
|
146
150
|
end
|
147
151
|
|
148
|
-
|
149
152
|
def find_by_id(id)
|
150
153
|
get(id)
|
151
154
|
end
|
data/mordor.gemspec
CHANGED
@@ -13,4 +13,14 @@ describe "connecting to mongo" do
|
|
13
13
|
it "should select the correct database" do
|
14
14
|
@db.name.should == Mordor::Config[:database]
|
15
15
|
end
|
16
|
+
|
17
|
+
it "should be possible to change the configuration" do
|
18
|
+
old_db = Mordor::Config[:database]
|
19
|
+
Mordor::Config.use do |c|
|
20
|
+
c[:database] = 'some_other'
|
21
|
+
end
|
22
|
+
|
23
|
+
Mordor::Config[:database].should == 'some_other'
|
24
|
+
Mordor::Config[:database] = old_db
|
25
|
+
end
|
16
26
|
end
|
@@ -146,19 +146,15 @@ describe "with respect to resources" do
|
|
146
146
|
end
|
147
147
|
|
148
148
|
private
|
149
|
-
def self.do_ensure_indices
|
150
|
-
indices.each do |index|
|
151
|
-
do_ensure_index(index)
|
152
|
-
end
|
153
|
-
end
|
154
149
|
|
155
150
|
def self.do_ensure_index(attribute)
|
156
151
|
collection.ensure_index( [ [attribute.to_s, index_types[attribute]] ] )
|
157
152
|
end
|
158
153
|
|
159
154
|
def self.ensure_indices
|
160
|
-
|
161
|
-
|
155
|
+
indices.each do |index|
|
156
|
+
ensure_index(index)
|
157
|
+
end
|
162
158
|
end
|
163
159
|
|
164
160
|
def self.ensure_index(attribute)
|
@@ -173,7 +169,7 @@ describe "with respect to resources" do
|
|
173
169
|
TestResource.create({:first => 'first', :second => 'second', :third => 'third'})
|
174
170
|
TestResource.reset_ensure_count
|
175
171
|
TestResource.all()
|
176
|
-
TestResource.ensure_count.should ==
|
172
|
+
TestResource.ensure_count.should == 2 # For each index
|
177
173
|
end
|
178
174
|
|
179
175
|
it "should call ensure index for each index attribute on creation" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mordor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 8
|
10
|
+
version: 0.2.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan-Willem Koelewijn
|