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