scoped_search 4.1.2 → 4.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31cbd8d30fd85c320926ca1ee4719f98e2860211
4
- data.tar.gz: c502bfc5ef2f14ad4aec19b253b6e9942d316236
3
+ metadata.gz: f8e71c1616716946f906c72f741b5e9b1950fdd8
4
+ data.tar.gz: d9386d5cc2fca4d418bc9a3d7a96d5b18601659b
5
5
  SHA512:
6
- metadata.gz: 018d005d707959d03cabee90cca7c17450e719fe0e6a32124d153e21f709980b7aae8f98be22a2620531d3c07ebacc32e8de8889ef13165e98de4c9162ef9cf0
7
- data.tar.gz: 4b6997024cb1e5ee01d3c7bc41a34b1ac31f77eae6e09ce885087645f5b530f264baeab5fd74c302ac7a42b38c45fc2740f81741ad03f6cc0ee39adda9cc89bd
6
+ metadata.gz: cc2400a7f26ef7f1bfed7273094a7cac04c5cb09b35509a4d2e3464b543f9f1413214c9100117d0d356620b9df8ed47fd504a0d5a208ec087ec5742f0d9c3afe
7
+ data.tar.gz: 3715276e0f495f13f1fd9158d6f4032c0a949682843e235e4b4dea8c035c33ad52de21427d894e1e4109f732299b5d5c8336e7cf9a6f20c70eeb2b29790ba580
@@ -8,6 +8,12 @@ Please add an entry to the "Unreleased changes" section in your pull requests.
8
8
 
9
9
  *Nothing yet*
10
10
 
11
+ === Version 4.1.3
12
+
13
+ - Bugfix related to default fields for sets when using ext_method (#174)
14
+ - Improved error reporting for exceptions raised in ext_method (#173)
15
+ - Bugfix related to validtions of values used with :in operator (#171)
16
+
11
17
  === Version 4.1.2
12
18
 
13
19
  - Bugfix related to using polymorphic relations introduced in 4.1.1 (#170)
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- gem 'actionview', '>= 5.1.0.beta1', '< 5.2'
5
- gem 'activerecord', '>= 5.1.0.beta1', '< 5.2'
4
+ gem 'actionview', '~> 5.1.0'
5
+ gem 'activerecord', '~> 5.1.0'
6
6
 
7
7
  platforms :jruby do
8
8
  gem 'activerecord-jdbcsqlite3-adapter'
@@ -251,7 +251,7 @@ module ScopedSearch
251
251
  column_types += [:integer] if value =~ INTEGER_REGXP
252
252
  column_types += [:datetime, :date, :timestamp] if (parse_temporal(value))
253
253
 
254
- default_fields.select { |field| column_types.include?(field.type) && !field.set? }
254
+ default_fields.select { |field| !field.set? && column_types.include?(field.type) }
255
255
  end
256
256
 
257
257
  # Try to parse a string as a datetime.
@@ -402,7 +402,11 @@ module ScopedSearch
402
402
 
403
403
  def to_ext_method_sql(key, operator, value, &block)
404
404
  raise ScopedSearch::QueryNotSupported, "'#{definition.klass}' doesn't respond to '#{ext_method}'" unless definition.klass.respond_to?(ext_method)
405
- conditions = definition.klass.send(ext_method.to_sym,key, operator, value) rescue {}
405
+ begin
406
+ conditions = definition.klass.send(ext_method.to_sym, key, operator, value)
407
+ rescue StandardError => e
408
+ raise ScopedSearch::QueryNotSupported, "external method '#{ext_method}' failed with error: #{e}"
409
+ end
406
410
  raise ScopedSearch::QueryNotSupported, "external method '#{ext_method}' should return hash" unless conditions.kind_of?(Hash)
407
411
  sql = ''
408
412
  conditions.map do |notification, content|
@@ -484,7 +488,11 @@ module ScopedSearch
484
488
  raise ScopedSearch::QueryNotSupported, "Field '#{lhs.value}' not recognized for searching!" unless field
485
489
 
486
490
  # see if the value passes user defined validation
487
- validate_value(field, rhs.value)
491
+ if operator == :in
492
+ rhs.value.split(',').each { |v| validate_value(field, v) }
493
+ else
494
+ validate_value(field, rhs.value)
495
+ end
488
496
 
489
497
  builder.sql_test(field, operator, rhs.value,lhs.value, &block)
490
498
  end
@@ -1,3 +1,3 @@
1
1
  module ScopedSearch
2
- VERSION = "4.1.2"
2
+ VERSION = "4.1.3"
3
3
  end
@@ -124,4 +124,11 @@ describe ScopedSearch::Definition do
124
124
  @subdefinition.fields.should eq(foo: field2, bar: field3)
125
125
  end
126
126
  end
127
+
128
+ describe '#default_fields_for' do
129
+ it "finds fields when there's a field not directly mapped to a DB column" do
130
+ @definition.define(:on => :custom_flag, :complete_value => { :true => true, :false => false }, :ext_method => :search_by_custom_flag)
131
+ @definition.default_fields_for("").should eq([])
132
+ end
133
+ end
127
134
  end
@@ -47,6 +47,22 @@ describe ScopedSearch::QueryBuilder do
47
47
  lambda { ScopedSearch::QueryBuilder.build_query(@definition, 'test_field = test_val') }.should raise_error(ScopedSearch::QueryNotSupported)
48
48
  end
49
49
 
50
+ it "should validate value if validator selected" do
51
+ field = double('field')
52
+ field.stub(:only_explicit).and_return(true)
53
+ field.stub(:field).and_return(:test_field)
54
+ field.stub(:ext_method).and_return(nil)
55
+ field.stub(:key_field).and_return(nil)
56
+ field.stub(:set?).and_return(false)
57
+ field.stub(:to_sql).and_return('')
58
+ field.stub(:validator).and_return(->(value) { value =~ /^\d+$/ })
59
+
60
+ @definition.stub(:field_by_name).and_return(field)
61
+
62
+ lambda { ScopedSearch::QueryBuilder.build_query(@definition, 'test_field ^ (1,2)') }.should_not raise_error
63
+ lambda { ScopedSearch::QueryBuilder.build_query(@definition, 'test_field ^ (1,a)') }.should raise_error(ScopedSearch::QueryNotSupported)
64
+ end
65
+
50
66
  it "should display custom error from validator" do
51
67
  field = double('field')
52
68
  field.stub(:only_explicit).and_return(true)
@@ -83,9 +99,9 @@ describe ScopedSearch::QueryBuilder do
83
99
  lambda { ScopedSearch::QueryBuilder.build_query(@definition, 'test_field = test_val') }.should raise_error(ScopedSearch::QueryNotSupported, /doesn't respond to 'ext_test'/)
84
100
  end
85
101
 
86
- it "should ignore exceptions" do
102
+ it "should raise error when method raises exception" do
87
103
  klass.should_receive(:ext_test).and_raise('test')
88
- ScopedSearch::QueryBuilder.build_query(@definition, 'test_field = test_val').should eq({})
104
+ lambda { ScopedSearch::QueryBuilder.build_query(@definition, 'test_field = test_val') }.should raise_error(ScopedSearch::QueryNotSupported, /failed with error: test/)
89
105
  end
90
106
  end
91
107
  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.2
4
+ version: 4.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amos Benari
@@ -10,48 +10,48 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-09-07 00:00:00.000000000 Z
13
+ date: 2018-03-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - '>='
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: 4.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - '>='
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: 4.2.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rspec
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ~>
33
+ - - "~>"
34
34
  - !ruby/object:Gem::Version
35
35
  version: '3.0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ~>
40
+ - - "~>"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '3.0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rake
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  description: |2
@@ -77,8 +77,8 @@ extra_rdoc_files:
77
77
  - CONTRIBUTING.rdoc
78
78
  - LICENSE
79
79
  files:
80
- - .gitignore
81
- - .travis.yml
80
+ - ".gitignore"
81
+ - ".travis.yml"
82
82
  - CHANGELOG.rdoc
83
83
  - CONTRIBUTING.rdoc
84
84
  - Gemfile
@@ -137,27 +137,27 @@ licenses:
137
137
  metadata: {}
138
138
  post_install_message:
139
139
  rdoc_options:
140
- - --title
140
+ - "--title"
141
141
  - scoped_search
142
- - --main
142
+ - "--main"
143
143
  - README.rdoc
144
- - --line-numbers
145
- - --inline-source
144
+ - "--line-numbers"
145
+ - "--inline-source"
146
146
  require_paths:
147
147
  - lib
148
148
  required_ruby_version: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - '>='
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
152
  version: 2.0.0
153
153
  required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - '>='
155
+ - - ">="
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
159
  rubyforge_project:
160
- rubygems_version: 2.0.14.1
160
+ rubygems_version: 2.6.8
161
161
  signing_key:
162
162
  specification_version: 4
163
163
  summary: Easily search you ActiveRecord models with a simple query language using