ransack 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,7 +13,8 @@ module Ransack
13
13
 
14
14
  def evaluate(search, opts = {})
15
15
  viz = Visitor.new
16
- @object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
16
+ relation = @object.except(:order).where(viz.accept(search.base)).order(viz.accept(search.sorts))
17
+ opts[:distinct] ? relation.select("DISTINCT #{@klass.quoted_table_name}.*") : relation
17
18
  end
18
19
 
19
20
  def attribute_method?(str, klass = @klass)
@@ -11,7 +11,8 @@ module Ransack
11
11
 
12
12
  def evaluate(search, opts = {})
13
13
  viz = Visitor.new
14
- @object.where(viz.accept(search.base)).order(viz.accept(search.sorts))
14
+ relation = @object.except(:order).where(viz.accept(search.base)).order(viz.accept(search.sorts))
15
+ opts[:distinct] ? relation.select("DISTINCT #{@klass.quoted_table_name}.*") : relation
15
16
  end
16
17
 
17
18
  def attribute_method?(str, klass = @klass)
@@ -1,3 +1,3 @@
1
1
  module Ransack
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -129,6 +129,12 @@ module Ransack
129
129
  where.to_sql.should match /\("people"."name" = 'Ernie' OR "children_people"."name" = 'Ernie'\) AND \("people"."name" = 'Bert' OR "children_people"."name" = 'Bert'\)/
130
130
  end
131
131
 
132
+ it 'returns distinct records when passed :distinct => true' do
133
+ search = Search.new(Person, :g => [{:m => 'or', :comments_body_cont => 'e', :articles_comments_body_cont => 'e'}])
134
+ search.result.should have(920).items
135
+ search.result(:distinct => true).should have(330).items
136
+ search.result.all.uniq.should eq search.result(:distinct => true).all
137
+ end
132
138
  end
133
139
 
134
140
  describe '#sorts=' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-10 00:00:00.000000000 -04:00
12
+ date: 2011-06-11 00:00:00.000000000 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &2153569220 !ruby/object:Gem::Requirement
17
+ requirement: &2153456940 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2153569220
25
+ version_requirements: *2153456940
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &2153568300 !ruby/object:Gem::Requirement
28
+ requirement: &2153456420 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2153568300
36
+ version_requirements: *2153456420
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: actionpack
39
- requirement: &2153567660 !ruby/object:Gem::Requirement
39
+ requirement: &2153455960 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '3.0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2153567660
47
+ version_requirements: *2153455960
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &2153567060 !ruby/object:Gem::Requirement
50
+ requirement: &2153455380 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 2.5.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2153567060
58
+ version_requirements: *2153455380
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: machinist
61
- requirement: &2153566460 !ruby/object:Gem::Requirement
61
+ requirement: &2153454840 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.0.6
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2153566460
69
+ version_requirements: *2153454840
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: faker
72
- requirement: &2153565840 !ruby/object:Gem::Requirement
72
+ requirement: &2153454360 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 0.9.5
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2153565840
80
+ version_requirements: *2153454360
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: sqlite3
83
- requirement: &2153565180 !ruby/object:Gem::Requirement
83
+ requirement: &2153453880 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,7 +88,7 @@ dependencies:
88
88
  version: 1.3.3
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2153565180
91
+ version_requirements: *2153453880
92
92
  description: Ransack is the successor to the MetaSearch gem. It improves and expands
93
93
  upon MetaSearch's functionality, but does not have a 100%-compatible API.
94
94
  email: