adding tests for CmsTag::PageString

Oleg committed Aug 24, 2010
commit 2d385b739657b5d92a4769d1793fc375a904297b
Showing 9 changed files with 45 additions and 32 deletions
Gemfile +3 -24
@@ @@ -2,30 +2,9 @@ source 'http://rubygems.org'
gem 'rails', '3.0.0.rc'
- # Bundle edge Rails instead:
- # gem 'rails', :git => 'git://github.com/rails/rails.git'
-
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'haml'
- # Use unicorn as the web server
- # gem 'unicorn'
-
- # Deploy with Capistrano
- # gem 'capistrano'
-
- # To use debugger
- # gem 'ruby-debug'
-
- # Bundle the extra gems:
- # gem 'bj'
- # gem 'nokogiri', '1.4.1'
- # gem 'sqlite3-ruby', :require => 'sqlite3'
- # gem 'aws-s3', :require => 'aws/s3'
-
- # Bundle gems for the local environment. Make sure to
- # put test-only gems in this group so their generators
- # and rake tasks are available in development mode:
- # group :test do
- # gem 'shoulda'
- # end
\ No newline at end of file
+ group :test do
+ gem 'redgreen'
+ end
\ No newline at end of file
Gemfile.lock +2 -0
@@ @@ -60,6 +60,7 @@ GEM
rake (>= 0.8.3)
thor (~> 0.14.0)
rake (0.8.7)
+ redgreen (1.2.2)
sqlite3-ruby (1.2.5)
thor (0.14.0)
treetop (1.4.8)
@@ @@ -72,4 +73,5 @@ PLATFORMS
DEPENDENCIES
haml
rails (= 3.0.0.rc)
+ redgreen
sqlite3-ruby
app/models/cms_tag.rb +1 -1
@@ @@ -33,7 +33,7 @@ module CmsTag
# Content that is used during page rendering
def render
- ''
+ content
end
end
app/models/cms_tags/page_string.rb +5 -1
@@ @@ -1,4 +1,4 @@
- class CmsTag::PageString
+ class CmsTag::PageString < CmsBlock
include CmsTag
@@ @@ -11,4 +11,8 @@ class CmsTag::PageString
self.class.regex_tag_signature(label)
end
+ def content
+ read_attribute(:content_string)
+ end
+
end
\ No newline at end of file
app/models/cms_tags/page_text.rb +0 -4
@@ @@ -15,8 +15,4 @@ class CmsTag::PageText < CmsBlock
read_attribute(:content_text)
end
- def render
- content
- end
-
end
\ No newline at end of file
test/fixtures/cms_blocks.yml +6 -0
@@ @@ -3,3 +3,9 @@ default_page_text:
type: CmsTag::PageText
label: content
content_text: default_page_text_content
+
+ default_page_string:
+ cms_page: default
+ type: CmsTag::PageString
+ label: title
+ content_string: default_page_string_content
test/fixtures/cms_layouts.yml +1 -0
@@ @@ -3,3 +3,4 @@ default: &layout
content: |-
<cms:page:content/>
<cms:page:title:string/>
+
test/unit/cms_page_test.rb +1 -0
@@ @@ -6,6 +6,7 @@ class CmsPageTest < ActiveSupport::TestCase
page = cms_pages(:default)
assert_equal [
'default_page_text_content',
+ 'default_page_string_content'
].join("\n"), page.content
end
test/unit/cms_tags/page_string_test.rb +26 -2
@@ @@ -2,8 +2,32 @@ require File.dirname(__FILE__) + '/../../test_helper'
class PageStringTest < ActiveSupport::TestCase
- def test_something
- flunk
+ def test_regex_tag_signature
+ %w(
+ <cms:page:title:string/>
+ <cms:page:title:string>
+ ).each do |tag|
+ assert_match CmsTag::PageString.regex_tag_signature, tag
+ assert_match CmsTag::PageString.regex_tag_signature('title'), tag
+ assert_match cms_blocks(:default_page_string).regex_tag_signature, tag
+ end
+
+ assert_no_match CmsTag::PageString.regex_tag_signature, '<cms:page:title:text>'
+ assert_no_match CmsTag::PageString.regex_tag_signature('something'), '<cms:page:title:string/>'
+ assert_no_match CmsTag::PageString.regex_tag_signature, '<cms_page:header>'
+ end
+
+ def test_initialization_of_content_objects
+ content = cms_layouts(:default).content
+ block = CmsTag::PageString.initialize_tag_objects(content).first
+ assert_equal CmsTag::PageString, block.class
+ end
+
+ def test_method_content
+ block = cms_blocks(:default_page_string)
+ assert_equal CmsTag::PageString, block.class
+ assert_equal block.read_attribute(:content_string), block.content
+ assert_equal block.content, block.render
end
end
\ No newline at end of file