<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -93,7 +93,8 @@ class Admin::SitesController &lt; Admin::BaseController
     def protect_single_site_mode
       unless Site.multi_sites_enabled
         if params[:action] == 'index'
-          site = Site.find_or_initialize_by_host(request.host_with_port)
+          site = Site.find_by_host(request.host_with_port)
+          site = Site.first unless site
           redirect_to admin_site_url(site)
         else
           render :action =&gt; :multi_sites_disabled, :layout =&gt; 'simple'</diff>
      <filename>engines/adva_cms/app/controllers/admin/sites_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -34,6 +34,41 @@ class AdminSitesControllerTest &lt; ActionController::TestCase
     end
   end
 
+  describe &quot;GET to :index with single site mode on. If no site with request host name is found it redirects to first Site&quot; do
+    with :single_site_enabled do
+      with :is_superuser do
+        with :access_granted do
+            before do
+              mock(Site).find_by_host(&quot;site-with-pages.com&quot;) { nil }
+              @site_mock = Site.new
+              mock(@site_mock).id.times(any_times) { 1 }
+              mock(Site).first { @site_mock }
+            end
+
+            action { get :index }
+
+            it_redirects_to { admin_site_url(@site_mock) }
+        end
+      end
+    end
+  end
+
+  describe &quot;GET to :index with single site mode on. If a site with request host name is found it redirects to the found site&quot; do
+    with :single_site_enabled do
+      with :is_superuser do
+        with :access_granted do
+            before do
+              dont_allow(Site).first
+            end
+
+            action { get :index }
+
+            it_redirects_to { admin_site_url(Site.find_by_host(&quot;site-with-pages.com&quot;)) }
+        end
+      end
+    end
+  end
+
   describe &quot;GET to :index&quot; do
     with :is_superuser do
       action { get :index }</diff>
      <filename>engines/adva_cms/test/functional/admin/sites_controller_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cfd086c241889d26643167fd1eb0b484174e56d9</id>
    </parent>
  </parents>
  <author>
    <name>Raphaela Wrede</name>
    <email>rwrede@adva-business.com</email>
  </author>
  <url>http://github.com/svenfuchs/adva_cms/commit/8ad2cec4d1186883cdf703bb29a15f5f35dc9d72</url>
  <id>8ad2cec4d1186883cdf703bb29a15f5f35dc9d72</id>
  <committed-date>2009-11-03T02:12:56-08:00</committed-date>
  <authored-date>2009-11-03T02:10:24-08:00</authored-date>
  <message>Given single site mode on
And no site with request host name is found 
it redirects to first Site.</message>
  <tree>a56c516db51166d135c68b200f40948149c9a8c8</tree>
  <committer>
    <name>Raphaela Wrede</name>
    <email>rwrede@adva-business.com</email>
  </committer>
</commit>
