Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
sunspot-rails-tester
Advanced tools
This gem allows you to "turn on" solr for certain portions of your tests. For the code that does not use solr, you would want to "stub" sunspot to avoid unneeded indexing.
Here is an example RSpec 2 spec_helper.rb:
$original_sunspot_session = Sunspot.session
RSpec.configure do |config|
config.before do
Sunspot.session = Sunspot::Rails::StubSessionProxy.new($original_sunspot_session)
end
config.before :each, :solr => true do
Sunspot::Rails::Tester.start_original_sunspot_session
Sunspot.session = $original_sunspot_session
Sunspot.remove_all!
end
end
Let's go through what the above code does.
$original_sunspot_session
stores the original sunspot
session. By default, sunspot_rails uses the SessionProxy::ThreadLocalSessionProxy
.
In the first before
block, we set the session to a stub session for
every example. Sunspot::Rails::StubSessionProxy
is just a dummy class
that skips indexing.
In the second before
block, we use RSpec 2's metadata feature by
adding :solr => true
. Any example or example group with this metadata
will run the original sunspot session.
Sunspot::Rails::Tester.start_original_sunspot_session
starts the solr instance
if it's not running.
Here is an example spec that utilizes sunspot-rails-tester:
require 'spec_helper'
describe 'search page' do
it 'highlights the active tab in the navigation' do
# uses the stub session
end
it 'finds and displays a person', :solr => true do
# uses actual solr - indexing will happen
end
end
To get this gem to work with Spork, all you need to do is move the start_original_sunspot_session
line out of the RSpec.configure
block:
$original_sunspot_session = Sunspot.session
Sunspot::Rails::Tester.start_original_sunspot_session
RSpec.configure do |config|
config.before do
Sunspot.session = Sunspot::Rails::StubSessionProxy.new($original_sunspot_session)
end
config.before :each, :solr => true do
Sunspot.session = $original_sunspot_session
Sunspot.remove_all!
end
end
The following articles served as guidance and inspiration for this gem:
sunspot-rails-tester is released under the MIT license. See LICENSE for details.
Copyright (c) 2011 Justin Ko
FAQs
Unknown package
We found that sunspot-rails-tester demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.