summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2020-04-06 10:02:27 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2020-04-06 10:02:27 +0000
commitb50b9ec5b3d6091b5c3ab51507004e079b538b70 (patch)
tree4e8da416077de8b67f801b5dfb82b457928d81c8 /test
parent6ccf502e95b39ca298d79cd2a502ae921c188bce (diff)
downloadredmine-b50b9ec5b3d6091b5c3ab51507004e079b538b70.tar.gz
redmine-b50b9ec5b3d6091b5c3ab51507004e079b538b70.zip
Merged r19676 to r19678 to 4.1-stable (#32774).
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@19679 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/timelog_controller_test.rb12
-rw-r--r--test/integration/api_test/time_entries_test.rb34
-rw-r--r--test/unit/time_entry_import_test.rb16
3 files changed, 49 insertions, 13 deletions
diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb
index 43c53a576..3b17c563b 100644
--- a/test/functional/timelog_controller_test.rb
+++ b/test/functional/timelog_controller_test.rb
@@ -383,7 +383,7 @@ class TimelogControllerTest < Redmine::ControllerTest
assert_equal 2, t.author_id
end
- def test_create_for_other_user_should_deny_for_user_without_permission
+ def test_create_for_other_user_should_fail_without_permission
Role.find_by_name('Manager').remove_permission! :log_time_for_other_users
@request.session[:user_id] = 2
@@ -399,8 +399,8 @@ class TimelogControllerTest < Redmine::ControllerTest
}
}
- assert_response 403
- assert_select 'p[id=?]', 'errorExplanation', :text => I18n.t(:error_not_allowed_to_log_time_for_other_users)
+ assert_response :success
+ assert_select_error /User is invalid/
end
def test_create_and_continue_at_project_level
@@ -668,7 +668,7 @@ class TimelogControllerTest < Redmine::ControllerTest
assert_select_error /Issue is invalid/
end
- def test_update_should_deny_changing_user_for_user_without_permission
+ def test_update_should_fail_when_changing_user_without_permission
Role.find_by_name('Manager').remove_permission! :log_time_for_other_users
@request.session[:user_id] = 2
@@ -679,8 +679,8 @@ class TimelogControllerTest < Redmine::ControllerTest
}
}
- assert_response 403
- assert_select 'p[id=?]', 'errorExplanation', :text => I18n.t(:error_not_allowed_to_log_time_for_other_users)
+ assert_response :success
+ assert_select_error /User is invalid/
end
def test_update_should_allow_updating_existing_entry_logged_on_a_locked_user
diff --git a/test/integration/api_test/time_entries_test.rb b/test/integration/api_test/time_entries_test.rb
index f42d0ae97..4557032be 100644
--- a/test/integration/api_test/time_entries_test.rb
+++ b/test/integration/api_test/time_entries_test.rb
@@ -144,6 +144,40 @@ class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base
assert_select 'errors error', :text => "Hours cannot be blank"
end
+ test "POST /time_entries.xml with :project_id for other user" do
+ Role.find_by_name('Manager').add_permission! :log_time_for_other_users
+
+ entry = new_record(TimeEntry) do
+ post(
+ '/time_entries.xml',
+ :params =>
+ {:time_entry =>
+ {:project_id => '1', :spent_on => '2010-12-02', :user_id => '3',
+ :hours => '3.5', :activity_id => '11'}},
+ :headers => credentials('jsmith'))
+ end
+ assert_response :created
+ assert_equal 3, entry.user_id
+ assert_equal 2, entry.author_id
+ end
+
+ test "POST /time_entries.xml with :issue_id for other user" do
+ Role.find_by_name('Manager').add_permission! :log_time_for_other_users
+
+ entry = new_record(TimeEntry) do
+ post(
+ '/time_entries.xml',
+ :params =>
+ {:time_entry =>
+ {:issue_id => '1', :spent_on => '2010-12-02', :user_id => '3',
+ :hours => '3.5', :activity_id => '11'}},
+ :headers => credentials('jsmith'))
+ end
+ assert_response :created
+ assert_equal 3, entry.user_id
+ assert_equal 2, entry.author_id
+ end
+
test "PUT /time_entries/:id.xml with valid parameters should update time entry" do
assert_no_difference 'TimeEntry.count' do
put(
diff --git a/test/unit/time_entry_import_test.rb b/test/unit/time_entry_import_test.rb
index d84de22f4..440089dc9 100644
--- a/test/unit/time_entry_import_test.rb
+++ b/test/unit/time_entry_import_test.rb
@@ -127,7 +127,8 @@ class TimeEntryImportTest < ActiveSupport::TestCase
end
def test_maps_user_id_for_user_with_permissions
- User.current = User.find(1)
+ Role.find_by_name('Manager').add_permission! :log_time_for_other_users
+
import = generate_import_with_mapping
first, second, third, fourth = new_records(TimeEntry, 4) { import.run }
@@ -138,16 +139,17 @@ class TimeEntryImportTest < ActiveSupport::TestCase
end
def test_maps_user_to_column_value
- User.current = User.find(1)
+ Role.find_by_name('Manager').add_permission! :log_time_for_other_users
+
import = generate_import_with_mapping
- import.mapping.merge!('user_id' => 'value:1')
+ import.mapping.merge!('user_id' => 'value:3')
import.save!
first, second, third, fourth = new_records(TimeEntry, 4) { import.run }
- assert_equal 1, first.user_id
- assert_equal 1, second.user_id
- assert_equal 1, third.user_id
- assert_equal 1, fourth.user_id
+ assert_equal 3, first.user_id
+ assert_equal 3, second.user_id
+ assert_equal 3, third.user_id
+ assert_equal 3, fourth.user_id
end
def test_maps_user_id_for_user_without_permissions