Project

General

Profile

Defect #20677 » issues_controller_test.rb.patch

Pavel Rosický, 2015-09-04 23:49

View differences:

issues_controller_test.rb (working copy)
str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5')
issue = Issue.generate!(:subject => str_utf8)
get :index, :project_id => 1,
:f => ['subject'],
get :index, :project_id => 1,
:f => ['subject'],
:op => '=', :values => [str_utf8],
:format => 'csv'
assert_equal 'text/csv; header=present', @response.content_type
......
str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8')
issue = Issue.generate!(:subject => str_utf8)
get :index, :project_id => 1,
:f => ['subject'],
get :index, :project_id => 1,
:f => ['subject'],
:op => '=', :values => [str_utf8],
:c => ['status', 'subject'],
:format => 'csv',
......
str1 = "test_index_csv_tw"
issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
get :index, :project_id => 1,
:f => ['subject'],
get :index, :project_id => 1,
:f => ['subject'],
:op => '=', :values => [str1],
:c => ['estimated_hours', 'subject'],
:format => 'csv',
......
str1 = "test_index_csv_fr"
issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
get :index, :project_id => 1,
:f => ['subject'],
get :index, :project_id => 1,
:f => ['subject'],
:op => '=', :values => [str1],
:c => ['estimated_hours', 'subject'],
:format => 'csv',
......
Setting.issue_list_default_columns = %w(subject author)
get :index, :sort => 'tracker'
end
def test_index_sort_by_assigned_to
get :index, :sort => 'assigned_to'
assert_response :success
......
assert_equal assignees.sort, assignees
assert_select 'table.issues.sort-by-assigned-to.sort-asc'
end
def test_index_sort_by_assigned_to_desc
get :index, :sort => 'assigned_to:desc'
assert_response :success
......
assert_equal assignees.sort.reverse, assignees
assert_select 'table.issues.sort-by-assigned-to.sort-desc'
end
def test_index_group_by_assigned_to
get :index, :group_by => 'assigned_to', :sort => 'priority'
assert_response :success
end
def test_index_sort_by_author
get :index, :sort => 'author'
assert_response :success
authors = assigns(:issues).collect(&:author)
assert_equal authors.sort, authors
end
def test_index_sort_by_author_desc
get :index, :sort => 'author:desc'
assert_response :success
authors = assigns(:issues).collect(&:author)
assert_equal authors.sort.reverse, authors
end
def test_index_group_by_author
get :index, :group_by => 'author', :sort => 'priority'
assert_response :success
end
def test_index_sort_by_spent_hours
get :index, :sort => 'spent_hours:desc'
assert_response :success
hours = assigns(:issues).collect(&:spent_hours)
assert_equal hours.sort.reverse, hours
end
def test_index_sort_by_total_spent_hours
get :index, :sort => 'total_spent_hours:desc'
assert_response :success
......
def test_show_should_display_prev_next_links_with_query_and_sort_on_association
@request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
%w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
@request.session['issues_index_sort'] = assoc_sort
......
end
def test_show_export_to_pdf
issue = Issue.find(3)
issue = Issue.find(3)
assert issue.relations.select{|r| r.other_issue(issue).visible?}.present?
get :show, :id => 3, :format => 'pdf'
assert_response :success
......
assert_select_error /Bar cannot be blank/i
end
def test_create_should_validate_required_list_fields
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
WorkflowPermission.delete_all
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'required')
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
@request.session[:user_id] = 2
assert_no_difference 'Issue.count' do
post :create, :project_id => 1, :issue => {
:tracker_id => 2,
:status_id => 1,
:subject => 'Test',
:start_date => '',
:due_date => '',
:custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ['']}
}
assert_response :success
assert_template 'new'
end
assert_select_error /Foo cannot be blank/i
assert_select_error /Bar cannot be blank/i
end
def test_create_should_ignore_readonly_fields
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
......
assert_nil issue.custom_field_value(cf2)
end
def test_create_should_ignore_readonly_list_fields
cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => false, :possible_values => ['a', 'b'])
cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'list', :is_for_all => true, :tracker_ids => [1, 2], :multiple => true, :possible_values => ['a', 'b'])
WorkflowPermission.delete_all
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf1.id.to_s, :rule => 'readonly')
WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
@request.session[:user_id] = 2
assert_difference 'Issue.count' do
post :create, :project_id => 1, :issue => {
:tracker_id => 2,
:status_id => 1,
:subject => 'Test',
:start_date => '2012-07-14',
:due_date => '2012-07-16',
:custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => ['value2']}
}
assert_response 302
end
issue = Issue.order('id DESC').first
assert_equal nil, issue.custom_field_value(cf1)
assert_equal [nil], issue.custom_field_value(cf2)
end
def test_post_create_with_watchers
@request.session[:user_id] = 2
ActionMailer::Base.deliveries.clear
......
:custom_field_values => {'2' => 'Value for field 2'}}
end
assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
assert_equal 1, ActionMailer::Base.deliveries.size
end
end
......
get :new, :project_id => 1
assert_response :success
assert_template 'new'
issue = assigns(:issue)
assert_not_nil issue.default_status
......
def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
@request.session[:user_id] = 2
Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
get :edit, :id => 1
assert_select 'input[name=?]', 'time_entry[hours]'
end
......
def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
@request.session[:user_id] = 2
Role.find_by_name('Manager').remove_permission! :log_time
get :edit, :id => 1
assert_select 'input[name=?]', 'time_entry[hours]', 0
end
......
assert_select 'select[name=?]', 'issue[project_id]'
assert_select 'input[name=?]', 'issue[parent_issue_id]'
# Project specific custom field, date type
field = CustomField.find(9)
assert !field.is_for_all?
assert_equal 'date', field.field_format
assert_select 'input[name=?]', 'issue[custom_field_values][9]'
# System wide custom field
assert CustomField.find(1).is_for_all?
assert_select 'select[name=?]', 'issue[custom_field_values][1]'
# Be sure we don't display inactive IssuePriorities
assert ! IssuePriority.find(15).active?
assert_select 'select[name=?]', 'issue[priority_id]' do
......
assert_select 'option[value="2"]'
end
end
def test_bulk_copy_to_another_project
@request.session[:user_id] = 2
assert_difference 'Issue.count', 2 do
......
:assigned_to_id => 3)
]
assert_difference 'Issue.count', issues.size do
post :bulk_update, :ids => issues.map(&:id), :copy => '1',
post :bulk_update, :ids => issues.map(&:id), :copy => '1',
:issue => {
:project_id => '', :tracker_id => '', :assigned_to_id => '',
:status_id => '', :start_date => '', :due_date => ''
......
@request.session[:user_id] = 2
assert_difference 'Issue.count', 2 do
assert_no_difference 'Project.find(1).issues.count' do
post :bulk_update, :ids => [1, 2], :copy => '1',
post :bulk_update, :ids => [1, 2], :copy => '1',
:issue => {
:project_id => '2', :tracker_id => '', :assigned_to_id => '4',
:status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
(1-1/2)