adva_blog 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/adva_blog.gemspec +17 -0
- data/app/controllers/admin/blog/articles_controller.rb +5 -0
- data/app/controllers/admin/blog/categories_controller.rb +1 -0
- data/app/controllers/admin/blog/contents_controller.rb +5 -0
- data/app/controllers/admin/blogs_controller.rb +1 -0
- data/app/controllers/blog_articles_controller.rb +23 -0
- data/app/helpers/blog_helper.rb +49 -0
- data/app/models/blog.rb +34 -0
- data/app/views/admin/blog/articles/index.html.erb +40 -0
- data/app/views/admin/sections/settings/_blog.html.erb +11 -0
- data/app/views/blogs/articles/_article.html.erb +28 -0
- data/app/views/blogs/articles/_footer.html.erb +40 -0
- data/app/views/blogs/articles/index.atom.builder +21 -0
- data/app/views/blogs/articles/index.html.erb +4 -0
- data/app/views/blogs/articles/show.html.erb +14 -0
- data/config/initializers/base_controller.rb +3 -0
- data/config/routes.rb +49 -0
- data/lib/adva_blog.rb +10 -0
- data/lib/adva_blog/version.rb +3 -0
- data/test/contexts.rb +9 -0
- data/test/fixtures.rb +50 -0
- data/test/functional/blog_articles_controller_test.rb +139 -0
- data/test/functional/blog_articles_routes_test.rb +159 -0
- data/test/integration/admin/blog_article_test.rb +54 -0
- data/test/integration/admin/blog_ping_test.rb +68 -0
- data/test/integration/admin/blog_test.rb +43 -0
- data/test/integration/blog_article_test.rb +40 -0
- data/test/integration/blog_categories_test.rb +55 -0
- data/test/integration/blog_comment_test.rb +51 -0
- data/test/integration/blog_index_test.rb +104 -0
- data/test/test_helper.rb +2 -0
- data/test/unit/cells/blog_cell_test.rb +29 -0
- data/test/unit/helpers/blog_helper_test.rb +50 -0
- data/test/unit/helpers/content_helper_test.rb +19 -0
- data/test/unit/models/blog_test.rb +37 -0
- data/test/unit/models/counter_test.rb +44 -0
- metadata +101 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper' )
|
2
|
+
|
3
|
+
module IntegrationTests
|
4
|
+
class AdminBlogTest < ActionController::IntegrationTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@section = Blog.first
|
8
|
+
@site = @section.site
|
9
|
+
use_site! @site
|
10
|
+
end
|
11
|
+
|
12
|
+
test "Admin creates a blog, changes settings and deletes it" do
|
13
|
+
login_as_admin
|
14
|
+
visit "/admin/sites/#{@site.id}"
|
15
|
+
create_a_new_section
|
16
|
+
revise_the_section_settings
|
17
|
+
delete_the_section
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_a_new_section
|
21
|
+
click_link 'Sections'
|
22
|
+
click_link 'New'
|
23
|
+
fill_in 'title', :with => 'the blog'
|
24
|
+
select 'Blog'
|
25
|
+
click_button 'Save'
|
26
|
+
|
27
|
+
assert @site.sections.last.is_a?(Blog)
|
28
|
+
request.url.should =~ %r(/admin/sites/\d+/sections/\d+/articles)
|
29
|
+
end
|
30
|
+
|
31
|
+
def revise_the_section_settings
|
32
|
+
click_link_within '#main_menu', 'Settings'
|
33
|
+
fill_in 'title', :with => 'the uberblog'
|
34
|
+
click_button 'Save'
|
35
|
+
request.url.should =~ %r(/admin/sites/\d+/sections/\d+/edit)
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete_the_section
|
39
|
+
click_link 'Delete'
|
40
|
+
request.url.should =~ %r(/admin/sites/\d+/sections/new)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
2
|
+
|
3
|
+
module IntegrationTests
|
4
|
+
class BlogArticleTest < ActionController::IntegrationTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@site = use_site! 'site with blog'
|
8
|
+
|
9
|
+
@published_article = Article.find_by_title 'a blog article'
|
10
|
+
@unpublished_article = Article.find_by_title 'an unpublished blog article'
|
11
|
+
|
12
|
+
stub(Time).now.returns Time.utc(2008, 1, 2)
|
13
|
+
end
|
14
|
+
|
15
|
+
test "User clicks through blog frontend blog article show pages" do
|
16
|
+
visits_published_article_page
|
17
|
+
visits_unpublished_article_page_as_anonymous
|
18
|
+
visits_unpublished_article_page_as_admin
|
19
|
+
end
|
20
|
+
|
21
|
+
def visits_published_article_page
|
22
|
+
get '/2008/1/1/a-blog-article'
|
23
|
+
renders_template "blogs/articles/show"
|
24
|
+
displays_article @published_article
|
25
|
+
displays_comments @published_article.approved_comments
|
26
|
+
end
|
27
|
+
|
28
|
+
def visits_unpublished_article_page_as_anonymous
|
29
|
+
get '/2008/1/1/an-unpublished-blog-article'
|
30
|
+
assert_status 404
|
31
|
+
end
|
32
|
+
|
33
|
+
def visits_unpublished_article_page_as_admin
|
34
|
+
login_as_superuser
|
35
|
+
get '/2008/1/1/an-unpublished-blog-article'
|
36
|
+
renders_template "blogs/articles/show"
|
37
|
+
displays_article @unpublished_article
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper' )
|
2
|
+
|
3
|
+
module IntegrationTests
|
4
|
+
class BlogCategoriesTest < ActionController::IntegrationTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@section = Blog.first
|
8
|
+
@site = @section.site
|
9
|
+
use_site! @site
|
10
|
+
@special_characters_category = @section.categories.find_by_title('$%&')
|
11
|
+
@non_ascii_category = @section.categories.find_by_title('öäü')
|
12
|
+
@section.categories.build(:title => 'uk').save
|
13
|
+
@section.categories.build(:title => 'london').save
|
14
|
+
@london = @section.categories.find_by_title('london')
|
15
|
+
@uk = @section.categories.find_by_title('uk')
|
16
|
+
@london.move_to_child_of(@uk)
|
17
|
+
@section.categories.update_paths!
|
18
|
+
end
|
19
|
+
|
20
|
+
test "user views categories of a blog that has nested categories" do
|
21
|
+
login_as_user
|
22
|
+
visit_blog_index
|
23
|
+
|
24
|
+
if default_theme?
|
25
|
+
visit_category(@uk)
|
26
|
+
visit_category(@london)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
test "category with special characters permalink is accessible" do
|
31
|
+
login_as_user
|
32
|
+
visit_blog_index
|
33
|
+
|
34
|
+
visit_category(@non_ascii_category) if default_theme?
|
35
|
+
end
|
36
|
+
|
37
|
+
# FIXME categories does not work with characters like $%&
|
38
|
+
# test "category with special characters permalink is accessible" do
|
39
|
+
# login_as_user
|
40
|
+
# visit_blog_index
|
41
|
+
# visit_category(@special_characters_category)
|
42
|
+
# end
|
43
|
+
|
44
|
+
def visit_blog_index
|
45
|
+
visit blog_path(@section)
|
46
|
+
assert_template 'blogs/articles/index'
|
47
|
+
end
|
48
|
+
|
49
|
+
def visit_category(category)
|
50
|
+
click_link category.title
|
51
|
+
assert_template 'blogs/articles/index'
|
52
|
+
assert_select 'h2.list_header', "Articles about #{category.title}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
2
|
+
|
3
|
+
module IntegrationTests
|
4
|
+
class BlogCommentTest < ActionController::IntegrationTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@site = use_site! 'site with blog'
|
8
|
+
@site.update_attributes! :permissions => { 'create comment' => 'anonymous' }
|
9
|
+
@published_article = Article.find_by_title 'a blog article'
|
10
|
+
end
|
11
|
+
|
12
|
+
# FIXME test edit/delete comment
|
13
|
+
# http://artweb-design.lighthouseapp.com/projects/13992/tickets/215
|
14
|
+
test "An anonymous user posts a comment to a blog article" do
|
15
|
+
post_a_blog_comment_as_anonymous
|
16
|
+
view_submitted_comment
|
17
|
+
go_back_to_article
|
18
|
+
end
|
19
|
+
|
20
|
+
test "A registered user posts a comment to a blog article" do
|
21
|
+
login_as_user
|
22
|
+
post_a_blog_comment_as_user
|
23
|
+
view_submitted_comment
|
24
|
+
go_back_to_article
|
25
|
+
end
|
26
|
+
|
27
|
+
def post_a_blog_comment_as_anonymous
|
28
|
+
visit '/2008/1/1/a-blog-article'
|
29
|
+
fill_in "user_name", :with => "John Doe"
|
30
|
+
fill_in "user_email", :with => "john@example.com"
|
31
|
+
fill_in "comment_body", :with => "What a nice article!"
|
32
|
+
click_button "Submit comment"
|
33
|
+
end
|
34
|
+
|
35
|
+
def post_a_blog_comment_as_user
|
36
|
+
visit '/2008/1/1/a-blog-article'
|
37
|
+
fill_in "comment_body", :with => "What a nice article!"
|
38
|
+
click_button "Submit comment"
|
39
|
+
end
|
40
|
+
|
41
|
+
def view_submitted_comment
|
42
|
+
request.url.should =~ %r(#{@site.host}/comments/\d+)
|
43
|
+
has_tag ".comment", /What a nice article!/
|
44
|
+
end
|
45
|
+
|
46
|
+
def go_back_to_article
|
47
|
+
click_link 'a blog article'
|
48
|
+
request.url.should == controller.show_url(Article.find_by_permalink('a-blog-article'))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper' ))
|
2
|
+
|
3
|
+
module IntegrationTests
|
4
|
+
class BlogIndexTest < ActionController::IntegrationTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@site = use_site! 'site with blog'
|
8
|
+
|
9
|
+
@published_article = Article.find_by_title 'a blog article'
|
10
|
+
@unpublished_article = Article.find_by_title 'an unpublished blog article'
|
11
|
+
|
12
|
+
@category = Category.find_by_title 'a blog category'
|
13
|
+
@another_category = Category.find_by_title 'another blog category'
|
14
|
+
end
|
15
|
+
|
16
|
+
test "User clicks through blog frontend blog index pages" do
|
17
|
+
visits_blog_index
|
18
|
+
|
19
|
+
visits_blog_category_index
|
20
|
+
visits_empty_blog_category_index
|
21
|
+
|
22
|
+
visits_blog_tag_index
|
23
|
+
visits_missing_blog_tag_index
|
24
|
+
|
25
|
+
visits_blog_this_years_archive_index
|
26
|
+
visits_blog_last_years_archive_index
|
27
|
+
|
28
|
+
visits_blog_this_months_archive_index
|
29
|
+
visits_blog_last_months_archive_index
|
30
|
+
end
|
31
|
+
|
32
|
+
def visits_blog_index
|
33
|
+
get "/"
|
34
|
+
|
35
|
+
renders_template "blogs/articles/index"
|
36
|
+
displays_article @published_article
|
37
|
+
does_not_display_article @unpublished_article
|
38
|
+
end
|
39
|
+
|
40
|
+
def visits_blog_category_index
|
41
|
+
get 'categories/a-category'
|
42
|
+
# click_link 'a category'
|
43
|
+
|
44
|
+
renders_template "blogs/articles/index"
|
45
|
+
displays_article @published_article
|
46
|
+
does_not_display_article @unpublished_article
|
47
|
+
end
|
48
|
+
|
49
|
+
def visits_empty_blog_category_index
|
50
|
+
get 'categories/another-category'
|
51
|
+
# click_link 'another category' # FIXME webrat seems to be confused about the current session
|
52
|
+
|
53
|
+
renders_template "blogs/articles/index"
|
54
|
+
does_not_display_article @published_article
|
55
|
+
does_not_display_article @unpublished_article
|
56
|
+
end
|
57
|
+
|
58
|
+
def visits_blog_tag_index
|
59
|
+
get "/tags/foo"
|
60
|
+
|
61
|
+
renders_template "blogs/articles/index"
|
62
|
+
displays_article @published_article
|
63
|
+
does_not_display_article @unpublished_article
|
64
|
+
end
|
65
|
+
|
66
|
+
def visits_missing_blog_tag_index
|
67
|
+
get "/tags/does-not-exist"
|
68
|
+
|
69
|
+
assert_status 404
|
70
|
+
end
|
71
|
+
|
72
|
+
def visits_blog_this_years_archive_index
|
73
|
+
get "/2008"
|
74
|
+
|
75
|
+
renders_template "blogs/articles/index"
|
76
|
+
displays_article @published_article
|
77
|
+
does_not_display_article @unpublished_article
|
78
|
+
end
|
79
|
+
|
80
|
+
def visits_blog_last_years_archive_index
|
81
|
+
get "/2007"
|
82
|
+
|
83
|
+
renders_template "blogs/articles/index"
|
84
|
+
does_not_display_article @published_article
|
85
|
+
does_not_display_article @unpublished_article
|
86
|
+
end
|
87
|
+
|
88
|
+
def visits_blog_this_months_archive_index
|
89
|
+
get "/2008/1"
|
90
|
+
|
91
|
+
renders_template "blogs/articles/index"
|
92
|
+
displays_article @published_article
|
93
|
+
does_not_display_article @unpublished_article
|
94
|
+
end
|
95
|
+
|
96
|
+
def visits_blog_last_months_archive_index
|
97
|
+
get "/2007/12"
|
98
|
+
|
99
|
+
renders_template "blogs/articles/index"
|
100
|
+
does_not_display_article @published_article
|
101
|
+
does_not_display_article @unpublished_article
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
#
|
3
|
+
# describe BlogCell do
|
4
|
+
# before :each do
|
5
|
+
# CachedPage.delete_all
|
6
|
+
# CachedPageReference.delete_all
|
7
|
+
# Article.delete_all
|
8
|
+
#
|
9
|
+
# site = mock('site', :id => 1)
|
10
|
+
# section = mock('section', :id => 1, :track_method_calls => nil) # TODO: use real object?
|
11
|
+
# user = User.first || User.create!(:name => 'name', :email => 'email@email.org', :password => 'password')
|
12
|
+
#
|
13
|
+
# @article = Article.create!(:site => Site.first, :section => Section.first, :title => 'title', :body => 'body', :author => user)
|
14
|
+
#
|
15
|
+
# request = mock('request', :path => '/path/of/request')
|
16
|
+
# @controller = mock('controller', :params => {}, :perform_caching => true, :request => request, :site => site, :section => section)
|
17
|
+
# @cell = BlogCell.new(@controller, nil)
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# it "it renders" do
|
21
|
+
# @cell.render_state(:recent_articles).should =~ /recent \d* posts/i
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# it "caches references for the assigned articles" do
|
25
|
+
# @cell.render_state(:recent_articles)
|
26
|
+
# reference = CachedPageReference.find_by_object_id_and_object_type(@article.id, 'Article')
|
27
|
+
# reference.should be_instance_of(CachedPageReference)
|
28
|
+
# end
|
29
|
+
# end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../../test_helper")
|
2
|
+
|
3
|
+
class BlogHelperTest < ActionView::TestCase
|
4
|
+
include BlogHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@blog = Blog.first
|
9
|
+
@article = @blog.articles.published.first
|
10
|
+
@category = @blog.categories.first
|
11
|
+
@tags = ['foo', 'bar']
|
12
|
+
@month = Time.local(2008, 1)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#articles_title' do
|
16
|
+
it 'returns the title with category if given' do
|
17
|
+
articles_title(@category).should == "Articles about a category"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns the title with tags if given' do
|
21
|
+
articles_title(nil, @tags).should == "Articles tagged foo and bar"
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the title with archive month if given' do
|
25
|
+
articles_title(nil, nil, @month).should == "Articles from January 2008"
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns the full collection title if all values are given' do
|
29
|
+
articles_title(@category, @tags, @month).should == "Articles from January 2008, about a category, tagged foo and bar"
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns the title wrapped into the format string if given' do
|
33
|
+
articles_title(@category, :format => '<h1>%s</h1>').should == "<h1>Articles about a category</h1>"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#archive_month' do
|
38
|
+
it 'returns the archive month if year and month are given' do
|
39
|
+
archive_month(:year => 2008, :month => 1).should == Time.local(2008, 1)
|
40
|
+
end
|
41
|
+
|
42
|
+
it '#archive_month returns the archive month if year is given' do
|
43
|
+
archive_month(:year => 2008).should == Time.local(2008)
|
44
|
+
end
|
45
|
+
|
46
|
+
it '#archive_month returns nil if no year is given' do
|
47
|
+
archive_month.should be_nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
module BlogTests
|
4
|
+
class ContentHelperTest < ActionView::TestCase
|
5
|
+
include ContentHelper
|
6
|
+
include ResourceHelper
|
7
|
+
include BlogHelper
|
8
|
+
attr_accessor :controller
|
9
|
+
|
10
|
+
def setup
|
11
|
+
@controller = Class.new { def controller_path; 'articles' end }.new
|
12
|
+
end
|
13
|
+
|
14
|
+
test "#show_path given the content's section is a Blog it returns a blog_article_path" do
|
15
|
+
@article = Blog.first.articles.first
|
16
|
+
show_path(@article).should =~ %r(/2008/1/1/a-blog-article)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class BlogTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
# FIXME move to database/populate
|
7
|
+
@blog = Blog.first
|
8
|
+
Article.delete_all
|
9
|
+
1.upto(3) do |month|
|
10
|
+
1.upto(month) do |day|
|
11
|
+
Article.create :author => User.first, :site => @blog.site, :section => @blog,
|
12
|
+
:title => "Article on day #{day} in month #{month}", :body => 'body',
|
13
|
+
:published_at => Time.zone.local(2008, month, day)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "is a kind of Section" do
|
19
|
+
Section.should === Blog.new
|
20
|
+
end
|
21
|
+
|
22
|
+
test "#articles_by_month returns a hash with months (dates) as keys and articles as values" do
|
23
|
+
@blog.articles_by_month.size.should == 3
|
24
|
+
@blog.article_counts_by_month.transpose.first.map(&:month).sort.should == [1, 2, 3]
|
25
|
+
@blog.articles_by_month.to_a.transpose.last.flatten.map(&:class).uniq.should == [Article]
|
26
|
+
end
|
27
|
+
|
28
|
+
test '#article_counts_by_month returns a hash with months (dates) as keys and article counts as values' do
|
29
|
+
@blog.article_counts_by_month.size.should == 3
|
30
|
+
@blog.article_counts_by_month.transpose.first.map(&:month).sort.should == [1, 2, 3]
|
31
|
+
@blog.article_counts_by_month.transpose.last.sort.should == [1, 2, 3]
|
32
|
+
end
|
33
|
+
|
34
|
+
test '#archive_months returns an array with the months of published articles' do
|
35
|
+
@blog.archive_months.map(&:month).sort.should == [1, 2, 3]
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
|
3
|
+
class BlogCounterTest < ActiveSupport::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@blog = Blog.find_by_permalink 'a-blog'
|
7
|
+
@article = @blog.articles.first
|
8
|
+
end
|
9
|
+
|
10
|
+
test "has_one comments_counter" do
|
11
|
+
@blog.should have_one(:comments_counter)
|
12
|
+
end
|
13
|
+
|
14
|
+
test "responds to :comments_count" do
|
15
|
+
@blog.should respond_to(:comments_count)
|
16
|
+
end
|
17
|
+
|
18
|
+
test "after create it has a counter initialized and saved" do
|
19
|
+
@blog.comments_counter.should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
test "#comments_count is a shortcut to #comments_counter.count" do
|
23
|
+
@blog.comments_counter.count = 5
|
24
|
+
@blog.comments_count.should == 5
|
25
|
+
end
|
26
|
+
|
27
|
+
test "increments the counter when a comment has been created" do
|
28
|
+
assert_difference('@blog.comments_counter(true).count') do
|
29
|
+
create_comment!
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test "decrements the counter when a comment has been destroyed" do
|
34
|
+
@comment = create_comment!
|
35
|
+
assert_difference('@blog.comments_counter(true).count', -1) do
|
36
|
+
@comment.section.comments_counter.reload # hmmmm ...
|
37
|
+
@comment.destroy
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def create_comment!
|
42
|
+
@blog.comments.create! :section => @blog, :body => 'body', :author => User.first, :commentable => @article
|
43
|
+
end
|
44
|
+
end
|