meta_search 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ Changes since 1.0.4 (2011-04-08):
2
+ * Add :join_type option to Builder to allow for using InnerJoin if desired
3
+ (Stephen Pike)
4
+ * Fix a memory leak in development mode (Bonias)
5
+
1
6
  Changes since 1.0.3 (2011-03-14):
2
7
  * Be sure not to override form_for options if super returns a non-true value,
3
8
  fixes a compatibility issue when using client_side_validation
data/README.rdoc CHANGED
@@ -1,5 +1,8 @@
1
1
  = MetaSearch
2
2
 
3
+ (If you're using edge Rails and you'd like to take an early peek at the successor to
4
+ MetaSearch, please have a look at {Ransack}[http://github.com/ernie/ransack])
5
+
3
6
  MetaSearch is extensible searching for your form_for enjoyment. It “wraps” one of your ActiveRecord models, providing methods that allow you to build up search conditions against that model, and has a few extra form helpers to simplify sorting and supplying multiple parameters to your condition methods as well.
4
7
 
5
8
  == Getting Started
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.0.5
@@ -33,6 +33,8 @@ module MetaSearch
33
33
  @base = @relation.klass
34
34
  @search_key = (opts.delete(:search_key) || 'search').to_s
35
35
  @options = opts # Let's just hang on to other options for use in authorization blocks
36
+ @join_type = opts[:join_type] || Arel::Nodes::OuterJoin
37
+ @join_type = get_join_type(@join_type)
36
38
  @join_dependency = build_join_dependency
37
39
  @search_attributes = {}
38
40
  @errors = ActiveModel::Errors.new(self)
@@ -257,7 +259,7 @@ module MetaSearch
257
259
  assoc.parent == parent
258
260
  end
259
261
  unless found_association
260
- @join_dependency.send(:build_with_metasearch, association, parent, Arel::Nodes::OuterJoin, klass)
262
+ @join_dependency.send(:build_with_metasearch, association, parent, @join_type, klass)
261
263
  found_association = @join_dependency.join_associations.last
262
264
  @relation = @relation.joins(found_association)
263
265
  end
@@ -299,5 +301,15 @@ module MetaSearch
299
301
  arel.joins(arel)
300
302
  end
301
303
 
304
+ def get_join_type(opt_join)
305
+ # Allow "inner"/:inner and "upper"/:upper
306
+ if opt_join.to_s.upcase == 'INNER'
307
+ opt_join = Arel::Nodes::InnerJoin
308
+ elsif opt_join.to_s.upcase == 'OUTER'
309
+ opt_join = Arel::Nodes::OuterJoin
310
+ end
311
+ # Default to trusting what the user gave us
312
+ opt_join
313
+ end
302
314
  end
303
- end
315
+ end
@@ -181,22 +181,23 @@ module MetaSearch
181
181
  end
182
182
 
183
183
  def self.for(klass)
184
- DISPATCH[klass]
184
+ DISPATCH[klass.name]
185
185
  end
186
186
 
187
187
  private
188
188
 
189
- DISPATCH = Hash.new do |hash, klass|
190
- class_name = klass.name.gsub('::', '_')
191
- hash[klass] = module_eval <<-RUBY_EVAL
189
+ DISPATCH = Hash.new do |hash, klass_name|
190
+ class_name = klass_name.gsub('::', '_')
191
+ hash[klass_name] = module_eval <<-RUBY_EVAL
192
192
  class #{class_name} < MetaSearch::Builder
193
193
  def self.klass
194
- ::#{klass}
194
+ ::#{klass_name}
195
195
  end
196
196
  end
197
197
 
198
198
  #{class_name}
199
199
  RUBY_EVAL
200
200
  end
201
+
201
202
  end
202
203
  end
data/meta_search.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{meta_search}
8
- s.version = "1.0.4"
8
+ s.version = "1.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ernie Miller"]
12
- s.date = %q{2011-04-08}
11
+ s.authors = [%q{Ernie Miller}]
12
+ s.date = %q{2011-05-05}
13
13
  s.description = %q{
14
14
  Allows simple search forms to be created against an AR3 model
15
15
  and its associations, has useful view helpers for sort links
@@ -70,20 +70,9 @@ you're feeling especially appreciative. It'd help me justify this
70
70
  "open source" stuff to my lovely wife. :)
71
71
 
72
72
  }
73
- s.require_paths = ["lib"]
74
- s.rubygems_version = %q{1.7.2}
73
+ s.require_paths = [%q{lib}]
74
+ s.rubygems_version = %q{1.8.0}
75
75
  s.summary = %q{Object-based searching (and more) for simply creating search forms.}
76
- s.test_files = [
77
- "test/fixtures/company.rb",
78
- "test/fixtures/data_type.rb",
79
- "test/fixtures/developer.rb",
80
- "test/fixtures/note.rb",
81
- "test/fixtures/project.rb",
82
- "test/fixtures/schema.rb",
83
- "test/helper.rb",
84
- "test/test_search.rb",
85
- "test/test_view_helpers.rb"
86
- ]
87
76
 
88
77
  if s.respond_to? :specification_version then
89
78
  s.specification_version = 3
@@ -52,4 +52,11 @@ another:
52
52
  company_id: 3
53
53
  name : Another Guy
54
54
  salary : 80000
55
- slacker : false
55
+ slacker : false
56
+
57
+ forgetful:
58
+ id : 9
59
+ company_id: 3
60
+ name : Forgetful Notetaker
61
+ salary : 40000
62
+ slacker : false
data/test/test_search.rb CHANGED
@@ -74,6 +74,52 @@ class TestSearch < Test::Unit::TestCase
74
74
  end
75
75
  end
76
76
 
77
+ context "A Developer search" do
78
+ setup do
79
+ @s = Developer.search({:name_equals=>"Forgetful Notetaker"})
80
+ end
81
+
82
+ context "without any opts" do
83
+ should "find a null entry when searching notes" do
84
+ assert_equal 1, @s.notes_note_is_null(true).all.size
85
+ end
86
+
87
+ should "find no non-null entry when searching notes" do
88
+ assert_equal 0, @s.notes_note_is_not_null(true).all.size
89
+ end
90
+ end
91
+
92
+ context "with outer join specified" do
93
+ setup do
94
+ @s = Developer.search({:name_equals=>"Forgetful Notetaker"}, :join_type=>:outer)
95
+ end
96
+
97
+ should "find a null entry when searching notes" do
98
+ assert_equal 1, @s.notes_note_is_null(true).all.size
99
+ end
100
+
101
+ should "find no non-null entry when searching notes" do
102
+ assert_equal 0, @s.notes_note_is_not_null(true).all.size
103
+ end
104
+ end
105
+
106
+ context "with inner join specified" do
107
+ setup do
108
+ @s = Developer.search({:name_equals=>"Forgetful Notetaker"}, :join_type=>:inner)
109
+ end
110
+
111
+ should "find no null entry when searching notes" do
112
+ assert_equal 0, @s.notes_note_is_null(true).all.size
113
+ end
114
+
115
+ should "find no non-null entry when searching notes" do
116
+ assert_equal 0, @s.notes_note_is_not_null(true).all.size
117
+ end
118
+ end
119
+
120
+
121
+ end
122
+
77
123
  [{:name => 'Company', :object => Company},
78
124
  {:name => 'Company as a Relation', :object => Company.scoped}].each do |object|
79
125
  context_a_search_against object[:name], object[:object] do
@@ -477,8 +523,8 @@ class TestSearch < Test::Unit::TestCase
477
523
  @s.name_ne = 'Ernie Miller'
478
524
  end
479
525
 
480
- should "return seven results" do
481
- assert_equal 7, @s.all.size
526
+ should "return eight results" do
527
+ assert_equal 8, @s.all.size
482
528
  end
483
529
 
484
530
  should "not return a developer named Ernie Miller" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: meta_search
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.4
5
+ version: 1.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ernie Miller
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-08 00:00:00 Z
13
+ date: 2011-05-05 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: shoulda
@@ -144,17 +144,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements: []
145
145
 
146
146
  rubyforge_project:
147
- rubygems_version: 1.7.2
147
+ rubygems_version: 1.8.0
148
148
  signing_key:
149
149
  specification_version: 3
150
150
  summary: Object-based searching (and more) for simply creating search forms.
151
- test_files:
152
- - test/fixtures/company.rb
153
- - test/fixtures/data_type.rb
154
- - test/fixtures/developer.rb
155
- - test/fixtures/note.rb
156
- - test/fixtures/project.rb
157
- - test/fixtures/schema.rb
158
- - test/helper.rb
159
- - test/test_search.rb
160
- - test/test_view_helpers.rb
151
+ test_files: []
152
+