search_cop 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module SearchCop
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -92,6 +92,18 @@ module SearchCopGrammar
92
92
  end
93
93
  end
94
94
 
95
+ class SingleQuotedAnywhereExpression < AnywhereExpression
96
+ def text_value
97
+ super.gsub /^'|'$/, ""
98
+ end
99
+ end
100
+
101
+ class DoubleQuotedAnywhereExpression < AnywhereExpression
102
+ def text_value
103
+ super.gsub /^"|"$/, ""
104
+ end
105
+ end
106
+
95
107
  class AndExpression < BaseNode
96
108
  def evaluate
97
109
  [elements.first.evaluate, elements.last.evaluate].inject(:and)
@@ -37,7 +37,7 @@ grammar SearchCopGrammar
37
37
  end
38
38
 
39
39
  rule anywhere_expression
40
- ("'" ([^\']* <AnywhereExpression>) "'") / ('"' ([^\"]* <AnywhereExpression>) '"') / [^\s()]+ <AnywhereExpression>
40
+ "'" [^\']* "'" <SingleQuotedAnywhereExpression> / '"' [^\"]* '"' <DoubleQuotedAnywhereExpression> / [^\s()]+ <AnywhereExpression>
41
41
  end
42
42
 
43
43
  rule simple_column
data/test/string_test.rb CHANGED
@@ -9,6 +9,16 @@ class StringTest < SearchCop::TestCase
9
9
  refute_includes Product.search("Rejected"), product
10
10
  end
11
11
 
12
+ def test_anywhere_quoted
13
+ product = create(:product, :title => "Expected title")
14
+
15
+ assert_includes Product.search("'Expected title'"), product
16
+ assert_includes Product.search('"Expected title"'), product
17
+
18
+ refute_includes Product.search("'Rejected title'"), product
19
+ refute_includes Product.search('"Rejected title"'), product
20
+ end
21
+
12
22
  def test_multiple
13
23
  product = create(:product, :comments => [create(:comment, :title => "Expected title", :message => "Expected message")])
14
24
 
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.4
4
+ version: 1.0.5
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: 2014-12-22 00:00:00.000000000 Z
12
+ date: 2015-01-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: treetop