redirect to new if empty index

Oleg committed Oct 29, 2010
commit 4bdc22fffb9f758e7adb06d508928dd8ecdba8d8
Showing 9 changed files with 32 additions and 6 deletions
app/controllers/cms_admin/layouts_controller.rb +1 -0
@@ @@ -4,6 +4,7 @@ class CmsAdmin::LayoutsController < CmsAdmin::BaseController
before_filter :load_cms_layout, :only => [:edit, :update, :destroy]
def index
+ return redirect_to :action => :new if @cms_site.cms_layouts.count == 0
@cms_layouts = @cms_site.cms_layouts.roots
end
app/controllers/cms_admin/pages_controller.rb +1 -0
@@ @@ -4,6 +4,7 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
before_filter :load_cms_page, :only => [:edit, :update, :destroy]
def index
+ return redirect_to :action => :new if @cms_site.cms_pages.count == 0
@cms_pages = [@cms_site.cms_pages.root].compact
end
app/controllers/cms_admin/sites_controller.rb +1 -0
@@ @@ -6,6 +6,7 @@ class CmsAdmin::SitesController < CmsAdmin::BaseController
before_filter :load_cms_site, :only => [:edit, :update, :destroy]
def index
+ return redirect_to :action => :new if CmsSite.count == 0
@cms_sites = CmsSite.all
end
app/controllers/cms_admin/snippets_controller.rb +1 -0
@@ @@ -4,6 +4,7 @@ class CmsAdmin::SnippetsController < CmsAdmin::BaseController
before_filter :load_cms_snippet, :only => [:edit, :update, :destroy]
def index
+ return redirect_to :action => :new if @cms_site.cms_snippets.count == 0
@cms_snippets = @cms_site.cms_snippets.all(:order => 'label')
end
test/functional/cms_admin/layouts_controller_test.rb +7 -0
@@ @@ -9,6 +9,13 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
assert_template :index
end
+ def test_get_index_with_no_layouts
+ CmsLayout.delete_all
+ get :index
+ assert_response :redirect
+ assert_redirected_to :action => :new
+ end
+
def test_get_new
get :new
assert_response :success
test/functional/cms_admin/pages_controller_test.rb +7 -0
@@ @@ -9,6 +9,13 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
assert_template :index
end
+ def test_get_index_with_no_pages
+ CmsPage.delete_all
+ get :index
+ assert_response :redirect
+ assert_redirected_to :action => :new
+ end
+
def test_get_new
get :new
assert_response :success
test/functional/cms_admin/sites_controller_test.rb +7 -0
@@ @@ -9,6 +9,13 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase
assert_template :index
end
+ def test_get_index_with_no_sites
+ CmsSite.delete_all
+ get :index
+ assert_response :redirect
+ assert_redirected_to :action => :new
+ end
+
def test_get_new
get :new
assert_response :success
test/functional/cms_admin/snippets_controller_test.rb +7 -0
@@ @@ -9,6 +9,13 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
assert_template :index
end
+ def test_get_index_with_no_snippets
+ CmsSnippet.delete_all
+ get :index
+ assert_response :redirect
+ assert_redirected_to :action => :new
+ end
+
def test_get_new
get :new
assert_response :success
test/integration/sites_test.rb +0 -6
@@ @@ -14,12 +14,6 @@ class SitesTest < ActionDispatch::IntegrationTest
assert_redirected_to new_cms_admin_site_path
end
- def test_get_admin_sites_index_with_no_site
- CmsSite.delete_all
- http_auth :get, cms_admin_sites_path
- assert_response :success
- end
-
def test_get_public_page_for_non_existent_site
host! 'bogus.host'
get '/'