Skip to content

Commit 7eb7ea5

Browse files
committed
added test for thread_rename preventing same-title updates
1 parent e693d4b commit 7eb7ea5

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

test/controllers/comments/rename_test.rb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ class CommentsControllerTest < ActionController::TestCase
99
sign_in users(:deleter)
1010

1111
try_rename_thread(comment_threads(:normal))
12+
@thread = assigns(:comment_thread)
1213

1314
assert_response(:found)
14-
assert_not_nil assigns(:comment_thread)
15-
assert_redirected_to comment_thread_path(assigns(:comment_thread))
16-
assert_equal 'new thread title', assigns(:comment_thread).title
15+
assert_not_nil(@thread)
16+
assert_redirected_to comment_thread_path(@thread)
17+
assert_equal 'new thread title', @thread.title
1718
end
1819

1920
test 'non-moderators should not be able to rename restricted threads' do
@@ -26,12 +27,26 @@ class CommentsControllerTest < ActionController::TestCase
2627
@thread = assigns(:comment_thread)
2728

2829
assert_response(:found)
29-
assert_not_nil @thread
30+
assert_not_nil(@thread)
3031
assert_redirected_to comment_thread_path(@thread)
3132
assert_equal before_title, @thread.title
3233
end
3334
end
3435

36+
test 'should not allow renaming to the current title' do
37+
sign_in users(:admin)
38+
39+
thread = comment_threads(:normal)
40+
41+
try_rename_thread(thread, title: thread.title)
42+
@thread = assigns(:comment_thread)
43+
44+
assert_response(:found)
45+
assert_not_nil(@thread)
46+
assert_equal flash[:danger], I18n.t('comments.errors.no_rename_thread_to_current_title')
47+
assert_equal thread.title, @thread.title
48+
end
49+
3550
test 'should correctly handle invalid thread titles' do
3651
sign_in users(:admin)
3752

@@ -40,7 +55,7 @@ class CommentsControllerTest < ActionController::TestCase
4055
@thread = assigns(:comment_thread)
4156

4257
assert_response(:found)
43-
assert_not_nil @thread
58+
assert_not_nil(@thread)
4459
assert_not @thread.valid?
4560
assert_not_nil flash[:danger]
4661
end

0 commit comments

Comments
 (0)