]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/reports_controller_test.rb
Merge remote-tracking branch 'upstream/pull/2225'
[rails.git] / test / controllers / reports_controller_test.rb
index 206958ab88486c568444b90a5d7dee2d50235486..612ead2e6978257aa55a37fb0b59bd481b8ada40 100644 (file)
@@ -13,8 +13,6 @@ class ReportsControllerTest < ActionController::TestCase
 
     session[:user] = create(:user).id
 
-    assert_equal 0, Issue.count
-
     # Create an Issue and a report
     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
     assert_response :success
@@ -30,9 +28,8 @@ class ReportsControllerTest < ActionController::TestCase
              }
            }
     end
-    assert_equal 1, Issue.count
     assert_response :redirect
-    assert_redirected_to root_path
+    assert_redirected_to user_path(target_user)
   end
 
   def test_new_report_with_incomplete_details
@@ -42,8 +39,6 @@ class ReportsControllerTest < ActionController::TestCase
     # Login
     session[:user] = create(:user).id
 
-    assert_equal 0, Issue.count
-
     # Create an Issue and a report
     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
     assert_response :success
@@ -59,9 +54,12 @@ class ReportsControllerTest < ActionController::TestCase
              }
            }
     end
-    assert_equal 1, Issue.count
     assert_response :redirect
-    assert_redirected_to root_path
+    assert_redirected_to user_path(target_user)
+
+    issue = Issue.last
+
+    assert_equal 1, issue.reports.count
 
     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
     assert_response :success
@@ -78,7 +76,8 @@ class ReportsControllerTest < ActionController::TestCase
            }
     end
     assert_response :redirect
-    assert_equal 1, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
+
+    assert_equal 1, issue.reports.count
   end
 
   def test_new_report_with_complete_details
@@ -88,8 +87,6 @@ class ReportsControllerTest < ActionController::TestCase
     # Login
     session[:user] = create(:user).id
 
-    assert_equal 0, Issue.count
-
     # Create an Issue and a report
     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
     assert_response :success
@@ -105,9 +102,12 @@ class ReportsControllerTest < ActionController::TestCase
              }
            }
     end
-    assert_equal 1, Issue.count
     assert_response :redirect
-    assert_redirected_to root_path
+    assert_redirected_to user_path(target_user)
+
+    issue = Issue.last
+
+    assert_equal 1, issue.reports.count
 
     # Create a report for an existing Issue
     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
@@ -125,7 +125,7 @@ class ReportsControllerTest < ActionController::TestCase
            }
     end
     assert_response :redirect
-    report_count = Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
-    assert_equal 2, report_count
+
+    assert_equal 2, issue.reports.count
   end
 end