can't start making pages when there's no layout yet. also adding license file'

Oleg committed Jan 14, 2011
commit 456eeb26eba260bc775c0f1934f3689db7caff97
Showing 4 changed files with 47 additions and 0 deletions
LICENSE +20 -0
@@ @@ -0,0 +1,20 @@
+ Copyright (c) 2010-2011 Oleg Khabarov, The Working Group Inc
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
app/controllers/cms_admin/pages_controller.rb +8 -0
@@ @@ -1,5 +1,6 @@
class CmsAdmin::PagesController < CmsAdmin::BaseController
+ before_filter :check_for_layouts, :only => [:new, :edit]
before_filter :build_cms_page, :only => [:new, :create]
before_filter :load_cms_page, :only => [:edit, :update, :destroy]
before_filter :preview_cms_page, :only => [:create, :update]
@@ @@ -48,6 +49,13 @@ class CmsAdmin::PagesController < CmsAdmin::BaseController
end
protected
+
+ def check_for_layouts
+ if CmsLayout.count == 0
+ flash[:error] = 'No Layouts found. Please create one.'
+ redirect_to new_cms_admin_layout_path
+ end
+ end
def build_cms_page
@cms_page = @cms_site.cms_pages.new(params[:cms_page])
test/functional/cms_admin/pages_controller_test.rb +17 -0
@@ @@ -282,4 +282,21 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
assert_not_equal 'Updated Label', page.label
end
end
+
+ def test_get_new_with_no_layout
+ CmsLayout.destroy_all
+ get :new
+ assert_response :redirect
+ assert_redirected_to new_cms_admin_layout_path
+ assert_equal 'No Layouts found. Please create one.', flash[:error]
+ end
+
+ def test_get_edit_with_no_layout
+ CmsLayout.destroy_all
+ page = cms_pages(:default)
+ get :edit, :id => page
+ assert_response :redirect
+ assert_redirected_to new_cms_admin_layout_path
+ assert_equal 'No Layouts found. Please create one.', flash[:error]
+ end
end
\ No newline at end of file
test/integration/sites_test.rb +2 -0
@@ @@ -38,6 +38,7 @@ class SitesTest < ActionDispatch::IntegrationTest
http_auth :get, cms_admin_pages_path
assert_response :redirect
assert_redirected_to cms_admin_sites_path
+ assert_equal 'No Site defined for this hostname. Create it now.', flash[:error]
end
end
@@ @@ -48,6 +49,7 @@ class SitesTest < ActionDispatch::IntegrationTest
http_auth :get, cms_admin_pages_path
assert_response :redirect
assert_redirected_to cms_admin_sites_path
+ assert_equal 'No Site defined for this hostname. Create it now.', flash[:error]
end
end