|
|
@@ -28,31 +28,37 @@ class TimelogControllerTest < ActionController::TestCase |
|
|
|
|
|
|
|
include Redmine::I18n |
|
|
|
|
|
|
|
def test_new_with_project_id |
|
|
|
def test_new |
|
|
|
@request.session[:user_id] = 3 |
|
|
|
get :new, :project_id => 1 |
|
|
|
get :new |
|
|
|
assert_response :success |
|
|
|
assert_template 'new' |
|
|
|
assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
|
|
assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]' |
|
|
|
assert_select 'input[name=?][type=hidden]', 'project_id', 0 |
|
|
|
assert_select 'input[name=?][type=hidden]', 'issue_id', 0 |
|
|
|
assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
|
|
# blank option for project |
|
|
|
assert_select 'option[value=]' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def test_new_with_issue_id |
|
|
|
def test_new_with_project_id |
|
|
|
@request.session[:user_id] = 3 |
|
|
|
get :new, :issue_id => 2 |
|
|
|
get :new, :project_id => 1 |
|
|
|
assert_response :success |
|
|
|
assert_template 'new' |
|
|
|
assert_select 'input[name=?][type=hidden]', 'project_id' |
|
|
|
assert_select 'input[name=?][type=hidden]', 'issue_id', 0 |
|
|
|
assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
|
|
assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]' |
|
|
|
end |
|
|
|
|
|
|
|
def test_new_without_project |
|
|
|
def test_new_with_issue_id |
|
|
|
@request.session[:user_id] = 3 |
|
|
|
get :new |
|
|
|
get :new, :issue_id => 2 |
|
|
|
assert_response :success |
|
|
|
assert_template 'new' |
|
|
|
assert_select 'select[name=?]', 'time_entry[project_id]' |
|
|
|
assert_select 'input[name=?]', 'time_entry[project_id]', 0 |
|
|
|
assert_select 'input[name=?][type=hidden]', 'project_id', 0 |
|
|
|
assert_select 'input[name=?][type=hidden]', 'issue_id' |
|
|
|
assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
|
|
end |
|
|
|
|
|
|
|
def test_new_without_project_should_prefill_the_form |
|
|
@@ -63,7 +69,6 @@ class TimelogControllerTest < ActionController::TestCase |
|
|
|
assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
|
|
assert_select 'option[value=1][selected=selected]' |
|
|
|
end |
|
|
|
assert_select 'input[name=?]', 'time_entry[project_id]', 0 |
|
|
|
end |
|
|
|
|
|
|
|
def test_new_without_project_should_deny_without_permission |
|
|
@@ -113,80 +118,101 @@ class TimelogControllerTest < ActionController::TestCase |
|
|
|
end |
|
|
|
|
|
|
|
def test_post_create |
|
|
|
# TODO: should POST to issues’ time log instead of project. change form |
|
|
|
# and routing |
|
|
|
@request.session[:user_id] = 3 |
|
|
|
post :create, :project_id => 1, |
|
|
|
assert_difference 'TimeEntry.count' do |
|
|
|
post :create, :project_id => 1, |
|
|
|
:time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
|
|
# Not the default activity |
|
|
|
:activity_id => '11', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:issue_id => '1', |
|
|
|
:hours => '7.3'} |
|
|
|
assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
|
|
assert_redirected_to '/projects/ecookbook/time_entries' |
|
|
|
end |
|
|
|
|
|
|
|
i = Issue.find(1) |
|
|
|
t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
|
|
t = TimeEntry.order('id DESC').first |
|
|
|
assert_not_nil t |
|
|
|
assert_equal 'Some work on TimelogControllerTest', t.comments |
|
|
|
assert_equal 1, t.project_id |
|
|
|
assert_equal 1, t.issue_id |
|
|
|
assert_equal 11, t.activity_id |
|
|
|
assert_equal 7.3, t.hours |
|
|
|
assert_equal 3, t.user_id |
|
|
|
assert_equal i, t.issue |
|
|
|
assert_equal i.project, t.project |
|
|
|
end |
|
|
|
|
|
|
|
def test_post_create_with_blank_issue |
|
|
|
# TODO: should POST to issues’ time log instead of project. change form |
|
|
|
# and routing |
|
|
|
@request.session[:user_id] = 3 |
|
|
|
post :create, :project_id => 1, |
|
|
|
assert_difference 'TimeEntry.count' do |
|
|
|
post :create, :project_id => 1, |
|
|
|
:time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
|
|
# Not the default activity |
|
|
|
:activity_id => '11', |
|
|
|
:issue_id => '', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:hours => '7.3'} |
|
|
|
assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
|
|
assert_redirected_to '/projects/ecookbook/time_entries' |
|
|
|
end |
|
|
|
|
|
|
|
t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
|
|
t = TimeEntry.order('id DESC').first |
|
|
|
assert_not_nil t |
|
|
|
assert_equal 'Some work on TimelogControllerTest', t.comments |
|
|
|
assert_equal 1, t.project_id |
|
|
|
assert_nil t.issue_id |
|
|
|
assert_equal 11, t.activity_id |
|
|
|
assert_equal 7.3, t.hours |
|
|
|
assert_equal 3, t.user_id |
|
|
|
end |
|
|
|
|
|
|
|
def test_create_and_continue |
|
|
|
def test_create_and_continue_at_project_level |
|
|
|
@request.session[:user_id] = 2 |
|
|
|
post :create, :project_id => 1, |
|
|
|
:time_entry => {:activity_id => '11', |
|
|
|
:issue_id => '', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:hours => '7.3'}, |
|
|
|
:continue => '1' |
|
|
|
assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=' |
|
|
|
assert_difference 'TimeEntry.count' do |
|
|
|
post :create, :time_entry => {:project_id => '1', |
|
|
|
:activity_id => '11', |
|
|
|
:issue_id => '', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:hours => '7.3'}, |
|
|
|
:continue => '1' |
|
|
|
assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def test_create_and_continue_with_issue_id |
|
|
|
def test_create_and_continue_at_issue_level |
|
|
|
@request.session[:user_id] = 2 |
|
|
|
post :create, :project_id => 1, |
|
|
|
:time_entry => {:activity_id => '11', |
|
|
|
:issue_id => '1', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:hours => '7.3'}, |
|
|
|
:continue => '1' |
|
|
|
assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1' |
|
|
|
assert_difference 'TimeEntry.count' do |
|
|
|
post :create, :time_entry => {:project_id => '', |
|
|
|
:activity_id => '11', |
|
|
|
:issue_id => '1', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:hours => '7.3'}, |
|
|
|
:continue => '1' |
|
|
|
assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def test_create_and_continue_without_project |
|
|
|
def test_create_and_continue_with_project_id |
|
|
|
@request.session[:user_id] = 2 |
|
|
|
post :create, :time_entry => {:project_id => '1', |
|
|
|
:activity_id => '11', |
|
|
|
:issue_id => '', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:hours => '7.3'}, |
|
|
|
:continue => '1' |
|
|
|
assert_difference 'TimeEntry.count' do |
|
|
|
post :create, :project_id => 1, |
|
|
|
:time_entry => {:activity_id => '11', |
|
|
|
:issue_id => '', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:hours => '7.3'}, |
|
|
|
:continue => '1' |
|
|
|
assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1' |
|
|
|
def test_create_and_continue_with_issue_id |
|
|
|
@request.session[:user_id] = 2 |
|
|
|
assert_difference 'TimeEntry.count' do |
|
|
|
post :create, :issue_id => 1, |
|
|
|
:time_entry => {:activity_id => '11', |
|
|
|
:issue_id => '1', |
|
|
|
:spent_on => '2008-03-14', |
|
|
|
:hours => '7.3'}, |
|
|
|
:continue => '1' |
|
|
|
assert_redirected_to '/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def test_create_without_log_time_permission_should_be_denied |
|
|
@@ -201,6 +227,14 @@ class TimelogControllerTest < ActionController::TestCase |
|
|
|
assert_response 403 |
|
|
|
end |
|
|
|
|
|
|
|
def test_create_without_project_and_issue_should_fail |
|
|
|
@request.session[:user_id] = 2 |
|
|
|
post :create, :time_entry => {:issue_id => ''} |
|
|
|
|
|
|
|
assert_response :success |
|
|
|
assert_template 'new' |
|
|
|
end |
|
|
|
|
|
|
|
def test_create_with_failure |
|
|
|
@request.session[:user_id] = 2 |
|
|
|
post :create, :project_id => 1, |
|
|
@@ -546,8 +580,6 @@ class TimelogControllerTest < ActionController::TestCase |
|
|
|
# display all time |
|
|
|
assert_nil assigns(:from) |
|
|
|
assert_nil assigns(:to) |
|
|
|
# TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes |
|
|
|
# to use /issues/:issue_id/time_entries |
|
|
|
assert_tag :form, |
|
|
|
:attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'} |
|
|
|
end |