From 5c2e1bfe1e9d06769756890d44c254d8d520f588 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Mon, 9 Mar 2020 11:27:52 +0100 Subject: [PATCH] Rubocop autocorrect specs --- spec/controllers/search_controller_spec.rb | 32 ++- spec/factories/papers.rb | 10 +- spec/factory_helper.rb | 34 ++-- spec/features/basic_search_spec.rb | 217 ++++++++++----------- spec/features/search_filters_spec.rb | 94 +++++---- spec/models/paper_spec.rb | 30 +-- spec/rails_helper.rb | 10 +- spec/spec_helper.rb | 98 +++++----- spec/support/capybara.rb | 12 +- spec/support/database_cleaner.rb | 3 +- spec/support/elasticsearch.rb | 4 +- spec/support/factory_bot.rb | 2 + spec/support/shoulda.rb | 2 + 13 files changed, 279 insertions(+), 269 deletions(-) diff --git a/spec/controllers/search_controller_spec.rb b/spec/controllers/search_controller_spec.rb index 171b17f..881856c 100644 --- a/spec/controllers/search_controller_spec.rb +++ b/spec/controllers/search_controller_spec.rb @@ -1,48 +1,46 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe SearchController, type: :controller, elasticsearch: true do - - describe "GET #index" do - it "returns http success" do + describe 'GET #index' do + it 'returns http success' do get :index, body: 'leipzig' expect(response).to have_http_status(:success) 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') get :index, body: 'leipzig' expect(assigns(:search_definition).attributes).to eq(search.attributes) end - it "renders the index template" do + it 'renders the index template' do get :index, body: 'leipzig' expect(response).to render_template(:index) end - it "executes the search with PaperSearch parameters" do - pending("simplify search implementation") - result_page = double("page", results: []) # MEH - response = double("es_response", page: result_page) + it 'executes the search with PaperSearch parameters' do + pending('simplify search implementation') + result_page = double('page', results: []) # MEH + response = double('es_response', page: result_page) expect(Paper).to receive(:search).and_return(response) get :index, body: 'leipzig' end - - it "returns rss" do - get :index, :format => "rss", body: 'leipzig' + it 'returns rss' do + get :index, format: 'rss', body: 'leipzig' expect(response).to be_success expect(response).to render_template(:index) - expect(response.content_type).to eq("application/rss+xml") - #expect(response.body).to have_tag "rss" do + expect(response.content_type).to eq('application/rss+xml') + # expect(response.body).to have_tag "rss" do # with_tag "channel" do # with_tag "title" # with_tag "description" # with_tag "link" # end - #end + # end end - end - end diff --git a/spec/factories/papers.rb b/spec/factories/papers.rb index 85f0c98..40da37a 100644 --- a/spec/factories/papers.rb +++ b/spec/factories/papers.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + require_relative '../factory_helper' FactoryBot.define do factory :paper do 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) } - body { "leipzig" } - published_at { "2015-07-20 21:16:53" } - scraped_at { "2015-07-20 21:16:53" } + body { 'leipzig' } + published_at { '2015-07-20 21:16:53' } + scraped_at { '2015-07-20 21:16:53' } paper_type { FactoryHelper.paper_type } originator { Faker::Name.name } resolution { Faker::Lorem.paragraph(sentence_count: 3) } diff --git a/spec/factory_helper.rb b/spec/factory_helper.rb index 95f08db..0d9266a 100644 --- a/spec/factory_helper.rb +++ b/spec/factory_helper.rb @@ -1,29 +1,29 @@ -module FactoryHelper +# frozen_string_literal: true +module FactoryHelper PAPER_TYPES = [ - "Verwaltungsstandpunkt", - "Anfrage", - "Beschlussvorlage", - "Änderungsantrag", - "Antrag", - "Neufassung", - "Informationsvorlage", - "Einwohneranfrage", - "Petition", - "schriftliche Antwort zur Anfrage", - "Wichtige Angelegenheit", - "Eilentscheidung", - "Dringliche Anfrage" - ] + 'Verwaltungsstandpunkt', + 'Anfrage', + 'Beschlussvorlage', + 'Änderungsantrag', + 'Antrag', + 'Neufassung', + 'Informationsvorlage', + 'Einwohneranfrage', + 'Petition', + 'schriftliche Antwort zur Anfrage', + 'Wichtige Angelegenheit', + 'Eilentscheidung', + 'Dringliche Anfrage' + ].freeze def self.paper_type PAPER_TYPES.sample end - REFERENCE = "A-%05i/16" + REFERENCE = 'A-%05i/16' def self.reference(seq) REFERENCE % seq end - end diff --git a/spec/features/basic_search_spec.rb b/spec/features/basic_search_spec.rb index 3cae8fc..86c2c11 100644 --- a/spec/features/basic_search_spec.rb +++ b/spec/features/basic_search_spec.rb @@ -1,130 +1,130 @@ +# frozen_string_literal: true + require 'rails_helper' require 'pp' -RSpec.feature "Basic search", type: :feature, elasticsearch: true do - +RSpec.feature 'Basic search', type: :feature, elasticsearch: true do before(:each) do @papers = FactoryBot.create_list(:paper, 11) Paper.__elasticsearch__.refresh_index! end - scenario "It displays the search form" do - visit search_path body: "leipzig" - expect(page).to have_content("Stadtratmonitor") - expect(page).to have_field("paper_search_query") - expect(page).to have_select("Typ") - expect(page).to have_select("Einreicher") - 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_score", type: "radio") + scenario 'It displays the search form' do + visit search_path body: 'leipzig' + expect(page).to have_content('Stadtratmonitor') + expect(page).to have_field('paper_search_query') + expect(page).to have_select('Typ') + expect(page).to have_select('Einreicher') + 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_score', type: 'radio') end - scenario "With empty query displays all documents" do - visit search_path body: "leipzig" - expect(page).to have_selector("ul#search_results") + scenario 'With empty query displays all documents' do + visit search_path body: 'leipzig' + expect(page).to have_selector('ul#search_results') expect(page).to have_content("#{@papers.size} Dokumente in der Datenbank") end - scenario "Search results are paginated" do - visit search_path body: "leipzig" - expect(page).to have_css("li.search-result", count: 10) - expect(page).to have_css("div#pagination") - within("div#pagination") do - 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_link("2") - expect(page).to have_link("Weiter") - expect(page).to have_link("Ende") + scenario 'Search results are paginated' do + visit search_path body: 'leipzig' + expect(page).to have_css('li.search-result', count: 10) + expect(page).to have_css('div#pagination') + within('div#pagination') do + 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_link('2') + expect(page).to have_link('Weiter') + expect(page).to have_link('Ende') end - page.find("div#pagination").click_link("2") - expect(page).to have_css("li.search-result", count: 1) - within("div#pagination") do - expect(page).to have_css("li.current", text: "2") + page.find('div#pagination').click_link('2') + expect(page).to have_css('li.search-result', count: 1) + within('div#pagination') do + expect(page).to have_css('li.current', text: '2') end end - scenario "Search results have basic information" do - visit search_path body: "leipzig" + scenario 'Search results have basic information' do + visit search_path body: 'leipzig' 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) - resultSubEntry = resultEntry.find("li.current", match: :first) + resultSubEntry = resultEntry.find('li.current', match: :first) linkName = getLinkName(paper) expect(resultSubEntry).to have_link(linkName, href: paper.url) end def getLinkName(paper) dateStr = I18n.l(paper.published_at.to_date) - originatorStr = (paper.originator.kind_of?(Array) ? - paper.originator.join(", ") : paper.originator) - return "#{dateStr}: #{paper.paper_type} von #{originatorStr}" + originatorStr = (paper.originator.is_a?(Array) ? + paper.originator.join(', ') : paper.originator) + "#{dateStr}: #{paper.paper_type} von #{originatorStr}" end - scenario "Finds papers by name" do - paper = FactoryBot.create(:paper, name: "Opendata als default") + scenario 'Finds papers by name' do + paper = FactoryBot.create(:paper, name: 'Opendata als default') 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) + 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) - resultSubEntry = resultEntry.find("li.current", match: :first) + resultSubEntry = resultEntry.find('li.current', match: :first) linkName = getLinkName(paper) expect(resultSubEntry).to have_link(linkName, href: paper.url) end - scenario "Finds papers by content" do + scenario 'Finds papers by content' do paper = FactoryBot.create(:paper, - name: "Opendata als default", - content: "Alle Verwaltungsdokumente werden als Opendata veröffentlicht" - ) + name: 'Opendata als default', + content: 'Alle Verwaltungsdokumente werden als Opendata veröffentlicht') 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) + 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) - resultSubEntry = resultEntry.find("li.current", match: :first) + resultSubEntry = resultEntry.find('li.current', match: :first) linkName = getLinkName(paper) expect(resultSubEntry).to have_link(linkName, href: paper.url) 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', - 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', - name: "Opendata als optional", reference: "VI-0815-ÄA-01") + 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) + 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) + 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") + 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 + 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") + 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") + name: 'Opendata als optional', reference: 'VI-0815-ÄA-02') 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! - 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) + 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) - resultSubEntries = resultEntry.find("ul").all("li") + resultSubEntries = resultEntry.find('ul').all('li') linkName1 = getLinkName(newPaper1) expect(resultSubEntries[0]).to have_link(linkName1, href: newPaper1.url) 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) 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', - 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', - 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', - 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! - 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) + 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) - resultSubEntries = resultEntry.find("ul").all("li") + resultSubEntries = resultEntry.find('ul').all('li') linkName1 = getLinkName(newPaper1) expect(resultSubEntries[0]).to have_link(linkName1, href: newPaper1.url) linkName2 = getLinkName(newPaper1Change) @@ -155,85 +155,84 @@ RSpec.feature "Basic search", type: :feature, elasticsearch: true do end scenario "Finds 'Testen' with search 'Test'" do - paper = FactoryBot.create(:paper, name: "Testen") + paper = FactoryBot.create(:paper, name: 'Testen') 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) + 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) end scenario "Finds 'Test' with search 'Testen'" do - paper = FactoryBot.create(:paper, name: "Test") + paper = FactoryBot.create(:paper, name: 'Test') 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) + 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) end 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! - 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) + 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) end 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! - 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) + 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) end 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! - 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) + 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) end 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! - 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) + 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) end scenario "Finds no 'Fahrrad' with search 'Rad'" do - paper = FactoryBot.create(:paper, name: "Fahrrad") + paper = FactoryBot.create(:paper, name: 'Fahrrad') Paper.__elasticsearch__.refresh_index! - visit search_path body: "leipzig", paper_search: {query: "Rad"} - expect(page).to have_content("0 Dokumente in der Datenbank") + visit search_path body: 'leipzig', paper_search: { query: 'Rad' } + expect(page).to have_content('0 Dokumente in der Datenbank') 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', - 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', - name: "Opendata als optional", reference: "VI-00768/14-ÄA-01") + 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) + 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) + 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") + 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 - end diff --git a/spec/features/search_filters_spec.rb b/spec/features/search_filters_spec.rb index 8c5000f..dcd3a73 100644 --- a/spec/features/search_filters_spec.rb +++ b/spec/features/search_filters_spec.rb @@ -1,69 +1,65 @@ +# frozen_string_literal: true + require 'rails_helper' -RSpec.feature "Search filters", type: :feature, elasticsearch: true do - +RSpec.feature 'Search filters', type: :feature, elasticsearch: true do before(:each) do @antrag = FactoryBot.create(:paper, - paper_type: "Antrag", - name: "Mehr Spielplätze in Leipzig", - originator: "Dezernat Jugend, Soziales, Gesundheit und Schule" - ) + paper_type: 'Antrag', + name: 'Mehr Spielplätze in Leipzig', + originator: 'Dezernat Jugend, Soziales, Gesundheit und Schule') @anfrage = FactoryBot.create(:paper, - paper_type: "Anfrage", - originator: "CDU-Fraktion" - ) + paper_type: 'Anfrage', + originator: 'CDU-Fraktion') @vorlage_1 = FactoryBot.create(:paper, - paper_type: "Vorlage", - name: "Zustand der Spielplätze", - originator: "Dezernat Jugend, Soziales, Gesundheit und Schule" - ) + paper_type: 'Vorlage', + name: 'Zustand der Spielplätze', + originator: 'Dezernat Jugend, Soziales, Gesundheit und Schule') @vorlage_2 = FactoryBot.create(:paper, - paper_type: "Vorlage", - name: "Mehr Ampeln in der Innenstadt", - originator: "Oberbürgermeister" - ) + paper_type: 'Vorlage', + name: 'Mehr Ampeln in der Innenstadt', + originator: 'Oberbürgermeister') Paper.__elasticsearch__.refresh_index! end - scenario "Displays paper types and their respective count witin the search results" do - visit search_path body: "leipzig" - 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: "Anfrage (1)") - expect(paper_type_filter).to have_css("option", text: "Vorlage (2)") + scenario 'Displays paper types and their respective count witin the search results' do + visit search_path body: 'leipzig' + 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: 'Anfrage (1)') + expect(paper_type_filter).to have_css('option', text: 'Vorlage (2)') - visit search_path body: "leipzig", paper_search: {query: "Spielplätze"} - 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).not_to have_css("option", text: "Anfrage") - expect(paper_type_filter).to have_css("option", text: "Vorlage (1)") + visit search_path body: 'leipzig', paper_search: { query: 'Spielplätze' } + 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).not_to have_css('option', text: 'Anfrage') + expect(paper_type_filter).to have_css('option', text: 'Vorlage (1)') end - scenario "Filtering by paper type", js: true do - visit search_path body: "leipzig" - expect(page).to have_css("li.search-result", count: 4) - select "Antrag (1)", from: "Typ" - expect(page).to have_css("li.search-result", count: 1, text: "Spielplätze") + scenario 'Filtering by paper type', js: true do + visit search_path body: 'leipzig' + expect(page).to have_css('li.search-result', count: 4) + select 'Antrag (1)', from: 'Typ' + expect(page).to have_css('li.search-result', count: 1, text: 'Spielplätze') end - scenario "Displays originators and their respective count within the search results" do - visit search_path body: "leipzig" - 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: "Dezernat Jugend, Soziales, Gesundheit und Schule (2)") - expect(originator_filter).to have_css("option", text: "Oberbürgermeister (1)") + scenario 'Displays originators and their respective count within the search results' do + visit search_path body: 'leipzig' + 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: 'Dezernat Jugend, Soziales, Gesundheit und Schule (2)') + expect(originator_filter).to have_css('option', text: 'Oberbürgermeister (1)') - visit search_path body: "leipzig", paper_search: {query: "Spielplätze"} - 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).not_to have_css("option", text: "Oberbürgermeister") + visit search_path body: 'leipzig', paper_search: { query: 'Spielplätze' } + 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).not_to have_css('option', text: 'Oberbürgermeister') end - scenario "Filtering by originator", js: true do - visit search_path body: "leipzig" - expect(page).to have_css("li.search-result", count: 4) - select "Oberbürgermeister (1)", from: "Einreicher" - expect(page).to have_css("li.search-result", count: 1, text: "Ampeln") + scenario 'Filtering by originator', js: true do + visit search_path body: 'leipzig' + expect(page).to have_css('li.search-result', count: 4) + select 'Oberbürgermeister (1)', from: 'Einreicher' + expect(page).to have_css('li.search-result', count: 1, text: 'Ampeln') end - end diff --git a/spec/models/paper_spec.rb b/spec/models/paper_spec.rb index d87a4cb..58bbc90 100644 --- a/spec/models/paper_spec.rb +++ b/spec/models/paper_spec.rb @@ -1,22 +1,24 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Paper do - context "Validations" do + context 'Validations' do 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_length_of(:url).is_at_most(1000) } - - context "URL uniqueness" do + + context 'URL uniqueness' do subject { FactoryBot.build(:paper) } it { should validate_uniqueness_of(:url) } end - - it "validate url format sane" do - expected_error = "ist keine gültige URL" - paper = FactoryBot.build(:paper, url: "wtf") - expect(paper).not_to be_valid, "Expected paper to not be valid with invalid URL" + + it 'validate url format sane' do + expected_error = 'ist keine gültige URL' + paper = FactoryBot.build(:paper, url: 'wtf') + 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]).to include(expected_error), "Expected #{paper.errors[:url]} to include \"#{expected_error}\"" end @@ -36,11 +38,11 @@ RSpec.describe Paper do it { should validate_presence_of(:paper_type) } 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 "validate date is parseable" do - expected_error = "ist kein gültiges Datum" - paper = FactoryBot.build(:paper, published_at: "fubar") + it 'validate date is parseable' do + expected_error = 'ist kein gültiges Datum' + paper = FactoryBot.build(:paper, published_at: 'fubar') expect(paper).not_to be_valid 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}\"" diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 02f950a..f319df4 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -1,8 +1,12 @@ +# frozen_string_literal: true + # This file is copied to spec/ when you run 'rails generate rspec:install' 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 -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 'rspec/rails' # 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 # 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. # If you are not using ActiveRecord, you can remove this line. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ec9b032..01c5ea7 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'coveralls' Coveralls.wear!('rails') @@ -43,53 +45,51 @@ RSpec.configure do |config| mocks.verify_partial_doubles = true end -# The settings below are suggested to provide a good initial experience -# 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 - # to individual examples or groups you care about by tagging them with - # `:focus` metadata. When nothing is tagged with `:focus`, all examples - # get run. - config.filter_run :focus - config.run_all_when_everything_filtered = true - - # Allows RSpec to persist some state between runs in order to support - # the `--only-failures` and `--next-failure` CLI options. We recommend - # you configure your source control system to ignore this file. - config.example_status_persistence_file_path = "spec/examples.txt" - - # Limits the available syntax to the non-monkey patched syntax that is - # recommended. For more details, see: - # - 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://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching - config.disable_monkey_patching! - - # 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 - # individual spec file. - if config.files_to_run.one? - # Use the documentation formatter for detailed output, - # unless a formatter has already been configured - # (e.g. via a command-line flag). - config.default_formatter = 'doc' - end - - # Print the 10 slowest examples and example groups at the - # end of the spec run, to help surface which specs are running - # particularly slow. - config.profile_examples = 10 - - # 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 - # the seed, which is printed after each run. - # --seed 1234 - config.order = :random - - # Seed global randomization in this process using the `--seed` CLI option. - # Setting this allows you to use `--seed` to deterministically reproduce - # test failures related to randomization by passing the same `--seed` value - # as the one that triggered the failure. - Kernel.srand config.seed -=end + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # 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 + # # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # # get run. + # config.filter_run :focus + # config.run_all_when_everything_filtered = true + # + # # Allows RSpec to persist some state between runs in order to support + # # the `--only-failures` and `--next-failure` CLI options. We recommend + # # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + # + # # Limits the available syntax to the non-monkey patched syntax that is + # # recommended. For more details, see: + # # - 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://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching + # config.disable_monkey_patching! + # + # # 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 + # # individual spec file. + # if config.files_to_run.one? + # # Use the documentation formatter for detailed output, + # # unless a formatter has already been configured + # # (e.g. via a command-line flag). + # config.default_formatter = 'doc' + # end + # + # # Print the 10 slowest examples and example groups at the + # # end of the spec run, to help surface which specs are running + # # particularly slow. + # config.profile_examples = 10 + # + # # 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 + # # the seed, which is printed after each run. + # # --seed 1234 + # config.order = :random + # + # # Seed global randomization in this process using the `--seed` CLI option. + # # Setting this allows you to use `--seed` to deterministically reproduce + # # test failures related to randomization by passing the same `--seed` value + # # as the one that triggered the failure. + # Kernel.srand config.seed end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 83c32b5..b67a22d 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'capybara/apparition' Capybara.register_driver :apparition do |app| - Capybara::Apparition::Driver.new( - app, - headless: true, - browser_options: [ :no_sandbox, disable_features: 'VizDisplayCompositor'] - ) + Capybara::Apparition::Driver.new( + app, + headless: true, + browser_options: [:no_sandbox, disable_features: 'VizDisplayCompositor'] + ) end Capybara.javascript_driver = :apparition diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 46147b0..2371e82 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.configure do |config| config.before(:suite) do DatabaseCleaner.clean_with(:truncation) @@ -18,5 +20,4 @@ RSpec.configure do |config| config.append_after(:each) do DatabaseCleaner.clean end - end diff --git a/spec/support/elasticsearch.rb b/spec/support/elasticsearch.rb index 2a3f246..0f9f749 100644 --- a/spec/support/elasticsearch.rb +++ b/spec/support/elasticsearch.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + RSpec.configure do |config| config.before :each, elasticsearch: true do 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 diff --git a/spec/support/factory_bot.rb b/spec/support/factory_bot.rb index c7890e4..2e7665c 100644 --- a/spec/support/factory_bot.rb +++ b/spec/support/factory_bot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + RSpec.configure do |config| config.include FactoryBot::Syntax::Methods end diff --git a/spec/support/shoulda.rb b/spec/support/shoulda.rb index 7d045f3..edcf9dd 100644 --- a/spec/support/shoulda.rb +++ b/spec/support/shoulda.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Shoulda::Matchers.configure do |config| config.integrate do |with| with.test_framework :rspec