meta_search 0.9.9.1 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/VERSION +1 -1
- data/lib/meta_search/builder.rb +8 -17
- data/lib/meta_search/model_compatibility.rb +1 -1
- data/meta_search.gemspec +2 -2
- data/test/locales/flanders.yml +2 -0
- data/test/test_search.rb +6 -12
- data/test/test_view_helpers.rb +1 -0
- metadata +3 -4
data/CHANGELOG
CHANGED
@@ -2,6 +2,7 @@ Changes since 0.9.9 (2010-11-15):
|
|
2
2
|
* Fix bug introduced by new polymorphic belongs_to association code in
|
3
3
|
honoring :url param to form_for
|
4
4
|
* Support localization of predicate text in labels
|
5
|
+
* Fix bug when accessing localizations for named search methods
|
5
6
|
|
6
7
|
Changes since 0.9.8 (2010-10-20):
|
7
8
|
* ARel 2.x and Rails 3.0.2 compatability
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.10
|
data/lib/meta_search/builder.rb
CHANGED
@@ -22,7 +22,7 @@ module MetaSearch
|
|
22
22
|
include ModelCompatibility
|
23
23
|
include Utility
|
24
24
|
|
25
|
-
attr_reader :base, :search_key, :search_attributes, :join_dependency, :errors
|
25
|
+
attr_reader :base, :relation, :search_key, :search_attributes, :join_dependency, :errors
|
26
26
|
delegate *RELATION_METHODS + [:to => :relation]
|
27
27
|
|
28
28
|
# Initialize a new Builder. Requires a base model to wrap, and supports a couple of options
|
@@ -36,11 +36,6 @@ module MetaSearch
|
|
36
36
|
@errors = ActiveModel::Errors.new(self)
|
37
37
|
end
|
38
38
|
|
39
|
-
def relation
|
40
|
-
enforce_join_depth_limit!
|
41
|
-
@relation
|
42
|
-
end
|
43
|
-
|
44
39
|
def get_column(column, base = @base)
|
45
40
|
base.columns_hash[column.to_s] unless base_excludes_attribute(base, column)
|
46
41
|
end
|
@@ -132,12 +127,6 @@ module MetaSearch
|
|
132
127
|
end
|
133
128
|
end
|
134
129
|
|
135
|
-
def enforce_join_depth_limit!
|
136
|
-
raise JoinDepthError, "Maximum join depth of #{MAX_JOIN_DEPTH} exceeded." if @join_dependency.join_associations.detect {|ja|
|
137
|
-
gauge_depth_of_join_association(ja) > MAX_JOIN_DEPTH
|
138
|
-
}
|
139
|
-
end
|
140
|
-
|
141
130
|
def gauge_depth_of_join_association(ja)
|
142
131
|
1 + (ja.respond_to?(:parent) ? gauge_depth_of_join_association(ja.parent) : 0)
|
143
132
|
end
|
@@ -236,22 +225,24 @@ module MetaSearch
|
|
236
225
|
end
|
237
226
|
end
|
238
227
|
|
239
|
-
def column_type(name, base = @base)
|
228
|
+
def column_type(name, base = @base, depth = 1)
|
240
229
|
type = nil
|
241
230
|
if column = get_column(name, base)
|
242
231
|
type = column.type
|
243
232
|
elsif (segments = name.split(/_/)).size > 1
|
244
|
-
type = type_from_association_segments(segments, base)
|
233
|
+
type = type_from_association_segments(segments, base, depth)
|
245
234
|
end
|
246
235
|
type
|
247
236
|
end
|
248
237
|
|
249
|
-
def type_from_association_segments(segments, base)
|
238
|
+
def type_from_association_segments(segments, base, depth)
|
250
239
|
remainder = []
|
251
240
|
found_assoc = nil
|
252
241
|
type = nil
|
253
242
|
while remainder.unshift(segments.pop) && segments.size > 0 && !found_assoc do
|
254
243
|
if found_assoc = get_association(segments.join('_'), base)
|
244
|
+
depth += 1
|
245
|
+
raise JoinDepthError, "Maximum join depth of #{MAX_JOIN_DEPTH} exceeded." if depth > MAX_JOIN_DEPTH
|
255
246
|
if found_assoc.options[:polymorphic]
|
256
247
|
unless delimiter = remainder.index('type')
|
257
248
|
raise PolymorphicAssociationMissingTypeError, "Polymorphic association specified without a type"
|
@@ -259,9 +250,9 @@ module MetaSearch
|
|
259
250
|
polymorphic_class, attribute_name = remainder[0...delimiter].join('_'),
|
260
251
|
remainder[delimiter + 1...remainder.size].join('_')
|
261
252
|
polymorphic_class = polymorphic_class.classify.constantize
|
262
|
-
type = column_type(attribute_name, polymorphic_class)
|
253
|
+
type = column_type(attribute_name, polymorphic_class, depth)
|
263
254
|
else
|
264
|
-
type = column_type(remainder.join('_'), found_assoc.klass)
|
255
|
+
type = column_type(remainder.join('_'), found_assoc.klass, depth)
|
265
256
|
end
|
266
257
|
end
|
267
258
|
end
|
@@ -64,7 +64,7 @@ module MetaSearch
|
|
64
64
|
defaults << options.delete(:default) if options[:default]
|
65
65
|
defaults << attribute.to_s.humanize
|
66
66
|
|
67
|
-
options.reverse_merge! :count => 1, :default => defaults, :attribute => klass.human_attribute_name(predicate_attribute)
|
67
|
+
options.reverse_merge! :count => 1, :default => defaults, :attribute => klass.human_attribute_name(predicate_attribute || attribute)
|
68
68
|
I18n.translate(defaults.shift, options)
|
69
69
|
end
|
70
70
|
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 = "0.9.
|
8
|
+
s.version = "0.9.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ernie Miller"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-18}
|
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
|
data/test/locales/flanders.yml
CHANGED
data/test/test_search.rb
CHANGED
@@ -80,6 +80,12 @@ class TestSearch < Test::Unit::TestCase
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
should "raise an error when MAX_JOIN_DEPTH is exceeded" do
|
84
|
+
assert_raise MetaSearch::JoinDepthError do
|
85
|
+
@s.developers_company_developers_company_developers_name_equals = "Ernie Miller"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
83
89
|
context "sorted by name in ascending order" do
|
84
90
|
setup do
|
85
91
|
@s.meta_sort = 'name.asc'
|
@@ -211,18 +217,6 @@ class TestSearch < Test::Unit::TestCase
|
|
211
217
|
end
|
212
218
|
end
|
213
219
|
|
214
|
-
context "with a join more than five tables deep (including source table)" do
|
215
|
-
setup do
|
216
|
-
@s.developers_company_developers_company_developers_name_equals = "Ernie Miller"
|
217
|
-
end
|
218
|
-
|
219
|
-
should "raise an error when the relation is accessed" do
|
220
|
-
assert_raise MetaSearch::JoinDepthError do
|
221
|
-
@s.all
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
220
|
context "where backwards name is hcetinI" do
|
227
221
|
setup do
|
228
222
|
@s.backwards_name = 'hcetinI'
|
data/test/test_view_helpers.rb
CHANGED
@@ -60,6 +60,7 @@ class TestViewHelpers < ActionView::TestCase
|
|
60
60
|
|
61
61
|
should "localize according to their bases" do
|
62
62
|
assert_match /Company name-diddly contains-diddly/, @f1.label(:name_contains)
|
63
|
+
assert_match /Company reverse name-diddly/, @f1.label(:reverse_name)
|
63
64
|
assert_match /Developer name-diddly contains-aroonie/, @f2.label(:name_like)
|
64
65
|
end
|
65
66
|
end
|
metadata
CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.9.9.1
|
8
|
+
- 10
|
9
|
+
version: 0.9.10
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Ernie Miller
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-18 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|