]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/reports_controller_test.rb
Merge branch 'master' into cancancan
[rails.git] / test / controllers / reports_controller_test.rb
index 8dc10238ecfad5a28730fe48be915a3dc5d949c6..612ead2e6978257aa55a37fb0b59bd481b8ada40 100644 (file)
@@ -13,24 +13,23 @@ class ReportsControllerTest < ActionController::TestCase
 
     session[:user] = create(:user).id
 
-    assert_equal Issue.count, 0
-
     # Create an Issue and a report
     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
     assert_response :success
     assert_difference "Issue.count", 1 do
       details = "Details of a report"
+      category = "other"
       post :create,
            :params => {
              :report => {
                :details => details,
+               :category => category,
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
     end
-    assert_equal Issue.count, 1
     assert_response :redirect
-    assert_redirected_to root_path
+    assert_redirected_to user_path(target_user)
   end
 
   def test_new_report_with_incomplete_details
@@ -40,53 +39,45 @@ class ReportsControllerTest < ActionController::TestCase
     # Login
     session[:user] = create(:user).id
 
-    assert_equal Issue.count, 0
-
     # Create an Issue and a report
     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
     assert_response :success
     assert_difference "Issue.count", 1 do
       details = "Details of a report"
+      category = "other"
       post :create,
            :params => {
              :report => {
                :details => details,
+               :category => category,
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
     end
-    assert_equal Issue.count, 1
     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
 
-    # Report without report_type
-    assert_no_difference "Issue.count" do
-      details = "Details of another report under the same issue"
-      post :create,
-           :params => {
-             :report => {
-               :details => details,
-               :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
-             }
-           }
-    end
-    assert_response :redirect
-    assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count, 1
-
     # Report without details
     assert_no_difference "Issue.count" do
+      category = "other"
       post :create,
            :params => {
              :report => {
+               :category => category,
                :issue => { :reportable_id => 1, :reportable_type => "User" }
              }
            }
     end
     assert_response :redirect
-    assert_equal Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count, 1
+
+    assert_equal 1, issue.reports.count
   end
 
   def test_new_report_with_complete_details
@@ -96,40 +87,45 @@ class ReportsControllerTest < ActionController::TestCase
     # Login
     session[:user] = create(:user).id
 
-    assert_equal Issue.count, 0
-
     # Create an Issue and a report
     get :new, :params => { :reportable_id => target_user.id, :reportable_type => "User" }
     assert_response :success
     assert_difference "Issue.count", 1 do
       details = "Details of a report"
+      category = "other"
       post :create,
            :params => {
              :report => {
                :details => details,
+               :category => category,
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
     end
-    assert_equal Issue.count, 1
     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" }
     assert_response :success
     assert_no_difference "Issue.count" do
       details = "Details of another report under the same issue"
+      category = "other"
       post :create,
            :params => {
              :report => {
                :details => details,
+               :category => category,
                :issue => { :reportable_id => target_user.id, :reportable_type => "User" }
              }
            }
     end
     assert_response :redirect
-    report_count = Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").reports.count
-    assert_equal report_count, 2
+
+    assert_equal 2, issue.reports.count
   end
 end