Merge pull request #30 from CodeforLeipzig/more-tests

Add more tests
This commit is contained in:
Joerg Reichert 2016-04-12 21:03:46 +02:00
commit 568da30c54
7 changed files with 109 additions and 2 deletions

View file

@ -1,9 +1,13 @@
FROM ruby:2.2
RUN apt-get update && apt-get install -y build-essential zlib1g-dev libsqlite3-dev nodejs nodejs-legacy
RUN apt-get update && apt-get install -y build-essential zlib1g-dev libsqlite3-dev nodejs nodejs-legacy npm
RUN npm install phantomjs-prebuilt
RUN ln -sf /node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs /usr/local/bin/
RUN mkdir -p /app
WORKDIR /tmp
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN bundle install

View file

@ -64,6 +64,7 @@ group :test do
gem 'test_after_commit' # TODO remove when moving to rails 5
gem 'database_cleaner'
gem 'coveralls', require: false
gem 'poltergeist'
end
# Use ActiveModel has_secure_password

View file

@ -46,6 +46,7 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
cliver (0.3.2)
coderay (1.1.0)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
@ -153,6 +154,11 @@ GEM
faraday
multi_json
omniauth (~> 1.0)
poltergeist (1.9.0)
capybara (~> 2.1)
cliver (~> 0.3.1)
multi_json (~> 1.0)
websocket-driver (>= 0.2.0)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@ -283,6 +289,9 @@ GEM
validate_url (1.0.2)
activemodel (>= 3.0.0)
addressable
websocket-driver (0.6.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
win32console (1.3.2)
xpath (2.0.0)
nokogiri (~> 1.3)
@ -310,6 +319,7 @@ DEPENDENCIES
launchy
omniauth
omniauth-browserid
poltergeist
pry
pry-rails
quiet_assets

View file

@ -8,7 +8,7 @@ div
.right
/ button.button. TODO: Suche Abbonieren
- else
| #{@papers.total} Dokumente in der Datenbank
| #{pluralize(@papers.total, "Dokument", "Dokumente")} in der Datenbank
div
ul.no-bullet#search_results
- @papers.each do |doc|

View file

@ -53,4 +53,25 @@ RSpec.feature "Basic search", type: :feature, elasticsearch: true do
expect(result).to have_css("span.published", text: I18n.l(paper.published_at.to_date))
end
scenario "Finds papers by name" do
paper = FactoryGirl.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")
result = page.find("li.search-result", match: :first)
expect(result).to have_link(paper.name, href: paper.url)
end
scenario "Finds papers by content" do
paper = FactoryGirl.create(:paper,
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")
result = page.find("li.search-result", match: :first)
expect(result).to have_link(paper.name, href: paper.url)
end
end

View file

@ -0,0 +1,69 @@
require 'rails_helper'
RSpec.feature "Search filters", type: :feature, elasticsearch: true do
before(:each) do
@antrag = FactoryGirl.create(:paper,
paper_type: "Antrag",
name: "Mehr Spielplätze in Leipzig",
originator: "Dezernat Jugend, Soziales, Gesundheit und Schule"
)
@anfrage = FactoryGirl.create(:paper,
paper_type: "Anfrage",
originator: "CDU-Fraktion"
)
@vorlage_1 = FactoryGirl.create(:paper,
paper_type: "Vorlage",
name: "Zustand der Spielplätze",
originator: "Dezernat Jugend, Soziales, Gesundheit und Schule"
)
@vorlage_2 = FactoryGirl.create(:paper,
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)")
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")
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)")
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")
end
end

2
spec/support/capybara.rb Normal file
View file

@ -0,0 +1,2 @@
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist