scoped_search 4.1.10 → 4.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/scoped_search/definition.rb +13 -5
- data/lib/scoped_search/query_builder.rb +3 -1
- data/lib/scoped_search/version.rb +1 -1
- data/spec/integration/ordinal_querying_spec.rb +6 -0
- data/spec/integration/rails_helper_spec.rb +12 -12
- data/spec/integration/set_query_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a3be22acffe6a33b115957197a5eca96b2e9cf2abe445b657b302663594abbe
|
4
|
+
data.tar.gz: a97d2cd9a8db87347dee308b1340e87967a887dd6b3c5c7b2124f7d9859a9843
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 840841fa78847d12b0f71ef620dbc73905e34a48325e10864ac56bf4aa746659d12f5cbbb18847c660e019bd42700700afb04928e7ccd48871bfe427ca8ba824
|
7
|
+
data.tar.gz: 11839160ebde29751173c28c718546d92a4378c316f081632f18eef2d688d569a4f1277caf14c40c4896f2168a7e4f42d0717af7482d430de13e9b04b3e77b9a
|
@@ -281,13 +281,13 @@ module ScopedSearch
|
|
281
281
|
# In case Time responds to #zone, we know this is Rails environment and we can use Time.zone.parse. The benefit is that the
|
282
282
|
# current timezone is respected and does not have to be specified explicitly. That way even relative dates work as expected.
|
283
283
|
def parse_temporal(value)
|
284
|
-
return Date.current if value =~ /\btoday\b/i
|
285
|
-
return 1.day.ago
|
286
|
-
return 1.day.from_now
|
284
|
+
return date_with_timezone(Date.current) if value =~ /\btoday\b/i
|
285
|
+
return date_with_timezone(1.day.ago) if value =~ /\byesterday\b/i
|
286
|
+
return date_with_timezone(1.day.from_now) if value =~ /\btomorrow\b/i
|
287
287
|
return (eval($1.strip.gsub(/\s+/,'.').downcase)).to_datetime if value =~ /\A\s*(\d+\s+\b(?:hours?|minutes?)\b\s+\bago)\b\s*\z/i
|
288
|
-
return (eval($1.strip.gsub(/\s+/,'.').downcase))
|
288
|
+
return date_with_timezone(eval($1.strip.gsub(/\s+/,'.').downcase)) if value =~ /\A\s*(\d+\s+\b(?:days?|weeks?|months?|years?)\b\s+\bago)\b\s*\z/i
|
289
289
|
return (eval($1.strip.gsub(/from\s+now/i,'from_now').gsub(/\s+/,'.').downcase)).to_datetime if value =~ /\A\s*(\d+\s+\b(?:hours?|minutes?)\b\s+\bfrom\s+now)\b\s*\z/i
|
290
|
-
return (eval($1.strip.gsub(/from\s+now/i,'from_now').gsub(/\s+/,'.').downcase))
|
290
|
+
return date_with_timezone(eval($1.strip.gsub(/from\s+now/i,'from_now').gsub(/\s+/,'.').downcase)) if value =~ /\A\s*(\d+\s+\b(?:days?|weeks?|months?|years?)\b\s+\bfrom\s+now)\b\s*\z/i
|
291
291
|
if Time.respond_to?(:zone) && !Time.zone.nil?
|
292
292
|
parsed = Time.zone.parse(value) rescue nil
|
293
293
|
parsed && parsed.to_datetime
|
@@ -334,6 +334,14 @@ module ScopedSearch
|
|
334
334
|
|
335
335
|
search_scope
|
336
336
|
end
|
337
|
+
|
338
|
+
# This should get called only when the relative specifiers (1 day ago and
|
339
|
+
# so on), this code path is only viable when Rails are available
|
340
|
+
def date_with_timezone(datetime)
|
341
|
+
date = datetime.to_date
|
342
|
+
return datetime unless date.respond_to?(:in_time_zone)
|
343
|
+
date.in_time_zone.to_datetime
|
344
|
+
end
|
337
345
|
end
|
338
346
|
|
339
347
|
# Registers the complete_for method within the class that is used for searching.
|
@@ -450,7 +450,9 @@ module ScopedSearch
|
|
450
450
|
field = definition.field_by_name(value)
|
451
451
|
if field && field.set? && field.complete_value.values.include?(true)
|
452
452
|
key = field.complete_value.map{|k,v| k if v == true}.compact.first
|
453
|
-
|
453
|
+
sql, *params = builder.set_test(field, :eq, key, &block)
|
454
|
+
params.each { |p| yield(:parameter, p) }
|
455
|
+
return sql
|
454
456
|
end
|
455
457
|
# Search keywords found without context, just search on all the default fields
|
456
458
|
fragments = definition.default_fields_for(value).map do |field|
|
@@ -210,6 +210,12 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
210
210
|
@class.search_for('timestamp > "3 hours ago"').length.should == 4
|
211
211
|
end
|
212
212
|
|
213
|
+
it "should take timezone into consideration" do
|
214
|
+
now = Time.now
|
215
|
+
expected = DateTime.new(now.year, now.month, now.day, 0, 0, 0, now.zone).utc.strftime('%Y-%m-%d %H:%M:%S')
|
216
|
+
@class.search_for('timestamp > yesterday').to_sql.should include(expected)
|
217
|
+
end
|
218
|
+
|
213
219
|
it "should accept 1 week from now as date format" do
|
214
220
|
@class.search_for('date < "1 week from now"').length.should == 6
|
215
221
|
end
|
@@ -9,54 +9,54 @@ describe ScopedSearch::RailsHelper do
|
|
9
9
|
let(:params) { HashWithIndifferentAccess.new(:controller => "resources", :action => "search") }
|
10
10
|
|
11
11
|
it "should generate a link with the order param set" do
|
12
|
-
should_receive(:url_for).with(
|
12
|
+
should_receive(:url_for).with({
|
13
13
|
"controller" => "resources",
|
14
14
|
"action" => "search",
|
15
15
|
"order" => "field ASC"
|
16
|
-
).and_return("/example")
|
16
|
+
}).and_return("/example")
|
17
17
|
|
18
18
|
sort("field")
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should generate a link with order param set to alternative default sorting order" do
|
22
|
-
should_receive(:url_for).with(
|
22
|
+
should_receive(:url_for).with({
|
23
23
|
"controller" => "resources",
|
24
24
|
"action" => "search",
|
25
25
|
"order" => "field DESC"
|
26
|
-
).and_return("/example")
|
26
|
+
}).and_return("/example")
|
27
27
|
|
28
28
|
sort("field", :default => "DESC")
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should generate a link with the order param inverted" do
|
32
|
-
should_receive(:url_for).with(
|
32
|
+
should_receive(:url_for).with({
|
33
33
|
"controller" => "resources",
|
34
34
|
"action" => "search",
|
35
35
|
"order" => "field DESC"
|
36
|
-
).and_return("/example")
|
36
|
+
}).and_return("/example")
|
37
37
|
|
38
38
|
params[:order] = "field ASC"
|
39
39
|
sort("field")
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should generate a link with other parameters retained" do
|
43
|
-
should_receive(:url_for).with(
|
43
|
+
should_receive(:url_for).with({
|
44
44
|
"controller" => "resources",
|
45
45
|
"action" => "search",
|
46
46
|
"walrus" => "unicorns",
|
47
47
|
"order" => "field ASC"
|
48
|
-
).and_return("/example")
|
48
|
+
}).and_return("/example")
|
49
49
|
|
50
50
|
params[:walrus] = "unicorns"
|
51
51
|
sort("field")
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should replace the current sorting order" do
|
55
|
-
should_receive(:url_for).with(
|
55
|
+
should_receive(:url_for).with({
|
56
56
|
"controller" => "resources",
|
57
57
|
"action" => "search",
|
58
58
|
"order" => "other ASC"
|
59
|
-
).and_return("/example")
|
59
|
+
}).and_return("/example")
|
60
60
|
|
61
61
|
params[:order] = "field ASC"
|
62
62
|
sort("other")
|
@@ -83,12 +83,12 @@ describe ScopedSearch::RailsHelper do
|
|
83
83
|
let(:ac_params) { double('ActionController::Parameters') }
|
84
84
|
|
85
85
|
it "should call to_h on passed params object" do
|
86
|
-
should_receive(:url_for).with(
|
86
|
+
should_receive(:url_for).with({
|
87
87
|
"controller" => "resources",
|
88
88
|
"action" => "search",
|
89
89
|
"walrus" => "unicorns",
|
90
90
|
"order" => "field ASC"
|
91
|
-
).and_return("/example")
|
91
|
+
}).and_return("/example")
|
92
92
|
|
93
93
|
params[:walrus] = "unicorns"
|
94
94
|
|
@@ -12,6 +12,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
12
12
|
@class = ScopedSearch::RSpec::Database.create_model(:bool => :boolean, :status => :integer) do |klass|
|
13
13
|
klass.scoped_search :on => :bool, :complete_value => {:yes => true, :no => false}
|
14
14
|
klass.scoped_search :on => :status, :complete_value => {:unknown => 0, :up => 1, :down => 2}
|
15
|
+
klass.scoped_search :on => :bool, :rename => :bool2, :complete_value => {:true => true, :false => false}
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -71,6 +72,11 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
|
|
71
72
|
it "should find two record with bool = false" do
|
72
73
|
@class.search_for('bool != yes').length.should == 2
|
73
74
|
end
|
75
|
+
|
76
|
+
it "should be able to search without value" do
|
77
|
+
@class.search_for('bool').length.should == 1
|
78
|
+
@class.search_for('bool2').length.should == 1
|
79
|
+
end
|
74
80
|
end
|
75
81
|
end
|
76
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scoped_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.1.
|
4
|
+
version: 4.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amos Benari
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2023-06-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
|
-
rubygems_version: 3.
|
168
|
+
rubygems_version: 3.4.13
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Easily search you ActiveRecord models with a simple query language using
|