mordor 0.2.5 → 0.2.6
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.
- data/lib/mordor/resource.rb +6 -2
- data/mordor.gemspec +2 -2
- data/spec/mordor/resource_spec.rb +60 -32
- metadata +4 -4
data/lib/mordor/resource.rb
CHANGED
@@ -82,7 +82,6 @@ module Mordor
|
|
82
82
|
else
|
83
83
|
insert_id = self.update
|
84
84
|
end
|
85
|
-
self.class.send(:ensure_indices)
|
86
85
|
saved?
|
87
86
|
end
|
88
87
|
|
@@ -185,6 +184,7 @@ module Mordor
|
|
185
184
|
if options[:index]
|
186
185
|
@indices << name unless @indices.include?(name)
|
187
186
|
@index_types[name] = options[:index_type] ? options[:index_type] : Mongo::DESCENDING
|
187
|
+
ensure_index(name)
|
188
188
|
end
|
189
189
|
|
190
190
|
if options[:timestamp]
|
@@ -224,10 +224,14 @@ module Mordor
|
|
224
224
|
|
225
225
|
def ensure_indices
|
226
226
|
indices.each do |index|
|
227
|
-
|
227
|
+
ensure_index(index)
|
228
228
|
end
|
229
229
|
end
|
230
230
|
|
231
|
+
def ensure_index(attribute)
|
232
|
+
collection.ensure_index( [ [attribute.to_s, index_types[attribute] ]] )
|
233
|
+
end
|
234
|
+
|
231
235
|
def indices
|
232
236
|
@indices ||= []
|
233
237
|
end
|
data/mordor.gemspec
CHANGED
@@ -2,8 +2,8 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = "mordor"
|
3
3
|
|
4
4
|
# Do not set the version and date field manually, this is done by the release script
|
5
|
-
s.version = "0.2.
|
6
|
-
s.date = "2012-01-
|
5
|
+
s.version = "0.2.6"
|
6
|
+
s.date = "2012-01-04"
|
7
7
|
|
8
8
|
s.summary = "mordor"
|
9
9
|
s.description = <<-eos
|
@@ -48,38 +48,6 @@ describe "with respect to resources" do
|
|
48
48
|
TestResource.send(:index_types)[:second].should == Mongo::ASCENDING
|
49
49
|
end
|
50
50
|
|
51
|
-
it "should call ensure_index on the collection for each index when a query is performed" do
|
52
|
-
TestResource.class_eval do
|
53
|
-
def self.reset_ensure_count
|
54
|
-
@count = 0
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.ensure_count
|
58
|
-
@count ||= 0
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.ensure_count=(val)
|
62
|
-
@count = val
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
def self.do_ensure_indices
|
67
|
-
indices.each do |index|
|
68
|
-
collection.ensure_index( [ [index.to_s, index_types[index]] ] )
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.ensure_indices
|
73
|
-
self.ensure_count = self.ensure_count + 1
|
74
|
-
self.do_ensure_indices
|
75
|
-
end
|
76
|
-
end
|
77
|
-
TestResource.create({:first => 'first', :second => 'second', :third => 'third'})
|
78
|
-
TestResource.reset_ensure_count
|
79
|
-
TestResource.all()
|
80
|
-
TestResource.ensure_count.should == 1
|
81
|
-
end
|
82
|
-
|
83
51
|
it "should be possible to designate an attribute as a timestamp" do
|
84
52
|
TestResource.timestamped_attribute.should_not be_nil
|
85
53
|
TestResource.timestamped_attribute.should == :at
|
@@ -157,6 +125,66 @@ describe "with respect to resources" do
|
|
157
125
|
|
158
126
|
end
|
159
127
|
|
128
|
+
context "with respect to indices" do
|
129
|
+
before :each do
|
130
|
+
class TestResource2
|
131
|
+
include Mordor::Resource
|
132
|
+
end
|
133
|
+
|
134
|
+
[TestResource, TestResource2].each do |klass|
|
135
|
+
klass.class_eval do
|
136
|
+
def self.reset_ensure_count
|
137
|
+
@count = 0
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.ensure_count
|
141
|
+
@count ||= 0
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.ensure_count=(val)
|
145
|
+
@count = val
|
146
|
+
end
|
147
|
+
|
148
|
+
private
|
149
|
+
def self.do_ensure_indices
|
150
|
+
indices.each do |index|
|
151
|
+
do_ensure_index(index)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.do_ensure_index(attribute)
|
156
|
+
collection.ensure_index( [ [attribute.to_s, index_types[attribute]] ] )
|
157
|
+
end
|
158
|
+
|
159
|
+
def self.ensure_indices
|
160
|
+
self.ensure_count = self.ensure_count + 1
|
161
|
+
self.do_ensure_indices
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.ensure_index(attribute)
|
165
|
+
self.ensure_count += 1
|
166
|
+
self.do_ensure_index(attribute)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should call ensure_index on the collection for each index when a query is performed" do
|
173
|
+
TestResource.create({:first => 'first', :second => 'second', :third => 'third'})
|
174
|
+
TestResource.reset_ensure_count
|
175
|
+
TestResource.all()
|
176
|
+
TestResource.ensure_count.should == 1
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should call ensure index for each index attribute on creation" do
|
180
|
+
TestResource2.class_eval do
|
181
|
+
attribute :test_attribute, :index => true
|
182
|
+
end
|
183
|
+
|
184
|
+
TestResource2.ensure_count.should == 1
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
160
188
|
context "with respect to creating" do
|
161
189
|
before :each do
|
162
190
|
clean_sheet
|
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: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan-Willem Koelewijn
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-01-
|
19
|
+
date: 2012-01-04 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|