Commit ca8b260a authored by Rubén Dávila Santos's avatar Rubén Dávila Santos

Merge branch 'fix-elastic-search-specs' into 'master'

Run Sidekiq in inline mode for Elastic Search related specs



See merge request !652
parents cf1076a5 6deb952e
......@@ -14,6 +14,7 @@ describe Issue, elastic: true do
it "searches issues" do
project = create :empty_project
Sidekiq::Testing.inline! do
create :issue, title: 'bla-bla term', project: project
create :issue, description: 'bla-bla term', project: project
create :issue, project: project
......@@ -22,6 +23,7 @@ describe Issue, elastic: true do
create :issue, title: 'bla-bla term'
Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [project.id] }
......
......@@ -14,6 +14,7 @@ describe Milestone, elastic: true do
it "searches milestones" do
project = create :empty_project
Sidekiq::Testing.inline! do
create :milestone, title: 'bla-bla term', project: project
create :milestone, description: 'bla-bla term', project: project
create :milestone, project: project
......@@ -22,6 +23,7 @@ describe Milestone, elastic: true do
create :milestone, title: 'bla-bla term'
Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [project.id] }
......
......@@ -14,6 +14,7 @@ describe Note, elastic: true do
it "searches notes" do
issue = create :issue
Sidekiq::Testing.inline! do
create :note, note: 'bla-bla term', project: issue.project
create :note, project: issue.project
......@@ -21,6 +22,7 @@ describe Note, elastic: true do
create :note, note: 'bla-bla term'
Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [issue.project.id] }
......@@ -56,10 +58,10 @@ describe Note, elastic: true do
it "does not find note" do
issue = create :issue, :confidential
create :note, note: 'bla-bla term', project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [issue.project.id] }
......@@ -70,10 +72,10 @@ describe Note, elastic: true do
user = create :user
issue = create :issue, :confidential, author: user
create :note, note: 'bla-bla term', project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [issue.project.id], current_user: user }
......@@ -87,10 +89,10 @@ describe Note, elastic: true do
member = create(:user)
issue.project.team << [member, :developer]
create :note, note: 'bla-bla term', project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [issue.project.id], current_user: member }
......@@ -104,14 +106,19 @@ describe Note, elastic: true do
member = create(:user)
issue.project.team << [member, :guest]
create :note, note: 'bla-bla term', project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [issue.project.id], current_user: member }
expect(Note.elastic_search('term', options: options).total_count).to eq(0)
end
end
def create_notes_for(issue, note)
create :note, note: note, project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue
end
end
......@@ -12,13 +12,17 @@ describe Project, elastic: true do
end
it "searches projects" do
project_ids = []
Sidekiq::Testing.inline! do
project = create :empty_project, name: 'test'
project1 = create :empty_project, path: 'test1'
project2 = create :empty_project
create :empty_project, path: 'someone_elses_project'
project_ids = [project.id, project1.id, project2.id]
project_ids += [project.id, project1.id, project2.id]
Gitlab::Elastic::Helper.refresh_index
end
expect(described_class.elastic_search('test', options: { pids: project_ids }).total_count).to eq(1)
expect(described_class.elastic_search('test1', options: { pids: project_ids }).total_count).to eq(1)
......
......@@ -14,10 +14,12 @@ describe Repository, elastic: true do
it "searches blobs and commits" do
project = create :project
Sidekiq::Testing.inline! do
project.repository.index_blobs
project.repository.index_commits
Gitlab::Elastic::Helper.refresh_index
end
expect(project.repository.search('def popen')[:blobs][:total_count]).to eq(1)
expect(project.repository.search('initial')[:commits][:total_count]).to eq(1)
......
......@@ -73,12 +73,14 @@ describe Snippet, elastic: true do
it 'searches snippets by title and file_name' do
user = create(:user)
Sidekiq::Testing.inline! do
create(:snippet, :public, title: 'home')
create(:snippet, :private, title: 'home 1')
create(:snippet, :public, file_name: 'index.php')
create(:snippet)
Gitlab::Elastic::Helper.refresh_index
end
options = { user: user }
......
......@@ -14,11 +14,12 @@ describe ProjectWiki, elastic: true do
it "searches wiki page" do
project = create :empty_project
Sidekiq::Testing.inline! do
project.wiki.create_page("index_page", "Bla bla")
project.wiki.index_blobs
Gitlab::Elastic::Helper.refresh_index
end
expect(project.wiki.search('bla', type: :blob)[:blobs][:total_count]).to eq(1)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment