Permalink
Browse files

Tests refactoring

  • Loading branch information...
alce committed Jul 11, 2010
1 parent b369e20 commit 175f18f2e514c609fee34f4b74294036d5552a36
Showing with 59 additions and 63 deletions.
  1. +1 −1 Rakefile
  2. +52 −0 test/blog_helper.rb
  3. +2 −7 test/functional/blog_controller_test.rb
  4. +2 −6 test/functional/blog_post_controller_test.rb
  5. +2 −49 test/test_helper.rb
View
@@ -26,7 +26,7 @@ begin
gemspec.files += Dir["lib/bcms_blog.rb"]
gemspec.files += Dir["lib/bcms_blog/*"]
gemspec.files += Dir["rails/init.rb"]
- gemspec.add_development_dependency 'bcms_test_support'
+ gemspec.add_development_dependency 'bcms_support'
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install jeweler"
View
@@ -0,0 +1,52 @@
+module BlogHelper
+
+ # Seeds all data created by this module's migrations
+ def seed_blog_data
+ @content_type_group = ContentTypeGroup.create!(:name => "Blog")
+ CategoryType.create!(:name => "Blog Post")
+ ContentType.create!(:name => "Blog", :content_type_group => @content_type_group)
+ ContentType.create!(:name => "BlogPost", :content_type_group => @content_type_group)
+ ContentType.create!(:name => "BlogComment", :content_type_group => @content_type_group)
+ end
+
+ # Creates data specifically used on tests
+ def create_test_data
+ template = %q[<% page_title @page_title || @blog.name %><%= render :partial => "partials/blog_post", :collection => @blog_posts %>"]
+ @blog = Blog.create!(:name => "MyBlog", :template => template)
+
+ @category_type = CategoryType.find_by_name("Blog Post")
+
+ @stuff = Category.create!(:name => "Stuff", :category_type => @category_type)
+ @general = Category.create!(:name => "General", :category_type => @category_type)
+
+ opts = {:blog => @blog, :publish_on_save => true}
+ @first_post = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 5, 6)))
+ @foo_post_1 = Factory(:blog_post, opts.merge(:category => @stuff, :published_at => Time.utc(2008, 7, 5, 12), :tag_list => "foo stuff"))
+ @foo_post_2 = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 21)))
+ @bar_post_1 = Factory(:blog_post, opts.merge(:category => @stuff, :published_at => Time.utc(2008, 9, 2), :tag_list => "foo stuff"))
+ @bar_post_2 = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2009, 3, 18)))
+
+ publish_all_pages
+ end
+
+ def setup_blog_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)
+ end
+
+ def create_group
+ @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
+ @group.permissions << Factory(:permission, :name => "edit_content")
+ @group.permissions << Factory(:permission, :name => "publish_content")
+ end
+
+ def create_user(opts = {})
+ create_group
+ @group.permissions << Factory(:permission, :name => "administrate") if opts[:admin]
+ @user = Factory(:user, :groups => [@group])
+ end
+end
@@ -5,13 +5,8 @@ class BlogControllerTest < ActionController::TestCase
def setup
seed_bcms_data
- # DATA CREATED ON BLOG MIGRATIONS
- @content_type_group = ContentTypeGroup.create!(:name => "Blog")
- CategoryType.create!(:name => "Blog Post")
- ContentType.create!(:name => "Blog", :content_type_group => @content_type_group)
- ContentType.create!(:name => "BlogPost", :content_type_group => @content_type_group)
- ContentType.create!(:name => "BlogComment", :content_type_group => @content_type_group)
- create_baseline_data
+ seed_blog_data
+ create_test_data
end
test "displays the list of blog posts" do
@@ -5,12 +5,8 @@ class BlogPostControllerTest < ActionController::TestCase
def setup
seed_bcms_data
- @content_type_group = ContentTypeGroup.create!(:name => "Blog")
- CategoryType.create!(:name => "Blog Post")
- ContentType.create!(:name => "Blog", :content_type_group => @content_type_group)
- ContentType.create!(:name => "BlogPost", :content_type_group => @content_type_group)
- ContentType.create!(:name => "BlogComment", :content_type_group => @content_type_group)
- create_baseline_data
+ seed_blog_data
+ create_test_data
end
# def test_show_post
View
@@ -5,60 +5,13 @@
require 'mocha'
require 'test_logging'
require 'bcms_support'
+require 'blog_helper'
class ActiveSupport::TestCase
-
include BcmsSupport::Test
+ include BlogHelper
include TestLogging
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
-
- def create_baseline_data
- @blog = Blog.create!(:name => "MyBlog", :template => %q[<% page_title @page_title || @blog.name %><%= render :partial => "partials/blog_post", :collection => @blog_posts %>"])
- @blog.publish
-
- @category_type = CategoryType.find_by_name("Blog Post")
-
- @stuff = Category.create!(:name => "Stuff", :category_type => @category_type)
- @general = Category.create!(:name => "General", :category_type => @category_type)
-
- @first_post = Factory(:blog_post, :blog => @blog, :category => @general,
- :published_at => Time.utc(2008, 7, 5, 6), :publish_on_save => true)
-
- @foo_post_1 = Factory(:blog_post, :blog => @blog, :category => @stuff,
- :published_at => Time.utc(2008, 7, 5, 12), :tag_list => "foo stuff", :publish_on_save => true)
-
- @foo_post_2 = Factory(:blog_post, :blog => @blog, :category => @general,
- :published_at => Time.utc(2008, 7, 21), :publish_on_save => true)
-
- @bar_post_1 = Factory(:blog_post, :blog => @blog, :category => @stuff,
- :published_at => Time.utc(2008, 9, 2), :tag_list => "foo stuff", :publish_on_save => true)
-
- @bar_post_2 = Factory(:blog_post, :blog => @blog, :category => @general,
- :published_at => Time.utc(2009, 3, 18), :publish_on_save => true)
-
- publish_all_pages
- end
-
- def setup_blog_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)
- end
-
- def create_group
- @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
- @group.permissions << Factory(:permission, :name => "edit_content")
- @group.permissions << Factory(:permission, :name => "publish_content")
- end
-
- def create_user(opts = {})
- create_group
- @group.permissions << Factory(:permission, :name => "administrate") if opts[:admin]
- @user = Factory(:user, :groups => [@group])
- end
end

0 comments on commit 175f18f

Please sign in to comment.