bcms_blog 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. data/LICENSE.txt +165 -0
  2. data/README.markdown +113 -2
  3. data/app/controllers/application_controller.rb +10 -0
  4. data/app/controllers/cms/blog_comments_controller.rb +1 -1
  5. data/app/controllers/cms/blog_posts_controller.rb +34 -1
  6. data/app/controllers/cms/blogs_controller.rb +10 -1
  7. data/app/controllers/feeds_controller.rb +8 -0
  8. data/app/helpers/application_helper.rb +3 -0
  9. data/app/helpers/cms/blog_helper.rb +17 -0
  10. data/app/helpers/feeds_helper.rb +2 -0
  11. data/app/models/blog.rb +70 -14
  12. data/app/models/blog_comment.rb +15 -9
  13. data/app/models/blog_group_membership.rb +4 -0
  14. data/app/models/blog_observer.rb +135 -0
  15. data/app/models/blog_post.rb +76 -32
  16. data/app/portlets/blog_post_portlet.rb +23 -9
  17. data/app/portlets/blog_posts_portlet.rb +50 -0
  18. data/app/views/cms/blog_posts/_form.html.erb +9 -4
  19. data/app/views/cms/blog_posts/no_access.html.erb +9 -0
  20. data/app/views/cms/blog_posts/render.html.erb +1 -5
  21. data/app/views/cms/blogs/_form.html.erb +27 -1
  22. data/app/views/cms/blogs/admin_only.html.erb +9 -0
  23. data/app/views/cms/blogs/render.html.erb +2 -3
  24. data/app/views/feeds/index.rss.builder +18 -0
  25. data/app/views/partials/_blog_post.html.erb +102 -0
  26. data/app/views/partials/_blog_post.html.haml +91 -0
  27. data/app/views/portlets/blog_post/_form.html.erb +2 -1
  28. data/app/views/portlets/blog_post/render.html.erb +33 -36
  29. data/app/views/portlets/blog_posts/_form.html.erb +13 -0
  30. data/app/views/portlets/blog_posts/render.html.haml +9 -0
  31. data/db/migrate/20090415000000_create_blogs.rb +31 -18
  32. data/db/migrate/20090415000001_create_blog_posts.rb +5 -30
  33. data/db/migrate/20090415000002_create_blog_comments.rb +2 -1
  34. data/db/migrate/20090415000003_add_attachment_to_blog_posts.rb +23 -0
  35. data/db/migrate/20100521042244_add_moderate_comments_to_blog.rb +10 -0
  36. data/doc/README_FOR_APP +2 -0
  37. data/doc/migrate_to_20100427.rb +77 -0
  38. data/doc/release_notes.txt +40 -0
  39. data/lib/bcms_blog/routes.rb +3 -0
  40. data/rails/init.rb +6 -1
  41. data/test/factories.rb +47 -1
  42. data/test/functional/blog_post_test.rb +19 -17
  43. data/test/functional/blog_test.rb +47 -25
  44. data/test/functional/cms/blog_posts_controller_test.rb +44 -0
  45. data/test/functional/cms/blogs_controller_test.rb +25 -0
  46. data/test/functional/feeds_controller_test.rb +8 -0
  47. data/test/test_helper.rb +64 -120
  48. data/test/unit/blog_comment_test.rb +34 -0
  49. data/test/unit/blog_observer_test.rb +61 -0
  50. data/test/unit/blog_post_test.rb +43 -0
  51. data/test/unit/blog_test.rb +42 -0
  52. data/test/unit/helpers/feeds_helper_test.rb +4 -0
  53. metadata +64 -7
  54. data/app/views/portlets/blog_post/_blog_post.html.erb +0 -29
@@ -1,3 +1,15 @@
1
+ require 'pp'
2
+
3
+ Page # trigger auto-loading
4
+ # At the time of this writing, these associations are missing :dependent => :destroy
5
+ class Page
6
+ has_many :page_routes, :dependent => :destroy
7
+ end
8
+ class PageRoute
9
+ has_many :requirements, :class_name => "PageRouteRequirement", :dependent => :destroy
10
+ has_many :conditions, :class_name => "PageRouteCondition", :dependent => :destroy
11
+ end
12
+
1
13
  class CreateBlogs < ActiveRecord::Migration
2
14
  def self.up
3
15
  create_versioned_table :blogs do |t|
@@ -5,28 +17,29 @@ class CreateBlogs < ActiveRecord::Migration
5
17
  t.string :format
6
18
  t.text :template
7
19
  end
8
- ContentType.create!(:name => "Blog", :group_name => "Blog")
9
20
 
10
- blog_page = Page.first(:conditions => {:path => "/"})
11
-
12
- Blog.create!(
13
- :name => "My Blog",
14
- :template => Blog.default_template,
15
- :connect_to_page_id => blog_page.id,
16
- :connect_to_container => "main",
17
- :publish_on_save => true)
18
-
19
- blog_page.page_routes.create(
20
- :name => "Blog Posts With Tag",
21
- :pattern => "/articles/tag/:tag")
22
-
23
- blog_page.page_routes.create(
24
- :name => "Blog Posts In Category",
25
- :pattern => "/articles/category/:category")
21
+ create_table :blog_group_memberships do |t|
22
+ t.integer :blog_id
23
+ t.integer :group_id
24
+ end
25
+
26
+ ContentType.create!(:name => "Blog", :group_name => "Blog")
26
27
  end
27
28
 
28
29
  def self.down
29
- ContentType.delete_all(['name = ?', 'Blog'])
30
+ puts "Destroying portlets, pages, page_routes..."
31
+ pp (portlets = BlogPostPortlet.all).map(&:connected_pages).flatten.each(&:destroy)
32
+ pp portlets.each(&:destroy)
33
+
34
+ #Blog.all.map(&:connected_pages).flatten.map(&:page_routes).flatten.each(&:destroy)
35
+ pp Blog.all.map(&:connected_pages).flatten.each(&:destroy)
36
+
37
+ ContentType.destroy_all(:name => "Blog")
38
+ Connector.destroy_all(:connectable_type => "Blog")
39
+
40
+ drop_table :blog_versions
30
41
  drop_table :blogs
42
+
43
+ drop_table :blog_group_memberships
31
44
  end
32
45
  end
@@ -4,46 +4,21 @@ class CreateBlogPosts < ActiveRecord::Migration
4
4
  t.integer :blog_id
5
5
  t.integer :author_id
6
6
  t.integer :category_id
7
- t.string :name
7
+ t.string :name
8
8
  t.string :slug
9
- t.text :summary
9
+ t.text :summary
10
10
  t.text :body, :size => (64.kilobytes + 1)
11
11
  t.integer :comments_count
12
12
  t.datetime :published_at
13
13
  end
14
14
  CategoryType.create!(:name => "Blog Post")
15
15
  ContentType.create!(:name => "BlogPost", :group_name => "Blog")
16
-
17
- blog_post_page = Page.create!(
18
- :name => "Blog Post",
19
- :path => "/blog/post",
20
- :section => Section.root.first,
21
- :template_file_name => "default.html.erb")
22
-
23
- BlogPostPortlet.create!(
24
- :name => "Blog Post Portlet",
25
- :template => BlogPostPortlet.default_template,
26
- :connect_to_page_id => blog_post_page.id,
27
- :connect_to_container => "main",
28
- :publish_on_save => true)
29
-
30
- route = blog_post_page.page_routes.build(
31
- :name => "Blog Post",
32
- :pattern => "/articles/:year/:month/:day/:slug",
33
- :code => "@blog_post = BlogPost.published_on(params).with_slug(params[:slug]).first")
34
- route.add_condition(:method, "get")
35
- route.add_requirement(:year, '\d{4,}')
36
- route.add_requirement(:month, '\d{2,}')
37
- route.add_requirement(:day, '\d{2,}')
38
- route.save!
39
-
40
-
41
-
42
16
  end
43
17
 
44
18
  def self.down
45
- ContentType.delete_all(['name = ?', 'BlogPost'])
46
- CategoryType.all(:conditions => ['name = ?', 'Blog Post']).each(&:destroy)
19
+ ContentType.destroy_all(:name => 'BlogPost')
20
+ CategoryType.destroy_all(:name => "Blog Post")
21
+
47
22
  drop_table :blog_post_versions
48
23
  drop_table :blog_posts
49
24
  end
@@ -12,7 +12,8 @@ class CreateBlogComments < ActiveRecord::Migration
12
12
  end
13
13
 
14
14
  def self.down
15
- ContentType.delete_all(['name = ?', 'BlogComment'])
15
+ ContentType.destroy_all(:name => 'BlogComment')
16
+ drop_table :blog_comment_versions
16
17
  drop_table :blog_comments
17
18
  end
18
19
  end
@@ -0,0 +1,23 @@
1
+ class AddAttachmentToBlogPosts < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :blog_posts do |t|
4
+ t.belongs_to :attachment
5
+ t.integer :attachment_version
6
+ end
7
+ change_table :blog_post_versions do |t|
8
+ t.belongs_to :attachment
9
+ t.integer :attachment_version
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ change_table :blog_posts do |t|
15
+ t.remove :attachment
16
+ t.remove :attachment_version
17
+ end
18
+ change_table :blog_post_versions do |t|
19
+ t.remove :attachment
20
+ t.remove :attachment_version
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ class AddModerateCommentsToBlog < ActiveRecord::Migration
2
+ def self.up
3
+ add_content_column :blogs, :moderate_comments, :boolean, :default => true
4
+ end
5
+
6
+ def self.down
7
+ remove_column :blogs, :moderate_comments
8
+ remove_column :blog_versions, :moderate_comments
9
+ end
10
+ end
@@ -0,0 +1,2 @@
1
+ Use this README file to introduce your application and point to useful places in the API for learning more.
2
+ Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries.
@@ -0,0 +1,77 @@
1
+ # Ideally, we would create a new migration whenever we wanted to make changes to an existing
2
+ # migration that is already in circulation, instead of simply editing the existing migrations
3
+ # and publishing the new version, because doing rake db:migrate:redo VERSION=20090415000000,
4
+ # etc. on each updated migration is not only a pain but will probably result in more data being
5
+ # lost than is strictly necessary -- assuming the migrations work correctly at all.
6
+ #
7
+ # On the other hand, there's something pretty compelling about "fixing" the migration so that
8
+ # it doesn't have any useless steps that are just going to get reverted by the next migration.
9
+ #
10
+ # There is also the problem of model dependencies: you can't safely remove a model in the same
11
+ # commit that you use that model in a migration (f.e., Model.destroy_all). Even if you remove it
12
+ # in the following commit, it's only safe if people check out every intermediate version and run
13
+ # db:migrate at each version, instead of simply checking out the tip version and then running
14
+ # db:migrate. And people don't do that.
15
+ #
16
+ # Anyway, I guess we assume that there are only a few brave souls out there who are already
17
+ # using bcms_blog and hope for the best. Here is the "missing migration"; hopefully it will be
18
+ # helpful to you.
19
+ #
20
+ # Run this script instead of re-running the changed migrations with rake db:migrate:redo so that
21
+ # your blog data is not destroyed.
22
+ #
23
+ # Usage: ./script/runner 'require "/path/to/bcms_blog/doc/migrate_to_20100427.rb"'
24
+
25
+ require 'pp'
26
+
27
+ Page # trigger auto-loading
28
+ # At the time of this writing, these associations are missing :dependent => :destroy
29
+ class Page
30
+ has_many :page_routes, :dependent => :destroy
31
+ end
32
+ class PageRoute
33
+ has_many :requirements, :class_name => "PageRouteRequirement", :dependent => :destroy
34
+ has_many :conditions, :class_name => "PageRouteCondition", :dependent => :destroy
35
+ end
36
+
37
+ # Added these here because these classes will be removed by the next commit, so if anyone tried to run this script in future versions it would have a missing constant error unless we keep these class definitions around
38
+ class BlogPostsInCategoryPortlet < Portlet; end
39
+ class BlogPostsWithTagPortlet < Portlet; end
40
+ class BlogPostPortlet < Portlet; end
41
+ class BlogPostsInDayPortlet < Portlet; end
42
+ class BlogPostsInMonthPortlet < Portlet; end
43
+ class BlogPostsInYearPortlet < Portlet; end
44
+
45
+ class MigrateTo20100427 < ActiveRecord::Migration
46
+ def self.up
47
+ drop_table :blog_group_membership_versions
48
+
49
+ PageRouteOption.all.each {|a| a.destroy unless a.page_route }
50
+
51
+ puts "Destroying portlets, pages, page_routes left over from old version of bcms_blog..."
52
+ puts "(*Not* destroying any existing Blogs, pages on which Blogs are connected, or BlogPosts)"
53
+ portlets = [BlogPostPortlet, BlogPostsInCategoryPortlet, BlogPostsWithTagPortlet, BlogPostsInDayPortlet, BlogPostsInMonthPortlet, BlogPostsInYearPortlet]
54
+ #pp portlets.map(&:all).flatten.map(&:connected_pages).flatten.map(&:page_routes).flatten.each(&:destroy)
55
+ pp portlets.map(&:all).flatten.map(&:connected_pages).flatten.each(&:destroy)
56
+ pp portlets.map(&:all).flatten.each(&:destroy)
57
+
58
+ # Something like this might not work if they have moved their Blog page to a different section or to no section, so we better let users resolve this manually...
59
+ #Blog.all.map(&:connected_pages).flatten.each do |page|
60
+ # page.hidden = true
61
+ # page.save!
62
+ # page.section.hidden = false
63
+ # page.section.save!
64
+ #end
65
+
66
+ puts "Calling after_create on each Blog in the system..."
67
+ Blog.all.each do |blog|
68
+ puts "#{blog}..."
69
+ blog.send :after_create
70
+ end
71
+ end
72
+
73
+ def self.down
74
+ end
75
+ end
76
+
77
+ MigrateTo20100427.up
@@ -0,0 +1,40 @@
1
+ v1.1.0
2
+
3
+ This version introduces significant changes and improvements over version 1.0.0
4
+ and lays the groundwork for a more sophisticated blogging platform for BrowserCMS.
5
+
6
+ Notable Features:
7
+ =================
8
+
9
+ 1. A Blog and supporting structure (sections, pages, page routes, etc.) and data are no longer
10
+ created as part of the modules's installation process. When running the module's migrations,
11
+ only the following items are created:
12
+
13
+ * blogs, blog_posts and blog_comment tables (and corresponding tables to hold versioning data)
14
+ * blog_group_memberships table
15
+ * Blog, BlogPost and BlogComment content types
16
+ * Blog Post category type
17
+
18
+ 2. It is only until a Blog is created when a corresponding section, pages, page routes and portlets are created.
19
+ Each blog has its own section, pages and page routes, which allows for multiple blogs to be created.
20
+
21
+ 3. It is now possible to add attachments to blog posts.
22
+
23
+ 4. Comments are moderated by default using BrowserCMS' default behaviors. However, when creating a Blog,
24
+ users can specify whether comments should be published automatically.
25
+
26
+ 5. The module now uses BrowserCMS' permissions framework to specify if a particular user is able to
27
+ create or edit Blogs and BlogPosts.
28
+
29
+ 6. Portlets have been improved to match common standard blog publishing templates.
30
+
31
+ For a complete rundown and rationale behind the changes introduced, please refer to:
32
+ https://browsermedia.lighthouseapp.com/projects/28481/tickets/163-review-and-integrate-changes-to-the-blog-module
33
+
34
+ Contributors:
35
+ =============
36
+ Tyler Rick
37
+ Jon Leighton
38
+
39
+
40
+ v1.0.0
@@ -1,5 +1,8 @@
1
1
  module Cms::Routes
2
2
  def routes_for_bcms_blog
3
+
4
+ blog_feeds '/blog/feeds', :controller => "feeds", :format => "rss"
5
+
3
6
  namespace(:cms) do |cms|
4
7
  cms.content_blocks :blogs
5
8
  cms.content_blocks :blog_posts
data/rails/init.rb CHANGED
@@ -1,3 +1,8 @@
1
1
  gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2
2
  Cms.add_to_rails_paths gem_root
3
- Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
3
+ Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
4
+ ApplicationHelper.module_eval { include Cms::BlogHelper }
5
+
6
+ config.after_initialize do
7
+ ActiveRecord::Base.observers << BlogObserver
8
+ end
data/test/factories.rb CHANGED
@@ -1,3 +1,49 @@
1
+ Factory.define :category_type do |m|
2
+ m.name "Blog Post"
3
+ end
4
+
5
+ Factory.define :group do |m|
6
+ m.sequence(:name) {|n| "TestGroup#{n}" }
7
+ m.association :group_type
8
+ end
9
+
10
+ Factory.define :group_type do |m|
11
+ m.sequence(:name) {|n| "TestGroupType#{n}" }
12
+ end
13
+
14
+ Factory.define :permission do |m|
15
+ m.name "edit_content"
16
+ end
17
+
18
+ Factory.define :user do |m|
19
+ m.first_name "Test"
20
+ m.last_name "User"
21
+ m.sequence(:login) {|n| "test_#{n}" }
22
+ m.email {|a| "#{a.login}@example.com" }
23
+ m.password "password"
24
+ m.password_confirmation {|a| a.password }
25
+ end
26
+
27
+ Factory.define :section do |m|
28
+ m.name "A Section"
29
+ m.path "/a-section"
30
+ end
31
+
1
32
  Factory.define :blog do |m|
2
33
  m.sequence(:name) {|n| "TestBlog#{n}"}
3
- end
34
+ m.moderate_comments true
35
+ end
36
+
37
+ Factory.define :blog_post do |m|
38
+ m.sequence(:name) { |n| "BlogPost#{n}" }
39
+ m.blog {|b| b.association(:blog) }
40
+ m.sequence(:body) { |n| "Lorem ipsum #{n}" }
41
+ m.association :author, :factory => :user
42
+ end
43
+
44
+ Factory.define :blog_comment do |m|
45
+ m.name "Just a comment"
46
+ m.body "Nice blog"
47
+ m.association :post, :factory => :blog_post
48
+ m.association :author, :factory => :user
49
+ end
@@ -5,31 +5,33 @@ class BlogPostTest < ActionController::TestCase
5
5
 
6
6
  def setup
7
7
  create_baseline_data
8
- @blog_post_portlet = BlogPostPortlet.create!(:name => "Blog Post Portlet",
9
- :template => BlogPostPortlet.default_template,
10
- :connect_to_page_id => @blog_post_page.id,
11
- :connect_to_container => "main",
12
- :publish_on_save => true)
13
8
  end
14
-
9
+
10
+ =begin
15
11
  def test_show_post
16
- get :show_page_route, :_page_route_id => @blog_post_route.id.to_s,
17
- :year => @first_post.year,
18
- :month => @first_post.month,
19
- :day => @first_post.day,
20
- :slug => @first_post.slug
21
- #log @response.body
12
+ get :show, :path => ["myblog"],
13
+ :year => 2008,
14
+ :month => 07,
15
+ :day => 05
16
+ log @response.body
22
17
  assert_response :success
23
18
  assert_select "title", @first_post.name
24
19
  assert_select ".blog_post", 1
25
-
20
+
26
21
  assert_select "#blog_post_#{@first_post.id}" do
27
- assert_select "h2 a", "First Post"
28
- assert_select "p.body", "Yadda Yadda Yadda"
22
+ assert_select "h2 a", @first_post.name
23
+ assert_select "p.body", @first_post.body
29
24
  assert_select "p.meta a", "General"
30
25
  assert_select "p.meta a", "0 Comments"
31
26
  end
32
-
27
+ end
28
+ =end
29
+
30
+ def test_non_existent_slug_should_return_404
31
+ get :show, :path => ["blog", "post"],
32
+ :year => 2005, :month => 6, :day => 14,
33
+ :slug => "not-here"
34
+ assert_response :not_found
33
35
  end
34
36
 
35
- end
37
+ end
@@ -6,40 +6,62 @@ class BlogTest < ActionController::TestCase
6
6
  def setup
7
7
  create_baseline_data
8
8
  end
9
-
10
- def test_list_of_blog_posts
11
- get :show, :paths => ["/"]
12
- #log @response.body
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"
18
- assert_select "p.body", "Yadda Yadda Yadda"
19
- assert_select "p.meta a", "General"
20
- assert_select "p.meta a", "0 Comments"
21
- end
22
-
23
- assert_select "#blog_post_#{@foo_post_1.id}" do
24
- assert_select "h2 a", "Foo #1"
25
- assert_select "p.body", "Foo 1 Foo 1 Foo 1"
26
- assert_select "p.meta .tags a", "foo"
27
- assert_select "p.meta .tags a", "stuff"
9
+
10
+ =begin
11
+ test "displays the list of blog posts" do
12
+ get :show, :path => ['myblog']
13
+ log @response.body
14
+ assert_response :success
15
+ assert_select ".blog_post", 5
16
+
17
+ assert_select "#blog_post_#{@first_post.id}" do
18
+ assert_select "h2 a", @first_post.name
19
+ assert_select "p.body", @first_post.body
20
+ assert_select "p.meta a", "General"
21
+ assert_select "p.meta a", "0 Comments"
22
+ end
23
+
24
+ assert_select "#blog_post_#{@foo_post_1.id}" do
25
+ assert_select "h2 a", @foo_post_1.name
26
+ assert_select "p.body", @foo_post_1.body
27
+ assert_select "p.meta .tags a", "foo"
28
+ assert_select "p.meta .tags a", "stuff"
29
+ end
28
30
  end
29
- end
30
31
 
31
32
  def test_list_of_tagged_blog_posts
32
- get :show, :paths => ["/"], :category => "General"
33
- #log @response.body
33
+ get :show, :category => "General"
34
+ puts @response.body
34
35
  assert_response :success
35
36
  assert_select ".blog_post", 3
36
37
  end
37
38
 
38
39
  def test_list_of_categorized_blog_posts
39
- get :show, :paths => ["/"], :tag => "foo"
40
- #log @response.body
40
+ get :show, :tag => "foo"
41
+ assert_response :success
42
+ assert_select ".blog_post", 2
43
+ end
44
+
45
+ def test_list_of_blog_posts_in_day
46
+ get :show, :path => ["blog", "posts_in_day"],
47
+ :year => 2008, :month => 7, :day => 5
41
48
  assert_response :success
42
49
  assert_select ".blog_post", 2
43
50
  end
44
51
 
45
- end
52
+ def test_list_of_blog_posts_in_month
53
+ get :show, :path => ["blog", "posts_in_month"],
54
+ :year => 2008, :month => 7
55
+ assert_response :success
56
+ assert_select ".blog_post", 3
57
+ end
58
+
59
+ def test_list_of_blog_posts_in_year
60
+ get :show, :path => ["blog", "posts_in_year"],
61
+ :year => 2008
62
+ assert_response :success
63
+ assert_select ".blog_post", 4
64
+ end
65
+ =end
66
+
67
+ end
@@ -0,0 +1,44 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class Cms::BlogPostsControllerTest < ActionController::TestCase
4
+ def setup
5
+ setup_stubs
6
+ ContentType.create!(:name => 'BlogPost', :group_name => 'Blog')
7
+ login_as(_create_user)
8
+ end
9
+
10
+ def test_access_denied_on_create_if_blog_not_user_editable
11
+ @editable = Factory(:blog, :groups => [@group])
12
+ @non_editable = Factory(:blog)
13
+ post :create, :blog_post => { :blog_id => @non_editable.id }
14
+ assert @response.body.include?("Access Denied")
15
+ end
16
+
17
+ def test_access_denied_on_update_if_blog_not_user_editable
18
+ @editable = Factory.create(:blog, :groups => [@group])
19
+ @non_editable = Factory.create(:blog)
20
+ @blog_post = Factory.create(:blog_post, :blog => @non_editable)
21
+ put :update, :id => @blog_post, :blog_post => { :name => "Foo" }
22
+ assert @response.body.include?("Access Denied")
23
+ end
24
+
25
+ def test_no_access_if_no_editable_blogs
26
+ @blog = Factory.create(:blog)
27
+ get :index
28
+ assert_template "no_access"
29
+ end
30
+
31
+ def test_index_shouldnt_show_non_editable_posts
32
+ @editable = Factory.create(:blog, :groups => [@group])
33
+ @non_editable = Factory.create(:blog)
34
+ @blog_post = Factory.create(:blog_post, :name => "Non-editable", :blog => @non_editable)
35
+ get :index
36
+ assert !@response.body.include?("Non-editable")
37
+ end
38
+
39
+ def test_create_sets_author
40
+ @blog = Factory.create(:blog, :groups => [@group])
41
+ post :create, :blog_post => { :blog_id => @blog.id }
42
+ assert_equal @user, assigns(:block).author
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class Cms::BlogsControllerTest < ActionController::TestCase
4
+
5
+ def setup
6
+ setup_stubs
7
+ ContentType.create!(:name => 'Blog', :group_name => 'Blog')
8
+ Factory(:blog)
9
+ end
10
+
11
+ test "should allow access to admin users" do
12
+ login_as(_create_user(:admin => true))
13
+ get :index
14
+ assert_response :success
15
+ assert assigns(:blocks)
16
+ assert_template("index")
17
+ end
18
+
19
+ test "should not allow access to non-admin users" do
20
+ login_as(_create_user)
21
+ get :index
22
+ assert_response :success
23
+ assert_template("admin_only.html.erb")
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class FeedsControllerTest < ActionController::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end