replace shoulda context "with workflow privilege" at IssuesControllerTest

git-svn-id: http://svn.redmine.org/redmine/trunk@12786 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2014-02-04 07:50:55 +00:00
parent 06c53f878f
commit cfcdf06f89
1 changed files with 71 additions and 63 deletions

View File

@ -2323,30 +2323,34 @@ class IssuesControllerTest < ActionController::TestCase
assert_nil issue.assigned_to assert_nil issue.assigned_to
end end
context "with workflow privilege" do def setup_with_workflow_privilege
setup do
WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) :old_status_id => 1, :new_status_id => 3)
WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
:old_status_id => 1, :new_status_id => 4)
Role.anonymous.add_permission! :add_issues, :add_issue_notes Role.anonymous.add_permission! :add_issues, :add_issue_notes
end end
private :setup_with_workflow_privilege
context "#update" do test "with workflow privilege #update should accept authorized status" do
should "accept authorized status" do setup_with_workflow_privilege
assert_difference 'Journal.count' do assert_difference 'Journal.count' do
put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
end end
assert_equal 3, Issue.find(1).status_id assert_equal 3, Issue.find(1).status_id
end end
should "ignore unauthorized status" do test "with workflow privilege #update should ignore unauthorized status" do
setup_with_workflow_privilege
assert_difference 'Journal.count' do assert_difference 'Journal.count' do
put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
end end
assert_equal 1, Issue.find(1).status_id assert_equal 1, Issue.find(1).status_id
end end
should "accept authorized attributes changes" do test "with workflow privilege #update should accept authorized attributes changes" do
setup_with_workflow_privilege
assert_difference 'Journal.count' do assert_difference 'Journal.count' do
put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'} put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'}
end end
@ -2354,44 +2358,48 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal 2, issue.assigned_to_id assert_equal 2, issue.assigned_to_id
end end
should "ignore unauthorized attributes changes" do test "with workflow privilege #update should ignore unauthorized attributes changes" do
setup_with_workflow_privilege
assert_difference 'Journal.count' do assert_difference 'Journal.count' do
put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'} put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'}
end end
issue = Issue.find(1) issue = Issue.find(1)
assert_equal "Can't print recipes", issue.subject assert_equal "Can't print recipes", issue.subject
end end
end
context "and :edit_issues permission" do def setup_with_workflow_privilege_and_edit_issues_permission
setup do setup_with_workflow_privilege
Role.anonymous.add_permission! :add_issues, :edit_issues Role.anonymous.add_permission! :add_issues, :edit_issues
end end
private :setup_with_workflow_privilege_and_edit_issues_permission
should "accept authorized status" do test "with workflow privilege and :edit_issues permission should accept authorized status" do
setup_with_workflow_privilege_and_edit_issues_permission
assert_difference 'Journal.count' do assert_difference 'Journal.count' do
put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
end end
assert_equal 3, Issue.find(1).status_id assert_equal 3, Issue.find(1).status_id
end end
should "ignore unauthorized status" do test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do
setup_with_workflow_privilege_and_edit_issues_permission
assert_difference 'Journal.count' do assert_difference 'Journal.count' do
put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
end end
assert_equal 1, Issue.find(1).status_id assert_equal 1, Issue.find(1).status_id
end end
should "accept authorized attributes changes" do test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do
setup_with_workflow_privilege_and_edit_issues_permission
assert_difference 'Journal.count' do assert_difference 'Journal.count' do
put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'} put :update, :id => 1,
:issue => {:subject => 'changed', :assigned_to_id => 2,
:notes => 'just trying'}
end end
issue = Issue.find(1) issue = Issue.find(1)
assert_equal "changed", issue.subject assert_equal "changed", issue.subject
assert_equal 2, issue.assigned_to_id assert_equal 2, issue.assigned_to_id
end end
end
end
def test_new_as_copy def test_new_as_copy
@request.session[:user_id] = 2 @request.session[:user_id] = 2