diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-11-11 16:37:16 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-11-11 16:37:16 +0000 |
commit | 0eb7d8f6149c8b328cbc612035b8b11e4be4b382 (patch) | |
tree | 64968cbad242477de28f0de54656dc7258357c95 /test/functional/issues_controller_test.rb | |
parent | aa84e6c1794e00973375b177e8761bff64bd4140 (diff) | |
download | redmine-0eb7d8f6149c8b328cbc612035b8b11e4be4b382.tar.gz redmine-0eb7d8f6149c8b328cbc612035b8b11e4be4b382.zip |
Moved some permission checks for issue update from controller to model.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4393 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/issues_controller_test.rb')
-rw-r--r-- | test/functional/issues_controller_test.rb | 101 |
1 files changed, 100 insertions, 1 deletions
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index e81556d5f..ab02acf00 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -580,7 +580,7 @@ class IssuesControllerTest < ActionController::TestCase context "without workflow privilege" do setup do Workflow.delete_all(["role_id = ?", Role.anonymous.id]) - Role.anonymous.add_permission! :add_issues + Role.anonymous.add_permission! :add_issues, :add_issue_notes end context "#new" do @@ -605,6 +605,17 @@ class IssuesControllerTest < ActionController::TestCase assert_equal IssueStatus.default, issue.status end + should "accept default status" do + assert_difference 'Issue.count' do + post :create, :project_id => 1, + :issue => {:tracker_id => 1, + :subject => 'This is an issue', + :status_id => 1} + end + issue = Issue.last(:order => 'id') + assert_equal IssueStatus.default, issue.status + end + should "ignore unauthorized status" do assert_difference 'Issue.count' do post :create, :project_id => 1, @@ -616,6 +627,94 @@ class IssuesControllerTest < ActionController::TestCase assert_equal IssueStatus.default, issue.status end end + + context "#update" do + should "ignore status change" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} + end + assert_equal 1, Issue.find(1).status_id + end + + should "ignore attributes changes" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} + end + issue = Issue.find(1) + assert_equal "Can't print recipes", issue.subject + assert_nil issue.assigned_to + end + end + end + + context "with workflow privilege" do + setup do + Workflow.delete_all(["role_id = ?", Role.anonymous.id]) + Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) + Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) + Role.anonymous.add_permission! :add_issues, :add_issue_notes + end + + context "#update" do + should "accept authorized status" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} + end + assert_equal 3, Issue.find(1).status_id + end + + should "ignore unauthorized status" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} + end + assert_equal 1, Issue.find(1).status_id + end + + should "accept authorized attributes changes" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} + end + issue = Issue.find(1) + assert_equal 2, issue.assigned_to_id + end + + should "ignore unauthorized attributes changes" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} + end + issue = Issue.find(1) + assert_equal "Can't print recipes", issue.subject + end + end + + context "and :edit_issues permission" do + setup do + Role.anonymous.add_permission! :add_issues, :edit_issues + end + + should "accept authorized status" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} + end + assert_equal 3, Issue.find(1).status_id + end + + should "ignore unauthorized status" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} + end + assert_equal 1, Issue.find(1).status_id + end + + should "accept authorized attributes changes" do + assert_difference 'Journal.count' do + put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} + end + issue = Issue.find(1) + assert_equal "changed", issue.subject + assert_equal 2, issue.assigned_to_id + end + end end def test_copy_issue |