tylerrick-bcms_blog 1.0.5

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 (44) hide show
  1. data/README.markdown +63 -0
  2. data/app/controllers/application_controller.rb +10 -0
  3. data/app/controllers/cms/blog_comments_controller.rb +3 -0
  4. data/app/controllers/cms/blog_posts_controller.rb +35 -0
  5. data/app/controllers/cms/blogs_controller.rb +11 -0
  6. data/app/helpers/application_helper.rb +3 -0
  7. data/app/helpers/cms/blog_helper.rb +11 -0
  8. data/app/models/blog.rb +143 -0
  9. data/app/models/blog_comment.rb +28 -0
  10. data/app/models/blog_group_membership.rb +4 -0
  11. data/app/models/blog_post.rb +101 -0
  12. data/app/portlets/blog_post_portlet.rb +38 -0
  13. data/app/views/cms/blog_comments/_form.html.erb +5 -0
  14. data/app/views/cms/blog_comments/render.html.erb +2 -0
  15. data/app/views/cms/blog_posts/_form.html.erb +11 -0
  16. data/app/views/cms/blog_posts/no_access.html.erb +9 -0
  17. data/app/views/cms/blog_posts/render.html.erb +1 -0
  18. data/app/views/cms/blogs/_form.html.erb +23 -0
  19. data/app/views/cms/blogs/admin_only.html.erb +9 -0
  20. data/app/views/cms/blogs/render.html.erb +2 -0
  21. data/app/views/partials/_blog_post.html.erb +106 -0
  22. data/app/views/partials/_blog_post.html.haml +91 -0
  23. data/app/views/portlets/blog_post/_form.html.erb +3 -0
  24. data/app/views/portlets/blog_post/render.html.erb +33 -0
  25. data/db/migrate/20090415000000_create_blogs.rb +45 -0
  26. data/db/migrate/20090415000001_create_blog_posts.rb +25 -0
  27. data/db/migrate/20090415000002_create_blog_comments.rb +19 -0
  28. data/db/migrate/20090415000003_add_attachment_to_blog_posts.rb +23 -0
  29. data/doc/README_FOR_APP +2 -0
  30. data/doc/migrate_to_20100427.rb +68 -0
  31. data/lib/bcms_blog/routes.rb +9 -0
  32. data/lib/bcms_blog.rb +1 -0
  33. data/rails/init.rb +4 -0
  34. data/test/factories.rb +31 -0
  35. data/test/functional/blog_post_test.rb +41 -0
  36. data/test/functional/blog_test.rb +69 -0
  37. data/test/functional/cms/blog_posts_controller_test.rb +43 -0
  38. data/test/functional/cms/blogs_controller_test.rb +12 -0
  39. data/test/performance/browsing_test.rb +9 -0
  40. data/test/test_helper.rb +104 -0
  41. data/test/test_logging.rb +64 -0
  42. data/test/unit/blog_post_test.rb +16 -0
  43. data/test/unit/blog_test.rb +23 -0
  44. metadata +96 -0
@@ -0,0 +1,91 @@
1
+ %style
2
+ :sass
3
+ .blog_post.first
4
+ h2, h2 a
5
+ font: normal 30px/28px 'arial black', arial, sans-serif !important
6
+ border-bottom: 1px solid #ccc
7
+
8
+ .blog_post
9
+ border: 0px solid gray
10
+ margin-bottom: 20px
11
+
12
+ h2
13
+ margin-bottom: 0
14
+ h2, h2 a
15
+ font: normal 20px/23px 'arial black', arial, sans-serif !important
16
+ text-decoration: none !important
17
+ h2 a:hover
18
+ text-decoration: underline !important
19
+
20
+ .image
21
+ float: left
22
+ border: 1px solid #ccc
23
+ margin: 10px
24
+ margin-top: 0
25
+
26
+ .date
27
+ color: #666
28
+ .read_more
29
+ font-weight: bold
30
+
31
+ .comment + .comment
32
+ border-top: 1px dashed #ccc
33
+
34
+ .clear
35
+ clear: both
36
+
37
+ :ruby
38
+ # _counter is defined only if we pass :collection to the partial
39
+ if defined?(blog_post_counter)
40
+ showing_individual_post = false
41
+ else
42
+ showing_individual_post = true
43
+ blog_post_counter = 0
44
+ end
45
+
46
+ if blog_post_counter == 0
47
+ max_width = 250
48
+ css_class = 'first'
49
+ else
50
+ max_width = 75
51
+ css_class = ''
52
+ end
53
+
54
+ .blog_post.clear{:id => "blog_post_#{blog_post.id}", :class => css_class}
55
+ - if blog_post.attachment
56
+ -# .image= image_tag_with_max_size blog_post.attachment.file_path, blog_post.attachment.full_file_location, :width => max_width
57
+ .image= image_tag blog_post.attachment.file_path
58
+
59
+ %h2= link_to h(blog_post.name), href = _blog_post_path(blog_post)
60
+
61
+ .date= blog_post.published_at.to_s(:long)
62
+
63
+ .body
64
+ - if showing_individual_post or blog_post.summary.blank?
65
+ = blog_post.body
66
+ - else
67
+ = blog_post.summary
68
+ %p.read_more= link_to 'Read More »', href
69
+
70
+ - if showing_individual_post || blog_post_counter == 0
71
+ .meta
72
+ - unless blog_post.category_id.blank?
73
+ Posted in #{link_to h(blog_post.category_name), _blog_path(blog_post.blog, 'posts_in_category', :category => blog_post.category_name)}
74
+ %strong |
75
+ - if blog_post.tags.any?
76
+ Tags:
77
+ %span.tags
78
+ = blog_post.tags.map{|t| link_to(h(t.name), _blog_path(blog_post.blog, 'posts_with_tag', :tag => t.name)) }.join(", ")
79
+ %strong |
80
+ = link_to h(pluralize(blog_post.comments_count, "Comment")), "#{_blog_post_path(blog_post)}#comments"
81
+ %br.clear/
82
+
83
+ - comments = blog_post.comments.reject(&:new_record?)
84
+ - if showing_individual_post and comments.any?
85
+ %h2 Comments
86
+ - comments.each_with_index do |comment, i|
87
+ %div{:class => "comment #{'first' if i == 0}"}
88
+ = h comment.body
89
+ %p
90
+ \—#{comment.url.present? ? link_to(h(comment.author), comment.url) : h(comment.author)}
91
+
@@ -0,0 +1,3 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_drop_down :blog_id, Blog.all.map{|b| [b.name, b.id.to_s]} %>
3
+ <%= f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -0,0 +1,33 @@
1
+ <% page_title @blog_post.name %>
2
+ <%= render :partial => "partials/blog_post", :object => @blog_post %>
3
+
4
+ <style>
5
+ @import url('/stylesheets/cms/form_layout.css');
6
+ </style>
7
+
8
+ <div class="blog_comment_form">
9
+ <% form_for @blog_comment, :url => cms_handler_path(@portlet, "create_comment") do |f| %>
10
+ <%= f.hidden_field :post_id %>
11
+ <%= f.error_messages %>
12
+ <div class="fields text_fields">
13
+ <%= f.label :author, 'Name *' %>
14
+ <%= f.text_field :author %>
15
+ </div>
16
+ <div class="fields text_fields clear">
17
+ <%= f.label :email, 'E-mail address' %>
18
+ <%= f.text_field :email %>
19
+ </div>
20
+ <div class="fields text_fields clear">
21
+ <%= f.label :url, 'Web site' %>
22
+ <%= f.text_field :url %>
23
+ </div>
24
+ <div class="fields text_editor_fields clear">
25
+ <%= f.label :body, 'Body *' %>
26
+ <br/>
27
+ <%= f.text_area :body, :size => "50x5", :style => 'height: auto' %>
28
+ </div>
29
+ <div class="buttons clear">
30
+ <%= submit_tag "Submit comment" %>
31
+ </div>
32
+ <% end %>
33
+ </div>
@@ -0,0 +1,45 @@
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
+
13
+ class CreateBlogs < ActiveRecord::Migration
14
+ def self.up
15
+ create_versioned_table :blogs do |t|
16
+ t.string :name
17
+ t.string :format
18
+ t.text :template
19
+ end
20
+
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")
27
+ end
28
+
29
+ def self.down
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
41
+ drop_table :blogs
42
+
43
+ drop_table :blog_group_memberships
44
+ end
45
+ end
@@ -0,0 +1,25 @@
1
+ class CreateBlogPosts < ActiveRecord::Migration
2
+ def self.up
3
+ create_versioned_table :blog_posts do |t|
4
+ t.integer :blog_id
5
+ t.integer :author_id
6
+ t.integer :category_id
7
+ t.string :name
8
+ t.string :slug
9
+ t.text :summary
10
+ t.text :body, :size => (64.kilobytes + 1)
11
+ t.integer :comments_count
12
+ t.datetime :published_at
13
+ end
14
+ CategoryType.create!(:name => "Blog Post")
15
+ ContentType.create!(:name => "BlogPost", :group_name => "Blog")
16
+ end
17
+
18
+ def self.down
19
+ ContentType.destroy_all(:name => 'BlogPost')
20
+ CategoryType.destroy_all(:name => "Blog Post")
21
+
22
+ drop_table :blog_post_versions
23
+ drop_table :blog_posts
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ class CreateBlogComments < ActiveRecord::Migration
2
+ def self.up
3
+ create_versioned_table :blog_comments do |t|
4
+ t.integer :post_id
5
+ t.string :author
6
+ t.string :email
7
+ t.string :url
8
+ t.string :ip
9
+ t.text :body
10
+ end
11
+ ContentType.create!(:name => "BlogComment", :group_name => "Blog")
12
+ end
13
+
14
+ def self.down
15
+ ContentType.destroy_all(:name => 'BlogComment')
16
+ drop_table :blog_comment_versions
17
+ drop_table :blog_comments
18
+ end
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,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,68 @@
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
+ class MigrateTo20100427 < ActiveRecord::Migration
38
+ def self.up
39
+ drop_table :blog_group_membership_versions
40
+
41
+ PageRouteOption.all.each {|a| a.destroy unless a.page_route }
42
+
43
+ puts "Destroying portlets, pages, page_routes left over from old version of bcms_blog..."
44
+ puts "(*Not* destroying any existing Blogs, pages on which Blogs are connected, or BlogPosts)"
45
+ portlets = [BlogPostPortlet, BlogPostsInCategoryPortlet, BlogPostsWithTagPortlet, BlogPostsInDayPortlet, BlogPostsInMonthPortlet, BlogPostsInYearPortlet]
46
+ #pp portlets.map(&:all).flatten.map(&:connected_pages).flatten.map(&:page_routes).flatten.each(&:destroy)
47
+ pp portlets.map(&:all).flatten.map(&:connected_pages).flatten.each(&:destroy)
48
+
49
+ # 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...
50
+ #Blog.all.map(&:connected_pages).flatten.each do |page|
51
+ # page.hidden = true
52
+ # page.save!
53
+ # page.section.hidden = false
54
+ # page.section.save!
55
+ #end
56
+
57
+ puts "Calling after_create on each Blog in the system..."
58
+ Blog.all.each do |blog|
59
+ puts "#{blog}..."
60
+ blog.send :after_create
61
+ end
62
+ end
63
+
64
+ def self.down
65
+ end
66
+ end
67
+
68
+ MigrateTo20100427.up
@@ -0,0 +1,9 @@
1
+ module Cms::Routes
2
+ def routes_for_bcms_blog
3
+ namespace(:cms) do |cms|
4
+ cms.content_blocks :blogs
5
+ cms.content_blocks :blog_posts
6
+ cms.content_blocks :blog_comments
7
+ end
8
+ end
9
+ end
data/lib/bcms_blog.rb ADDED
@@ -0,0 +1 @@
1
+ require 'bcms_blog/routes'
data/rails/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2
+ Cms.add_to_rails_paths gem_root
3
+ Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
4
+ ApplicationHelper.module_eval { include Cms::BlogHelper }
data/test/factories.rb ADDED
@@ -0,0 +1,31 @@
1
+ if ActiveRecord::Base.connection.table_exists?("blogs")
2
+
3
+ Factory.define :group do |m|
4
+ m.sequence(:name) {|n| "TestGroup#{n}" }
5
+ end
6
+
7
+ Factory.define :group_type do |m|
8
+ m.sequence(:name) {|n| "TestGroupType#{n}" }
9
+ end
10
+
11
+ Factory.define :user do |m|
12
+ m.first_name "Test"
13
+ m.last_name "User"
14
+ m.sequence(:login) {|n| "test_#{n}" }
15
+ m.email {|a| "#{a.login}@example.com" }
16
+ m.password "password"
17
+ m.password_confirmation {|a| a.password }
18
+ end
19
+
20
+ Factory.define :blog do |m|
21
+ m.sequence(:name) {|n| "TestBlog#{n}"}
22
+ end
23
+
24
+ Factory.define :blog_post do |b|
25
+ b.sequence(:name) { |n| "BlogPost#{n}" }
26
+ b.blog { Factory.create(:blog) }
27
+ b.sequence(:body) { |n| "Lorem ipsum #{n}" }
28
+ b.author { User.find(:first) }
29
+ end
30
+
31
+ end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class BlogPostTest < ActionController::TestCase
4
+ tests Cms::ContentController
5
+
6
+ def setup
7
+ create_baseline_data
8
+ end
9
+
10
+ def teardown
11
+ destroy_baseline_data
12
+ end
13
+
14
+ def test_show_post
15
+ get :show, :path => ["blog", "post"],
16
+ :year => @first_post.year,
17
+ :month => @first_post.month,
18
+ :day => @first_post.day,
19
+ :slug => @first_post.slug
20
+ #log @response.body
21
+ assert_response :success
22
+ assert_select "title", @first_post.name
23
+ assert_select ".blog_post", 1
24
+
25
+ assert_select "#blog_post_#{@first_post.id}" do
26
+ assert_select "h2 a", @first_post.name
27
+ assert_select "p.body", @first_post.body
28
+ assert_select "p.meta a", "General"
29
+ assert_select "p.meta a", "0 Comments"
30
+ end
31
+
32
+ end
33
+
34
+ def test_non_existent_slug_should_return_404
35
+ get :show, :path => ["blog", "post"],
36
+ :year => 2005, :month => 6, :day => 14,
37
+ :slug => "not-here"
38
+ assert_response :not_found
39
+ end
40
+
41
+ end
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class BlogTest < ActionController::TestCase
4
+ tests Cms::ContentController
5
+
6
+ def setup
7
+ create_baseline_data
8
+ end
9
+
10
+ def teardown
11
+ destroy_baseline_data
12
+ end
13
+
14
+ def test_list_of_blog_posts
15
+ get :show
16
+ #log @response.body
17
+ assert_response :success
18
+ assert_select ".blog_post", 5
19
+
20
+ assert_select "#blog_post_#{@first_post.id}" do
21
+ assert_select "h2 a", @first_post.name
22
+ assert_select "p.body", @first_post.body
23
+ assert_select "p.meta a", "General"
24
+ assert_select "p.meta a", "0 Comments"
25
+ end
26
+
27
+ assert_select "#blog_post_#{@foo_post_1.id}" do
28
+ assert_select "h2 a", @foo_post_1.name
29
+ assert_select "p.body", @foo_post_1.body
30
+ assert_select "p.meta .tags a", "foo"
31
+ assert_select "p.meta .tags a", "stuff"
32
+ end
33
+ end
34
+
35
+ def test_list_of_tagged_blog_posts
36
+ get :show, :category => "General"
37
+ #log @response.body
38
+ assert_response :success
39
+ assert_select ".blog_post", 3
40
+ end
41
+
42
+ def test_list_of_categorized_blog_posts
43
+ get :show, :tag => "foo"
44
+ #log @response.body
45
+ assert_response :success
46
+ assert_select ".blog_post", 2
47
+ end
48
+
49
+ def test_list_of_blog_posts_in_day
50
+ get :show, :path => ["blog", "posts_in_day"],
51
+ :year => 2008, :month => 7, :day => 5
52
+ assert_response :success
53
+ assert_select ".blog_post", 2
54
+ end
55
+
56
+ def test_list_of_blog_posts_in_month
57
+ get :show, :path => ["blog", "posts_in_month"],
58
+ :year => 2008, :month => 7
59
+ assert_response :success
60
+ assert_select ".blog_post", 3
61
+ end
62
+
63
+ def test_list_of_blog_posts_in_year
64
+ get :show, :path => ["blog", "posts_in_year"],
65
+ :year => 2008
66
+ assert_response :success
67
+ assert_select ".blog_post", 4
68
+ end
69
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class Cms::BlogPostsControllerTest < ActionController::TestCase
4
+ def setup
5
+ create_non_admin_user
6
+ login_as(@user)
7
+ end
8
+
9
+ def test_access_denied_on_create_if_blog_not_user_editable
10
+ @editable = Factory.create(:blog, :groups => [@group])
11
+ @non_editable = Factory.create(:blog)
12
+ post :create, :blog_post => { :blog_id => @non_editable.id }
13
+ assert @response.body.include?("AccessDenied")
14
+ end
15
+
16
+ def test_access_denied_on_update_if_blog_not_user_editable
17
+ @editable = Factory.create(:blog, :groups => [@group])
18
+ @non_editable = Factory.create(:blog)
19
+ @blog_post = Factory.create(:blog_post, :blog => @non_editable)
20
+ put :update, :id => @blog_post, :blog_post => { :name => "Foo" }
21
+ assert @response.body.include?("AccessDenied")
22
+ end
23
+
24
+ def test_no_access_if_no_editable_blogs
25
+ @blog = Factory.create(:blog)
26
+ get :index
27
+ assert_template "no_access"
28
+ end
29
+
30
+ def test_index_shouldnt_show_non_editable_posts
31
+ @editable = Factory.create(:blog, :groups => [@group])
32
+ @non_editable = Factory.create(:blog)
33
+ @blog_post = Factory.create(:blog_post, :name => "Non-editable", :blog => @non_editable)
34
+ get :index
35
+ assert !@response.body.include?("Non-editable")
36
+ end
37
+
38
+ def test_create_sets_author
39
+ @blog = Factory.create(:blog, :groups => [@group])
40
+ post :create, :blog_post => { :blog_id => @blog.id }
41
+ assert_equal @user, assigns(:block).author
42
+ end
43
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ class Cms::BlogsControllerTest < ActionController::TestCase
4
+ def test_list_blog_posts_as_non_admin
5
+ create_non_admin_user
6
+ login_as(@user)
7
+
8
+ get :index
9
+ assert_response :success
10
+ assert @response.body.include? "Sorry, this section is restricted to administrators."
11
+ end
12
+ 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,104 @@
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
+ unless $database_initialized
7
+ $database_initialized = true
8
+
9
+ # Empty the database and load in the default seed data for browsercms
10
+ # and the blog module
11
+ `rake db:test:purge`
12
+ `rake db:migrate`
13
+
14
+ # Publish all pages, as they are drafts after migrating
15
+ Page.find(:all).each(&:publish!)
16
+ end
17
+
18
+ class ActiveSupport::TestCase
19
+ require File.dirname(__FILE__) + '/test_logging'
20
+ include TestLogging
21
+ # Transactional fixtures accelerate your tests by wrapping each test method
22
+ # in a transaction that's rolled back on completion. This ensures that the
23
+ # test database remains unchanged so your fixtures don't have to be reloaded
24
+ # between every test method. Fewer database queries means faster tests.
25
+ #
26
+ # Read Mike Clark's excellent walkthrough at
27
+ # http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
28
+ #
29
+ # Every Active Record database supports transactions except MyISAM tables
30
+ # in MySQL. Turn off transactional fixtures in this case; however, if you
31
+ # don't care one way or the other, switching from MyISAM to InnoDB tables
32
+ # is recommended.
33
+ #
34
+ # The only drawback to using transactional fixtures is when you actually
35
+ # need to test transactions. Since your test is bracketed by a transaction,
36
+ # any transactions started in your code will be automatically rolled back.
37
+ self.use_transactional_fixtures = true
38
+
39
+ # Instantiated fixtures are slow, but give you @david where otherwise you
40
+ # would need people(:david). If you don't want to migrate your existing
41
+ # test cases which use the @david style and don't mind the speed hit (each
42
+ # instantiated fixtures translates to a database query per test method),
43
+ # then set this back to true.
44
+ self.use_instantiated_fixtures = false
45
+
46
+ # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
47
+ #
48
+ # Note: You'll currently still have to declare fixtures explicitly in integration tests
49
+ # -- they do not yet inherit this setting
50
+ fixtures :all
51
+
52
+ # Add more helper methods to be used by all tests here...
53
+ def create_baseline_data
54
+ # Find the seed data items
55
+ @blog = Blog.find_by_name("My Blog")
56
+ @blog_page = Page.find_by_path("/")
57
+ @blog_post_page = Page.find_by_path("/blog/post")
58
+ @category_type = CategoryType.find_by_name("Blog Post")
59
+
60
+ # For some reason this is necessary otherwise the relevant page routes aren't loaded when
61
+ # the tests are run via "rake" (as opposed to running them directly). I don't know exactly
62
+ # why this is the case.
63
+ ActionController::Routing::Routes.load!
64
+
65
+ @stuff = Category.create!(:name => "Stuff", :category_type => @category_type)
66
+ @general = Category.create!(:name => "General", :category_type => @category_type)
67
+
68
+ @first_post = Factory(:blog_post, :blog => @blog, :category => @general,
69
+ :published_at => Time.utc(2008, 7, 5, 6), :publish_on_save => true)
70
+
71
+ @foo_post_1 = Factory(:blog_post, :blog => @blog, :category => @stuff,
72
+ :published_at => Time.utc(2008, 7, 5, 12), :tag_list => "foo stuff", :publish_on_save => true)
73
+
74
+ @foo_post_2 = Factory(:blog_post, :blog => @blog, :category => @general,
75
+ :published_at => Time.utc(2008, 7, 21), :publish_on_save => true)
76
+
77
+ @bar_post_1 = Factory(:blog_post, :blog => @blog, :category => @stuff,
78
+ :published_at => Time.utc(2008, 9, 2), :tag_list => "foo stuff", :publish_on_save => true)
79
+
80
+ @bar_post_2 = Factory(:blog_post, :blog => @blog, :category => @general,
81
+ :published_at => Time.utc(2009, 3, 18), :publish_on_save => true)
82
+ end
83
+
84
+ def destroy_baseline_data
85
+ Category.destroy_all
86
+ BlogPost.destroy_all
87
+ end
88
+
89
+ def create_non_admin_user
90
+ @group = Factory(:group, :name => "Test", :group_type => Factory(:group_type, :name => "CMS User", :cms_access => true))
91
+ @group.permissions << Permission.find_by_name("edit_content")
92
+ @group.permissions << Permission.find_by_name("publish_content")
93
+ @group.save!
94
+
95
+ @user = Factory(:user)
96
+ @user.groups << @group
97
+ @user.save!
98
+ end
99
+
100
+ def login_as(user)
101
+ @request.session[:user_id] = user ? user.id : nil
102
+ end
103
+
104
+ end