Mercurial > hg > soundsoftware-site
comparison test/functional/issues_controller_test.rb @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
19 require 'issues_controller' | |
20 | 19 |
21 class IssuesControllerTest < ActionController::TestCase | 20 class IssuesControllerTest < ActionController::TestCase |
22 fixtures :projects, | 21 fixtures :projects, |
23 :users, | 22 :users, |
24 :roles, | 23 :roles, |
46 :changesets | 45 :changesets |
47 | 46 |
48 include Redmine::I18n | 47 include Redmine::I18n |
49 | 48 |
50 def setup | 49 def setup |
51 @controller = IssuesController.new | |
52 @request = ActionController::TestRequest.new | |
53 @response = ActionController::TestResponse.new | |
54 User.current = nil | 50 User.current = nil |
55 end | 51 end |
56 | 52 |
57 def test_index | 53 def test_index |
58 with_settings :default_language => "en" do | 54 with_settings :default_language => "en" do |
329 get :index, :project_id => 1, :query_id => 999 | 325 get :index, :project_id => 1, :query_id => 999 |
330 assert_response 404 | 326 assert_response 404 |
331 end | 327 end |
332 | 328 |
333 def test_index_with_cross_project_query_in_session_should_show_project_issues | 329 def test_index_with_cross_project_query_in_session_should_show_project_issues |
334 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil) | 330 q = IssueQuery.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil) |
335 @request.session[:query] = {:id => q.id, :project_id => 1} | 331 @request.session[:query] = {:id => q.id, :project_id => 1} |
336 | 332 |
337 with_settings :display_subprojects_issues => '0' do | 333 with_settings :display_subprojects_issues => '0' do |
338 get :index, :project_id => 1 | 334 get :index, :project_id => 1 |
339 end | 335 end |
343 assert_equal 1, assigns(:query).project_id | 339 assert_equal 1, assigns(:query).project_id |
344 assert_equal [1], assigns(:issues).map(&:project_id).uniq | 340 assert_equal [1], assigns(:issues).map(&:project_id).uniq |
345 end | 341 end |
346 | 342 |
347 def test_private_query_should_not_be_available_to_other_users | 343 def test_private_query_should_not_be_available_to_other_users |
348 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) | 344 q = IssueQuery.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) |
349 @request.session[:user_id] = 3 | 345 @request.session[:user_id] = 3 |
350 | 346 |
351 get :index, :query_id => q.id | 347 get :index, :query_id => q.id |
352 assert_response 403 | 348 assert_response 403 |
353 end | 349 end |
354 | 350 |
355 def test_private_query_should_be_available_to_its_user | 351 def test_private_query_should_be_available_to_its_user |
356 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) | 352 q = IssueQuery.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil) |
357 @request.session[:user_id] = 2 | 353 @request.session[:user_id] = 2 |
358 | 354 |
359 get :index, :query_id => q.id | 355 get :index, :query_id => q.id |
360 assert_response :success | 356 assert_response :success |
361 end | 357 end |
362 | 358 |
363 def test_public_query_should_be_available_to_other_users | 359 def test_public_query_should_be_available_to_other_users |
364 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil) | 360 q = IssueQuery.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil) |
365 @request.session[:user_id] = 3 | 361 @request.session[:user_id] = 3 |
366 | 362 |
367 get :index, :query_id => q.id | 363 get :index, :query_id => q.id |
368 assert_response :success | 364 assert_response :success |
369 end | 365 end |
382 assert_response :success | 378 assert_response :success |
383 assert_not_nil assigns(:issues) | 379 assert_not_nil assigns(:issues) |
384 assert_equal 'text/csv; header=present', @response.content_type | 380 assert_equal 'text/csv; header=present', @response.content_type |
385 assert @response.body.starts_with?("#,") | 381 assert @response.body.starts_with?("#,") |
386 lines = @response.body.chomp.split("\n") | 382 lines = @response.body.chomp.split("\n") |
387 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size | 383 assert_equal assigns(:query).columns.size, lines[0].split(',').size |
388 end | 384 end |
389 | 385 |
390 def test_index_csv_with_project | 386 def test_index_csv_with_project |
391 get :index, :project_id => 1, :format => 'csv' | 387 get :index, :project_id => 1, :format => 'csv' |
392 assert_response :success | 388 assert_response :success |
393 assert_not_nil assigns(:issues) | 389 assert_not_nil assigns(:issues) |
394 assert_equal 'text/csv; header=present', @response.content_type | 390 assert_equal 'text/csv; header=present', @response.content_type |
395 end | 391 end |
396 | 392 |
397 def test_index_csv_with_description | 393 def test_index_csv_with_description |
398 get :index, :format => 'csv', :description => '1' | 394 Issue.generate!(:description => 'test_index_csv_with_description') |
399 assert_response :success | 395 |
400 assert_not_nil assigns(:issues) | 396 with_settings :default_language => 'en' do |
401 assert_equal 'text/csv; header=present', @response.content_type | 397 get :index, :format => 'csv', :description => '1' |
402 assert @response.body.starts_with?("#,") | 398 assert_response :success |
403 lines = @response.body.chomp.split("\n") | 399 assert_not_nil assigns(:issues) |
404 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size | 400 end |
401 | |
402 assert_equal 'text/csv; header=present', response.content_type | |
403 headers = response.body.chomp.split("\n").first.split(',') | |
404 assert_include 'Description', headers | |
405 assert_include 'test_index_csv_with_description', response.body | |
405 end | 406 end |
406 | 407 |
407 def test_index_csv_with_spent_time_column | 408 def test_index_csv_with_spent_time_column |
408 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2) | 409 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2) |
409 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today) | 410 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today) |
418 def test_index_csv_with_all_columns | 419 def test_index_csv_with_all_columns |
419 get :index, :format => 'csv', :columns => 'all' | 420 get :index, :format => 'csv', :columns => 'all' |
420 assert_response :success | 421 assert_response :success |
421 assert_not_nil assigns(:issues) | 422 assert_not_nil assigns(:issues) |
422 assert_equal 'text/csv; header=present', @response.content_type | 423 assert_equal 'text/csv; header=present', @response.content_type |
423 assert @response.body.starts_with?("#,") | 424 assert_match /\A#,/, response.body |
424 lines = @response.body.chomp.split("\n") | 425 lines = response.body.chomp.split("\n") |
425 assert_equal assigns(:query).available_inline_columns.size + 1, lines[0].split(',').size | 426 assert_equal assigns(:query).available_inline_columns.size, lines[0].split(',').size |
426 end | 427 end |
427 | 428 |
428 def test_index_csv_with_multi_column_field | 429 def test_index_csv_with_multi_column_field |
429 CustomField.find(1).update_attribute :multiple, true | 430 CustomField.find(1).update_attribute :multiple, true |
430 issue = Issue.find(1) | 431 issue = Issue.find(1) |
433 | 434 |
434 get :index, :format => 'csv', :columns => 'all' | 435 get :index, :format => 'csv', :columns => 'all' |
435 assert_response :success | 436 assert_response :success |
436 lines = @response.body.chomp.split("\n") | 437 lines = @response.body.chomp.split("\n") |
437 assert lines.detect {|line| line.include?('"MySQL, Oracle"')} | 438 assert lines.detect {|line| line.include?('"MySQL, Oracle"')} |
439 end | |
440 | |
441 def test_index_csv_should_format_float_custom_fields_with_csv_decimal_separator | |
442 field = IssueCustomField.create!(:name => 'Float', :is_for_all => true, :tracker_ids => [1], :field_format => 'float') | |
443 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {field.id => '185.6'}) | |
444 | |
445 with_settings :default_language => 'fr' do | |
446 get :index, :format => 'csv', :columns => 'all' | |
447 assert_response :success | |
448 issue_line = response.body.chomp.split("\n").map {|line| line.split(';')}.detect {|line| line[0]==issue.id.to_s} | |
449 assert_include '185,60', issue_line | |
450 end | |
451 | |
452 with_settings :default_language => 'en' do | |
453 get :index, :format => 'csv', :columns => 'all' | |
454 assert_response :success | |
455 issue_line = response.body.chomp.split("\n").map {|line| line.split(',')}.detect {|line| line[0]==issue.id.to_s} | |
456 assert_include '185.60', issue_line | |
457 end | |
438 end | 458 end |
439 | 459 |
440 def test_index_csv_big_5 | 460 def test_index_csv_big_5 |
441 with_settings :default_language => "zh-TW" do | 461 with_settings :default_language => "zh-TW" do |
442 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" | 462 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" |
455 lines = @response.body.chomp.split("\n") | 475 lines = @response.body.chomp.split("\n") |
456 s1 = "\xaa\xac\xbaA" | 476 s1 = "\xaa\xac\xbaA" |
457 if str_utf8.respond_to?(:force_encoding) | 477 if str_utf8.respond_to?(:force_encoding) |
458 s1.force_encoding('Big5') | 478 s1.force_encoding('Big5') |
459 end | 479 end |
460 assert lines[0].include?(s1) | 480 assert_include s1, lines[0] |
461 assert lines[1].include?(str_big5) | 481 assert_include str_big5, lines[1] |
462 end | 482 end |
463 end | 483 end |
464 | 484 |
465 def test_index_csv_cannot_convert_should_be_replaced_big_5 | 485 def test_index_csv_cannot_convert_should_be_replaced_big_5 |
466 with_settings :default_language => "zh-TW" do | 486 with_settings :default_language => "zh-TW" do |
668 get :index, :set_filter => 1, :c => columns | 688 get :index, :set_filter => 1, :c => columns |
669 assert_response :success | 689 assert_response :success |
670 | 690 |
671 # query should use specified columns | 691 # query should use specified columns |
672 query = assigns(:query) | 692 query = assigns(:query) |
673 assert_kind_of Query, query | 693 assert_kind_of IssueQuery, query |
674 assert_equal columns, query.column_names.map(&:to_s) | 694 assert_equal columns, query.column_names.map(&:to_s) |
675 | 695 |
676 # columns should be stored in session | 696 # columns should be stored in session |
677 assert_kind_of Hash, session[:query] | 697 assert_kind_of Hash, session[:query] |
678 assert_kind_of Array, session[:query][:column_names] | 698 assert_kind_of Array, session[:query][:column_names] |
690 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] | 710 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
691 get :index, :set_filter => 1 | 711 get :index, :set_filter => 1 |
692 | 712 |
693 # query should use specified columns | 713 # query should use specified columns |
694 query = assigns(:query) | 714 query = assigns(:query) |
695 assert_kind_of Query, query | 715 assert_kind_of IssueQuery, query |
696 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name) | 716 assert_equal [:id, :project, :tracker, :subject, :assigned_to], query.columns.map(&:name) |
697 end | 717 end |
698 | 718 |
699 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column | 719 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column |
700 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] | 720 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to'] |
701 columns = ['tracker', 'subject', 'assigned_to'] | 721 columns = ['id', 'tracker', 'subject', 'assigned_to'] |
702 get :index, :set_filter => 1, :c => columns | 722 get :index, :set_filter => 1, :c => columns |
703 | 723 |
704 # query should use specified columns | 724 # query should use specified columns |
705 query = assigns(:query) | 725 query = assigns(:query) |
706 assert_kind_of Query, query | 726 assert_kind_of IssueQuery, query |
707 assert_equal columns.map(&:to_sym), query.columns.map(&:name) | 727 assert_equal columns.map(&:to_sym), query.columns.map(&:name) |
708 end | 728 end |
709 | 729 |
710 def test_index_with_custom_field_column | 730 def test_index_with_custom_field_column |
711 columns = %w(tracker subject cf_2) | 731 columns = %w(tracker subject cf_2) |
712 get :index, :set_filter => 1, :c => columns | 732 get :index, :set_filter => 1, :c => columns |
713 assert_response :success | 733 assert_response :success |
714 | 734 |
715 # query should use specified columns | 735 # query should use specified columns |
716 query = assigns(:query) | 736 query = assigns(:query) |
717 assert_kind_of Query, query | 737 assert_kind_of IssueQuery, query |
718 assert_equal columns, query.column_names.map(&:to_s) | 738 assert_equal columns, query.column_names.map(&:to_s) |
719 | 739 |
720 assert_select 'table.issues td.cf_2.string' | 740 assert_select 'table.issues td.cf_2.string' |
721 end | 741 end |
722 | 742 |
897 def test_show_should_display_update_form | 917 def test_show_should_display_update_form |
898 @request.session[:user_id] = 2 | 918 @request.session[:user_id] = 2 |
899 get :show, :id => 1 | 919 get :show, :id => 1 |
900 assert_response :success | 920 assert_response :success |
901 | 921 |
902 assert_tag 'form', :attributes => {:id => 'issue-form'} | 922 assert_select 'form#issue-form' do |
903 assert_tag 'input', :attributes => {:name => 'issue[is_private]'} | 923 assert_select 'input[name=?]', 'issue[is_private]' |
904 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} | 924 assert_select 'select[name=?]', 'issue[project_id]' |
905 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | 925 assert_select 'select[name=?]', 'issue[tracker_id]' |
906 assert_tag 'input', :attributes => {:name => 'issue[subject]'} | 926 assert_select 'input[name=?]', 'issue[subject]' |
907 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} | 927 assert_select 'textarea[name=?]', 'issue[description]' |
908 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} | 928 assert_select 'select[name=?]', 'issue[status_id]' |
909 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} | 929 assert_select 'select[name=?]', 'issue[priority_id]' |
910 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | 930 assert_select 'select[name=?]', 'issue[assigned_to_id]' |
911 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} | 931 assert_select 'select[name=?]', 'issue[category_id]' |
912 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | 932 assert_select 'select[name=?]', 'issue[fixed_version_id]' |
913 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | 933 assert_select 'input[name=?]', 'issue[parent_issue_id]' |
914 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} | 934 assert_select 'input[name=?]', 'issue[start_date]' |
915 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} | 935 assert_select 'input[name=?]', 'issue[due_date]' |
916 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | 936 assert_select 'select[name=?]', 'issue[done_ratio]' |
917 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } | 937 assert_select 'input[name=?]', 'issue[custom_field_values][2]' |
918 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | 938 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
919 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} | 939 assert_select 'textarea[name=?]', 'issue[notes]' |
940 end | |
920 end | 941 end |
921 | 942 |
922 def test_show_should_display_update_form_with_minimal_permissions | 943 def test_show_should_display_update_form_with_minimal_permissions |
923 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] | 944 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] |
924 WorkflowTransition.delete_all :role_id => 1 | 945 WorkflowTransition.delete_all :role_id => 1 |
925 | 946 |
926 @request.session[:user_id] = 2 | 947 @request.session[:user_id] = 2 |
927 get :show, :id => 1 | 948 get :show, :id => 1 |
928 assert_response :success | 949 assert_response :success |
929 | 950 |
930 assert_tag 'form', :attributes => {:id => 'issue-form'} | 951 assert_select 'form#issue-form' do |
931 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} | 952 assert_select 'input[name=?]', 'issue[is_private]', 0 |
932 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} | 953 assert_select 'select[name=?]', 'issue[project_id]', 0 |
933 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | 954 assert_select 'select[name=?]', 'issue[tracker_id]', 0 |
934 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} | 955 assert_select 'input[name=?]', 'issue[subject]', 0 |
935 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} | 956 assert_select 'textarea[name=?]', 'issue[description]', 0 |
936 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'} | 957 assert_select 'select[name=?]', 'issue[status_id]', 0 |
937 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} | 958 assert_select 'select[name=?]', 'issue[priority_id]', 0 |
938 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | 959 assert_select 'select[name=?]', 'issue[assigned_to_id]', 0 |
939 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} | 960 assert_select 'select[name=?]', 'issue[category_id]', 0 |
940 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | 961 assert_select 'select[name=?]', 'issue[fixed_version_id]', 0 |
941 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | 962 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
942 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} | 963 assert_select 'input[name=?]', 'issue[start_date]', 0 |
943 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} | 964 assert_select 'input[name=?]', 'issue[due_date]', 0 |
944 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | 965 assert_select 'select[name=?]', 'issue[done_ratio]', 0 |
945 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } | 966 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0 |
946 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | 967 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
947 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} | 968 assert_select 'textarea[name=?]', 'issue[notes]' |
969 end | |
948 end | 970 end |
949 | 971 |
950 def test_show_should_display_update_form_with_workflow_permissions | 972 def test_show_should_display_update_form_with_workflow_permissions |
951 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] | 973 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes] |
952 | 974 |
953 @request.session[:user_id] = 2 | 975 @request.session[:user_id] = 2 |
954 get :show, :id => 1 | 976 get :show, :id => 1 |
955 assert_response :success | 977 assert_response :success |
956 | 978 |
957 assert_tag 'form', :attributes => {:id => 'issue-form'} | 979 assert_select 'form#issue-form' do |
958 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} | 980 assert_select 'input[name=?]', 'issue[is_private]', 0 |
959 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} | 981 assert_select 'select[name=?]', 'issue[project_id]', 0 |
960 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | 982 assert_select 'select[name=?]', 'issue[tracker_id]', 0 |
961 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'} | 983 assert_select 'input[name=?]', 'issue[subject]', 0 |
962 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'} | 984 assert_select 'textarea[name=?]', 'issue[description]', 0 |
963 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} | 985 assert_select 'select[name=?]', 'issue[status_id]' |
964 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'} | 986 assert_select 'select[name=?]', 'issue[priority_id]', 0 |
965 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | 987 assert_select 'select[name=?]', 'issue[assigned_to_id]' |
966 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'} | 988 assert_select 'select[name=?]', 'issue[category_id]', 0 |
967 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | 989 assert_select 'select[name=?]', 'issue[fixed_version_id]' |
968 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | 990 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
969 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'} | 991 assert_select 'input[name=?]', 'issue[start_date]', 0 |
970 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'} | 992 assert_select 'input[name=?]', 'issue[due_date]', 0 |
971 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | 993 assert_select 'select[name=?]', 'issue[done_ratio]' |
972 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' } | 994 assert_select 'input[name=?]', 'issue[custom_field_values][2]', 0 |
973 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | 995 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 |
974 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'} | 996 assert_select 'textarea[name=?]', 'issue[notes]' |
997 end | |
975 end | 998 end |
976 | 999 |
977 def test_show_should_not_display_update_form_without_permissions | 1000 def test_show_should_not_display_update_form_without_permissions |
978 Role.find(1).update_attribute :permissions, [:view_issues] | 1001 Role.find(1).update_attribute :permissions, [:view_issues] |
979 | 1002 |
1002 def test_update_form_should_allow_attachment_upload | 1025 def test_update_form_should_allow_attachment_upload |
1003 @request.session[:user_id] = 2 | 1026 @request.session[:user_id] = 2 |
1004 get :show, :id => 1 | 1027 get :show, :id => 1 |
1005 | 1028 |
1006 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do | 1029 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do |
1007 assert_select 'input[type=file][name=?]', 'attachments[1][file]' | 1030 assert_select 'input[type=file][name=?]', 'attachments[dummy][file]' |
1008 end | 1031 end |
1009 end | 1032 end |
1010 | 1033 |
1011 def test_show_should_deny_anonymous_access_without_permission | 1034 def test_show_should_deny_anonymous_access_without_permission |
1012 Role.anonymous.remove_permission!(:view_issues) | 1035 Role.anonymous.remove_permission!(:view_issues) |
1138 assert_select 'span.position', :text => "3 of #{count}" | 1161 assert_select 'span.position', :text => "3 of #{count}" |
1139 end | 1162 end |
1140 end | 1163 end |
1141 | 1164 |
1142 def test_show_should_display_prev_next_links_with_saved_query_in_session | 1165 def test_show_should_display_prev_next_links_with_saved_query_in_session |
1143 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, | 1166 query = IssueQuery.create!(:name => 'test', :is_public => true, :user_id => 1, |
1144 :filters => {'status_id' => {:values => ['5'], :operator => '='}}, | 1167 :filters => {'status_id' => {:values => ['5'], :operator => '='}}, |
1145 :sort_criteria => [['id', 'asc']]) | 1168 :sort_criteria => [['id', 'asc']]) |
1146 @request.session[:query] = {:id => query.id, :project_id => nil} | 1169 @request.session[:query] = {:id => query.id, :project_id => nil} |
1147 | 1170 |
1148 get :show, :id => 11 | 1171 get :show, :id => 11 |
1230 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') | 1253 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2') |
1231 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') | 1254 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3') |
1232 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') | 1255 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3') |
1233 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') | 1256 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '') |
1234 | 1257 |
1235 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, :filters => {}, | 1258 query = IssueQuery.create!(:name => 'test', :is_public => true, :user_id => 1, :filters => {}, |
1236 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']]) | 1259 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']]) |
1237 @request.session[:query] = {:id => query.id, :project_id => nil} | 1260 @request.session[:query] = {:id => query.id, :project_id => nil} |
1238 | 1261 |
1239 get :show, :id => 3 | 1262 get :show, :id => 3 |
1240 assert_response :success | 1263 assert_response :success |
1418 assert_response :success | 1441 assert_response :success |
1419 assert_equal 'application/pdf', @response.content_type | 1442 assert_equal 'application/pdf', @response.content_type |
1420 assert @response.body.starts_with?('%PDF') | 1443 assert @response.body.starts_with?('%PDF') |
1421 end | 1444 end |
1422 | 1445 |
1446 def test_show_invalid_should_respond_with_404 | |
1447 get :show, :id => 999 | |
1448 assert_response 404 | |
1449 end | |
1450 | |
1423 def test_get_new | 1451 def test_get_new |
1424 @request.session[:user_id] = 2 | 1452 @request.session[:user_id] = 2 |
1425 get :new, :project_id => 1, :tracker_id => 1 | 1453 get :new, :project_id => 1, :tracker_id => 1 |
1426 assert_response :success | 1454 assert_response :success |
1427 assert_template 'new' | 1455 assert_template 'new' |
1428 | 1456 |
1429 assert_tag 'input', :attributes => {:name => 'issue[is_private]'} | 1457 assert_select 'form#issue-form' do |
1430 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} | 1458 assert_select 'input[name=?]', 'issue[is_private]' |
1431 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | 1459 assert_select 'select[name=?]', 'issue[project_id]', 0 |
1432 assert_tag 'input', :attributes => {:name => 'issue[subject]'} | 1460 assert_select 'select[name=?]', 'issue[tracker_id]' |
1433 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} | 1461 assert_select 'input[name=?]', 'issue[subject]' |
1434 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} | 1462 assert_select 'textarea[name=?]', 'issue[description]' |
1435 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} | 1463 assert_select 'select[name=?]', 'issue[status_id]' |
1436 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | 1464 assert_select 'select[name=?]', 'issue[priority_id]' |
1437 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} | 1465 assert_select 'select[name=?]', 'issue[assigned_to_id]' |
1438 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | 1466 assert_select 'select[name=?]', 'issue[category_id]' |
1439 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | 1467 assert_select 'select[name=?]', 'issue[fixed_version_id]' |
1440 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} | 1468 assert_select 'input[name=?]', 'issue[parent_issue_id]' |
1441 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} | 1469 assert_select 'input[name=?]', 'issue[start_date]' |
1442 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | 1470 assert_select 'input[name=?]', 'issue[due_date]' |
1443 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } | 1471 assert_select 'select[name=?]', 'issue[done_ratio]' |
1444 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | 1472 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string' |
1473 assert_select 'input[name=?]', 'issue[watcher_user_ids][]' | |
1474 end | |
1445 | 1475 |
1446 # Be sure we don't display inactive IssuePriorities | 1476 # Be sure we don't display inactive IssuePriorities |
1447 assert ! IssuePriority.find(15).active? | 1477 assert ! IssuePriority.find(15).active? |
1448 assert_no_tag :option, :attributes => {:value => '15'}, | 1478 assert_select 'select[name=?]', 'issue[priority_id]' do |
1449 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | 1479 assert_select 'option[value=15]', 0 |
1480 end | |
1450 end | 1481 end |
1451 | 1482 |
1452 def test_get_new_with_minimal_permissions | 1483 def test_get_new_with_minimal_permissions |
1453 Role.find(1).update_attribute :permissions, [:add_issues] | 1484 Role.find(1).update_attribute :permissions, [:add_issues] |
1454 WorkflowTransition.delete_all :role_id => 1 | 1485 WorkflowTransition.delete_all :role_id => 1 |
1456 @request.session[:user_id] = 2 | 1487 @request.session[:user_id] = 2 |
1457 get :new, :project_id => 1, :tracker_id => 1 | 1488 get :new, :project_id => 1, :tracker_id => 1 |
1458 assert_response :success | 1489 assert_response :success |
1459 assert_template 'new' | 1490 assert_template 'new' |
1460 | 1491 |
1461 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'} | 1492 assert_select 'form#issue-form' do |
1462 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'} | 1493 assert_select 'input[name=?]', 'issue[is_private]', 0 |
1463 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'} | 1494 assert_select 'select[name=?]', 'issue[project_id]', 0 |
1464 assert_tag 'input', :attributes => {:name => 'issue[subject]'} | 1495 assert_select 'select[name=?]', 'issue[tracker_id]' |
1465 assert_tag 'textarea', :attributes => {:name => 'issue[description]'} | 1496 assert_select 'input[name=?]', 'issue[subject]' |
1466 assert_tag 'select', :attributes => {:name => 'issue[status_id]'} | 1497 assert_select 'textarea[name=?]', 'issue[description]' |
1467 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'} | 1498 assert_select 'select[name=?]', 'issue[status_id]' |
1468 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'} | 1499 assert_select 'select[name=?]', 'issue[priority_id]' |
1469 assert_tag 'select', :attributes => {:name => 'issue[category_id]'} | 1500 assert_select 'select[name=?]', 'issue[assigned_to_id]' |
1470 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'} | 1501 assert_select 'select[name=?]', 'issue[category_id]' |
1471 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'} | 1502 assert_select 'select[name=?]', 'issue[fixed_version_id]' |
1472 assert_tag 'input', :attributes => {:name => 'issue[start_date]'} | 1503 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
1473 assert_tag 'input', :attributes => {:name => 'issue[due_date]'} | 1504 assert_select 'input[name=?]', 'issue[start_date]' |
1474 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'} | 1505 assert_select 'input[name=?]', 'issue[due_date]' |
1475 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' } | 1506 assert_select 'select[name=?]', 'issue[done_ratio]' |
1476 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'} | 1507 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Default string' |
1508 assert_select 'input[name=?]', 'issue[watcher_user_ids][]', 0 | |
1509 end | |
1477 end | 1510 end |
1478 | 1511 |
1479 def test_get_new_with_list_custom_field | 1512 def test_get_new_with_list_custom_field |
1480 @request.session[:user_id] = 2 | 1513 @request.session[:user_id] = 2 |
1481 get :new, :project_id => 1, :tracker_id => 1 | 1514 get :new, :project_id => 1, :tracker_id => 1 |
1566 def test_get_new_form_should_allow_attachment_upload | 1599 def test_get_new_form_should_allow_attachment_upload |
1567 @request.session[:user_id] = 2 | 1600 @request.session[:user_id] = 2 |
1568 get :new, :project_id => 1, :tracker_id => 1 | 1601 get :new, :project_id => 1, :tracker_id => 1 |
1569 | 1602 |
1570 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do | 1603 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do |
1571 assert_select 'input[name=?][type=file]', 'attachments[1][file]' | 1604 assert_select 'input[name=?][type=file]', 'attachments[dummy][file]' |
1572 assert_select 'input[name=?][maxlength=255]', 'attachments[1][description]' | |
1573 end | 1605 end |
1574 end | 1606 end |
1575 | 1607 |
1576 def test_get_new_should_prefill_the_form_from_params | 1608 def test_get_new_should_prefill_the_form_from_params |
1577 @request.session[:user_id] = 2 | 1609 @request.session[:user_id] = 2 |
1661 get :new, :project_id => 1 | 1693 get :new, :project_id => 1 |
1662 assert_response 500 | 1694 assert_response 500 |
1663 assert_error_tag :content => /No tracker/ | 1695 assert_error_tag :content => /No tracker/ |
1664 end | 1696 end |
1665 | 1697 |
1666 def test_update_new_form | 1698 def test_update_form_for_new_issue |
1667 @request.session[:user_id] = 2 | 1699 @request.session[:user_id] = 2 |
1668 xhr :post, :new, :project_id => 1, | 1700 xhr :post, :update_form, :project_id => 1, |
1669 :issue => {:tracker_id => 2, | 1701 :issue => {:tracker_id => 2, |
1670 :subject => 'This is the test_new issue', | 1702 :subject => 'This is the test_new issue', |
1671 :description => 'This is the description', | 1703 :description => 'This is the description', |
1672 :priority_id => 5} | 1704 :priority_id => 5} |
1673 assert_response :success | 1705 assert_response :success |
1680 assert_equal 1, issue.project_id | 1712 assert_equal 1, issue.project_id |
1681 assert_equal 2, issue.tracker_id | 1713 assert_equal 2, issue.tracker_id |
1682 assert_equal 'This is the test_new issue', issue.subject | 1714 assert_equal 'This is the test_new issue', issue.subject |
1683 end | 1715 end |
1684 | 1716 |
1685 def test_update_new_form_should_propose_transitions_based_on_initial_status | 1717 def test_update_form_for_new_issue_should_propose_transitions_based_on_initial_status |
1686 @request.session[:user_id] = 2 | 1718 @request.session[:user_id] = 2 |
1687 WorkflowTransition.delete_all | 1719 WorkflowTransition.delete_all |
1688 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2) | 1720 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2) |
1689 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5) | 1721 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5) |
1690 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4) | 1722 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4) |
1691 | 1723 |
1692 xhr :post, :new, :project_id => 1, | 1724 xhr :post, :update_form, :project_id => 1, |
1693 :issue => {:tracker_id => 1, | 1725 :issue => {:tracker_id => 1, |
1694 :status_id => 5, | 1726 :status_id => 5, |
1695 :subject => 'This is an issue'} | 1727 :subject => 'This is an issue'} |
1696 | 1728 |
1697 assert_equal 5, assigns(:issue).status_id | 1729 assert_equal 5, assigns(:issue).status_id |
1718 assert_equal 2, issue.author_id | 1750 assert_equal 2, issue.author_id |
1719 assert_equal 3, issue.tracker_id | 1751 assert_equal 3, issue.tracker_id |
1720 assert_equal 2, issue.status_id | 1752 assert_equal 2, issue.status_id |
1721 assert_equal Date.parse('2010-11-07'), issue.start_date | 1753 assert_equal Date.parse('2010-11-07'), issue.start_date |
1722 assert_nil issue.estimated_hours | 1754 assert_nil issue.estimated_hours |
1723 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) | 1755 v = issue.custom_values.where(:custom_field_id => 2).first |
1724 assert_not_nil v | 1756 assert_not_nil v |
1725 assert_equal 'Value for field 2', v.value | 1757 assert_equal 'Value for field 2', v.value |
1726 end | 1758 end |
1727 | 1759 |
1728 def test_post_new_with_group_assignment | 1760 def test_post_new_with_group_assignment |
2080 :priority_id => 6, | 2112 :priority_id => 6, |
2081 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} | 2113 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
2082 assert_response :success | 2114 assert_response :success |
2083 assert_template 'new' | 2115 assert_template 'new' |
2084 | 2116 |
2085 assert_tag :textarea, :attributes => { :name => 'issue[description]' }, | 2117 assert_select 'textarea[name=?]', 'issue[description]', :text => 'This is a description' |
2086 :content => "\nThis is a description" | 2118 assert_select 'select[name=?]', 'issue[priority_id]' do |
2087 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | 2119 assert_select 'option[value=6][selected=selected]', :text => 'High' |
2088 :child => { :tag => 'option', :attributes => { :selected => 'selected', | 2120 end |
2089 :value => '6' }, | |
2090 :content => 'High' } | |
2091 # Custom fields | 2121 # Custom fields |
2092 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, | 2122 assert_select 'select[name=?]', 'issue[custom_field_values][1]' do |
2093 :child => { :tag => 'option', :attributes => { :selected => 'selected', | 2123 assert_select 'option[value=Oracle][selected=selected]', :text => 'Oracle' |
2094 :value => 'Oracle' }, | 2124 end |
2095 :content => 'Oracle' } | 2125 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Value for field 2' |
2096 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', | |
2097 :value => 'Value for field 2'} | |
2098 end | 2126 end |
2099 | 2127 |
2100 def test_post_create_with_failure_should_preserve_watchers | 2128 def test_post_create_with_failure_should_preserve_watchers |
2101 assert !User.find(8).member_of?(Project.find(1)) | 2129 assert !User.find(8).member_of?(Project.find(1)) |
2102 | 2130 |
2105 :issue => {:tracker_id => 1, | 2133 :issue => {:tracker_id => 1, |
2106 :watcher_user_ids => ['3', '8']} | 2134 :watcher_user_ids => ['3', '8']} |
2107 assert_response :success | 2135 assert_response :success |
2108 assert_template 'new' | 2136 assert_template 'new' |
2109 | 2137 |
2110 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil} | 2138 assert_select 'input[name=?][value=2]:not(checked)', 'issue[watcher_user_ids][]' |
2111 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '3', :checked => 'checked'} | 2139 assert_select 'input[name=?][value=3][checked=checked]', 'issue[watcher_user_ids][]' |
2112 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '8', :checked => 'checked'} | 2140 assert_select 'input[name=?][value=8][checked=checked]', 'issue[watcher_user_ids][]' |
2113 end | 2141 end |
2114 | 2142 |
2115 def test_post_create_should_ignore_non_safe_attributes | 2143 def test_post_create_should_ignore_non_safe_attributes |
2116 @request.session[:user_id] = 2 | 2144 @request.session[:user_id] = 2 |
2117 assert_nothing_raised do | 2145 assert_nothing_raised do |
2161 attachment = Attachment.first(:order => 'id DESC') | 2189 attachment = Attachment.first(:order => 'id DESC') |
2162 assert_equal 'testfile.txt', attachment.filename | 2190 assert_equal 'testfile.txt', attachment.filename |
2163 assert File.exists?(attachment.diskfile) | 2191 assert File.exists?(attachment.diskfile) |
2164 assert_nil attachment.container | 2192 assert_nil attachment.container |
2165 | 2193 |
2166 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | 2194 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
2167 assert_tag 'span', :content => /testfile.txt/ | 2195 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
2168 end | 2196 end |
2169 | 2197 |
2170 def test_post_create_with_failure_should_keep_saved_attachments | 2198 def test_post_create_with_failure_should_keep_saved_attachments |
2171 set_tmp_attachments_directory | 2199 set_tmp_attachments_directory |
2172 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | 2200 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
2180 assert_response :success | 2208 assert_response :success |
2181 assert_template 'new' | 2209 assert_template 'new' |
2182 end | 2210 end |
2183 end | 2211 end |
2184 | 2212 |
2185 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | 2213 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
2186 assert_tag 'span', :content => /testfile.txt/ | 2214 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
2187 end | 2215 end |
2188 | 2216 |
2189 def test_post_create_should_attach_saved_attachments | 2217 def test_post_create_should_attach_saved_attachments |
2190 set_tmp_attachments_directory | 2218 set_tmp_attachments_directory |
2191 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | 2219 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
2216 context "#new" do | 2244 context "#new" do |
2217 should "propose default status only" do | 2245 should "propose default status only" do |
2218 get :new, :project_id => 1 | 2246 get :new, :project_id => 1 |
2219 assert_response :success | 2247 assert_response :success |
2220 assert_template 'new' | 2248 assert_template 'new' |
2221 assert_tag :tag => 'select', | 2249 assert_select 'select[name=?]', 'issue[status_id]' do |
2222 :attributes => {:name => 'issue[status_id]'}, | 2250 assert_select 'option', 1 |
2223 :children => {:count => 1}, | 2251 assert_select 'option[value=?]', IssueStatus.default.id.to_s |
2224 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} | 2252 end |
2225 end | 2253 end |
2226 | 2254 |
2227 should "accept default status" do | 2255 should "accept default status" do |
2228 assert_difference 'Issue.count' do | 2256 assert_difference 'Issue.count' do |
2229 post :create, :project_id => 1, | 2257 post :create, :project_id => 1, |
2347 orig = Issue.find(1) | 2375 orig = Issue.find(1) |
2348 assert_equal 1, assigns(:issue).project_id | 2376 assert_equal 1, assigns(:issue).project_id |
2349 assert_equal orig.subject, assigns(:issue).subject | 2377 assert_equal orig.subject, assigns(:issue).subject |
2350 assert assigns(:issue).copy? | 2378 assert assigns(:issue).copy? |
2351 | 2379 |
2352 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} | 2380 assert_select 'form[id=issue-form][action=/projects/ecookbook/issues]' do |
2353 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} | 2381 assert_select 'select[name=?]', 'issue[project_id]' do |
2354 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, | 2382 assert_select 'option[value=1][selected=selected]', :text => 'eCookbook' |
2355 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'} | 2383 assert_select 'option[value=2]:not([selected])', :text => 'OnlineStore' |
2356 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, | 2384 end |
2357 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'} | 2385 assert_select 'input[name=copy_from][value=1]' |
2358 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} | 2386 end |
2359 | 2387 |
2360 # "New issue" menu item should not link to copy | 2388 # "New issue" menu item should not link to copy |
2361 assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]' | 2389 assert_select '#main-menu a.new-issue[href=/projects/ecookbook/issues/new]' |
2362 end | 2390 end |
2363 | 2391 |
2365 @request.session[:user_id] = 2 | 2393 @request.session[:user_id] = 2 |
2366 issue = Issue.find(3) | 2394 issue = Issue.find(3) |
2367 assert issue.attachments.count > 0 | 2395 assert issue.attachments.count > 0 |
2368 get :new, :project_id => 1, :copy_from => 3 | 2396 get :new, :project_id => 1, :copy_from => 3 |
2369 | 2397 |
2370 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} | 2398 assert_select 'input[name=copy_attachments][type=checkbox][checked=checked][value=1]' |
2371 end | 2399 end |
2372 | 2400 |
2373 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox | 2401 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox |
2374 @request.session[:user_id] = 2 | 2402 @request.session[:user_id] = 2 |
2375 issue = Issue.find(3) | 2403 issue = Issue.find(3) |
2376 issue.attachments.delete_all | 2404 issue.attachments.delete_all |
2377 get :new, :project_id => 1, :copy_from => 3 | 2405 get :new, :project_id => 1, :copy_from => 3 |
2378 | 2406 |
2379 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'} | 2407 assert_select 'input[name=copy_attachments]', 0 |
2380 end | 2408 end |
2381 | 2409 |
2382 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox | 2410 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox |
2383 @request.session[:user_id] = 2 | 2411 @request.session[:user_id] = 2 |
2384 issue = Issue.generate_with_descendants! | 2412 issue = Issue.generate_with_descendants! |
2521 assert_template 'new' | 2549 assert_template 'new' |
2522 | 2550 |
2523 assert_not_nil assigns(:issue) | 2551 assert_not_nil assigns(:issue) |
2524 assert assigns(:issue).copy? | 2552 assert assigns(:issue).copy? |
2525 | 2553 |
2526 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'} | 2554 assert_select 'form#issue-form[action=/projects/ecookbook/issues]' do |
2527 assert_tag 'select', :attributes => {:name => 'issue[project_id]'} | 2555 assert_select 'select[name=?]', 'issue[project_id]' do |
2528 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, | 2556 assert_select 'option[value=1]:not([selected])', :text => 'eCookbook' |
2529 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'} | 2557 assert_select 'option[value=2][selected=selected]', :text => 'OnlineStore' |
2530 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}, | 2558 end |
2531 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'} | 2559 assert_select 'input[name=copy_from][value=1]' |
2532 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'} | 2560 end |
2533 end | 2561 end |
2534 | 2562 |
2535 def test_create_as_copy_on_project_without_permission_should_ignore_target_project | 2563 def test_create_as_copy_on_project_without_permission_should_ignore_target_project |
2536 @request.session[:user_id] = 2 | 2564 @request.session[:user_id] = 2 |
2537 assert !User.find(2).member_of?(Project.find(4)) | 2565 assert !User.find(2).member_of?(Project.find(4)) |
2552 assert_not_nil assigns(:issue) | 2580 assert_not_nil assigns(:issue) |
2553 assert_equal Issue.find(1), assigns(:issue) | 2581 assert_equal Issue.find(1), assigns(:issue) |
2554 | 2582 |
2555 # Be sure we don't display inactive IssuePriorities | 2583 # Be sure we don't display inactive IssuePriorities |
2556 assert ! IssuePriority.find(15).active? | 2584 assert ! IssuePriority.find(15).active? |
2557 assert_no_tag :option, :attributes => {:value => '15'}, | 2585 assert_select 'select[name=?]', 'issue[priority_id]' do |
2558 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | 2586 assert_select 'option[value=15]', 0 |
2587 end | |
2559 end | 2588 end |
2560 | 2589 |
2561 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission | 2590 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission |
2562 @request.session[:user_id] = 2 | 2591 @request.session[:user_id] = 2 |
2563 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] | 2592 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time] |
2564 | 2593 |
2565 get :edit, :id => 1 | 2594 get :edit, :id => 1 |
2566 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'} | 2595 assert_select 'input[name=?]', 'time_entry[hours]' |
2567 end | 2596 end |
2568 | 2597 |
2569 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission | 2598 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission |
2570 @request.session[:user_id] = 2 | 2599 @request.session[:user_id] = 2 |
2571 Role.find_by_name('Manager').remove_permission! :log_time | 2600 Role.find_by_name('Manager').remove_permission! :log_time |
2572 | 2601 |
2573 get :edit, :id => 1 | 2602 get :edit, :id => 1 |
2574 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'} | 2603 assert_select 'input[name=?]', 'time_entry[hours]', 0 |
2575 end | 2604 end |
2576 | 2605 |
2577 def test_get_edit_with_params | 2606 def test_get_edit_with_params |
2578 @request.session[:user_id] = 2 | 2607 @request.session[:user_id] = 2 |
2579 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, | 2608 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, |
2580 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } | 2609 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => 10 } |
2581 assert_response :success | 2610 assert_response :success |
2582 assert_template 'edit' | 2611 assert_template 'edit' |
2583 | 2612 |
2584 issue = assigns(:issue) | 2613 issue = assigns(:issue) |
2585 assert_not_nil issue | 2614 assert_not_nil issue |
2586 | 2615 |
2587 assert_equal 5, issue.status_id | 2616 assert_equal 5, issue.status_id |
2588 assert_tag :select, :attributes => { :name => 'issue[status_id]' }, | 2617 assert_select 'select[name=?]', 'issue[status_id]' do |
2589 :child => { :tag => 'option', | 2618 assert_select 'option[value=5][selected=selected]', :text => 'Closed' |
2590 :content => 'Closed', | 2619 end |
2591 :attributes => { :selected => 'selected' } } | |
2592 | 2620 |
2593 assert_equal 7, issue.priority_id | 2621 assert_equal 7, issue.priority_id |
2594 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | 2622 assert_select 'select[name=?]', 'issue[priority_id]' do |
2595 :child => { :tag => 'option', | 2623 assert_select 'option[value=7][selected=selected]', :text => 'Urgent' |
2596 :content => 'Urgent', | 2624 end |
2597 :attributes => { :selected => 'selected' } } | 2625 |
2598 | 2626 assert_select 'input[name=?][value=2.5]', 'time_entry[hours]' |
2599 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } | 2627 assert_select 'select[name=?]', 'time_entry[activity_id]' do |
2600 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, | 2628 assert_select 'option[value=10][selected=selected]', :text => 'Development' |
2601 :child => { :tag => 'option', | 2629 end |
2602 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } } | 2630 assert_select 'input[name=?][value=test_get_edit_with_params]', 'time_entry[comments]' |
2603 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' } | |
2604 end | 2631 end |
2605 | 2632 |
2606 def test_get_edit_with_multi_custom_field | 2633 def test_get_edit_with_multi_custom_field |
2607 field = CustomField.find(1) | 2634 field = CustomField.find(1) |
2608 field.update_attribute :multiple, true | 2635 field.update_attribute :multiple, true |
2613 @request.session[:user_id] = 2 | 2640 @request.session[:user_id] = 2 |
2614 get :edit, :id => 1 | 2641 get :edit, :id => 1 |
2615 assert_response :success | 2642 assert_response :success |
2616 assert_template 'edit' | 2643 assert_template 'edit' |
2617 | 2644 |
2618 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'} | 2645 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do |
2619 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, | 2646 assert_select 'option', 3 |
2620 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}} | 2647 assert_select 'option[value=MySQL][selected=selected]' |
2621 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, | 2648 assert_select 'option[value=Oracle][selected=selected]' |
2622 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}} | 2649 assert_select 'option[value=PostgreSQL]:not([selected])' |
2623 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'}, | 2650 end |
2624 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}} | 2651 end |
2625 end | 2652 |
2626 | 2653 def test_update_form_for_existing_issue |
2627 def test_update_edit_form | 2654 @request.session[:user_id] = 2 |
2628 @request.session[:user_id] = 2 | 2655 xhr :put, :update_form, :project_id => 1, |
2629 xhr :put, :new, :project_id => 1, | |
2630 :id => 1, | 2656 :id => 1, |
2631 :issue => {:tracker_id => 2, | 2657 :issue => {:tracker_id => 2, |
2632 :subject => 'This is the test_new issue', | 2658 :subject => 'This is the test_new issue', |
2633 :description => 'This is the description', | 2659 :description => 'This is the description', |
2634 :priority_id => 5} | 2660 :priority_id => 5} |
2643 assert_equal 1, issue.project_id | 2669 assert_equal 1, issue.project_id |
2644 assert_equal 2, issue.tracker_id | 2670 assert_equal 2, issue.tracker_id |
2645 assert_equal 'This is the test_new issue', issue.subject | 2671 assert_equal 'This is the test_new issue', issue.subject |
2646 end | 2672 end |
2647 | 2673 |
2648 def test_update_edit_form_should_keep_issue_author | 2674 def test_update_form_for_existing_issue_should_keep_issue_author |
2649 @request.session[:user_id] = 3 | 2675 @request.session[:user_id] = 3 |
2650 xhr :put, :new, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'} | 2676 xhr :put, :update_form, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'} |
2651 assert_response :success | 2677 assert_response :success |
2652 assert_equal 'text/javascript', response.content_type | 2678 assert_equal 'text/javascript', response.content_type |
2653 | 2679 |
2654 issue = assigns(:issue) | 2680 issue = assigns(:issue) |
2655 assert_equal User.find(2), issue.author | 2681 assert_equal User.find(2), issue.author |
2656 assert_equal 2, issue.author_id | 2682 assert_equal 2, issue.author_id |
2657 assert_not_equal User.current, issue.author | 2683 assert_not_equal User.current, issue.author |
2658 end | 2684 end |
2659 | 2685 |
2660 def test_update_edit_form_should_propose_transitions_based_on_initial_status | 2686 def test_update_form_for_existing_issue_should_propose_transitions_based_on_initial_status |
2661 @request.session[:user_id] = 2 | 2687 @request.session[:user_id] = 2 |
2662 WorkflowTransition.delete_all | 2688 WorkflowTransition.delete_all |
2663 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) | 2689 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1) |
2664 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) | 2690 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5) |
2665 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4) | 2691 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4) |
2666 | 2692 |
2667 xhr :put, :new, :project_id => 1, | 2693 xhr :put, :update_form, :project_id => 1, |
2668 :id => 2, | 2694 :id => 2, |
2669 :issue => {:tracker_id => 2, | 2695 :issue => {:tracker_id => 2, |
2670 :status_id => 5, | 2696 :status_id => 5, |
2671 :subject => 'This is an issue'} | 2697 :subject => 'This is an issue'} |
2672 | 2698 |
2673 assert_equal 5, assigns(:issue).status_id | 2699 assert_equal 5, assigns(:issue).status_id |
2674 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort | 2700 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort |
2675 end | 2701 end |
2676 | 2702 |
2677 def test_update_edit_form_with_project_change | 2703 def test_update_form_for_existing_issue_with_project_change |
2678 @request.session[:user_id] = 2 | 2704 @request.session[:user_id] = 2 |
2679 xhr :put, :new, :project_id => 1, | 2705 xhr :put, :update_form, :project_id => 1, |
2680 :id => 1, | 2706 :id => 1, |
2681 :issue => {:project_id => 2, | 2707 :issue => {:project_id => 2, |
2682 :tracker_id => 2, | 2708 :tracker_id => 2, |
2683 :subject => 'This is the test_new issue', | 2709 :subject => 'This is the test_new issue', |
2684 :description => 'This is the description', | 2710 :description => 'This is the description', |
2829 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } | 2855 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first } |
2830 end | 2856 end |
2831 assert_redirected_to :action => 'show', :id => '1' | 2857 assert_redirected_to :action => 'show', :id => '1' |
2832 issue.reload | 2858 issue.reload |
2833 assert_equal 2, issue.status_id | 2859 assert_equal 2, issue.status_id |
2834 j = Journal.find(:first, :order => 'id DESC') | 2860 j = Journal.order('id DESC').first |
2835 assert_equal 'Assigned to dlopper', j.notes | 2861 assert_equal 'Assigned to dlopper', j.notes |
2836 assert_equal 2, j.details.size | 2862 assert_equal 2, j.details.size |
2837 | 2863 |
2838 mail = ActionMailer::Base.deliveries.last | 2864 mail = ActionMailer::Base.deliveries.last |
2839 assert_mail_body_match "Status changed from New to Assigned", mail | 2865 assert_mail_body_match "Status changed from New to Assigned", mail |
2846 # anonymous user | 2872 # anonymous user |
2847 put :update, | 2873 put :update, |
2848 :id => 1, | 2874 :id => 1, |
2849 :issue => { :notes => notes } | 2875 :issue => { :notes => notes } |
2850 assert_redirected_to :action => 'show', :id => '1' | 2876 assert_redirected_to :action => 'show', :id => '1' |
2851 j = Journal.find(:first, :order => 'id DESC') | 2877 j = Journal.order('id DESC').first |
2852 assert_equal notes, j.notes | 2878 assert_equal notes, j.notes |
2853 assert_equal 0, j.details.size | 2879 assert_equal 0, j.details.size |
2854 assert_equal User.anonymous, j.user | 2880 assert_equal User.anonymous, j.user |
2855 | 2881 |
2856 mail = ActionMailer::Base.deliveries.last | 2882 mail = ActionMailer::Base.deliveries.last |
2902 end | 2928 end |
2903 assert_redirected_to :action => 'show', :id => '1' | 2929 assert_redirected_to :action => 'show', :id => '1' |
2904 | 2930 |
2905 issue = Issue.find(1) | 2931 issue = Issue.find(1) |
2906 | 2932 |
2907 j = Journal.find(:first, :order => 'id DESC') | 2933 j = Journal.order('id DESC').first |
2908 assert_equal '2.5 hours added', j.notes | 2934 assert_equal '2.5 hours added', j.notes |
2909 assert_equal 0, j.details.size | 2935 assert_equal 0, j.details.size |
2910 | 2936 |
2911 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') | 2937 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') |
2912 assert_not_nil t | 2938 assert_not_nil t |
2941 :issue => {:notes => ''}, | 2967 :issue => {:notes => ''}, |
2942 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} | 2968 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} |
2943 end | 2969 end |
2944 | 2970 |
2945 assert_redirected_to :action => 'show', :id => '1' | 2971 assert_redirected_to :action => 'show', :id => '1' |
2946 j = Issue.find(1).journals.find(:first, :order => 'id DESC') | 2972 j = Issue.find(1).journals.reorder('id DESC').first |
2947 assert j.notes.blank? | 2973 assert j.notes.blank? |
2948 assert_equal 1, j.details.size | 2974 assert_equal 1, j.details.size |
2949 assert_equal 'testfile.txt', j.details.first.value | 2975 assert_equal 'testfile.txt', j.details.first.value |
2950 assert_equal User.anonymous, j.user | 2976 assert_equal User.anonymous, j.user |
2951 | 2977 |
2980 attachment = Attachment.first(:order => 'id DESC') | 3006 attachment = Attachment.first(:order => 'id DESC') |
2981 assert_equal 'testfile.txt', attachment.filename | 3007 assert_equal 'testfile.txt', attachment.filename |
2982 assert File.exists?(attachment.diskfile) | 3008 assert File.exists?(attachment.diskfile) |
2983 assert_nil attachment.container | 3009 assert_nil attachment.container |
2984 | 3010 |
2985 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | 3011 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
2986 assert_tag 'span', :content => /testfile.txt/ | 3012 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
2987 end | 3013 end |
2988 | 3014 |
2989 def test_put_update_with_failure_should_keep_saved_attachments | 3015 def test_put_update_with_failure_should_keep_saved_attachments |
2990 set_tmp_attachments_directory | 3016 set_tmp_attachments_directory |
2991 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | 3017 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
2999 assert_response :success | 3025 assert_response :success |
3000 assert_template 'edit' | 3026 assert_template 'edit' |
3001 end | 3027 end |
3002 end | 3028 end |
3003 | 3029 |
3004 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token} | 3030 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token |
3005 assert_tag 'span', :content => /testfile.txt/ | 3031 assert_select 'input[name=?][value=?]', 'attachments[p0][filename]', 'testfile.txt' |
3006 end | 3032 end |
3007 | 3033 |
3008 def test_put_update_should_attach_saved_attachments | 3034 def test_put_update_should_attach_saved_attachments |
3009 set_tmp_attachments_directory | 3035 set_tmp_attachments_directory |
3010 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) | 3036 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2) |
3090 end | 3116 end |
3091 assert_response :success | 3117 assert_response :success |
3092 assert_template 'edit' | 3118 assert_template 'edit' |
3093 | 3119 |
3094 assert_error_tag :descendant => {:content => /Activity can't be blank/} | 3120 assert_error_tag :descendant => {:content => /Activity can't be blank/} |
3095 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes | 3121 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes |
3096 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } | 3122 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z' |
3097 end | 3123 end |
3098 | 3124 |
3099 def test_put_update_with_invalid_spent_time_comments_only | 3125 def test_put_update_with_invalid_spent_time_comments_only |
3100 @request.session[:user_id] = 2 | 3126 @request.session[:user_id] = 2 |
3101 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | 3127 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
3109 assert_response :success | 3135 assert_response :success |
3110 assert_template 'edit' | 3136 assert_template 'edit' |
3111 | 3137 |
3112 assert_error_tag :descendant => {:content => /Activity can't be blank/} | 3138 assert_error_tag :descendant => {:content => /Activity can't be blank/} |
3113 assert_error_tag :descendant => {:content => /Hours can't be blank/} | 3139 assert_error_tag :descendant => {:content => /Hours can't be blank/} |
3114 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes | 3140 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes |
3115 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" } | 3141 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment' |
3116 end | 3142 end |
3117 | 3143 |
3118 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject | 3144 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject |
3119 issue = Issue.find(2) | 3145 issue = Issue.find(2) |
3120 @request.session[:user_id] = 2 | 3146 @request.session[:user_id] = 2 |
3165 @request.session[:user_id] = 2 | 3191 @request.session[:user_id] = 2 |
3166 get :bulk_edit, :ids => [1, 2] | 3192 get :bulk_edit, :ids => [1, 2] |
3167 assert_response :success | 3193 assert_response :success |
3168 assert_template 'bulk_edit' | 3194 assert_template 'bulk_edit' |
3169 | 3195 |
3170 assert_tag :select, :attributes => {:name => 'issue[project_id]'} | 3196 assert_select 'ul#bulk-selection' do |
3171 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} | 3197 assert_select 'li', 2 |
3172 | 3198 assert_select 'li a', :text => 'Bug #1' |
3173 # Project specific custom field, date type | 3199 end |
3174 field = CustomField.find(9) | 3200 |
3175 assert !field.is_for_all? | 3201 assert_select 'form#bulk_edit_form[action=?]', '/issues/bulk_update' do |
3176 assert_equal 'date', field.field_format | 3202 assert_select 'input[name=?]', 'ids[]', 2 |
3177 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | 3203 assert_select 'input[name=?][value=1][type=hidden]', 'ids[]' |
3178 | 3204 |
3179 # System wide custom field | 3205 assert_select 'select[name=?]', 'issue[project_id]' |
3180 assert CustomField.find(1).is_for_all? | 3206 assert_select 'input[name=?]', 'issue[parent_issue_id]' |
3181 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} | 3207 |
3182 | 3208 # Project specific custom field, date type |
3183 # Be sure we don't display inactive IssuePriorities | 3209 field = CustomField.find(9) |
3184 assert ! IssuePriority.find(15).active? | 3210 assert !field.is_for_all? |
3185 assert_no_tag :option, :attributes => {:value => '15'}, | 3211 assert_equal 'date', field.field_format |
3186 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} } | 3212 assert_select 'input[name=?]', 'issue[custom_field_values][9]' |
3213 | |
3214 # System wide custom field | |
3215 assert CustomField.find(1).is_for_all? | |
3216 assert_select 'select[name=?]', 'issue[custom_field_values][1]' | |
3217 | |
3218 # Be sure we don't display inactive IssuePriorities | |
3219 assert ! IssuePriority.find(15).active? | |
3220 assert_select 'select[name=?]', 'issue[priority_id]' do | |
3221 assert_select 'option[value=15]', 0 | |
3222 end | |
3223 end | |
3187 end | 3224 end |
3188 | 3225 |
3189 def test_get_bulk_edit_on_different_projects | 3226 def test_get_bulk_edit_on_different_projects |
3190 @request.session[:user_id] = 2 | 3227 @request.session[:user_id] = 2 |
3191 get :bulk_edit, :ids => [1, 2, 6] | 3228 get :bulk_edit, :ids => [1, 2, 6] |
3192 assert_response :success | 3229 assert_response :success |
3193 assert_template 'bulk_edit' | 3230 assert_template 'bulk_edit' |
3194 | 3231 |
3195 # Can not set issues from different projects as children of an issue | 3232 # Can not set issues from different projects as children of an issue |
3196 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} | 3233 assert_select 'input[name=?]', 'issue[parent_issue_id]', 0 |
3197 | 3234 |
3198 # Project specific custom field, date type | 3235 # Project specific custom field, date type |
3199 field = CustomField.find(9) | 3236 field = CustomField.find(9) |
3200 assert !field.is_for_all? | 3237 assert !field.is_for_all? |
3201 assert !field.project_ids.include?(Issue.find(6).project_id) | 3238 assert !field.project_ids.include?(Issue.find(6).project_id) |
3202 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | 3239 assert_select 'input[name=?]', 'issue[custom_field_values][9]', 0 |
3203 end | 3240 end |
3204 | 3241 |
3205 def test_get_bulk_edit_with_user_custom_field | 3242 def test_get_bulk_edit_with_user_custom_field |
3206 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) | 3243 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) |
3207 | 3244 |
3208 @request.session[:user_id] = 2 | 3245 @request.session[:user_id] = 2 |
3209 get :bulk_edit, :ids => [1, 2] | 3246 get :bulk_edit, :ids => [1, 2] |
3210 assert_response :success | 3247 assert_response :success |
3211 assert_template 'bulk_edit' | 3248 assert_template 'bulk_edit' |
3212 | 3249 |
3213 assert_tag :select, | 3250 assert_select 'select.user_cf[name=?]', "issue[custom_field_values][#{field.id}]" do |
3214 :attributes => {:name => "issue[custom_field_values][#{field.id}]", :class => 'user_cf'}, | 3251 assert_select 'option', Project.find(1).users.count + 2 # "no change" + "none" options |
3215 :children => { | 3252 end |
3216 :only => {:tag => 'option'}, | |
3217 :count => Project.find(1).users.count + 2 # "no change" + "none" options | |
3218 } | |
3219 end | 3253 end |
3220 | 3254 |
3221 def test_get_bulk_edit_with_version_custom_field | 3255 def test_get_bulk_edit_with_version_custom_field |
3222 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) | 3256 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) |
3223 | 3257 |
3224 @request.session[:user_id] = 2 | 3258 @request.session[:user_id] = 2 |
3225 get :bulk_edit, :ids => [1, 2] | 3259 get :bulk_edit, :ids => [1, 2] |
3226 assert_response :success | 3260 assert_response :success |
3227 assert_template 'bulk_edit' | 3261 assert_template 'bulk_edit' |
3228 | 3262 |
3229 assert_tag :select, | 3263 assert_select 'select.version_cf[name=?]', "issue[custom_field_values][#{field.id}]" do |
3230 :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, | 3264 assert_select 'option', Project.find(1).shared_versions.count + 2 # "no change" + "none" options |
3231 :children => { | 3265 end |
3232 :only => {:tag => 'option'}, | |
3233 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options | |
3234 } | |
3235 end | 3266 end |
3236 | 3267 |
3237 def test_get_bulk_edit_with_multi_custom_field | 3268 def test_get_bulk_edit_with_multi_custom_field |
3238 field = CustomField.find(1) | 3269 field = CustomField.find(1) |
3239 field.update_attribute :multiple, true | 3270 field.update_attribute :multiple, true |
3241 @request.session[:user_id] = 2 | 3272 @request.session[:user_id] = 2 |
3242 get :bulk_edit, :ids => [1, 2] | 3273 get :bulk_edit, :ids => [1, 2] |
3243 assert_response :success | 3274 assert_response :success |
3244 assert_template 'bulk_edit' | 3275 assert_template 'bulk_edit' |
3245 | 3276 |
3246 assert_tag :select, | 3277 assert_select 'select[name=?]', 'issue[custom_field_values][1][]' do |
3247 :attributes => {:name => "issue[custom_field_values][1][]"}, | 3278 assert_select 'option', field.possible_values.size + 1 # "none" options |
3248 :children => { | 3279 end |
3249 :only => {:tag => 'option'}, | |
3250 :count => field.possible_values.size + 1 # "none" options | |
3251 } | |
3252 end | 3280 end |
3253 | 3281 |
3254 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues | 3282 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues |
3255 WorkflowTransition.delete_all | 3283 WorkflowTransition.delete_all |
3256 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1) | 3284 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1) |
3265 assert_response :success | 3293 assert_response :success |
3266 statuses = assigns(:available_statuses) | 3294 statuses = assigns(:available_statuses) |
3267 assert_not_nil statuses | 3295 assert_not_nil statuses |
3268 assert_equal [1, 3], statuses.map(&:id).sort | 3296 assert_equal [1, 3], statuses.map(&:id).sort |
3269 | 3297 |
3270 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}, | 3298 assert_select 'select[name=?]', 'issue[status_id]' do |
3271 :children => {:count => 3} # 2 statuses + "no change" option | 3299 assert_select 'option', 3 # 2 statuses + "no change" option |
3300 end | |
3272 end | 3301 end |
3273 | 3302 |
3274 def test_bulk_edit_should_propose_target_project_open_shared_versions | 3303 def test_bulk_edit_should_propose_target_project_open_shared_versions |
3275 @request.session[:user_id] = 2 | 3304 @request.session[:user_id] = 2 |
3276 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} | 3305 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} |
3277 assert_response :success | 3306 assert_response :success |
3278 assert_template 'bulk_edit' | 3307 assert_template 'bulk_edit' |
3279 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort | 3308 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort |
3280 assert_tag 'select', | 3309 |
3281 :attributes => {:name => 'issue[fixed_version_id]'}, | 3310 assert_select 'select[name=?]', 'issue[fixed_version_id]' do |
3282 :descendant => {:tag => 'option', :content => '2.0'} | 3311 assert_select 'option', :text => '2.0' |
3312 end | |
3283 end | 3313 end |
3284 | 3314 |
3285 def test_bulk_edit_should_propose_target_project_categories | 3315 def test_bulk_edit_should_propose_target_project_categories |
3286 @request.session[:user_id] = 2 | 3316 @request.session[:user_id] = 2 |
3287 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} | 3317 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1} |
3288 assert_response :success | 3318 assert_response :success |
3289 assert_template 'bulk_edit' | 3319 assert_template 'bulk_edit' |
3290 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort | 3320 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort |
3291 assert_tag 'select', | 3321 |
3292 :attributes => {:name => 'issue[category_id]'}, | 3322 assert_select 'select[name=?]', 'issue[category_id]' do |
3293 :descendant => {:tag => 'option', :content => 'Recipes'} | 3323 assert_select 'option', :text => 'Recipes' |
3324 end | |
3294 end | 3325 end |
3295 | 3326 |
3296 def test_bulk_update | 3327 def test_bulk_update |
3297 @request.session[:user_id] = 2 | 3328 @request.session[:user_id] = 2 |
3298 # update issues priority | 3329 # update issues priority |
3304 assert_response 302 | 3335 assert_response 302 |
3305 # check that the issues were updated | 3336 # check that the issues were updated |
3306 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | 3337 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
3307 | 3338 |
3308 issue = Issue.find(1) | 3339 issue = Issue.find(1) |
3309 journal = issue.journals.find(:first, :order => 'created_on DESC') | 3340 journal = issue.journals.reorder('created_on DESC').first |
3310 assert_equal '125', issue.custom_value_for(2).value | 3341 assert_equal '125', issue.custom_value_for(2).value |
3311 assert_equal 'Bulk editing', journal.notes | 3342 assert_equal 'Bulk editing', journal.notes |
3312 assert_equal 1, journal.details.size | 3343 assert_equal 1, journal.details.size |
3313 end | 3344 end |
3314 | 3345 |
3339 assert_response 302 | 3370 assert_response 302 |
3340 # check that the issues were updated | 3371 # check that the issues were updated |
3341 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) | 3372 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) |
3342 | 3373 |
3343 issue = Issue.find(1) | 3374 issue = Issue.find(1) |
3344 journal = issue.journals.find(:first, :order => 'created_on DESC') | 3375 journal = issue.journals.reorder('created_on DESC').first |
3345 assert_equal '125', issue.custom_value_for(2).value | 3376 assert_equal '125', issue.custom_value_for(2).value |
3346 assert_equal 'Bulk editing', journal.notes | 3377 assert_equal 'Bulk editing', journal.notes |
3347 assert_equal 1, journal.details.size | 3378 assert_equal 1, journal.details.size |
3348 end | 3379 end |
3349 | 3380 |
3441 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes | 3472 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes |
3442 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes | 3473 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes |
3443 end | 3474 end |
3444 | 3475 |
3445 def test_bulk_update_parent_id | 3476 def test_bulk_update_parent_id |
3477 IssueRelation.delete_all | |
3478 | |
3446 @request.session[:user_id] = 2 | 3479 @request.session[:user_id] = 2 |
3447 post :bulk_update, :ids => [1, 3], | 3480 post :bulk_update, :ids => [1, 3], |
3448 :notes => 'Bulk editing parent', | 3481 :notes => 'Bulk editing parent', |
3449 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} | 3482 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} |
3450 | 3483 |
3464 :custom_field_values => {'2' => '777'}} | 3497 :custom_field_values => {'2' => '777'}} |
3465 | 3498 |
3466 assert_response 302 | 3499 assert_response 302 |
3467 | 3500 |
3468 issue = Issue.find(1) | 3501 issue = Issue.find(1) |
3469 journal = issue.journals.find(:first, :order => 'created_on DESC') | 3502 journal = issue.journals.reorder('created_on DESC').first |
3470 assert_equal '777', issue.custom_value_for(2).value | 3503 assert_equal '777', issue.custom_value_for(2).value |
3471 assert_equal 1, journal.details.size | 3504 assert_equal 1, journal.details.size |
3472 assert_equal '125', journal.details.first.old_value | 3505 assert_equal '125', journal.details.first.old_value |
3473 assert_equal '777', journal.details.first.value | 3506 assert_equal '777', journal.details.first.value |
3474 end | 3507 end |
3776 end | 3809 end |
3777 assert_response :success | 3810 assert_response :success |
3778 assert_template 'destroy' | 3811 assert_template 'destroy' |
3779 assert_not_nil assigns(:hours) | 3812 assert_not_nil assigns(:hours) |
3780 assert Issue.find_by_id(1) && Issue.find_by_id(3) | 3813 assert Issue.find_by_id(1) && Issue.find_by_id(3) |
3781 assert_tag 'form', | 3814 |
3782 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}} | 3815 assert_select 'form' do |
3816 assert_select 'input[name=_method][value=delete]' | |
3817 end | |
3783 end | 3818 end |
3784 | 3819 |
3785 def test_destroy_issues_and_destroy_time_entries | 3820 def test_destroy_issues_and_destroy_time_entries |
3786 @request.session[:user_id] = 2 | 3821 @request.session[:user_id] = 2 |
3787 | 3822 |
3843 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' | 3878 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy' |
3844 end | 3879 end |
3845 assert_response 302 | 3880 assert_response 302 |
3846 end | 3881 end |
3847 | 3882 |
3883 def test_destroy_invalid_should_respond_with_404 | |
3884 @request.session[:user_id] = 2 | |
3885 assert_no_difference 'Issue.count' do | |
3886 delete :destroy, :id => 999 | |
3887 end | |
3888 assert_response 404 | |
3889 end | |
3890 | |
3848 def test_default_search_scope | 3891 def test_default_search_scope |
3849 get :index | 3892 get :index |
3850 assert_tag :div, :attributes => {:id => 'quick-search'}, | 3893 |
3851 :child => {:tag => 'form', | 3894 assert_select 'div#quick-search form' do |
3852 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} | 3895 assert_select 'input[name=issues][value=1][type=hidden]' |
3896 end | |
3853 end | 3897 end |
3854 end | 3898 end |