category_controller_test.rb
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require File.dirname(__FILE__) + '/../test_helper'
require 'category_controller'
# Re-raise errors caught by the controller.
class CategoryController; def rescue_action(e) raise e end; end
class CategoryControllerTest < Test::Unit::TestCase
def setup
@controller = CategoryController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
@category = Category.create!(:name => 'my category', :environment => Environment.default)
end
def test_should_display_a_given_category
get :view, :path => [ 'my-category' ]
assert_equal @category, assigns(:category)
end
should 'expose category in a method' do
get :view, :path => [ 'my-category' ]
assert_same assigns(:category), @controller.category
end
should 'list recent articles in the category' do
@controller.expects(:category).returns(@category).at_least_once
recent = []
@category.expects(:recent_articles).returns(recent)
get :view, :path => [ 'my-category' ]
assert_same recent, assigns(:recent_articles)
end
should 'list recent comments in the category' do
@controller.expects(:category).returns(@category).at_least_once
recent = []
@category.expects(:recent_comments).returns(recent)
get :view, :path => [ 'my-category' ]
assert_same recent, assigns(:recent_comments)
end
should 'list most commented articles in the category' do
@controller.expects(:category).returns(@category).at_least_once
most_commented = []
@category.expects(:most_commented_articles).returns(most_commented)
get :view, :path => [ 'my-category' ]
assert_same most_commented, assigns(:most_commented_articles)
end
end