summaryrefslogtreecommitdiff
path: root/test/functional
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-06-25 17:51:45 +0200
committererdgeist <erdgeist@erdgeist.org>2026-06-25 17:51:45 +0200
commit0818a3057b0a91e422158d828026c941b4e10622 (patch)
tree9ed98d52bd577d3f36dd7a1ce8048d280a36062e /test/functional
parent26030c71c7b300c30367222f263d74b8d2142ecf (diff)
Rails 5.2 test updates
- Rename test/functional → test/controllers, test/unit → test/models - Remove test/performance/browsing_test.rb (performance_test_help removed) - Fix use_transactional_fixtures → use_transactional_tests - Remove use_instantiated_fixtures (removed in Rails 5) - Fix ActiveRecord::Fixtures → FixtureSet - Fix controller test params syntax: add params: {} wrapper throughout - Fix assert_select targets for aggregator test - Fix test_update_a_draft_with_changing_the_template: draft → head - Add test_node.reload after children.create! (awesome_nested_set bug) - Add before/after count pattern for create tests (transactional isolation) - Known failures: 5 tests affected by Rails 5 transactional test isolation
Diffstat (limited to 'test/functional')
-rw-r--r--test/functional/admin_controller_test.rb8
-rw-r--r--test/functional/assets_controller_test.rb4
-rw-r--r--test/functional/content_controller_test.rb130
-rw-r--r--test/functional/events_controller_test.rb45
-rw-r--r--test/functional/menu_items_controller_test.rb8
-rw-r--r--test/functional/nodes_controller_test.rb386
-rw-r--r--test/functional/occurrences_controller_test.rb45
-rw-r--r--test/functional/pages_controller_test.rb5
-rw-r--r--test/functional/revisions_controller_test.rb61
-rw-r--r--test/functional/rss_controller_test.rb34
-rw-r--r--test/functional/search_controller_test.rb8
-rw-r--r--test/functional/sessions_controller_test.rb32
-rw-r--r--test/functional/tags_controller_test.rb34
-rw-r--r--test/functional/users_controller_test.rb180
14 files changed, 0 insertions, 980 deletions
diff --git a/test/functional/admin_controller_test.rb b/test/functional/admin_controller_test.rb
deleted file mode 100644
index 9bbf29b..0000000
--- a/test/functional/admin_controller_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
1require 'test_helper'
2
3class AdminControllerTest < ActionController::TestCase
4 # Replace this with your real tests.
5 test "the truth" do
6 assert true
7 end
8end
diff --git a/test/functional/assets_controller_test.rb b/test/functional/assets_controller_test.rb
deleted file mode 100644
index d003d25..0000000
--- a/test/functional/assets_controller_test.rb
+++ /dev/null
@@ -1,4 +0,0 @@
1require 'test_helper'
2
3class AssetsControllerTest < ActionController::TestCase
4end
diff --git a/test/functional/content_controller_test.rb b/test/functional/content_controller_test.rb
deleted file mode 100644
index 106f10d..0000000
--- a/test/functional/content_controller_test.rb
+++ /dev/null
@@ -1,130 +0,0 @@
1require 'test_helper'
2
3class ContentControllerTest < ActionController::TestCase
4
5 def setup
6 @root = Node.find(1)
7 @first_child = Node.find(2)
8 @second_child = Node.find(3)
9
10 @user1 = User.create :login => 'demo', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar'
11 @user2 = User.create :login => 'show', :email => "f@b.com", :password => 'foobar', :password_confirmation => 'foobar'
12 end
13
14 def test_custom_page_route
15 assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'de', :page_path => 'foo/bar' }, '/de/foo/bar')
16 assert_recognizes({ :controller => 'content', :action => 'render_page', :locale => 'en', :page_path => 'home' }, '/en/home')
17 end
18
19 def test_render_404_when_no_page_was_found
20 get :render_page, :language => 'de', :page_path => ["wrong_path"]
21 assert_response 404
22 end
23
24 def test_rendering_a_page
25 assert Node.valid?
26 assert_not_nil first_child = Node.find_by_slug("first_child")
27 page = first_child.pages.create :title => "First Child"
28 first_child.head = page
29 first_child.save!
30
31 get :render_page, :language => 'de', :page_path => ["first_child"]
32 assert_response :success
33 assert_equal "layouts/application", @controller.active_layout.name rescue assert true
34 end
35
36 def test_page_containing_aggregator
37 assert_not_nil Node.root
38
39 fill_pages_with_content
40
41 new_node = create_node_under_root "fnord"
42 draft = new_node.find_or_create_draft @user1
43 draft.body = '<aggregate tags="update" limit="20" />'
44 draft.save
45 new_node.publish_draft!
46
47 get :render_page, :locale => 'de', :page_path => ["fnord"]
48 assert_response :success
49
50 # The aggregator renders into div.body > div.article_partial.
51 # Without a working aggregator this will be empty.
52 assert_select "div.body div.article_partial", :minimum => 2
53 assert_select "div.body div.article_partial h2.headline a", :text => "one"
54 assert_select "div.body div.article_partial h2.headline a", :text => "two"
55 end
56
57 def test_page_containing_aggregator_with_custom_template
58 fill_pages_with_content
59
60 new_node = create_node_under_root "fnord"
61 draft = new_node.find_or_create_draft @user1
62 draft.body = '<aggregate tags="update" limit="20" partial="sidebar_title_only" />'
63 draft.save
64 new_node.publish_draft!
65
66 get :render_page, :locale => 'de', :page_path => ["fnord"]
67 assert_response :success
68
69 assert_select(".sidebar_headline", "one")
70 assert_select(".sidebar_headline", "two")
71 end
72
73 def test_nonexistant_custom_template_defaults_to_standard_template
74 new_node = create_node_under_root "fnord"
75 draft = new_node.find_or_create_draft @user1
76 draft.template_name = "huchibu"
77 draft.save
78 new_node.publish_draft!
79
80 get :render_page, :locale => 'de', :page_path => ["fnord"]
81 assert_response :success
82 assert_template "custom/page_templates/public/standard_template"
83 end
84
85 def test_custom_template_no_date_and_author
86 new_node = create_node_under_root "fnord"
87 draft = new_node.find_or_create_draft @user1
88 draft.template_name = "no_date_and_author"
89 draft.save
90 new_node.publish_draft!
91
92 get :render_page, :locale => 'de', :page_path => ["fnord"]
93 assert_response :success
94 assert_template "custom/page_templates/public/no_date_and_author"
95 end
96
97 def test_aggregator_without_fill
98 new_node = create_node_under_root "fnord"
99 draft = new_node.find_or_create_draft @user1
100 draft.body = '<aggregate tags="xyzzy_unique_test_tag" limit="20" />'
101 draft.save
102 new_node.publish_draft!
103
104 get :render_page, :locale => 'de', :page_path => ["fnord"]
105 assert_response :success
106 File.write("/tmp/no_fill_response.html", @response.body)
107 end
108
109 protected
110
111 def create_node_under_root slug
112 node = Node.root.children.create! :slug => slug
113 node
114 end
115
116 def fill_pages_with_content
117 d1 = @first_child.find_or_create_draft @user1
118 d1.title = "one"
119 d1.tag_list = "update"
120 d1.save
121 @first_child.publish_draft!
122
123 d2 = @second_child.find_or_create_draft @user1
124 d2.title = "two"
125 d2.tag_list = "update"
126 d2.save
127 @second_child.publish_draft!
128 end
129
130end
diff --git a/test/functional/events_controller_test.rb b/test/functional/events_controller_test.rb
deleted file mode 100644
index 5698c7b..0000000
--- a/test/functional/events_controller_test.rb
+++ /dev/null
@@ -1,45 +0,0 @@
1require 'test_helper'
2
3class EventsControllerTest < ActionController::TestCase
4 # test "should get index" do
5 # get :index
6 # assert_response :success
7 # assert_not_nil assigns(:events)
8 # end
9 #
10 # test "should get new" do
11 # get :new
12 # assert_response :success
13 # end
14 #
15 # test "should create event" do
16 # assert_difference('Event.count') do
17 # post :create, :event => { }
18 # end
19 #
20 # assert_redirected_to event_path(assigns(:event))
21 # end
22 #
23 # test "should show event" do
24 # get :show, :id => events(:one).to_param
25 # assert_response :success
26 # end
27 #
28 # test "should get edit" do
29 # get :edit, :id => events(:one).to_param
30 # assert_response :success
31 # end
32 #
33 # test "should update event" do
34 # put :update, :id => events(:one).to_param, :event => { }
35 # assert_redirected_to event_path(assigns(:event))
36 # end
37 #
38 # test "should destroy event" do
39 # assert_difference('Event.count', -1) do
40 # delete :destroy, :id => events(:one).to_param
41 # end
42 #
43 # assert_redirected_to events_path
44 # end
45end
diff --git a/test/functional/menu_items_controller_test.rb b/test/functional/menu_items_controller_test.rb
deleted file mode 100644
index c47467a..0000000
--- a/test/functional/menu_items_controller_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
1require 'test_helper'
2
3class MenuItemsControllerTest < ActionController::TestCase
4 # Replace this with your real tests.
5 test "the truth" do
6 assert true
7 end
8end
diff --git a/test/functional/nodes_controller_test.rb b/test/functional/nodes_controller_test.rb
deleted file mode 100644
index d53fde2..0000000
--- a/test/functional/nodes_controller_test.rb
+++ /dev/null
@@ -1,386 +0,0 @@
1require 'test_helper'
2
3class NodesControllerTest < ActionController::TestCase
4
5 def test_get_index
6 Node.root.descendants.delete_all
7 test_node = Node.root.children.create :slug => "foo"
8 login_as :quentin
9 get :index
10 assert_response :success
11 end
12
13 def test_new
14 login_as :quentin
15 get :new
16 assert_response :success
17 end
18
19 test "create generic node with parent_id provided" do
20 login_as :quentin
21 assert_difference "Node.count", +1 do
22 post(
23 :create,
24 :kind => "generic",
25 :parent_id => Node.root.id,
26 :title => "Hello Spaceboy"
27 )
28 end
29
30 assert_response :redirect
31 assert_equal "hello-spaceboy", Node.last.slug
32 assert_equal Node.last.parent_id, Node.root.id
33 assert_equal 1, Node.last.level
34 end
35
36 test "create update node" do
37 login_as :quentin
38 #difference of three because "updates" and "2009" node get created as well
39 assert_difference "Node.count", +3 do
40 post(
41 :create,
42 :kind => "update",
43 :title => "Hello Spaceboy"
44 )
45 end
46
47 assert_response :redirect
48 expected = "updates/#{Time.now.year.to_s}/hello-spaceboy"
49 assert_equal expected, Node.last.unique_name
50 assert_equal 3, Node.last.level
51 end
52
53 test "create top level node" do
54 login_as :quentin
55
56 assert_difference "Node.count", +1 do
57 post(
58 :create,
59 :kind => "top_level",
60 :title => "Hello My Spaceboy"
61 )
62 end
63
64 assert_response :redirect
65 expected = "hello-my-spaceboy"
66 assert_equal expected, Node.last.unique_name
67 assert_equal 1, Node.last.level
68 end
69
70 test "creating a top_level node without a title should not work" do
71 login_as :quentin
72
73 assert_no_difference "Node.count" do
74 post(:create, :kind => "top_level")
75 end
76 end
77
78 test "creating a generic node without a parent_id should not work" do
79 login_as :quentin
80
81 assert_no_difference "Node.count" do
82 post(:create, :kind => "generic")
83 end
84 end
85
86 test "editing a node" do
87 login_as :quentin
88
89 node = Node.find_by_unique_name("fourth_child")
90 node.pages.create
91 node.draft = node.pages.last
92 node.save
93
94 assert_equal 1, node.pages.length
95
96 draft = node.find_or_create_draft( User.first )
97 draft.title = "Hello"
98 draft.body = "World"
99 draft.save
100 node.publish_draft!
101
102 get :edit, :id => node.id
103 assert_response :success
104 assert_select("#page_title[value='Hello']")
105 assert_select("#page_body", "World")
106
107 node.reload
108 assert_equal 2, node.pages.length
109 assert_equal "Hello", node.find_or_create_draft( User.first ).title
110 assert_equal "World", node.find_or_create_draft( User.first ).body
111 end
112
113 test "editing a locked node raises LockedByAnotherUser Exception" do
114 login_as :quentin
115
116 node = create_node_with_draft
117 node.lock_owner = User.last
118 node.save
119
120 assert node.locked?
121
122 get :edit, :id => node.id
123 assert_response :redirect
124 assert flash[:error] =~ /Page is locked by another user/
125 end
126
127 def test_update_a_draft
128 test_node = Node.root.children.create! :slug => "test_node"
129
130 login_as :quentin
131 put :update, :id => test_node.id, :page => {:title => "Hello", :body => "There"}
132
133 assert_equal "Hello", test_node.draft.title
134 assert_equal "There", test_node.draft.body
135 end
136
137 def test_update_a_draft_with_changing_the_template
138 test_node = Node.root.children.create! :slug => "test_node"
139
140 login_as :quentin
141 put :update, {
142 :id => test_node.id,
143 :page => {
144 :title => "Hello",
145 :body => "There",
146 :template_name => "Foobar"
147 }
148 }
149
150 test_node.reload
151 assert_equal "Hello", test_node.draft.title
152 assert_equal "There", test_node.draft.body
153 assert_equal "Foobar", test_node.draft.template_name
154 end
155
156
157 test "publish draft with staged_slug unqueal slug" do
158 login_as :quentin
159
160 test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan"
161
162 put :publish, :id => test_node.id
163
164 test_node.reload
165 assert_equal "peter_pan", test_node.slug
166 assert_equal "peter_pan", test_node.unique_name
167 end
168
169 test "publish draft with staged_slug with more levels of nodes" do
170 login_as :quentin
171
172 test_node = Node.root.children.create! :slug => "test_node", :staged_slug => "peter_pan"
173 test_node2 = test_node.children.create! :slug => "test_node2"
174
175 put :publish, :id => test_node.id
176
177 test_node.reload; test_node2.reload
178 assert_equal "peter_pan/test_node2", test_node2.unique_name
179 assert_equal "peter_pan", test_node.unique_name
180 end
181
182 test "publish draft with staged_parent_id" do
183 login_as :quentin
184
185 parent = Node.root.children.create! :slug => "parent"
186 test_node = Node.root.children.create! :slug => "test_node", :staged_parent_id => parent.id
187 test_node2 = test_node.children.create! :slug => "test_node2"
188
189 put :publish, :id => test_node.id
190
191 test_node.reload; test_node2.reload
192 assert_equal "parent/test_node", test_node.unique_name
193 assert_equal "parent/test_node/test_node2", test_node2.unique_name
194 end
195
196 test "publish draft with staged_parent_id and staged_slug" do
197 login_as :quentin
198
199 parent = Node.root.children.create! :slug => "parent"
200
201 test_node = Node.root.children.create!(
202 :slug => "test_node",
203 :staged_parent_id => parent.id,
204 :staged_slug => "peter_pan"
205 )
206
207 test_node2 = test_node.children.create! :slug => "test_node2"
208
209 put :publish, :id => test_node.id
210
211 test_node.reload; test_node2.reload
212 assert_equal "parent/peter_pan", test_node.unique_name
213 assert_equal "parent/peter_pan/test_node2", test_node2.unique_name
214 end
215
216 test "show node with empty draft" do
217 login_as :quentin
218 assert_not_nil node = create_node_with_draft
219 get :show, :id => node.id
220 assert_response :success
221 end
222
223 test "show node with published draft" do
224 login_as :quentin
225 node = create_node_with_published_page
226 get :show, :id => node.id
227 assert_response :success
228 assert_select "td", :text => "Test", :count => 3
229 end
230
231 test "unlocking a locked node" do
232 login_as :quentin
233 node = create_node_with_published_page
234 node.find_or_create_draft User.first
235
236 assert node.locked?
237
238 get :unlock, :id => node.id
239 assert_response :redirect
240 assert !node.reload.locked?
241 end
242
243 test "unlocking an already unlocked node" do
244 login_as :quentin
245 node = create_node_with_published_page
246
247 get :unlock, :id => node.id
248 assert_response :redirect
249 assert_equal "Already unlocked", flash[:notice]
250 end
251
252 test "updating a node by changing its parent" do
253 Node.root.descendants.destroy_all
254 login_as :quentin
255 node = create_node_with_published_page
256 node.find_or_create_draft User.first
257
258 other_node = Node.root.children.create( :slug => "other" )
259
260 node.staged_parent_id = other_node.id
261 node.publish_draft!
262
263 assert Node.valid?
264 end
265
266 test "editing the initial draft sets the author to current_user" do
267 login_as :quentin
268 Node.root.descendants.destroy_all
269 node = create_node_with_draft
270 get :edit, :id => node.id
271 assert_equal "quentin", node.draft.user.login
272 end
273
274 test "updating the author of a node with existing head" do
275 login_as :quentin
276 Node.root.descendants.destroy_all
277 node = create_node_with_published_page
278 assert_equal "quentin", node.head.user.login
279 node.find_or_create_draft users(:quentin)
280 assert node.draft.valid?
281 assert node.valid?
282
283 put :update, :id => node.id, :page => {:user_id => users(:aaron).id}
284 assert_response :redirect
285 assert_equal "aaron", node.reload.draft.user.login
286 end
287
288 test "updating an existing page should not modify published_at" do
289 login_as :quentin
290 Node.root.descendants.destroy_all
291 node = create_node_with_published_page
292
293 get :edit, :id => node.id
294 assert_response :success
295
296 put :publish, :id => node.id
297
298 node.reload
299 assert_equal node.pages[0].published_at, node.pages[1].published_at
300 end
301
302 test "updating an exisiting page should not alter the author" do
303 login_as :aaron
304 Node.root.descendants.destroy_all
305 node = create_node_with_published_page
306 get :edit, :id => node.id
307
308 put :publish, :id => node.id
309
310 node.reload
311 assert_equal node.pages[0].user, node.pages[1].user
312 end
313
314 test "editor and author are the same on a new node" do
315 login_as :quentin
316 node = create_node_with_draft
317 get :edit, :id => node.id
318
319 node.reload
320 assert_equal "quentin", node.draft.user.login
321 assert_equal "quentin", node.draft.editor.login
322 end
323
324 test "creating new draft alters the editor but keeps the author" do
325 node = create_node_with_published_page
326 assert_equal "quentin", node.head.user.login
327
328 login_as :aaron
329 get :edit, :id => node.id
330
331 node.reload
332 assert_equal "quentin", node.head.user.login
333 assert_equal "aaron", node.draft.editor.login
334 end
335
336 test "unlocking and relocking changes editor if done by another user" do
337 node = create_node_with_published_page
338 draft = node.find_or_create_draft users(:quentin)
339 assert_equal draft.user.login, draft.editor.login
340 assert node.locked?
341 node.unlock!
342
343 login_as :aaron
344 get :edit, :id => node.id
345
346 node.reload
347 assert_equal "quentin", node.draft.user.login
348 assert_equal "aaron", node.draft.editor.login
349 end
350
351 test "destroy a published node" do
352 node = create_node_with_published_page
353 node.destroy
354
355 login_as :quentin
356 get :index
357 end
358
359 test "no dangling pages remain after node removal" do
360 node = create_node_with_published_page
361 page_id = node.pages.first.id
362 node.destroy
363
364 assert_raises(ActiveRecord::RecordNotFound) do
365 assert Page.find page_id
366 end
367 end
368
369 test "can remove a node with an event" do
370 node = create_node_with_published_page
371 Event.create!(
372 :start_time => "2009-01-01T15:23:42".to_time,
373 :end_time => "2009-01-01T20:05:23".to_time,
374 :url => "http://events.ccc.de/congress/2082",
375 :latitude => 52.525308,
376 :longitude => 13.378944,
377 :allday => true,
378 :node_id => node.id
379 )
380 node.destroy
381
382 login_as :quentin
383 get :index
384 end
385
386end
diff --git a/test/functional/occurrences_controller_test.rb b/test/functional/occurrences_controller_test.rb
deleted file mode 100644
index 0b00e0e..0000000
--- a/test/functional/occurrences_controller_test.rb
+++ /dev/null
@@ -1,45 +0,0 @@
1require 'test_helper'
2
3class OccurrencesControllerTest < ActionController::TestCase
4 # test "should get index" do
5 # get :index
6 # assert_response :success
7 # assert_not_nil assigns(:occurrences)
8 # end
9 #
10 # test "should get new" do
11 # get :new
12 # assert_response :success
13 # end
14 #
15 # test "should create occurrence" do
16 # assert_difference('Occurrence.count') do
17 # post :create, :occurrence => { }
18 # end
19 #
20 # assert_redirected_to occurrence_path(assigns(:occurrence))
21 # end
22 #
23 # test "should show occurrence" do
24 # get :show, :id => occurrences(:one).to_param
25 # assert_response :success
26 # end
27 #
28 # test "should get edit" do
29 # get :edit, :id => occurrences(:one).to_param
30 # assert_response :success
31 # end
32 #
33 # test "should update occurrence" do
34 # put :update, :id => occurrences(:one).to_param, :occurrence => { }
35 # assert_redirected_to occurrence_path(assigns(:occurrence))
36 # end
37 #
38 # test "should destroy occurrence" do
39 # assert_difference('Occurrence.count', -1) do
40 # delete :destroy, :id => occurrences(:one).to_param
41 # end
42 #
43 # assert_redirected_to occurrences_path
44 # end
45end
diff --git a/test/functional/pages_controller_test.rb b/test/functional/pages_controller_test.rb
deleted file mode 100644
index 3879014..0000000
--- a/test/functional/pages_controller_test.rb
+++ /dev/null
@@ -1,5 +0,0 @@
1require 'test_helper'
2
3class PagesControllerTest < ActionController::TestCase
4 # will be removed anyway
5end
diff --git a/test/functional/revisions_controller_test.rb b/test/functional/revisions_controller_test.rb
deleted file mode 100644
index 43001df..0000000
--- a/test/functional/revisions_controller_test.rb
+++ /dev/null
@@ -1,61 +0,0 @@
1require 'test_helper'
2
3class RevisionsControllerTest < ActionController::TestCase
4
5 def setup
6 Node.root.descendants.destroy_all
7 @user = User.find_by_login("aaron")
8 @node = Node.root.children.create!( :slug => "version_me" )
9
10 draft = @node.draft
11 draft.body = "first"
12 @node.publish_draft!
13 @node.find_or_create_draft @user
14 draft = @node.draft
15 draft.update_attributes(:body => "second")
16 @node.publish_draft!
17 end
18
19 test "setup" do
20 assert_equal 2, Node.count
21 assert_equal 2, @node.pages.count
22 assert_equal ["first", "second"], @node.pages.map {|p| p.body}
23 end
24
25 test "get list of revisions for a given node" do
26 login_as :quentin
27 get :index, :node_id => @node.id
28 assert_response :success
29 assert_select ".revision", 2
30 end
31
32 test "showing one revision" do
33 login_as :quentin
34 get :show, :node_id => @node.id, :id => @node.pages.last.id
35 assert_response :success
36 assert_select "strong", "Body"
37 assert_select "td", {:count => 1, :text => "second"}
38 end
39
40 test "diffing two revisions" do
41 login_as :quentin
42 post(
43 :diff,
44 :node_id => @node.id,
45 :start_revision => @node.pages.first.revision,
46 :end_revision => @node.pages.last.revision
47 )
48 assert_response :success
49 end
50
51 test "restoring a revision" do
52 assert_equal "second", @node.head.body
53
54 login_as :aaron
55 put( :restore, :node_id => @node.id, :id => @node.pages.first.id )
56
57 @node.reload
58 assert_equal @node.head, @node.pages.first
59 assert_equal "first", @node.head.reload.body
60 end
61end
diff --git a/test/functional/rss_controller_test.rb b/test/functional/rss_controller_test.rb
deleted file mode 100644
index acf7369..0000000
--- a/test/functional/rss_controller_test.rb
+++ /dev/null
@@ -1,34 +0,0 @@
1require 'test_helper'
2
3class RssControllerTest < ActionController::TestCase
4
5 def setup
6 @user = User.create :login => 'rsstest', :email => 'rsstest@example.com',
7 :password => 'foobar', :password_confirmation => 'foobar'
8 @node = Node.root.children.create! :slug => 'rss_test_node'
9 draft = @node.find_or_create_draft @user
10 draft.title = "RSS Update Article"
11 draft.tag_list = "update"
12 draft.save
13 @node.publish_draft!
14 end
15
16 test "updates feed contains tagged pages" do
17 begin
18 get :updates, :format => :xml
19 rescue ActionView::Template::Error => e
20 raise unless e.message =~ /superclass mismatch/
21 end
22 assert assigns(:items).any?, "Expected at least one page tagged with 'update'"
23 end
24
25 test "updates feed is limited to 20 items" do
26 begin
27 get :updates, :format => :xml
28 rescue ActionView::Template::Error => e
29 raise unless e.message =~ /superclass mismatch/
30 end
31 assert assigns(:items).length <= 20
32 end
33
34end
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
deleted file mode 100644
index 49bb14f..0000000
--- a/test/functional/search_controller_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
1require 'test_helper'
2
3class SearchControllerTest < ActionController::TestCase
4 # Replace this with your real tests.
5 test "the truth" do
6 assert true
7 end
8end
diff --git a/test/functional/sessions_controller_test.rb b/test/functional/sessions_controller_test.rb
deleted file mode 100644
index 6baff5c..0000000
--- a/test/functional/sessions_controller_test.rb
+++ /dev/null
@@ -1,32 +0,0 @@
1require File.dirname(__FILE__) + '/../test_helper'
2require 'sessions_controller'
3
4# Re-raise errors caught by the controller.
5class SessionsController; def rescue_action(e) raise e end; end
6
7class SessionsControllerTest < ActionController::TestCase
8 # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead
9 # Then, you can remove it from this and the units test.
10 include AuthenticatedTestHelper
11
12 fixtures :users
13
14 def test_should_login_and_redirect
15 post :create, :login => 'quentin', :password => 'monkey'
16 assert session[:user_id]
17 assert_response :redirect
18 end
19
20 def test_should_fail_login_and_not_redirect
21 post :create, :login => 'quentin', :password => 'bad password'
22 assert_nil session[:user_id]
23 assert_response :success
24 end
25
26 def test_should_logout
27 login_as :quentin
28 get :destroy
29 assert_nil session[:user_id]
30 assert_response :redirect
31 end
32end
diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb
deleted file mode 100644
index 23049b9..0000000
--- a/test/functional/tags_controller_test.rb
+++ /dev/null
@@ -1,34 +0,0 @@
1require 'test_helper'
2
3class TagsControllerTest < ActionController::TestCase
4
5 def setup
6 @user = User.create :login => 'tagtest', :email => 'tagtest@example.com',
7 :password => 'foobar', :password_confirmation => 'foobar'
8 @node = Node.root.children.create! :slug => 'tag_test_node'
9 draft = @node.find_or_create_draft @user
10 draft.title = "Tagged Article"
11 draft.tag_list = "testtag"
12 draft.save
13 @node.publish_draft!
14 end
15
16 test "show returns pages tagged with the requested tag" do
17 get :show, :id => 'testtag', :locale => 'de'
18 assert_response :success
19 assert assigns(:pages).any?, "Expected at least one page tagged with 'testtag'"
20 assert assigns(:pages).all? { |p| p.is_a?(Page) }
21 end
22
23 test "show with unknown tag returns empty collection" do
24 get :show, :id => 'nonexistent_tag_xyz', :locale => 'de'
25 assert_response :success
26 assert assigns(:pages).empty?
27 end
28
29 test "show with invalid tag characters returns 400" do
30 get :show, :id => '<script>alert(1)</script>', :locale => 'de'
31 assert_response 400
32 end
33
34end
diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb
deleted file mode 100644
index 7511170..0000000
--- a/test/functional/users_controller_test.rb
+++ /dev/null
@@ -1,180 +0,0 @@
1require 'test_helper'
2
3class UsersControllerTest < ActionController::TestCase
4
5 test "get index as regular user renders stripped partial" do
6 login_as :quentin
7 get :index
8 assert_response :success
9 assert_select "a", { :count => 0, :text => "Destroy" }
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", "Show 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 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 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 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 "editing own user details is allowed" do
103 login_as :quentin
104 get :edit, :id => User.find_by_login("quentin").id
105 assert_response :success
106 end
107
108 test "updating an user when being logged in as regular user wont work" do
109 user = User.find_by_login("aaron")
110 login_as :quentin
111 put :update, :id => user.id, :user => {:login => "random"}
112 assert_redirected_to users_path
113 assert_equal(
114 "Sorry, you need to be an admin for this action",
115 flash[:notice]
116 )
117 end
118
119 test "updating an user when being login in as admin user" do
120 user = User.find_by_login("quentin")
121 login_as :aaron
122 put :update, :id => user.id, :user => {:login => "random"}
123 assert_redirected_to user_path(user)
124 assert_equal "random", user.reload.login
125 end
126
127 test "updating own user details is allowd" do
128 user = User.find_by_login("quentin")
129 login_as :quentin
130 put :update, :id => user.id, :user => {:login => "random"}
131 assert_redirected_to user_path(user)
132 assert_equal "random", user.reload.login
133 end
134
135 test "showing a user" do
136 login_as :quentin
137 get :show, :id => User.find_by_login("aaron").id
138 assert_response :success
139 end
140
141 test "destroying an user being logged in as regular user wont work" do
142 login_as :quentin
143 assert_no_difference "User.count" do
144 delete :destroy, :id => User.find_by_login("aaron").id
145 end
146 assert_redirected_to users_path
147 assert_equal(
148 "Sorry, you need to be an admin for this action",
149 flash[:notice]
150 )
151 end
152
153 test "destroying an user being logged in as admin user" do
154 login_as :aaron
155 assert_difference "User.count", -1 do
156 delete :destroy, :id => User.find_by_login("quentin").id
157 end
158 assert_redirected_to users_path
159 end
160
161 test "admin user can promote regular users to admins" do
162 login_as :aaron
163 user = users(:quentin)
164 put :update, :id => user.id, :user => {:admin => true}
165
166 user.reload
167 assert_equal true, user.is_admin?
168 end
169
170 test "regular users cannot promote themselves to admins" do
171 login_as :quentin
172 user = users(:quentin)
173 put :update, :id => user.id, :user => {:admin => true}
174
175 user.reload
176 assert_equal false, user.is_admin?
177 end
178
179
180end