scoped_search 2.6.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzUyZjNjZjdmMDY2MTgzNzJkYjExNWI2NzY5MjMyYmMwNWEzMzUwNQ==
5
+ data.tar.gz: !binary |-
6
+ MDc4ZmFjZTRlYmMyZDRhZjljYzg2NzFmYWM1OWJkNDllOGQwMmUzOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YzE3ZjUwNmJlZjc4YTMyM2Q1YmM4NmI3MmI2ZGY1MzUxY2RiZDExZThiMDYw
10
+ ZjBhMmI2YmZlNGNlYTBmNzBmMmZjMjg0Y2NjN2YzZjgwOTA5NjJmMDhlYzg4
11
+ ODI0MmEyYTI0NGZiN2NjYzBiN2ZlNzA1ZGY1ZDM0Y2FkZDcyMzg=
12
+ data.tar.gz: !binary |-
13
+ NmU5N2UwN2FiOWE1MGI2NDNjNWZkMWEyNGI5YTk2MzIxM2Q5ZTc5YjIwOGQ5
14
+ N2UzMTg0ODlhMTljZDQ5NDAxNGZiNTMwMDhkODg5MmQ3Yzc3NzNhMGU1Y2I0
15
+ NTlmMDEwODgxMTk3ZWNiZjI5NjU5N2RjNzE3MzBjMDYwZDk0NzM=
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'activerecord', '~> 2'
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'activerecord', '~> 3'
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'activerecord', '~> 4.0.0.beta1'
@@ -53,6 +53,10 @@ module ScopedSearch::QueryLanguage::AST
53
53
  def eql?(node) # :nodoc
54
54
  node.kind_of?(LeafNode) && node.value == value
55
55
  end
56
+
57
+ def empty?
58
+ false
59
+ end
56
60
  end
57
61
 
58
62
  # AST class for representing operators in the query. An operator node has an operator
@@ -64,9 +68,11 @@ module ScopedSearch::QueryLanguage::AST
64
68
  attr_reader :operator
65
69
  attr_reader :children
66
70
 
67
- def initialize(operator, children) # :nodoc
71
+ def initialize(operator, children, root_node = false) # :nodoc
68
72
  @operator = operator
69
73
  @children = children
74
+
75
+ raise ScopedSearch::QueryNotSupported, "Empty list of operands" if @children.empty? && !root_node
70
76
  end
71
77
 
72
78
  # Tree simplicication: returns itself after simpifying its children
@@ -97,6 +103,10 @@ module ScopedSearch::QueryLanguage::AST
97
103
  children.length == 1 ? children[0] : children[1]
98
104
  end
99
105
 
106
+ def empty?
107
+ children.length == 0
108
+ end
109
+
100
110
  # Returns true if this is an infix operator
101
111
  def infix?
102
112
  children.length > 1
@@ -25,12 +25,14 @@ module ScopedSearch::QueryLanguage::Parser
25
25
  end
26
26
 
27
27
  # Parses a sequence of expressions
28
- def parse_expression_sequence(initial = false)
28
+ def parse_expression_sequence(root_node = false)
29
29
  expressions = []
30
- next_token if !initial && peek_token == :lparen # skip staring :lparen
30
+
31
+ next_token if !root_node && peek_token == :lparen # skip starting :lparen
31
32
  expressions << parse_logical_expression until peek_token.nil? || peek_token == :rparen
32
- next_token if !initial && peek_token == :rparen # skip final :rparen
33
- return ScopedSearch::QueryLanguage::AST::LogicalOperatorNode.new(DEFAULT_SEQUENCE_OPERATOR, expressions)
33
+ next_token if !root_node && peek_token == :rparen # skip final :rparen
34
+
35
+ return ScopedSearch::QueryLanguage::AST::LogicalOperatorNode.new(DEFAULT_SEQUENCE_OPERATOR, expressions, root_node)
34
36
  end
35
37
 
36
38
  # Parses a logical expression.
@@ -60,6 +62,8 @@ module ScopedSearch::QueryLanguage::Parser
60
62
  when :lparen; parse_expression_sequence
61
63
  else parse_comparison
62
64
  end
65
+
66
+ raise ScopedSearch::QueryNotSupported, "No operands found" if negated_expression.empty?
63
67
  return ScopedSearch::QueryLanguage::AST::OperatorNode.new(:not, [negated_expression])
64
68
  end
65
69
 
@@ -1,3 +1,3 @@
1
1
  module ScopedSearch
2
- VERSION = "2.6.0"
2
+ VERSION = "2.6.1"
3
3
  end
@@ -2,14 +2,15 @@ sqlite:
2
2
  adapter: "sqlite3"
3
3
  database: ":memory:"
4
4
 
5
- mysql:
6
- adapter: "mysql2"
7
- host: "localhost"
8
- username: "root"
9
- database: "scoped_search_test"
5
+ # mysql:
6
+ # adapter: "mysql2"
7
+ # host: "127.0.0.1"
8
+ # port: 13306
9
+ # username: "root"
10
+ # database: "scoped_search_test"
10
11
 
11
- postgresql:
12
- adapter: "postgresql"
13
- host: "localhost"
14
- username: "postgres"
15
- database: "scoped_search_test"
12
+ # postgresql:
13
+ # adapter: "postgresql"
14
+ # host: "127.0.0.1"
15
+ # port: 5432
16
+ # database: "scoped_search_test"
@@ -87,7 +87,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
87
87
  it "encoded string should not raise TypeError when querying non-indexed column without a value" do
88
88
  if defined? Encoding
89
89
  query = 'unindexed ='.force_encoding(Encoding::UTF_8).encode
90
- lambda { @class.search_for(query) }.should_not raise_error(TypeError)
90
+ lambda { @class.search_for(query) }.should_not raise_error
91
91
  end
92
92
  end
93
93
 
data/spec/lib/mocks.rb CHANGED
@@ -5,17 +5,17 @@ module ScopedSearch::RSpec::Mocks
5
5
  end
6
6
 
7
7
  def mock_activerecord_class
8
- ar_mock = mock('ActiveRecord::Base')
9
- ar_mock.stub!(:named_scope).with(:search_for, anything)
10
- ar_mock.stub!(:scope).with(:search_for, anything)
11
- ar_mock.stub!(:connection).and_return(mock_database_connection)
12
- ar_mock.stub!(:ancestors).and_return([ActiveRecord::Base])
13
- ar_mock.stub!(:columns_hash).and_return({'existing' => mock('column')})
8
+ ar_mock = double('ActiveRecord::Base')
9
+ ar_mock.stub(:named_scope).with(:search_for, anything)
10
+ ar_mock.stub(:scope).with(:search_for, anything)
11
+ ar_mock.stub(:connection).and_return(mock_database_connection)
12
+ ar_mock.stub(:ancestors).and_return([ActiveRecord::Base])
13
+ ar_mock.stub(:columns_hash).and_return({'existing' => double('column')})
14
14
  return ar_mock
15
15
  end
16
16
 
17
17
  def mock_database_connection
18
- c_mock = mock('ActiveRecord::Base.connection')
18
+ c_mock = double('ActiveRecord::Base.connection')
19
19
  return c_mock
20
20
  end
21
21
 
@@ -3,10 +3,10 @@ require "spec_helper"
3
3
  describe ScopedSearch::AutoCompleteBuilder do
4
4
 
5
5
  before(:each) do
6
- @definition = mock('ScopedSearch::Definition')
7
- @definition.stub!(:klass).and_return(Class.new(ActiveRecord::Base))
8
- @definition.stub!(:profile).and_return(:default)
9
- @definition.stub!(:profile=).and_return(true)
6
+ @definition = double('ScopedSearch::Definition')
7
+ @definition.stub(:klass).and_return(Class.new(ActiveRecord::Base))
8
+ @definition.stub(:profile).and_return(:default)
9
+ @definition.stub(:profile=).and_return(true)
10
10
  end
11
11
 
12
12
  it "should return empty suggestions if the search query is nil" do
@@ -5,7 +5,7 @@ describe ScopedSearch::Definition do
5
5
  before(:each) do
6
6
  @klass = mock_activerecord_class
7
7
  @definition = ScopedSearch::Definition.new(@klass)
8
- @definition.stub!(:setup_adapter)
8
+ @definition.stub(:setup_adapter)
9
9
  end
10
10
 
11
11
  describe ScopedSearch::Definition::Field do
@@ -19,7 +19,7 @@ describe ScopedSearch::Definition do
19
19
  it "should not raise an exception when using an unknown field" do
20
20
  lambda {
21
21
  @definition.define(:on => 'existing').column
22
- }.should_not raise_error(ActiveRecord::UnknownAttributeError)
22
+ }.should_not raise_error
23
23
  end
24
24
  end
25
25
  end
@@ -34,7 +34,7 @@ describe ScopedSearch::Definition do
34
34
  end
35
35
 
36
36
  it "should not create the named scope if it already exists" do
37
- @klass.stub!(:search_for)
37
+ @klass.stub(:search_for)
38
38
  @klass.should_not_receive(:named_scope)
39
39
  ScopedSearch::Definition.new(@klass)
40
40
  end
@@ -47,7 +47,7 @@ describe ScopedSearch::Definition do
47
47
  end
48
48
 
49
49
  it "should not create the named scope if it already exists" do
50
- @klass.stub!(:search_for)
50
+ @klass.stub(:search_for)
51
51
  @klass.should_not_receive(:scope)
52
52
  ScopedSearch::Definition.new(@klass)
53
53
  end
@@ -101,4 +101,8 @@ describe ScopedSearch::QueryLanguage::Parser do
101
101
  it "should parse a null? keyword" do
102
102
  'set? a b null? c'.should parse_to([:and, [:notnull, 'a'], 'b', [:null, 'c']])
103
103
  end
104
+
105
+ it "should refuse to parse an empty not expression" do
106
+ lambda { ScopedSearch::QueryLanguage::Compiler.parse('!()|*') }.should raise_error(ScopedSearch::QueryNotSupported)
107
+ end
104
108
  end
@@ -3,11 +3,11 @@ require "spec_helper"
3
3
  describe ScopedSearch::QueryBuilder do
4
4
 
5
5
  before(:each) do
6
- @definition = mock('ScopedSearch::Definition')
7
- @definition.stub!(:klass).and_return(Class.new(ActiveRecord::Base))
8
- @definition.stub!(:profile).and_return(:default)
9
- @definition.stub!(:default_order).and_return(nil)
10
- @definition.stub!(:profile=).and_return(true)
6
+ @definition = double('ScopedSearch::Definition')
7
+ @definition.stub(:klass).and_return(Class.new(ActiveRecord::Base))
8
+ @definition.stub(:profile).and_return(:default)
9
+ @definition.stub(:default_order).and_return(nil)
10
+ @definition.stub(:profile=).and_return(true)
11
11
  end
12
12
 
13
13
  it "should return empty conditions if the search query is nil" do
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoped_search
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 2.6.0
4
+ version: 2.6.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Amos Benari
@@ -11,56 +10,50 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-06-17 00:00:00.000000000 Z
13
+ date: 2013-12-17 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
- version_requirements: !ruby/object:Gem::Requirement
16
+ name: activerecord
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: 2.1.0
22
- none: false
23
- name: activerecord
24
22
  type: :runtime
25
23
  prerelease: false
26
- requirement: !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
27
25
  requirements:
28
26
  - - ! '>='
29
27
  - !ruby/object:Gem::Version
30
28
  version: 2.1.0
31
- none: false
32
29
  - !ruby/object:Gem::Dependency
33
- version_requirements: !ruby/object:Gem::Requirement
30
+ name: rspec
31
+ requirement: !ruby/object:Gem::Requirement
34
32
  requirements:
35
33
  - - ~>
36
34
  - !ruby/object:Gem::Version
37
35
  version: '2.0'
38
- none: false
39
- name: rspec
40
36
  type: :development
41
37
  prerelease: false
42
- requirement: !ruby/object:Gem::Requirement
38
+ version_requirements: !ruby/object:Gem::Requirement
43
39
  requirements:
44
40
  - - ~>
45
41
  - !ruby/object:Gem::Version
46
42
  version: '2.0'
47
- none: false
48
43
  - !ruby/object:Gem::Dependency
49
- version_requirements: !ruby/object:Gem::Requirement
44
+ name: rake
45
+ requirement: !ruby/object:Gem::Requirement
50
46
  requirements:
51
47
  - - ! '>='
52
48
  - !ruby/object:Gem::Version
53
49
  version: '0'
54
- none: false
55
- name: rake
56
50
  type: :development
57
51
  prerelease: false
58
- requirement: !ruby/object:Gem::Requirement
52
+ version_requirements: !ruby/object:Gem::Requirement
59
53
  requirements:
60
54
  - - ! '>='
61
55
  - !ruby/object:Gem::Version
62
56
  version: '0'
63
- none: false
64
57
  description: ! " Scoped search makes it easy to search your ActiveRecord-based
65
58
  models.\n \n It will create a named scope :search_for that can be called with
66
59
  a query string. It will build an SQL query using\n the provided query string
@@ -130,6 +123,7 @@ files:
130
123
  - spec/unit/tokenizer_spec.rb
131
124
  homepage: https://github.com/wvanbergen/scoped_search/wiki
132
125
  licenses: []
126
+ metadata: {}
133
127
  post_install_message:
134
128
  rdoc_options:
135
129
  - --title
@@ -145,18 +139,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
139
  - - ! '>='
146
140
  - !ruby/object:Gem::Version
147
141
  version: '0'
148
- none: false
149
142
  required_rubygems_version: !ruby/object:Gem::Requirement
150
143
  requirements:
151
144
  - - ! '>='
152
145
  - !ruby/object:Gem::Version
153
146
  version: '0'
154
- none: false
155
147
  requirements: []
156
148
  rubyforge_project:
157
- rubygems_version: 1.8.23
149
+ rubygems_version: 2.1.4
158
150
  signing_key:
159
- specification_version: 3
151
+ specification_version: 4
160
152
  summary: Easily search you ActiveRecord models with a simple query language using
161
153
  a named scope
162
154
  test_files:
@@ -180,3 +172,4 @@ test_files:
180
172
  - spec/unit/parser_spec.rb
181
173
  - spec/unit/query_builder_spec.rb
182
174
  - spec/unit/tokenizer_spec.rb
175
+ has_rdoc: