Skip to content
Browse files

Fixed a bug in the ordinalisation of dates.

* 11, 12, 13 were appearing as 11st, 12nd and 13rd respectively.  We added tests and fixed the bug in the blog renderer.
* We locked the version of Vanilla as later versions aren't entirely compatible with the version this site was originally based on.
* The 'load' line in the Rakefile was causing it to break.
* The 'publish' task in the Rakefile was unnecessary.
  • Loading branch information...
1 parent 776e188 commit 8d243cfdc2ed08ee2cd5d48a1e19dfe671758179 @chrisroos-and-lazyatom chrisroos-and-lazyatom committed May 4, 2011
Showing with 128 additions and 13 deletions.
  1. +1 −1 Gemfile
  2. +1 −1 Gemfile.lock
  3. +7 −7 Rakefile
  4. +4 −4 lib/blog.rb
  5. +42 −0 test/blog_renderer_test.rb
  6. +73 −0 test/test_helper.rb
View
2 Gemfile
@@ -1,7 +1,7 @@
source 'http://rubygems.org'
gem "haml"
-gem "vanilla", ">=1.13.2"
+gem "vanilla", "1.13.2"
gem "kramdown"
gem "capistrano"
View
2 Gemfile.lock
@@ -94,4 +94,4 @@ DEPENDENCIES
haml
kramdown
rake
- vanilla (>= 1.13.2)
+ vanilla (= 1.13.2)
View
14 Rakefile
@@ -1,9 +1,9 @@
-require 'vanilla'
-load 'tasks/vanilla.rake'
+task :default => :test
-task :default => :publish
-
-desc 'Publish to gofreerange.com'
-task :publish do
- raise "'rake publish' has been deprecated. Please use 'cap deploy' instead"
+require "rake/testtask"
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.ruby_opts << "-rubygems"
+ t.test_files = FileList["test/**/*_test.rb"]
+ t.verbose = true
end
View
8 lib/blog.rb
@@ -21,12 +21,12 @@ def process_text(content)
end
def article_date(time)
- suffix = case time.day.to_s.match(/(\d$)/)[0]
- when "1"
+ suffix = case time.day
+ when 1, 21, 31
"st"
- when "2"
+ when 2, 22
"nd"
- when "3"
+ when 3, 23
"rd"
else
"th"
View
42 test/blog_renderer_test.rb
@@ -0,0 +1,42 @@
+require "test_helper"
+require 'blog'
+
+class BlogRendererTest < Test::Unit::TestCase
+ include Vanilla::Test
+
+ def setup
+ setup_clean_environment
+ end
+
+ def teardown
+ FileUtils.rm_rf(test_app_directory)
+ end
+
+ def test_should_format_the_date
+ author_attrs = {:name => 'author-name', :content => 'Author Name', :image => 'author-image'}
+ blog_post_attrs = {
+ :name => "my-blog-post", :content => "x", :render_as => 'Blog', :kind => 'blog',
+ :written_with => 'Markdown', :author => author_attrs[:name], :page_title => 'page-title'
+ }
+
+ create_snip(:name => 'blog-template', :content => 'ENTRY_DATE')
+ create_snip(:name => 'blog-layout', :content => "<layout>{current_snip}</layout>")
+ create_snip(author_attrs)
+
+ days_of_month = 1.upto(31).to_a
+ {
+ :st => (sts = [1, 21, 31]),
+ :nd => (nds = [2, 22]),
+ :rd => (rds = [3, 23]),
+ :th => days_of_month - (sts + nds + rds)
+ }.each do |suffix, days|
+ days.each do |day|
+ date = Date.parse("2011-01-#{day}")
+ create_snip(blog_post_attrs.merge(:created_at => date))
+
+ assert_response_body_match "#{day}#{suffix} January", blog_post_attrs[:name]
+ end
+ end
+ end
+
+end
View
73 test/test_helper.rb
@@ -0,0 +1,73 @@
+require 'rubygems'
+require 'bundler/setup'
+require "fileutils"
+require "rack/mock"
+require "vanilla"
+require 'test/unit'
+
+module Vanilla
+ module Test
+ def setup_clean_environment
+ FileUtils.mkdir_p(File.dirname(config_file_for_tests))
+ File.open(config_file_for_tests, 'w') { |f| f.write({:soup => soup_path}.to_yaml) }
+ @app = Vanilla::App.new(config_file_for_tests)
+
+ require "vanilla/dynasnips/current_snip"
+ @app.soup << CurrentSnip.snip_attributes
+ create_snip :name => "layout", :content => "{current_snip}"
+ end
+
+ def response_for(url)
+ mock_env = Rack::MockRequest.env_for(url)
+ @app.call(mock_env)
+ end
+
+ def response_body_for(url)
+ response_for(url)[2].body[0]
+ end
+
+ def response_code_for(url)
+ response_for(url)[0]
+ end
+
+ def assert_response_body_equal(expected, uri)
+ assert_equal expected.strip, response_body_for(uri).strip
+ end
+
+ def assert_response_body_match(expected, uri)
+ assert_match expected, response_body_for(uri).strip
+ end
+
+ def set_main_template(template_content)
+ @app.soup << {:name => "layout", :content => template_content}
+ end
+
+ def create_snip(params)
+ @app.soup << params
+ end
+
+ def mock_env_for_url(url)
+ Rack::MockRequest.env_for(url)
+ end
+
+ def mock_request(url)
+ Rack::Request.new(mock_env_for_url(url))
+ end
+
+ def test_app_directory
+ File.join(File.dirname(__FILE__), "tmp")
+ end
+
+ def config_file_for_tests
+ File.join(test_app_directory, "config.yml")
+ end
+
+ def config_for_tests(options={})
+ File.open(config_file_for_tests, 'w') { |f| f.write({:soup => soup_path}.update(options).to_yaml) }
+ end
+
+ def soup_path
+ File.expand_path(File.join(test_app_directory, "soup"))
+ end
+ end
+end

0 comments on commit 8d243cf

Please sign in to comment.
Something went wrong with that request. Please try again.