]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/diary_entries_controller_test.rb
Allow admins to unhide diary comments, if they wish
[rails.git] / test / controllers / diary_entries_controller_test.rb
index 6011de9abd3b2414c2e6cff5a832854ccdf1d858..2b4230db7a41cfbfdf92cb4a6bcd73fcc611900c 100644 (file)
@@ -93,6 +93,10 @@ class DiaryEntriesControllerTest < ActionController::TestCase
       { :path => "/user/username/diary/1/hidecomment/2", :method => :post },
       { :controller => "diary_entries", :action => "hidecomment", :display_name => "username", :id => "1", :comment => "2" }
     )
+    assert_routing(
+      { :path => "/user/username/diary/1/unhidecomment/2", :method => :post },
+      { :controller => "diary_entries", :action => "unhidecomment", :display_name => "username", :id => "1", :comment => "2" }
+    )
     assert_routing(
       { :path => "/user/username/diary/1/subscribe", :method => :post },
       { :controller => "diary_entries", :action => "subscribe", :display_name => "username", :id => "1" }
@@ -809,6 +813,34 @@ class DiaryEntriesControllerTest < ActionController::TestCase
     assert_equal false, DiaryComment.find(diary_comment.id).visible
   end
 
+  def test_unhidecomment
+    user = create(:user)
+    administrator_user = create(:administrator_user)
+    diary_entry = create(:diary_entry, :user => user)
+    diary_comment = create(:diary_comment, :diary_entry => diary_entry, :visible => false)
+    # Try without logging in
+    post :unhidecomment,
+         :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }
+    assert_response :forbidden
+    assert_equal false, DiaryComment.find(diary_comment.id).visible
+
+    # Now try as a normal user
+    post :unhidecomment,
+         :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
+         :session => { :user => user }
+    assert_response :redirect
+    assert_redirected_to :controller => :errors, :action => :forbidden
+    assert_equal false, DiaryComment.find(diary_comment.id).visible
+
+    # Finally try as an administrator
+    post :unhidecomment,
+         :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id },
+         :session => { :user => administrator_user }
+    assert_response :redirect
+    assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id
+    assert_equal true, DiaryComment.find(diary_comment.id).visible
+  end
+
   def test_comments
     user = create(:user)
     other_user = create(:user)