Rubocop autocorrect specs

This commit is contained in:
Lars Henrik Mai 2020-03-09 11:27:52 +01:00
parent 247f4b85b7
commit 5c2e1bfe1e
13 changed files with 279 additions and 269 deletions

View file

@ -1,48 +1,46 @@
# frozen_string_literal: true
require 'rails_helper' require 'rails_helper'
RSpec.describe SearchController, type: :controller, elasticsearch: true do RSpec.describe SearchController, type: :controller, elasticsearch: true do
describe 'GET #index' do
describe "GET #index" do it 'returns http success' do
it "returns http success" do
get :index, body: 'leipzig' get :index, body: 'leipzig'
expect(response).to have_http_status(:success) expect(response).to have_http_status(:success)
end end
it "assigns @search_definition with default sort order" do it 'assigns @search_definition with default sort order' do
search = PaperSearch.new(sort_by: 'date') search = PaperSearch.new(sort_by: 'date')
get :index, body: 'leipzig' get :index, body: 'leipzig'
expect(assigns(:search_definition).attributes).to eq(search.attributes) expect(assigns(:search_definition).attributes).to eq(search.attributes)
end end
it "renders the index template" do it 'renders the index template' do
get :index, body: 'leipzig' get :index, body: 'leipzig'
expect(response).to render_template(:index) expect(response).to render_template(:index)
end end
it "executes the search with PaperSearch parameters" do it 'executes the search with PaperSearch parameters' do
pending("simplify search implementation") pending('simplify search implementation')
result_page = double("page", results: []) # MEH result_page = double('page', results: []) # MEH
response = double("es_response", page: result_page) response = double('es_response', page: result_page)
expect(Paper).to receive(:search).and_return(response) expect(Paper).to receive(:search).and_return(response)
get :index, body: 'leipzig' get :index, body: 'leipzig'
end end
it 'returns rss' do
it "returns rss" do get :index, format: 'rss', body: 'leipzig'
get :index, :format => "rss", body: 'leipzig'
expect(response).to be_success expect(response).to be_success
expect(response).to render_template(:index) expect(response).to render_template(:index)
expect(response.content_type).to eq("application/rss+xml") expect(response.content_type).to eq('application/rss+xml')
#expect(response.body).to have_tag "rss" do # expect(response.body).to have_tag "rss" do
# with_tag "channel" do # with_tag "channel" do
# with_tag "title" # with_tag "title"
# with_tag "description" # with_tag "description"
# with_tag "link" # with_tag "link"
# end # end
#end # end
end end
end end
end end

View file

@ -1,13 +1,15 @@
# frozen_string_literal: true
require_relative '../factory_helper' require_relative '../factory_helper'
FactoryBot.define do FactoryBot.define do
factory :paper do factory :paper do
name { Faker::Lorem.sentence } name { Faker::Lorem.sentence }
sequence(:url) { |n| Faker::Internet.url(host: "ris.example.org", path: "/paper-#{n}.html") } sequence(:url) { |n| Faker::Internet.url(host: 'ris.example.org', path: "/paper-#{n}.html") }
sequence(:reference) { |n| FactoryHelper.reference(n) } sequence(:reference) { |n| FactoryHelper.reference(n) }
body { "leipzig" } body { 'leipzig' }
published_at { "2015-07-20 21:16:53" } published_at { '2015-07-20 21:16:53' }
scraped_at { "2015-07-20 21:16:53" } scraped_at { '2015-07-20 21:16:53' }
paper_type { FactoryHelper.paper_type } paper_type { FactoryHelper.paper_type }
originator { Faker::Name.name } originator { Faker::Name.name }
resolution { Faker::Lorem.paragraph(sentence_count: 3) } resolution { Faker::Lorem.paragraph(sentence_count: 3) }

View file

@ -1,29 +1,29 @@
module FactoryHelper # frozen_string_literal: true
module FactoryHelper
PAPER_TYPES = [ PAPER_TYPES = [
"Verwaltungsstandpunkt", 'Verwaltungsstandpunkt',
"Anfrage", 'Anfrage',
"Beschlussvorlage", 'Beschlussvorlage',
"Änderungsantrag", 'Änderungsantrag',
"Antrag", 'Antrag',
"Neufassung", 'Neufassung',
"Informationsvorlage", 'Informationsvorlage',
"Einwohneranfrage", 'Einwohneranfrage',
"Petition", 'Petition',
"schriftliche Antwort zur Anfrage", 'schriftliche Antwort zur Anfrage',
"Wichtige Angelegenheit", 'Wichtige Angelegenheit',
"Eilentscheidung", 'Eilentscheidung',
"Dringliche Anfrage" 'Dringliche Anfrage'
] ].freeze
def self.paper_type def self.paper_type
PAPER_TYPES.sample PAPER_TYPES.sample
end end
REFERENCE = "A-%05i/16" REFERENCE = 'A-%05i/16'
def self.reference(seq) def self.reference(seq)
REFERENCE % seq REFERENCE % seq
end end
end end

View file

@ -1,130 +1,130 @@
# frozen_string_literal: true
require 'rails_helper' require 'rails_helper'
require 'pp' require 'pp'
RSpec.feature "Basic search", type: :feature, elasticsearch: true do RSpec.feature 'Basic search', type: :feature, elasticsearch: true do
before(:each) do before(:each) do
@papers = FactoryBot.create_list(:paper, 11) @papers = FactoryBot.create_list(:paper, 11)
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
end end
scenario "It displays the search form" do scenario 'It displays the search form' do
visit search_path body: "leipzig" visit search_path body: 'leipzig'
expect(page).to have_content("Stadtratmonitor") expect(page).to have_content('Stadtratmonitor')
expect(page).to have_field("paper_search_query") expect(page).to have_field('paper_search_query')
expect(page).to have_select("Typ") expect(page).to have_select('Typ')
expect(page).to have_select("Einreicher") expect(page).to have_select('Einreicher')
expect(page).to have_selector("label", text: "Sortierung") expect(page).to have_selector('label', text: 'Sortierung')
expect(page).to have_field("paper_search_sort_by_date", type: "radio") expect(page).to have_field('paper_search_sort_by_date', type: 'radio')
expect(page).to have_field("paper_search_sort_by_score", type: "radio") expect(page).to have_field('paper_search_sort_by_score', type: 'radio')
end end
scenario "With empty query displays all documents" do scenario 'With empty query displays all documents' do
visit search_path body: "leipzig" visit search_path body: 'leipzig'
expect(page).to have_selector("ul#search_results") expect(page).to have_selector('ul#search_results')
expect(page).to have_content("#{@papers.size} Dokumente in der Datenbank") expect(page).to have_content("#{@papers.size} Dokumente in der Datenbank")
end end
scenario "Search results are paginated" do scenario 'Search results are paginated' do
visit search_path body: "leipzig" visit search_path body: 'leipzig'
expect(page).to have_css("li.search-result", count: 10) expect(page).to have_css('li.search-result', count: 10)
expect(page).to have_css("div#pagination") expect(page).to have_css('div#pagination')
within("div#pagination") do within('div#pagination') do
expect(page).to have_css("li", count: 4) # two pages + next + last expect(page).to have_css('li', count: 4) # two pages + next + last
expect(page).to have_css("li.current", text: "1") expect(page).to have_css('li.current', text: '1')
expect(page).to have_link("2") expect(page).to have_link('2')
expect(page).to have_link("Weiter") expect(page).to have_link('Weiter')
expect(page).to have_link("Ende") expect(page).to have_link('Ende')
end end
page.find("div#pagination").click_link("2") page.find('div#pagination').click_link('2')
expect(page).to have_css("li.search-result", count: 1) expect(page).to have_css('li.search-result', count: 1)
within("div#pagination") do within('div#pagination') do
expect(page).to have_css("li.current", text: "2") expect(page).to have_css('li.current', text: '2')
end end
end end
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).to have_content(paper.name)
resultSubEntry = resultEntry.find("li.current", match: :first) resultSubEntry = resultEntry.find('li.current', match: :first)
linkName = getLinkName(paper) linkName = getLinkName(paper)
expect(resultSubEntry).to have_link(linkName, href: paper.url) expect(resultSubEntry).to have_link(linkName, href: paper.url)
end end
def getLinkName(paper) def getLinkName(paper)
dateStr = I18n.l(paper.published_at.to_date) dateStr = I18n.l(paper.published_at.to_date)
originatorStr = (paper.originator.kind_of?(Array) ? originatorStr = (paper.originator.is_a?(Array) ?
paper.originator.join(", ") : paper.originator) paper.originator.join(', ') : paper.originator)
return "#{dateStr}: #{paper.paper_type} von #{originatorStr}" "#{dateStr}: #{paper.paper_type} von #{originatorStr}"
end end
scenario "Finds papers by name" do scenario 'Finds papers by name' do
paper = FactoryBot.create(:paper, name: "Opendata als default") paper = FactoryBot.create(:paper, name: 'Opendata als default')
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).to have_content(paper.name)
resultSubEntry = resultEntry.find("li.current", match: :first) resultSubEntry = resultEntry.find('li.current', match: :first)
linkName = getLinkName(paper) linkName = getLinkName(paper)
expect(resultSubEntry).to have_link(linkName, href: paper.url) expect(resultSubEntry).to have_link(linkName, href: paper.url)
end end
scenario "Finds papers by content" do scenario 'Finds papers by content' do
paper = FactoryBot.create(:paper, paper = FactoryBot.create(:paper,
name: "Opendata als default", name: 'Opendata als default',
content: "Alle Verwaltungsdokumente werden als Opendata veröffentlicht" content: 'Alle Verwaltungsdokumente werden als Opendata veröffentlicht')
)
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).to have_content(paper.name)
resultSubEntry = resultEntry.find("li.current", match: :first) resultSubEntry = resultEntry.find('li.current', match: :first)
linkName = getLinkName(paper) linkName = getLinkName(paper)
expect(resultSubEntry).to have_link(linkName, href: paper.url) expect(resultSubEntry).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', mainPaper = 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', newPaper = 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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(mainPaper.name) expect(resultEntry).to have_content(mainPaper.name)
resultSubEntry1 = resultEntry.find("li.current", match: :first) resultSubEntry1 = resultEntry.find('li.current', match: :first)
linkName1 = getLinkName(mainPaper) linkName1 = getLinkName(mainPaper)
expect(resultSubEntry1).to have_link(linkName1, href: mainPaper.url) expect(resultSubEntry1).to have_link(linkName1, href: mainPaper.url)
resultSubEntries = resultEntry.find("ul").all("li") resultSubEntries = resultEntry.find('ul').all('li')
linkName2 = getLinkName(newPaper) linkName2 = getLinkName(newPaper)
expect(resultSubEntries[0]).to have_link(linkName2, href: newPaper.url) expect(resultSubEntries[0]).to have_link(linkName2, href: newPaper.url)
expect(resultSubEntries[1]).to have_link(linkName1, href: mainPaper.url) expect(resultSubEntries[1]).to have_link(linkName1, href: mainPaper.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', mainPaper = 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', newPaper1 = 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', newPaper2 = 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) resultEntry = page.find('li.search-result', match: :first)
resultSubEntries = resultEntry.find("ul").all("li") resultSubEntries = resultEntry.find('ul').all('li')
linkName1 = getLinkName(newPaper1) linkName1 = getLinkName(newPaper1)
expect(resultSubEntries[0]).to have_link(linkName1, href: newPaper1.url) expect(resultSubEntries[0]).to have_link(linkName1, href: newPaper1.url)
linkName2 = getLinkName(newPaper2) linkName2 = getLinkName(newPaper2)
@ -133,19 +133,19 @@ RSpec.feature "Basic search", type: :feature, elasticsearch: true do
expect(resultSubEntries[2]).to have_link(linkName3, href: mainPaper.url) expect(resultSubEntries[2]).to have_link(linkName3, href: mainPaper.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', mainPaper = 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', newPaper1 = 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', newPaper1Change = 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) resultEntry = page.find('li.search-result', match: :first)
resultSubEntries = resultEntry.find("ul").all("li") resultSubEntries = resultEntry.find('ul').all('li')
linkName1 = getLinkName(newPaper1) linkName1 = getLinkName(newPaper1)
expect(resultSubEntries[0]).to have_link(linkName1, href: newPaper1.url) expect(resultSubEntries[0]).to have_link(linkName1, href: newPaper1.url)
linkName2 = getLinkName(newPaper1Change) linkName2 = getLinkName(newPaper1Change)
@ -155,85 +155,84 @@ RSpec.feature "Basic search", type: :feature, elasticsearch: true do
end end
scenario "Finds 'Testen' with search 'Test'" do scenario "Finds 'Testen' with search 'Test'" do
paper = FactoryBot.create(:paper, name: "Testen") paper = FactoryBot.create(:paper, name: 'Testen')
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).to have_content(paper.name)
end end
scenario "Finds 'Test' with search 'Testen'" do scenario "Finds 'Test' with search 'Testen'" do
paper = FactoryBot.create(:paper, name: "Test") paper = FactoryBot.create(:paper, name: 'Test')
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).to have_content(paper.name)
end end
scenario "Finds 'Fahrräderverleih' with search 'Fahrrad'" do scenario "Finds 'Fahrräderverleih' with search 'Fahrrad'" do
paper = FactoryBot.create(:paper, name: "Fahrräderverleih") paper = FactoryBot.create(:paper, name: 'Fahrräderverleih')
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).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
paper = FactoryBot.create(:paper, name: "Fahrräderverleih") paper = FactoryBot.create(:paper, name: 'Fahrräderverleih')
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).to have_content(paper.name)
end end
scenario "Finds 'Fahrräderverleih' with search 'Verleih'" do scenario "Finds 'Fahrräderverleih' with search 'Verleih'" do
paper = FactoryBot.create(:paper, name: "Fahrräderverleih") paper = FactoryBot.create(:paper, name: 'Fahrräderverleih')
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).to have_content(paper.name)
end end
scenario "Finds 'Fahrräderverleih' with search 'Autoverleih'" do scenario "Finds 'Fahrräderverleih' with search 'Autoverleih'" do
paper = FactoryBot.create(:paper, name: "Fahrräderverleih") paper = FactoryBot.create(:paper, name: 'Fahrräderverleih')
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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(paper.name) expect(resultEntry).to have_content(paper.name)
end end
scenario "Finds no 'Fahrrad' with search 'Rad'" do scenario "Finds no 'Fahrrad' with search 'Rad'" do
paper = FactoryBot.create(:paper, name: "Fahrrad") paper = FactoryBot.create(:paper, name: 'Fahrrad')
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
visit search_path body: "leipzig", paper_search: {query: "Rad"} visit search_path body: 'leipzig', paper_search: { query: 'Rad' }
expect(page).to have_content("0 Dokumente in der Datenbank") expect(page).to have_content('0 Dokumente in der Datenbank')
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', mainPaper = 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', newPaper = 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) resultEntry = page.find('li.search-result', match: :first)
expect(resultEntry).to have_content(mainPaper.name) expect(resultEntry).to have_content(mainPaper.name)
resultSubEntry1 = resultEntry.find("li.current", match: :first) resultSubEntry1 = resultEntry.find('li.current', match: :first)
linkName1 = getLinkName(mainPaper) linkName1 = getLinkName(mainPaper)
expect(resultSubEntry1).to have_link(linkName1, href: mainPaper.url) expect(resultSubEntry1).to have_link(linkName1, href: mainPaper.url)
resultSubEntries = resultEntry.find("ul").all("li") resultSubEntries = resultEntry.find('ul').all('li')
linkName2 = getLinkName(newPaper) linkName2 = getLinkName(newPaper)
expect(resultSubEntries[0]).to have_link(linkName2, href: newPaper.url) expect(resultSubEntries[0]).to have_link(linkName2, href: newPaper.url)
expect(resultSubEntries[1]).to have_link(linkName1, href: mainPaper.url) expect(resultSubEntries[1]).to have_link(linkName1, href: mainPaper.url)
end end
end end

View file

@ -1,69 +1,65 @@
# frozen_string_literal: true
require 'rails_helper' require 'rails_helper'
RSpec.feature "Search filters", type: :feature, elasticsearch: true do RSpec.feature 'Search filters', type: :feature, elasticsearch: true do
before(:each) do before(:each) do
@antrag = FactoryBot.create(:paper, @antrag = FactoryBot.create(:paper,
paper_type: "Antrag", paper_type: 'Antrag',
name: "Mehr Spielplätze in Leipzig", name: 'Mehr Spielplätze in Leipzig',
originator: "Dezernat Jugend, Soziales, Gesundheit und Schule" originator: 'Dezernat Jugend, Soziales, Gesundheit und Schule')
)
@anfrage = FactoryBot.create(:paper, @anfrage = FactoryBot.create(:paper,
paper_type: "Anfrage", paper_type: 'Anfrage',
originator: "CDU-Fraktion" originator: 'CDU-Fraktion')
)
@vorlage_1 = FactoryBot.create(:paper, @vorlage_1 = FactoryBot.create(:paper,
paper_type: "Vorlage", paper_type: 'Vorlage',
name: "Zustand der Spielplätze", name: 'Zustand der Spielplätze',
originator: "Dezernat Jugend, Soziales, Gesundheit und Schule" originator: 'Dezernat Jugend, Soziales, Gesundheit und Schule')
)
@vorlage_2 = FactoryBot.create(:paper, @vorlage_2 = FactoryBot.create(:paper,
paper_type: "Vorlage", paper_type: 'Vorlage',
name: "Mehr Ampeln in der Innenstadt", name: 'Mehr Ampeln in der Innenstadt',
originator: "Oberbürgermeister" originator: 'Oberbürgermeister')
)
Paper.__elasticsearch__.refresh_index! Paper.__elasticsearch__.refresh_index!
end end
scenario "Displays paper types and their respective count witin the search results" do scenario 'Displays paper types and their respective count witin the search results' do
visit search_path body: "leipzig" visit search_path body: 'leipzig'
paper_type_filter = page.find("select#paper_search_paper_type") paper_type_filter = page.find('select#paper_search_paper_type')
expect(paper_type_filter).to have_css("option", text: "Antrag (1)") expect(paper_type_filter).to have_css('option', text: 'Antrag (1)')
expect(paper_type_filter).to have_css("option", text: "Anfrage (1)") expect(paper_type_filter).to have_css('option', text: 'Anfrage (1)')
expect(paper_type_filter).to have_css("option", text: "Vorlage (2)") expect(paper_type_filter).to have_css('option', text: 'Vorlage (2)')
visit search_path body: "leipzig", paper_search: {query: "Spielplätze"} visit search_path body: 'leipzig', paper_search: { query: 'Spielplätze' }
paper_type_filter = page.find("select#paper_search_paper_type") paper_type_filter = page.find('select#paper_search_paper_type')
expect(paper_type_filter).to have_css("option", text: "Antrag (1)") expect(paper_type_filter).to have_css('option', text: 'Antrag (1)')
expect(paper_type_filter).not_to have_css("option", text: "Anfrage") expect(paper_type_filter).not_to have_css('option', text: 'Anfrage')
expect(paper_type_filter).to have_css("option", text: "Vorlage (1)") expect(paper_type_filter).to have_css('option', text: 'Vorlage (1)')
end end
scenario "Filtering by paper type", js: true do scenario 'Filtering by paper type', js: true do
visit search_path body: "leipzig" visit search_path body: 'leipzig'
expect(page).to have_css("li.search-result", count: 4) expect(page).to have_css('li.search-result', count: 4)
select "Antrag (1)", from: "Typ" select 'Antrag (1)', from: 'Typ'
expect(page).to have_css("li.search-result", count: 1, text: "Spielplätze") expect(page).to have_css('li.search-result', count: 1, text: 'Spielplätze')
end end
scenario "Displays originators and their respective count within the search results" do scenario 'Displays originators and their respective count within the search results' do
visit search_path body: "leipzig" visit search_path body: 'leipzig'
originator_filter = page.find("select#paper_search_originator") originator_filter = page.find('select#paper_search_originator')
expect(originator_filter).to have_css("option", text: "CDU-Fraktion (1)") expect(originator_filter).to have_css('option', text: 'CDU-Fraktion (1)')
expect(originator_filter).to have_css("option", text: "Dezernat Jugend, Soziales, Gesundheit und Schule (2)") expect(originator_filter).to have_css('option', text: 'Dezernat Jugend, Soziales, Gesundheit und Schule (2)')
expect(originator_filter).to have_css("option", text: "Oberbürgermeister (1)") expect(originator_filter).to have_css('option', text: 'Oberbürgermeister (1)')
visit search_path body: "leipzig", paper_search: {query: "Spielplätze"} visit search_path body: 'leipzig', paper_search: { query: 'Spielplätze' }
originator_filter = page.find("select#paper_search_originator") originator_filter = page.find('select#paper_search_originator')
expect(originator_filter).to have_css("option", text: "Dezernat Jugend, Soziales, Gesundheit und Schule (2)") expect(originator_filter).to have_css('option', text: 'Dezernat Jugend, Soziales, Gesundheit und Schule (2)')
expect(originator_filter).not_to have_css("option", text: "Oberbürgermeister") expect(originator_filter).not_to have_css('option', text: 'Oberbürgermeister')
end end
scenario "Filtering by originator", js: true do scenario 'Filtering by originator', js: true do
visit search_path body: "leipzig" visit search_path body: 'leipzig'
expect(page).to have_css("li.search-result", count: 4) expect(page).to have_css('li.search-result', count: 4)
select "Oberbürgermeister (1)", from: "Einreicher" select 'Oberbürgermeister (1)', from: 'Einreicher'
expect(page).to have_css("li.search-result", count: 1, text: "Ampeln") expect(page).to have_css('li.search-result', count: 1, text: 'Ampeln')
end end
end end

View file

@ -1,22 +1,24 @@
# frozen_string_literal: true
require 'rails_helper' require 'rails_helper'
RSpec.describe Paper do RSpec.describe Paper do
context "Validations" do context 'Validations' do
it { should validate_presence_of(:name) } it { should validate_presence_of(:name) }
it { should validate_length_of(:name).is_at_most(1000) } it { should validate_length_of(:name).is_at_most(1000) }
it { should validate_presence_of(:url) } it { should validate_presence_of(:url) }
it { should validate_length_of(:url).is_at_most(1000) } it { should validate_length_of(:url).is_at_most(1000) }
context "URL uniqueness" do context 'URL uniqueness' do
subject { FactoryBot.build(:paper) } subject { FactoryBot.build(:paper) }
it { should validate_uniqueness_of(:url) } it { should validate_uniqueness_of(:url) }
end end
it "validate url format sane" do it 'validate url format sane' do
expected_error = "ist keine gültige URL" expected_error = 'ist keine gültige URL'
paper = FactoryBot.build(:paper, url: "wtf") paper = FactoryBot.build(:paper, url: 'wtf')
expect(paper).not_to be_valid, "Expected paper to not be valid with invalid URL" expect(paper).not_to be_valid, 'Expected paper to not be valid with invalid URL'
expect(paper.errors[:url]).not_to be_empty expect(paper.errors[:url]).not_to be_empty
expect(paper.errors[:url]).to include(expected_error), "Expected #{paper.errors[:url]} to include \"#{expected_error}\"" expect(paper.errors[:url]).to include(expected_error), "Expected #{paper.errors[:url]} to include \"#{expected_error}\""
end end
@ -36,11 +38,11 @@ RSpec.describe Paper do
it { should validate_presence_of(:paper_type) } it { should validate_presence_of(:paper_type) }
it { should validate_length_of(:paper_type).is_at_most(50) } it { should validate_length_of(:paper_type).is_at_most(50) }
context "published_at" do context 'published_at' do
it { should validate_presence_of(:published_at) } it { should validate_presence_of(:published_at) }
it "validate date is parseable" do it 'validate date is parseable' do
expected_error = "ist kein gültiges Datum" expected_error = 'ist kein gültiges Datum'
paper = FactoryBot.build(:paper, published_at: "fubar") paper = FactoryBot.build(:paper, published_at: 'fubar')
expect(paper).not_to be_valid expect(paper).not_to be_valid
expect(paper.errors[:published_at]).not_to be_empty expect(paper.errors[:published_at]).not_to be_empty
expect(paper.errors[:published_at]).to include(expected_error), "Expected #{paper.errors[:published_at]} to include \"#{expected_error}\"" expect(paper.errors[:published_at]).to include(expected_error), "Expected #{paper.errors[:published_at]} to include \"#{expected_error}\""

View file

@ -1,8 +1,12 @@
# frozen_string_literal: true
# This file is copied to spec/ when you run 'rails generate rspec:install' # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV['RAILS_ENV'] ||= 'test' ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__) require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production # Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production? if Rails.env.production?
abort('The Rails environment is running in production mode!')
end
require 'spec_helper' require 'spec_helper'
require 'rspec/rails' require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point! # Add additional requires below this line. Rails is not loaded until this point!
@ -20,7 +24,7 @@ require 'rspec/rails'
# directory. Alternatively, in the individual `*_spec.rb` files, manually # directory. Alternatively, in the individual `*_spec.rb` files, manually
# require only the support files necessary. # require only the support files necessary.
# #
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f }
# Checks for pending migrations before tests are run. # Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line. # If you are not using ActiveRecord, you can remove this line.

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'coveralls' require 'coveralls'
Coveralls.wear!('rails') Coveralls.wear!('rails')
@ -43,53 +45,51 @@ RSpec.configure do |config|
mocks.verify_partial_doubles = true mocks.verify_partial_doubles = true
end end
# The settings below are suggested to provide a good initial experience # The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content. # with RSpec, but feel free to customize to your heart's content.
=begin # # These two settings work together to allow you to limit a spec run
# These two settings work together to allow you to limit a spec run # # to individual examples or groups you care about by tagging them with
# to individual examples or groups you care about by tagging them with # # `:focus` metadata. When nothing is tagged with `:focus`, all examples
# `:focus` metadata. When nothing is tagged with `:focus`, all examples # # get run.
# get run. # config.filter_run :focus
config.filter_run :focus # config.run_all_when_everything_filtered = true
config.run_all_when_everything_filtered = true #
# # Allows RSpec to persist some state between runs in order to support
# Allows RSpec to persist some state between runs in order to support # # the `--only-failures` and `--next-failure` CLI options. We recommend
# the `--only-failures` and `--next-failure` CLI options. We recommend # # you configure your source control system to ignore this file.
# you configure your source control system to ignore this file. # config.example_status_persistence_file_path = "spec/examples.txt"
config.example_status_persistence_file_path = "spec/examples.txt" #
# # Limits the available syntax to the non-monkey patched syntax that is
# Limits the available syntax to the non-monkey patched syntax that is # # recommended. For more details, see:
# recommended. For more details, see: # # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ # # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching # config.disable_monkey_patching!
config.disable_monkey_patching! #
# # Many RSpec users commonly either run the entire suite or an individual
# Many RSpec users commonly either run the entire suite or an individual # # file, and it's useful to allow more verbose output when running an
# file, and it's useful to allow more verbose output when running an # # individual spec file.
# individual spec file. # if config.files_to_run.one?
if config.files_to_run.one? # # Use the documentation formatter for detailed output,
# Use the documentation formatter for detailed output, # # unless a formatter has already been configured
# unless a formatter has already been configured # # (e.g. via a command-line flag).
# (e.g. via a command-line flag). # config.default_formatter = 'doc'
config.default_formatter = 'doc' # end
end #
# # Print the 10 slowest examples and example groups at the
# Print the 10 slowest examples and example groups at the # # end of the spec run, to help surface which specs are running
# end of the spec run, to help surface which specs are running # # particularly slow.
# particularly slow. # config.profile_examples = 10
config.profile_examples = 10 #
# # Run specs in random order to surface order dependencies. If you find an
# Run specs in random order to surface order dependencies. If you find an # # order dependency and want to debug it, you can fix the order by providing
# order dependency and want to debug it, you can fix the order by providing # # the seed, which is printed after each run.
# the seed, which is printed after each run. # # --seed 1234
# --seed 1234 # config.order = :random
config.order = :random #
# # Seed global randomization in this process using the `--seed` CLI option.
# Seed global randomization in this process using the `--seed` CLI option. # # Setting this allows you to use `--seed` to deterministically reproduce
# Setting this allows you to use `--seed` to deterministically reproduce # # test failures related to randomization by passing the same `--seed` value
# test failures related to randomization by passing the same `--seed` value # # as the one that triggered the failure.
# as the one that triggered the failure. # Kernel.srand config.seed
Kernel.srand config.seed
=end
end end

View file

@ -1,10 +1,12 @@
# frozen_string_literal: true
require 'capybara/apparition' require 'capybara/apparition'
Capybara.register_driver :apparition do |app| Capybara.register_driver :apparition do |app|
Capybara::Apparition::Driver.new( Capybara::Apparition::Driver.new(
app, app,
headless: true, headless: true,
browser_options: [ :no_sandbox, disable_features: 'VizDisplayCompositor'] browser_options: [:no_sandbox, disable_features: 'VizDisplayCompositor']
) )
end end
Capybara.javascript_driver = :apparition Capybara.javascript_driver = :apparition

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.configure do |config| RSpec.configure do |config|
config.before(:suite) do config.before(:suite) do
DatabaseCleaner.clean_with(:truncation) DatabaseCleaner.clean_with(:truncation)
@ -18,5 +20,4 @@ RSpec.configure do |config|
config.append_after(:each) do config.append_after(:each) do
DatabaseCleaner.clean DatabaseCleaner.clean
end end
end end

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
RSpec.configure do |config| RSpec.configure do |config|
config.before :each, elasticsearch: true do config.before :each, elasticsearch: true do
Paper.__elasticsearch__.create_index!(force: true) Paper.__elasticsearch__.create_index!(force: true)
Elasticsearch::Model.client.cluster.health wait_for_status: "yellow" Elasticsearch::Model.client.cluster.health wait_for_status: 'yellow'
end end
end end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
RSpec.configure do |config| RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods config.include FactoryBot::Syntax::Methods
end end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
Shoulda::Matchers.configure do |config| Shoulda::Matchers.configure do |config|
config.integrate do |with| config.integrate do |with|
with.test_framework :rspec with.test_framework :rspec