]> git.openstreetmap.org Git - rails.git/blobdiff - test/functional/diary_entry_controller_test.rb
Add tests for diary_entry#comments
[rails.git] / test / functional / diary_entry_controller_test.rb
index 5d0cb93acfe3df6bf4bfbb0f0f504f52fb3c8738..be4dbe87ae1957093871ca50c80167a2677f9d21 100644 (file)
@@ -201,7 +201,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
       assert_select "body", :count => 1 do
         assert_select "div.wrapper", :count => 1 do
           assert_select "div.content-heading", :count => 1 do
-            assert_select "h2", :text => /#{entry.user.display_name}&#x27;s diary/, :count => 1
+            assert_select "h2", :text => /#{entry.user.display_name}&#39;s diary/, :count => 1
           end
           assert_select "div#content", :count => 1 do
             assert_select "div.post_heading", :text => /#{new_title}/, :count => 1
@@ -230,7 +230,7 @@ class DiaryEntryControllerTest < ActionController::TestCase
       assert_select "body", :count => 1 do
         assert_select "div.wrapper", :count => 1 do
           assert_select "div.content-heading", :count => 1 do
-            assert_select "h2", :text => /#{users(:normal_user).display_name}&#x27;s diary/, :count => 1
+            assert_select "h2", :text => /#{users(:normal_user).display_name}&#39;s diary/, :count => 1
           end
           assert_select "div#content", :count => 1 do
             assert_select "div.post_heading", :text => /#{new_title}/, :count => 1
@@ -430,4 +430,76 @@ class DiaryEntryControllerTest < ActionController::TestCase
     assert_response :success
     assert_template 'view'
   end
+
+  def test_hide
+    # Try without logging in
+    post :hide, {:display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_entry_1).id}
+    assert_response :forbidden
+    assert_equal true, DiaryEntry.find(diary_entries(:normal_user_entry_1).id).visible
+
+    @request.cookies["_osm_username"] = users(:normal_user).display_name
+
+    # Now try as a normal user
+    post :hide, {:display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_entry_1).id}, {:user => users(:normal_user).id}
+    assert_response :redirect
+    assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_entry_1).id
+    assert_equal true, DiaryEntry.find(diary_entries(:normal_user_entry_1).id).visible
+
+    @request.cookies["_osm_username"] = users(:administrator_user).display_name
+
+    # Finally try as an administrator
+    post :hide, {:display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_entry_1).id}, {:user => users(:administrator_user).id}
+    assert_response :redirect
+    assert_redirected_to :action => :list, :display_name => users(:normal_user).display_name
+    assert_equal false, DiaryEntry.find(diary_entries(:normal_user_entry_1).id).visible
+  end
+
+  def test_hidecomment
+    # Try without logging in
+    post :hidecomment, {:display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_geo_entry).id, :comment => diary_comments(:comment_for_geo_post).id}
+    assert_response :forbidden
+    assert_equal true, DiaryComment.find(diary_comments(:comment_for_geo_post).id).visible
+
+    @request.cookies["_osm_username"] = users(:normal_user).display_name
+
+    # Now try as a normal user
+    post :hidecomment, {:display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_geo_entry).id, :comment => diary_comments(:comment_for_geo_post).id}, {:user => users(:normal_user).id}
+    assert_response :redirect
+    assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_geo_entry).id
+    assert_equal true, DiaryComment.find(diary_comments(:comment_for_geo_post).id).visible
+
+    @request.cookies["_osm_username"] = users(:administrator_user).display_name
+
+    # Finally try as an administrator
+    post :hidecomment, {:display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_geo_entry).id, :comment => diary_comments(:comment_for_geo_post).id}, {:user => users(:administrator_user).id}
+    assert_response :redirect
+    assert_redirected_to :action => :view, :display_name => users(:normal_user).display_name, :id => diary_entries(:normal_user_geo_entry).id
+    assert_equal false, DiaryComment.find(diary_comments(:comment_for_geo_post).id).visible
+  end
+
+  def test_comments
+    # Test a user with no comments
+    get :comments, :display_name => users(:normal_user).display_name
+    assert_response :success
+    assert_template :comments
+    assert_select "table.messages" do
+      assert_select "tr", :count => 1 # header, no comments
+    end
+
+    # Test a user with a comment
+    get :comments, :display_name => users(:public_user).display_name
+    assert_response :success
+    assert_template :comments
+    assert_select "table.messages" do
+      assert_select "tr", :count => 2 # header and one comment
+    end
+
+    # Test a suspended user
+    get :comments, :display_name => users(:suspended_user).display_name
+    assert_response :not_found
+
+    # Test a deleted user
+    get :comments, :display_name => users(:deleted_user).display_name
+    assert_response :not_found
+  end
 end