directiverecord 0.1.15 → 0.1.16

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTRiYmVkOTVmOWQwNjg0NGNlYjllYjdkZWFmNDI2ZjU0N2FkYjE4ZA==
4
+ YmEyYjEwZjExYzg4OTE0ZjE2MTc5NjhmNTU4NzgyOGFhZGY5MzVhZA==
5
5
  data.tar.gz: !binary |-
6
- NmU5MWY1NzM2OTI1ZTM4ZWIwNjEzZjJhNTg0YzJmMjc1ODJhMDAwNQ==
6
+ ZjQxZDk5OGUyMWU2MjkyZTcyNTA5Yzc3OTFhOTY5OWU0ZDU3YjQyYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZjdlZWY4NDg0NTRmMTRiYjViNWY5M2E4NTZkMWNkYjFiNmJkYTY2ZTU2YWNj
10
- YjZlZDkzY2NhYzE4NTM5NDU1MjY3ZmNkZjBkNGE2NGIyN2M4YjJhM2M0Mjdk
11
- YzYwZjRhZDc0NDQyMWZjNDdkOTBhYzY5MGM1YWFmMGM5YzAzOTA=
9
+ MTgzNDFjMGJmNTY5ZTcxN2Q5ZjRmNDhlMTIwZDA2Y2RjMTI0YTRjN2YzMmI0
10
+ Yjk0NjM5Zjc2ZmNhMmEwNzY2YjkxOThlZjA1YzBmYzQ4YmI4NDI4NTg3YjBh
11
+ MmZhZDliY2Y3YzBjMDM2NTNjMjZlMTVkZWRkYzllNjU2MGQ1ZTM=
12
12
  data.tar.gz: !binary |-
13
- YTI5NjE0NGJiMGVlNzVmZGM5OThkODQwMGNlOTE1NGJhNWQxZTNlMDU1NzQ1
14
- YmUzMzQxMjBmN2NiZDczZTE3ZjQ3ZjA5ZDQ1OGM1MzU0MDc4ZWUwNmEwN2U5
15
- MzMxMjJhZDQ0MjEwNjFkYjEwMzczYWRhYzZhNjY0ZDNkZWY4ZmQ=
13
+ MWMwODE0ZjUxZTJiOGExMjhkODBjM2JlZjhkZjg0YWNkNmUzNTM2Mjc0YTYy
14
+ MDUxZWM1MmYzYWE1MDA5ZjA4NjYxMGUyNDhiNDZkYjA5YWEzNzcwMTBkZGJl
15
+ NGQxOTZhOWVkZmVhOGY5Y2E1NmVjOWMzODRlMTZjNzU4YTI1M2Q=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = DirectiveRecord CHANGELOG
2
2
 
3
+ == Version 0.1.16 (March 12, 2015)
4
+
5
+ * Made ActiveRecord::Relation#count(:all) override more strict: only overrule behavior when having detected a possible path in the query options
6
+
3
7
  == Version 0.1.15 (March 10, 2015)
4
8
 
5
9
  * Being able to include / exclude subselect options
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.15
1
+ 0.1.16
@@ -17,10 +17,23 @@ module ActiveRecord
17
17
 
18
18
  def count(column_name = nil, options = {})
19
19
  if !loaded? && (column_name == :all) && (options == {})
20
- qry("COUNT(DISTINCT id)")[0][0]
21
- else
22
- original_count column_name, options
20
+ associations = klass.reflections.keys.collect(&:to_s)
21
+
22
+ contains_possible_paths = qry_options.any? do |key, value|
23
+ if value.is_a?(Array)
24
+ value.any? do |val|
25
+ val.to_s.scan(/(?:^|[^\.])([a-z_]+)\.[a-z_]+/).flatten.any? do |string|
26
+ associations.include?(string)
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ if contains_possible_paths
33
+ return qry("COUNT(DISTINCT id)")[0][0]
34
+ end
23
35
  end
36
+ original_count column_name, options
24
37
  end
25
38
 
26
39
  end
@@ -1,7 +1,7 @@
1
1
  module DirectiveRecord
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 15
4
+ TINY = 16
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
@@ -45,10 +45,26 @@ module Unit
45
45
  end
46
46
  end
47
47
  describe "when not loaded" do
48
- it "uses qry to count the records" do
49
- @relation.expects(:loaded?).returns(false)
50
- @relation.expects(:qry).with("COUNT(DISTINCT id)").returns([[1982]])
51
- assert_equal 1982, @relation.count(:all)
48
+ describe "when not having potential path query options" do
49
+ it "invokes the original count method" do
50
+ @relation.expects(:loaded?).returns(false)
51
+ @relation.expects(:qry_options).returns({:where => ["foo = 12"]})
52
+ @relation.expects(:original_count)
53
+ @relation.count(:all)
54
+
55
+ @relation.expects(:loaded?).returns(false)
56
+ @relation.expects(:qry_options).returns({:where => ["foo.bar = 12"]})
57
+ @relation.expects(:original_count)
58
+ @relation.count(:all)
59
+ end
60
+ end
61
+ describe "when having potential path query options" do
62
+ it "uses #qry to count the records" do
63
+ @relation.expects(:loaded?).returns(false)
64
+ @relation.expects(:qry_options).returns({:where => ["employees.foo = 12"]})
65
+ @relation.expects(:qry).with("COUNT(DISTINCT id)").returns([[1982]])
66
+ assert_equal 1982, @relation.count(:all)
67
+ end
52
68
  end
53
69
  end
54
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: directiverecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord