-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
32 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,92 @@ | ||
require_relative '../../../test_helper' | ||
|
||
class Comfy::Blog::PostsControllerTest < ActionController::TestCase | ||
|
||
def setup | ||
@blog = comfy_blog_blogs(:default) | ||
@post = comfy_blog_posts(:default) | ||
end | ||
|
||
def test_get_index | ||
get :serve | ||
assert_response :success | ||
assert_template :index | ||
assert assigns(:posts) | ||
assert_equal 1, assigns(:posts).size | ||
end | ||
|
||
def test_get_index_as_rss | ||
get :serve, :format => :rss | ||
assert_response :success | ||
assert_template :index | ||
assert assigns(:posts) | ||
assert_equal 1, assigns(:posts).size | ||
end | ||
|
||
def test_get_index_with_unpublished | ||
comfy_blog_posts(:default).update_column(:is_published, false) | ||
get :serve | ||
assert_response :success | ||
assert_equal 0, assigns(:posts).size | ||
end | ||
|
||
def test_get_index_for_year_archive | ||
get :index, :year => 2012 | ||
assert_response :success | ||
assert_equal 1, assigns(:posts).size | ||
|
||
get :index, :year => 1999 | ||
assert_response :success | ||
assert_equal 0, assigns(:posts).size | ||
end | ||
|
||
def test_get_index_for_month_archive | ||
get :index, :year => 2012, :month => 1 | ||
assert_response :success | ||
assert_equal 1, assigns(:posts).size | ||
|
||
get :index, :year => 2012, :month => 12 | ||
assert_response :success | ||
assert_equal 0, assigns(:posts).size | ||
end | ||
|
||
def test_get_show | ||
get :serve, :slug => @post.slug | ||
assert_response :success | ||
assert_template :show | ||
assert assigns(:post) | ||
end | ||
|
||
def test_get_show_unpublished | ||
@post.update_attribute(:is_published, false) | ||
assert_exception_raised ComfortableMexicanSofa::MissingPage do | ||
get :serve, :slug => @post.slug | ||
end | ||
end | ||
|
||
def test_get_show_with_date | ||
get :show, :year => @post.year, :month => @post.month, :slug => @post.slug | ||
assert_response :success | ||
assert_template :show | ||
assert assigns(:post) | ||
end | ||
|
||
def test_get_show_with_date_invalid | ||
assert_exception_raised ComfortableMexicanSofa::MissingPage do | ||
get :show, :year => '1999', :month => '99', :slug => 'invalid' | ||
end | ||
end | ||
|
||
|
||
def test_custom_post_not_found_proc_called | ||
original = ComfyBlog.config.post_not_found | ||
begin | ||
ComfyBlog.config.post_not_found = Proc.new { raise 'Oh no' } | ||
assert_exception_raised RuntimeError do | ||
get :serve, :slug => 'not-here' | ||
end | ||
ensure | ||
ComfyBlog.config.post_not_found = original | ||
end | ||
end | ||
|
||
end |