summaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/nodes_controller_test.rb2
-rw-r--r--test/functional/users_controller_test.rb146
2 files changed, 143 insertions, 5 deletions
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb
index 3293f42..3dae9db 100644
--- a/test/functional/nodes_controller_test.rb
+++ b/test/functional/nodes_controller_test.rb
@@ -2,8 +2,6 @@ require 'test_helper'
2 2
3class NodesControllerTest < ActionController::TestCase 3class NodesControllerTest < ActionController::TestCase
4 4
5 include AuthenticatedTestHelper
6
7 def test_get_index 5 def test_get_index
8 Node.root.descendants.delete_all 6 Node.root.descendants.delete_all
9 test_node = Node.create :slug => "foo" 7 test_node = Node.create :slug => "foo"
diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb
index c3db123..a8333fe 100644
--- a/test/functional/users_controller_test.rb
+++ b/test/functional/users_controller_test.rb
@@ -1,8 +1,148 @@
1require 'test_helper' 1require 'test_helper'
2 2
3class UsersControllerTest < ActionController::TestCase 3class UsersControllerTest < ActionController::TestCase
4 # Replace this with your real tests. 4
5 test "the truth" do 5 test "get index as regular user renders stripped partial" do
6 assert true 6 login_as :quentin
7 get :index
8 assert_response :success
9 assert_select "a", { :count => 0, :text => "Destroy" }
7 end 10 end
11
12 test "get index as admin user renders admin partial" do
13 login_as :aaron
14 get :index
15 assert_response :success
16 assert_select "a", "Destroy"
17 assert_select "a", "Show", "Edit Link is missing"
18 end
19
20 test "get new when logged in as admin" do
21 login_as :aaron
22 get :new
23 assert_response :success
24 end
25
26 test "get new without being logged in as admin redirects back to index" do
27 login_as :quentin
28 get :new
29 assert_response :redirect
30 assert_redirected_to users_path
31 assert_equal(
32 "Sorry, you need to be an admin for this action",
33 @response.flash[:notice]
34 )
35 end
36
37 test "creating new users being logged in as admin" do
38 login_as :aaron
39 assert_difference "User.count", +1 do
40 post :create, :user => {
41 :login => "peter",
42 :email => "foo@bar.com",
43 :password => "xxxzzz",
44 :password_confirmation => "xxxzzz"
45 }
46 end
47
48 assert_redirected_to user_path(User.last)
49 assert !User.last.admin
50 end
51
52 test "creating new admin users being logged in as admin" do
53 login_as :aaron
54 assert_difference "User.count", +1 do
55 post :create, :user => {
56 :login => "peter",
57 :email => "foo@bar.com",
58 :password => "xxxzzz",
59 :password_confirmation => "xxxzzz",
60 :admin => true
61 }
62 end
63
64 assert_redirected_to user_path(User.last)
65 assert User.last.admin
66 end
67
68 test "creating new users not being logged as regular user wont work" do
69 login_as :quentin
70 assert_no_difference "User.count" do
71 post :create, :user => {
72 :login => "peter",
73 :email => "foo@bar.com",
74 :password => "xxxzzz",
75 :password_confirmation => "xxxzzz"
76 }
77 end
78
79 assert_redirected_to users_path
80 assert_equal(
81 "Sorry, you need to be an admin for this action",
82 @response.flash[:notice]
83 )
84 end
85
86 test "get edit of another user being logged in as regular user wont work" do
87 login_as :quentin
88 get :edit, :id => User.find_by_login("aaron").id
89 assert_redirected_to users_path
90 assert_equal(
91 "Sorry, you need to be an admin for this action",
92 @response.flash[:notice]
93 )
94 end
95
96 test "get edit of another user being logged in as admin user" do
97 login_as :aaron
98 get :edit, :id => User.find_by_login("quentin").id
99 assert_response :success
100 end
101
102 test "updating an user when being logged in as regular user wont work" do
103 user = User.find_by_login("aaron")
104 login_as :quentin
105 put :update, :id => user.id, :user => {:login => "random"}
106 assert_redirected_to users_path
107 assert_equal(
108 "Sorry, you need to be an admin for this action",
109 @response.flash[:notice]
110 )
111 end
112
113 test "updating an user when being login in as admin user" do
114 user = User.find_by_login("quentin")
115 login_as :aaron
116 put :update, :id => user.id, :user => {:login => "random"}
117 assert_redirected_to user_path(user)
118 assert_equal "random", user.reload.login
119 end
120
121 test "showing a user" do
122 login_as :quentin
123 get :show, :id => User.find_by_login("aaron").id
124 assert_response :success
125 end
126
127 test "destroying an user being logged in as regular user wont work" do
128 login_as :quentin
129 assert_no_difference "User.count" do
130 delete :destroy, :id => User.find_by_login("aaron").id
131 end
132 assert_redirected_to users_path
133 assert_equal(
134 "Sorry, you need to be an admin for this action",
135 @response.flash[:notice]
136 )
137 end
138
139 test "destroying an user being logged in as admin user" do
140 login_as :aaron
141 assert_difference "User.count", -1 do
142 delete :destroy, :id => User.find_by_login("quentin").id
143 end
144 assert_redirected_to users_path
145 end
146
147
8end 148end