pg_search 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ describe PgSearch::Configuration::Column do
10
10
 
11
11
  it "returns the fully-qualified table and column name" do
12
12
  column = described_class.new("name", nil, Model)
13
- expect(column.full_name).to eq(%Q{#{Model.quoted_table_name}."name"})
13
+ expect(column.full_name).to eq(%(#{Model.quoted_table_name}."name"))
14
14
  end
15
15
  end
16
16
 
@@ -23,7 +23,7 @@ describe PgSearch::Configuration::Column do
23
23
 
24
24
  it "returns an expression that casts the column to text and coalesces it with an empty string" do
25
25
  column = described_class.new("name", nil, Model)
26
- expect(column.to_sql).to eq(%Q{coalesce(#{Model.quoted_table_name}."name"::text, '')})
26
+ expect(column.to_sql).to eq(%{coalesce(#{Model.quoted_table_name}."name"::text, '')})
27
27
  end
28
28
  end
29
29
  end
@@ -24,8 +24,8 @@ describe PgSearch::Configuration::ForeignColumn do
24
24
 
25
25
  it "returns a consistent string" do
26
26
  association = PgSearch::Configuration::Association.new(Model,
27
- :another_model,
28
- :title)
27
+ :another_model,
28
+ :title)
29
29
  foreign_column = described_class.new("title", nil, Model, association)
30
30
 
31
31
  column_alias = foreign_column.alias
@@ -21,7 +21,7 @@ describe PgSearch::Features::DMetaphone do
21
21
 
22
22
  feature = described_class.new(query, options, columns, Model, normalizer)
23
23
  expect(feature.rank.to_sql).to eq(
24
- %Q{(ts_rank((to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."name"::text, ''))) || to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."content"::text, '')))), (to_tsquery('simple', ''' ' || pg_search_dmetaphone('query') || ' ''')), 0))}
24
+ %{(ts_rank((to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."name"::text, ''))) || to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."content"::text, '')))), (to_tsquery('simple', ''' ' || pg_search_dmetaphone('query') || ' ''')), 0))}
25
25
  )
26
26
  end
27
27
  end
@@ -46,7 +46,7 @@ describe PgSearch::Features::DMetaphone do
46
46
 
47
47
  feature = described_class.new(query, options, columns, Model, normalizer)
48
48
  expect(feature.conditions.to_sql).to eq(
49
- %Q{((to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."name"::text, ''))) || to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."content"::text, '')))) @@ (to_tsquery('simple', ''' ' || pg_search_dmetaphone('query') || ' ''')))}
49
+ %{((to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."name"::text, ''))) || to_tsvector('simple', pg_search_dmetaphone(coalesce(#{Model.quoted_table_name}."content"::text, '')))) @@ (to_tsquery('simple', ''' ' || pg_search_dmetaphone('query') || ' ''')))}
50
50
  )
51
51
  end
52
52
  end
@@ -5,10 +5,12 @@ describe PgSearch::Features::Trigram do
5
5
  subject(:feature) { described_class.new(query, options, columns, Model, normalizer) }
6
6
  let(:query) { 'lolwut' }
7
7
  let(:options) { {} }
8
- let(:columns) {[
9
- PgSearch::Configuration::Column.new(:name, nil, Model),
10
- PgSearch::Configuration::Column.new(:content, nil, Model)
11
- ]}
8
+ let(:columns) {
9
+ [
10
+ PgSearch::Configuration::Column.new(:name, nil, Model),
11
+ PgSearch::Configuration::Column.new(:content, nil, Model)
12
+ ]
13
+ }
12
14
  let(:normalizer) { PgSearch::Normalizer.new(config) }
13
15
  let(:config) { OpenStruct.new(:ignore => [], :postgresql_version => 90000) }
14
16
 
@@ -59,7 +61,6 @@ describe PgSearch::Features::Trigram do
59
61
  coalesced_column = "coalesce(#{Model.quoted_table_name}.\"name\"::text, '')"
60
62
  expect(feature.conditions.to_sql).to eq("((#{coalesced_column}) % '#{query}')")
61
63
  end
62
-
63
64
  end
64
65
  context 'multiple columns' do
65
66
  let(:options) { { only: [:name, :content] } }
@@ -70,7 +71,6 @@ describe PgSearch::Features::Trigram do
70
71
  end
71
72
  end
72
73
  end
73
-
74
74
  end
75
75
 
76
76
  describe '#rank' do
@@ -21,7 +21,7 @@ describe PgSearch::Features::TSearch do
21
21
 
22
22
  feature = described_class.new(query, options, columns, Model, normalizer)
23
23
  expect(feature.rank.to_sql).to eq(
24
- %Q{(ts_rank((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))), (to_tsquery('simple', ''' ' || 'query' || ' ''')), 0))}
24
+ %{(ts_rank((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))), (to_tsquery('simple', ''' ' || 'query' || ' ''')), 0))}
25
25
  )
26
26
  end
27
27
  end
@@ -46,7 +46,7 @@ describe PgSearch::Features::TSearch do
46
46
 
47
47
  feature = described_class.new(query, options, columns, Model, normalizer)
48
48
  expect(feature.conditions.to_sql).to eq(
49
- %Q{((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'query' || ' ''')))}
49
+ %{((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || 'query' || ' ''')))}
50
50
  )
51
51
  end
52
52
 
@@ -63,7 +63,7 @@ describe PgSearch::Features::TSearch do
63
63
 
64
64
  feature = described_class.new(query, options, columns, Model, normalizer)
65
65
  expect(feature.conditions.to_sql).to eq(
66
- %Q{((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', '!' || ''' ' || 'query' || ' ''')))}
66
+ %{((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', '!' || ''' ' || 'query' || ' ''')))}
67
67
  )
68
68
  end
69
69
  end
@@ -81,7 +81,7 @@ describe PgSearch::Features::TSearch do
81
81
 
82
82
  feature = described_class.new(query, options, columns, Model, normalizer)
83
83
  expect(feature.conditions.to_sql).to eq(
84
- %Q{((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || '!query' || ' ''')))}
84
+ %{((to_tsvector('simple', coalesce(#{Model.quoted_table_name}."name"::text, '')) || to_tsvector('simple', coalesce(#{Model.quoted_table_name}."content"::text, ''))) @@ (to_tsquery('simple', ''' ' || '!query' || ' ''')))}
85
85
  )
86
86
  end
87
87
  end
@@ -99,7 +99,7 @@ describe PgSearch::Features::TSearch do
99
99
 
100
100
  feature = described_class.new(query, options, columns, Model, normalizer)
101
101
  expect(feature.conditions.to_sql).to eq(
102
- %Q{((#{Model.quoted_table_name}.\"my_tsvector\") @@ (to_tsquery('simple', ''' ' || 'query' || ' ''')))}
102
+ %{((#{Model.quoted_table_name}.\"my_tsvector\") @@ (to_tsquery('simple', ''' ' || 'query' || ' ''')))}
103
103
  )
104
104
  end
105
105
  end
@@ -117,7 +117,7 @@ describe PgSearch::Features::TSearch do
117
117
 
118
118
  feature = described_class.new(query, options, columns, Model, normalizer)
119
119
  expect(feature.conditions.to_sql).to eq(
120
- %Q{((#{Model.quoted_table_name}.\"tsvector1\" || #{Model.quoted_table_name}.\"tsvector2\") @@ (to_tsquery('simple', ''' ' || 'query' || ' ''')))}
120
+ %{((#{Model.quoted_table_name}.\"tsvector1\" || #{Model.quoted_table_name}.\"tsvector2\") @@ (to_tsquery('simple', ''' ' || 'query' || ' ''')))}
121
121
  )
122
122
  end
123
123
  end
@@ -83,7 +83,7 @@ describe PgSearch::Multisearch::Rebuilder do
83
83
 
84
84
  it "should execute the default SQL" do
85
85
  time = DateTime.parse("2001-01-01")
86
- rebuilder = PgSearch::Multisearch::Rebuilder.new(Model, lambda { time } )
86
+ rebuilder = PgSearch::Multisearch::Rebuilder.new(Model, ->{ time } )
87
87
 
88
88
  # Handle change in precision of DateTime objects in SQL in Active Record 4.0.1
89
89
  # https://github.com/rails/rails/commit/17f5d8e062909f1fcae25351834d8e89967b645e
@@ -114,8 +114,8 @@ describe PgSearch::Multisearch::Rebuilder do
114
114
 
115
115
  executed_sql = []
116
116
 
117
- notifier = ActiveSupport::Notifications.subscribe("sql.active_record") do |name, start, finish, id, payload|
118
- executed_sql << payload[:sql] if payload[:sql].include?(%Q{INSERT INTO "pg_search_documents"})
117
+ notifier = ActiveSupport::Notifications.subscribe("sql.active_record") do |_name, _start, _finish, _id, payload|
118
+ executed_sql << payload[:sql] if payload[:sql].include?(%(INSERT INTO "pg_search_documents"))
119
119
  end
120
120
 
121
121
  rebuilder.rebuild
@@ -139,7 +139,7 @@ describe PgSearch::Multisearch::Rebuilder do
139
139
 
140
140
  it "generates SQL with the correct primary key" do
141
141
  time = DateTime.parse("2001-01-01")
142
- rebuilder = PgSearch::Multisearch::Rebuilder.new(ModelWithNonStandardPrimaryKey, lambda { time } )
142
+ rebuilder = PgSearch::Multisearch::Rebuilder.new(ModelWithNonStandardPrimaryKey, ->{ time } )
143
143
 
144
144
  # Handle change in precision of DateTime objects in SQL in Active Record 4.0.1
145
145
  # https://github.com/rails/rails/commit/17f5d8e062909f1fcae25351834d8e89967b645e
@@ -170,8 +170,8 @@ describe PgSearch::Multisearch::Rebuilder do
170
170
 
171
171
  executed_sql = []
172
172
 
173
- notifier = ActiveSupport::Notifications.subscribe("sql.active_record") do |name, start, finish, id, payload|
174
- executed_sql << payload[:sql] if payload[:sql].include?(%Q{INSERT INTO "pg_search_documents"})
173
+ notifier = ActiveSupport::Notifications.subscribe("sql.active_record") do |_name, _start, _finish, _id, payload|
174
+ executed_sql << payload[:sql] if payload[:sql].include?(%(INSERT INTO "pg_search_documents"))
175
175
  end
176
176
 
177
177
  rebuilder.rebuild
@@ -105,7 +105,7 @@ describe PgSearch::Multisearchable do
105
105
 
106
106
  model do
107
107
  include PgSearch
108
- multisearchable :if => lambda { |record| record.multisearchable? }
108
+ multisearchable :if => ->(record) { record.multisearchable? }
109
109
  end
110
110
  end
111
111
 
@@ -233,7 +233,7 @@ describe PgSearch::Multisearchable do
233
233
 
234
234
  model do
235
235
  include PgSearch
236
- multisearchable :unless => lambda { |record| record.not_multisearchable? }
236
+ multisearchable :unless => ->(record) { record.not_multisearchable? }
237
237
  end
238
238
  end
239
239
 
@@ -309,7 +309,6 @@ describe PgSearch::Multisearchable do
309
309
  expect { PgSearch::Document.find(document.id) }.to raise_error(ActiveRecord::RecordNotFound)
310
310
  end
311
311
  end
312
-
313
312
  end
314
313
  end
315
314
 
@@ -17,7 +17,7 @@ describe PgSearch do
17
17
  end
18
18
 
19
19
  context "with PgSearch.multisearch_options set to a Hash" do
20
- before { allow(PgSearch).to receive(:multisearch_options).and_return({:using => :dmetaphone}) }
20
+ before { allow(PgSearch).to receive(:multisearch_options).and_return(:using => :dmetaphone) }
21
21
  subject { PgSearch.multisearch(query).map(&:searchable) }
22
22
 
23
23
  with_model :MultisearchableModel do
@@ -94,16 +94,13 @@ describe PgSearch do
94
94
  end
95
95
 
96
96
  it "returns only results for that subclass" do
97
- included = [
98
- SearchableSubclassModel.create!(:content => "foo bar")
99
- ]
100
- excluded = [
101
- SearchableSubclassModel.create!(:content => "baz"),
102
- SuperclassModel.create!(:content => "foo bar"),
103
- SuperclassModel.create!(:content => "baz"),
104
- NonSearchableSubclassModel.create!(:content => "foo bar"),
105
- NonSearchableSubclassModel.create!(:content => "baz")
106
- ]
97
+ included = SearchableSubclassModel.create!(:content => "foo bar")
98
+
99
+ SearchableSubclassModel.create!(:content => "baz")
100
+ SuperclassModel.create!(:content => "foo bar")
101
+ SuperclassModel.create!(:content => "baz")
102
+ NonSearchableSubclassModel.create!(:content => "foo bar")
103
+ NonSearchableSubclassModel.create!(:content => "baz")
107
104
 
108
105
  expect(SuperclassModel.count).to be 6
109
106
  expect(SearchableSubclassModel.count).to be 2
@@ -112,9 +109,7 @@ describe PgSearch do
112
109
 
113
110
  results = PgSearch.multisearch("foo bar")
114
111
 
115
- expect(results.length).to be 1
116
- expect(results.first.searchable.class).to be SearchableSubclassModel
117
- expect(results.first.searchable).to eq included.first
112
+ expect(results).to eq [included.pg_search_document]
118
113
  end
119
114
 
120
115
  it "updates an existing STI model does not create a new pg_search document" do
@@ -151,8 +146,8 @@ describe PgSearch do
151
146
  end
152
147
 
153
148
  it "reindexing searchable STI doesn't clobber other related STI models" do
154
- searchable_s = SearchableSubclassModel.create!(:content => "baz")
155
- searchable_a = AnotherSearchableSubclassModel.create!(:content => "baz")
149
+ SearchableSubclassModel.create!(:content => "baz")
150
+ AnotherSearchableSubclassModel.create!(:content => "baz")
156
151
 
157
152
  expect(PgSearch::Document.count).to be 2
158
153
  PgSearch::Multisearch.rebuild(SearchableSubclassModel)
@@ -187,16 +182,13 @@ describe PgSearch do
187
182
  end
188
183
 
189
184
  it "returns only results for that subclass" do
190
- included = [
191
- SearchableSubclassModel.create!(:content => "foo bar")
192
- ]
193
- excluded = [
194
- SearchableSubclassModel.create!(:content => "baz"),
195
- SuperclassModel.create!(:content => "foo bar"),
196
- SuperclassModel.create!(:content => "baz"),
197
- NonSearchableSubclassModel.create!(:content => "foo bar"),
198
- NonSearchableSubclassModel.create!(:content => "baz")
199
- ]
185
+ included = SearchableSubclassModel.create!(:content => "foo bar")
186
+
187
+ SearchableSubclassModel.create!(:content => "baz")
188
+ SuperclassModel.create!(:content => "foo bar")
189
+ SuperclassModel.create!(:content => "baz")
190
+ NonSearchableSubclassModel.create!(:content => "foo bar")
191
+ NonSearchableSubclassModel.create!(:content => "baz")
200
192
 
201
193
  expect(SuperclassModel.count).to be 6
202
194
  expect(SearchableSubclassModel.count).to be 2
@@ -205,9 +197,7 @@ describe PgSearch do
205
197
 
206
198
  results = PgSearch.multisearch("foo bar")
207
199
 
208
- expect(results.length).to be 1
209
- expect(results.first.searchable.class).to be SearchableSubclassModel
210
- expect(results.first.searchable).to eq included.first
200
+ expect(results).to eq [included.pg_search_document]
211
201
  end
212
202
  end
213
203
  end
@@ -233,7 +223,7 @@ describe PgSearch do
233
223
  @multisearch_enabled_inside = PgSearch.multisearch_enabled?
234
224
  raise
235
225
  end
236
- rescue # rubocop:disable Lint/HandleExceptions
226
+ rescue
237
227
  end
238
228
 
239
229
  @multisearch_enabled_after = PgSearch.multisearch_enabled?
@@ -1,3 +1,6 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  require "bundler/setup"
2
5
  require "pg_search"
3
6
 
@@ -9,6 +12,8 @@ RSpec.configure do |config|
9
12
  config.mock_with :rspec do |c|
10
13
  c.syntax = :expect
11
14
  end
15
+
16
+ config.example_status_persistence_file_path = 'tmp/examples.txt'
12
17
  end
13
18
 
14
19
  require 'support/database'
@@ -38,12 +38,12 @@ if ENV["LOGGER"]
38
38
  ActiveRecord::Base.logger = Logger.new(STDOUT)
39
39
  end
40
40
 
41
- def install_extension_if_missing(name, query, expected_result)
41
+ def install_extension_if_missing(name, query, expected_result) # rubocop:disable Metrics/AbcSize
42
42
  connection = ActiveRecord::Base.connection
43
43
  postgresql_version = connection.send(:postgresql_version)
44
44
  result = connection.select_value(query)
45
45
  raise "Unexpected output for #{query}: #{result.inspect}" unless result.downcase == expected_result.downcase
46
- rescue => e
46
+ rescue
47
47
  begin
48
48
  if postgresql_version >= 90100
49
49
  ActiveRecord::Base.connection.execute "CREATE EXTENSION #{name};"
@@ -52,13 +52,13 @@ rescue => e
52
52
  ActiveRecord::Base.connection.execute File.read(File.join(share_path, 'contrib', "#{name}.sql"))
53
53
  puts $!.message
54
54
  end
55
- rescue => e2
55
+ rescue => exception
56
56
  at_exit do
57
57
  puts "-" * 80
58
58
  puts "Please install the #{name} contrib module"
59
59
  puts "-" * 80
60
60
  end
61
- raise e2
61
+ raise exception
62
62
  end
63
63
  end
64
64
 
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.4
4
+ version: 1.0.5
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: 2015-06-14 00:00:00.000000000 Z
12
+ date: 2015-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -85,16 +85,16 @@ dependencies:
85
85
  name: rspec
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: '3.0'
90
+ version: '3.3'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - "~>"
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: '3.0'
97
+ version: '3.3'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: with_model
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +134,7 @@ extra_rdoc_files: []
134
134
  files:
135
135
  - ".autotest"
136
136
  - ".bundle/config"
137
+ - ".codeclimate.yml"
137
138
  - ".gitignore"
138
139
  - ".rspec"
139
140
  - ".rubocop.yml"
@@ -175,6 +176,7 @@ files:
175
176
  - lib/pg_search/tasks.rb
176
177
  - lib/pg_search/version.rb
177
178
  - pg_search.gemspec
179
+ - spec/.rubocop.yml
178
180
  - spec/integration/associations_spec.rb
179
181
  - spec/integration/pagination_spec.rb
180
182
  - spec/integration/pg_search_spec.rb