record_filter 0.9.16 → 0.9.17

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 16
3
2
  :major: 0
4
3
  :minor: 9
4
+ :patch: 17
@@ -5,7 +5,13 @@ module RecordFilter
5
5
 
6
6
  def parse_column_in_table(column, table)
7
7
  while column.is_a?(Hash)
8
- table = table.find_join!(column.keys[0]).right_table
8
+ join = table.find_join(column.keys[0])
9
+ if join
10
+ table = join.right_table
11
+ else
12
+ table.join_association(column.keys[0])
13
+ table = table.find_join(column.keys[0]).right_table
14
+ end
9
15
  column = column.values[0]
10
16
  end
11
17
  [column, table]
@@ -23,6 +23,10 @@ module RecordFilter
23
23
  @query = Query.new(@clazz, filter, *args, &block)
24
24
  end
25
25
 
26
+ def filter_class
27
+ @clazz
28
+ end
29
+
26
30
  def first(*args) # :nodoc:
27
31
  do_with_scope do
28
32
  @clazz.find(:first, *args)
@@ -57,9 +57,9 @@ module RecordFilter
57
57
 
58
58
  def join_type_string
59
59
  @join_type_string ||= case(@join_type)
60
- when :inner then 'INNER'
61
- when :left then 'LEFT OUTER'
62
- when :right then 'RIGHT OUTER'
60
+ when :inner, 'inner' then 'INNER'
61
+ when :left, 'left' then 'LEFT OUTER'
62
+ when :right, 'right' then 'RIGHT OUTER'
63
63
  else nil
64
64
  end
65
65
  end
@@ -10,8 +10,8 @@ module RecordFilter
10
10
 
11
11
  def to_sql
12
12
  dir = case @direction
13
- when :asc then 'ASC'
14
- when :desc then 'DESC'
13
+ when :asc, 'asc' then 'ASC'
14
+ when :desc, 'desc' then 'DESC'
15
15
  else raise InvalidFilterException.new("An invalid order of #{@direction} was specified.")
16
16
  end
17
17
 
@@ -20,8 +20,6 @@ module RecordFilter
20
20
  params = {}
21
21
  conditions = @conjunction.to_conditions
22
22
  params = { :conditions => conditions } if conditions
23
- joins = @table.all_joins
24
- params[:joins] = joins.map { |join| join.to_sql } unless joins.empty?
25
23
  set_select(params, count_query)
26
24
  orders = @table.orders
27
25
  params[:order] = orders.map { |order| order.to_sql } * ', ' unless orders.empty?
@@ -30,6 +28,10 @@ module RecordFilter
30
28
  params[:limit] = @conjunction.limit if @conjunction.limit
31
29
  params[:offset] = @conjunction.offset if @conjunction.offset
32
30
  params[:readonly] = false
31
+ # this is a bit of a hack, but the joins need to go at the end because the other
32
+ # operations may have implicitly created joins as they were sql-ized.
33
+ joins = @table.all_joins
34
+ params[:joins] = joins.map { |join| join.to_sql } unless joins.empty?
33
35
  params
34
36
  end
35
37
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{record_filter}
8
- s.version = "0.9.16"
8
+ s.version = "0.9.17"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aubrey Holland", "Mat Brown"]
12
- s.date = %q{2010-02-12}
12
+ s.date = %q{2010-03-04}
13
13
  s.description = %q{RecordFilter is a Pure-ruby criteria API for building complex queries in ActiveRecord. It supports queries that are built on the fly as well as named filters that can be added to objects and chained to create complex queries. It also gets rid of the nasty hard-coded SQL that shows up in most ActiveRecord code with a clean API that makes queries simple and intuitive to build.}
14
14
  s.email = %q{aubreyholland@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -74,7 +74,7 @@ Gem::Specification.new do |s|
74
74
  s.rdoc_options = ["--charset=UTF-8"]
75
75
  s.require_paths = ["lib"]
76
76
  s.rubyforge_project = %q{record-filter}
77
- s.rubygems_version = %q{1.3.5}
77
+ s.rubygems_version = %q{1.3.6}
78
78
  s.summary = %q{An ActiveRecord query API for replacing SQL with awesome}
79
79
  s.test_files = [
80
80
  "spec/active_record_spec.rb",
@@ -55,7 +55,7 @@ describe 'raising exceptions' do
55
55
  Post.filter do
56
56
  order({ :this_is_not_there => :eh }, :asc)
57
57
  end.inspect
58
- }.should raise_error(RecordFilter::InvalidJoinException)
58
+ }.should raise_error(RecordFilter::AssociationNotFoundException)
59
59
  end
60
60
 
61
61
  it 'should raise ColumnNotFoundException for explicit joins on bad column names for the right table' do
@@ -257,6 +257,14 @@ describe 'implicit joins' do
257
257
  end
258
258
  end
259
259
 
260
+ it 'should allow strings to be passed as the join type' do
261
+ Blog.filter do
262
+ having({ :posts => :comments }, :join_type => 'left') do
263
+ with(:offensive, true)
264
+ end
265
+ end.inspect
266
+ end
267
+
260
268
  describe 'on polymorphic associations' do
261
269
  before do
262
270
  PublicPost.filter do
@@ -293,6 +301,15 @@ describe 'implicit joins' do
293
301
  end
294
302
  end
295
303
 
304
+ describe 'adding joins automatically on ordering' do
305
+ it 'should infer the join' do
306
+ Post.filter do
307
+ order(:comments => :created_at)
308
+ end.inspect
309
+ Post.last_find.should == {:order => 'posts__comments.created_at ASC', :joins => [%q(INNER JOIN "comments" AS posts__comments ON "posts".id = posts__comments.post_id)], :readonly => false}
310
+ end
311
+ end
312
+
296
313
  describe 'on has_one_through associations' do
297
314
  before do
298
315
  Post.filter do
@@ -84,7 +84,7 @@ describe 'RecordFilter restrictions' do
84
84
  Post.filter do
85
85
  with(:blog_id).not_in([])
86
86
  end.inspect
87
- Post.last_find.should == { :readonly => false }
87
+ Post.last_find.should == { :conditions => [], :readonly => false }
88
88
  end
89
89
 
90
90
  it 'should do the right thing for IN filters with single values' do
@@ -271,4 +271,9 @@ describe 'RecordFilter restrictions' do
271
271
  end.inspect
272
272
  Blog.last_find[:conditions].should == [%q(("blogs".created_at > cmts.created_at))]
273
273
  end
274
+
275
+ it 'should return the filter class from a filter' do
276
+ filter = Blog.filter { having(:comments) }
277
+ filter.filter_class.should == Blog
278
+ end
274
279
  end
data/spec/test.db CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: record_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.16
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 17
9
+ version: 0.9.17
5
10
  platform: ruby
6
11
  authors:
7
12
  - Aubrey Holland
@@ -10,29 +15,33 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2010-02-12 00:00:00 -05:00
18
+ date: 2010-03-04 00:00:00 -05:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
17
22
  name: activerecord
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
24
30
  version: "0"
25
- version:
31
+ type: :runtime
32
+ version_requirements: *id001
26
33
  - !ruby/object:Gem::Dependency
27
34
  name: rspec
28
- type: :development
29
- version_requirement:
30
- version_requirements: !ruby/object:Gem::Requirement
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
31
37
  requirements:
32
38
  - - ">="
33
39
  - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
34
42
  version: "0"
35
- version:
43
+ type: :development
44
+ version_requirements: *id002
36
45
  description: RecordFilter is a Pure-ruby criteria API for building complex queries in ActiveRecord. It supports queries that are built on the fly as well as named filters that can be added to objects and chained to create complex queries. It also gets rid of the nasty hard-coded SQL that shows up in most ActiveRecord code with a clean API that makes queries simple and intuitive to build.
37
46
  email: aubreyholland@gmail.com
38
47
  executables: []
@@ -108,18 +117,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
117
  requirements:
109
118
  - - ">="
110
119
  - !ruby/object:Gem::Version
120
+ segments:
121
+ - 0
111
122
  version: "0"
112
- version:
113
123
  required_rubygems_version: !ruby/object:Gem::Requirement
114
124
  requirements:
115
125
  - - ">="
116
126
  - !ruby/object:Gem::Version
127
+ segments:
128
+ - 0
117
129
  version: "0"
118
- version:
119
130
  requirements: []
120
131
 
121
132
  rubyforge_project: record-filter
122
- rubygems_version: 1.3.5
133
+ rubygems_version: 1.3.6
123
134
  signing_key:
124
135
  specification_version: 3
125
136
  summary: An ActiveRecord query API for replacing SQL with awesome