Index: apps/audit/tests/test_model.doctest
===================================================================
--- apps/audit/tests/test_model.doctest	(revision 1577)
+++ apps/audit/tests/test_model.doctest	(working copy)
@@ -19,6 +19,7 @@ Store the receivers so we can disconnect them at cleanup.
 Load the fixture.
 
     >>> from django.core.management import call_command
+    >>> call_command('flush', verbosity=0, interactive=False)
     >>> call_command('loaddata', 'audit/test_model', verbosity=0)
 
 Create a Person and make some changes.
Index: apps/dash/tests/sections.doctest
===================================================================
--- apps/dash/tests/sections.doctest	(revision 1577)
+++ apps/dash/tests/sections.doctest	(working copy)
@@ -10,6 +10,7 @@
 
 Load fixtures.
 
+    >>> call_command('flush', verbosity=0, interactive=False)
     >>> call_command('loaddata', 'dash/test_sections', verbosity=0)
 
 Test table section.
Index: apps/feeds/tests/test_view.doctest
===================================================================
--- apps/feeds/tests/test_view.doctest	(revision 1577)
+++ apps/feeds/tests/test_view.doctest	(working copy)
@@ -11,7 +11,14 @@ Set up the necessary conditions to run the tests
     >>> from feeds.tests.utils import news_feeds
 
     >>> from django.core.management import call_command
+
+Load fixtures.
+
+    >>> call_command('flush', verbosity=0, interactive=False)
     >>> call_command('loaddata', 'feeds/test_view', verbosity=0)
+
+Setup.
+
     >>> project = Project.objects.all()[0]
     >>> url_info = {
     ...     'project_slug': project.slug,
@@ -33,13 +40,13 @@ Test a get request on a rss feed page.
       <channel>
         <title>Basie: Latest News</title>...
         <description>Project: news_project</description>...
-        <lastBuildDate>Sat, 20 Dec 2008 17:07:01 -0400</lastBuildDate>
+        <lastBuildDate>Sat, 20 Dec 2008 17:07:01...</lastBuildDate>
         <item>
           <title>title1 </title>
           <link>http://testserver/news/1/</link>
           <description>news1 </description>
           <author>news_user@example.org (news_user)</author>
-          <pubDate>Sat, 20 Dec 2008 17:07:01 -0400</pubDate>
+          <pubDate>Sat, 20 Dec 2008 17:07:01...</pubDate>
           <guid>http://testserver/news/1/</guid>
         </item>
         <item>
@@ -47,7 +54,7 @@ Test a get request on a rss feed page.
           <link>http://testserver/news/2/</link>
           <description>news2 </description>
           <author>news_user@example.org (news_user)</author>
-          <pubDate>Sat, 20 Dec 2008 17:07:01 -0400</pubDate>
+          <pubDate>Sat, 20 Dec 2008 17:07:01...</pubDate>
           <guid>http://testserver/news/2/</guid>
         </item>
         <item>
@@ -55,7 +62,7 @@ Test a get request on a rss feed page.
           <link>http://testserver/news/3/</link>
           <description>news3 </description>
           <author>news_user@example.org (news_user)</author>
-          <pubDate>Sat, 20 Dec 2008 17:07:01 -0400</pubDate>
+          <pubDate>Sat, 20 Dec 2008 17:07:01...</pubDate>
           <guid>http://testserver/news/3/</guid>
         </item>
       </channel>
@@ -72,12 +79,12 @@ Test a get request on a atom feed page.
     <?xml version="1.0" encoding="utf-8"?>
     <feed xmlns="http://www.w3.org/2005/Atom"...>
       <title>Basie: Latest News</title>...
-      <updated>2008-12-20T17:07:01-04:00</updated>
+      <updated>2008-12-20T17:07:01...</updated>
       <subtitle>Project: news_project</subtitle>
       <entry>
         <title>title1 </title>
         <link href="http://testserver/news/1/"...> </link>
-        <updated>2008-12-20T17:07:01-04:00</updated>
+        <updated>2008-12-20T17:07:01...</updated>
         <author>
           <name>news_user</name>
           <email>news_user@example.org</email>
@@ -88,7 +95,7 @@ Test a get request on a atom feed page.
       <entry>
         <title>title2 </title>
         <link href="http://testserver/news/2/"...> </link>
-        <updated>2008-12-20T17:07:01-04:00</updated>
+        <updated>2008-12-20T17:07:01...</updated>
         <author>
           <name>news_user</name>
           <email>news_user@example.org</email>
@@ -99,7 +106,7 @@ Test a get request on a atom feed page.
       <entry>
         <title>title3 </title>
         <link href="http://testserver/news/3/"...> </link>
-        <updated>2008-12-20T17:07:01-04:00</updated>
+        <updated>2008-12-20T17:07:01...</updated>
         <author>
           <name>news_user</name>
           <email>news_user@example.org</email>
Index: apps/lists/tests/sorting.doctest
===================================================================
--- apps/lists/tests/sorting.doctest	(revision 1577)
+++ apps/lists/tests/sorting.doctest	(working copy)
@@ -1,6 +1,7 @@
 Load the fixture.
 
     >>> from django.core.management import call_command
+    >>> call_command('flush', verbosity=0, interactive=False)
     >>> call_command('loaddata', 'lists/test_sorting', verbosity=0)
 
 
Index: apps/mail/fixtures/mail/test_index.yaml
===================================================================
--- apps/mail/fixtures/mail/test_index.yaml	(revision 1577)
+++ apps/mail/fixtures/mail/test_index.yaml	(working copy)
@@ -17,14 +17,14 @@
     is_superuser: true
 
 - model: a3c.project
-  pk: &PROJECT1 1
+  pk: &PROJECT1 100
   fields:
     name: Project1
     slug: project1
     default_group: &EMPTY_GROUP 1
 
 - model: a3c.project
-  pk: &PROJECT2 2
+  pk: &PROJECT2 101
   fields:
     name: Project2
     slug: project2
@@ -46,17 +46,24 @@
     group: *READER_GROUP
     status: *APPROVED_STATUS
 
+- model: mail.useremail
+  pk: 100
+  fields:
+    user: *USER1
+    address: user1@example.org
+    forwarding: true
+
 - model: mail.mailmessage
-  pk: 1
+  pk: 100
   fields:
     project: *PROJECT1
-    user: *USER1
+    sender: user1@example.org
     subject: Alpha beta
     body: Gamma delta epsilon omega
     date: !!timestamp '2008-12-20 17:07:01.200583'
 
 - model: mail.mailmessage
-  pk: 2
+  pk: 101
   fields:
     project: *PROJECT1
     subject: Yellow brown
@@ -65,7 +72,7 @@
     hidden: true
 
 - model: mail.mailmessage
-  pk: 3
+  pk: 102
   fields:
     project: *PROJECT2
     subject: One two
@@ -73,7 +80,7 @@
     date: !!timestamp '2008-12-20 17:07:01.200583'
 
 - model: mail.mailmessage
-  pk: 4
+  pk: 103
   fields:
     project: *PROJECT2
     subject: Hello World
Index: apps/search/__init__.py
===================================================================
--- apps/search/__init__.py	(revision 1577)
+++ apps/search/__init__.py	(working copy)
@@ -20,10 +20,8 @@ def register(model, document_class):
 def post_save_callback(sender, instance, created, **kwargs):
     """Update the index when an instance of a registered model is saved."""
     document = REGISTRY[sender](instance)
-    if created:
-        document.add_to_index()
-    else:
-        document.update_in_index()
+    # We can not assume the creation signal comes first.
+    document.update_in_index()
 
 
 def post_delete_callback(sender, instance, **kwargs):
Index: apps/search/document.py
===================================================================
--- apps/search/document.py	(revision 1577)
+++ apps/search/document.py	(working copy)
@@ -57,12 +57,8 @@ class BaseDocument(object):
         # TODO: Use is_visible to restrict the results visibility.
         return True
 
-    def add_to_index(self):
-        writer = index.open_index().writer()
-        writer.add_document(**self.document)
-        writer.commit()
-
     def update_in_index(self):
+        """Add or update an instance in the index."""
         writer = index.open_index().writer()
         writer.update_document(**self.document)
         writer.commit()
Index: apps/search/management/commands/fullindex.py
===================================================================
--- apps/search/management/commands/fullindex.py	(revision 1577)
+++ apps/search/management/commands/fullindex.py	(working copy)
@@ -14,4 +14,4 @@ class Command(BaseCommand):
         for model in REGISTRY:
             for instance in model.objects.all():
                 document = REGISTRY[model](instance)
-                document.add_to_index()
+                document.update_in_index()
Index: apps/search/tests/test_indexing.doctest
===================================================================
--- apps/search/tests/test_indexing.doctest	(revision 1577)
+++ apps/search/tests/test_indexing.doctest	(working copy)
@@ -10,6 +10,7 @@
 
 Load fixtures.
 
+    >>> call_command('flush', verbosity=0, interactive=False)
     >>> call_command('loaddata', 'search/test_indexing', verbosity=0)
 
 Auxiliar function.
@@ -135,20 +136,20 @@ Test fullindex custom command.
     >>> search('project', 'project1 project2')
     >>> call_command('fullindex')
     >>> search('project', 'project1 project2')
-    {'project': u'Project2', 'url': u'project2/comment/1', 'content_type': u'comment', 'title': u'Yellow brown'}
-    {'project': u'Project2', 'url': u'project2/comment/2', 'content_type': u'comment', 'title': u'Alpha beta'}
-    {'project': u'Project1', 'url': u'project1/comment/3', 'content_type': u'comment', 'title': u'One two'}
     {'project': u'Project1', 'url': u'project1/article/1', 'content_type': u'article', 'title': u'Yellow brown'}
     {'project': u'Project1', 'url': u'project1/article/2', 'content_type': u'article', 'title': u'Alpha beta'}
     {'project': u'Project2', 'url': u'project2/article/3', 'content_type': u'article', 'title': u'One two'}
-    >>> call_command('fullindex')
-    >>> search('project', 'project1 project2')
     {'project': u'Project2', 'url': u'project2/comment/1', 'content_type': u'comment', 'title': u'Yellow brown'}
     {'project': u'Project2', 'url': u'project2/comment/2', 'content_type': u'comment', 'title': u'Alpha beta'}
     {'project': u'Project1', 'url': u'project1/comment/3', 'content_type': u'comment', 'title': u'One two'}
+    >>> call_command('fullindex')
+    >>> search('project', 'project1 project2')
     {'project': u'Project1', 'url': u'project1/article/1', 'content_type': u'article', 'title': u'Yellow brown'}
     {'project': u'Project1', 'url': u'project1/article/2', 'content_type': u'article', 'title': u'Alpha beta'}
     {'project': u'Project2', 'url': u'project2/article/3', 'content_type': u'article', 'title': u'One two'}
+    {'project': u'Project2', 'url': u'project2/comment/1', 'content_type': u'comment', 'title': u'Yellow brown'}
+    {'project': u'Project2', 'url': u'project2/comment/2', 'content_type': u'comment', 'title': u'Alpha beta'}
+    {'project': u'Project1', 'url': u'project1/comment/3', 'content_type': u'comment', 'title': u'One two'}
 
 Clean-up the index and the instances loaded in the database.
 
Index: apps/search/tests/test_searching.doctest
===================================================================
--- apps/search/tests/test_searching.doctest	(revision 1577)
+++ apps/search/tests/test_searching.doctest	(working copy)
@@ -7,6 +7,7 @@
 
 Load fixtures.
 
+    >>> call_command('flush', verbosity=0, interactive=False)
     >>> call_command('loaddata', 'search/test_searching', verbosity=0)
 
 Auxiliar function.
Index: apps/search/tests/test_views.doctest
===================================================================
--- apps/search/tests/test_views.doctest	(revision 1577)
+++ apps/search/tests/test_views.doctest	(working copy)
@@ -14,6 +14,7 @@
 
 Load fixtures.
 
+    >>> call_command('flush', verbosity=0, interactive=False)
     >>> call_command('loaddata', 'search/test_searching', verbosity=0)
 
 Auxiliar functions.
Index: apps/tickets/tests/tickets_dash.doctest
===================================================================
--- apps/tickets/tests/tickets_dash.doctest	(revision 1577)
+++ apps/tickets/tests/tickets_dash.doctest	(working copy)
@@ -7,6 +7,7 @@
 
 Load fixtures.
 
+    >>> call_command('flush', verbosity=0, interactive=False)
     >>> call_command('loaddata', 'tickets/test_dash', verbosity=0)
 
 Test the get_rows funtion related to open tickets pie.
Index: apps/wiki/fixtures/wiki/test_index.yaml
===================================================================
--- apps/wiki/fixtures/wiki/test_index.yaml	(revision 1577)
+++ apps/wiki/fixtures/wiki/test_index.yaml	(working copy)
@@ -11,14 +11,14 @@
     username: user2
 
 - model: a3c.project
-  pk: &PROJECT1 1
+  pk: &PROJECT1 100
   fields:
     name: Project1
     slug: project1
     default_group: &EMPTY_GROUP 1
 
 - model: a3c.project
-  pk: &PROJECT2 2
+  pk: &PROJECT2 101
   fields:
     name: Project2
     slug: project2
@@ -47,7 +47,7 @@
     status: *APPROVED_STATUS
 
 - model: wiki.wikipage
-  pk: 1
+  pk: 100
   fields:
     name: Alpha beta
     slug: alpha-beta
@@ -58,7 +58,7 @@
     date_edited: !!timestamp '2009-06-12 07:37:10.200583'
 
 - model: wiki.wikipage
-  pk: 2
+  pk: 101
   fields:
     name: Yellow brown
     slug: yello-brown
@@ -67,7 +67,7 @@
     hidden: true
 
 - model: wiki.wikipage
-  pk: 3
+  pk: 102
   fields:
     name: One two
     slug: one-two
@@ -75,7 +75,7 @@
     project: *PROJECT2
 
 - model: wiki.wikipage
-  pk: 4
+  pk: 103
   fields:
     name: Hello World
     slug: hello-world
Index: apps/wiki/tests/test_index.py
===================================================================
--- apps/wiki/tests/test_index.py	(revision 1577)
+++ apps/wiki/tests/test_index.py	(working copy)
@@ -27,23 +27,29 @@ class IndexTest(test.TestCase):
         query = parser.parse(unicode(query))
         results = list(searcher.search(query))
         assert len(results) == 1
-        page = WikiPage.objects.all()[0]
+        page = WikiPage.objects.get(name='Alpha beta')
         found_page = results[0]
         assert found_page['url'] == page.get_absolute_url()
         assert found_page['title'] == page.name
         assert found_page['content_type'] == 'wiki'
         assert found_page['project'] == page.project.name
 
+    def check_project(self, results, project):
+        """Check that the results are ones corresponding to a given project."""
+        for result in results:
+            assert result['project'] == project
+        expected_results = WikiPage.objects.filter(project__name=project, hidden=False)
+        assert expected_results.count() == len(results)
+
     def test_filtering(self):
         """Test that wiki pages are being filtered according to the user."""
         search_query = 'content_type:wiki'
         user1 = User.objects.get(username='user1')
         results = searching.get_filtered_results(search_query, user1)
-        assert results[0]['project'] == 'Project1'
+        self.check_project(results, 'Project1')
         user2 = User.objects.get(username='user2')
         results = searching.get_filtered_results(search_query, user2)
-        assert len(results) == 1
-        assert results[0]['project'] == 'Project2'
+        self.check_project(results, 'Project2')
         superuser = User.objects.get(username='superuser')
         results = searching.get_filtered_results(search_query, superuser)
-        assert len(results) == 4
+        assert len(results) == WikiPage.objects.count()
Index: basie/tests/test_root_pages.py
===================================================================
--- basie/tests/test_root_pages.py	(revision 1577)
+++ basie/tests/test_root_pages.py	(working copy)
@@ -1,4 +1,5 @@
 from django import test
+from django.contrib.auth.models import Group
 
 from nose.tools import eq_
 
@@ -17,6 +18,8 @@ class PageTestCase(test.TestCase):
 
     def test_project_root(self):
         """Check that /<project>/ shows project details."""
+        reader = Group.objects.get(name='reader')
+        project = Project.objects.create(name='basie', default_group=reader)
         response = self.client.get('/basie/')
 
         eq_(response.status_code, 200)
