From d4dfdb40329b8e15e6bba022b966984a8a994a87 Mon Sep 17 00:00:00 2001 From: hukl Date: Thu, 29 Jan 2009 21:40:04 +0100 Subject: added the content controller which will be responsible for rendering all public pages later on. added a new custom route for the public url schema as well as a functional test which tests the correct mapping of the custom route --- app/controllers/content_controller.rb | 5 ++++ app/helpers/content_helper.rb | 2 ++ app/views/content/render_page.html.erb | 2 ++ config/routes.rb | 42 +++--------------------------- doc/README_FOR_APP | 11 ++++++-- test/functional/content_controller_test.rb | 21 +++++++++++++++ test/unit/helpers/content_helper_test.rb | 4 +++ 7 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 app/controllers/content_controller.rb create mode 100644 app/helpers/content_helper.rb create mode 100644 app/views/content/render_page.html.erb create mode 100644 test/functional/content_controller_test.rb create mode 100644 test/unit/helpers/content_helper_test.rb diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb new file mode 100644 index 0000000..afa093c --- /dev/null +++ b/app/controllers/content_controller.rb @@ -0,0 +1,5 @@ +class ContentController < ApplicationController + def render_page + end + +end diff --git a/app/helpers/content_helper.rb b/app/helpers/content_helper.rb new file mode 100644 index 0000000..3199604 --- /dev/null +++ b/app/helpers/content_helper.rb @@ -0,0 +1,2 @@ +module ContentHelper +end diff --git a/app/views/content/render_page.html.erb b/app/views/content/render_page.html.erb new file mode 100644 index 0000000..af7ef88 --- /dev/null +++ b/app/views/content/render_page.html.erb @@ -0,0 +1,2 @@ +

Content#render_page

+

Find me in app/views/content/render_page.html.erb

diff --git a/config/routes.rb b/config/routes.rb index 4f3d9d2..cbad5cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,43 +1,9 @@ ActionController::Routing::Routes.draw do |map| - # The priority is based upon order of creation: first created -> highest priority. - - # Sample of regular route: - # map.connect 'products/:id', :controller => 'catalog', :action => 'view' - # Keep in mind you can assign values other than :controller and :action - - # Sample of named route: - # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase' - # This route can be invoked with purchase_url(:id => product.id) - - # Sample resource route (maps HTTP verbs to controller actions automatically): - # map.resources :products - - # Sample resource route with options: - # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get } - - # Sample resource route with sub-resources: - # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller - # Sample resource route with more complex sub-resources - # map.resources :products do |products| - # products.resources :comments - # products.resources :sales, :collection => { :recent => :get } - # end - - # Sample resource route within a namespace: - # map.namespace :admin do |admin| - # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb) - # admin.resources :products - # end - - # You can have the root of your site routed with map.root -- just remember to delete public/index.html. - # map.root :controller => "welcome" - - # See how all your routes lay out with "rake routes" - - # Install the default routes as the lowest priority. - # Note: These default routes make all actions in every controller accessible via GET requests. You should - # consider removing the them or commenting them out if you're using named routes and resources. + map.connect ':language/*pagepath', + :controller => 'content', :action => 'render_page', + :requirements => {:language => /\w{2}/} + map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end diff --git a/doc/README_FOR_APP b/doc/README_FOR_APP index fe41f5c..acd2d3f 100644 --- a/doc/README_FOR_APP +++ b/doc/README_FOR_APP @@ -1,2 +1,9 @@ -Use this README file to introduce your application and point to useful places in the API for learning more. -Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. +CCCMS + + +The basic structure of the cccms is built from Nodes. Nodes live within a +nested set. When a arbitrary url is entered it is dispatched to the +ContentController action render_page. Based on the url parameters the +render_page action retrieves the corresponding Node from the database. Rather +than walking through the tree of the nested set to find the node, the Node is +retrieved directly by its unique_name which matches the url parameters. \ No newline at end of file diff --git a/test/functional/content_controller_test.rb b/test/functional/content_controller_test.rb new file mode 100644 index 0000000..c44b221 --- /dev/null +++ b/test/functional/content_controller_test.rb @@ -0,0 +1,21 @@ +require 'test_helper' + +class ContentControllerTest < ActionController::TestCase + + def test_custom_page_route + assert_recognizes({ :controller => 'content', :action => 'render_page', :language => 'de', :pagepath => ['foo', 'bar'] }, '/de/foo/bar') + assert_recognizes({ :controller => 'content', :action => 'render_page', :language => 'en', :pagepath => ['home'] }, '/en/home') + end + + # def test_rendering_a_page + # Page.destroy_all + # load_atp 'content_controller' + # Page.all.each {|x| x.update_unique_name; x.save} + # assert Page.valid? + # assert_not_nil Page.find_by_title("short name yo") + # get :render_page, :language => 'de', :pagepath => ["shortname","barfoo"] + # assert_response :success + # assert_template 'wtp_eins' + # assert_equal "page_templates/layouts/screen", @response.layout + # end +end diff --git a/test/unit/helpers/content_helper_test.rb b/test/unit/helpers/content_helper_test.rb new file mode 100644 index 0000000..2da82d7 --- /dev/null +++ b/test/unit/helpers/content_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ContentHelperTest < ActionView::TestCase +end -- cgit v1.3