comfy_blog 1.1.1 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/README.md +3 -3
  4. data/app/controllers/{admin → comfy/admin}/blog/base_controller.rb +2 -2
  5. data/app/controllers/{admin → comfy/admin}/blog/blogs_controller.rb +1 -1
  6. data/app/controllers/{admin → comfy/admin}/blog/comments_controller.rb +1 -1
  7. data/app/controllers/{admin → comfy/admin}/blog/posts_controller.rb +2 -1
  8. data/app/controllers/{blog → comfy/blog}/base_controller.rb +1 -1
  9. data/app/controllers/{blog → comfy/blog}/comments_controller.rb +4 -4
  10. data/app/controllers/{blog → comfy/blog}/posts_controller.rb +1 -1
  11. data/app/models/{blog → comfy/blog}/blog.rb +4 -2
  12. data/app/models/{blog → comfy/blog}/comment.rb +2 -2
  13. data/app/models/{blog → comfy/blog}/post.rb +2 -2
  14. data/app/views/{admin → comfy/admin}/blog/blogs/_form.html.haml +2 -2
  15. data/app/views/{admin → comfy/admin}/blog/blogs/edit.html.haml +0 -0
  16. data/app/views/comfy/admin/blog/blogs/index.html.haml +26 -0
  17. data/app/views/{admin → comfy/admin}/blog/blogs/new.html.haml +0 -0
  18. data/app/views/comfy/admin/blog/comments/_comment.html.haml +17 -0
  19. data/app/views/{admin → comfy/admin}/blog/comments/index.html.haml +1 -1
  20. data/app/views/{admin → comfy/admin}/blog/comments/toggle_publish.js.erb +0 -0
  21. data/app/views/comfy/admin/blog/partials/_navigation.html.haml +6 -0
  22. data/app/views/{admin → comfy/admin}/blog/posts/_form.html.haml +4 -3
  23. data/app/views/{admin → comfy/admin}/blog/posts/edit.html.haml +0 -0
  24. data/app/views/comfy/admin/blog/posts/index.html.haml +32 -0
  25. data/app/views/{admin → comfy/admin}/blog/posts/new.html.haml +0 -0
  26. data/app/views/{blog → comfy/blog}/comments/_form.html.haml +1 -1
  27. data/app/views/{blog → comfy/blog}/posts/index.html.haml +1 -1
  28. data/app/views/{blog → comfy/blog}/posts/index.rss.builder +2 -2
  29. data/app/views/{blog → comfy/blog}/posts/show.html.haml +1 -1
  30. data/app/views/layouts/{blog → comfy/blog}/application.html.haml +0 -0
  31. data/comfy_blog.gemspec +2 -2
  32. data/config/application.rb +2 -0
  33. data/config/initializers/comfy_blog.rb +6 -3
  34. data/db/migrate/00_create_cms.rb +41 -39
  35. data/db/migrate/01_create_blog.rb +13 -13
  36. data/lib/comfy_blog/configuration.rb +7 -3
  37. data/lib/comfy_blog/engine.rb +2 -2
  38. data/lib/comfy_blog/routes/blog.rb +10 -8
  39. data/lib/comfy_blog/routes/blog_admin.rb +8 -6
  40. data/lib/comfy_blog/version.rb +1 -1
  41. data/lib/generators/comfy/blog/blog_generator.rb +1 -1
  42. data/test/controllers/{admin → comfy/admin}/blog/blogs_controller_test.rb +8 -8
  43. data/test/controllers/{admin → comfy/admin}/blog/comments_controller_test.rb +7 -7
  44. data/test/controllers/{admin → comfy/admin}/blog/posts_controller_test.rb +16 -8
  45. data/test/controllers/{blog → comfy/blog}/comments_controller_test.rb +8 -8
  46. data/test/controllers/{blog → comfy/blog}/posts_controller_test.rb +5 -5
  47. data/test/fixtures/{blog → comfy/blog}/blogs.yml +1 -1
  48. data/test/fixtures/{blog → comfy/blog}/comments.yml +0 -0
  49. data/test/fixtures/{blog → comfy/blog}/posts.yml +0 -0
  50. data/test/fixtures/{cms → comfy/cms}/sites.yml +0 -0
  51. data/test/generators/blog_generator_test.rb +1 -1
  52. data/test/lib/configuration_test.rb +4 -3
  53. data/test/models/{blog/blog_test.rb → blog_test.rb} +10 -10
  54. data/test/models/{blog/comments_test.rb → comments_test.rb} +9 -9
  55. data/test/models/{blog/posts_test.rb → posts_test.rb} +19 -19
  56. data/test/test_helper.rb +3 -2
  57. metadata +45 -46
  58. data/app/views/admin/blog/blogs/index.html.haml +0 -26
  59. data/app/views/admin/blog/comments/_comment.html.haml +0 -17
  60. data/app/views/admin/blog/partials/_navigation.html.haml +0 -6
  61. data/app/views/admin/blog/posts/index.html.haml +0 -32
@@ -1,7 +1,7 @@
1
1
  class CreateBlog < ActiveRecord::Migration
2
2
 
3
3
  def self.up
4
- create_table :blogs do |t|
4
+ create_table :comfy_blogs do |t|
5
5
  t.integer :site_id, :null => false
6
6
  t.string :label, :null => false
7
7
  t.string :identifier, :null => false
@@ -9,10 +9,10 @@ class CreateBlog < ActiveRecord::Migration
9
9
  t.string :path
10
10
  t.text :description
11
11
  end
12
- add_index :blogs, [:site_id, :path]
13
- add_index :blogs, :identifier
12
+ add_index :comfy_blogs, [:site_id, :path]
13
+ add_index :comfy_blogs, :identifier
14
14
 
15
- create_table :blog_posts do |t|
15
+ create_table :comfy_blog_posts do |t|
16
16
  t.integer :blog_id, :null => false
17
17
  t.string :title, :null => false
18
18
  t.string :slug, :null => false
@@ -25,12 +25,12 @@ class CreateBlog < ActiveRecord::Migration
25
25
  t.datetime :published_at, :null => false
26
26
  t.timestamps
27
27
  end
28
- add_index :blog_posts, [:is_published, :year, :month, :slug],
28
+ add_index :comfy_blog_posts, [:is_published, :year, :month, :slug],
29
29
  :name => 'index_blog_posts_on_published_year_month_slug'
30
- add_index :blog_posts, [:is_published, :created_at]
31
- add_index :blog_posts, :created_at
30
+ add_index :comfy_blog_posts, [:is_published, :created_at]
31
+ add_index :comfy_blog_posts, :created_at
32
32
 
33
- create_table :blog_comments do |t|
33
+ create_table :comfy_blog_comments do |t|
34
34
  t.integer :post_id, :null => false
35
35
  t.string :author, :null => false
36
36
  t.string :email, :null => false
@@ -38,15 +38,15 @@ class CreateBlog < ActiveRecord::Migration
38
38
  t.boolean :is_published, :null => false, :default => false
39
39
  t.timestamps
40
40
  end
41
- add_index :blog_comments, [:post_id, :created_at]
42
- add_index :blog_comments, [:post_id, :is_published, :created_at],
41
+ add_index :comfy_blog_comments, [:post_id, :created_at]
42
+ add_index :comfy_blog_comments, [:post_id, :is_published, :created_at],
43
43
  :name => 'index_blog_comments_on_post_published_created'
44
44
  end
45
45
 
46
46
  def self.down
47
- drop_table :blogs
48
- drop_table :blog_posts
49
- drop_table :blog_comments
47
+ drop_table :comfy_blogs
48
+ drop_table :comfy_posts
49
+ drop_table :comfy_comments
50
50
  end
51
51
 
52
52
  end
@@ -1,18 +1,22 @@
1
1
  module ComfyBlog
2
2
  class Configuration
3
-
3
+
4
4
  # Number of posts per page. Default is 10
5
5
  attr_accessor :posts_per_page
6
-
6
+
7
7
  # Comments can be automatically approved/published by changing this setting
8
8
  # Default is false.
9
9
  attr_accessor :auto_publish_comments
10
10
 
11
+ # A default author can be specified for posts
12
+ attr_accessor :default_author
13
+
11
14
  # Configuration defaults
12
15
  def initialize
13
16
  @posts_per_page = 10
14
17
  @auto_publish_comments = false
18
+ @default_author = nil
15
19
  end
16
-
20
+
17
21
  end
18
22
  end
@@ -16,9 +16,9 @@ module ComfyBlog
16
16
 
17
17
  class Engine < ::Rails::Engine
18
18
  initializer 'comfy_blog.configuration' do |app|
19
- ComfortableMexicanSofa::ViewHooks.add(:navigation, '/admin/blog/partials/navigation')
19
+ ComfortableMexicanSofa::ViewHooks.add(:navigation, '/comfy/admin/blog/partials/navigation')
20
20
  config.to_prepare do
21
- Cms::Site.send :include, ComfyBlog::CmsSiteExtensions
21
+ Comfy::Cms::Site.send :include, ComfyBlog::CmsSiteExtensions
22
22
  end
23
23
  end
24
24
  end
@@ -4,15 +4,17 @@ class ActionDispatch::Routing::Mapper
4
4
  options[:path] ||= 'blog'
5
5
  path = ['(:cms_path)', options[:path], '(:blog_path)'].join('/')
6
6
 
7
- namespace :blog, :path => path, :constraints => {:blog_path => /\w[a-z0-9_-]*/} do
8
- with_options :constraints => {:year => /\d{4}/, :month => /\d{1,2}/} do |o|
9
- o.get ':year' => 'posts#index', :as => :posts_of_year
10
- o.get ':year/:month' => 'posts#index', :as => :posts_of_month
11
- o.get ':year/:month/:slug' => 'posts#show', :as => :posts_dated
7
+ scope :module => :comfy, :as => :comfy do
8
+ namespace :blog, :path => path, :constraints => {:blog_path => /\w[a-z0-9_-]*/} do
9
+ with_options :constraints => {:year => /\d{4}/, :month => /\d{1,2}/} do |o|
10
+ o.get ':year' => 'posts#index', :as => :posts_of_year
11
+ o.get ':year/:month' => 'posts#index', :as => :posts_of_month
12
+ o.get ':year/:month/:slug' => 'posts#show', :as => :posts_dated
13
+ end
14
+ post ':slug/comments' => 'comments#create', :as => :comments
15
+ get ':slug' => 'posts#serve', :as => :post
16
+ get '/' => 'posts#serve', :as => :posts
12
17
  end
13
- post ':slug/comments' => 'comments#create', :as => :comments
14
- get ':slug' => 'posts#serve', :as => :post
15
- get '/' => 'posts#serve', :as => :posts
16
18
  end
17
19
  end
18
20
  end
@@ -4,12 +4,14 @@ class ActionDispatch::Routing::Mapper
4
4
  options[:path] ||= 'admin'
5
5
  path = [options[:path], 'sites', ':site_id'].join('/')
6
6
 
7
- scope :module => :admin do
8
- namespace :blog, :as => :admin, :path => path, :except => [:show] do
9
- resources :blogs do
10
- resources :posts
11
- resources :comments, :only => [:index, :destroy] do
12
- patch :toggle_publish, :on => :member
7
+ scope :module => :comfy, :as => :comfy do
8
+ scope :module => :admin do
9
+ namespace :blog, :as => :admin, :path => path, :except => [:show] do
10
+ resources :blogs do
11
+ resources :posts
12
+ resources :comments, :only => [:index, :destroy] do
13
+ patch :toggle_publish, :on => :member
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -1,3 +1,3 @@
1
1
  module ComfyBlog
2
- VERSION = "1.1.1"
2
+ VERSION = "1.12.0"
3
3
  end
@@ -37,7 +37,7 @@ module Comfy
37
37
  end
38
38
 
39
39
  def generate_views
40
- directory 'app/views/blog', 'app/views/blog'
40
+ directory 'app/views/comfy/blog', 'app/views/comfy/blog'
41
41
  end
42
42
 
43
43
  def show_readme
@@ -1,10 +1,10 @@
1
- require_relative '../../../test_helper'
1
+ require_relative '../../../../test_helper'
2
2
 
3
- class Admin::Blog::BlogsControllerTest < ActionController::TestCase
3
+ class Comfy::Admin::Blog::BlogsControllerTest < ActionController::TestCase
4
4
 
5
5
  def setup
6
- @site = cms_sites(:default)
7
- @blog = blog_blogs(:default)
6
+ @site = comfy_cms_sites(:default)
7
+ @blog = comfy_blog_blogs(:default)
8
8
  end
9
9
 
10
10
  def test_get_index
@@ -38,14 +38,14 @@ class Admin::Blog::BlogsControllerTest < ActionController::TestCase
38
38
  end
39
39
 
40
40
  def test_creation
41
- assert_difference 'Blog::Blog.count' do
41
+ assert_difference 'Comfy::Blog::Blog.count' do
42
42
  post :create, :site_id => @site, :blog => {
43
43
  :label => 'Test Blog',
44
44
  :identifier => 'test-blog',
45
45
  :path => 'test-blog',
46
46
  :description => 'Test Description'
47
47
  }
48
- blog = Blog::Blog.last
48
+ blog = Comfy::Blog::Blog.last
49
49
  assert_response :redirect
50
50
  assert_redirected_to :action => :edit, :id => blog
51
51
  assert_equal 'Blog created', flash[:success]
@@ -53,7 +53,7 @@ class Admin::Blog::BlogsControllerTest < ActionController::TestCase
53
53
  end
54
54
 
55
55
  def test_creation_failure
56
- assert_no_difference 'Blog::Blog.count' do
56
+ assert_no_difference 'Comfy::Blog::Blog.count' do
57
57
  post :create, :site_id => @site, :blog => { }
58
58
  assert_response :success
59
59
  assert_template :new
@@ -84,7 +84,7 @@ class Admin::Blog::BlogsControllerTest < ActionController::TestCase
84
84
  end
85
85
 
86
86
  def test_destroy
87
- assert_difference 'Blog::Blog.count', -1 do
87
+ assert_difference 'Comfy::Blog::Blog.count', -1 do
88
88
  delete :destroy, :site_id => @site, :id => @blog
89
89
  assert_response :redirect
90
90
  assert_redirected_to :action => :index
@@ -1,12 +1,12 @@
1
- require_relative '../../../test_helper'
1
+ require_relative '../../../../test_helper'
2
2
 
3
- class Admin::Blog::CommentsControllerTest < ActionController::TestCase
3
+ class Comfy::Admin::Blog::CommentsControllerTest < ActionController::TestCase
4
4
 
5
5
  def setup
6
- @site = cms_sites(:default)
7
- @blog = blog_blogs(:default)
8
- @post = blog_posts(:default)
9
- @comment = blog_comments(:default)
6
+ @site = comfy_cms_sites(:default)
7
+ @blog = comfy_blog_blogs(:default)
8
+ @post = comfy_blog_posts(:default)
9
+ @comment = comfy_blog_comments(:default)
10
10
  end
11
11
 
12
12
  def test_get_index
@@ -39,7 +39,7 @@ class Admin::Blog::CommentsControllerTest < ActionController::TestCase
39
39
  end
40
40
 
41
41
  def test_destroy
42
- assert_difference 'Blog::Comment.count', -1 do
42
+ assert_difference 'Comfy::Blog::Comment.count', -1 do
43
43
  delete :destroy, :site_id => @site, :blog_id => @blog, :id => @comment
44
44
  assert_response :redirect
45
45
  assert_redirected_to :action => :index
@@ -1,11 +1,11 @@
1
- require_relative '../../../test_helper'
1
+ require_relative '../../../../test_helper'
2
2
 
3
- class Admin::Blog::PostsControllerTest < ActionController::TestCase
3
+ class Comfy::Admin::Blog::PostsControllerTest < ActionController::TestCase
4
4
 
5
5
  def setup
6
- @site = cms_sites(:default)
7
- @blog = blog_blogs(:default)
8
- @post = blog_posts(:default)
6
+ @site = comfy_cms_sites(:default)
7
+ @blog = comfy_blog_blogs(:default)
8
+ @post = comfy_blog_posts(:default)
9
9
  end
10
10
 
11
11
  def test_get_index
@@ -23,8 +23,16 @@ class Admin::Blog::PostsControllerTest < ActionController::TestCase
23
23
  assert_select "form[action='/admin/sites/#{@site.id}/blogs/#{@blog.id}/posts']"
24
24
  end
25
25
 
26
+ def test_get_new_with_default_author
27
+ ComfyBlog.config.default_author = 'Default Author'
28
+ get :new, :site_id => @site, :blog_id => @blog
29
+ assert_response :success
30
+ assert assigns(:post)
31
+ assert_equal 'Default Author', assigns(:post).author
32
+ end
33
+
26
34
  def test_creation
27
- assert_difference 'Blog::Post.count' do
35
+ assert_difference 'Comfy::Blog::Post.count' do
28
36
  post :create, :site_id => @site, :blog_id => @blog, :post => {
29
37
  :title => 'Test Post',
30
38
  :slug => 'test-post',
@@ -40,7 +48,7 @@ class Admin::Blog::PostsControllerTest < ActionController::TestCase
40
48
  end
41
49
 
42
50
  def test_creation_failure
43
- assert_no_difference 'Blog::Post.count' do
51
+ assert_no_difference 'Comfy::Blog::Post.count' do
44
52
  post :create, :site_id => @site, :blog_id => @blog, :post => { }
45
53
  assert_response :success
46
54
  assert_template :new
@@ -89,7 +97,7 @@ class Admin::Blog::PostsControllerTest < ActionController::TestCase
89
97
  end
90
98
 
91
99
  def test_destroy
92
- assert_difference 'Blog::Post.count', -1 do
100
+ assert_difference 'Comfy::Blog::Post.count', -1 do
93
101
  delete :destroy, :site_id => @site, :blog_id => @blog, :id => @post
94
102
  assert_response :redirect
95
103
  assert_redirected_to :action => :index
@@ -1,31 +1,31 @@
1
- require_relative '../../test_helper'
1
+ require_relative '../../../test_helper'
2
2
 
3
- class Blog::CommentsControllerTest < ActionController::TestCase
3
+ class Comfy::Blog::CommentsControllerTest < ActionController::TestCase
4
4
 
5
5
  def setup
6
- @blog = blog_blogs(:default)
7
- @post = blog_posts(:default)
6
+ @blog = comfy_blog_blogs(:default)
7
+ @post = comfy_blog_posts(:default)
8
8
  end
9
9
 
10
10
  def test_creation
11
- assert_difference 'Blog::Comment.count' do
11
+ assert_difference 'Comfy::Blog::Comment.count' do
12
12
  post :create, :slug => @post.slug, :comment => {
13
13
  :author => 'Test',
14
14
  :email => 'test@test.test',
15
15
  :content => 'Test Content'
16
16
  }
17
17
  assert_response :redirect
18
- assert_redirected_to blog_post_path
18
+ assert_redirected_to comfy_blog_post_path
19
19
  assert_equal 'Comment created', flash[:success]
20
20
 
21
- comment = Blog::Comment.last
21
+ comment = Comfy::Blog::Comment.last
22
22
  assert_equal 'Test', comment.author
23
23
  assert_equal @post, comment.post
24
24
  end
25
25
  end
26
26
 
27
27
  def test_creation_failure
28
- assert_no_difference 'Blog::Comment.count' do
28
+ assert_no_difference 'Comfy::Blog::Comment.count' do
29
29
  post :create, :slug => @post.slug, :comment => { }
30
30
  assert_response :success
31
31
  assert_template :show
@@ -1,10 +1,10 @@
1
- require_relative '../../test_helper'
1
+ require_relative '../../../test_helper'
2
2
 
3
- class Blog::PostsControllerTest < ActionController::TestCase
3
+ class Comfy::Blog::PostsControllerTest < ActionController::TestCase
4
4
 
5
5
  def setup
6
- @blog = blog_blogs(:default)
7
- @post = blog_posts(:default)
6
+ @blog = comfy_blog_blogs(:default)
7
+ @post = comfy_blog_posts(:default)
8
8
  end
9
9
 
10
10
  def test_get_index
@@ -24,7 +24,7 @@ class Blog::PostsControllerTest < ActionController::TestCase
24
24
  end
25
25
 
26
26
  def test_get_index_with_unpublished
27
- blog_posts(:default).update_column(:is_published, false)
27
+ comfy_blog_posts(:default).update_column(:is_published, false)
28
28
  get :serve
29
29
  assert_response :success
30
30
  assert_equal 0, assigns(:posts).size
@@ -3,5 +3,5 @@ default:
3
3
  label: Default Blog
4
4
  identifier: default-blog
5
5
  path:
6
- app_layout: blog/application
6
+ app_layout: comfy/blog/application
7
7
  description: Default Description
@@ -13,7 +13,7 @@ class CmsGeneratorTest < Rails::Generators::TestCase
13
13
 
14
14
  assert_file 'config/routes.rb', read_file('blog/routes.rb')
15
15
 
16
- assert_directory 'app/views/blog'
16
+ assert_directory 'app/views/comfy/blog'
17
17
  end
18
18
 
19
19
  end
@@ -1,16 +1,17 @@
1
1
  require_relative '../test_helper'
2
2
 
3
3
  class ConfigurationTest < ActiveSupport::TestCase
4
-
4
+
5
5
  def test_configuration
6
6
  assert config = ComfyBlog.configuration
7
7
  assert_equal 10, config.posts_per_page
8
8
  assert_equal false, config.auto_publish_comments
9
+ assert_equal nil, config.default_author
9
10
  end
10
-
11
+
11
12
  def test_initialization_overrides
12
13
  ComfyBlog.config.posts_per_page = 5
13
14
  assert_equal 5, ComfyBlog.config.posts_per_page
14
15
  end
15
-
16
+
16
17
  end
@@ -1,28 +1,28 @@
1
- require_relative '../../test_helper'
1
+ require_relative '../test_helper'
2
2
 
3
3
  class BlogTest < ActiveSupport::TestCase
4
4
 
5
5
  def test_site_association
6
- assert_equal [blog_blogs(:default)], cms_sites(:default).blogs
6
+ assert_equal [comfy_blog_blogs(:default)], comfy_cms_sites(:default).blogs
7
7
  end
8
8
 
9
9
  def test_fixtures_validity
10
- Blog::Blog.all.each do |blog|
10
+ Comfy::Blog::Blog.all.each do |blog|
11
11
  assert blog.valid?, blog.errors.inspect
12
12
  end
13
13
  end
14
14
 
15
15
  def test_validation
16
- blog = Blog::Blog.new
16
+ blog = Comfy::Blog::Blog.new
17
17
  assert blog.invalid?
18
18
  assert_errors_on blog, :site_id, :label, :identifier, :path
19
19
  end
20
20
 
21
21
  def test_validation_path_presence
22
- blog_a = blog_blogs(:default)
22
+ blog_a = comfy_blog_blogs(:default)
23
23
  refute blog_a.path.present?
24
24
 
25
- blog_b = cms_sites(:default).blogs.new(
25
+ blog_b = comfy_cms_sites(:default).blogs.new(
26
26
  :label => 'Test Blog A',
27
27
  :identifier => 'test-blog-a'
28
28
  )
@@ -42,8 +42,8 @@ class BlogTest < ActiveSupport::TestCase
42
42
  end
43
43
 
44
44
  def test_creation
45
- assert_difference 'Blog::Blog.count' do
46
- cms_sites(:default).blogs.create(
45
+ assert_difference 'Comfy::Blog::Blog.count' do
46
+ comfy_cms_sites(:default).blogs.create(
47
47
  :label => 'Test Blog',
48
48
  :identifier => 'test-blog',
49
49
  :path => 'test-blog'
@@ -52,8 +52,8 @@ class BlogTest < ActiveSupport::TestCase
52
52
  end
53
53
 
54
54
  def test_destroy
55
- assert_difference ['Blog::Blog.count', 'Blog::Post.count'], -1 do
56
- blog_blogs(:default).destroy
55
+ assert_difference ['Comfy::Blog::Blog.count', 'Comfy::Blog::Post.count'], -1 do
56
+ comfy_blog_blogs(:default).destroy
57
57
  end
58
58
  end
59
59
  end