Skip to content
Browse files

* All tests pass now.

  • Loading branch information...
1 parent 26a6f2e commit be63af4129ef76059a6a0ef139ba54bb762cedf8 @peakpg peakpg committed Jan 6, 2012
Showing with 47 additions and 8 deletions.
  1. +13 −5 app/models/blog_observer.rb
  2. +4 −2 config/application.rb
  3. +3 −0 lib/bcms_blog/engine.rb
  4. +6 −0 test/factories.rb
  5. +21 −1 test/unit/blog_observer_test.rb
View
18 app/models/blog_observer.rb
@@ -5,15 +5,25 @@ def after_create(blog)
create_section_pages_and_routes
end
- def before_update(blog)
- update_section_pages_and_route(blog)
+ def after_save(blog)
+ if blog.persisted?
+ blog.publish
+ end
+ end
+
+ # Can't use before_update since CMS callback stack is altered from normal callbacks.
+ def before_save(blog)
+ if blog.persisted?
+ update_section_pages_and_route(blog)
+ end
end
def after_update(blog)
blog.publish
end
private
+
# A section, two pages, 6 routes and a portlet are created alongside every 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
@@ -37,9 +47,7 @@ def create_blog_section
:path => "/#{@blog.name_for_path}",
:parent_id => 1
)
- @section.groups << Group.find_by_code("cms-admin")
- @section.groups << Group.find_by_code("guest")
- @section.groups << Group.find_by_code("content-editor")
+ @section.allow_groups = :all
@section.save!
@section
)
View
6 config/application.rb
@@ -8,8 +8,10 @@
module BcmsBlog
class Application < Rails::Application
- # BrowserCMS should serve static CMS assets (js, css, images) from the Gem
-config.serve_static_assets = true
+ # BrowserCMS should serve static CMS assets (js, css, images) from the Gem
+ config.serve_static_assets = true
+
+
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
View
3 lib/bcms_blog/engine.rb
@@ -3,5 +3,8 @@
module BcmsBlog
class Engine < Rails::Engine
include Cms::Module
+
+ config.active_record.observers = :blog_observer
+
end
end
View
6 test/factories.rb
@@ -16,3 +16,9 @@
m.association :post, :factory => :blog_post
m.association :author, :factory => :user
end
+
+Factory.define :root_section, :class=>Section do |m|
+ m.name "My Site"
+ m.root true
+ m.path "/"
+end
View
22 test/unit/blog_observer_test.rb
@@ -1,5 +1,25 @@
require 'test_helper'
+class BlogPersistenceTest < ActiveSupport::TestCase
+
+ def setup
+ @root = Factory(:root_section)
+ @blog = Factory(:blog, :name => 'TestBlog')
+ end
+
+ test "Update pages/routes when a section changes" do
+ BlogObserver.any_instance.expects(:update_section_pages_and_route).with(@blog)
+ @blog.name = "Change the Name"
+ @blog.save!
+ end
+
+ test "Published afters saving" do
+ BlogObserver.any_instance.expects(:update_section_pages_and_route).with(@blog)
+ @blog.name = "Change the Name"
+ @blog.save!
+ assert @blog.published?
+ end
+end
class BlogObserverTest < ActiveSupport::TestCase
@@ -9,7 +29,7 @@ def setup
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)

0 comments on commit be63af4

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