spec/integration/associations_spec.rb in pg_search-2.3.2 vs spec/integration/associations_spec.rb in pg_search-2.3.3
- old
+ new
@@ -1,11 +1,12 @@
# frozen_string_literal: true
require "spec_helper"
-describe PgSearch do
- context "joining to another table" do
+# rubocop:disable RSpec/NestedGroups
+describe "a pg_search_scope" do
+ context "when joining to another table" do
context "without an :against" do
with_model :AssociatedModel do
table do |t|
t.string "title"
end
@@ -39,11 +40,11 @@
expect(results.map(&:title)).to match_array(included.map(&:title))
expect(results).not_to include(excluded)
end
end
- context "through a belongs_to association" do
+ context "via a belongs_to association" do
with_model :AssociatedModel do
table do |t|
t.string 'title'
end
end
@@ -75,11 +76,11 @@
expect(results.map(&:title)).to match_array(included.map(&:title))
expect(results).not_to include(excluded)
end
end
- context "through a has_many association" do
+ context "via a has_many association" do
with_model :AssociatedModelWithHasMany do
table do |t|
t.string 'title'
t.belongs_to 'ModelWithHasMany', index: false
end
@@ -139,12 +140,12 @@
expect(results.map(&:title)).to match_array(included.map(&:title))
expect(results).not_to include(excluded)
end
end
- context "across multiple associations" do
- context "on different tables" do
+ context "when across multiple associations" do
+ context "when on different tables" do
with_model :FirstAssociatedModel do
table do |t|
t.string 'title'
t.belongs_to 'ModelWithManyAssociations', index: false
end
@@ -205,11 +206,11 @@
expect(results.map(&:title)).to match_array(included.map(&:title))
excluded.each { |object| expect(results).not_to include(object) }
end
end
- context "on the same table" do
+ context "when on the same table" do
with_model :DoublyAssociatedModel do
table do |t|
t.string 'title'
t.belongs_to 'ModelWithDoubleAssociation', index: false
t.belongs_to 'ModelWithDoubleAssociation_again', index: false
@@ -266,11 +267,11 @@
excluded.each { |object| expect(results).not_to include(object) }
end
end
end
- context "against multiple attributes on one association" do
+ context "when against multiple attributes on one association" do
with_model :AssociatedModel do
table do |t|
t.string 'title'
t.text 'author'
end
@@ -287,11 +288,11 @@
pg_search_scope :with_associated, associated_against: { another_model: %i[title author] }
end
end
- it "should only do one join" do
+ it "joins only once" do
included = [
ModelWithAssociation.create!(
another_model: AssociatedModel.create!(
title: "foo",
author: "bar"
@@ -319,11 +320,11 @@
included.each { |object| expect(results).to include(object) }
excluded.each { |object| expect(results).not_to include(object) }
end
end
- context "against non-text columns" do
+ context "when against non-text columns" do
with_model :AssociatedModel do
table do |t|
t.integer 'number'
end
end
@@ -340,11 +341,11 @@
pg_search_scope :with_associated, associated_against: { another_model: :number }
end
end
- it "should cast the columns to text" do
+ it "casts the columns to text" do
associated = AssociatedModel.create!(number: 123)
included = [
Model.create!(number: 123, another_model: associated),
Model.create!(number: 456, another_model: associated)
]
@@ -393,11 +394,11 @@
expect(results).not_to include(excluded)
end
end
end
- context "merging a pg_search_scope into another model's scope" do
+ context "when merging a pg_search_scope into another model's scope" do
with_model :ModelWithAssociation do
model do
has_many :associated_models
end
end
@@ -414,11 +415,11 @@
pg_search_scope :search_content, against: :content
end
end
- it "should find records of the other model" do
+ it "finds records of the other model" do
included_associated_1 = AssociatedModel.create(content: "foo bar")
included_associated_2 = AssociatedModel.create(content: "foo baz")
excluded_associated_1 = AssociatedModel.create(content: "baz quux")
excluded_associated_2 = AssociatedModel.create(content: "baz bar")
@@ -439,11 +440,11 @@
expect(results).to include(*included)
expect(results).not_to include(*excluded)
end
end
- context "chained onto a has_many association" do
+ context "when chained onto a has_many association" do
with_model :Company do
model do
has_many :positions
end
end
@@ -459,56 +460,15 @@
pg_search_scope :search, against: :title, using: %i[tsearch trigram]
end
end
# https://github.com/Casecommons/pg_search/issues/106
- it "should handle numbers in a trigram query properly" do
+ it "handles numbers in a trigram query properly" do
company = Company.create!
another_company = Company.create!
included = [
- Position.create!(company_id: company.id, title: "teller 1")
- ]
-
- excluded = [
- Position.create!(company_id: nil, title: "teller 1"),
- Position.create!(company_id: another_company.id, title: "teller 1"),
- Position.create!(company_id: company.id, title: "penn 1")
- ]
-
- results = company.positions.search('teller 1')
-
- expect(results).to include(*included)
- expect(results).not_to include(*excluded)
- end
- end
-
- context "chained onto a has_many association" do
- with_model :Company do
- model do
- has_many :positions
- end
- end
-
- with_model :Position do
- table do |t|
- t.string :title
- t.belongs_to :company
- end
-
- model do
- include PgSearch::Model
- pg_search_scope :search, against: :title, using: %i[tsearch trigram]
- end
- end
-
- # https://github.com/Casecommons/pg_search/issues/106
- it "should handle numbers in a trigram query properly" do
- company = Company.create!
- another_company = Company.create!
-
- included = [
Position.create!(company_id: company.id, title: "teller 1"),
Position.create!(company_id: company.id, title: "teller 2") # close enough
]
excluded = [
@@ -522,5 +482,6 @@
expect(results).to include(*included)
expect(results).not_to include(*excluded)
end
end
end
+# rubocop:enable RSpec/NestedGroups