From da95e5dc7befff6fee168289d36b1e4c57de5e8e Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 27 Sep 2007 06:19:14 +0000 Subject: [PATCH] adding first page controller and first revision of the Page model. also adding unit tests for the model. git-svn-id: http://svn.barleysodas.com/barleysodas/trunk@6 0f7b21a7-9e3a-4941-bbeb-ce5c7c368fa7 --- app/controllers/pages_controller.rb | 2 ++ app/helpers/pages_helper.rb | 2 ++ app/models/page.rb | 37 ++++++++++++++++++++++++ config/routes.rb | 2 ++ db/migrate/002_create_pages.rb | 19 ++++++++++++ test/fixtures/pages.yml | 7 +++++ test/functional/pages_controller_test.rb | 20 +++++++++++++ test/test_helper.rb | 12 ++++++++ test/unit/page_test.rb | 13 +++++++++ 9 files changed, 114 insertions(+) create mode 100644 app/controllers/pages_controller.rb create mode 100644 app/helpers/pages_helper.rb create mode 100644 app/models/page.rb create mode 100644 db/migrate/002_create_pages.rb create mode 100644 test/fixtures/pages.yml create mode 100644 test/functional/pages_controller_test.rb create mode 100644 test/unit/page_test.rb diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 0000000..95217e1 --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,2 @@ +class PagesController < ApplicationController +end \ No newline at end of file diff --git a/app/helpers/pages_helper.rb b/app/helpers/pages_helper.rb new file mode 100644 index 0000000..2c057fd --- /dev/null +++ b/app/helpers/pages_helper.rb @@ -0,0 +1,2 @@ +module PagesHelper +end diff --git a/app/models/page.rb b/app/models/page.rb new file mode 100644 index 0000000..e1088fc --- /dev/null +++ b/app/models/page.rb @@ -0,0 +1,37 @@ +## +# This is a representation of a page of the wiki. My wiki is awfully simple +# because i don't like too many features. This works and it has many different +# associations. All of the major models has_one of these and it belongs_to +# some kind of polymorphic owner. +# +# Bonuses: +# * Uses RedCloth markup. +# * Automatically converts/caches HTML +# * Allows any character or space in the name +# * Uses [[ and ]] for WikiWord representation. +# +class Page < ActiveRecord::Base + acts_as_versioned + + belongs_to :owner, :polymorphic => true + validates_presence_of :title + validates_uniqueness_of :title + validates_format_of :title, :with => /[A-Za-z0-9 ]/, + :message => 'may only contain letters, numbers and spaces' + before_save :update_html + + protected + + ## + # Updates the HTML chunk from the RedCloth source. + # + def update_html + # need to filter HTML first... remove