Browse files

Making it more clear that testing requires transactional fixtures tur…

…ned off.
  • Loading branch information...
1 parent ecc20dc commit 377f7546678147cfa24c99fe530c748398b33d06 @pat pat committed Apr 7, 2011
Showing with 20 additions and 1 deletion.
  1. +20 −1 ts/en/testing.textile
@@ -5,6 +5,8 @@ title: Testing
h2. Testing with Thinking Sphinx
+Before you get caught up in the specifics of testing Thinking Sphinx using certain tools, it's worth noting that no matter what the approach, you'll need to turn off transactional fixtures and index your data after creating the appropriate records - otherwise you won't get any search results.
<li><a href="#unit_tests">Unit Tests and Specs</a></li>
<li><a href="#cucumber">Cucumber</a></li>
@@ -24,12 +26,19 @@ require 'cucumber/thinking_sphinx/external_world'
{% endhighlight %}
-And you also _need_ to turn transactional fixtures off:
+Don't forget, you also _need_ to turn transactional fixtures off. This can be done on a global level in your @features/support/env.rb@ file:
{% highlight ruby %}
Cucumber::Rails::World.use_transactional_fixtures = false
{% endhighlight %}
+Or, you can tag either an entire feature or single scenarios with the @@no-txn@ tag:
+{% highlight gherkin %}
+Feature: Searching for articles
+{% endhighlight %}
The reason for this is that while ActiveRecord can run all its operations within a single transaction, Sphinx doesn't have access to that, and so indexing will not include your transaction's changes.
The added complication to this is that you'll probably want to clear all the data from your database between scenarios. This can be done within the @Before@ block, in one of your steps files (see below). Another option is Ben Mabey's "Database Cleaner": library.
@@ -74,6 +83,16 @@ require 'thinking_sphinx/test'
{% endhighlight %}
+You can turn off transactional features on a per-test basis within the test class definition:
+{% highlight ruby %}
+class SearchControllerTest
+ self.use_transactional_fixtures = false
+ # ...
+{% endhighlight %}
To actually have Sphinx running, you have a few options...
If you want it running constantly for _all_ of your tests, you can call @start_with_autostop@ in your @test_helper.rb@ file:

0 comments on commit 377f754

Please sign in to comment.