+ def test_unhide
+ user = create(:user)
+
+ # Try without logging in
+ diary_entry = create(:diary_entry, :user => user, :visible => false)
+ post :unhide,
+ :params => { :display_name => user.display_name, :id => diary_entry.id }
+ assert_response :forbidden
+ assert_equal false, DiaryEntry.find(diary_entry.id).visible
+
+ # Now try as a normal user
+ post :unhide,
+ :params => { :display_name => user.display_name, :id => diary_entry.id },
+ :session => { :user => user }
+ assert_response :redirect
+ assert_redirected_to :controller => :errors, :action => :forbidden
+ assert_equal false, DiaryEntry.find(diary_entry.id).visible
+
+ # Finally try as an administrator
+ post :unhide,
+ :params => { :display_name => user.display_name, :id => diary_entry.id },
+ :session => { :user => create(:administrator_user) }
+ assert_response :redirect
+ assert_redirected_to :action => :index, :display_name => user.display_name
+ assert_equal true, DiaryEntry.find(diary_entry.id).visible
+ end
+