comfy_blog 0.0.0 → 0.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.
- data/README.md +48 -6
- data/VERSION +1 -1
- data/app/controllers/admin/blog/base_controller.rb +3 -0
- data/app/controllers/{blog/admin → admin/blog}/comments_controller.rb +1 -1
- data/app/controllers/{blog/admin → admin/blog}/posts_controller.rb +7 -7
- data/app/controllers/admin/blog/tags_controller.rb +56 -0
- data/app/controllers/blog/comments_controller.rb +35 -0
- data/app/controllers/blog/posts_controller.rb +8 -1
- data/app/helpers/blog/application_helper.rb +5 -2
- data/app/models/blog/comment.rb +11 -1
- data/app/models/blog/post.rb +8 -4
- data/app/models/blog/tag.rb +3 -3
- data/app/models/blog/tagging.rb +1 -1
- data/app/views/{blog/admin → admin/blog}/_html_head.html.erb +0 -0
- data/app/views/admin/blog/_navigation.html.erb +2 -0
- data/app/views/{blog/admin → admin/blog}/comments/_comment.html.erb +2 -2
- data/app/views/{blog/admin → admin/blog}/comments/destroy.js.erb +0 -0
- data/app/views/{blog/admin → admin/blog}/comments/index.html.erb +3 -1
- data/app/views/{blog/admin → admin/blog}/comments/publish.js.erb +0 -0
- data/app/views/{blog/admin → admin/blog}/posts/_form.html.erb +11 -0
- data/app/views/{blog/admin → admin/blog}/posts/_post.html.erb +4 -4
- data/app/views/{blog/admin → admin/blog}/posts/edit.html.erb +0 -0
- data/app/views/admin/blog/posts/index.html.erb +11 -0
- data/app/views/{blog/admin → admin/blog}/posts/new.html.erb +0 -0
- data/app/views/admin/blog/tags/_form.html.erb +20 -0
- data/app/views/admin/blog/tags/_tag.html.erb +16 -0
- data/app/views/admin/blog/tags/edit.html.erb +5 -0
- data/app/views/admin/blog/tags/index.html.erb +9 -0
- data/app/views/admin/blog/tags/new.html.erb +5 -0
- data/app/views/blog/comments/_comment.html.erb +4 -0
- data/app/views/blog/comments/_form.html.erb +6 -0
- data/app/views/blog/comments/create.js.erb +6 -0
- data/app/views/blog/posts/_post.html.erb +2 -12
- data/app/views/blog/posts/index.rss.builder +18 -0
- data/app/views/blog/posts/show.html.erb +9 -1
- data/comfy_blog.gemspec +33 -18
- data/config/initializers/comfy_blog.rb +7 -0
- data/config/initializers/wrap_parameters.rb +1 -1
- data/config/routes.rb +9 -7
- data/db/migrate/01_create_comfy_blog.rb +4 -5
- data/db/schema.rb +8 -9
- data/lib/comfy_blog/configuration.rb +20 -6
- data/lib/comfy_blog/engine.rb +6 -6
- data/lib/comfy_blog.rb +1 -1
- data/lib/generators/README +6 -6
- data/lib/generators/blog_generator.rb +3 -3
- data/lib/tasks/comfy_blog.rake +4 -0
- data/test/fixtures/blog/tags.yml +5 -0
- data/test/functional/{blog/admin → admin/blog}/comments_controller_test.rb +1 -1
- data/test/functional/{blog/admin → admin/blog}/posts_controller_test.rb +6 -8
- data/test/functional/admin/blog/tags_controller_test.rb +88 -0
- data/test/functional/blog/comments_controller_test.rb +78 -0
- data/test/functional/blog/posts_controller_test.rb +8 -0
- data/test/integration/routing_test.rb +26 -0
- data/test/test_helper.rb +9 -6
- data/test/unit/comment_test.rb +13 -1
- data/test/unit/configuration_test.rb +8 -5
- data/test/unit/post_test.rb +19 -0
- data/test/unit/tag_test.rb +2 -1
- metadata +42 -27
- data/app/controllers/blog/admin/base_controller.rb +0 -3
- data/app/views/blog/admin/_navigation.html.erb +0 -1
- data/app/views/blog/admin/posts/index.html.erb +0 -9
data/comfy_blog.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "comfy_blog"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Oleg Khabarov", "The Working Group Inc."]
|
12
|
-
s.date = "2012-01-
|
12
|
+
s.date = "2012-01-20"
|
13
13
|
s.description = ""
|
14
14
|
s.email = "oleg@twg.ca"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,10 +27,12 @@ Gem::Specification.new do |s|
|
|
27
27
|
"app/assets/stylesheets/comfy_blog/admin.css",
|
28
28
|
"app/assets/stylesheets/comfy_blog/application.css",
|
29
29
|
"app/assets/stylesheets/comfy_blog/reset.css",
|
30
|
+
"app/controllers/admin/blog/base_controller.rb",
|
31
|
+
"app/controllers/admin/blog/comments_controller.rb",
|
32
|
+
"app/controllers/admin/blog/posts_controller.rb",
|
33
|
+
"app/controllers/admin/blog/tags_controller.rb",
|
30
34
|
"app/controllers/application_controller.rb",
|
31
|
-
"app/controllers/blog/
|
32
|
-
"app/controllers/blog/admin/comments_controller.rb",
|
33
|
-
"app/controllers/blog/admin/posts_controller.rb",
|
35
|
+
"app/controllers/blog/comments_controller.rb",
|
34
36
|
"app/controllers/blog/posts_controller.rb",
|
35
37
|
"app/helpers/blog/application_helper.rb",
|
36
38
|
"app/models/.gitkeep",
|
@@ -38,19 +40,28 @@ Gem::Specification.new do |s|
|
|
38
40
|
"app/models/blog/post.rb",
|
39
41
|
"app/models/blog/tag.rb",
|
40
42
|
"app/models/blog/tagging.rb",
|
41
|
-
"app/views/blog/
|
42
|
-
"app/views/blog/
|
43
|
-
"app/views/blog/
|
44
|
-
"app/views/blog/
|
45
|
-
"app/views/blog/
|
46
|
-
"app/views/blog/
|
47
|
-
"app/views/blog/
|
48
|
-
"app/views/blog/
|
49
|
-
"app/views/blog/
|
50
|
-
"app/views/blog/
|
51
|
-
"app/views/blog/
|
43
|
+
"app/views/admin/blog/_html_head.html.erb",
|
44
|
+
"app/views/admin/blog/_navigation.html.erb",
|
45
|
+
"app/views/admin/blog/comments/_comment.html.erb",
|
46
|
+
"app/views/admin/blog/comments/destroy.js.erb",
|
47
|
+
"app/views/admin/blog/comments/index.html.erb",
|
48
|
+
"app/views/admin/blog/comments/publish.js.erb",
|
49
|
+
"app/views/admin/blog/posts/_form.html.erb",
|
50
|
+
"app/views/admin/blog/posts/_post.html.erb",
|
51
|
+
"app/views/admin/blog/posts/edit.html.erb",
|
52
|
+
"app/views/admin/blog/posts/index.html.erb",
|
53
|
+
"app/views/admin/blog/posts/new.html.erb",
|
54
|
+
"app/views/admin/blog/tags/_form.html.erb",
|
55
|
+
"app/views/admin/blog/tags/_tag.html.erb",
|
56
|
+
"app/views/admin/blog/tags/edit.html.erb",
|
57
|
+
"app/views/admin/blog/tags/index.html.erb",
|
58
|
+
"app/views/admin/blog/tags/new.html.erb",
|
59
|
+
"app/views/blog/comments/_comment.html.erb",
|
60
|
+
"app/views/blog/comments/_form.html.erb",
|
61
|
+
"app/views/blog/comments/create.js.erb",
|
52
62
|
"app/views/blog/posts/_post.html.erb",
|
53
63
|
"app/views/blog/posts/index.html.erb",
|
64
|
+
"app/views/blog/posts/index.rss.builder",
|
54
65
|
"app/views/blog/posts/show.html.erb",
|
55
66
|
"app/views/layouts/application.html.erb",
|
56
67
|
"comfy_blog.gemspec",
|
@@ -77,6 +88,7 @@ Gem::Specification.new do |s|
|
|
77
88
|
"lib/comfy_blog/form_builder.rb",
|
78
89
|
"lib/generators/README",
|
79
90
|
"lib/generators/blog_generator.rb",
|
91
|
+
"lib/tasks/comfy_blog.rake",
|
80
92
|
"script/rails",
|
81
93
|
"test/fixtures/.gitkeep",
|
82
94
|
"test/fixtures/blog/comments.yml",
|
@@ -84,9 +96,12 @@ Gem::Specification.new do |s|
|
|
84
96
|
"test/fixtures/blog/taggings.yml",
|
85
97
|
"test/fixtures/blog/tags.yml",
|
86
98
|
"test/functional/.gitkeep",
|
87
|
-
"test/functional/blog/
|
88
|
-
"test/functional/blog/
|
99
|
+
"test/functional/admin/blog/comments_controller_test.rb",
|
100
|
+
"test/functional/admin/blog/posts_controller_test.rb",
|
101
|
+
"test/functional/admin/blog/tags_controller_test.rb",
|
102
|
+
"test/functional/blog/comments_controller_test.rb",
|
89
103
|
"test/functional/blog/posts_controller_test.rb",
|
104
|
+
"test/integration/routing_test.rb",
|
90
105
|
"test/test_helper.rb",
|
91
106
|
"test/unit/.gitkeep",
|
92
107
|
"test/unit/comment_test.rb",
|
@@ -9,10 +9,17 @@ ComfyBlog.configure do |config|
|
|
9
9
|
# Form builder
|
10
10
|
# config.form_builder = 'ComfyBlog::FormBuilder'
|
11
11
|
|
12
|
+
# Set the public path if you have changed it
|
13
|
+
# config.public_route_prefix = ''
|
14
|
+
|
12
15
|
# Layout used for public posts/comments
|
13
16
|
# config.public_layout = 'application'
|
14
17
|
|
15
18
|
# Number of posts per page. Default is 10
|
16
19
|
# config.posts_per_page = 10
|
17
20
|
|
21
|
+
# Comments can be automatically approved/published by changing this setting
|
22
|
+
# Default is false.
|
23
|
+
# config.auto_publish_comments = false
|
24
|
+
|
18
25
|
end
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
|
7
7
|
ActiveSupport.on_load(:action_controller) do
|
8
|
-
wrap_parameters format
|
8
|
+
wrap_parameters :format => [:json]
|
9
9
|
end
|
10
10
|
|
11
11
|
# Disable root element in JSON by default.
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
|
3
|
-
|
4
|
-
namespace :
|
3
|
+
namespace :admin, :path => ComfyBlog.config.admin_route_prefix do
|
4
|
+
namespace :blog do
|
5
5
|
resources :posts, :except => [:show] do
|
6
6
|
resources :comments, :only => [:index]
|
7
7
|
end
|
@@ -9,13 +9,13 @@ Rails.application.routes.draw do
|
|
9
9
|
put :publish, :on => :member
|
10
10
|
end
|
11
11
|
resources :tags, :except => [:show]
|
12
|
-
end
|
13
|
-
end
|
12
|
+
end
|
13
|
+
end unless ComfyBlog.config.admin_route_prefix.blank?
|
14
14
|
|
15
15
|
scope ComfyBlog.config.public_route_prefix, :module => :blog do
|
16
|
-
get '' => 'posts#index', :as => :blog_posts
|
17
|
-
get 'tag/:tag'
|
18
|
-
get 'category/:category'
|
16
|
+
get '/' => 'posts#index', :as => :blog_posts
|
17
|
+
get 'tag/:tag' => 'posts#index', :as => :tagged_blog_posts
|
18
|
+
get 'category/:category' => 'posts#index', :as => :categorized_blog_posts
|
19
19
|
|
20
20
|
with_options :constraints => { :year => /\d{4}/, :month => /\d{1,2}/ } do |o|
|
21
21
|
o.get ':year' => 'posts#index', :as => :year_blog_posts
|
@@ -23,6 +23,8 @@ Rails.application.routes.draw do
|
|
23
23
|
o.get ':year/:month/:slug' => 'posts#show', :as => :dated_blog_post
|
24
24
|
end
|
25
25
|
|
26
|
+
post ':post_id/comments' => 'comments#create', :as => :blog_post_comments
|
27
|
+
|
26
28
|
get ':id' => 'posts#show', :as => :blog_post
|
27
29
|
end
|
28
30
|
|
@@ -38,12 +38,11 @@ class CreateComfyBlog < ActiveRecord::Migration
|
|
38
38
|
add_index :blog_tags, :taggings_count
|
39
39
|
|
40
40
|
create_table :blog_taggings do |t|
|
41
|
-
t.integer :post_id,
|
42
|
-
t.integer :tag_id,
|
43
|
-
t.datetime :created_at
|
41
|
+
t.integer :post_id, :null => false
|
42
|
+
t.integer :tag_id, :null => false
|
44
43
|
end
|
45
|
-
add_index :blog_taggings, [:post_id, :tag_id
|
46
|
-
:name => '
|
44
|
+
add_index :blog_taggings, [:post_id, :tag_id], :unique => true,
|
45
|
+
:name => 'index_blog_taggings_on_post_tag'
|
47
46
|
end
|
48
47
|
|
49
48
|
def self.down
|
data/db/schema.rb
CHANGED
@@ -27,14 +27,14 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
27
27
|
add_index "blog_comments", ["post_id", "is_published", "created_at"], :name => "index_blog_comments_on_post_published_created"
|
28
28
|
|
29
29
|
create_table "blog_posts", :force => true do |t|
|
30
|
-
t.string "title",
|
31
|
-
t.string "slug",
|
30
|
+
t.string "title", :null => false
|
31
|
+
t.string "slug", :null => false
|
32
32
|
t.text "content"
|
33
33
|
t.string "excerpt", :limit => 1024
|
34
34
|
t.string "author"
|
35
|
-
t.integer "year", :limit => 4,
|
36
|
-
t.integer "month", :limit => 2,
|
37
|
-
t.boolean "is_published", :default =>
|
35
|
+
t.integer "year", :limit => 4, :null => false
|
36
|
+
t.integer "month", :limit => 2, :null => false
|
37
|
+
t.boolean "is_published", :default => true, :null => false
|
38
38
|
t.datetime "created_at"
|
39
39
|
t.datetime "updated_at"
|
40
40
|
end
|
@@ -44,12 +44,11 @@ ActiveRecord::Schema.define(:version => 1) do
|
|
44
44
|
add_index "blog_posts", ["is_published", "year", "month", "slug"], :name => "index_blog_posts_on_published_year_month_slug"
|
45
45
|
|
46
46
|
create_table "blog_taggings", :force => true do |t|
|
47
|
-
t.integer
|
48
|
-
t.integer
|
49
|
-
t.datetime "created_at"
|
47
|
+
t.integer "post_id", :null => false
|
48
|
+
t.integer "tag_id", :null => false
|
50
49
|
end
|
51
50
|
|
52
|
-
add_index "blog_taggings", ["post_id", "tag_id"
|
51
|
+
add_index "blog_taggings", ["post_id", "tag_id"], :name => "index_blog_taggings_on_post_tag", :unique => true
|
53
52
|
|
54
53
|
create_table "blog_tags", :force => true do |t|
|
55
54
|
t.string "name", :null => false
|
@@ -1,5 +1,12 @@
|
|
1
1
|
module ComfyBlog
|
2
2
|
class Configuration
|
3
|
+
|
4
|
+
# Title of your Blog
|
5
|
+
attr_accessor :title
|
6
|
+
|
7
|
+
# What is your blog all about
|
8
|
+
attr_accessor :description
|
9
|
+
|
3
10
|
# Default url to access admin area is http://yourhost/cms-admin/
|
4
11
|
# You can change 'cms-admin' to 'admin', for example.
|
5
12
|
attr_accessor :admin_route_prefix
|
@@ -20,14 +27,21 @@ module ComfyBlog
|
|
20
27
|
# Number of posts per page. Default is 10
|
21
28
|
attr_accessor :posts_per_page
|
22
29
|
|
30
|
+
# Comments can be automatically approved/published by changing this setting
|
31
|
+
# Default is false.
|
32
|
+
attr_accessor :auto_publish_comments
|
33
|
+
|
23
34
|
# Configuration defaults
|
24
35
|
def initialize
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@
|
28
|
-
@
|
29
|
-
@
|
30
|
-
@
|
36
|
+
@title = 'ComfyBlog'
|
37
|
+
@description = 'A Simple Blog'
|
38
|
+
@admin_route_prefix = 'admin'
|
39
|
+
@public_route_prefix = ''
|
40
|
+
@admin_controller = 'ApplicationController'
|
41
|
+
@form_builder = 'ComfyBlog::FormBuilder'
|
42
|
+
@public_layout = 'application'
|
43
|
+
@posts_per_page = 10
|
44
|
+
@auto_publish_comments = false
|
31
45
|
end
|
32
46
|
end
|
33
47
|
end
|
data/lib/comfy_blog/engine.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
require '
|
1
|
+
require 'comfy_blog'
|
2
2
|
require 'rails'
|
3
3
|
|
4
|
-
module
|
4
|
+
module ComfyBlog
|
5
5
|
class Engine < Rails::Engine
|
6
|
-
initializer '
|
6
|
+
initializer 'comfy_blog.configuration' do |app|
|
7
7
|
if defined?(ComfortableMexicanSofa)
|
8
8
|
# Applying configuraion
|
9
|
-
|
9
|
+
ComfyBlog.configure do |conf|
|
10
10
|
conf.admin_route_prefix = ComfortableMexicanSofa.config.admin_route_prefix
|
11
11
|
conf.admin_controller = 'CmsAdmin::BaseController'
|
12
12
|
conf.form_builder = 'ComfortableMexicanSofa::FormBuilder'
|
13
13
|
end
|
14
14
|
# Adding view hooks
|
15
|
-
ComfortableMexicanSofa::ViewHooks.add(:navigation, '/
|
16
|
-
ComfortableMexicanSofa::ViewHooks.add(:html_head, '/
|
15
|
+
ComfortableMexicanSofa::ViewHooks.add(:navigation, '/admin/blog/navigation')
|
16
|
+
ComfortableMexicanSofa::ViewHooks.add(:html_head, '/admin/blog/html_head')
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/comfy_blog.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Loading engine only if this is not a standalone installation
|
2
2
|
unless defined? ComfyBlog::Application
|
3
|
-
require File.expand_path('
|
3
|
+
require File.expand_path('comfy_blog/engine', File.dirname(__FILE__))
|
4
4
|
end
|
5
5
|
|
6
6
|
[ 'comfy_blog/core_ext/string',
|
data/lib/generators/README
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
____ __ ____ _
|
2
|
+
/ ___|___ _ __ ___ / _|_ _| __ )| | ___ __ _
|
3
|
+
| | / _ \| '_ ` _ \| |_| | | | _ \| |/ _ \ / _` |
|
4
|
+
| |__| (_) | | | | | | _| |_| | |_) | | (_) | (_| |
|
5
|
+
\____\___/|_| |_| |_|_| \__, |____/|_|\___/ \__, |
|
6
|
+
|___/ |___/
|
7
7
|
|
8
8
|
Hey! Everything is almost done. Please don't forget to
|
9
9
|
|
@@ -6,12 +6,12 @@ class BlogGenerator < Rails::Generators::Base
|
|
6
6
|
source_root File.expand_path('../../..', __FILE__)
|
7
7
|
|
8
8
|
def generate_migration
|
9
|
-
destination = File.expand_path('db/migrate/
|
9
|
+
destination = File.expand_path('db/migrate/01_create_comfy_blog.rb', self.destination_root)
|
10
10
|
migration_dir = File.dirname(destination)
|
11
|
-
destination = self.class.migration_exists?(migration_dir, '
|
11
|
+
destination = self.class.migration_exists?(migration_dir, 'create_comfy_blog')
|
12
12
|
|
13
13
|
if destination
|
14
|
-
puts "\e[0m\e[31mFound existing
|
14
|
+
puts "\e[0m\e[31mFound existing create_comfy_blog.rb migration. Remove it if you want to regenerate.\e[0m"
|
15
15
|
else
|
16
16
|
migration_template 'db/migrate/01_create_comfy_blog.rb', 'db/migrate/create_comfy_blog.rb'
|
17
17
|
end
|
data/test/fixtures/blog/tags.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../../../test_helper', File.dirname(__FILE__))
|
2
2
|
|
3
|
-
class Blog::
|
3
|
+
class Admin::Blog::PostsControllerTest < ActionController::TestCase
|
4
4
|
|
5
5
|
def test_get_index
|
6
6
|
get :index
|
@@ -21,7 +21,7 @@ class Blog::Admin::PostsControllerTest < ActionController::TestCase
|
|
21
21
|
assert_response :success
|
22
22
|
assert assigns(:post)
|
23
23
|
assert_template :new
|
24
|
-
assert_select "form[action='/admin/posts']"
|
24
|
+
assert_select "form[action='/admin/blog/posts']"
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_creation
|
@@ -30,9 +30,8 @@ class Blog::Admin::PostsControllerTest < ActionController::TestCase
|
|
30
30
|
:title => 'Test',
|
31
31
|
:content => 'Content'
|
32
32
|
}
|
33
|
-
assert_response :
|
34
|
-
|
35
|
-
assert assigns(:post)
|
33
|
+
assert_response :redirect
|
34
|
+
assert_redirected_to :action => :edit, :id => assigns(:post)
|
36
35
|
assert_equal 'Blog Post created', flash[:notice]
|
37
36
|
end
|
38
37
|
end
|
@@ -66,9 +65,8 @@ class Blog::Admin::PostsControllerTest < ActionController::TestCase
|
|
66
65
|
put :update, :id => post, :post => {
|
67
66
|
:title => 'Updated Post'
|
68
67
|
}
|
69
|
-
assert_response :
|
70
|
-
|
71
|
-
assert assigns(:post)
|
68
|
+
assert_response :redirect
|
69
|
+
assert_redirected_to :action => :edit, :id => assigns(:post)
|
72
70
|
assert_equal 'Blog Post updated', flash[:notice]
|
73
71
|
|
74
72
|
post.reload
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class Admin::Blog::TagsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_get_index
|
6
|
+
get :index
|
7
|
+
assert_response :success
|
8
|
+
assert_template :index
|
9
|
+
assert assigns(:tags)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_edit
|
13
|
+
get :edit, :id => blog_tags(:tag)
|
14
|
+
assert_response :success
|
15
|
+
assert_template :edit
|
16
|
+
assert assigns(:tag)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_new
|
20
|
+
get :new
|
21
|
+
assert_response :success
|
22
|
+
assert_template :new
|
23
|
+
assert assigns(:tag)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_update
|
27
|
+
tag = blog_tags(:tag)
|
28
|
+
assert_no_difference 'Blog::Tag.count' do
|
29
|
+
put :update, :id => tag, :tag => {
|
30
|
+
:name => 'Updated'
|
31
|
+
}
|
32
|
+
assert_response :redirect
|
33
|
+
assert_redirected_to :action => :index
|
34
|
+
|
35
|
+
tag.reload
|
36
|
+
assert_equal 'Updated', tag.name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_update_failure
|
41
|
+
tag = blog_tags(:tag)
|
42
|
+
assert_no_difference 'Blog::Tag.count' do
|
43
|
+
put :update, :id => tag, :tag => {
|
44
|
+
:name => 'Duplicate' # Notice case
|
45
|
+
}
|
46
|
+
assert_response :success
|
47
|
+
assert_template :edit
|
48
|
+
assert_equal 'Failed to update Blog Tag', flash[:error]
|
49
|
+
|
50
|
+
tag.reload
|
51
|
+
assert_equal 'tag', tag.name
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_creation
|
56
|
+
assert_difference 'Blog::Tag.count' do
|
57
|
+
post :create, :tag => {
|
58
|
+
:name => 'test'
|
59
|
+
}
|
60
|
+
assert_response :redirect
|
61
|
+
assert_redirected_to :action => :index
|
62
|
+
assert assigns(:tag).valid?
|
63
|
+
assert_equal 'Blog Tag created', flash[:notice]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_creation_failure
|
68
|
+
assert_no_difference 'Blog::Tag.count' do
|
69
|
+
post :create, :tag => {
|
70
|
+
:name => 'Duplicate' # Notice case
|
71
|
+
}
|
72
|
+
assert_response :success
|
73
|
+
assert_template :new
|
74
|
+
assert assigns(:tag).invalid?
|
75
|
+
assert_equal 'Failed to create Blog Tag', flash[:error]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_destroy
|
80
|
+
assert_difference 'Blog::Tag.count', -1 do
|
81
|
+
delete :destroy, :id => blog_tags(:tag)
|
82
|
+
assert_response :redirect
|
83
|
+
assert_redirected_to :action => :index
|
84
|
+
assert_equal 'Blog Tag removed', flash[:notice]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class Blog::CommentsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_creation
|
6
|
+
p = blog_posts(:default)
|
7
|
+
|
8
|
+
assert_difference 'Blog::Comment.count' do
|
9
|
+
post :create, :post_id => p, :comment => {
|
10
|
+
:author => 'Test',
|
11
|
+
:email => 'test@test.test',
|
12
|
+
:content => 'Test Content'
|
13
|
+
}
|
14
|
+
assert_response :redirect
|
15
|
+
assert_redirected_to dated_blog_post_path(p.year, p.month, p.slug)
|
16
|
+
assert_equal 'Comment created', flash[:notice]
|
17
|
+
|
18
|
+
comment = Blog::Comment.last
|
19
|
+
assert_equal 'Test', comment.author
|
20
|
+
assert_equal p, comment.post
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_creation_failure
|
25
|
+
p = blog_posts(:default)
|
26
|
+
|
27
|
+
assert_no_difference 'Blog::Comment.count' do
|
28
|
+
post :create, :post_id => p, :comment => { }
|
29
|
+
assert_response :success
|
30
|
+
assert_template :show
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_creation_failure_invalid_post
|
35
|
+
assert_no_difference 'Blog::Comment.count' do
|
36
|
+
post :create, :post_id => 'invalid', :comment => { }
|
37
|
+
assert_response :redirect
|
38
|
+
assert_redirected_to blog_posts_path
|
39
|
+
assert_equal 'Blog Post not found', flash[:error]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_creation_xhr
|
44
|
+
p = blog_posts(:default)
|
45
|
+
|
46
|
+
assert_difference 'Blog::Comment.count' do
|
47
|
+
xhr :post, :create, :post_id => p, :comment => {
|
48
|
+
:author => 'Test',
|
49
|
+
:email => 'test@test.test',
|
50
|
+
:content => 'Test Content'
|
51
|
+
}
|
52
|
+
assert_response :success
|
53
|
+
assert_template :create
|
54
|
+
|
55
|
+
comment = Blog::Comment.last
|
56
|
+
assert_equal 'Test', comment.author
|
57
|
+
assert_equal p, comment.post
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_creation_xhr_failure
|
62
|
+
p = blog_posts(:default)
|
63
|
+
|
64
|
+
assert_no_difference 'Blog::Comment.count' do
|
65
|
+
xhr :post, :create, :post_id => p, :comment => { }
|
66
|
+
assert_response :success
|
67
|
+
assert_template :create
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_creation_xhr_failure_invalid_post
|
72
|
+
assert_no_difference 'Blog::Comment.count' do
|
73
|
+
xhr :post, :create, :post_id => 'invalid', :comment => { }
|
74
|
+
assert_response 404
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -10,6 +10,14 @@ class Blog::PostsControllerTest < ActionController::TestCase
|
|
10
10
|
assert_equal 1, assigns(:posts).size
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_get_index_as_rss
|
14
|
+
get :index, :format => :rss
|
15
|
+
assert_response :success
|
16
|
+
assert_template :index
|
17
|
+
assert assigns(:posts)
|
18
|
+
assert_equal 1, assigns(:posts).size
|
19
|
+
end
|
20
|
+
|
13
21
|
def test_get_index_with_unpublished
|
14
22
|
blog_posts(:default).update_attribute(:is_published, false)
|
15
23
|
get :index
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class RoutingTest < ActionDispatch::IntegrationTest
|
4
|
+
|
5
|
+
def setup
|
6
|
+
reset_config
|
7
|
+
Rails.application.reload_routes!
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_admin_route_prefix
|
11
|
+
ComfyBlog.config.admin_route_prefix = 'custom-admin'
|
12
|
+
Rails.application.reload_routes!
|
13
|
+
|
14
|
+
get '/custom-admin/blog/posts'
|
15
|
+
assert_response :success
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_public_route_prefix
|
19
|
+
ComfyBlog.config.public_route_prefix = 'blog'
|
20
|
+
Rails.application.reload_routes!
|
21
|
+
|
22
|
+
get '/blog'
|
23
|
+
assert_response :success
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -14,12 +14,15 @@ class ActiveSupport::TestCase
|
|
14
14
|
# resetting default configuration
|
15
15
|
def reset_config
|
16
16
|
ComfyBlog.configure do |config|
|
17
|
-
config.
|
18
|
-
config.
|
19
|
-
config.
|
20
|
-
config.
|
21
|
-
config.
|
22
|
-
config.
|
17
|
+
config.title = 'ComfyBlog'
|
18
|
+
config.description = 'A Simple Blog'
|
19
|
+
config.admin_route_prefix = 'admin'
|
20
|
+
config.public_route_prefix = ''
|
21
|
+
config.admin_controller = 'ApplicationController'
|
22
|
+
config.form_builder = 'ComfyBlog::FormBuilder'
|
23
|
+
config.public_layout = 'application'
|
24
|
+
config.posts_per_page = 10
|
25
|
+
config.auto_publish_comments = false
|
23
26
|
end
|
24
27
|
end
|
25
28
|
|
data/test/unit/comment_test.rb
CHANGED
@@ -16,14 +16,26 @@ class CommentTest < ActiveSupport::TestCase
|
|
16
16
|
|
17
17
|
def test_creation
|
18
18
|
assert_difference 'Blog::Comment.count' do
|
19
|
-
blog_posts(:default).comments.create(
|
19
|
+
comment = blog_posts(:default).comments.create(
|
20
20
|
:content => 'Test Content',
|
21
21
|
:author => 'Tester',
|
22
22
|
:email => 'test@test.test'
|
23
23
|
)
|
24
|
+
assert !comment.is_published?
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
28
|
+
def test_creation_with_auto_publishing
|
29
|
+
ComfyBlog.config.auto_publish_comments = true
|
30
|
+
|
31
|
+
comment = blog_posts(:default).comments.create(
|
32
|
+
:content => 'Test Content',
|
33
|
+
:author => 'Tester',
|
34
|
+
:email => 'test@test.test'
|
35
|
+
)
|
36
|
+
assert comment.is_published?
|
37
|
+
end
|
38
|
+
|
27
39
|
def test_scope_published
|
28
40
|
assert_equal 1, Blog::Comment.published.count
|
29
41
|
|