mordor 0.2.0 → 0.2.1
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 +8 -2
- data/mordor.gemspec +2 -2
- data/spec/mordor/resource_spec.rb +38 -0
- metadata +4 -4
data/lib/mordor/resource.rb
CHANGED
@@ -162,12 +162,18 @@ module Mordor
|
|
162
162
|
|
163
163
|
method_name = options.key?(:finder_method) ? options[:finder_method] : "find_by_#{name}"
|
164
164
|
|
165
|
-
|
166
165
|
class_eval <<-EOS, __FILE__, __LINE__
|
167
166
|
attr_accessor name
|
168
167
|
|
169
168
|
def self.#{method_name}(value, options = {})
|
170
|
-
|
169
|
+
if value.is_a?(Hash)
|
170
|
+
raise ArgumentError.new(":value missing from complex query hash") unless value.keys.include?(:value)
|
171
|
+
query = {:#{name} => value.delete(:value)}
|
172
|
+
query = query.merge(value)
|
173
|
+
else
|
174
|
+
query = {:#{name} => value}
|
175
|
+
end
|
176
|
+
col = perform_collection_find(query, options)
|
171
177
|
Collection.new(self, col)
|
172
178
|
end
|
173
179
|
EOS
|
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 = "2011-12-
|
5
|
+
s.version = "0.2.1"
|
6
|
+
s.date = "2011-12-27"
|
7
7
|
|
8
8
|
s.summary = "mordor"
|
9
9
|
s.description = <<-eos
|
@@ -242,6 +242,44 @@ describe "with respect to resources" do
|
|
242
242
|
collection.should_not be_nil
|
243
243
|
collection.size.should == 1
|
244
244
|
end
|
245
|
+
|
246
|
+
describe "with respect to passing extra query parameters to finder methods" do
|
247
|
+
before :each do
|
248
|
+
5.times do |i|
|
249
|
+
TestResource.create({:first => "first", :second => "second-#{i}", :third => "third-#{i}"})
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
it "should raise an argument exception if the :value option is omitted from a complex finder query" do
|
254
|
+
collection = TestResource.find_by_first("first")
|
255
|
+
collection.size.should == 5
|
256
|
+
|
257
|
+
lambda{ TestResource.find_by_first({:second => "second-2"})}.should raise_error
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should be possible to add extra query clauses to a finder method" do
|
261
|
+
collection = TestResource.find_by_first("first")
|
262
|
+
collection.size.should == 5
|
263
|
+
|
264
|
+
collection = TestResource.find_by_first({:value => "first", :second => "second-2"})
|
265
|
+
collection.size.should == 1
|
266
|
+
resource = collection.first
|
267
|
+
resource.first.should == "first"
|
268
|
+
resource.second.should == "second-2"
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should be possible to add more complex query clauses to a finder method" do
|
272
|
+
collection = TestResource.find_by_first("first")
|
273
|
+
collection.size.should == 5
|
274
|
+
|
275
|
+
collection = TestResource.find_by_first({:value => "first", :second => {:$in => ["second-1", "second-2"]}})
|
276
|
+
collection.size.should == 2
|
277
|
+
collection.each do |res|
|
278
|
+
res.first.should == "first"
|
279
|
+
["second-1", "second-2"].should include res.second
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
245
283
|
end
|
246
284
|
|
247
285
|
context "with respect to retrieving by day" 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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
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: 2011-12-
|
19
|
+
date: 2011-12-27 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|