Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
xel1045 committed Apr 7, 2021
1 parent f87d0e9 commit bee6081
Showing 4 changed files with 116 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/risk_issues_controller.rb
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ def create
end

def destroy
@issue = Issue.visible.find_by_id(params[:issue_id])
@issue = @risk.issues.visible.find_by_id(params[:issue_id])

if @issue
@risk.init_journal(User.current)
43 changes: 43 additions & 0 deletions test/functional/context_menus_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require File.expand_path('../../test_helper', __FILE__)

class ContextMenuControllerTest < ActionController::TestCase
fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:enabled_modules,
:enumerations,
:issues,
:risks,
:risk_issues

def setup
@controller = ContextMenusController.new

# Enable the Risks module on one project
@project1 = Project.find(1)
EnabledModule.create(:project => @project1, :name => 'risks')

# Configure the logged user
@request.session[:user_id] = 1
end

def test_get_risks_single
compatible_request :get, :risks, :ids => [1]

assert_response :success
assert_match 'Impact', @response.body
assert_match 'Probability', @response.body
assert_match 'Strategy', @response.body
end

def test_get_risks_many
compatible_request :get, :risks, :ids => [1, 2]

assert_response :success
assert_match 'Impact', @response.body
assert_match 'Probability', @response.body
assert_match 'Strategy', @response.body
end
end
44 changes: 44 additions & 0 deletions test/functional/risk_issues_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require File.expand_path('../../test_helper', __FILE__)

class RiskIssuesControllerTest < ActionController::TestCase
fixtures :projects,
:users,
:roles,
:members,
:member_roles,
:enabled_modules,
:enumerations,
:issues,
:risks,
:risk_issues

def setup
# Enable the Risks module on one project
@project1 = Project.find(1)
EnabledModule.create(:project => @project1, :name => 'risks')

# Configure the logged user
@request.session[:user_id] = 1
end

def test_post_create
compatible_xhr_request :post, :create, :risk_id => 1, :issue_id => 2

assert_response :success

risk = Risk.find(1)

assert_equal 2, risk.issues.count
assert_equal [1, 2], risk.issues.map(&:id).sort
end

def test_delete_destroy
compatible_xhr_request :delete, :destroy, :risk_id => 1, :issue_id => 1

assert_response :success

risk = Risk.find(1)

assert_equal 0, risk.issues.count
end
end
28 changes: 28 additions & 0 deletions test/functional/risks_controller_test.rb
Original file line number Diff line number Diff line change
@@ -166,4 +166,32 @@ def test_get_preview_for_existing_risk
assert_response :success
assert_match '<strong>Rhoncus turpis</strong> magnis blandit', @response.body
end

def test_post_quoted
compatible_xhr_request :post, :quoted, :id => 1

assert_response :success
assert_match '> Amet tellus quis phasellus dis ultrices nulla', @response.body
end

def test_post_bulk_update
compatible_request :post, :bulk_update, :ids => [1, 2],
:risk => {
:probability => 75,
:impact => 100,
:strategy => 'eliminate',
}

assert_response 302

risk1 = Risk.find(1)
assert_equal 75, risk1.probability
assert_equal 100, risk1.impact
assert_equal 'eliminate', risk1.strategy

risk2 = Risk.find(2)
assert_equal 75, risk2.probability
assert_equal 100, risk2.impact
assert_equal 'eliminate', risk2.strategy
end
end

0 comments on commit bee6081

Please sign in to comment.