Permalink
Browse files

BlogOvserver tests

  • Loading branch information...
1 parent 568bd15 commit e6c88a089e3d48891ce8439938866e8bc2197b3d @alce alce committed Jun 29, 2010
View
@@ -91,8 +91,4 @@ def potential_authors
def name_for_path
name.to_slug.gsub('-', '_')
end
-
- protected
-
-
end
@@ -18,7 +18,6 @@ def after_update(blog)
# This structure provides sensible defaults so users can pretty much start adding
# posts right after creating a blog without having to worry about where to put
# their blog and portlets.
-
def create_section_pages_and_routes
create_blog_section
create_blog_block_page
@@ -31,7 +30,6 @@ def create_section_pages_and_routes
# created. This section will hold two pages: one for the blog ContentBlock that
# will render the list of posts and one for the BlogPost portlet (ie the individual
# post view)
-
def create_blog_section
@section = Section.find_by_name(@blog.name) || (
@section = Section.create!(
@@ -51,7 +49,6 @@ def create_blog_section
# holds the Blog ContentBlock directly, not a portlet. Together with the 5 created routes,
# this page and its ContentBlock handle different post listings (all posts, posts in year,
# month or day and posts by tag or category).
-
def create_blog_block_page
page = Page.find_by_name(@blog.name) || Page.create!(
:name => @blog.name,
@@ -71,7 +68,6 @@ def create_blog_block_page
# The second page that is created holds the BlogPostPortlet and displays the individual
# post view, along with it's comments.
-
def create_post_portlet_page
page = Page.find_by_name(portlet_name = "#{@blog.name}: Post") || Page.create!(
:name => portlet_name,
@@ -92,7 +88,6 @@ def create_post_portlet_page
# Note that no other routes or paths are updated. This is intentional to be consistent
# with how BrowserCMS behaves when a Section or Page names change: paths are not
# updated automatically.
-
def update_section_pages_and_route(blog)
if blog.name_changed?
old_blog_name = blog.name_was
@@ -29,4 +29,5 @@
SITE_DOMAIN="localhost:3000"
config.gem "factory_girl", :source => "http://gemcutter.org"
+require "test/unit"
config.gem "mocha", :version => ">= 0.9.7"
View
@@ -2,6 +2,7 @@
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require 'factory_girl'
+require 'mocha'
class ActiveSupport::TestCase
require File.dirname(__FILE__) + '/test_logging'
@@ -1,8 +1,61 @@
require 'test_helper'
class BlogObserverTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
+
+ def setup
+ setup_stubs
+ [Section, PageRoute, Page].each {|klass| klass.stubs(:find_by_name)}
+ BlogPostPortlet.stubs(:create!)
+ @blog = Factory(:blog, :name => 'TestBlog')
+ end
+
+ test "does not update section, pageroute and pages if name did not change when updated" do
+ [Section, PageRoute, Page].each {|klass| klass.expects(:find_by_name).never}
+ @blog.toggle!(:moderate_comments)
+ end
+
+ test "updates section, pageroute and pages if name changed" do
+ route = mock('page_route', :update_attribute => true)
+ page = mock('page')
+ Section.expects(:find_by_name).returns(Section.new)
+ PageRoute.expects(:find_by_name).returns(route)
+ Page.expects(:find_by_name).twice.returns(page)
+ page.expects(:update_attribute).twice.returns(true)
+ page.expects(:publish).twice.returns(true)
+
+ @blog.update_attribute(:name, "OtherName")
end
+
+ test "should create a section with the same name and route" do
+ Section.expects(:create!).with(:name => 'Test', :path => '/test', :parent_id => 1).returns(@section)
+ Factory(:blog, :name => 'Test')
+ end
+
+ test "should create a hidden page with the same name in the section with the blog's name" do
+ Page.expects(:create!).with(:name => 'Test',
+ :path => '/test',
+ :section => @section,
+ :template_file_name => 'default.html.erb',
+ :hidden => true).returns(Page.new)
+ Factory(:blog, :name => 'Test')
+ end
+
+ test "should create a page to hold the BlogPostPortlet" do
+ Page.expects(:create!).with(:name => 'Test: Post',
+ :path => '/test/post',
+ :section => @section,
+ :template_file_name => 'default.html.erb',
+ :hidden => true).returns(Page.new)
+ Factory(:blog, :name => 'Test')
+ end
+
+ test "should create an instance of BlogPostPortlet" do
+ BlogPostPortlet.expects(:create!).with(:name => 'Test: Post Portlet',
+ :blog_id => 2,
+ :template => BlogPostPortlet.default_template,
+ :connect_to_page_id => nil,
+ :connect_to_container => 'main',
+ :publish_on_save => true).returns(BlogPostPortlet.new)
+ Factory(:blog, :name => 'Test')
+ end
end
View
@@ -5,7 +5,6 @@ class BlogTest < ActiveSupport::TestCase
def setup
setup_stubs
@blog = Factory(:blog, :name => 'TestBlog')
- # Factory(:blog_post, :blog => @blog) #unpublished post
end
test "creates a valid instance" do
@@ -29,30 +28,7 @@ def setup
admin.expects(:able_to?).with(:administrate).returns(true)
assert @blog.editable_by?(admin)
end
-
- test "should create a section with the same name and route" do
- Section.expects(:create!).with(:name => 'Test', :path => '/test', :parent_id => 1).returns(@section)
- Factory(:blog, :name => 'Test')
- end
-
- test "should create a hidden page with the same name in the section with the blog's name" do
- Page.expects(:create!).with(:name => 'Test',
- :path => '/test',
- :section => @section,
- :template_file_name => 'default.html.erb',
- :hidden => true).returns(Page.new)
- Factory(:blog, :name => 'Test')
- end
-
- test "should create a page to hold the BlogPostPortlet" do
- Page.expects(:create!).with(:name => 'Test: Post',
- :path => '/test/post',
- :section => @section,
- :template_file_name => 'default.html.erb',
- :hidden => true).returns(Page.new)
- Factory(:blog, :name => 'Test')
- end
-
+
test "should create an instance of BlogPostPortlet" do
BlogPostPortlet.expects(:create!).with(:name => 'Test: Post Portlet',
:blog_id => 2,
@@ -62,11 +38,9 @@ def setup
:publish_on_save => true).returns(BlogPostPortlet.new)
Factory(:blog, :name => 'Test')
end
+
- # test "should update section and page names on name update" do
- # end
-
- # test "should find posts tagged with 'Ruby'" do
+ # test "#render should find posts tagged with 'Ruby'" do
#
# end
#

0 comments on commit e6c88a0

Please sign in to comment.