pg_search 1.0.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ describe PgSearch::Features::Trigram do
12
12
  ]
13
13
  }
14
14
  let(:normalizer) { PgSearch::Normalizer.new(config) }
15
- let(:config) { OpenStruct.new(:ignore => [], :postgresql_version => 90000) }
15
+ let(:config) { OpenStruct.new(:ignore => []) }
16
16
 
17
17
  let(:coalesced_columns) do
18
18
  <<-SQL.strip_heredoc.chomp
@@ -1,5 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
+ def has_microsecond_precision?
4
+ (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 1) ||
5
+ (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0 && ActiveRecord::VERSION::TINY >= 1)
6
+ end
7
+
3
8
  describe PgSearch::Multisearch::Rebuilder do
4
9
  with_table "pg_search_documents", {}, &DOCUMENTS_SCHEMA
5
10
 
@@ -96,22 +101,11 @@ describe PgSearch::Multisearch::Rebuilder do
96
101
 
97
102
  it "should execute the default SQL" do
98
103
  time = DateTime.parse("2001-01-01")
99
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model, ->{ time } )
104
+ rebuilder = PgSearch::Multisearch::Rebuilder.new(Model, -> { time })
100
105
 
101
106
  # Handle change in precision of DateTime objects in SQL in Active Record 4.0.1
102
107
  # https://github.com/rails/rails/commit/17f5d8e062909f1fcae25351834d8e89967b645e
103
- version_4_0_1_or_newer = (
104
- (ActiveRecord::VERSION::MAJOR > 4) ||
105
- (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 1) ||
106
- (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0 && ActiveRecord::VERSION::TINY >= 1)
107
- )
108
-
109
- expected_timestamp =
110
- if version_4_0_1_or_newer
111
- "2001-01-01 00:00:00.000000"
112
- else
113
- "2001-01-01 00:00:00"
114
- end
108
+ expected_timestamp = has_microsecond_precision? ? "2001-01-01 00:00:00.000000" : "2001-01-01 00:00:00"
115
109
 
116
110
  expected_sql = <<-SQL.strip_heredoc
117
111
  INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
@@ -152,22 +146,11 @@ describe PgSearch::Multisearch::Rebuilder do
152
146
 
153
147
  it "generates SQL with the correct primary key" do
154
148
  time = DateTime.parse("2001-01-01")
155
- rebuilder = PgSearch::Multisearch::Rebuilder.new(ModelWithNonStandardPrimaryKey, ->{ time } )
149
+ rebuilder = PgSearch::Multisearch::Rebuilder.new(ModelWithNonStandardPrimaryKey, -> { time })
156
150
 
157
151
  # Handle change in precision of DateTime objects in SQL in Active Record 4.0.1
158
152
  # https://github.com/rails/rails/commit/17f5d8e062909f1fcae25351834d8e89967b645e
159
- version_4_0_1_or_newer = (
160
- (ActiveRecord::VERSION::MAJOR > 4) ||
161
- (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR >= 1) ||
162
- (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0 && ActiveRecord::VERSION::TINY >= 1)
163
- )
164
-
165
- expected_timestamp =
166
- if version_4_0_1_or_newer
167
- "2001-01-01 00:00:00.000000"
168
- else
169
- "2001-01-01 00:00:00"
170
- end
153
+ expected_timestamp = has_microsecond_precision? ? "2001-01-01 00:00:00.000000" : "2001-01-01 00:00:00"
171
154
 
172
155
  expected_sql = <<-SQL.strip_heredoc
173
156
  INSERT INTO "pg_search_documents" (searchable_type, searchable_id, content, created_at, updated_at)
@@ -248,8 +231,8 @@ describe PgSearch::Multisearch::Rebuilder do
248
231
  end
249
232
 
250
233
  it "calls update_pg_search_document on each record" do
251
- record1 = Model.create!(:active => true)
252
- record2 = Model.create!(:active => false)
234
+ record_1 = Model.create!(:active => true)
235
+ record_2 = Model.create!(:active => false)
253
236
 
254
237
  rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
255
238
 
@@ -266,8 +249,8 @@ describe PgSearch::Multisearch::Rebuilder do
266
249
 
267
250
  rebuilder.rebuild
268
251
 
269
- expect(record1.pg_search_document).to be_present
270
- expect(record2.pg_search_document).not_to be_present
252
+ expect(record_1.pg_search_document).to be_present
253
+ expect(record_2.pg_search_document).not_to be_present
271
254
  end
272
255
  end
273
256
 
@@ -284,8 +267,8 @@ describe PgSearch::Multisearch::Rebuilder do
284
267
  end
285
268
 
286
269
  it "calls update_pg_search_document on each record" do
287
- record1 = Model.create!(:inactive => true)
288
- record2 = Model.create!(:inactive => false)
270
+ record_1 = Model.create!(:inactive => true)
271
+ record_2 = Model.create!(:inactive => false)
289
272
 
290
273
  rebuilder = PgSearch::Multisearch::Rebuilder.new(Model)
291
274
 
@@ -302,8 +285,8 @@ describe PgSearch::Multisearch::Rebuilder do
302
285
 
303
286
  rebuilder.rebuild
304
287
 
305
- expect(record1.pg_search_document).not_to be_present
306
- expect(record2.pg_search_document).to be_present
288
+ expect(record_1.pg_search_document).not_to be_present
289
+ expect(record_2.pg_search_document).to be_present
307
290
  end
308
291
  end
309
292
  end
@@ -2,80 +2,56 @@ require "spec_helper"
2
2
 
3
3
  describe PgSearch::Normalizer do
4
4
  describe "#add_normalization" do
5
- context "for PostgreSQL 9.0 and above" do
6
- context "when config[:ignore] includes :accents" do
7
- context "when passed an Arel node" do
8
- it "wraps the expression in unaccent()" do
9
- config = double("config", :ignore => [:accents], :postgresql_version => 90000)
10
- node = Arel::Nodes::NamedFunction.new("foo", [PgSearch::Compatibility.build_quoted("bar")])
5
+ context "when config[:ignore] includes :accents" do
6
+ context "when passed an Arel node" do
7
+ it "wraps the expression in unaccent()" do
8
+ config = double("config", :ignore => [:accents])
9
+ node = Arel::Nodes::NamedFunction.new("foo", [Arel::Nodes.build_quoted("bar")])
11
10
 
12
- normalizer = PgSearch::Normalizer.new(config)
13
- expect(normalizer.add_normalization(node)).to eq("unaccent(foo('bar'))")
14
- end
15
-
16
- context "when a custom unaccent function is specified" do
17
- it "wraps the expression in that function" do
18
- allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
19
- node = Arel::Nodes::NamedFunction.new("foo", [PgSearch::Compatibility.build_quoted("bar")])
20
-
21
- config = double("config", :ignore => [:accents], :postgresql_version => 90000)
22
-
23
- normalizer = PgSearch::Normalizer.new(config)
24
- expect(normalizer.add_normalization(node)).to eq("my_unaccent(foo('bar'))")
25
- end
26
- end
11
+ normalizer = PgSearch::Normalizer.new(config)
12
+ expect(normalizer.add_normalization(node)).to eq("unaccent(foo('bar'))")
27
13
  end
28
14
 
29
- context "when passed a String" do
30
- it "wraps the expression in unaccent()" do
31
- config = double("config", :ignore => [:accents], :postgresql_version => 90000)
32
-
33
- normalizer = PgSearch::Normalizer.new(config)
34
- expect(normalizer.add_normalization("foo")).to eq("unaccent(foo)")
35
- end
36
-
37
- context "when a custom unaccent function is specified" do
38
- it "wraps the expression in that function" do
39
- allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
15
+ context "when a custom unaccent function is specified" do
16
+ it "wraps the expression in that function" do
17
+ allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
18
+ node = Arel::Nodes::NamedFunction.new("foo", [Arel::Nodes.build_quoted("bar")])
40
19
 
41
- config = double("config", :ignore => [:accents], :postgresql_version => 90000)
20
+ config = double("config", :ignore => [:accents])
42
21
 
43
- normalizer = PgSearch::Normalizer.new(config)
44
- expect(normalizer.add_normalization("foo")).to eq("my_unaccent(foo)")
45
- end
22
+ normalizer = PgSearch::Normalizer.new(config)
23
+ expect(normalizer.add_normalization(node)).to eq("my_unaccent(foo('bar'))")
46
24
  end
47
25
  end
48
26
  end
49
27
 
50
- context "when config[:ignore] does not include :accents" do
51
- it "passes the expression through" do
52
- config = double("config", :ignore => [], :postgresql_version => 90000)
28
+ context "when passed a String" do
29
+ it "wraps the expression in unaccent()" do
30
+ config = double("config", :ignore => [:accents])
53
31
 
54
32
  normalizer = PgSearch::Normalizer.new(config)
55
- expect(normalizer.add_normalization("foo")).to eq("foo")
33
+ expect(normalizer.add_normalization("foo")).to eq("unaccent(foo)")
56
34
  end
57
- end
58
- end
59
35
 
60
- context "for PostgreSQL versions before 9.0" do
61
- context "when config[:ignore] includes :accents" do
62
- it "raises a NotSupportedForPostgresqlVersion exception" do
63
- config = double("config", :ignore => [:accents], :postgresql_version => 89999)
36
+ context "when a custom unaccent function is specified" do
37
+ it "wraps the expression in that function" do
38
+ allow(PgSearch).to receive(:unaccent_function).and_return("my_unaccent")
64
39
 
65
- normalizer = PgSearch::Normalizer.new(config)
66
- expect {
67
- normalizer.add_normalization("foo")
68
- }.to raise_exception(PgSearch::NotSupportedForPostgresqlVersion)
40
+ config = double("config", :ignore => [:accents])
41
+
42
+ normalizer = PgSearch::Normalizer.new(config)
43
+ expect(normalizer.add_normalization("foo")).to eq("my_unaccent(foo)")
44
+ end
69
45
  end
70
46
  end
47
+ end
71
48
 
72
- context "when config[:ignore] does not include :accents" do
73
- it "passes the expression through" do
74
- config = double("config", :ignore => [], :postgresql_version => 90000)
49
+ context "when config[:ignore] does not include :accents" do
50
+ it "passes the expression through" do
51
+ config = double("config", :ignore => [])
75
52
 
76
- normalizer = PgSearch::Normalizer.new(config)
77
- expect(normalizer.add_normalization("foo")).to eq("foo")
78
- end
53
+ normalizer = PgSearch::Normalizer.new(config)
54
+ expect(normalizer.add_normalization("foo")).to eq("foo")
79
55
  end
80
56
  end
81
57
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
1
+ require 'simplecov'
2
+ SimpleCov.start
3
3
 
4
4
  require "bundler/setup"
5
5
  require "pg_search"
@@ -1,5 +1,5 @@
1
1
  if defined? JRUBY_VERSION
2
- require 'activerecord-jdbcpostgresql-adapter'
2
+ require "activerecord-jdbc-adapter"
3
3
  error_classes = [ActiveRecord::JDBCError]
4
4
  else
5
5
  require "pg"
@@ -15,14 +15,13 @@ begin
15
15
  ENV["USER"]
16
16
  end
17
17
 
18
- ActiveRecord::Base.establish_connection(:adapter => 'postgresql',
18
+ ActiveRecord::Base.establish_connection(:adapter => 'postgresql',
19
19
  :database => 'pg_search_test',
20
20
  :username => database_user,
21
21
  :min_messages => 'warning')
22
22
  connection = ActiveRecord::Base.connection
23
- postgresql_version = connection.send(:postgresql_version)
24
23
  connection.execute("SELECT 1")
25
- rescue *error_classes
24
+ rescue *error_classes => exception
26
25
  at_exit do
27
26
  puts "-" * 80
28
27
  puts "Unable to connect to database. Please run:"
@@ -30,7 +29,7 @@ rescue *error_classes
30
29
  puts " createdb pg_search_test"
31
30
  puts "-" * 80
32
31
  end
33
- raise $ERROR_INFO
32
+ raise exception
34
33
  end
35
34
 
36
35
  if ENV["LOGGER"]
@@ -38,34 +37,29 @@ if ENV["LOGGER"]
38
37
  ActiveRecord::Base.logger = Logger.new(STDOUT)
39
38
  end
40
39
 
41
- def install_extension_if_missing(name, query, expected_result) # rubocop:disable Metrics/AbcSize
40
+ def install_extension(name)
42
41
  connection = ActiveRecord::Base.connection
43
- postgresql_version = connection.send(:postgresql_version)
44
- result = connection.select_value(query)
42
+ extension = connection.execute "SELECT * FROM pg_catalog.pg_extension WHERE extname = '#{name}';"
43
+ return unless extension.none?
44
+ connection.execute "CREATE EXTENSION #{name};"
45
+ rescue => exception
46
+ at_exit do
47
+ puts "-" * 80
48
+ puts "Please install the #{name} extension"
49
+ puts "-" * 80
50
+ end
51
+ raise exception
52
+ end
53
+
54
+ def install_extension_if_missing(name, query, expected_result)
55
+ result = ActiveRecord::Base.connection.select_value(query)
45
56
  raise "Unexpected output for #{query}: #{result.inspect}" unless result.downcase == expected_result.downcase
46
57
  rescue
47
- begin
48
- if postgresql_version >= 90100
49
- ActiveRecord::Base.connection.execute "CREATE EXTENSION #{name};"
50
- else
51
- share_path = `pg_config --sharedir`.strip
52
- ActiveRecord::Base.connection.execute File.read(File.join(share_path, 'contrib', "#{name}.sql"))
53
- puts $ERROR_INFO.message
54
- end
55
- rescue => exception
56
- at_exit do
57
- puts "-" * 80
58
- puts "Please install the #{name} contrib module"
59
- puts "-" * 80
60
- end
61
- raise exception
62
- end
58
+ install_extension(name)
63
59
  end
64
60
 
65
61
  install_extension_if_missing("pg_trgm", "SELECT 'abcdef' % 'cdef'", "t")
66
- unless postgresql_version < 90000
67
- install_extension_if_missing("unaccent", "SELECT unaccent('foo')", "foo")
68
- end
62
+ install_extension_if_missing("unaccent", "SELECT unaccent('foo')", "foo")
69
63
  install_extension_if_missing("fuzzystrmatch", "SELECT dmetaphone('foo')", "f")
70
64
 
71
65
  def load_sql(filename)
@@ -74,10 +68,4 @@ def load_sql(filename)
74
68
  connection.execute(file_contents)
75
69
  end
76
70
 
77
- if postgresql_version < 80400
78
- unless connection.select_value("SELECT 1 FROM pg_catalog.pg_aggregate WHERE aggfnoid = 'array_agg'::REGPROC") == "1"
79
- load_sql("array_agg.sql")
80
- end
81
- load_sql("unnest.sql")
82
- end
83
71
  load_sql("dmetaphone.sql")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Hutchins
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-22 00:00:00.000000000 Z
12
+ date: 2016-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,42 +17,42 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '3.1'
20
+ version: '4.2'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '3.1'
27
+ version: '4.2'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '3.1'
34
+ version: '4.2'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '3.1'
41
+ version: '4.2'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: arel
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - ">="
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '6'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '6'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rake
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,34 @@ dependencies:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0.36'
126
+ - !ruby/object:Gem::Dependency
127
+ name: codeclimate-test-reporter
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: simplecov
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
126
154
  description: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's
127
155
  full text search
128
156
  email:
@@ -148,23 +176,19 @@ files:
148
176
  - README.md
149
177
  - Rakefile
150
178
  - lib/pg_search.rb
151
- - lib/pg_search/compatibility.rb
152
179
  - lib/pg_search/configuration.rb
153
180
  - lib/pg_search/configuration/association.rb
154
181
  - lib/pg_search/configuration/column.rb
155
182
  - lib/pg_search/configuration/foreign_column.rb
156
183
  - lib/pg_search/document.rb
157
- - lib/pg_search/extensions/arel.rb
158
184
  - lib/pg_search/features.rb
159
185
  - lib/pg_search/features/dmetaphone.rb
160
186
  - lib/pg_search/features/feature.rb
161
187
  - lib/pg_search/features/trigram.rb
162
188
  - lib/pg_search/features/tsearch.rb
163
- - lib/pg_search/migration/associated_against_generator.rb
164
189
  - lib/pg_search/migration/dmetaphone_generator.rb
165
190
  - lib/pg_search/migration/generator.rb
166
191
  - lib/pg_search/migration/multisearch_generator.rb
167
- - lib/pg_search/migration/templates/add_pg_search_associated_against_support_functions.rb.erb
168
192
  - lib/pg_search/migration/templates/add_pg_search_dmetaphone_support_functions.rb.erb
169
193
  - lib/pg_search/migration/templates/create_pg_search_documents.rb.erb
170
194
  - lib/pg_search/multisearch.rb
@@ -195,12 +219,8 @@ files:
195
219
  - spec/spec_helper.rb
196
220
  - spec/support/database.rb
197
221
  - spec/support/with_model.rb
198
- - sql/array_agg.sql
199
222
  - sql/dmetaphone.sql
200
- - sql/uninstall_array_agg.sql
201
223
  - sql/uninstall_dmetaphone.sql
202
- - sql/uninstall_unnest.sql
203
- - sql/unnest.sql
204
224
  homepage: https://github.com/Casecommons/pg_search
205
225
  licenses:
206
226
  - MIT
@@ -213,7 +233,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
233
  requirements:
214
234
  - - ">="
215
235
  - !ruby/object:Gem::Version
216
- version: 1.9.2
236
+ version: '2.1'
217
237
  required_rubygems_version: !ruby/object:Gem::Requirement
218
238
  requirements:
219
239
  - - ">="
@@ -221,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
241
  version: '0'
222
242
  requirements: []
223
243
  rubyforge_project:
224
- rubygems_version: 2.5.1
244
+ rubygems_version: 2.5.2
225
245
  signing_key:
226
246
  specification_version: 4
227
247
  summary: PgSearch builds Active Record named scopes that take advantage of PostgreSQL's