bcms_blog 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data/Gemfile +10 -0
  2. data/README.markdown +10 -4
  3. data/app/assets/javascripts/bcms_blog/application.js +15 -0
  4. data/app/assets/stylesheets/bcms_blog/application.css +13 -0
  5. data/app/controllers/bcms_blog/blog_comments_controller.rb +5 -0
  6. data/app/controllers/bcms_blog/blog_posts_controller.rb +37 -0
  7. data/app/controllers/bcms_blog/blogs_controller.rb +13 -0
  8. data/app/controllers/bcms_blog/feeds_controller.rb +10 -0
  9. data/app/helpers/bcms_blog/blog_helper.rb +27 -0
  10. data/app/models/bcms_blog/blog.rb +99 -0
  11. data/app/models/bcms_blog/blog_comment.rb +36 -0
  12. data/app/models/bcms_blog/blog_group_membership.rb +6 -0
  13. data/app/models/bcms_blog/blog_observer.rb +141 -0
  14. data/app/models/bcms_blog/blog_post.rb +108 -0
  15. data/app/portlets/blog_post_portlet.rb +6 -6
  16. data/app/portlets/blog_posts_portlet.rb +4 -4
  17. data/app/views/bcms_blog/blog_comments/_form.html.erb +5 -0
  18. data/app/views/bcms_blog/blog_comments/render.html.erb +2 -0
  19. data/app/views/{cms → bcms_blog}/blog_posts/_form.html.erb +1 -1
  20. data/app/views/{cms → bcms_blog}/blog_posts/no_access.html.erb +0 -0
  21. data/app/views/{cms → bcms_blog}/blog_posts/render.html.erb +0 -0
  22. data/app/views/{cms → bcms_blog}/blogs/_form.html.erb +2 -2
  23. data/app/views/{cms → bcms_blog}/blogs/admin_only.html.erb +0 -0
  24. data/app/views/{cms → bcms_blog}/blogs/render.html.erb +0 -0
  25. data/app/views/{feeds → bcms_blog/feeds}/index.rss.builder +3 -3
  26. data/app/views/portlets/blog_post/_form.html.erb +1 -1
  27. data/app/views/portlets/blog_post/render.html.erb +3 -1
  28. data/app/views/portlets/blog_posts/_form.html.erb +1 -1
  29. data/config/routes.rb +5 -0
  30. data/db/bcms_blog.seeds.rb +4 -0
  31. data/db/migrate/20090415000000_create_blogs.rb +5 -6
  32. data/db/migrate/20090415000001_create_blog_posts.rb +1 -5
  33. data/db/migrate/20090415000002_create_blog_comments.rb +0 -2
  34. data/db/migrate/20120529184028_v130.rb +12 -0
  35. data/lib/bcms_blog/engine.rb +15 -1
  36. data/lib/bcms_blog/route_extensions.rb +8 -0
  37. data/lib/bcms_blog/version.rb +3 -0
  38. data/lib/bcms_blog.rb +5 -2
  39. data/lib/generators/bcms_blog/install/install_generator.rb +11 -11
  40. data/lib/tasks/bcms_blog_tasks.rake +4 -0
  41. data/test/bcms_blog_test.rb +7 -0
  42. data/test/functional/cms/blog_posts_controller_test.rb +47 -0
  43. data/test/functional/cms/blogs_controller_test.rb +27 -0
  44. data/test/integration/blog_controller_test.rb +63 -0
  45. data/test/integration/blog_post_test.rb +31 -0
  46. data/test/support/blog_test_helper.rb +71 -0
  47. data/test/support/factories.rb +54 -0
  48. data/test/support/factory_girl_support.rb +2 -0
  49. data/test/test_helper.rb +15 -0
  50. data/test/test_logging.rb +64 -0
  51. data/test/unit/blog_comment_test.rb +34 -0
  52. data/test/unit/blog_observer_test.rb +84 -0
  53. data/test/unit/blog_post_test.rb +45 -0
  54. data/test/unit/blog_test.rb +42 -0
  55. data/test/unit/helpers/feeds_helper_test.rb +4 -0
  56. metadata +83 -35
  57. data/app/controllers/cms/blog_comments_controller.rb +0 -3
  58. data/app/controllers/cms/blog_posts_controller.rb +0 -35
  59. data/app/controllers/cms/blogs_controller.rb +0 -11
  60. data/app/controllers/feeds_controller.rb +0 -8
  61. data/app/helpers/cms/blog_helper.rb +0 -20
  62. data/app/models/blog.rb +0 -95
  63. data/app/models/blog_comment.rb +0 -34
  64. data/app/models/blog_group_membership.rb +0 -4
  65. data/app/models/blog_observer.rb +0 -140
  66. data/app/models/blog_post.rb +0 -113
  67. data/app/views/cms/blog_comments/_form.html.erb +0 -5
  68. data/app/views/cms/blog_comments/render.html.erb +0 -2
  69. data/app/views/layouts/templates/default.html.erb +0 -17
  70. data/doc/README_FOR_APP +0 -2
  71. data/doc/migrate_to_20100427.rb +0 -77
  72. data/doc/release_notes.txt +0 -48
  73. data/lib/bcms_blog/routes.rb +0 -10
@@ -5,7 +5,7 @@
5
5
  <label>Permissions</label>
6
6
  <%= hidden_field_tag "blog[group_ids][]", "", :id => nil %>
7
7
  <div class="checkboxes">
8
- <% for group in Group.cms_access.all(:order => "groups.name") %>
8
+ <% for group in Cms::Group.cms_access.all(:order => "groups.name") %>
9
9
  <div class="checkbox_fields">
10
10
  <%= check_box_tag "blog[group_ids][]", group.id,
11
11
  @block.groups.include?(group), :class => "cms_group_ids", :id => "cms_group_ids_#{group.id}", :tabindex => next_tabindex %>
@@ -21,7 +21,7 @@
21
21
  </div>
22
22
  <br clear="all" />
23
23
 
24
- <%= f.cms_text_area :template, :default_value => Blog.default_template %>
24
+ <%= f.cms_text_area :template, :default_value => BcmsBlog::Blog.default_template %>
25
25
 
26
26
  <div class="instructions" style="float:none">
27
27
  Saving your blog might take a couple of seconds while everything is set up.
File without changes
@@ -2,7 +2,7 @@ xml.instruct! :xml, :version=>"1.0"
2
2
  xml.rss(:version=>"2.0") do
3
3
  xml.channel do
4
4
  xml.title("#{@blog.name} Posts Feed")
5
- xml.link(blog_feeds_url(:id => @blog.id, :format => "rss"))
5
+ xml.link(main_app.blog_feeds_url(:id => @blog.id, :format => "rss"))
6
6
  xml.description("")
7
7
  xml.language('en-us')
8
8
  for post in @blog_posts
@@ -10,8 +10,8 @@ xml.rss(:version=>"2.0") do
10
10
  xml.title(post.name)
11
11
  xml.description(post.summary) unless post.summary.blank?
12
12
  xml.pubDate(post.published_at.strftime("%a, %d %b %Y %H:%M:%S %z")) unless post.published_at.blank?
13
- xml.link(send("#{@blog.name_for_path}_post_url", post.route_params))
14
- xml.guid(send("#{@blog.name_for_path}_post_url", post.route_params))
13
+ xml.link(main_app.send("#{@blog.name_for_path}_post_url", post.route_params))
14
+ xml.guid(main_app.send("#{@blog.name_for_path}_post_url", post.route_params))
15
15
  end
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  <%= f.cms_text_field :name %>
2
- <%= f.cms_drop_down :blog_id, Blog.all.map{|b| [b.name, b.id.to_s]} %>
2
+ <%= f.cms_drop_down :blog_id, BcmsBlog::Blog.all.map{|b| [b.name, b.id.to_s]} %>
3
3
  <%# f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -7,7 +7,9 @@
7
7
  <%= render :partial => "partials/blog_post", :object => @blog_post %>
8
8
 
9
9
  <div class="blog_comment_form">
10
- <%= form_for @blog_comment, :url => new_comment_path(@portlet) do |f| %>
10
+ <%#= form_for @blog_comment, :url => new_comment_path(@portlet) do |f| %>
11
+ <%= form_for @blog_comment, new_comment_params(@portlet) do |f| %>
12
+
11
13
  <%= f.hidden_field :post_id %>
12
14
  <%= f.cms_error_messages %>
13
15
  <div class="fields text_fields">
@@ -1,6 +1,6 @@
1
1
  <%= f.cms_text_field :name, :label => 'Portlet Name', :instructions => 'Since we may have many Articles portlets, each with different parameters, give each portlet a descriptive name.' %>
2
2
 
3
- <%= f.cms_drop_down :blog_id, Blog.all.map{|b| [b.name, b.id.to_s]}, :include_blank => true, :label => "Show posts from", :instructions => 'Leave blank to include posts from all blogs' %>
3
+ <%= f.cms_drop_down :blog_id, Bcms::Blog.all.map{|b| [b.name, b.id.to_s]}, :include_blank => true, :label => "Show posts from", :instructions => 'Leave blank to include posts from all blogs' %>
4
4
  <%# f.cms_drop_down :show_posts_as, [['First post as full post, the rest as Summary + Read More link', 'first_full_post_others_summary'], ['Summary + Read More link', 'summary'], ['Full post', 'full_post'], ['Title (links to post)', 'link']] %>
5
5
  <%= f.cms_drop_down :show_posts_as, [['Title (links to post)', 'link'], ['Post', 'post']] %>
6
6
  <%= f.cms_check_box :show_full_posts %>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ BcmsBlog::Engine.routes.draw do
2
+ content_blocks :blogs
3
+ content_blocks :blog_posts
4
+ content_blocks :blog_comments
5
+ end
@@ -0,0 +1,4 @@
1
+ Cms::ContentType.create!(:name => "BcmsBlog::Blog", :group_name => "Blog")
2
+ Cms::CategoryType.create!(:name => "Blog Post")
3
+ Cms::ContentType.create!(:name => "BcmsBlog::BlogPost", :group_name => "Blog")
4
+ Cms::ContentType.create!(:name => "BcmsBlog::BlogComment", :group_name => "Blog")
@@ -1,11 +1,11 @@
1
1
  require 'pp'
2
2
 
3
- Page # trigger auto-loading
3
+ Cms::Page # trigger auto-loading
4
4
  # At the time of this writing, these associations are missing :dependent => :destroy
5
- class Page
5
+ class Cms::Page
6
6
  has_many :page_routes, :dependent => :destroy
7
7
  end
8
- class PageRoute
8
+ class Cms::PageRoute
9
9
  has_many :requirements, :class_name => "PageRouteRequirement", :dependent => :destroy
10
10
  has_many :conditions, :class_name => "PageRouteCondition", :dependent => :destroy
11
11
  end
@@ -23,7 +23,6 @@ class CreateBlogs < ActiveRecord::Migration
23
23
  t.integer :group_id
24
24
  end
25
25
 
26
- ContentType.create!(:name => "Blog", :group_name => "Blog")
27
26
  end
28
27
 
29
28
  def self.down
@@ -34,8 +33,8 @@ class CreateBlogs < ActiveRecord::Migration
34
33
  #Blog.all.map(&:connected_pages).flatten.map(&:page_routes).flatten.each(&:destroy)
35
34
  pp Blog.all.map(&:connected_pages).flatten.each(&:destroy)
36
35
 
37
- ContentType.destroy_all(:name => "Blog")
38
- Connector.destroy_all(:connectable_type => "Blog")
36
+ Cms::ContentType.destroy_all(:name => "Blog")
37
+ Cms::Connector.destroy_all(:connectable_type => "Blog")
39
38
 
40
39
  drop_table :blog_versions
41
40
  drop_table :blogs
@@ -11,14 +11,10 @@ class CreateBlogPosts < ActiveRecord::Migration
11
11
  t.integer :comments_count
12
12
  t.datetime :published_at
13
13
  end
14
- CategoryType.create!(:name => "Blog Post")
15
- ContentType.create!(:name => "BlogPost", :group_name => "Blog")
14
+
16
15
  end
17
16
 
18
17
  def self.down
19
- ContentType.destroy_all(:name => 'BlogPost')
20
- CategoryType.destroy_all(:name => "Blog Post")
21
-
22
18
  drop_table :blog_post_versions
23
19
  drop_table :blog_posts
24
20
  end
@@ -8,11 +8,9 @@ class CreateBlogComments < ActiveRecord::Migration
8
8
  t.string :ip
9
9
  t.text :body
10
10
  end
11
- ContentType.create!(:name => "BlogComment", :group_name => "Blog")
12
11
  end
13
12
 
14
13
  def self.down
15
- ContentType.destroy_all(:name => 'BlogComment')
16
14
  drop_table :blog_comment_versions
17
15
  drop_table :blog_comments
18
16
  end
@@ -0,0 +1,12 @@
1
+ require 'cms/upgrades/v3_5_0'
2
+
3
+ # Upgrade this module to v1.3.0 of BcmsBlog (Rails 3.2/CMS 3.5.x compatible)
4
+ class V130 < ActiveRecord::Migration
5
+ def change
6
+ ["Blog", "BlogPost", "BlogComment"].each do |model|
7
+ v3_5_0_apply_namespace_to_block("BcmsBlog", model)
8
+ end
9
+
10
+ rename_table "blog_group_memberships", "bcms_blog_blog_group_memberships"
11
+ end
12
+ end
@@ -3,8 +3,22 @@ require 'browsercms'
3
3
  module BcmsBlog
4
4
  class Engine < Rails::Engine
5
5
  include Cms::Module
6
+ isolate_namespace BcmsBlog
6
7
 
7
- config.active_record.observers = :blog_observer
8
+ config.active_record.observers = 'bcms_blog/blog_observer'
8
9
 
10
+ config.to_prepare do
11
+ Cms::ViewContext.send(:include, BcmsBlog::BlogHelper)
12
+ ApplicationHelper.send(:include, BcmsBlog::BlogHelper)
13
+ end
14
+
15
+ initializer 'bcms_blog.route_extensions', :after => 'action_dispatch.prepare_dispatcher' do |app|
16
+ ActionDispatch::Routing::Mapper.send :include, BcmsBlog::RouteExtensions
17
+ end
18
+
19
+ config.before_configuration do |app|
20
+ # Used by blog_feed_url to determine the host
21
+ Rails.application.routes.default_url_options[:host]= config.cms.site_domain
22
+ end
9
23
  end
10
24
  end
@@ -0,0 +1,8 @@
1
+ module BcmsBlog::RouteExtensions
2
+ def mount_bcms_blog
3
+ mount BcmsBlog::Engine => "/bcms_blog"
4
+ match '/blog/feeds', :to=>"bcms_blog/feeds#index", :defaults=>{:format => "rss"}, :as=>'blog_feeds'
5
+ end
6
+
7
+ alias :routes_for_bcms_blog :mount_bcms_blog
8
+ end
@@ -0,0 +1,3 @@
1
+ module BcmsBlog
2
+ VERSION = "1.3.0"
3
+ end
data/lib/bcms_blog.rb CHANGED
@@ -1,2 +1,5 @@
1
- require 'bcms_blog/engine'
2
- require 'bcms_blog/routes'
1
+ require "bcms_blog/engine"
2
+ require 'bcms_blog/route_extensions'
3
+
4
+ module BcmsBlog
5
+ end
@@ -2,17 +2,17 @@ require 'cms/module_installation'
2
2
 
3
3
  class BcmsBlog::InstallGenerator < Cms::ModuleInstallation
4
4
  add_migrations_directory_to_source_root __FILE__
5
-
6
- # Add migrations to be copied, by uncommenting the following file and editing as needed.
7
5
 
8
- ['20090415000001_create_blog_posts.rb', '20090415000000_create_blogs.rb', '20090415000002_create_blog_comments.rb',
9
- '20090415000003_add_attachment_to_blog_posts.rb', '20100521042244_add_moderate_comments_to_blog.rb'].each do |mg|
10
- copy_migration_file mg
11
- end
6
+ def copy_migrations
7
+ rake 'bcms_blog:install:migrations'
8
+ end
9
+
10
+ def add_seed_data_to_project
11
+ copy_file "../bcms_blog.seeds.rb", "db/bcms_blog.seeds.rb"
12
+ append_to_file "db/seeds.rb", "\nload File.expand_path('../bcms_blog.seeds.rb', __FILE__)\n"
13
+ end
12
14
 
13
- def add_helpers
14
- append_to_file 'app/helpers/application_helper.rb', :after=>"module ApplicationHelper\n" do
15
- " include Cms::BlogHelper\n"
16
- end
17
- end
15
+ def add_routes
16
+ route 'mount_bcms_blog'
17
+ end
18
18
  end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bcms_blog do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class BcmsBlogTest < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, BcmsBlog
6
+ end
7
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ module BcmsBlog
4
+ class BlogPostsControllerTest < ActionController::TestCase
5
+
6
+ def setup
7
+ setup_blog_stubs
8
+ Cms::ContentType.create!(:name => 'BcmsBlog::BlogPost', :group_name => 'Blog')
9
+ login_as(create_user)
10
+ end
11
+
12
+ def test_access_denied_on_create_if_blog_not_user_editable
13
+ @editable = create(:blog, :groups => [@group])
14
+ @non_editable = create(:blog)
15
+ post :create, :blog_post => { :blog_id => @non_editable.id }
16
+ assert @response.body.include?("Access Denied")
17
+ end
18
+
19
+ def test_access_denied_on_update_if_blog_not_user_editable
20
+ @editable = create(:blog, :groups => [@group])
21
+ @non_editable = create(:blog)
22
+ @blog_post = create(:blog_post, :blog => @non_editable)
23
+ put :update, :id => @blog_post, :blog_post => { :name => "Foo" }
24
+ assert @response.body.include?("Access Denied")
25
+ end
26
+
27
+ def test_no_access_if_no_editable_blogs
28
+ @blog = create(:blog)
29
+ get :index
30
+ assert_template "no_access"
31
+ end
32
+
33
+ def test_index_shouldnt_show_non_editable_posts
34
+ @editable = create(:blog, :groups => [@group])
35
+ @non_editable = create(:blog)
36
+ @blog_post = create(:blog_post, :name => "Non-editable", :blog => @non_editable)
37
+ get :index
38
+ assert !@response.body.include?("Non-editable")
39
+ end
40
+
41
+ def test_create_sets_author
42
+ @blog = create(:blog, :groups => [@group])
43
+ post :create, :blog_post => { :blog_id => @blog.id }
44
+ assert_equal @user, assigns(:block).author
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ module BcmsBlog
4
+ class BlogsControllerTest < ActionController::TestCase
5
+
6
+ def setup
7
+ setup_blog_stubs
8
+ Cms::ContentType.create!(:name => 'BcmsBlog::Blog', :group_name => 'Blog')
9
+ create(:blog)
10
+ end
11
+
12
+ test "should allow access to admin users" do
13
+ login_as(create_user(:admin => true))
14
+ get :index
15
+ assert_response :success
16
+ assert assigns(:blocks)
17
+ assert_template("index")
18
+ end
19
+
20
+ test "should not allow access to non-admin users" do
21
+ login_as(create_user)
22
+ get :index
23
+ assert_response :success
24
+ assert_select "p", "Sorry, this section is restricted to administrators."
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+
3
+ class BlogControllerTest < ActionController::IntegrationTest
4
+ def setup
5
+ seed_bcms_data
6
+ seed_blog_data
7
+ create_test_data
8
+ end
9
+
10
+ test "displays the list of blog posts" do
11
+ get "/myblog"
12
+
13
+ assert_response :success
14
+ assert_select ".blog_post", 5
15
+
16
+ assert_select "#blog_post_#{@first_post.id}" do
17
+ assert_select "h2 a", @first_post.name
18
+ assert_select "div.body", @first_post.body
19
+ assert_select "div.meta" do
20
+ assert_select "a", 2
21
+ end
22
+ end
23
+ assert_select "#blog_post_#{@foo_post_1.id}" do
24
+ assert_select "h2 a", @foo_post_1.name
25
+ assert_select "div.body", @foo_post_1.body
26
+ assert_select "div.meta .tags a", "foo"
27
+ assert_select "div.meta .tags a", "stuff"
28
+ end
29
+ end
30
+
31
+ test "list of blog posts by category" do
32
+ get "/myblog/category/General"
33
+ assert_response :success
34
+ assert_select ".blog_post", 3
35
+ end
36
+
37
+ test "list of blog posts by tag" do
38
+ get "/myblog/tag/foo"
39
+ assert_response :success
40
+ assert_select ".blog_post", 2
41
+ end
42
+
43
+ test "list_of_blog_posts_in_day" do
44
+ get "/myblog/2008/07/05"
45
+ assert_response :success
46
+ assert_select ".blog_post", 2
47
+ end
48
+
49
+ test "list_of_blog_posts_in_month" do
50
+ get '/myblog/2008/07'
51
+ assert_response :success
52
+ assert_select ".blog_post", 3
53
+ end
54
+
55
+ test "list_of_blog_posts_in_year" do
56
+ get "/myblog/2008"
57
+ assert_response :success
58
+ assert_select ".blog_post", 4
59
+ end
60
+
61
+ private
62
+
63
+ end
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class BlogPostIntegrationTest < ActionController::IntegrationTest
4
+
5
+ def setup
6
+ seed_bcms_data
7
+ seed_blog_data
8
+ create_test_data
9
+ end
10
+
11
+ def test_show_post
12
+ get "/myblog/#{@first_post.year}/#{@first_post.month}/#{@first_post.day}/#{@first_post.slug}"
13
+ assert_response :success
14
+ assert_select "title", @first_post.name
15
+ assert_select ".blog_post", 1
16
+
17
+ assert_select "#blog_post_#{@first_post.id}" do
18
+ assert_select "h2 a", @first_post.name
19
+ assert_select ".body", @first_post.body
20
+ assert_select ".meta a", "General"
21
+ assert_select ".meta a", "0 Comments"
22
+ end
23
+
24
+ end
25
+
26
+ test "non_existent_post_should_return_404" do
27
+ get "/myblog/2005/6/14/non-existent"
28
+ assert_response :not_found
29
+ end
30
+
31
+ end
@@ -0,0 +1,71 @@
1
+ module Cms
2
+ module BlogTestHelper
3
+
4
+ def seed_bcms_data
5
+ silence_stream(STDOUT) do
6
+ load File.expand_path('../../dummy/db/browsercms.seeds.rb', __FILE__)
7
+ end
8
+ end
9
+
10
+ def login_as(user)
11
+ @request.session[:user_id] = user ? user.id : nil
12
+ end
13
+
14
+
15
+ # Seeds all data created by this module's migrations
16
+ def seed_blog_data
17
+ @content_type_group = ContentTypeGroup.create!(:name => "Blog")
18
+ Cms::CategoryType.create!(:name => "Blog Post")
19
+ Cms::ContentType.create!(:name => "Blog", :content_type_group => @content_type_group)
20
+ Cms::ContentType.create!(:name => "BlogPost", :content_type_group => @content_type_group)
21
+ Cms::ContentType.create!(:name => "BlogComment", :content_type_group => @content_type_group)
22
+ end
23
+
24
+ # Creates data specifically used on tests
25
+ def create_test_data
26
+ template = %q[<% page_title @page_title || @blog.name %><%= render :partial => "partials/blog_post", :collection => @blog_posts %>"]
27
+ @blog = BcmsBlog::Blog.create!(:name => "MyBlog", :template => template)
28
+
29
+ @category_type = CategoryType.find_by_name("Blog Post")
30
+
31
+ @stuff = Category.create!(:name => "Stuff", :category_type => @category_type)
32
+ @general = Category.create!(:name => "General", :category_type => @category_type)
33
+
34
+ opts = {:blog => @blog, :publish_on_save => true}
35
+ @first_post = FactoryGirl.create(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 5, 6), :name => "The first Post"))
36
+ @foo_post_1 = FactoryGirl.create(:blog_post, opts.merge(:category => @stuff, :published_at => Time.utc(2008, 7, 5, 12), :tag_list => "foo stuff"))
37
+ @foo_post_2 = FactoryGirl.create(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2008, 7, 21)))
38
+ @bar_post_1 = FactoryGirl.create(:blog_post, opts.merge(:category => @stuff, :published_at => Time.utc(2008, 9, 2), :tag_list => "foo stuff"))
39
+ @bar_post_2 = FactoryGirl.create(:blog_post, opts.merge(:category => @general, :published_at => Time.utc(2009, 3, 18)))
40
+
41
+ publish_all_pages
42
+ end
43
+
44
+ def publish_all_pages
45
+ Cms::Page.all.each(&:publish)
46
+ end
47
+
48
+ def setup_blog_stubs()
49
+ Cms::PageRoute.stubs(:reload_routes)
50
+ @section = Section.new
51
+ Cms::Section.stubs(:create! => @section)
52
+ @section.stubs(:groups => [], :save! => true)
53
+ Cms::Page.stubs(:create! => Page.new)
54
+ Cms::Page.any_instance.stubs(:create_connector)
55
+ Cms::PageRoute.any_instance.stubs(:save!)
56
+ end
57
+
58
+ def create_group
59
+ @group = FactoryGirl.create(:group, :name => "Test", :group_type => FactoryGirl.create(:group_type, :name => "CMS User", :cms_access => true))
60
+ @group.permissions << FactoryGirl.create(:permission, :name => "edit_content")
61
+ @group.permissions << FactoryGirl.create(:permission, :name => "publish_content")
62
+ end
63
+
64
+ def create_user(opts = {})
65
+ create_group
66
+ @group.permissions << FactoryGirl.create(:permission, :name => "administrate") if opts[:admin]
67
+ @user = FactoryGirl.create(:user, :groups => [@group])
68
+ end
69
+ end
70
+ end
71
+ ActiveSupport::TestCase.send(:include, Cms::BlogTestHelper)
@@ -0,0 +1,54 @@
1
+ require 'factory_girl'
2
+ # These factories are copied from bcms_support to avoid needing to update dependency
3
+
4
+ FactoryGirl.define do
5
+ factory :user, :class => Cms::User do |m|
6
+ m.first_name "Test"
7
+ m.last_name "User"
8
+ m.sequence(:login) {|n| "test_#{n}" }
9
+ m.email {|a| "#{a.login}@example.com" }
10
+ m.password "password"
11
+ m.password_confirmation {|a| a.password }
12
+ end
13
+
14
+ factory :group_type, :class => Cms::GroupType do |m|
15
+ m.sequence(:name) {|n| "TestGroupType#{n}" }
16
+ end
17
+
18
+ factory :group, :class => Cms::Group do |m|
19
+ m.sequence(:name) {|n| "TestGroup#{n}" }
20
+ end
21
+
22
+ factory :permission, :class => Cms::Permission do |m|
23
+ m.sequence(:name) {|n| "TestPermission#{n}" }
24
+ end
25
+ end
26
+
27
+
28
+ # Blog specific factories
29
+ FactoryGirl.define do
30
+ factory :blog, :class=>BcmsBlog::Blog do |m|
31
+ m.sequence(:name) {|n| "TestBlog#{n}"}
32
+ m.moderate_comments true
33
+ end
34
+
35
+ factory :blog_post, :class=>BcmsBlog::BlogPost do |m|
36
+ m.sequence(:name) { |n| "BlogPost#{n}" }
37
+ m.blog {|b| b.association(:blog) }
38
+ m.sequence(:body) { |n| "Lorem ipsum #{n}" }
39
+ m.association :author, :factory => :user
40
+ end
41
+
42
+ factory :blog_comment, :class=>BcmsBlog::BlogComment do |m|
43
+ m.name "Just a comment"
44
+ m.body "Nice blog"
45
+ m.association :post, :factory => :blog_post
46
+ m.association :author, :factory => :user
47
+ end
48
+
49
+ factory :root_section, :class=>Cms::Section do |m|
50
+ m.name "My Site"
51
+ m.root true
52
+ m.path "/"
53
+ end
54
+ end
@@ -0,0 +1,2 @@
1
+ require 'factory_girl'
2
+ ActiveSupport::TestCase.send(:include, FactoryGirl::Syntax::Methods)
@@ -0,0 +1,15 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ # Load fixtures from the engine
13
+ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
14
+ ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
15
+ end
@@ -0,0 +1,64 @@
1
+ module TestLogging
2
+ def log(msg)
3
+ Rails.logger.info(msg)
4
+ end
5
+
6
+ def log_array(obj, *columns)
7
+ lengths = columns.map{|m| m.to_s.length }
8
+
9
+ obj.each do |r|
10
+ columns.each_with_index do |m, i|
11
+ v = r.send(m)
12
+ if v.to_s.length > lengths[i]
13
+ lengths[i] = v.to_s.length
14
+ end
15
+ end
16
+ end
17
+
18
+ str = " "
19
+ columns.each_with_index do |m, i|
20
+ str << "%#{lengths[i]}s" % m
21
+ str << " "
22
+ end
23
+ str << "\n "
24
+
25
+ columns.each_with_index do |m, i|
26
+ str << ("-"*lengths[i])
27
+ str << " "
28
+ end
29
+ str << "\n "
30
+
31
+ obj.each do |r|
32
+ columns.each_with_index do |m, i|
33
+ str << "%#{lengths[i]}s" % r.send(m)
34
+ str << " "
35
+ end
36
+ str << "\n "
37
+ end
38
+
39
+ log str
40
+ end
41
+
42
+ def log_table(cls, options={})
43
+ if options[:include_columns]
44
+ columns = options[:include_columns]
45
+ elsif options[:exclude_columns]
46
+ columns = cls.column_names - options[:exclude_columns].map(&:to_s)
47
+ else
48
+ columns = cls.column_names
49
+ end
50
+ log_array (cls.uses_soft_delete? ? cls.find_with_deleted(:all) : cls.all), *columns
51
+ end
52
+
53
+ def log_table_with(cls, *columns)
54
+ log_table(cls, :include_columns => columns)
55
+ end
56
+
57
+ def log_table_without(cls, *columns)
58
+ log_table(cls, :exclude_columns => columns)
59
+ end
60
+
61
+ def log_table_without_stamps(cls, *columns)
62
+ log_table(cls, :exclude_columns => %w[created_at updated_at created_by_id updated_by_id] + columns)
63
+ end
64
+ end