Improve controller tests for issues
This commit is contained in:
parent
5e2c567b7f
commit
22385c179a
3 changed files with 116 additions and 40 deletions
|
@ -10,6 +10,7 @@ class IssueCommentsControllerTest < ActionController::TestCase
|
|||
post :create, :params => { :issue_id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
assert_equal 0, issue.comments.length
|
||||
end
|
||||
|
||||
def test_comment
|
||||
|
|
|
@ -1,69 +1,144 @@
|
|||
require "test_helper"
|
||||
|
||||
class IssuesControllerTest < ActionController::TestCase
|
||||
teardown do
|
||||
# cleanup any emails set off by the test
|
||||
ActionMailer::Base.deliveries.clear
|
||||
end
|
||||
|
||||
def test_view_dashboard_without_auth
|
||||
# Access issues_path without login
|
||||
def test_index
|
||||
# Access issues list without login
|
||||
get :index
|
||||
assert_response :redirect
|
||||
assert_redirected_to login_path(:referer => issues_path)
|
||||
|
||||
# Access issues_path as normal user
|
||||
# Access issues list as normal user
|
||||
session[:user] = create(:user).id
|
||||
get :index
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
|
||||
# Access issues_path by admin
|
||||
# Access issues list as administrator
|
||||
session[:user] = create(:administrator_user).id
|
||||
get :index
|
||||
assert_response :success
|
||||
|
||||
# Access issues_path by moderator
|
||||
# Access issues list as moderator
|
||||
session[:user] = create(:moderator_user).id
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_change_status_by_normal_user
|
||||
def test_show
|
||||
target_user = create(:user)
|
||||
issue = create(:issue, :reportable => target_user, :reported_user => target_user)
|
||||
|
||||
# Login as normal user
|
||||
# Access issue without login
|
||||
get :show, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to login_path(:referer => issue_path(issue))
|
||||
|
||||
# Access issue as normal user
|
||||
session[:user] = create(:user).id
|
||||
|
||||
assert_equal 1, Issue.count
|
||||
|
||||
get :resolve, :params => { :id => issue.id }
|
||||
|
||||
get :show, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
|
||||
# Access issue as administrator
|
||||
session[:user] = create(:administrator_user).id
|
||||
get :show, :params => { :id => issue.id }
|
||||
assert_response :success
|
||||
|
||||
# Access issue as moderator
|
||||
session[:user] = create(:moderator_user).id
|
||||
get :show, :params => { :id => issue.id }
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
def test_change_status_by_admin
|
||||
def test_resolve
|
||||
target_user = create(:user)
|
||||
issue = create(:issue, :reportable => target_user, :reported_user => target_user)
|
||||
|
||||
# Login as administrator
|
||||
session[:user] = create(:administrator_user).id
|
||||
|
||||
# Test 'Resolved'
|
||||
# Resolve issue without login
|
||||
get :resolve, :params => { :id => issue.id }
|
||||
assert_equal true, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").resolved?
|
||||
assert_response :redirect
|
||||
assert_redirected_to login_path(:referer => resolve_issue_path(issue))
|
||||
|
||||
# Test 'Reopen'
|
||||
get :reopen, :params => { :id => issue.id }
|
||||
assert_equal true, Issue.find_by(:reportable_id => target_user.id, :reportable_type => "User").open?
|
||||
# Resolve issue as normal user
|
||||
session[:user] = create(:user).id
|
||||
get :resolve, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
|
||||
# Test 'Ignored'
|
||||
# Resolve issue as administrator
|
||||
session[:user] = create(:administrator_user).id
|
||||
get :resolve, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_equal true, issue.reload.resolved?
|
||||
|
||||
issue.reopen!
|
||||
|
||||
# Resolve issue as moderator
|
||||
session[:user] = create(:moderator_user).id
|
||||
get :resolve, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_equal true, issue.reload.resolved?
|
||||
end
|
||||
|
||||
def test_ignore
|
||||
target_user = create(:user)
|
||||
issue = create(:issue, :reportable => target_user, :reported_user => target_user)
|
||||
|
||||
# Ignore issue without login
|
||||
get :ignore, :params => { :id => issue.id }
|
||||
assert_equal true, Issue.find_by(:reportable_id => target_user, :reportable_type => "User").ignored?
|
||||
assert_response :redirect
|
||||
assert_redirected_to login_path(:referer => ignore_issue_path(issue))
|
||||
|
||||
# Ignore issue as normal user
|
||||
session[:user] = create(:user).id
|
||||
get :ignore, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
|
||||
# Ignore issue as administrator
|
||||
session[:user] = create(:administrator_user).id
|
||||
get :ignore, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_equal true, issue.reload.ignored?
|
||||
|
||||
issue.reopen!
|
||||
|
||||
# Ignore issue as moderator
|
||||
session[:user] = create(:moderator_user).id
|
||||
get :ignore, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_equal true, issue.reload.ignored?
|
||||
end
|
||||
|
||||
def test_reopen
|
||||
target_user = create(:user)
|
||||
issue = create(:issue, :reportable => target_user, :reported_user => target_user)
|
||||
|
||||
issue.resolve!
|
||||
|
||||
# Reopen issue without login
|
||||
get :reopen, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to login_path(:referer => reopen_issue_path(issue))
|
||||
|
||||
# Reopen issue as normal user
|
||||
session[:user] = create(:user).id
|
||||
get :reopen, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
|
||||
# Reopen issue as administrator
|
||||
session[:user] = create(:administrator_user).id
|
||||
get :reopen, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_equal true, issue.reload.open?
|
||||
|
||||
issue.resolve!
|
||||
|
||||
# Reopen issue as moderator
|
||||
session[:user] = create(:moderator_user).id
|
||||
get :reopen, :params => { :id => issue.id }
|
||||
assert_response :redirect
|
||||
assert_equal true, issue.reload.open?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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,7 +28,6 @@ class ReportsControllerTest < ActionController::TestCase
|
|||
}
|
||||
}
|
||||
end
|
||||
assert_equal 1, Issue.count
|
||||
assert_response :redirect
|
||||
assert_redirected_to user_path(target_user.display_name)
|
||||
end
|
||||
|
@ -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,10 +54,13 @@ class ReportsControllerTest < ActionController::TestCase
|
|||
}
|
||||
}
|
||||
end
|
||||
assert_equal 1, Issue.count
|
||||
assert_response :redirect
|
||||
assert_redirected_to user_path(target_user.display_name)
|
||||
|
||||
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,10 +102,13 @@ class ReportsControllerTest < ActionController::TestCase
|
|||
}
|
||||
}
|
||||
end
|
||||
assert_equal 1, Issue.count
|
||||
assert_response :redirect
|
||||
assert_redirected_to user_path(target_user.display_name)
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue