mordor-auditing 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mordor-auditing (0.0.11)
4
+ mordor-auditing (0.0.12)
5
5
  mordor (= 0.2.9)
6
6
 
7
7
  GEM
data/auditing.gemspec CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
2
2
  s.name = "mordor-auditing"
3
3
 
4
4
  # Do not set the version and date field manually, this is done by the release script
5
- s.version = "0.0.12"
5
+ s.version = "0.0.13"
6
6
  s.date = "2012-01-04"
7
7
 
8
8
  s.summary = "mordor-auditing"
@@ -36,20 +36,30 @@ module Auditing
36
36
  end
37
37
  end
38
38
 
39
- def self.find_by_url_parts(params = {})
40
- parts_params = {}
41
- params.each do |key, value|
42
- parts_params["url_parts.#{key}"] = value
39
+ def self.find_by_url_parts(params = {}, options = {})
40
+ query = {}
41
+ if parts_value = params.delete(:value)
42
+ query = params_to_query_params(parts_value).merge(params)
43
+ else
44
+ query = params_to_query_params(params)
43
45
  end
44
- Mordor::Collection.new(self, self.collection.find(parts_params))
46
+ col = perform_collection_find(query, options)
47
+ Mordor::Collection.new(self, col)
45
48
  end
46
49
 
47
50
  private
48
-
49
51
  def self.collection_name
50
52
  'audit_requests'
51
53
  end
52
54
 
55
+ def self.params_to_query_params(hash)
56
+ result = {}
57
+ hash.each do |key, value|
58
+ result["url_parts.#{key}"] = value
59
+ end
60
+ result
61
+ end
62
+
53
63
  def url_to_parts(url)
54
64
  result = {}
55
65
  if url
@@ -282,7 +282,7 @@ describe "with respect to auditing requests" do
282
282
  request.url_parts.keys.should_not include "week"
283
283
  end
284
284
 
285
- it "should corretly retrieve requests based on parts of the url" do
285
+ it "should correctly retrieve requests based on parts of the url" do
286
286
  options = {
287
287
  :url => '/week/2011-9/staffing_agencies/1234/customers/12/arrangements/123',
288
288
  :method => 'get',
@@ -331,7 +331,39 @@ describe "with respect to auditing requests" do
331
331
 
332
332
  match = (results.first._id == request._id || results.first._id == request2._id)
333
333
  match.should be_true
334
+ end
335
+
336
+ it "should be possible to add extra query parts to the url_parts query" do
337
+ options = {
338
+ :url => '/week/2011-9/staffing_agencies/1234/customers/12/arrangements/123',
339
+ :method => 'get',
340
+ :params => {:test_param1 => '1', :test_param2 => '2'},
341
+ :user_id => 4,
342
+ :real_user_id => 5,
343
+ :at => Time.now
344
+ }
345
+ request = Auditing::Request.new(options)
346
+ request.save.should be_true
347
+
348
+ options2 = {
349
+ :url => '/week/2011-9/staffing_agencies/13/customers/124/arrangements/123',
350
+ :method => 'get',
351
+ :params => {:test_param1 => '1', :test_param2 => '2'},
352
+ :user_id => 3,
353
+ :real_user_id => 5,
354
+ :at => Time.now
355
+ }
356
+ request2 = Auditing::Request.new(options2)
357
+ request2.save.should be_true
334
358
 
359
+ search_options = {
360
+ :week => "2011-9"
361
+ }
362
+ results = Auditing::Request.find_by_url_parts(search_options)
363
+ results.size.should == 2
364
+
365
+ results = Auditing::Request.find_by_url_parts({:value => search_options, :user_id => 4})
366
+ results.size.should == 1
335
367
  end
336
368
  end
337
369
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mordor-auditing
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 12
10
- version: 0.0.12
9
+ - 13
10
+ version: 0.0.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan-Willem Koelewijn