View difference between Paste ID: 9m7WbvN7 and gd1y7FED
SHOW: | | - or go back to the newest paste.
1
# spec/sphinx_helper.rb
2
# frozen_string_literal: true
3
4
require 'rails_helper'
5
6
RSpec.configure do |config|
7
  config.use_transactional_fixtures = false
8
9
  # DatabaseCleaner settings
10
  config.before(:suite) do
11
    DatabaseCleaner.clean_with(:truncation)
12
    # Ensure sphinx directories exist for the test environment
13
    ThinkingSphinx::Test.init
14
    # Configure and start Sphinx, and automatically stop Sphinx at the end of the test suite.
15
    ThinkingSphinx::Test.start_with_autostop
16
  end
17
18
  config.before(:each) do
19
    DatabaseCleaner.strategy = :transaction
20
  end
21
22
  config.before(:each, sphinx: true) do
23
    DatabaseCleaner.strategy = :truncation
24
    # Index data when running an acceptance spec.
25
    ThinkingSphinx::Test.index
26
  end
27
28
  config.before(:each) do
29
    DatabaseCleaner.start
30
  end
31
32
  config.after(:each) do
33
    DatabaseCleaner.clean
34
  end
35
end
36
37
# spec/features/search/search_spec.rb
38
require 'sphinx_helper'
39
40
feature 'user can search on the site', %q{
41
  As an user
42
  Id like to be able to search on site materials
43
} do
44
45
  given!(:user) { create(:user, username: 'Reality') }
46
  given!(:review) { create(:review, author: user, title: 'My Nightmares Turned into Reality') }
47
  given!(:reviews) { create_list(:review, 2) }
48
49
  background do
50
    visit root_path
51
  end
52
53
  scenario 'by everywhere', sphinx: true, js: true do
54
    ThinkingSphinx::Test.run do
55
      search(user.username)
56
57
      within('.results') do
58
        expect(page).to have_content(user.username, count: 2)
59
60
        reviews.each do |review|
61
          expect(page).to_not have_content(review.title)
62
        end
63
      end
64
    end
65
  end
66
67
  private
68
69
  def search(query, by: 'site')
70
    within('.search') do
71
      fill_in :search_query, with: query
72
      select by, from: :search_type
73
      click_on 'go'
74
    end
75
  end
76
end
77