Skip to content
This repository
Browse code

Tests refactoring

  • Loading branch information...
commit 175f18f2e514c609fee34f4b74294036d5552a36 1 parent b369e20
Juan  Alvarez authored July 10, 2010
2  Rakefile
@@ -26,7 +26,7 @@ begin
26 26
     gemspec.files += Dir["lib/bcms_blog.rb"]
27 27
     gemspec.files += Dir["lib/bcms_blog/*"]
28 28
     gemspec.files += Dir["rails/init.rb"]
29  
-    gemspec.add_development_dependency 'bcms_test_support'
  29
+    gemspec.add_development_dependency 'bcms_support'
30 30
   end
31 31
 rescue LoadError
32 32
   puts "Jeweler not available. Install it with: sudo gem install jeweler"
52  test/blog_helper.rb
... ...
@@ -0,0 +1,52 @@
  1
+module BlogHelper
  2
+
  3
+  # Seeds all data created by this module's migrations
  4
+  def seed_blog_data
  5
+    @content_type_group = ContentTypeGroup.create!(:name => "Blog")
  6
+    CategoryType.create!(:name => "Blog Post") 
  7
+    ContentType.create!(:name  => "Blog", :content_type_group => @content_type_group)
  8
+    ContentType.create!(:name  => "BlogPost", :content_type_group => @content_type_group)
  9
+    ContentType.create!(:name  => "BlogComment", :content_type_group => @content_type_group)   
  10
+  end
  11
+
  12
+  # Creates data specifically used on tests
  13
+  def create_test_data
  14
+    template = %q[<% page_title @page_title || @blog.name %><%= render :partial => "partials/blog_post", :collection => @blog_posts %>"]
  15
+    @blog = Blog.create!(:name => "MyBlog", :template => template)
  16
+
  17
+    @category_type = CategoryType.find_by_name("Blog Post")
  18
+
  19
+    @stuff = Category.create!(:name => "Stuff", :category_type => @category_type)
  20
+    @general = Category.create!(:name => "General", :category_type => @category_type)
  21
+
  22
+    opts = {:blog => @blog, :publish_on_save => true}
  23
+    @first_post = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 5, 6)))
  24
+    @foo_post_1 = Factory(:blog_post, opts.merge(:category => @stuff,   :published_at => Time.utc(2008, 7, 5, 12), :tag_list => "foo stuff"))
  25
+    @foo_post_2 = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 21)))
  26
+    @bar_post_1 = Factory(:blog_post, opts.merge(:category => @stuff,   :published_at => Time.utc(2008, 9, 2),     :tag_list => "foo stuff"))
  27
+    @bar_post_2 = Factory(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2009, 3, 18)))
  28
+
  29
+    publish_all_pages
  30
+  end
  31
+
  32
+  def setup_blog_stubs
  33
+    Blog.any_instance.stubs(:reload_routes)
  34
+    @section = Section.new
  35
+    Section.stubs(:create! => @section)
  36
+    @section.stubs(:groups => [], :save! => true)
  37
+    Page.stubs(:create! => Page.new)
  38
+    Page.any_instance.stubs(:create_connector)
  39
+  end
  40
+
  41
+  def create_group
  42
+    @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
  43
+    @group.permissions << Factory(:permission, :name => "edit_content")
  44
+    @group.permissions << Factory(:permission, :name => "publish_content")
  45
+  end
  46
+
  47
+  def create_user(opts = {})
  48
+    create_group
  49
+    @group.permissions << Factory(:permission, :name => "administrate") if opts[:admin]
  50
+    @user = Factory(:user, :groups => [@group])
  51
+  end
  52
+end
9  test/functional/blog_controller_test.rb
@@ -5,13 +5,8 @@ class BlogControllerTest < ActionController::TestCase
5 5
 
6 6
   def setup
7 7
     seed_bcms_data
8  
-    # DATA CREATED ON BLOG MIGRATIONS
9  
-    @content_type_group = ContentTypeGroup.create!(:name => "Blog")
10  
-    CategoryType.create!(:name => "Blog Post") 
11  
-    ContentType.create!(:name  => "Blog", :content_type_group => @content_type_group)
12  
-    ContentType.create!(:name  => "BlogPost", :content_type_group => @content_type_group)
13  
-    ContentType.create!(:name  => "BlogComment", :content_type_group => @content_type_group)
14  
-    create_baseline_data
  8
+    seed_blog_data
  9
+    create_test_data
15 10
   end
16 11
 
17 12
   test "displays the list of blog posts" do
8  test/functional/blog_post_controller_test.rb
@@ -5,12 +5,8 @@ class BlogPostControllerTest < ActionController::TestCase
5 5
   
6 6
   def setup
7 7
     seed_bcms_data
8  
-    @content_type_group = ContentTypeGroup.create!(:name => "Blog")
9  
-    CategoryType.create!(:name => "Blog Post") 
10  
-    ContentType.create!(:name  => "Blog", :content_type_group => @content_type_group)
11  
-    ContentType.create!(:name  => "BlogPost", :content_type_group => @content_type_group)
12  
-    ContentType.create!(:name  => "BlogComment", :content_type_group => @content_type_group)
13  
-    create_baseline_data
  8
+    seed_blog_data
  9
+    create_test_data
14 10
   end
15 11
 
16 12
   # def test_show_post
51  test/test_helper.rb
@@ -5,60 +5,13 @@
5 5
 require 'mocha'
6 6
 require 'test_logging'
7 7
 require 'bcms_support'
  8
+require 'blog_helper'
8 9
 
9 10
 class ActiveSupport::TestCase
10  
-
11 11
   include BcmsSupport::Test
  12
+  include BlogHelper
12 13
   include TestLogging
13 14
 
14 15
   self.use_transactional_fixtures = true
15 16
   self.use_instantiated_fixtures  = false
16  
-
17  
-  def create_baseline_data
18  
-    @blog = Blog.create!(:name => "MyBlog", :template => %q[<% page_title @page_title || @blog.name %><%= render :partial => "partials/blog_post", :collection => @blog_posts %>"])
19  
-    @blog.publish
20  
-
21  
-    @category_type = CategoryType.find_by_name("Blog Post")
22  
-
23  
-    @stuff = Category.create!(:name => "Stuff", :category_type => @category_type)
24  
-    @general = Category.create!(:name => "General", :category_type => @category_type)
25  
-
26  
-    @first_post = Factory(:blog_post, :blog => @blog, :category => @general,
27  
-    :published_at => Time.utc(2008, 7, 5, 6), :publish_on_save => true)
28  
-
29  
-    @foo_post_1 = Factory(:blog_post, :blog => @blog, :category => @stuff,
30  
-    :published_at => Time.utc(2008, 7, 5, 12), :tag_list => "foo stuff", :publish_on_save => true)
31  
-
32  
-    @foo_post_2 = Factory(:blog_post, :blog => @blog, :category => @general,
33  
-    :published_at => Time.utc(2008, 7, 21), :publish_on_save => true)
34  
-
35  
-    @bar_post_1 = Factory(:blog_post, :blog => @blog, :category => @stuff,
36  
-    :published_at => Time.utc(2008, 9, 2), :tag_list => "foo stuff", :publish_on_save => true)
37  
-
38  
-    @bar_post_2 = Factory(:blog_post, :blog => @blog, :category => @general,
39  
-    :published_at => Time.utc(2009, 3, 18), :publish_on_save => true)
40  
-    
41  
-    publish_all_pages
42  
-  end
43  
-
44  
-  def setup_blog_stubs
45  
-    Blog.any_instance.stubs(:reload_routes)
46  
-    @section = Section.new
47  
-    Section.stubs(:create! => @section)
48  
-    @section.stubs(:groups => [], :save! => true)
49  
-    Page.stubs(:create! => Page.new)
50  
-    Page.any_instance.stubs(:create_connector)
51  
-  end
52  
-
53  
-  def create_group
54  
-    @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
55  
-    @group.permissions << Factory(:permission, :name => "edit_content")
56  
-    @group.permissions << Factory(:permission, :name => "publish_content")
57  
-  end
58  
-
59  
-  def create_user(opts = {})
60  
-    create_group
61  
-    @group.permissions << Factory(:permission, :name => "administrate") if opts[:admin]
62  
-    @user = Factory(:user, :groups => [@group])
63  
-  end
64 17
 end

0 notes on commit 175f18f

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