scoped_search 3.2.2 → 3.3.0

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: 3291810a245c631791ecafd20c61946c46f7edc1
4
- data.tar.gz: cb14f9b463fa22b0537f48fcda37ecdd836302bc
3
+ metadata.gz: 8d62827c492fb99894adbd0b01e0a1341c6744a5
4
+ data.tar.gz: 2ee3ede28bcd6b96e12ca1a7629b7cbef38aee4d
5
5
  SHA512:
6
- metadata.gz: 43d3a5b905d957079ea970b3f7e936fc453200811edd3017f257fc9f0d052cececffc7ea6e1a4a073ddc909df3b5d0d0b34393aea6c24aebefba69cb4e284f20
7
- data.tar.gz: 1fe059d3579a6c51bb3c29c977bd956dc0294c6993098bebb4712ece85854ddead8d7d294ff02fb63914db8020cb9e405a1e864ee4b6ee3776b40251b4aa15ea
6
+ metadata.gz: 9e26efdc791ad2fde5e975f44c8512a5089c4774f41f299e68f2c03fab3657323be4668e0668deb86f448dce2b02fe92b95d8d180cfff76b6f7dacd6e4bb01df
7
+ data.tar.gz: 206daf327aa65a9de4b2ac8ed049620b4df5c4b71330b846413c9140d0f83aed95f612db37d9154d624d2f8c3a54a8d9fd785e41a76fa9e223b0b4e9b81a7497
@@ -14,7 +14,8 @@ rvm:
14
14
  - "1.9"
15
15
  - "2.0"
16
16
  - "2.1"
17
- - "2.2"
17
+ - "2.2.2"
18
+ - "2.3.1"
18
19
  - ruby-head
19
20
  - jruby-19mode
20
21
  - jruby-head
@@ -24,9 +25,19 @@ gemfile:
24
25
  - Gemfile.activerecord40
25
26
  - Gemfile.activerecord41
26
27
  - Gemfile.activerecord42
28
+ - Gemfile.activerecord50
27
29
 
28
30
  matrix:
29
31
  allow_failures:
30
- - rvm: ruby-head
31
- - rvm: jruby-head
32
- - rvm: jruby-19mode
32
+ - rvm: ruby-head
33
+ - rvm: jruby-head
34
+ - rvm: jruby-19mode
35
+ exclude:
36
+ - rvm: "1.9"
37
+ gemfile: Gemfile.activerecord50
38
+ - rvm: "2.0"
39
+ gemfile: Gemfile.activerecord50
40
+ - rvm: "2.1"
41
+ gemfile: Gemfile.activerecord50
42
+ - rvm: "2.3.1"
43
+ gemfile: Gemfile.activerecord32
@@ -8,6 +8,10 @@ Please add an entry to the "Unreleased changes" section in your pull requests.
8
8
 
9
9
  *Nothing yet*
10
10
 
11
+ === Version 3.3.0
12
+
13
+ - Support for ActiveRecord 5.0
14
+
11
15
  === Version 3.2.0
12
16
 
13
17
  - In MySQL, case sensitivity is now determined by the collation of the column, and
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'activerecord', '5.0.0.rc1'
5
+
6
+ platforms :jruby do
7
+ gem 'activerecord-jdbcsqlite3-adapter'
8
+ gem 'activerecord-jdbcmysql-adapter'
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
11
+
12
+ platforms :ruby do
13
+ gem 'sqlite3'
14
+ gem 'mysql2', '~> 0.3.11'
15
+ gem 'pg'
16
+ end
@@ -178,10 +178,10 @@ module ScopedSearch
178
178
  .where(value_conditions(field_name, val))
179
179
  .select(field_name)
180
180
  .limit(20)
181
+ .uniq
181
182
  .map(&field.key_field)
182
183
  .compact
183
184
  .map { |f| "#{name}.#{f} " }
184
- .uniq
185
185
  end
186
186
 
187
187
  # this method auto-completes values of fields that have a :complete_value marker
@@ -205,10 +205,10 @@ module ScopedSearch
205
205
  .where(value_conditions(field.quoted_field, val))
206
206
  .select(field.quoted_field)
207
207
  .limit(20)
208
+ .uniq
208
209
  .map(&field.field)
209
210
  .compact
210
211
  .map { |v| v.to_s =~ /\s/ ? "\"#{v}\"" : v }
211
- .uniq
212
212
  end
213
213
 
214
214
  def completer_scope(field)
@@ -250,7 +250,19 @@ module ScopedSearch
250
250
  def register_named_scope! # :nodoc
251
251
  definition = self
252
252
  @klass.scope(:search_for, proc { |query, options|
253
- search_scope = ActiveRecord::VERSION::MAJOR == 3 ? @klass.scoped : (ActiveRecord::VERSION::MINOR < 1 ? @klass.where(nil) : @klass.all)
253
+ klass = definition.klass
254
+
255
+ search_scope = case ActiveRecord::VERSION::MAJOR
256
+ when 3
257
+ klass.scoped
258
+ when 4
259
+ (ActiveRecord::VERSION::MINOR < 1) ? klass.where(nil) : klass.all
260
+ when 5
261
+ klass.all
262
+ else
263
+ raise ScopedSearch::DefinitionError, 'version ' \
264
+ "#{ActiveRecord::VERSION::MAJOR} of activerecord is not supported"
265
+ end
254
266
 
255
267
  find_options = ScopedSearch::QueryBuilder.build_query(definition, query || '', options || {})
256
268
  search_scope = search_scope.where(find_options[:conditions]) if find_options[:conditions]
@@ -28,9 +28,12 @@ module ScopedSearch
28
28
  # Loads the QueryBuilder class for the connection of the given definition.
29
29
  # If no specific adapter is found, the default QueryBuilder class is returned.
30
30
  def self.class_for(definition)
31
- self.const_get(definition.klass.connection.class.name.split('::').last)
32
- rescue
33
- self
31
+ case definition.klass.connection.class.name.split('::').last
32
+ when /postgresql/i
33
+ PostgreSQLAdapter
34
+ else
35
+ self
36
+ end
34
37
  end
35
38
 
36
39
  # Initializes the instance by setting the relevant parameters
@@ -1,3 +1,3 @@
1
1
  module ScopedSearch
2
- VERSION = "3.2.2"
2
+ VERSION = "3.3.0"
3
3
  end
@@ -52,6 +52,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
52
52
  @foo_1 = Foo.create!(:string => 'foo', :another => 'temp 1', :explicit => 'baz', :int => 9 , :date => 'February 8, 2011' , :unindexed => 10)
53
53
  Foo.create!(:string => 'bar', :another => 'temp 2', :explicit => 'baz', :int => 22 , :date => 'February 10, 2011', :unindexed => 10)
54
54
  Foo.create!(:string => 'baz', :another => nil, :explicit => nil , :int => nil, :date => nil , :unindexed => nil)
55
+ 20.times { Foo.create!(:explicit => "aaa") }
55
56
 
56
57
  Bar.create!(:related => 'lala', :foo => @foo_1)
57
58
  Bar.create!(:related => 'another lala', :foo => @foo_1)
@@ -136,7 +137,7 @@ ScopedSearch::RSpec::Database.test_databases.each do |db|
136
137
 
137
138
  context 'value auto complete' do
138
139
  it "should complete values list of values " do
139
- Foo.complete_for('explicit = ').length.should == 1
140
+ Foo.complete_for('explicit = ').length.should == 2
140
141
  end
141
142
 
142
143
  it "should complete values should contain baz" do
@@ -8,6 +8,7 @@ describe ScopedSearch::QueryBuilder do
8
8
  @definition.stub(:profile).and_return(:default)
9
9
  @definition.stub(:default_order).and_return(nil)
10
10
  @definition.stub(:profile=).and_return(true)
11
+ @definition.klass.stub(:connection).and_return(double())
11
12
  end
12
13
 
13
14
  it "should raise an ArgumentError if the query is not set" do
@@ -22,4 +23,14 @@ describe ScopedSearch::QueryBuilder do
22
23
  ScopedSearch::QueryBuilder.build_query(@definition, "\t ").should == { }
23
24
  end
24
25
 
26
+ it "should use default adapter when connection type is unknown" do
27
+ ScopedSearch::QueryBuilder.class_for(@definition).should == ScopedSearch::QueryBuilder
28
+ end
29
+
30
+ it "should use postgres adapter for postgres-like connection" do
31
+ connection = double()
32
+ connection.stub("name").and_return("SomePostgreSQLAdapter")
33
+ @definition.klass.connection.stub("class").and_return(connection)
34
+ ScopedSearch::QueryBuilder.class_for(@definition).should == ScopedSearch::QueryBuilder::PostgreSQLAdapter
35
+ end
25
36
  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: 3.2.2
4
+ version: 3.3.0
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: 2015-07-28 00:00:00.000000000 Z
13
+ date: 2016-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -86,6 +86,7 @@ files:
86
86
  - Gemfile.activerecord40
87
87
  - Gemfile.activerecord41
88
88
  - Gemfile.activerecord42
89
+ - Gemfile.activerecord50
89
90
  - LICENSE
90
91
  - README.rdoc
91
92
  - Rakefile
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  version: '0'
154
155
  requirements: []
155
156
  rubyforge_project:
156
- rubygems_version: 2.0.14
157
+ rubygems_version: 2.0.14.1
157
158
  signing_key:
158
159
  specification_version: 4
159
160
  summary: Easily search you ActiveRecord models with a simple query language using