comfy_blog 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -0
- data/LICENSE +20 -0
- data/README.md +23 -0
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/app/assets/images/rails.png +0 -0
- data/app/assets/javascripts/application.js +8 -0
- data/app/assets/stylesheets/comfy_blog/admin.css +57 -0
- data/app/assets/stylesheets/comfy_blog/application.css +73 -0
- data/app/assets/stylesheets/comfy_blog/reset.css +1 -0
- data/app/controllers/application_controller.rb +5 -0
- data/app/controllers/blog/admin/base_controller.rb +3 -0
- data/app/controllers/blog/admin/comments_controller.rb +34 -0
- data/app/controllers/blog/admin/posts_controller.rb +57 -0
- data/app/controllers/blog/posts_controller.rb +33 -0
- data/app/helpers/blog/application_helper.rb +16 -0
- data/app/models/.gitkeep +0 -0
- data/app/models/blog/comment.rb +21 -0
- data/app/models/blog/post.rb +81 -0
- data/app/models/blog/tag.rb +25 -0
- data/app/models/blog/tagging.rb +22 -0
- data/app/views/blog/admin/_html_head.html.erb +1 -0
- data/app/views/blog/admin/_navigation.html.erb +1 -0
- data/app/views/blog/admin/comments/_comment.html.erb +22 -0
- data/app/views/blog/admin/comments/destroy.js.erb +3 -0
- data/app/views/blog/admin/comments/index.html.erb +10 -0
- data/app/views/blog/admin/comments/publish.js.erb +1 -0
- data/app/views/blog/admin/posts/_form.html.erb +24 -0
- data/app/views/blog/admin/posts/_post.html.erb +21 -0
- data/app/views/blog/admin/posts/edit.html.erb +5 -0
- data/app/views/blog/admin/posts/index.html.erb +9 -0
- data/app/views/blog/admin/posts/new.html.erb +5 -0
- data/app/views/blog/posts/_post.html.erb +18 -0
- data/app/views/blog/posts/index.html.erb +5 -0
- data/app/views/blog/posts/show.html.erb +1 -0
- data/app/views/layouts/application.html.erb +17 -0
- data/comfy_blog.gemspec +125 -0
- data/config.ru +4 -0
- data/config/application.rb +48 -0
- data/config/boot.rb +6 -0
- data/config/database.yml +25 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +33 -0
- data/config/environments/production.rb +51 -0
- data/config/environments/test.rb +42 -0
- data/config/initializers/comfy_blog.rb +18 -0
- data/config/initializers/secret_token.rb +3 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +29 -0
- data/db/migrate/01_create_comfy_blog.rb +55 -0
- data/db/schema.rb +63 -0
- data/db/seeds.rb +7 -0
- data/lib/comfy_blog.rb +26 -0
- data/lib/comfy_blog/configuration.rb +33 -0
- data/lib/comfy_blog/core_ext/string.rb +8 -0
- data/lib/comfy_blog/engine.rb +20 -0
- data/lib/comfy_blog/form_builder.rb +50 -0
- data/lib/generators/README +10 -0
- data/lib/generators/blog_generator.rb +31 -0
- data/script/rails +6 -0
- data/test/fixtures/.gitkeep +0 -0
- data/test/fixtures/blog/comments.yml +6 -0
- data/test/fixtures/blog/posts.yml +8 -0
- data/test/fixtures/blog/taggings.yml +7 -0
- data/test/fixtures/blog/tags.yml +9 -0
- data/test/functional/.gitkeep +0 -0
- data/test/functional/blog/admin/comments_controller_test.rb +38 -0
- data/test/functional/blog/admin/posts_controller_test.rb +100 -0
- data/test/functional/blog/posts_controller_test.rb +93 -0
- data/test/test_helper.rb +40 -0
- data/test/unit/.gitkeep +0 -0
- data/test/unit/comment_test.rb +34 -0
- data/test/unit/configuration_test.rb +19 -0
- data/test/unit/post_test.rb +121 -0
- data/test/unit/tag_test.rb +44 -0
- data/test/unit/tagging_test.rb +30 -0
- metadata +172 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
____ __ ____ _
|
2
|
+
/ ___| ___ / _| __ _ | __ )| | ___ __ _
|
3
|
+
\___ \ / _ \| |_ / _` | | _ \| |/ _ \ / _` |
|
4
|
+
___) | (_) | _| (_| | | |_) | | (_) | (_| |
|
5
|
+
|____/ \___/|_| \__,_| |____/|_|\___/ \__, |
|
6
|
+
|___/
|
7
|
+
|
8
|
+
Hey! Everything is almost done. Please don't forget to
|
9
|
+
|
10
|
+
* run migrations -> `rake db:migrate`
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class BlogGenerator < Rails::Generators::Base
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
include Rails::Generators::Migration
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
source_root File.expand_path('../../..', __FILE__)
|
7
|
+
|
8
|
+
def generate_migration
|
9
|
+
destination = File.expand_path('db/migrate/01_create_sofa_blog.rb', self.destination_root)
|
10
|
+
migration_dir = File.dirname(destination)
|
11
|
+
destination = self.class.migration_exists?(migration_dir, 'create_sofa_blog')
|
12
|
+
|
13
|
+
if destination
|
14
|
+
puts "\e[0m\e[31mFound existing create_sofa_blog.rb migration. Remove it if you want to regenerate.\e[0m"
|
15
|
+
else
|
16
|
+
migration_template 'db/migrate/01_create_comfy_blog.rb', 'db/migrate/create_comfy_blog.rb'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate_initialization
|
21
|
+
copy_file 'config/initializers/comfy_blog.rb', 'config/initializers/comfy_blog.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
def show_readme
|
25
|
+
readme 'lib/generators/README'
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.next_migration_number(dirname)
|
29
|
+
ActiveRecord::Generators::Base.next_migration_number(dirname)
|
30
|
+
end
|
31
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
+
require File.expand_path('../../config/boot', __FILE__)
|
6
|
+
require 'rails/commands'
|
File without changes
|
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class Blog::Admin::CommentsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_get_index
|
6
|
+
get :index
|
7
|
+
assert_response :success
|
8
|
+
assert_template :index
|
9
|
+
assert assigns(:comments)
|
10
|
+
assert !assigns(:post)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_index_for_post
|
14
|
+
get :index, :post_id => blog_posts(:default)
|
15
|
+
assert_response :success
|
16
|
+
assert_template :index
|
17
|
+
assert assigns(:post)
|
18
|
+
assert assigns(:comments)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_publish
|
22
|
+
comment = blog_comments(:default)
|
23
|
+
comment.update_attribute(:is_published, false)
|
24
|
+
xhr :put, :publish, :id => comment
|
25
|
+
assert_response :success
|
26
|
+
|
27
|
+
comment.reload
|
28
|
+
assert comment.is_published
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_destroy
|
32
|
+
assert_difference 'Blog::Comment.count', -1 do
|
33
|
+
xhr :delete, :destroy, :id => blog_comments(:default)
|
34
|
+
assert_response :success
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class Blog::Admin::PostsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_get_index
|
6
|
+
get :index
|
7
|
+
assert_response :success
|
8
|
+
assert assigns(:posts)
|
9
|
+
assert_template :index
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_index_with_pagination
|
13
|
+
get :index, :page => 99
|
14
|
+
assert_response :success
|
15
|
+
assert assigns(:posts)
|
16
|
+
assert_equal 0, assigns(:posts).size
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_get_new
|
20
|
+
get :new
|
21
|
+
assert_response :success
|
22
|
+
assert assigns(:post)
|
23
|
+
assert_template :new
|
24
|
+
assert_select "form[action='/admin/posts']"
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_creation
|
28
|
+
assert_difference 'Blog::Post.count' do
|
29
|
+
post :create, :post => {
|
30
|
+
:title => 'Test',
|
31
|
+
:content => 'Content'
|
32
|
+
}
|
33
|
+
assert_response :success
|
34
|
+
assert_template :new
|
35
|
+
assert assigns(:post)
|
36
|
+
assert_equal 'Blog Post created', flash[:notice]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_creation_failure
|
41
|
+
assert_no_difference 'Blog::Post.count' do
|
42
|
+
post :create, :post => { }
|
43
|
+
assert_response :success
|
44
|
+
assert_template :new
|
45
|
+
assert assigns(:post)
|
46
|
+
assert_equal 'Failed to create Blog Post', flash[:error]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_get_edit
|
51
|
+
get :edit, :id => blog_posts(:default)
|
52
|
+
assert_response :success
|
53
|
+
assert_template :edit
|
54
|
+
assert assigns(:post)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_get_edit_failure
|
58
|
+
get :edit, :id => 'bogus'
|
59
|
+
assert_response :redirect
|
60
|
+
assert_redirected_to :action => :index
|
61
|
+
assert_equal 'Blog Post not found', flash[:error]
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_update
|
65
|
+
post = blog_posts(:default)
|
66
|
+
put :update, :id => post, :post => {
|
67
|
+
:title => 'Updated Post'
|
68
|
+
}
|
69
|
+
assert_response :success
|
70
|
+
assert_template :edit
|
71
|
+
assert assigns(:post)
|
72
|
+
assert_equal 'Blog Post updated', flash[:notice]
|
73
|
+
|
74
|
+
post.reload
|
75
|
+
assert_equal 'Updated Post', post.title
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_update_failure
|
79
|
+
post = blog_posts(:default)
|
80
|
+
put :update, :id => post, :post => {
|
81
|
+
:title => ''
|
82
|
+
}
|
83
|
+
assert_response :success
|
84
|
+
assert_template :edit
|
85
|
+
assert_equal 'Failed to update Blog Post', flash[:error]
|
86
|
+
|
87
|
+
post.reload
|
88
|
+
assert_not_equal '', post.title
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_destroy
|
92
|
+
assert_difference 'Blog::Post.count', -1 do
|
93
|
+
delete :destroy, :id => blog_posts(:default)
|
94
|
+
assert_response :redirect
|
95
|
+
assert_redirected_to :action => :index
|
96
|
+
assert_equal 'Blog Post removed', flash[:notice]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class Blog::PostsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_get_index
|
6
|
+
get :index
|
7
|
+
assert_response :success
|
8
|
+
assert_template :index
|
9
|
+
assert assigns(:posts)
|
10
|
+
assert_equal 1, assigns(:posts).size
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_index_with_unpublished
|
14
|
+
blog_posts(:default).update_attribute(:is_published, false)
|
15
|
+
get :index
|
16
|
+
assert_response :success
|
17
|
+
assert_equal 0, assigns(:posts).size
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_get_index_with_pagination
|
21
|
+
get :index, :page => 99
|
22
|
+
assert_response :success
|
23
|
+
assert_equal 0, assigns(:posts).size
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_get_index_for_tagged
|
27
|
+
get :index, :tag => blog_tags(:tag).name
|
28
|
+
assert_response :success
|
29
|
+
assert_equal 1, assigns(:posts).size
|
30
|
+
|
31
|
+
get :index, :tag => 'invalid'
|
32
|
+
assert_response :success
|
33
|
+
assert_equal 0, assigns(:posts).size
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_index_for_categorized
|
37
|
+
get :index, :category => blog_tags(:category).name
|
38
|
+
assert_response :success
|
39
|
+
assert_equal 1, assigns(:posts).size
|
40
|
+
|
41
|
+
get :index, :category => 'invalid'
|
42
|
+
assert_response :success
|
43
|
+
assert_equal 0, assigns(:posts).size
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_get_index_for_year_archive
|
47
|
+
get :index, :year => 2012
|
48
|
+
assert_response :success
|
49
|
+
assert_equal 1, assigns(:posts).size
|
50
|
+
|
51
|
+
get :index, :year => 1999
|
52
|
+
assert_response :success
|
53
|
+
assert_equal 0, assigns(:posts).size
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_get_index_for_month_archive
|
57
|
+
get :index, :year => 2012, :month => 1
|
58
|
+
assert_response :success
|
59
|
+
assert_equal 1, assigns(:posts).size
|
60
|
+
|
61
|
+
get :index, :year => 2012, :month => 12
|
62
|
+
assert_response :success
|
63
|
+
assert_equal 0, assigns(:posts).size
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_get_show
|
67
|
+
get :show, :id => blog_posts(:default)
|
68
|
+
assert_response :success
|
69
|
+
assert_template :show
|
70
|
+
assert assigns(:post)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_get_show_unpublished
|
74
|
+
post = blog_posts(:default)
|
75
|
+
post.update_attribute(:is_published, false)
|
76
|
+
get :show, :id => post
|
77
|
+
assert_response 404
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_get_show_with_date
|
81
|
+
post = blog_posts(:default)
|
82
|
+
get :show, :year => post.year, :month => post.month, :slug => blog_posts(:default).slug
|
83
|
+
assert_response :success
|
84
|
+
assert_template :show
|
85
|
+
assert assigns(:post)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_get_show_with_date_invalid
|
89
|
+
get :show, :year => '1999', :month => '99', :slug => 'invalid'
|
90
|
+
assert_response 404
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require File.expand_path('../../config/environment', __FILE__)
|
3
|
+
require 'rails/test_help'
|
4
|
+
|
5
|
+
class ActiveSupport::TestCase
|
6
|
+
|
7
|
+
fixtures :all
|
8
|
+
include ActionDispatch::TestProcess
|
9
|
+
|
10
|
+
def setup
|
11
|
+
reset_config
|
12
|
+
end
|
13
|
+
|
14
|
+
# resetting default configuration
|
15
|
+
def reset_config
|
16
|
+
ComfyBlog.configure do |config|
|
17
|
+
config.admin_route_prefix = 'admin'
|
18
|
+
config.public_route_prefix = ''
|
19
|
+
config.admin_controller = 'ApplicationController'
|
20
|
+
config.form_builder = 'ActionView::Helpers::FormBuilder'
|
21
|
+
config.public_layout = 'application'
|
22
|
+
config.posts_per_page = 10
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Example usage:
|
27
|
+
# assert_has_errors_on( @record, [:field_1, :field_2] )
|
28
|
+
# assert_has_errors_on( @record, {:field_1 => 'Message1', :field_2 => 'Message 2'} )
|
29
|
+
def assert_has_errors_on(record, fields)
|
30
|
+
fields = [fields].flatten unless fields.is_a?(Hash)
|
31
|
+
fields.each do |field, message|
|
32
|
+
assert record.errors.to_hash.has_key?(field.to_sym), "#{record.class.name} should error on invalid #{field}"
|
33
|
+
if message && record.errors[field].is_a?(Array) && !message.is_a?(Array)
|
34
|
+
assert_not_nil record.errors[field].index(message)
|
35
|
+
elsif message
|
36
|
+
assert_equal message, record.errors[field]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/test/unit/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class CommentTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_fixtures_validity
|
6
|
+
Blog::Comment.all.each do |comment|
|
7
|
+
assert comment.valid?, comment.errors.full_messages.to_s
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_validations
|
12
|
+
comment = Blog::Comment.new
|
13
|
+
assert comment.invalid?
|
14
|
+
assert_has_errors_on comment, [:post_id, :content, :author, :email]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_creation
|
18
|
+
assert_difference 'Blog::Comment.count' do
|
19
|
+
blog_posts(:default).comments.create(
|
20
|
+
:content => 'Test Content',
|
21
|
+
:author => 'Tester',
|
22
|
+
:email => 'test@test.test'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_scope_published
|
28
|
+
assert_equal 1, Blog::Comment.published.count
|
29
|
+
|
30
|
+
blog_comments(:default).update_attribute(:is_published, false)
|
31
|
+
assert_equal 0, Blog::Comment.published.count
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class ConfigurationTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_configuration
|
6
|
+
assert config = ComfyBlog.configuration
|
7
|
+
assert_equal 'admin', config.admin_route_prefix
|
8
|
+
assert_equal '', config.public_route_prefix
|
9
|
+
assert_equal 'ApplicationController', config.admin_controller
|
10
|
+
assert_equal 'ActionView::Helpers::FormBuilder', config.form_builder
|
11
|
+
assert_equal 10, config.posts_per_page
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_initialization_overrides
|
15
|
+
ComfyBlog.config.admin_route_prefix = 'new-admin'
|
16
|
+
assert_equal 'new-admin', ComfyBlog.config.admin_route_prefix
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class PostTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
def test_fixtures_validity
|
6
|
+
Blog::Post.all.each do |post|
|
7
|
+
assert post.valid?, post.errors.full_messages.to_s
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_validation
|
12
|
+
post = Blog::Post.new
|
13
|
+
assert post.invalid?
|
14
|
+
assert_has_errors_on post, [:title, :slug, :content]
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_validation_of_slug_uniqueness
|
18
|
+
old_post = blog_posts(:default)
|
19
|
+
old_post.update_attributes!(:year => Time.now.year, :month => Time.now.month)
|
20
|
+
post = Blog::Post.new(:title => old_post.title, :content => 'Test Content')
|
21
|
+
assert post.invalid?
|
22
|
+
assert_has_errors_on post, [:slug]
|
23
|
+
|
24
|
+
old_post.update_attributes!(:year => 1.year.ago.year, :month => Time.now.month)
|
25
|
+
assert post.valid?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_creation
|
29
|
+
assert_difference 'Blog::Post.count' do
|
30
|
+
post = Blog::Post.create!(
|
31
|
+
:title => 'Test Post',
|
32
|
+
:content => 'Test Content'
|
33
|
+
)
|
34
|
+
assert_equal 'test-post', post.slug
|
35
|
+
assert_equal Time.now.year, post.year
|
36
|
+
assert_equal Time.now.month, post.month
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_set_slug
|
41
|
+
post = Blog::Post.new(:title => 'Test Title')
|
42
|
+
post.send(:set_slug)
|
43
|
+
assert_equal 'test-title', post.slug
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_set_date
|
47
|
+
post = Blog::Post.new
|
48
|
+
post.send(:set_date)
|
49
|
+
assert_equal Time.now.year, post.year
|
50
|
+
assert_equal Time.now.month, post.month
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_sync_tags
|
54
|
+
post = blog_posts(:default)
|
55
|
+
assert_equal 'tag', post.tag_names
|
56
|
+
|
57
|
+
post.tag_names = 'one, two, three'
|
58
|
+
assert_equal 'one, two, three', post.tag_names
|
59
|
+
|
60
|
+
assert_difference ['Blog::Tag.count', 'Blog::Tagging.count'], 2 do
|
61
|
+
post.save!
|
62
|
+
post.reload
|
63
|
+
assert_equal 'one, two, three', post.tag_names
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_sync_categories
|
68
|
+
post = blog_posts(:default)
|
69
|
+
assert_equal 1, post.tags.categories.count
|
70
|
+
|
71
|
+
assert_difference 'Blog::Tagging.count', -1 do
|
72
|
+
post.update_attribute(:category_ids, blog_tags(:category).id => 0)
|
73
|
+
post.reload
|
74
|
+
assert_equal 0, post.tags.categories.count
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_difference 'Blog::Tagging.count' do
|
78
|
+
post.update_attribute(:category_ids, blog_tags(:category).id => 1)
|
79
|
+
post.reload
|
80
|
+
assert_equal 1, post.tags.categories.count
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_destroy
|
85
|
+
assert_difference ['Blog::Post.count', 'Blog::Comment.count'], -1 do
|
86
|
+
blog_posts(:default).destroy
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_scope_published
|
91
|
+
post = blog_posts(:default)
|
92
|
+
assert post.is_published?
|
93
|
+
assert_equal 1, Blog::Post.published.count
|
94
|
+
|
95
|
+
post.update_attribute(:is_published, false)
|
96
|
+
assert_equal 0, Blog::Post.published.count
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_scope_for_year
|
100
|
+
assert_equal 1, Blog::Post.for_year(2012).count
|
101
|
+
assert_equal 0, Blog::Post.for_year(2013).count
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_scope_for_month
|
105
|
+
assert_equal 1, Blog::Post.for_month(1).count
|
106
|
+
assert_equal 0, Blog::Post.for_month(2).count
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_scope_tagged_with
|
110
|
+
assert_equal 1, Blog::Post.tagged_with('tag').count
|
111
|
+
assert_equal 0, Blog::Post.tagged_with('category').count
|
112
|
+
assert_equal 0, Blog::Post.tagged_with('invalid').count
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_scope_categorized_as
|
116
|
+
assert_equal 1, Blog::Post.categorized_as('category').count
|
117
|
+
assert_equal 0, Blog::Post.categorized_as('tag').count
|
118
|
+
assert_equal 0, Blog::Post.categorized_as('invalid').count
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|