Convert basic_search_spec to snake_case

This commit is contained in:
Lars Henrik Mai 2020-03-09 13:02:36 +01:00
parent 163e43a3c9
commit 20d259d658

View file

@ -48,19 +48,19 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
scenario 'Search results have basic information' do scenario 'Search results have basic information' do
visit search_path body: 'leipzig' visit search_path body: 'leipzig'
paper = @papers.first paper = @papers.first
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
resultSubEntry = resultEntry.find('li.current', match: :first) result_subentry = result_entry.find('li.current', match: :first)
linkName = getLinkName(paper) linkname = get_linkname(paper)
expect(resultSubEntry).to have_link(linkName, href: paper.url) expect(result_subentry).to have_link(linkname, href: paper.url)
end end
def getLinkName(paper) def get_linkname(paper)
dateStr = I18n.l(paper.published_at.to_date) date = I18n.l(paper.published_at.to_date)
originatorStr = (paper.originator.is_a?(Array) ? originator = (paper.originator.is_a?(Array) ?
paper.originator.join(', ') : paper.originator) paper.originator.join(', ') : paper.originator)
"#{dateStr}: #{paper.paper_type} von #{originatorStr}" "#{date}: #{paper.paper_type} von #{originator}"
end end
scenario 'Finds papers by name' do scenario 'Finds papers by name' do
@ -68,12 +68,12 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Opendata' } visit search_path body: 'leipzig', paper_search: { query: 'Opendata' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
resultSubEntry = resultEntry.find('li.current', match: :first) result_subentry = result_entry.find('li.current', match: :first)
linkName = getLinkName(paper) linkname = get_linkname(paper)
expect(resultSubEntry).to have_link(linkName, href: paper.url) expect(result_subentry).to have_link(linkname, href: paper.url)
end end
scenario 'Finds papers by content' do scenario 'Finds papers by content' do
@ -83,75 +83,75 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Verwaltungsdokumente' } visit search_path body: 'leipzig', paper_search: { query: 'Verwaltungsdokumente' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
resultSubEntry = resultEntry.find('li.current', match: :first) result_subentry = result_entry.find('li.current', match: :first)
linkName = getLinkName(paper) linkname = get_linkname(paper)
expect(resultSubEntry).to have_link(linkName, href: paper.url) expect(result_subentry).to have_link(linkname, href: paper.url)
end end
scenario 'Papers with common reference id in search result ordered by date' do scenario 'Papers with common reference id in search result ordered by date' do
mainPaper = FactoryBot.create(:paper, published_at: '2016-12-19T19:00:00', main_paper = FactoryBot.create(:paper, published_at: '2016-12-19T19:00:00',
name: 'Opendata als default', reference: 'VI-0815') name: 'Opendata als default', reference: 'VI-0815')
newPaper = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00', new_paper = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00',
name: 'Opendata als optional', reference: 'VI-0815-ÄA-01') name: 'Opendata als optional', reference: 'VI-0815-ÄA-01')
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'default' } visit search_path body: 'leipzig', paper_search: { query: 'default' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(mainPaper.name) expect(result_entry).to have_content(main_paper.name)
resultSubEntry1 = resultEntry.find('li.current', match: :first) result_subentry1 = result_entry.find('li.current', match: :first)
linkName1 = getLinkName(mainPaper) linkname1 = get_linkname(main_paper)
expect(resultSubEntry1).to have_link(linkName1, href: mainPaper.url) expect(result_subentry1).to have_link(linkname1, href: main_paper.url)
resultSubEntries = resultEntry.find('ul').all('li') result_subentries = result_entry.find('ul').all('li')
linkName2 = getLinkName(newPaper) linkname2 = get_linkname(new_paper)
expect(resultSubEntries[0]).to have_link(linkName2, href: newPaper.url) expect(result_subentries[0]).to have_link(linkname2, href: new_paper.url)
expect(resultSubEntries[1]).to have_link(linkName1, href: mainPaper.url) expect(result_subentries[1]).to have_link(linkname1, href: main_paper.url)
end end
scenario 'Papers with common reference id in search result ordered by ref' do scenario 'Papers with common reference id in search result ordered by ref' do
mainPaper = FactoryBot.create(:paper, published_at: '2016-12-19T19:00:00', main_paper = FactoryBot.create(:paper, published_at: '2016-12-19T19:00:00',
name: 'Opendata als default', reference: 'VI-0815') name: 'Opendata als default', reference: 'VI-0815')
newPaper1 = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00', new_paper1 = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00',
name: 'Opendata als optional', reference: 'VI-0815-ÄA-02') name: 'Opendata als optional', reference: 'VI-0815-ÄA-02')
newPaper2 = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00', new_paper2 = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00',
name: 'Opendata als optional', reference: 'VI-0815-ÄA-01') name: 'Opendata als optional', reference: 'VI-0815-ÄA-01')
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'default' } visit search_path body: 'leipzig', paper_search: { query: 'default' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
resultSubEntries = resultEntry.find('ul').all('li') result_subentries = result_entry.find('ul').all('li')
linkName1 = getLinkName(newPaper1) linkname1 = get_linkname(new_paper1)
expect(resultSubEntries[0]).to have_link(linkName1, href: newPaper1.url) expect(result_subentries[0]).to have_link(linkname1, href: new_paper1.url)
linkName2 = getLinkName(newPaper2) linkname2 = get_linkname(new_paper2)
expect(resultSubEntries[1]).to have_link(linkName2, href: newPaper2.url) expect(result_subentries[1]).to have_link(linkname2, href: new_paper2.url)
linkName3 = getLinkName(mainPaper) linkname3 = get_linkname(main_paper)
expect(resultSubEntries[2]).to have_link(linkName3, href: mainPaper.url) expect(result_subentries[2]).to have_link(linkname3, href: main_paper.url)
end end
scenario 'Papers with common reference id handled also for missing prefix' do scenario 'Papers with common reference id handled also for missing prefix' do
mainPaper = FactoryBot.create(:paper, published_at: '2016-12-19T19:00:00', main_paper = FactoryBot.create(:paper, published_at: '2016-12-19T19:00:00',
name: 'Opendata als default', reference: 'VI-0815') name: 'Opendata als default', reference: 'VI-0815')
newPaper1 = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00', new_paper1 = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00',
name: 'Opendata als optional', reference: 'VI-0815-NF-01') name: 'Opendata als optional', reference: 'VI-0815-NF-01')
newPaper1Change = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00', new_paper2 = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00',
name: 'Opendata als nicht optional', reference: '-0815-NF-01-ÄA-01') name: 'Opendata als nicht optional', reference: '-0815-NF-01-ÄA-01')
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'default' } visit search_path body: 'leipzig', paper_search: { query: 'default' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
resultSubEntries = resultEntry.find('ul').all('li') result_subentries = result_entry.find('ul').all('li')
linkName1 = getLinkName(newPaper1) linkname1 = get_linkname(new_paper1)
expect(resultSubEntries[0]).to have_link(linkName1, href: newPaper1.url) expect(result_subentries[0]).to have_link(linkname1, href: new_paper1.url)
linkName2 = getLinkName(newPaper1Change) linkname2 = get_linkname(new_paper2)
expect(resultSubEntries[1]).to have_link(linkName2, href: newPaper1Change.url) expect(result_subentries[1]).to have_link(linkname2, href: new_paper2.url)
linkName3 = getLinkName(mainPaper) linkname3 = get_linkname(main_paper)
expect(resultSubEntries[2]).to have_link(linkName3, href: mainPaper.url) expect(result_subentries[2]).to have_link(linkname3, href: main_paper.url)
end end
scenario "Finds 'Testen' with search 'Test'" do scenario "Finds 'Testen' with search 'Test'" do
@ -159,8 +159,8 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Test' } visit search_path body: 'leipzig', paper_search: { query: 'Test' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
end end
scenario "Finds 'Test' with search 'Testen'" do scenario "Finds 'Test' with search 'Testen'" do
@ -168,8 +168,8 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Testen' } visit search_path body: 'leipzig', paper_search: { query: 'Testen' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
end end
scenario "Finds 'Fahrräderverleih' with search 'Fahrrad'" do scenario "Finds 'Fahrräderverleih' with search 'Fahrrad'" do
@ -177,8 +177,8 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Fahrrad' } visit search_path body: 'leipzig', paper_search: { query: 'Fahrrad' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
end end
scenario "Finds 'Fahrräderverleih' with search 'Fahrräder'" do scenario "Finds 'Fahrräderverleih' with search 'Fahrräder'" do
@ -186,8 +186,8 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Fahrräder' } visit search_path body: 'leipzig', paper_search: { query: 'Fahrräder' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
end end
scenario "Finds 'Fahrräderverleih' with search 'Verleih'" do scenario "Finds 'Fahrräderverleih' with search 'Verleih'" do
@ -195,8 +195,8 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Verleih' } visit search_path body: 'leipzig', paper_search: { query: 'Verleih' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
end end
scenario "Finds 'Fahrräderverleih' with search 'Autoverleih'" do scenario "Finds 'Fahrräderverleih' with search 'Autoverleih'" do
@ -204,8 +204,8 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'Autoverleih' } visit search_path body: 'leipzig', paper_search: { query: 'Autoverleih' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(result_entry).to have_content(paper.name)
end end
scenario "Finds no 'Fahrrad' with search 'Rad'" do scenario "Finds no 'Fahrrad' with search 'Rad'" do
@ -216,23 +216,23 @@ RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
end end
scenario 'Papers with reference id having slash is escaped' do scenario 'Papers with reference id having slash is escaped' do
mainPaper = FactoryBot.create(:paper, published_at: '2016-12-19T19:00:00', main_paper = FactoryBot.create(:paper, published_at: '2016-12-19T19:00:00',
name: 'Opendata als default', reference: 'VI-00768/14') name: 'Opendata als default', reference: 'VI-00768/14')
newPaper = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00', new_paper = FactoryBot.create(:paper, published_at: '2016-12-23T12:00:00',
name: 'Opendata als optional', reference: 'VI-00768/14-ÄA-01') name: 'Opendata als optional', reference: 'VI-00768/14-ÄA-01')
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: 'leipzig', paper_search: { query: 'default' } visit search_path body: 'leipzig', paper_search: { query: 'default' }
expect(page).to have_content('1 Dokument in der Datenbank') expect(page).to have_content('1 Dokument in der Datenbank')
resultEntry = page.find('li.search-result', match: :first) result_entry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(mainPaper.name) expect(result_entry).to have_content(main_paper.name)
resultSubEntry1 = resultEntry.find('li.current', match: :first) result_subentry1 = result_entry.find('li.current', match: :first)
linkName1 = getLinkName(mainPaper) linkname1 = get_linkname(main_paper)
expect(resultSubEntry1).to have_link(linkName1, href: mainPaper.url) expect(result_subentry1).to have_link(linkname1, href: main_paper.url)
resultSubEntries = resultEntry.find('ul').all('li') result_subentries = result_entry.find('ul').all('li')
linkName2 = getLinkName(newPaper) linkname2 = get_linkname(new_paper)
expect(resultSubEntries[0]).to have_link(linkName2, href: newPaper.url) expect(result_subentries[0]).to have_link(linkname2, href: new_paper.url)
expect(resultSubEntries[1]).to have_link(linkName1, href: mainPaper.url) expect(result_subentries[1]).to have_link(linkname1, href: main_paper.url)
end end
end end