search_cop 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
 
2
2
  # Changelog
3
3
 
4
+ Version 1.0.5:
5
+
6
+ * Fixes a bug regarding quotation
7
+
4
8
  Version 1.0.4:
5
9
 
6
10
  * Fix for Rails 4.2 regression regarding reflection access
data/README.md CHANGED
@@ -130,7 +130,7 @@ Book.where(:available => true).search("Harry Potter").order("books.id desc").pag
130
130
  By default, i.e. if you don't tell SearchCop about your fulltext indices,
131
131
  SearchCop will use `LIKE '%...%'` queries. Unfortunately, unless you
132
132
  create a [trigram index](http://www.postgresql.org/docs/9.1/static/pgtrgm.html)
133
- (postgres only), theses queries can not use SQL indices, such that every row
133
+ (postgres only), these queries can not use SQL indices, such that every row
134
134
  needs to be scanned by your RDBMS when you search for `Book.search("Harry
135
135
  Potter")` or similar. To avoid the penalty of `LIKE` queries, SearchCop
136
136
  can exploit the fulltext index capabilities of MySQL and PostgreSQL. To use
@@ -160,7 +160,7 @@ Book.search("Harry Potter")
160
160
  # PostgreSQL: ... WHERE (to_tsvector('simple', books.title) @@ to_tsquery('simple', 'Harry') OR to_tsvector('simple', books.author) @@ to_tsquery('simple', 'Harry')) AND (to_tsvector('simple', books.title) @@ to_tsquery('simple', 'Potter') OR to_tsvector('simple', books.author) @@ to_tsquery('simple', 'Potter'))
161
161
  ```
162
162
 
163
- Obviously, theses queries won't always return the same results as wildcard
163
+ Obviously, these queries won't always return the same results as wildcard
164
164
  `LIKE` queries, because we search for words instead of sub-strings. However,
165
165
  fulltext indices will usually of course provide better performance.
166
166
 
@@ -1,3 +1,3 @@
1
1
  module SearchCop
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
@@ -178,11 +178,11 @@ module SearchCopGrammar
178
178
  def parse(value)
179
179
  return value .. value unless value.is_a?(::String)
180
180
 
181
- if value =~ /^[0-9]{4,}$/
181
+ if value =~ /^[0-9]{4}$/
182
182
  ::Time.new(value).beginning_of_year .. ::Time.new(value).end_of_year
183
- elsif value =~ /^([0-9]{4,})(\.|-|\/)([0-9]{1,2})$/
183
+ elsif value =~ /^([0-9]{4})(\.|-|\/)([0-9]{1,2})$/
184
184
  ::Time.new($1, $3, 15).beginning_of_month .. ::Time.new($1, $3, 15).end_of_month
185
- elsif value =~ /^([0-9]{1,2})(\.|-|\/)([0-9]{4,})$/
185
+ elsif value =~ /^([0-9]{1,2})(\.|-|\/)([0-9]{4})$/
186
186
  ::Time.new($3, $1, 15).beginning_of_month .. ::Time.new($3, $1, 15).end_of_month
187
187
  elsif value !~ /:/
188
188
  time = ::Time.parse(value)
@@ -222,11 +222,11 @@ module SearchCopGrammar
222
222
  def parse(value)
223
223
  return value .. value unless value.is_a?(::String)
224
224
 
225
- if value =~ /^[0-9]{4,}$/
225
+ if value =~ /^[0-9]{4}$/
226
226
  ::Date.new(value.to_i).beginning_of_year .. ::Date.new(value.to_i).end_of_year
227
- elsif value =~ /^([0-9]{4,})(\.|-|\/)([0-9]{1,2})$/
227
+ elsif value =~ /^([0-9]{4})(\.|-|\/)([0-9]{1,2})$/
228
228
  ::Date.new($1.to_i, $3.to_i, 15).beginning_of_month .. ::Date.new($1.to_i, $3.to_i, 15).end_of_month
229
- elsif value =~ /^([0-9]{1,2})(\.|-|\/)([0-9]{4,})$/
229
+ elsif value =~ /^([0-9]{1,2})(\.|-|\/)([0-9]{4})$/
230
230
  ::Date.new($3.to_i, $1.to_i, 15).beginning_of_month .. ::Date.new($3.to_i, $1.to_i, 15).end_of_month
231
231
  else
232
232
  date = ::Date.parse(value)
data/test/date_test.rb CHANGED
@@ -66,6 +66,12 @@ class DateTest < SearchCop::TestCase
66
66
  refute_includes Product.search("created_on <= 2014-05-01"), product
67
67
  end
68
68
 
69
+ def test_no_overflow
70
+ assert_nothing_raised do
71
+ Product.search("created_on: 1000000").to_a
72
+ end
73
+ end
74
+
69
75
  def test_incompatible_datatype
70
76
  assert_raises SearchCop::IncompatibleDatatype do
71
77
  Product.unsafe_search "created_on: Value"
@@ -67,6 +67,12 @@ class DatetimeTest < SearchCop::TestCase
67
67
  refute_includes Product.search("created_at <= 2014-05-01"), product
68
68
  end
69
69
 
70
+ def test_no_overflow
71
+ assert_nothing_raised do
72
+ Product.search("created_at: 1000000").to_a
73
+ end
74
+ end
75
+
70
76
  def test_incompatible_datatype
71
77
  assert_raises SearchCop::IncompatibleDatatype do
72
78
  Product.unsafe_search "created_at: Value"
data/test/test_helper.rb CHANGED
@@ -149,6 +149,10 @@ class SearchCop::TestCase
149
149
  assert value
150
150
  end
151
151
 
152
+ def assert_nothing_raised
153
+ yield
154
+ end
155
+
152
156
  def quote_table_name(name)
153
157
  ActiveRecord::Base.connection.quote_table_name name
154
158
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: search_cop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-14 00:00:00.000000000 Z
12
+ date: 2015-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: treetop