/
base_test.rb
80 lines (62 loc) · 2.11 KB
/
base_test.rb
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
require File.dirname(__FILE__) + '/test_helper'
require 'action_view/test_case'
class User
def self.human_name; 'User'; end
end
class UsersController < InheritedViews::Base; end
UsersController.helper(InheritedViews::Helpers)
module UserTestHelper
def create_mock_user(expectations={})
user = mock(expectations.except(:errors))
user.stubs(:class).returns(User)
user.stubs(:errors).returns(expectations.fetch(:errors, {}))
user
end
end
class IndexActionBaseTest < ActionController::TestCase
include UserTestHelper
tests UsersController
def setup
super
mock_user_1 = create_mock_user
mock_user_2 = create_mock_user
User.expects(:find).with(:all).returns([mock_user_1, mock_user_2])
@columns = [ stub(:name => "username"),
stub(:name => "first_name"),
stub(:name => "last_name") ]
User.stubs(:content_columns).returns(@columns)
mock_user_1.stubs(:username => "john.doe", :first_name => "John", :last_name => "Doe")
mock_user_2.stubs(:username => "jane.doe", :first_name => "Jane", :last_name => "Doe")
get :index
# puts @controller.response.body
end
test "should render a nice heading" do
assert_select "h2", "Users"
end
test "should id and class the index table" do
assert_select "table#users_index_table"
assert_select "table.index_table"
end
test "should render a table with the attributes of the model" do
assert_select "th", "Username"
assert_select "th", "First Name"
assert_select "th", "Last Name"
end
test "should render each resource" do
assert_select "td", "john.doe"
assert_select "td", "John"
assert_select "td", "jane.doe"
assert_select "td", "Jane"
assert_select "td", "Doe"
end
test "should mark rows as odd and even" do
assert_select "tr.odd"
assert_select "tr.even"
end
test "should render using the table partial" do
assert_template :partial => "_table", :count => 1
end
test "should render the item partial for each resource in the table" do
assert_template :partial => "_item", :count => 2
end
end