summaryrefslogtreecommitdiffstats
path: root/test/functional/timelog_controller_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-07-21 16:58:59 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-07-21 16:58:59 +0000
commit29ddc82a11f30f7fcb917dd062fc38f48640b4ea (patch)
treef7d58fb646b26808462fe1dc91888a68d8ecdcd2 /test/functional/timelog_controller_test.rb
parent55e89ae5bc815e777165de12fdd79545cbf42c5a (diff)
downloadredmine-29ddc82a11f30f7fcb917dd062fc38f48640b4ea.tar.gz
redmine-29ddc82a11f30f7fcb917dd062fc38f48640b4ea.zip
Removes calls to #assert_template and #assigns in functional tests.
git-svn-id: http://svn.redmine.org/redmine/trunk@15724 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/timelog_controller_test.rb')
-rw-r--r--test/functional/timelog_controller_test.rb81
1 files changed, 37 insertions, 44 deletions
diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb
index 6a7219060..15a70404a 100644
--- a/test/functional/timelog_controller_test.rb
+++ b/test/functional/timelog_controller_test.rb
@@ -32,7 +32,7 @@ class TimelogControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 3
get :new
assert_response :success
- assert_template 'new'
+
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
@@ -45,7 +45,7 @@ class TimelogControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 3
get :new, :params => {: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
@@ -55,7 +55,7 @@ class TimelogControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 3
get :new, :params => {:issue_id => 2}
assert_response :success
- assert_template 'new'
+
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
@@ -65,7 +65,7 @@ class TimelogControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 3
get :new, :params => {:time_entry => {:project_id => '1'}}
assert_response :success
- assert_template 'new'
+
assert_select 'select[name=?]', 'time_entry[project_id]' do
assert_select 'option[value="1"][selected=selected]'
end
@@ -106,7 +106,7 @@ class TimelogControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 2
get :edit, :params => {:id => 2, :project_id => nil}
assert_response :success
- assert_template 'edit'
+
assert_select 'form[action=?]', '/time_entries/2'
end
@@ -118,7 +118,7 @@ class TimelogControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 1
get :edit, :params => {:project_id => 1, :id => 1}
assert_response :success
- assert_template 'edit'
+
# Blank option since nothing is pre-selected
assert_select 'option', :text => '--- Please select ---'
end
@@ -341,7 +341,7 @@ class TimelogControllerTest < Redmine::ControllerTest
post :create, :params => {:time_entry => {:issue_id => ''}}
assert_response :success
- assert_template 'new'
+ assert_select_error /Project cannot be blank/
end
def test_create_with_failure
@@ -356,7 +356,6 @@ class TimelogControllerTest < Redmine::ControllerTest
}
}
assert_response :success
- assert_template 'new'
end
def test_create_without_project
@@ -393,7 +392,7 @@ class TimelogControllerTest < Redmine::ControllerTest
end
assert_response :success
- assert assigns(:time_entry).errors[:issue_id].present?
+ assert_select_error /Issue is invalid/
end
def test_create_without_project_should_deny_without_permission
@@ -484,8 +483,8 @@ class TimelogControllerTest < Redmine::ControllerTest
:issue_id => '5'
}
}
- assert_response 200
- assert_include "Issue is invalid", assigns(:time_entry).errors.full_messages
+ assert_response :success
+ assert_select_error /Issue is invalid/
end
def test_get_bulk_edit
@@ -493,7 +492,6 @@ class TimelogControllerTest < Redmine::ControllerTest
get :bulk_edit, :params => {:ids => [1, 2]}
assert_response :success
- assert_template 'bulk_edit'
assert_select 'ul#bulk-selection' do
assert_select 'li', 2
@@ -517,7 +515,6 @@ class TimelogControllerTest < Redmine::ControllerTest
get :bulk_edit, :params => {:ids => [1, 2, 6]}
assert_response :success
- assert_template 'bulk_edit'
end
def test_bulk_edit_with_edit_own_time_entries_permission
@@ -664,26 +661,28 @@ class TimelogControllerTest < Redmine::ControllerTest
@request.session[:user_id] = 2
get :index
assert_response :success
- assert_template 'index'
+
assert_select 'a[href=?]', '/time_entries/new', :text => /Log time/
end
def test_index_my_spent_time
@request.session[:user_id] = 2
- get :index, :params => {:user_id => 'me'}
+ get :index, :params => {:user_id => 'me', :c => ['user']}
assert_response :success
- assert_template 'index'
- assert assigns(:entries).all? {|entry| entry.user_id == 2}
+
+ users = css_select('table.time-entries tbody td.user').map(&:text).uniq
+ assert_equal ["John Smith"], users
end
def test_index_at_project_level
- get :index, :params => {:project_id => 'ecookbook'}
+ get :index, :params => {:project_id => 'ecookbook', :c => ['project']}
assert_response :success
- assert_template 'index'
- assert_not_nil assigns(:entries)
- assert_equal 4, assigns(:entries).size
+
+ assert_select 'tr.time-entry', 4
+
# project and subproject
- assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
+ projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
+ assert_equal ["eCookbook", "eCookbook Subproject 1"], projects
assert_select '.total-for-hours', :text => 'Hours: 162.90'
assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
@@ -693,10 +692,11 @@ class TimelogControllerTest < Redmine::ControllerTest
entry = TimeEntry.generate!(:project => Project.find(3))
with_settings :display_subprojects_issues => '0' do
- get :index, :params => {:project_id => 'ecookbook'}
+ get :index, :params => {:project_id => 'ecookbook', :c => ['project']}
assert_response :success
- assert_template 'index'
- assert_not_include entry, assigns(:entries)
+
+ projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
+ assert_equal ["eCookbook"], projects
end
end
@@ -704,10 +704,11 @@ class TimelogControllerTest < Redmine::ControllerTest
entry = TimeEntry.generate!(:project => Project.find(3))
with_settings :display_subprojects_issues => '0' do
- get :index, :params => {:project_id => 'ecookbook', :subproject_id => 3}
+ get :index, :params => {:project_id => 'ecookbook', :c => ['project'], :subproject_id => 3}
assert_response :success
- assert_template 'index'
- assert_include entry, assigns(:entries)
+
+ projects = css_select('table.time-entries tbody td.project').map(&:text).uniq.sort
+ assert_equal ["eCookbook", "eCookbook Subproject 1"], projects
end
end
@@ -740,10 +741,8 @@ class TimelogControllerTest < Redmine::ControllerTest
:v => {'spent_on' => ['2007-03-20', '2007-04-30']}
}
assert_response :success
- assert_template 'index'
- assert_not_nil assigns(:entries)
- assert_equal 3, assigns(:entries).size
+ assert_select 'tr.time-entry', 3
assert_select '.total-for-hours', :text => 'Hours: 12.90'
assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
end
@@ -755,10 +754,8 @@ class TimelogControllerTest < Redmine::ControllerTest
:to => '2007-04-30'
}
assert_response :success
- assert_template 'index'
- assert_not_nil assigns(:entries)
- assert_equal 3, assigns(:entries).size
+ assert_select 'tr.time-entry', 3
assert_select '.total-for-hours', :text => 'Hours: 12.90'
assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries'
end
@@ -787,7 +784,7 @@ class TimelogControllerTest < Redmine::ControllerTest
:v => {'spent_on' => ['2012-06-15', '2012-06-16']}
}
assert_response :success
- assert_equal [t2, t1, t3], assigns(:entries)
+ assert_equal [t2, t1, t3].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
get :index, :params => {
:project_id => 1,
@@ -797,7 +794,7 @@ class TimelogControllerTest < Redmine::ControllerTest
:sort => 'spent_on'
}
assert_response :success
- assert_equal [t3, t1, t2], assigns(:entries)
+ assert_equal [t3, t1, t2].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
end
def test_index_with_filter_on_issue_custom_field
@@ -810,7 +807,7 @@ class TimelogControllerTest < Redmine::ControllerTest
:v => {'issue.cf_2' => ['filter_on_issue_custom_field']}
}
assert_response :success
- assert_equal [entry], assigns(:entries)
+ assert_equal [entry].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
end
def test_index_with_issue_custom_field_column
@@ -821,7 +818,6 @@ class TimelogControllerTest < Redmine::ControllerTest
:c => %w(project spent_on issue comments hours issue.cf_2)
}
assert_response :success
- assert_include :'issue.cf_2', assigns(:query).column_names
assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
end
@@ -834,7 +830,6 @@ class TimelogControllerTest < Redmine::ControllerTest
:c => ["hours", field_name]
}
assert_response :success
- assert_include field_name.to_sym, assigns(:query).column_names
assert_select "td.#{field_name}", :text => 'CF Value'
end
@@ -850,13 +845,12 @@ class TimelogControllerTest < Redmine::ControllerTest
:sort => field_name
}
assert_response :success
- assert_include field_name.to_sym, assigns(:query).column_names
assert_select "th a.sort", :text => 'String Field'
# Make sure that values are properly sorted
- values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact
- assert_equal 3, values.size
+ values = css_select("td.#{field_name}").map(&:text).reject(&:blank?)
assert_equal values.sort, values
+ assert_equal 3, values.size
end
def test_index_with_query
@@ -874,8 +868,7 @@ class TimelogControllerTest < Redmine::ControllerTest
get :index, :params => {:project_id => 1, :format => 'atom'}
assert_response :success
assert_equal 'application/atom+xml', @response.content_type
- assert_not_nil assigns(:items)
- assert assigns(:items).first.is_a?(TimeEntry)
+ assert_select 'entry > title', :text => /7\.65 hours/
end
def test_index_at_project_level_should_include_csv_export_dialog