Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # spec/sphinx_helper.rb
- # frozen_string_literal: true
- require 'rails_helper'
- RSpec.configure do |config|
- config.use_transactional_fixtures = false
- # DatabaseCleaner settings
- config.before(:suite) do
- DatabaseCleaner.clean_with(:truncation)
- # Ensure sphinx directories exist for the test environment
- ThinkingSphinx::Test.init
- # Configure and start Sphinx, and automatically stop Sphinx at the end of the test suite.
- ThinkingSphinx::Test.start_with_autostop
- end
- config.before(:each) do
- DatabaseCleaner.strategy = :transaction
- end
- config.before(:each, sphinx: true) do
- DatabaseCleaner.strategy = :truncation
- # Index data when running an acceptance spec.
- ThinkingSphinx::Test.index
- end
- config.before(:each) do
- DatabaseCleaner.start
- end
- config.after(:each) do
- DatabaseCleaner.clean
- end
- end
- # spec/features/search/search_spec.rb
- require 'sphinx_helper'
- feature 'user can search on the site', %q{
- As an user
- Id like to be able to search on site materials
- } do
- given!(:user) { create(:user, username: 'Reality') }
- given!(:review) { create(:review, author: user, title: 'My Nightmares Turned into Reality') }
- given!(:reviews) { create_list(:review, 2) }
- background do
- visit root_path
- end
- scenario 'by everywhere', sphinx: true, js: true do
- ThinkingSphinx::Test.run do
- search(user.username)
- within('.results') do
- expect(page).to have_content(user.username, count: 2)
- reviews.each do |review|
- expect(page).to_not have_content(review.title)
- end
- end
- end
- end
- private
- def search(query, by: 'site')
- within('.search') do
- fill_in :search_query, with: query
- select by, from: :search_type
- click_on 'go'
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement