Permalink
Browse files

All unit tests passing

  • Loading branch information...
1 parent 84d3c54 commit a0cf832338639b90a224211b6eb4f25d5062f9f1 @alce alce committed May 24, 2010
Showing with 82 additions and 36 deletions.
  1. +21 −11 test/test_helper.rb
  2. +22 −2 test/unit/blog_comment_test.rb
  3. +36 −9 test/unit/blog_post_test.rb
  4. +3 −14 test/unit/blog_test.rb
View
@@ -3,17 +3,17 @@
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
-unless $database_initialized
- $database_initialized = true
-
- # Empty the database and load in the default seed data for browsercms
- # and the blog module
- `rake db:test:purge`
- `rake db:migrate`
-
- # Publish all pages, as they are drafts after migrating
- Page.find(:all).each(&:publish!)
-end
+# unless $database_initialized
+# $database_initialized = true
+#
+# # Empty the database and load in the default seed data for browsercms
+# # and the blog module
+# `rake db:test:purge`
+# `rake db:migrate`
+#
+# # Publish all pages, as they are drafts after migrating
+# Page.find(:all).each(&:publish!)
+# end
class ActiveSupport::TestCase
require File.dirname(__FILE__) + '/test_logging'
@@ -50,6 +50,16 @@ class ActiveSupport::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
+ def setup_stubs
+ Blog.any_instance.stubs(:reload_routes)
+ @section = Section.new
+ Section.stubs(:create! => @section)
+ @section.stubs(:groups => [], :save! => true)
+ Page.stubs(:create! => Page.new)
+ Page.any_instance.stubs(:create_connector)
+ Group.stubs(:find_by_code => Group.new)
+ end
+
def create_baseline_data
# Find the seed data items
@blog = Blog.find_by_name("My Blog")
@@ -2,11 +2,31 @@
class BlogCommentTest < ActiveSupport::TestCase
- test "it should not be published if Blog#moderate_comments is true" do
+ def setup
+ setup_stubs
+ end
+
+ test "crates a valid instance" do
+ assert Factory.build(:blog_comment).valid?
+ end
+
+ test "requires post" do
+ assert !Factory.build(:blog_comment, :post => nil).valid?
+ end
+
+ test "requires author" do
+ assert !Factory.build(:blog_comment, :author => nil).valid?
+ end
+
+ test "requires body" do
+ assert !Factory.build(:blog_comment, :body => nil).valid?
+ end
+
+ test "should not be published if Blog#moderate_comments is true" do
assert !Factory(:blog_comment).published?
end
- test "it should be published if Blog#moderate_comments is false" do
+ test "should be published if Blog#moderate_comments is false" do
blog = Factory(:blog, :moderate_comments => false)
post = Factory(:blog_post, :blog => blog)
assert Factory(:blog_comment, :post => post).published?
@@ -2,15 +2,42 @@
class BlogPostTest < ActiveSupport::TestCase
- def test_existing_record_should_record_published_at_when_published
- @blog_post = Factory.create(:blog_post)
-
- assert_nil @blog_post.published_at
- assert !@blog_post.new_record?
-
- @blog_post.publish!
-
- assert_not_nil @blog_post.published_at
+ def setup
+ setup_stubs
+ @post = Factory(:blog_post, :name => "This is the first Post")
+ end
+
+ test "cretates a valid instance" do
+ assert @post.valid?
+ end
+
+ test "requires name" do
+ assert !Factory.build(:blog_post, :name => nil).valid?
+ end
+
+ test "requires blog_id" do
+ assert !Factory.build(:blog_post, :blog => nil).valid?
+ end
+
+ test "requires author_id" do
+ assert !Factory.build(:blog_post, :author => nil).valid?
+ end
+
+ test "should set slug" do
+ assert_equal('this-is-the-first-post', @post.slug)
+ end
+
+ test "should set published_at when published" do
+ assert_nil @post.published_at
+ @post.publish!
+ assert_not_nil @post.published_at
+ end
+
+ test "BlogPost should find posts published between 2 given dates" do
+ @post.publish!
+ Factory(:blog_post, :published_at => 5.days.ago)
+ Factory(:blog_post, :published_at => 10.days.ago)
+ assert_equal(1, BlogPost.published_between(6.days.ago, 4.days.ago).count)
end
end
View
@@ -12,7 +12,7 @@ def setup
assert @blog.valid?
end
- test "should not be valid without a name" do
+ test "requires name" do
assert !Factory.build(:blog, :name => nil).valid?
end
@@ -25,7 +25,8 @@ def setup
end
test "should be editable by administrators" do
- admin = Factory(:user, :groups => [Group.find_by_code("cms-admin")])
+ admin = Factory(:user)
+ admin.expects(:able_to?).with(:administrate).returns(true)
assert @blog.editable_by?(admin)
end
@@ -82,16 +83,4 @@ def setup
end
- private
-
- def setup_stubs
- Blog.any_instance.stubs(:reload_routes)
- @section = Section.new
- Section.stubs(:create! => @section)
- @section.stubs(:groups => [], :save! => true)
- Page.stubs(:create! => Page.new)
- Page.any_instance.stubs(:create_connector)
-
- PageRoute.any_instance.stubs(:create_without_callbacks)
- end
end

0 comments on commit a0cf832

Please sign in to comment.