mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-02 21:51:01 -05:00
exclude unapproved crops from search
This commit is contained in:
@@ -76,6 +76,7 @@ class Crop < ActiveRecord::Base
|
||||
mappings dynamic: 'false' do
|
||||
indexes :id, type: 'long'
|
||||
indexes :name, type: 'string', analyzer: 'gs_edgeNGram_analyzer'
|
||||
indexes :approval_status, type: 'string'
|
||||
indexes :scientific_names do
|
||||
indexes :scientific_name,
|
||||
type: 'string',
|
||||
@@ -92,7 +93,7 @@ class Crop < ActiveRecord::Base
|
||||
|
||||
def as_indexed_json(options={})
|
||||
self.as_json(
|
||||
only: [:id, :name],
|
||||
only: [:id, :name, :approval_status],
|
||||
include: {
|
||||
scientific_names: { only: :scientific_name },
|
||||
alternate_names: { only: :name }
|
||||
@@ -311,6 +312,9 @@ class Crop < ActiveRecord::Base
|
||||
fields: ["name", "scientific_names.scientific_name", "alternate_names.name"]
|
||||
}
|
||||
},
|
||||
filter: {
|
||||
term: {approval_status: "approved"}
|
||||
},
|
||||
size: 50
|
||||
}
|
||||
)
|
||||
|
||||
@@ -342,6 +342,16 @@ describe Crop do
|
||||
it "searches case insensitively" do
|
||||
Crop.search('mUsH').should include @mushroom
|
||||
end
|
||||
it "doesn't find 'rejected' crop" do
|
||||
@mushroom.approval_status = "rejected"
|
||||
sync_elasticsearch([@mushroom])
|
||||
Crop.search('mushroom').should_not include @mushroom
|
||||
end
|
||||
it "doesn't find 'pending' crop" do
|
||||
@mushroom.approval_status = "pending"
|
||||
sync_elasticsearch([@mushroom])
|
||||
Crop.search('mushroom').should_not include @mushroom
|
||||
end
|
||||
end
|
||||
|
||||
context "csv loading" do
|
||||
|
||||
Reference in New Issue
Block a user