more site related tests

Oleg committed Oct 18, 2010
commit 9914299b14aee25f4cab7dc9b9e9a067ed8f5f53
Showing 9 changed files with 64 additions and 34 deletions
app/controllers/cms_content_controller.rb +2 -2
@@ @@ -22,7 +22,7 @@ protected
def load_cms_site
@cms_site = CmsSite.find_by_hostname!(request.host.downcase)
rescue ActiveRecord::RecordNotFound
- render :text => 'Site is not found', :status => 404
+ render :text => 'Site Not Found', :status => 404
end
def load_cms_page
@@ @@ -31,7 +31,7 @@ protected
if @cms_page = @cms_site.cms_pages.find_by_full_path('/404')
render_html(404)
else
- render :text => 'Page not found', :status => 404
+ render :text => 'Page Not Found', :status => 404
end
end
test/functional/cms_admin/layouts_controller_test.rb +3 -1
@@ @@ -40,7 +40,9 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase
:content => 'Test Content'
}
assert_response :redirect
- assert_redirected_to :action => :edit, :id => CmsLayout.last
+ layout = CmsLayout.last
+ assert_equal cms_sites(:default), layout.cms_site
+ assert_redirected_to :action => :edit, :id => layout
assert_equal 'Layout created', flash[:notice]
end
end
test/functional/cms_admin/pages_controller_test.rb +3 -1
@@ @@ -137,7 +137,9 @@ class CmsAdmin::PagesControllerTest < ActionController::TestCase
]
}
assert_response :redirect
- assert_redirected_to :action => :edit, :id => CmsPage.last
+ page = CmsPage.last
+ assert_equal cms_sites(:default), page.cms_site
+ assert_redirected_to :action => :edit, :id => page
assert_equal 'Page saved', flash[:notice]
end
end
test/functional/cms_admin/snippets_controller_test.rb +3 -1
@@ @@ -40,7 +40,9 @@ class CmsAdmin::SnippetsControllerTest < ActionController::TestCase
:content => 'Test Content'
}
assert_response :redirect
- assert_redirected_to :action => :edit, :id => CmsSnippet.last
+ snippet = CmsSnippet.last
+ assert_equal cms_sites(:default), snippet.cms_site
+ assert_redirected_to :action => :edit, :id => snippet
assert_equal 'Snippet created', flash[:notice]
end
end
test/functional/cms_content_controller_test.rb +7 -6
@@ @@ -15,7 +15,7 @@ class CmsContentControllerTest < ActionController::TestCase
layout_content_b
default_snippet_content
layout_content_c'
- ), @response.body
+ ), response.body
end
def test_render_page_with_app_layout
@@ @@ -28,6 +28,7 @@ class CmsContentControllerTest < ActionController::TestCase
def test_render_page_not_found
get :render_html, :cms_path => 'doesnotexist'
assert_response 404
+ assert_equal 'Page Not Found', response.body
end
def test_render_page_not_found_with_custom_404
@@ @@ -45,14 +46,14 @@ class CmsContentControllerTest < ActionController::TestCase
get :render_html, :cms_path => 'doesnotexist'
assert_response 404
assert assigns(:cms_page)
- assert_match /custom 404 page content/, @response.body
+ assert_match /custom 404 page content/, response.body
end
def test_render_css
get :render_css, :id => cms_layouts(:default)
assert_response :success
- assert_match %r{text\/css}, @response.headers["Content-Type"]
- assert_equal cms_layouts(:default).css, @response.body
+ assert_match %r{text\/css}, response.headers["Content-Type"]
+ assert_equal cms_layouts(:default).css, response.body
end
def test_render_css_not_found
@@ @@ -63,8 +64,8 @@ class CmsContentControllerTest < ActionController::TestCase
def test_render_js
get :render_js, :id => cms_layouts(:default)
assert_response :success
- assert_match %r{text\/javascript}, @response.headers["Content-Type"]
- assert_equal cms_layouts(:default).js, @response.body
+ assert_match %r{text\/javascript}, response.headers["Content-Type"]
+ assert_equal cms_layouts(:default).js, response.body
end
def test_render_js_not_found
test/integration/admin_sites_test.rb +0 -23
@@ @@ -1,23 +0,0 @@
- require File.dirname(__FILE__) + '/../test_helper'
-
- class AdminSitesTest < ActionDispatch::IntegrationTest
-
- def test_get_admin_pages_index
- http_auth :get, cms_admin_pages_path
- assert_response :success
- end
-
- def test_get_admin_pages_index_with_no_site
- CmsSite.delete_all
- http_auth :get, cms_admin_pages_path
- assert_response :redirect
- 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
-
- end
\ No newline at end of file
test/integration/sites_test.rb +30 -0
@@ @@ -0,0 +1,30 @@
+ require File.dirname(__FILE__) + '/../test_helper'
+
+ class SitesTest < ActionDispatch::IntegrationTest
+
+ def test_get_admin_pages_index
+ http_auth :get, cms_admin_pages_path
+ assert_response :success
+ end
+
+ def test_get_admin_pages_index_with_no_site
+ CmsSite.delete_all
+ http_auth :get, cms_admin_pages_path
+ assert_response :redirect
+ 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 '/'
+ assert_response 404
+ assert_equal 'Site Not Found', response.body
+ end
+
+ end
\ No newline at end of file
test/test_helper.rb +4 -0
@@ @@ -12,6 +12,8 @@ class ActiveSupport::TestCase
config.cms_title = 'ComfortableMexicanSofa'
config.authentication = 'CmsHttpAuthentication'
end
+ CmsHttpAuthentication.username = 'username'
+ CmsHttpAuthentication.password = 'password'
end
# Example usage:
@@ @@ -45,6 +47,8 @@ class ActionDispatch::IntegrationTest
def setup
host! 'test.host'
+ CmsHttpAuthentication.username = 'username'
+ CmsHttpAuthentication.password = 'password'
end
def http_auth(method, path, options = {}, username = 'username', password = 'password')
test/unit/cms_site_test.rb +12 -0
@@ @@ -21,6 +21,18 @@ class CmsSiteTest < ActiveSupport::TestCase
assert site.valid?
end
+ def test_cascading_destroy
+ assert_difference 'CmsSite.count', -1 do
+ assert_difference 'CmsLayout.count', -3 do
+ assert_difference 'CmsPage.count', -2 do
+ assert_difference 'CmsSnippet.count', -1 do
+ cms_sites(:default).destroy
+ end
+ end
+ end
+ end
+ end
+
def test_options_for_select
assert_equal 1, CmsSite.options_for_select.size
assert_equal 'Default Site (test.host)', CmsSite.options_for_select[0][0]