wa_bcms_blog 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 (51) hide show
  1. data/LICENSE.txt +165 -0
  2. data/README.markdown +101 -0
  3. data/app/controllers/application_controller.rb +10 -0
  4. data/app/controllers/cms/blog_comments_controller.rb +3 -0
  5. data/app/controllers/cms/blog_posts_controller.rb +35 -0
  6. data/app/controllers/cms/blogs_controller.rb +11 -0
  7. data/app/helpers/application_helper.rb +3 -0
  8. data/app/helpers/cms/blog_helper.rb +11 -0
  9. data/app/models/blog.rb +162 -0
  10. data/app/models/blog_comment.rb +32 -0
  11. data/app/models/blog_group_membership.rb +4 -0
  12. data/app/models/blog_post.rb +113 -0
  13. data/app/portlets/blog_post_portlet.rb +38 -0
  14. data/app/portlets/blog_posts_portlet.rb +50 -0
  15. data/app/views/cms/blog_comments/_form.html.erb +5 -0
  16. data/app/views/cms/blog_comments/render.html.erb +2 -0
  17. data/app/views/cms/blog_posts/_form.html.erb +11 -0
  18. data/app/views/cms/blog_posts/no_access.html.erb +9 -0
  19. data/app/views/cms/blog_posts/render.html.erb +1 -0
  20. data/app/views/cms/blogs/_form.html.erb +28 -0
  21. data/app/views/cms/blogs/admin_only.html.erb +9 -0
  22. data/app/views/cms/blogs/render.html.erb +2 -0
  23. data/app/views/partials/_blog_post.html.erb +103 -0
  24. data/app/views/partials/_blog_post.html.haml +91 -0
  25. data/app/views/portlets/blog_post/_form.html.erb +3 -0
  26. data/app/views/portlets/blog_post/render.html.erb +33 -0
  27. data/app/views/portlets/blog_posts/_form.html.erb +13 -0
  28. data/app/views/portlets/blog_posts/render.html.haml +9 -0
  29. data/db/migrate/20090415000000_create_blogs.rb +45 -0
  30. data/db/migrate/20090415000001_create_blog_posts.rb +25 -0
  31. data/db/migrate/20090415000002_create_blog_comments.rb +19 -0
  32. data/db/migrate/20090415000003_add_attachment_to_blog_posts.rb +23 -0
  33. data/db/migrate/20100521042244_add_moderate_comments_to_blog.rb +10 -0
  34. data/doc/README_FOR_APP +2 -0
  35. data/doc/migrate_to_20100427.rb +77 -0
  36. data/doc/release_notes.txt +40 -0
  37. data/lib/bcms_blog.rb +1 -0
  38. data/lib/bcms_blog/routes.rb +9 -0
  39. data/rails/init.rb +4 -0
  40. data/test/factories.rb +48 -0
  41. data/test/functional/blog_post_test.rb +42 -0
  42. data/test/functional/blog_test.rb +74 -0
  43. data/test/functional/cms/blog_posts_controller_test.rb +46 -0
  44. data/test/functional/cms/blogs_controller_test.rb +25 -0
  45. data/test/performance/browsing_test.rb +9 -0
  46. data/test/test_helper.rb +103 -0
  47. data/test/test_logging.rb +64 -0
  48. data/test/unit/blog_comment_test.rb +34 -0
  49. data/test/unit/blog_post_test.rb +43 -0
  50. data/test/unit/blog_test.rb +86 -0
  51. metadata +127 -0
@@ -0,0 +1,46 @@
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
+ flunk
12
+ @editable = Factory(:blog, :groups => [@group])
13
+ @non_editable = Factory(:blog)
14
+ post :create, :blog_post => { :blog_id => @non_editable.id }
15
+ assert @response.body.include?("AccessDenied")
16
+ end
17
+
18
+ def test_access_denied_on_update_if_blog_not_user_editable
19
+ flunk
20
+ @editable = Factory.create(:blog, :groups => [@group])
21
+ @non_editable = Factory.create(:blog)
22
+ @blog_post = Factory.create(:blog_post, :blog => @non_editable)
23
+ put :update, :id => @blog_post, :blog_post => { :name => "Foo" }
24
+ assert @response.body.include?("AccessDenied")
25
+ end
26
+
27
+ def test_no_access_if_no_editable_blogs
28
+ @blog = Factory.create(:blog)
29
+ get :index
30
+ assert_template "no_access"
31
+ end
32
+
33
+ def test_index_shouldnt_show_non_editable_posts
34
+ @editable = Factory.create(:blog, :groups => [@group])
35
+ @non_editable = Factory.create(:blog)
36
+ @blog_post = Factory.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 = Factory.create(:blog, :groups => [@group])
43
+ post :create, :blog_post => { :blog_id => @blog.id }
44
+ assert_equal @user, assigns(:block).author
45
+ end
46
+ 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,9 @@
1
+ require 'test_helper'
2
+ require 'performance_test_help'
3
+
4
+ # Profiling results for each test method are written to tmp/performance.
5
+ class BrowsingTest < ActionController::PerformanceTest
6
+ def test_homepage
7
+ get '/'
8
+ end
9
+ end
@@ -0,0 +1,103 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ ENV['BACKTRACE'] = "YES PLEASE"
3
+ require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
4
+ require 'test_help'
5
+
6
+ class ActiveSupport::TestCase
7
+ require File.dirname(__FILE__) + '/test_logging'
8
+ include TestLogging
9
+ # Transactional fixtures accelerate your tests by wrapping each test method
10
+ # in a transaction that's rolled back on completion. This ensures that the
11
+ # test database remains unchanged so your fixtures don't have to be reloaded
12
+ # between every test method. Fewer database queries means faster tests.
13
+ #
14
+ # Read Mike Clark's excellent walkthrough at
15
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
16
+ #
17
+ # Every Active Record database supports transactions except MyISAM tables
18
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
19
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
20
+ # is recommended.
21
+ #
22
+ # The only drawback to using transactional fixtures is when you actually
23
+ # need to test transactions. Since your test is bracketed by a transaction,
24
+ # any transactions started in your code will be automatically rolled back.
25
+ self.use_transactional_fixtures = true
26
+
27
+ # Instantiated fixtures are slow, but give you @david where otherwise you
28
+ # would need people(:david). If you don't want to migrate your existing
29
+ # test cases which use the @david style and don't mind the speed hit (each
30
+ # instantiated fixtures translates to a database query per test method),
31
+ # then set this back to true.
32
+ self.use_instantiated_fixtures = false
33
+
34
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
35
+ #
36
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
37
+ # -- they do not yet inherit this setting
38
+ fixtures :all
39
+
40
+ # Add more helper methods to be used by all tests here...
41
+
42
+ def create_baseline_data
43
+ # Find the seed data items
44
+ @blog = Blog.find_by_name("My Blog")
45
+ @blog_page = Page.find_by_path("/")
46
+ @blog_post_page = Page.find_by_path("/blog/post")
47
+ @category_type = CategoryType.find_by_name("Blog Post")
48
+
49
+ # For some reason this is necessary otherwise the relevant page routes aren't loaded when
50
+ # the tests are run via "rake" (as opposed to running them directly). I don't know exactly
51
+ # why this is the case.
52
+ ActionController::Routing::Routes.load!
53
+
54
+ @stuff = Category.create!(:name => "Stuff", :category_type => @category_type)
55
+ @general = Category.create!(:name => "General", :category_type => @category_type)
56
+
57
+ @first_post = Factory(:blog_post, :blog => @blog, :category => @general,
58
+ :published_at => Time.utc(2008, 7, 5, 6), :publish_on_save => true)
59
+
60
+ @foo_post_1 = Factory(:blog_post, :blog => @blog, :category => @stuff,
61
+ :published_at => Time.utc(2008, 7, 5, 12), :tag_list => "foo stuff", :publish_on_save => true)
62
+
63
+ @foo_post_2 = Factory(:blog_post, :blog => @blog, :category => @general,
64
+ :published_at => Time.utc(2008, 7, 21), :publish_on_save => true)
65
+
66
+ @bar_post_1 = Factory(:blog_post, :blog => @blog, :category => @stuff,
67
+ :published_at => Time.utc(2008, 9, 2), :tag_list => "foo stuff", :publish_on_save => true)
68
+
69
+ @bar_post_2 = Factory(:blog_post, :blog => @blog, :category => @general,
70
+ :published_at => Time.utc(2009, 3, 18), :publish_on_save => true)
71
+ end
72
+
73
+ def destroy_baseline_data
74
+ Category.destroy_all
75
+ BlogPost.destroy_all
76
+ end
77
+
78
+ def setup_stubs
79
+ Blog.any_instance.stubs(:reload_routes)
80
+ @section = Section.new
81
+ Section.stubs(:create! => @section)
82
+ @section.stubs(:groups => [], :save! => true)
83
+ Page.stubs(:create! => Page.new)
84
+ Page.any_instance.stubs(:create_connector)
85
+ end
86
+
87
+ def create_group
88
+ @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
89
+ @group.permissions << Factory(:permission, :name => "edit_content")
90
+ @group.permissions << Factory(:permission, :name => "publish_content")
91
+ end
92
+
93
+ def create_user(opts = {})
94
+ create_group
95
+ @group.permissions << Factory(:permission, :name => "administrate") if opts[:admin]
96
+ @user = Factory(:user, :groups => [@group])
97
+ end
98
+
99
+ def login_as(user)
100
+ @request.session[:user_id] = user ? user.id : nil
101
+ end
102
+
103
+ 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
@@ -0,0 +1,34 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ class BlogCommentTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ setup_stubs
7
+ end
8
+
9
+ test "crates a valid instance" do
10
+ assert Factory.build(:blog_comment).valid?
11
+ end
12
+
13
+ test "requires post" do
14
+ assert !Factory.build(:blog_comment, :post => nil).valid?
15
+ end
16
+
17
+ test "requires author" do
18
+ assert !Factory.build(:blog_comment, :author => nil).valid?
19
+ end
20
+
21
+ test "requires body" do
22
+ assert !Factory.build(:blog_comment, :body => nil).valid?
23
+ end
24
+
25
+ test "should not be published if Blog#moderate_comments is true" do
26
+ assert !Factory(:blog_comment).published?
27
+ end
28
+
29
+ test "should be published if Blog#moderate_comments is false" do
30
+ blog = Factory(:blog, :moderate_comments => false)
31
+ post = Factory(:blog_post, :blog => blog)
32
+ assert Factory(:blog_comment, :post => post).published?
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ class BlogPostTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ setup_stubs
7
+ @post = Factory(:blog_post, :name => "This is the first Post")
8
+ end
9
+
10
+ test "cretates a valid instance" do
11
+ assert @post.valid?
12
+ end
13
+
14
+ test "requires name" do
15
+ assert !Factory.build(:blog_post, :name => nil).valid?
16
+ end
17
+
18
+ test "requires blog_id" do
19
+ assert !Factory.build(:blog_post, :blog => nil).valid?
20
+ end
21
+
22
+ test "requires author_id" do
23
+ assert !Factory.build(:blog_post, :author => nil).valid?
24
+ end
25
+
26
+ test "should set slug" do
27
+ assert_equal('this-is-the-first-post', @post.slug)
28
+ end
29
+
30
+ test "should set published_at when published" do
31
+ assert_nil @post.published_at
32
+ @post.publish!
33
+ assert_not_nil @post.published_at
34
+ end
35
+
36
+ test "BlogPost should find posts published between 2 given dates" do
37
+ @post.publish!
38
+ Factory(:blog_post, :published_at => 5.days.ago)
39
+ Factory(:blog_post, :published_at => 10.days.ago)
40
+ assert_equal(1, BlogPost.published_between(6.days.ago, 4.days.ago).count)
41
+ end
42
+
43
+ end
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ class BlogTest < ActiveSupport::TestCase
4
+
5
+ def setup
6
+ setup_stubs
7
+ @blog = Factory(:blog, :name => 'TestBlog')
8
+ # Factory(:blog_post, :blog => @blog) #unpublished post
9
+ end
10
+
11
+ test "creates a valid instance" do
12
+ assert @blog.valid?
13
+ end
14
+
15
+ test "requires name" do
16
+ assert !Factory.build(:blog, :name => nil).valid?
17
+ end
18
+
19
+ test "should be editable by user" do
20
+ group = Factory(:group, :group_type => Factory(:group_type,:cms_access => true))
21
+ user = Factory(:user, :groups => [group])
22
+ blog = Factory.build(:blog, :groups => [group])
23
+ assert blog.editable_by?(user)
24
+ assert !@blog.editable_by?(user)
25
+ end
26
+
27
+ test "should be editable by administrators" do
28
+ admin = Factory(:user)
29
+ admin.expects(:able_to?).with(:administrate).returns(true)
30
+ assert @blog.editable_by?(admin)
31
+ end
32
+
33
+ test "should create a section with the same name and route" do
34
+ Section.expects(:create!).with(:name => 'Test', :path => '/test', :parent_id => 1).returns(@section)
35
+ Factory(:blog, :name => 'Test')
36
+ end
37
+
38
+ test "should create a hidden page with the same name in the section with the blog's name" do
39
+ Page.expects(:create!).with(:name => 'Test',
40
+ :path => '/test',
41
+ :section => @section,
42
+ :template_file_name => 'default.html.erb',
43
+ :hidden => true).returns(Page.new)
44
+ Factory(:blog, :name => 'Test')
45
+ end
46
+
47
+ test "should create a page to hold the BlogPostPortlet" do
48
+ Page.expects(:create!).with(:name => 'Test: Post',
49
+ :path => '/test/post',
50
+ :section => @section,
51
+ :template_file_name => 'default.html.erb',
52
+ :hidden => true).returns(Page.new)
53
+ Factory(:blog, :name => 'Test')
54
+ end
55
+
56
+ test "should create an instance of BlogPostPortlet" do
57
+ BlogPostPortlet.expects(:create!).with(:name => 'Test: Post Portlet',
58
+ :blog_id => 2,
59
+ :template => BlogPostPortlet.default_template,
60
+ :connect_to_page_id => nil,
61
+ :connect_to_container => 'main',
62
+ :publish_on_save => true).returns(BlogPostPortlet.new)
63
+ Factory(:blog, :name => 'Test')
64
+ end
65
+
66
+ test "should find posts tagged with 'Ruby'" do
67
+
68
+ end
69
+
70
+ test "should find posts in category 'Rails'" do
71
+
72
+ end
73
+
74
+ test "should find posts published between a given date YY/MM/DD" do
75
+
76
+ end
77
+
78
+ test "should find posts published between a given date YY/MM" do
79
+
80
+ end
81
+
82
+ test "should find posts published between a given date YY" do
83
+
84
+ end
85
+
86
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wa_bcms_blog
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
11
+ platform: ruby
12
+ authors:
13
+ - BrowserMedia
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-24 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: The Blog Module for BrowserCMS
23
+ email: github@browsermedia.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - LICENSE.txt
30
+ - README.markdown
31
+ files:
32
+ - app/controllers/application_controller.rb
33
+ - app/controllers/cms/blog_comments_controller.rb
34
+ - app/controllers/cms/blog_posts_controller.rb
35
+ - app/controllers/cms/blogs_controller.rb
36
+ - app/helpers/application_helper.rb
37
+ - app/helpers/cms/blog_helper.rb
38
+ - app/models/blog.rb
39
+ - app/models/blog_comment.rb
40
+ - app/models/blog_group_membership.rb
41
+ - app/models/blog_post.rb
42
+ - app/portlets/blog_post_portlet.rb
43
+ - app/portlets/blog_posts_portlet.rb
44
+ - app/views/cms/blog_comments/_form.html.erb
45
+ - app/views/cms/blog_comments/render.html.erb
46
+ - app/views/cms/blog_posts/_form.html.erb
47
+ - app/views/cms/blog_posts/no_access.html.erb
48
+ - app/views/cms/blog_posts/render.html.erb
49
+ - app/views/cms/blogs/_form.html.erb
50
+ - app/views/cms/blogs/admin_only.html.erb
51
+ - app/views/cms/blogs/render.html.erb
52
+ - app/views/partials/_blog_post.html.erb
53
+ - app/views/partials/_blog_post.html.haml
54
+ - app/views/portlets/blog_post/_form.html.erb
55
+ - app/views/portlets/blog_post/render.html.erb
56
+ - app/views/portlets/blog_posts/_form.html.erb
57
+ - app/views/portlets/blog_posts/render.html.haml
58
+ - db/migrate/20090415000000_create_blogs.rb
59
+ - db/migrate/20090415000001_create_blog_posts.rb
60
+ - db/migrate/20090415000002_create_blog_comments.rb
61
+ - db/migrate/20090415000003_add_attachment_to_blog_posts.rb
62
+ - db/migrate/20100521042244_add_moderate_comments_to_blog.rb
63
+ - doc/README_FOR_APP
64
+ - doc/migrate_to_20100427.rb
65
+ - doc/release_notes.txt
66
+ - lib/bcms_blog.rb
67
+ - lib/bcms_blog/routes.rb
68
+ - rails/init.rb
69
+ - LICENSE.txt
70
+ - README.markdown
71
+ - test/factories.rb
72
+ - test/functional/blog_post_test.rb
73
+ - test/functional/blog_test.rb
74
+ - test/functional/cms/blog_posts_controller_test.rb
75
+ - test/functional/cms/blogs_controller_test.rb
76
+ - test/performance/browsing_test.rb
77
+ - test/test_helper.rb
78
+ - test/test_logging.rb
79
+ - test/unit/blog_comment_test.rb
80
+ - test/unit/blog_post_test.rb
81
+ - test/unit/blog_test.rb
82
+ has_rdoc: true
83
+ homepage: http://browsercms.org
84
+ licenses: []
85
+
86
+ post_install_message:
87
+ rdoc_options:
88
+ - --charset=UTF-8
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ requirements: []
110
+
111
+ rubyforge_project: browsercms
112
+ rubygems_version: 1.3.7
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: The Blog Module for BrowserCMS
116
+ test_files:
117
+ - test/factories.rb
118
+ - test/functional/blog_post_test.rb
119
+ - test/functional/blog_test.rb
120
+ - test/functional/cms/blog_posts_controller_test.rb
121
+ - test/functional/cms/blogs_controller_test.rb
122
+ - test/performance/browsing_test.rb
123
+ - test/test_helper.rb
124
+ - test/test_logging.rb
125
+ - test/unit/blog_comment_test.rb
126
+ - test/unit/blog_post_test.rb
127
+ - test/unit/blog_test.rb