X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/26777c44648f908b723c0c74b65972f75ac5fd3d..2142ff02c2442d28580ff99080bc1219c2bfe59f:/test/controllers/diary_entries_controller_test.rb diff --git a/test/controllers/diary_entries_controller_test.rb b/test/controllers/diary_entries_controller_test.rb index 426bc3851..b17d974d1 100644 --- a/test/controllers/diary_entries_controller_test.rb +++ b/test/controllers/diary_entries_controller_test.rb @@ -713,9 +713,9 @@ class DiaryEntriesControllerTest < ActionController::TestCase def test_hide user = create(:user) + diary_entry = create(:diary_entry, :user => user) # Try without logging in - diary_entry = create(:diary_entry, :user => user) post :hide, :params => { :display_name => user.display_name, :id => diary_entry.id } assert_response :forbidden @@ -726,9 +726,20 @@ class DiaryEntriesControllerTest < ActionController::TestCase :params => { :display_name => user.display_name, :id => diary_entry.id }, :session => { :user => user } assert_response :redirect - assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id + assert_redirected_to :controller => :errors, :action => :forbidden assert_equal true, DiaryEntry.find(diary_entry.id).visible + # Now try as a moderator + post :hide, + :params => { :display_name => user.display_name, :id => diary_entry.id }, + :session => { :user => create(:moderator_user) } + assert_response :redirect + assert_redirected_to :action => :index, :display_name => user.display_name + assert_equal false, DiaryEntry.find(diary_entry.id).visible + + # Reset + diary_entry.reload.update(:visible => true) + # Finally try as an administrator post :hide, :params => { :display_name => user.display_name, :id => diary_entry.id }, @@ -740,9 +751,9 @@ class DiaryEntriesControllerTest < ActionController::TestCase def test_hidecomment user = create(:user) - administrator_user = create(:administrator_user) diary_entry = create(:diary_entry, :user => user) diary_comment = create(:diary_comment, :diary_entry => diary_entry) + # Try without logging in post :hidecomment, :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id } @@ -754,13 +765,24 @@ class DiaryEntriesControllerTest < ActionController::TestCase :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }, :session => { :user => user } assert_response :redirect - assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id + assert_redirected_to :controller => :errors, :action => :forbidden assert_equal true, DiaryComment.find(diary_comment.id).visible + # Try as a moderator + post :hidecomment, + :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }, + :session => { :user => create(:moderator_user) } + assert_response :redirect + assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id + assert_equal false, DiaryComment.find(diary_comment.id).visible + + # Reset + diary_comment.reload.update(:visible => true) + # Finally try as an administrator post :hidecomment, :params => { :display_name => user.display_name, :id => diary_entry.id, :comment => diary_comment.id }, - :session => { :user => administrator_user } + :session => { :user => create(:administrator_user) } assert_response :redirect assert_redirected_to :action => :show, :display_name => user.display_name, :id => diary_entry.id assert_equal false, DiaryComment.find(diary_comment.id).visible