postgres_ext 2.1.1 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e108225b5ff194b97925399e805c0ab81ee95db6
4
- data.tar.gz: cad4d50e3d7b19566eabdf8841d1e206a13cbadf
3
+ metadata.gz: f41de74b7eea3b27f6770cb352ba70497d94513d
4
+ data.tar.gz: 3e9cf324c7a635ac338fd5af691909ed13f1f02e
5
5
  SHA512:
6
- metadata.gz: ede479c5b324e86d4c11a7427275a98871742052ebf55a30ebe67f1e332781db30b62ba791a59b271f0d72890c0ba8d9b281ca7c699654ef62f29271b060f160
7
- data.tar.gz: 5e7c698daacf2ecc3c5752d963add7ae9e596aff4602d92b4a1c2919d35f0660fe55a6a4e3f4d2f2ce731b72c2b153edfcdddd864e129d59c8081623bb198046
6
+ metadata.gz: 5843378f753e2755c7c8459d89b580d10089d564b18ee390e349a3590efb0260bb12f6e9ef784bb02ef2514389351b303d867dbe7de4de859ac16ffdd88925ab
7
+ data.tar.gz: cf54fb746947851736f94fbf0e543eae772dfa7e85094c343853f12086c0c3c2c906ae2f15b4412de00fed0f1c749279a51a15a004fe8c5f07de9bdbadc05092
@@ -130,25 +130,27 @@ module ActiveRecord
130
130
  end
131
131
 
132
132
  def build_rank(arel, ranks)
133
- rank_orders = ranks.uniq.reject(&:blank?).flat_map do |value|
134
- case value
135
- when :order
136
- arel.orders
137
- when Symbol
138
- table[value].asc
139
- when Hash
140
- value.map { |field, dir| table[field].send(dir) }
141
- else
142
- Arel::Nodes::SqlLiteral.new value
133
+ unless arel.projections.count == 1 && Arel::Nodes::Count === arel.projections.first
134
+ rank_orders = ranks.uniq.reject(&:blank?).flat_map do |value|
135
+ case value
136
+ when :order
137
+ arel.orders
138
+ when Symbol
139
+ table[value].asc
140
+ when Hash
141
+ value.map { |field, dir| table[field].send(dir) }
142
+ else
143
+ Arel::Nodes::SqlLiteral.new value
144
+ end
143
145
  end
144
- end
145
146
 
146
- unless rank_orders.blank?
147
- rank_node = Arel::Nodes::SqlLiteral.new 'rank()'
148
- window = Arel::Nodes::Window.new.order(rank_orders)
149
- over_node = Arel::Nodes::Over.new rank_node, window
147
+ unless rank_orders.blank?
148
+ rank_node = Arel::Nodes::SqlLiteral.new 'rank()'
149
+ window = Arel::Nodes::Window.new.order(rank_orders)
150
+ over_node = Arel::Nodes::Over.new rank_node, window
150
151
 
151
- arel.project(over_node)
152
+ arel.project(over_node)
153
+ end
152
154
  end
153
155
  end
154
156
 
@@ -1,3 +1,3 @@
1
1
  module PostgresExt
2
- VERSION = '2.1.1'
2
+ VERSION = '2.1.2'
3
3
  end
@@ -40,5 +40,10 @@ describe 'Window functions' do
40
40
  ranked_people[0].rank.should eq 1
41
41
  ranked_people[1].rank.should eq 2
42
42
  end
43
+
44
+ it 'does not apply the rank when performing a count' do
45
+ query = Person.ranked(lucky_number: :desc).count
46
+ query.should eq 0
47
+ end
43
48
  end
44
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan McClain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-03 00:00:00.000000000 Z
11
+ date: 2013-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord