Initial commit
This commit is contained in:
103
spec/support/models.rb
Executable file
103
spec/support/models.rb
Executable file
@@ -0,0 +1,103 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class VectorModel < ActiveRecord::Base
|
||||
include PgSearchable
|
||||
pg_search fields: %i[id name value], cache: :search_cache
|
||||
end
|
||||
|
||||
class VectorModelWithoutCallback < ActiveRecord::Base
|
||||
self.table_name = :vector_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[id name value], cache: :search_cache, skip_callback: true
|
||||
end
|
||||
|
||||
class VectorWithCustomCallback < ActiveRecord::Base
|
||||
self.table_name = :vector_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[id name value], cache: :search_cache, skip_callback: true, external_cache_data: :colors
|
||||
after_save :update_pg_search_cache
|
||||
|
||||
def colors
|
||||
%w[orange blue]
|
||||
end
|
||||
end
|
||||
|
||||
class VectorWithCustomPrimaryKeyModel < ActiveRecord::Base
|
||||
include PgSearchable
|
||||
pg_search fields: %i[uuid name value]
|
||||
self.primary_key = :uuid
|
||||
before_save { self.uuid = SecureRandom.uuid }
|
||||
end
|
||||
|
||||
class SimpleVectorModel < ActiveRecord::Base
|
||||
self.table_name = :vector_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[id name value], cache: :search_cache, language: :simple
|
||||
end
|
||||
|
||||
class VectorWithoutWildcardModel < ActiveRecord::Base
|
||||
self.table_name = :vector_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[id name value], cache: :search_cache, wildcard: false
|
||||
end
|
||||
|
||||
class VectorModelWithCustomSearchScope < ActiveRecord::Base
|
||||
self.table_name = :vector_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[id name value], cache: :search_cache, scope: 'fulltext'
|
||||
end
|
||||
|
||||
class VectorModelWithTagValues < ActiveRecord::Base
|
||||
self.table_name = :vector_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[id name value], cache: :search_cache, external_cache_data: :tag_values
|
||||
has_many :tags, as: :taggable
|
||||
|
||||
def tag_values
|
||||
tags.pluck(:value)
|
||||
end
|
||||
end
|
||||
|
||||
class DynamicModel < ActiveRecord::Base
|
||||
include PgSearchable
|
||||
pg_search fields: %i[id name value]
|
||||
end
|
||||
|
||||
class DynamicModelWithTagValues < ActiveRecord::Base
|
||||
self.table_name = :dynamic_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[dynamic_models.id dynamic_models.name dynamic_models.value tags.value], joins: [:tags]
|
||||
has_many :tags, as: :taggable
|
||||
end
|
||||
|
||||
class DynamicModelWithCategory < ActiveRecord::Base
|
||||
self.table_name = :dynamic_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[dynamic_models.id dynamic_models.name dynamic_models.value tags.value categories.name],
|
||||
joins: { tags: :category }
|
||||
has_many :tags, as: :taggable
|
||||
end
|
||||
|
||||
class DynamicModelWithSectionsTrhough < ActiveRecord::Base
|
||||
self.table_name = :dynamic_models
|
||||
include PgSearchable
|
||||
pg_search fields: %i[dynamic_models.id dynamic_models.name dynamic_models.value tags.value sections.name],
|
||||
joins: [{ tags: :category }, :sections]
|
||||
has_many :tags, as: :taggable
|
||||
has_many :sections, through: :tags
|
||||
end
|
||||
|
||||
class Tag < ActiveRecord::Base
|
||||
belongs_to :category
|
||||
has_many :sections
|
||||
belongs_to :taggable, polymorphic: true
|
||||
after_save { taggable.update_pg_search_cache if taggable.class.ts_cache_field.present? }
|
||||
end
|
||||
|
||||
class Section < ActiveRecord::Base
|
||||
belongs_to :tag
|
||||
end
|
||||
|
||||
class Category < ActiveRecord::Base
|
||||
has_many :tags
|
||||
end
|
||||
Reference in New Issue
Block a user