##// END OF EJS Templates
Don't use auth_sources fixtures when not needed....
Jean-Philippe Lang -
r8795:a9161a3fdeff
parent child
Show More
@@ -1,144 +1,143
1 require File.expand_path('../../test_helper', __FILE__)
1 require File.expand_path('../../test_helper', __FILE__)
2
2
3 class ActivitiesControllerTest < ActionController::TestCase
3 class ActivitiesControllerTest < ActionController::TestCase
4 fixtures :projects, :trackers, :issue_statuses, :issues,
4 fixtures :projects, :trackers, :issue_statuses, :issues,
5 :enumerations, :users, :issue_categories,
5 :enumerations, :users, :issue_categories,
6 :projects_trackers,
6 :projects_trackers,
7 :roles,
7 :roles,
8 :member_roles,
8 :member_roles,
9 :members,
9 :members,
10 :groups_users,
10 :groups_users,
11 :enabled_modules,
11 :enabled_modules,
12 :workflows,
12 :workflows,
13 :auth_sources,
14 :journals, :journal_details
13 :journals, :journal_details
15
14
16
15
17 def test_project_index
16 def test_project_index
18 get :index, :id => 1, :with_subprojects => 0
17 get :index, :id => 1, :with_subprojects => 0
19 assert_response :success
18 assert_response :success
20 assert_template 'index'
19 assert_template 'index'
21 assert_not_nil assigns(:events_by_day)
20 assert_not_nil assigns(:events_by_day)
22
21
23 assert_tag :tag => "h3",
22 assert_tag :tag => "h3",
24 :content => /#{2.days.ago.to_date.day}/,
23 :content => /#{2.days.ago.to_date.day}/,
25 :sibling => { :tag => "dl",
24 :sibling => { :tag => "dl",
26 :child => { :tag => "dt",
25 :child => { :tag => "dt",
27 :attributes => { :class => /issue-edit/ },
26 :attributes => { :class => /issue-edit/ },
28 :child => { :tag => "a",
27 :child => { :tag => "a",
29 :content => /(#{IssueStatus.find(2).name})/,
28 :content => /(#{IssueStatus.find(2).name})/,
30 }
29 }
31 }
30 }
32 }
31 }
33 end
32 end
34
33
35 def test_project_index_with_invalid_project_id_should_respond_404
34 def test_project_index_with_invalid_project_id_should_respond_404
36 get :index, :id => 299
35 get :index, :id => 299
37 assert_response 404
36 assert_response 404
38 end
37 end
39
38
40 def test_previous_project_index
39 def test_previous_project_index
41 get :index, :id => 1, :from => 3.days.ago.to_date
40 get :index, :id => 1, :from => 3.days.ago.to_date
42 assert_response :success
41 assert_response :success
43 assert_template 'index'
42 assert_template 'index'
44 assert_not_nil assigns(:events_by_day)
43 assert_not_nil assigns(:events_by_day)
45
44
46 assert_tag :tag => "h3",
45 assert_tag :tag => "h3",
47 :content => /#{3.day.ago.to_date.day}/,
46 :content => /#{3.day.ago.to_date.day}/,
48 :sibling => { :tag => "dl",
47 :sibling => { :tag => "dl",
49 :child => { :tag => "dt",
48 :child => { :tag => "dt",
50 :attributes => { :class => /issue/ },
49 :attributes => { :class => /issue/ },
51 :child => { :tag => "a",
50 :child => { :tag => "a",
52 :content => /#{Issue.find(1).subject}/,
51 :content => /#{Issue.find(1).subject}/,
53 }
52 }
54 }
53 }
55 }
54 }
56 end
55 end
57
56
58 def test_global_index
57 def test_global_index
59 get :index
58 get :index
60 assert_response :success
59 assert_response :success
61 assert_template 'index'
60 assert_template 'index'
62 assert_not_nil assigns(:events_by_day)
61 assert_not_nil assigns(:events_by_day)
63
62
64 assert_tag :tag => "h3",
63 assert_tag :tag => "h3",
65 :content => /#{5.day.ago.to_date.day}/,
64 :content => /#{5.day.ago.to_date.day}/,
66 :sibling => { :tag => "dl",
65 :sibling => { :tag => "dl",
67 :child => { :tag => "dt",
66 :child => { :tag => "dt",
68 :attributes => { :class => /issue/ },
67 :attributes => { :class => /issue/ },
69 :child => { :tag => "a",
68 :child => { :tag => "a",
70 :content => /#{Issue.find(5).subject}/,
69 :content => /#{Issue.find(5).subject}/,
71 }
70 }
72 }
71 }
73 }
72 }
74 end
73 end
75
74
76 def test_user_index
75 def test_user_index
77 get :index, :user_id => 2
76 get :index, :user_id => 2
78 assert_response :success
77 assert_response :success
79 assert_template 'index'
78 assert_template 'index'
80 assert_not_nil assigns(:events_by_day)
79 assert_not_nil assigns(:events_by_day)
81
80
82 assert_tag :tag => "h3",
81 assert_tag :tag => "h3",
83 :content => /#{3.day.ago.to_date.day}/,
82 :content => /#{3.day.ago.to_date.day}/,
84 :sibling => { :tag => "dl",
83 :sibling => { :tag => "dl",
85 :child => { :tag => "dt",
84 :child => { :tag => "dt",
86 :attributes => { :class => /issue/ },
85 :attributes => { :class => /issue/ },
87 :child => { :tag => "a",
86 :child => { :tag => "a",
88 :content => /#{Issue.find(1).subject}/,
87 :content => /#{Issue.find(1).subject}/,
89 }
88 }
90 }
89 }
91 }
90 }
92 end
91 end
93
92
94 def test_user_index_with_invalid_user_id_should_respond_404
93 def test_user_index_with_invalid_user_id_should_respond_404
95 get :index, :user_id => 299
94 get :index, :user_id => 299
96 assert_response 404
95 assert_response 404
97 end
96 end
98
97
99 def test_index_atom_feed
98 def test_index_atom_feed
100 get :index, :format => 'atom', :with_subprojects => 0
99 get :index, :format => 'atom', :with_subprojects => 0
101 assert_response :success
100 assert_response :success
102 assert_template 'common/feed.atom'
101 assert_template 'common/feed.atom'
103
102
104 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
103 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
105 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
104 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
106 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
105 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
107 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}
106 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}
108
107
109 assert_tag :tag => 'entry', :child => {
108 assert_tag :tag => 'entry', :child => {
110 :tag => 'link',
109 :tag => 'link',
111 :attributes => {:href => 'http://test.host/issues/11'}}
110 :attributes => {:href => 'http://test.host/issues/11'}}
112 end
111 end
113
112
114 def test_index_atom_feed_with_explicit_selection
113 def test_index_atom_feed_with_explicit_selection
115 get :index, :format => 'atom', :with_subprojects => 0,
114 get :index, :format => 'atom', :with_subprojects => 0,
116 :show_changesets => 1,
115 :show_changesets => 1,
117 :show_documents => 1,
116 :show_documents => 1,
118 :show_files => 1,
117 :show_files => 1,
119 :show_issues => 1,
118 :show_issues => 1,
120 :show_messages => 1,
119 :show_messages => 1,
121 :show_news => 1,
120 :show_news => 1,
122 :show_time_entries => 1,
121 :show_time_entries => 1,
123 :show_wiki_edits => 1
122 :show_wiki_edits => 1
124
123
125 assert_response :success
124 assert_response :success
126 assert_template 'common/feed.atom'
125 assert_template 'common/feed.atom'
127
126
128 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
127 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
129 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
128 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
130 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
129 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
131 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
130 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
132
131
133 assert_tag :tag => 'entry', :child => {
132 assert_tag :tag => 'entry', :child => {
134 :tag => 'link',
133 :tag => 'link',
135 :attributes => {:href => 'http://test.host/issues/11'}}
134 :attributes => {:href => 'http://test.host/issues/11'}}
136 end
135 end
137
136
138 def test_index_atom_feed_with_one_item_type
137 def test_index_atom_feed_with_one_item_type
139 get :index, :format => 'atom', :show_issues => '1'
138 get :index, :format => 'atom', :show_issues => '1'
140 assert_response :success
139 assert_response :success
141 assert_template 'common/feed.atom'
140 assert_template 'common/feed.atom'
142 assert_tag :tag => 'title', :content => /Issues/
141 assert_tag :tag => 'title', :content => /Issues/
143 end
142 end
144 end
143 end
@@ -1,44 +1,43
1 require File.expand_path('../../test_helper', __FILE__)
1 require File.expand_path('../../test_helper', __FILE__)
2
2
3 class AutoCompletesControllerTest < ActionController::TestCase
3 class AutoCompletesControllerTest < ActionController::TestCase
4 fixtures :projects, :issues, :issue_statuses,
4 fixtures :projects, :issues, :issue_statuses,
5 :enumerations, :users, :issue_categories,
5 :enumerations, :users, :issue_categories,
6 :trackers,
6 :trackers,
7 :projects_trackers,
7 :projects_trackers,
8 :roles,
8 :roles,
9 :member_roles,
9 :member_roles,
10 :members,
10 :members,
11 :auth_sources,
12 :enabled_modules,
11 :enabled_modules,
13 :workflows,
12 :workflows,
14 :journals, :journal_details
13 :journals, :journal_details
15
14
16 def test_issues_should_not_be_case_sensitive
15 def test_issues_should_not_be_case_sensitive
17 get :issues, :project_id => 'ecookbook', :q => 'ReCiPe'
16 get :issues, :project_id => 'ecookbook', :q => 'ReCiPe'
18 assert_response :success
17 assert_response :success
19 assert_not_nil assigns(:issues)
18 assert_not_nil assigns(:issues)
20 assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
19 assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
21 end
20 end
22
21
23 def test_issues_should_return_issue_with_given_id
22 def test_issues_should_return_issue_with_given_id
24 get :issues, :project_id => 'subproject1', :q => '13'
23 get :issues, :project_id => 'subproject1', :q => '13'
25 assert_response :success
24 assert_response :success
26 assert_not_nil assigns(:issues)
25 assert_not_nil assigns(:issues)
27 assert assigns(:issues).include?(Issue.find(13))
26 assert assigns(:issues).include?(Issue.find(13))
28 end
27 end
29
28
30 def test_auto_complete_with_scope_all_and_cross_project_relations
29 def test_auto_complete_with_scope_all_and_cross_project_relations
31 Setting.cross_project_issue_relations = '1'
30 Setting.cross_project_issue_relations = '1'
32 get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
31 get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
33 assert_response :success
32 assert_response :success
34 assert_not_nil assigns(:issues)
33 assert_not_nil assigns(:issues)
35 assert assigns(:issues).include?(Issue.find(13))
34 assert assigns(:issues).include?(Issue.find(13))
36 end
35 end
37
36
38 def test_auto_complete_with_scope_all_without_cross_project_relations
37 def test_auto_complete_with_scope_all_without_cross_project_relations
39 Setting.cross_project_issue_relations = '0'
38 Setting.cross_project_issue_relations = '0'
40 get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
39 get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
41 assert_response :success
40 assert_response :success
42 assert_equal [], assigns(:issues)
41 assert_equal [], assigns(:issues)
43 end
42 end
44 end
43 end
@@ -1,81 +1,80
1 require File.expand_path('../../test_helper', __FILE__)
1 require File.expand_path('../../test_helper', __FILE__)
2
2
3 class CalendarsControllerTest < ActionController::TestCase
3 class CalendarsControllerTest < ActionController::TestCase
4 fixtures :projects,
4 fixtures :projects,
5 :trackers,
5 :trackers,
6 :projects_trackers,
6 :projects_trackers,
7 :roles,
7 :roles,
8 :member_roles,
8 :member_roles,
9 :members,
9 :members,
10 :auth_sources,
11 :enabled_modules
10 :enabled_modules
12
11
13 def test_calendar
12 def test_calendar
14 get :show, :project_id => 1
13 get :show, :project_id => 1
15 assert_response :success
14 assert_response :success
16 assert_template 'calendar'
15 assert_template 'calendar'
17 assert_not_nil assigns(:calendar)
16 assert_not_nil assigns(:calendar)
18 end
17 end
19
18
20 def test_cross_project_calendar
19 def test_cross_project_calendar
21 get :show
20 get :show
22 assert_response :success
21 assert_response :success
23 assert_template 'calendar'
22 assert_template 'calendar'
24 assert_not_nil assigns(:calendar)
23 assert_not_nil assigns(:calendar)
25 end
24 end
26
25
27 context "GET :show" do
26 context "GET :show" do
28 should "run custom queries" do
27 should "run custom queries" do
29 @query = Query.generate_default!(:is_public => true)
28 @query = Query.generate_default!(:is_public => true)
30
29
31 get :show, :query_id => @query.id
30 get :show, :query_id => @query.id
32 assert_response :success
31 assert_response :success
33 end
32 end
34
33
35 end
34 end
36
35
37 def test_week_number_calculation
36 def test_week_number_calculation
38 Setting.start_of_week = 7
37 Setting.start_of_week = 7
39
38
40 get :show, :month => '1', :year => '2010'
39 get :show, :month => '1', :year => '2010'
41 assert_response :success
40 assert_response :success
42
41
43 assert_tag :tag => 'tr',
42 assert_tag :tag => 'tr',
44 :descendant => {:tag => 'td',
43 :descendant => {:tag => 'td',
45 :attributes => {:class => 'week-number'}, :content => '53'},
44 :attributes => {:class => 'week-number'}, :content => '53'},
46 :descendant => {:tag => 'td',
45 :descendant => {:tag => 'td',
47 :attributes => {:class => 'odd'}, :content => '27'},
46 :attributes => {:class => 'odd'}, :content => '27'},
48 :descendant => {:tag => 'td',
47 :descendant => {:tag => 'td',
49 :attributes => {:class => 'even'}, :content => '2'}
48 :attributes => {:class => 'even'}, :content => '2'}
50
49
51 assert_tag :tag => 'tr',
50 assert_tag :tag => 'tr',
52 :descendant => {:tag => 'td',
51 :descendant => {:tag => 'td',
53 :attributes => {:class => 'week-number'}, :content => '1'},
52 :attributes => {:class => 'week-number'}, :content => '1'},
54 :descendant => {:tag => 'td',
53 :descendant => {:tag => 'td',
55 :attributes => {:class => 'odd'}, :content => '3'},
54 :attributes => {:class => 'odd'}, :content => '3'},
56 :descendant => {:tag => 'td',
55 :descendant => {:tag => 'td',
57 :attributes => {:class => 'even'}, :content => '9'}
56 :attributes => {:class => 'even'}, :content => '9'}
58
57
59
58
60 Setting.start_of_week = 1
59 Setting.start_of_week = 1
61 get :show, :month => '1', :year => '2010'
60 get :show, :month => '1', :year => '2010'
62 assert_response :success
61 assert_response :success
63
62
64 assert_tag :tag => 'tr',
63 assert_tag :tag => 'tr',
65 :descendant => {:tag => 'td',
64 :descendant => {:tag => 'td',
66 :attributes => {:class => 'week-number'}, :content => '53'},
65 :attributes => {:class => 'week-number'}, :content => '53'},
67 :descendant => {:tag => 'td',
66 :descendant => {:tag => 'td',
68 :attributes => {:class => 'even'}, :content => '28'},
67 :attributes => {:class => 'even'}, :content => '28'},
69 :descendant => {:tag => 'td',
68 :descendant => {:tag => 'td',
70 :attributes => {:class => 'even'}, :content => '3'}
69 :attributes => {:class => 'even'}, :content => '3'}
71
70
72 assert_tag :tag => 'tr',
71 assert_tag :tag => 'tr',
73 :descendant => {:tag => 'td',
72 :descendant => {:tag => 'td',
74 :attributes => {:class => 'week-number'}, :content => '1'},
73 :attributes => {:class => 'week-number'}, :content => '1'},
75 :descendant => {:tag => 'td',
74 :descendant => {:tag => 'td',
76 :attributes => {:class => 'even'}, :content => '4'},
75 :attributes => {:class => 'even'}, :content => '4'},
77 :descendant => {:tag => 'td',
76 :descendant => {:tag => 'td',
78 :attributes => {:class => 'even'}, :content => '10'}
77 :attributes => {:class => 'even'}, :content => '10'}
79
78
80 end
79 end
81 end
80 end
@@ -1,252 +1,251
1 require File.expand_path('../../test_helper', __FILE__)
1 require File.expand_path('../../test_helper', __FILE__)
2
2
3 class ContextMenusControllerTest < ActionController::TestCase
3 class ContextMenusControllerTest < ActionController::TestCase
4 fixtures :projects,
4 fixtures :projects,
5 :trackers,
5 :trackers,
6 :projects_trackers,
6 :projects_trackers,
7 :roles,
7 :roles,
8 :member_roles,
8 :member_roles,
9 :members,
9 :members,
10 :auth_sources,
11 :enabled_modules,
10 :enabled_modules,
12 :workflows,
11 :workflows,
13 :journals, :journal_details,
12 :journals, :journal_details,
14 :versions,
13 :versions,
15 :issues, :issue_statuses, :issue_categories,
14 :issues, :issue_statuses, :issue_categories,
16 :users,
15 :users,
17 :enumerations,
16 :enumerations,
18 :time_entries
17 :time_entries
19
18
20 def test_context_menu_one_issue
19 def test_context_menu_one_issue
21 @request.session[:user_id] = 2
20 @request.session[:user_id] = 2
22 get :issues, :ids => [1]
21 get :issues, :ids => [1]
23 assert_response :success
22 assert_response :success
24 assert_template 'context_menu'
23 assert_template 'context_menu'
25 assert_tag :tag => 'a', :content => 'Edit',
24 assert_tag :tag => 'a', :content => 'Edit',
26 :attributes => { :href => '/issues/1/edit',
25 :attributes => { :href => '/issues/1/edit',
27 :class => 'icon-edit' }
26 :class => 'icon-edit' }
28 assert_tag :tag => 'a', :content => 'Closed',
27 assert_tag :tag => 'a', :content => 'Closed',
29 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5',
28 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5',
30 :class => '' }
29 :class => '' }
31 assert_tag :tag => 'a', :content => 'Immediate',
30 assert_tag :tag => 'a', :content => 'Immediate',
32 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8',
31 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8',
33 :class => '' }
32 :class => '' }
34 assert_no_tag :tag => 'a', :content => 'Inactive Priority'
33 assert_no_tag :tag => 'a', :content => 'Inactive Priority'
35 # Versions
34 # Versions
36 assert_tag :tag => 'a', :content => '2.0',
35 assert_tag :tag => 'a', :content => '2.0',
37 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3',
36 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3',
38 :class => '' }
37 :class => '' }
39 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
38 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
40 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4',
39 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4',
41 :class => '' }
40 :class => '' }
42
41
43 assert_tag :tag => 'a', :content => 'Dave Lopper',
42 assert_tag :tag => 'a', :content => 'Dave Lopper',
44 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3',
43 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3',
45 :class => '' }
44 :class => '' }
46 assert_tag :tag => 'a', :content => 'Copy',
45 assert_tag :tag => 'a', :content => 'Copy',
47 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
46 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
48 :class => 'icon-copy' }
47 :class => 'icon-copy' }
49 assert_no_tag :tag => 'a', :content => 'Move'
48 assert_no_tag :tag => 'a', :content => 'Move'
50 assert_tag :tag => 'a', :content => 'Delete',
49 assert_tag :tag => 'a', :content => 'Delete',
51 :attributes => { :href => '/issues?ids%5B%5D=1',
50 :attributes => { :href => '/issues?ids%5B%5D=1',
52 :class => 'icon-del' }
51 :class => 'icon-del' }
53 end
52 end
54
53
55 def test_context_menu_one_issue_by_anonymous
54 def test_context_menu_one_issue_by_anonymous
56 get :issues, :ids => [1]
55 get :issues, :ids => [1]
57 assert_response :success
56 assert_response :success
58 assert_template 'context_menu'
57 assert_template 'context_menu'
59 assert_tag :tag => 'a', :content => 'Delete',
58 assert_tag :tag => 'a', :content => 'Delete',
60 :attributes => { :href => '#',
59 :attributes => { :href => '#',
61 :class => 'icon-del disabled' }
60 :class => 'icon-del disabled' }
62 end
61 end
63
62
64 def test_context_menu_multiple_issues_of_same_project
63 def test_context_menu_multiple_issues_of_same_project
65 @request.session[:user_id] = 2
64 @request.session[:user_id] = 2
66 get :issues, :ids => [1, 2]
65 get :issues, :ids => [1, 2]
67 assert_response :success
66 assert_response :success
68 assert_template 'context_menu'
67 assert_template 'context_menu'
69 assert_not_nil assigns(:issues)
68 assert_not_nil assigns(:issues)
70 assert_equal [1, 2], assigns(:issues).map(&:id).sort
69 assert_equal [1, 2], assigns(:issues).map(&:id).sort
71
70
72 ids = assigns(:issues).map(&:id).map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
71 ids = assigns(:issues).map(&:id).map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
73 assert_tag :tag => 'a', :content => 'Edit',
72 assert_tag :tag => 'a', :content => 'Edit',
74 :attributes => { :href => "/issues/bulk_edit?#{ids}",
73 :attributes => { :href => "/issues/bulk_edit?#{ids}",
75 :class => 'icon-edit' }
74 :class => 'icon-edit' }
76 assert_tag :tag => 'a', :content => 'Closed',
75 assert_tag :tag => 'a', :content => 'Closed',
77 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
76 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
78 :class => '' }
77 :class => '' }
79 assert_tag :tag => 'a', :content => 'Immediate',
78 assert_tag :tag => 'a', :content => 'Immediate',
80 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
79 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
81 :class => '' }
80 :class => '' }
82 assert_tag :tag => 'a', :content => 'Dave Lopper',
81 assert_tag :tag => 'a', :content => 'Dave Lopper',
83 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3",
82 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3",
84 :class => '' }
83 :class => '' }
85 assert_tag :tag => 'a', :content => 'Copy',
84 assert_tag :tag => 'a', :content => 'Copy',
86 :attributes => { :href => "/issues/bulk_edit?copy=1&amp;#{ids}",
85 :attributes => { :href => "/issues/bulk_edit?copy=1&amp;#{ids}",
87 :class => 'icon-copy' }
86 :class => 'icon-copy' }
88 assert_no_tag :tag => 'a', :content => 'Move'
87 assert_no_tag :tag => 'a', :content => 'Move'
89 assert_tag :tag => 'a', :content => 'Delete',
88 assert_tag :tag => 'a', :content => 'Delete',
90 :attributes => { :href => "/issues?#{ids}",
89 :attributes => { :href => "/issues?#{ids}",
91 :class => 'icon-del' }
90 :class => 'icon-del' }
92 end
91 end
93
92
94 def test_context_menu_multiple_issues_of_different_projects
93 def test_context_menu_multiple_issues_of_different_projects
95 @request.session[:user_id] = 2
94 @request.session[:user_id] = 2
96 get :issues, :ids => [1, 2, 6]
95 get :issues, :ids => [1, 2, 6]
97 assert_response :success
96 assert_response :success
98 assert_template 'context_menu'
97 assert_template 'context_menu'
99 assert_not_nil assigns(:issues)
98 assert_not_nil assigns(:issues)
100 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
99 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
101
100
102 ids = assigns(:issues).map(&:id).map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
101 ids = assigns(:issues).map(&:id).map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
103 assert_tag :tag => 'a', :content => 'Edit',
102 assert_tag :tag => 'a', :content => 'Edit',
104 :attributes => { :href => "/issues/bulk_edit?#{ids}",
103 :attributes => { :href => "/issues/bulk_edit?#{ids}",
105 :class => 'icon-edit' }
104 :class => 'icon-edit' }
106 assert_tag :tag => 'a', :content => 'Closed',
105 assert_tag :tag => 'a', :content => 'Closed',
107 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
106 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
108 :class => '' }
107 :class => '' }
109 assert_tag :tag => 'a', :content => 'Immediate',
108 assert_tag :tag => 'a', :content => 'Immediate',
110 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
109 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
111 :class => '' }
110 :class => '' }
112 assert_tag :tag => 'a', :content => 'John Smith',
111 assert_tag :tag => 'a', :content => 'John Smith',
113 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2",
112 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2",
114 :class => '' }
113 :class => '' }
115 assert_tag :tag => 'a', :content => 'Delete',
114 assert_tag :tag => 'a', :content => 'Delete',
116 :attributes => { :href => "/issues?#{ids}",
115 :attributes => { :href => "/issues?#{ids}",
117 :class => 'icon-del' }
116 :class => 'icon-del' }
118 end
117 end
119
118
120 def test_context_menu_should_include_list_custom_fields
119 def test_context_menu_should_include_list_custom_fields
121 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
120 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
121 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
123 @request.session[:user_id] = 2
122 @request.session[:user_id] = 2
124 get :issues, :ids => [1]
123 get :issues, :ids => [1]
125
124
126 assert_tag 'a',
125 assert_tag 'a',
127 :content => 'List',
126 :content => 'List',
128 :attributes => {:href => '#'},
127 :attributes => {:href => '#'},
129 :sibling => {:tag => 'ul', :children => {:count => 3}}
128 :sibling => {:tag => 'ul', :children => {:count => 3}}
130
129
131 assert_tag 'a',
130 assert_tag 'a',
132 :content => 'Foo',
131 :content => 'Foo',
133 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo"}
132 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo"}
134 assert_tag 'a',
133 assert_tag 'a',
135 :content => 'none',
134 :content => 'none',
136 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D="}
135 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D="}
137 end
136 end
138
137
139 def test_context_menu_should_not_include_null_value_for_required_custom_fields
138 def test_context_menu_should_not_include_null_value_for_required_custom_fields
140 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
139 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
141 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
140 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
142 @request.session[:user_id] = 2
141 @request.session[:user_id] = 2
143 get :issues, :ids => [1, 2]
142 get :issues, :ids => [1, 2]
144
143
145 assert_tag 'a',
144 assert_tag 'a',
146 :content => 'List',
145 :content => 'List',
147 :attributes => {:href => '#'},
146 :attributes => {:href => '#'},
148 :sibling => {:tag => 'ul', :children => {:count => 2}}
147 :sibling => {:tag => 'ul', :children => {:count => 2}}
149 end
148 end
150
149
151 def test_context_menu_on_single_issue_should_select_current_custom_field_value
150 def test_context_menu_on_single_issue_should_select_current_custom_field_value
152 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
151 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
153 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
152 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
154 issue = Issue.find(1)
153 issue = Issue.find(1)
155 issue.custom_field_values = {field.id => 'Bar'}
154 issue.custom_field_values = {field.id => 'Bar'}
156 issue.save!
155 issue.save!
157 @request.session[:user_id] = 2
156 @request.session[:user_id] = 2
158 get :issues, :ids => [1]
157 get :issues, :ids => [1]
159
158
160 assert_tag 'a',
159 assert_tag 'a',
161 :content => 'List',
160 :content => 'List',
162 :attributes => {:href => '#'},
161 :attributes => {:href => '#'},
163 :sibling => {:tag => 'ul', :children => {:count => 3}}
162 :sibling => {:tag => 'ul', :children => {:count => 3}}
164 assert_tag 'a',
163 assert_tag 'a',
165 :content => 'Bar',
164 :content => 'Bar',
166 :attributes => {:class => /icon-checked/}
165 :attributes => {:class => /icon-checked/}
167 end
166 end
168
167
169 def test_context_menu_should_include_bool_custom_fields
168 def test_context_menu_should_include_bool_custom_fields
170 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
169 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
171 :is_for_all => true, :tracker_ids => [1, 2, 3])
170 :is_for_all => true, :tracker_ids => [1, 2, 3])
172 @request.session[:user_id] = 2
171 @request.session[:user_id] = 2
173 get :issues, :ids => [1]
172 get :issues, :ids => [1]
174
173
175 assert_tag 'a',
174 assert_tag 'a',
176 :content => 'Bool',
175 :content => 'Bool',
177 :attributes => {:href => '#'},
176 :attributes => {:href => '#'},
178 :sibling => {:tag => 'ul', :children => {:count => 3}}
177 :sibling => {:tag => 'ul', :children => {:count => 3}}
179
178
180 assert_tag 'a',
179 assert_tag 'a',
181 :content => 'Yes',
180 :content => 'Yes',
182 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1"}
181 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1"}
183 end
182 end
184
183
185 def test_context_menu_should_include_user_custom_fields
184 def test_context_menu_should_include_user_custom_fields
186 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
185 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
187 :is_for_all => true, :tracker_ids => [1, 2, 3])
186 :is_for_all => true, :tracker_ids => [1, 2, 3])
188 @request.session[:user_id] = 2
187 @request.session[:user_id] = 2
189 get :issues, :ids => [1]
188 get :issues, :ids => [1]
190
189
191 assert_tag 'a',
190 assert_tag 'a',
192 :content => 'User',
191 :content => 'User',
193 :attributes => {:href => '#'},
192 :attributes => {:href => '#'},
194 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).members.count + 1}}
193 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).members.count + 1}}
195
194
196 assert_tag 'a',
195 assert_tag 'a',
197 :content => 'John Smith',
196 :content => 'John Smith',
198 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2"}
197 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2"}
199 end
198 end
200
199
201 def test_context_menu_should_include_version_custom_fields
200 def test_context_menu_should_include_version_custom_fields
202 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
201 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
203 @request.session[:user_id] = 2
202 @request.session[:user_id] = 2
204 get :issues, :ids => [1]
203 get :issues, :ids => [1]
205
204
206 assert_tag 'a',
205 assert_tag 'a',
207 :content => 'Version',
206 :content => 'Version',
208 :attributes => {:href => '#'},
207 :attributes => {:href => '#'},
209 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).shared_versions.count + 1}}
208 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).shared_versions.count + 1}}
210
209
211 assert_tag 'a',
210 assert_tag 'a',
212 :content => '2.0',
211 :content => '2.0',
213 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3"}
212 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3"}
214 end
213 end
215
214
216 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
215 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
217 @request.session[:user_id] = 2
216 @request.session[:user_id] = 2
218 get :issues, :ids => [1]
217 get :issues, :ids => [1]
219 assert_response :success
218 assert_response :success
220 assert_template 'context_menu'
219 assert_template 'context_menu'
221
220
222 assert_tag :tag => 'a', :content => / me /,
221 assert_tag :tag => 'a', :content => / me /,
223 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2',
222 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2',
224 :class => '' }
223 :class => '' }
225 end
224 end
226
225
227 def test_context_menu_issue_visibility
226 def test_context_menu_issue_visibility
228 get :issues, :ids => [1, 4]
227 get :issues, :ids => [1, 4]
229 assert_response :success
228 assert_response :success
230 assert_template 'context_menu'
229 assert_template 'context_menu'
231 assert_equal [1], assigns(:issues).collect(&:id)
230 assert_equal [1], assigns(:issues).collect(&:id)
232 end
231 end
233
232
234 def test_time_entries_context_menu
233 def test_time_entries_context_menu
235 @request.session[:user_id] = 2
234 @request.session[:user_id] = 2
236 get :time_entries, :ids => [1, 2]
235 get :time_entries, :ids => [1, 2]
237 assert_response :success
236 assert_response :success
238 assert_template 'time_entries'
237 assert_template 'time_entries'
239 assert_tag 'a', :content => 'Edit'
238 assert_tag 'a', :content => 'Edit'
240 assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
239 assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
241 end
240 end
242
241
243 def test_time_entries_context_menu_without_edit_permission
242 def test_time_entries_context_menu_without_edit_permission
244 @request.session[:user_id] = 2
243 @request.session[:user_id] = 2
245 Role.find_by_name('Manager').remove_permission! :edit_time_entries
244 Role.find_by_name('Manager').remove_permission! :edit_time_entries
246
245
247 get :time_entries, :ids => [1, 2]
246 get :time_entries, :ids => [1, 2]
248 assert_response :success
247 assert_response :success
249 assert_template 'time_entries'
248 assert_template 'time_entries'
250 assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
249 assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
251 end
250 end
252 end
251 end
@@ -1,334 +1,334
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
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 'users_controller'
19 require 'users_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class UsersController; def rescue_action(e) raise e end; end
22 class UsersController; def rescue_action(e) raise e end; end
23
23
24 class UsersControllerTest < ActionController::TestCase
24 class UsersControllerTest < ActionController::TestCase
25 include Redmine::I18n
25 include Redmine::I18n
26
26
27 fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values, :groups_users
27 fixtures :users, :projects, :members, :member_roles, :roles, :custom_fields, :custom_values, :groups_users
28
28
29 def setup
29 def setup
30 @controller = UsersController.new
30 @controller = UsersController.new
31 @request = ActionController::TestRequest.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
32 @response = ActionController::TestResponse.new
33 User.current = nil
33 User.current = nil
34 @request.session[:user_id] = 1 # admin
34 @request.session[:user_id] = 1 # admin
35 end
35 end
36
36
37 def test_index
37 def test_index
38 get :index
38 get :index
39 assert_response :success
39 assert_response :success
40 assert_template 'index'
40 assert_template 'index'
41 end
41 end
42
42
43 def test_index
43 def test_index
44 get :index
44 get :index
45 assert_response :success
45 assert_response :success
46 assert_template 'index'
46 assert_template 'index'
47 assert_not_nil assigns(:users)
47 assert_not_nil assigns(:users)
48 # active users only
48 # active users only
49 assert_nil assigns(:users).detect {|u| !u.active?}
49 assert_nil assigns(:users).detect {|u| !u.active?}
50 end
50 end
51
51
52 def test_index_with_status_filter
52 def test_index_with_status_filter
53 get :index, :status => 3
53 get :index, :status => 3
54 assert_response :success
54 assert_response :success
55 assert_template 'index'
55 assert_template 'index'
56 assert_not_nil assigns(:users)
56 assert_not_nil assigns(:users)
57 assert_equal [3], assigns(:users).map(&:status).uniq
57 assert_equal [3], assigns(:users).map(&:status).uniq
58 end
58 end
59
59
60 def test_index_with_name_filter
60 def test_index_with_name_filter
61 get :index, :name => 'john'
61 get :index, :name => 'john'
62 assert_response :success
62 assert_response :success
63 assert_template 'index'
63 assert_template 'index'
64 users = assigns(:users)
64 users = assigns(:users)
65 assert_not_nil users
65 assert_not_nil users
66 assert_equal 1, users.size
66 assert_equal 1, users.size
67 assert_equal 'John', users.first.firstname
67 assert_equal 'John', users.first.firstname
68 end
68 end
69
69
70 def test_index_with_group_filter
70 def test_index_with_group_filter
71 get :index, :group_id => '10'
71 get :index, :group_id => '10'
72 assert_response :success
72 assert_response :success
73 assert_template 'index'
73 assert_template 'index'
74 users = assigns(:users)
74 users = assigns(:users)
75 assert users.any?
75 assert users.any?
76 assert_equal([], (users - Group.find(10).users))
76 assert_equal([], (users - Group.find(10).users))
77 end
77 end
78
78
79 def test_show
79 def test_show
80 @request.session[:user_id] = nil
80 @request.session[:user_id] = nil
81 get :show, :id => 2
81 get :show, :id => 2
82 assert_response :success
82 assert_response :success
83 assert_template 'show'
83 assert_template 'show'
84 assert_not_nil assigns(:user)
84 assert_not_nil assigns(:user)
85
85
86 assert_tag 'li', :content => /Phone number/
86 assert_tag 'li', :content => /Phone number/
87 end
87 end
88
88
89 def test_show_should_not_display_hidden_custom_fields
89 def test_show_should_not_display_hidden_custom_fields
90 @request.session[:user_id] = nil
90 @request.session[:user_id] = nil
91 UserCustomField.find_by_name('Phone number').update_attribute :visible, false
91 UserCustomField.find_by_name('Phone number').update_attribute :visible, false
92 get :show, :id => 2
92 get :show, :id => 2
93 assert_response :success
93 assert_response :success
94 assert_template 'show'
94 assert_template 'show'
95 assert_not_nil assigns(:user)
95 assert_not_nil assigns(:user)
96
96
97 assert_no_tag 'li', :content => /Phone number/
97 assert_no_tag 'li', :content => /Phone number/
98 end
98 end
99
99
100 def test_show_should_not_fail_when_custom_values_are_nil
100 def test_show_should_not_fail_when_custom_values_are_nil
101 user = User.find(2)
101 user = User.find(2)
102
102
103 # Create a custom field to illustrate the issue
103 # Create a custom field to illustrate the issue
104 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
104 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
105 custom_value = user.custom_values.build(:custom_field => custom_field).save!
105 custom_value = user.custom_values.build(:custom_field => custom_field).save!
106
106
107 get :show, :id => 2
107 get :show, :id => 2
108 assert_response :success
108 assert_response :success
109 end
109 end
110
110
111 def test_show_inactive
111 def test_show_inactive
112 @request.session[:user_id] = nil
112 @request.session[:user_id] = nil
113 get :show, :id => 5
113 get :show, :id => 5
114 assert_response 404
114 assert_response 404
115 end
115 end
116
116
117 def test_show_should_not_reveal_users_with_no_visible_activity_or_project
117 def test_show_should_not_reveal_users_with_no_visible_activity_or_project
118 @request.session[:user_id] = nil
118 @request.session[:user_id] = nil
119 get :show, :id => 9
119 get :show, :id => 9
120 assert_response 404
120 assert_response 404
121 end
121 end
122
122
123 def test_show_inactive_by_admin
123 def test_show_inactive_by_admin
124 @request.session[:user_id] = 1
124 @request.session[:user_id] = 1
125 get :show, :id => 5
125 get :show, :id => 5
126 assert_response 200
126 assert_response 200
127 assert_not_nil assigns(:user)
127 assert_not_nil assigns(:user)
128 end
128 end
129
129
130 def test_show_displays_memberships_based_on_project_visibility
130 def test_show_displays_memberships_based_on_project_visibility
131 @request.session[:user_id] = 1
131 @request.session[:user_id] = 1
132 get :show, :id => 2
132 get :show, :id => 2
133 assert_response :success
133 assert_response :success
134 memberships = assigns(:memberships)
134 memberships = assigns(:memberships)
135 assert_not_nil memberships
135 assert_not_nil memberships
136 project_ids = memberships.map(&:project_id)
136 project_ids = memberships.map(&:project_id)
137 assert project_ids.include?(2) #private project admin can see
137 assert project_ids.include?(2) #private project admin can see
138 end
138 end
139
139
140 def test_show_current_should_require_authentication
140 def test_show_current_should_require_authentication
141 @request.session[:user_id] = nil
141 @request.session[:user_id] = nil
142 get :show, :id => 'current'
142 get :show, :id => 'current'
143 assert_response 302
143 assert_response 302
144 end
144 end
145
145
146 def test_show_current
146 def test_show_current
147 @request.session[:user_id] = 2
147 @request.session[:user_id] = 2
148 get :show, :id => 'current'
148 get :show, :id => 'current'
149 assert_response :success
149 assert_response :success
150 assert_template 'show'
150 assert_template 'show'
151 assert_equal User.find(2), assigns(:user)
151 assert_equal User.find(2), assigns(:user)
152 end
152 end
153
153
154 def test_new
154 def test_new
155 get :new
155 get :new
156
156
157 assert_response :success
157 assert_response :success
158 assert_template :new
158 assert_template :new
159 assert assigns(:user)
159 assert assigns(:user)
160 end
160 end
161
161
162 def test_create
162 def test_create
163 Setting.bcc_recipients = '1'
163 Setting.bcc_recipients = '1'
164
164
165 assert_difference 'User.count' do
165 assert_difference 'User.count' do
166 assert_difference 'ActionMailer::Base.deliveries.size' do
166 assert_difference 'ActionMailer::Base.deliveries.size' do
167 post :create,
167 post :create,
168 :user => {
168 :user => {
169 :firstname => 'John',
169 :firstname => 'John',
170 :lastname => 'Doe',
170 :lastname => 'Doe',
171 :login => 'jdoe',
171 :login => 'jdoe',
172 :password => 'secret',
172 :password => 'secret',
173 :password_confirmation => 'secret',
173 :password_confirmation => 'secret',
174 :mail => 'jdoe@gmail.com',
174 :mail => 'jdoe@gmail.com',
175 :mail_notification => 'none'
175 :mail_notification => 'none'
176 },
176 },
177 :send_information => '1'
177 :send_information => '1'
178 end
178 end
179 end
179 end
180
180
181 user = User.first(:order => 'id DESC')
181 user = User.first(:order => 'id DESC')
182 assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id
182 assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id
183
183
184 assert_equal 'John', user.firstname
184 assert_equal 'John', user.firstname
185 assert_equal 'Doe', user.lastname
185 assert_equal 'Doe', user.lastname
186 assert_equal 'jdoe', user.login
186 assert_equal 'jdoe', user.login
187 assert_equal 'jdoe@gmail.com', user.mail
187 assert_equal 'jdoe@gmail.com', user.mail
188 assert_equal 'none', user.mail_notification
188 assert_equal 'none', user.mail_notification
189 assert user.check_password?('secret')
189 assert user.check_password?('secret')
190
190
191 mail = ActionMailer::Base.deliveries.last
191 mail = ActionMailer::Base.deliveries.last
192 assert_not_nil mail
192 assert_not_nil mail
193 assert_equal [user.mail], mail.bcc
193 assert_equal [user.mail], mail.bcc
194 assert mail.body.include?('secret')
194 assert mail.body.include?('secret')
195 end
195 end
196
196
197 def test_create_with_failure
197 def test_create_with_failure
198 assert_no_difference 'User.count' do
198 assert_no_difference 'User.count' do
199 post :create, :user => {}
199 post :create, :user => {}
200 end
200 end
201
201
202 assert_response :success
202 assert_response :success
203 assert_template 'new'
203 assert_template 'new'
204 end
204 end
205
205
206 def test_edit
206 def test_edit
207 get :edit, :id => 2
207 get :edit, :id => 2
208
208
209 assert_response :success
209 assert_response :success
210 assert_template 'edit'
210 assert_template 'edit'
211 assert_equal User.find(2), assigns(:user)
211 assert_equal User.find(2), assigns(:user)
212 end
212 end
213
213
214 def test_update
214 def test_update
215 ActionMailer::Base.deliveries.clear
215 ActionMailer::Base.deliveries.clear
216 put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
216 put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
217
217
218 user = User.find(2)
218 user = User.find(2)
219 assert_equal 'Changed', user.firstname
219 assert_equal 'Changed', user.firstname
220 assert_equal 'only_assigned', user.mail_notification
220 assert_equal 'only_assigned', user.mail_notification
221 assert_equal true, user.pref[:hide_mail]
221 assert_equal true, user.pref[:hide_mail]
222 assert_equal 'desc', user.pref[:comments_sorting]
222 assert_equal 'desc', user.pref[:comments_sorting]
223 assert ActionMailer::Base.deliveries.empty?
223 assert ActionMailer::Base.deliveries.empty?
224 end
224 end
225
225
226 def test_update_with_failure
226 def test_update_with_failure
227 assert_no_difference 'User.count' do
227 assert_no_difference 'User.count' do
228 put :update, :id => 2, :user => {:firstname => ''}
228 put :update, :id => 2, :user => {:firstname => ''}
229 end
229 end
230
230
231 assert_response :success
231 assert_response :success
232 assert_template 'edit'
232 assert_template 'edit'
233 end
233 end
234
234
235 def test_update_with_group_ids_should_assign_groups
235 def test_update_with_group_ids_should_assign_groups
236 put :update, :id => 2, :user => {:group_ids => ['10']}
236 put :update, :id => 2, :user => {:group_ids => ['10']}
237
237
238 user = User.find(2)
238 user = User.find(2)
239 assert_equal [10], user.group_ids
239 assert_equal [10], user.group_ids
240 end
240 end
241
241
242 def test_update_with_activation_should_send_a_notification
242 def test_update_with_activation_should_send_a_notification
243 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
243 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
244 u.login = 'foo'
244 u.login = 'foo'
245 u.status = User::STATUS_REGISTERED
245 u.status = User::STATUS_REGISTERED
246 u.save!
246 u.save!
247 ActionMailer::Base.deliveries.clear
247 ActionMailer::Base.deliveries.clear
248 Setting.bcc_recipients = '1'
248 Setting.bcc_recipients = '1'
249
249
250 put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
250 put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
251 assert u.reload.active?
251 assert u.reload.active?
252 mail = ActionMailer::Base.deliveries.last
252 mail = ActionMailer::Base.deliveries.last
253 assert_not_nil mail
253 assert_not_nil mail
254 assert_equal ['foo.bar@somenet.foo'], mail.bcc
254 assert_equal ['foo.bar@somenet.foo'], mail.bcc
255 assert mail.body.include?(ll('fr', :notice_account_activated))
255 assert mail.body.include?(ll('fr', :notice_account_activated))
256 end
256 end
257
257
258 def test_update_with_password_change_should_send_a_notification
258 def test_update_with_password_change_should_send_a_notification
259 ActionMailer::Base.deliveries.clear
259 ActionMailer::Base.deliveries.clear
260 Setting.bcc_recipients = '1'
260 Setting.bcc_recipients = '1'
261
261
262 put :update, :id => 2, :user => {:password => 'newpass', :password_confirmation => 'newpass'}, :send_information => '1'
262 put :update, :id => 2, :user => {:password => 'newpass', :password_confirmation => 'newpass'}, :send_information => '1'
263 u = User.find(2)
263 u = User.find(2)
264 assert u.check_password?('newpass')
264 assert u.check_password?('newpass')
265
265
266 mail = ActionMailer::Base.deliveries.last
266 mail = ActionMailer::Base.deliveries.last
267 assert_not_nil mail
267 assert_not_nil mail
268 assert_equal [u.mail], mail.bcc
268 assert_equal [u.mail], mail.bcc
269 assert mail.body.include?('newpass')
269 assert mail.body.include?('newpass')
270 end
270 end
271
271
272 test "put :update with a password change to an AuthSource user switching to Internal authentication" do
272 test "put :update with a password change to an AuthSource user switching to Internal authentication" do
273 # Configure as auth source
273 # Configure as auth source
274 u = User.find(2)
274 u = User.find(2)
275 u.auth_source = AuthSource.find(1)
275 u.auth_source = AuthSource.find(1)
276 u.save!
276 u.save!
277
277
278 put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass'}, :password_confirmation => 'newpass'
278 put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass'}, :password_confirmation => 'newpass'
279
279
280 assert_equal nil, u.reload.auth_source
280 assert_equal nil, u.reload.auth_source
281 assert u.check_password?('newpass')
281 assert u.check_password?('newpass')
282 end
282 end
283
283
284 def test_destroy
284 def test_destroy
285 assert_difference 'User.count', -1 do
285 assert_difference 'User.count', -1 do
286 delete :destroy, :id => 2
286 delete :destroy, :id => 2
287 end
287 end
288 assert_redirected_to '/users'
288 assert_redirected_to '/users'
289 assert_nil User.find_by_id(2)
289 assert_nil User.find_by_id(2)
290 end
290 end
291
291
292 def test_destroy_should_not_accept_get_requests
292 def test_destroy_should_not_accept_get_requests
293 assert_no_difference 'User.count' do
293 assert_no_difference 'User.count' do
294 get :destroy, :id => 2
294 get :destroy, :id => 2
295 end
295 end
296 assert_response 405
296 assert_response 405
297 end
297 end
298
298
299 def test_destroy_should_be_denied_for_non_admin_users
299 def test_destroy_should_be_denied_for_non_admin_users
300 @request.session[:user_id] = 3
300 @request.session[:user_id] = 3
301
301
302 assert_no_difference 'User.count' do
302 assert_no_difference 'User.count' do
303 get :destroy, :id => 2
303 get :destroy, :id => 2
304 end
304 end
305 assert_response 403
305 assert_response 403
306 end
306 end
307
307
308 def test_create_membership
308 def test_create_membership
309 assert_difference 'Member.count' do
309 assert_difference 'Member.count' do
310 post :edit_membership, :id => 7, :membership => { :project_id => 3, :role_ids => [2]}
310 post :edit_membership, :id => 7, :membership => { :project_id => 3, :role_ids => [2]}
311 end
311 end
312 assert_redirected_to :action => 'edit', :id => '7', :tab => 'memberships'
312 assert_redirected_to :action => 'edit', :id => '7', :tab => 'memberships'
313 member = Member.first(:order => 'id DESC')
313 member = Member.first(:order => 'id DESC')
314 assert_equal User.find(7), member.principal
314 assert_equal User.find(7), member.principal
315 assert_equal [2], member.role_ids
315 assert_equal [2], member.role_ids
316 assert_equal 3, member.project_id
316 assert_equal 3, member.project_id
317 end
317 end
318
318
319 def test_update_membership
319 def test_update_membership
320 assert_no_difference 'Member.count' do
320 assert_no_difference 'Member.count' do
321 put :edit_membership, :id => 2, :membership_id => 1, :membership => { :role_ids => [2]}
321 put :edit_membership, :id => 2, :membership_id => 1, :membership => { :role_ids => [2]}
322 end
322 end
323 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
323 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
324 assert_equal [2], Member.find(1).role_ids
324 assert_equal [2], Member.find(1).role_ids
325 end
325 end
326
326
327 def test_destroy_membership
327 def test_destroy_membership
328 assert_difference 'Member.count', -1 do
328 assert_difference 'Member.count', -1 do
329 delete :destroy_membership, :id => 2, :membership_id => 1
329 delete :destroy_membership, :id => 2, :membership_id => 1
330 end
330 end
331 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
331 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
332 assert_nil Member.find_by_id(1)
332 assert_nil Member.find_by_id(1)
333 end
333 end
334 end
334 end
@@ -1,128 +1,128
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
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
19
20 class TimeEntryTest < ActiveSupport::TestCase
20 class TimeEntryTest < ActiveSupport::TestCase
21 fixtures :issues, :projects, :users, :time_entries,
21 fixtures :issues, :projects, :users, :time_entries,
22 :members, :roles, :member_roles, :auth_sources,
22 :members, :roles, :member_roles,
23 :trackers, :issue_statuses,
23 :trackers, :issue_statuses,
24 :projects_trackers,
24 :projects_trackers,
25 :journals, :journal_details,
25 :journals, :journal_details,
26 :issue_categories, :enumerations,
26 :issue_categories, :enumerations,
27 :groups_users,
27 :groups_users,
28 :enabled_modules,
28 :enabled_modules,
29 :workflows
29 :workflows
30
30
31 def test_hours_format
31 def test_hours_format
32 assertions = { "2" => 2.0,
32 assertions = { "2" => 2.0,
33 "21.1" => 21.1,
33 "21.1" => 21.1,
34 "2,1" => 2.1,
34 "2,1" => 2.1,
35 "1,5h" => 1.5,
35 "1,5h" => 1.5,
36 "7:12" => 7.2,
36 "7:12" => 7.2,
37 "10h" => 10.0,
37 "10h" => 10.0,
38 "10 h" => 10.0,
38 "10 h" => 10.0,
39 "45m" => 0.75,
39 "45m" => 0.75,
40 "45 m" => 0.75,
40 "45 m" => 0.75,
41 "3h15" => 3.25,
41 "3h15" => 3.25,
42 "3h 15" => 3.25,
42 "3h 15" => 3.25,
43 "3 h 15" => 3.25,
43 "3 h 15" => 3.25,
44 "3 h 15m" => 3.25,
44 "3 h 15m" => 3.25,
45 "3 h 15 m" => 3.25,
45 "3 h 15 m" => 3.25,
46 "3 hours" => 3.0,
46 "3 hours" => 3.0,
47 "12min" => 0.2,
47 "12min" => 0.2,
48 }
48 }
49
49
50 assertions.each do |k, v|
50 assertions.each do |k, v|
51 t = TimeEntry.new(:hours => k)
51 t = TimeEntry.new(:hours => k)
52 assert_equal v, t.hours, "Converting #{k} failed:"
52 assert_equal v, t.hours, "Converting #{k} failed:"
53 end
53 end
54 end
54 end
55
55
56 def test_hours_should_default_to_nil
56 def test_hours_should_default_to_nil
57 assert_nil TimeEntry.new.hours
57 assert_nil TimeEntry.new.hours
58 end
58 end
59
59
60 def test_spent_on_with_blank
60 def test_spent_on_with_blank
61 c = TimeEntry.new
61 c = TimeEntry.new
62 c.spent_on = ''
62 c.spent_on = ''
63 assert_nil c.spent_on
63 assert_nil c.spent_on
64 end
64 end
65
65
66 def test_spent_on_with_nil
66 def test_spent_on_with_nil
67 c = TimeEntry.new
67 c = TimeEntry.new
68 c.spent_on = nil
68 c.spent_on = nil
69 assert_nil c.spent_on
69 assert_nil c.spent_on
70 end
70 end
71
71
72 def test_spent_on_with_string
72 def test_spent_on_with_string
73 c = TimeEntry.new
73 c = TimeEntry.new
74 c.spent_on = "2011-01-14"
74 c.spent_on = "2011-01-14"
75 assert_equal Date.parse("2011-01-14"), c.spent_on
75 assert_equal Date.parse("2011-01-14"), c.spent_on
76 end
76 end
77
77
78 def test_spent_on_with_invalid_string
78 def test_spent_on_with_invalid_string
79 c = TimeEntry.new
79 c = TimeEntry.new
80 c.spent_on = "foo"
80 c.spent_on = "foo"
81 assert_nil c.spent_on
81 assert_nil c.spent_on
82 end
82 end
83
83
84 def test_spent_on_with_date
84 def test_spent_on_with_date
85 c = TimeEntry.new
85 c = TimeEntry.new
86 c.spent_on = Date.today
86 c.spent_on = Date.today
87 assert_equal Date.today, c.spent_on
87 assert_equal Date.today, c.spent_on
88 end
88 end
89
89
90 def test_spent_on_with_time
90 def test_spent_on_with_time
91 c = TimeEntry.new
91 c = TimeEntry.new
92 c.spent_on = Time.now
92 c.spent_on = Time.now
93 assert_equal Date.today, c.spent_on
93 assert_equal Date.today, c.spent_on
94 end
94 end
95
95
96 def test_validate_time_entry
96 def test_validate_time_entry
97 anon = User.anonymous
97 anon = User.anonymous
98 project = Project.find(1)
98 project = Project.find(1)
99 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
99 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
100 :priority => IssuePriority.all.first, :subject => 'test_create',
100 :priority => IssuePriority.all.first, :subject => 'test_create',
101 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
101 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
102 assert issue.save
102 assert issue.save
103 activity = TimeEntryActivity.find_by_name('Design')
103 activity = TimeEntryActivity.find_by_name('Design')
104 te = TimeEntry.create(:spent_on => '2010-01-01',
104 te = TimeEntry.create(:spent_on => '2010-01-01',
105 :hours => 100000,
105 :hours => 100000,
106 :issue => issue,
106 :issue => issue,
107 :project => project,
107 :project => project,
108 :user => anon,
108 :user => anon,
109 :activity => activity)
109 :activity => activity)
110 assert_equal 1, te.errors.count
110 assert_equal 1, te.errors.count
111 end
111 end
112
112
113 def test_set_project_if_nil
113 def test_set_project_if_nil
114 anon = User.anonymous
114 anon = User.anonymous
115 project = Project.find(1)
115 project = Project.find(1)
116 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
116 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
117 :priority => IssuePriority.all.first, :subject => 'test_create',
117 :priority => IssuePriority.all.first, :subject => 'test_create',
118 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
118 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
119 assert issue.save
119 assert issue.save
120 activity = TimeEntryActivity.find_by_name('Design')
120 activity = TimeEntryActivity.find_by_name('Design')
121 te = TimeEntry.create(:spent_on => '2010-01-01',
121 te = TimeEntry.create(:spent_on => '2010-01-01',
122 :hours => 10,
122 :hours => 10,
123 :issue => issue,
123 :issue => issue,
124 :user => anon,
124 :user => anon,
125 :activity => activity)
125 :activity => activity)
126 assert_equal project.id, te.project.id
126 assert_equal project.id, te.project.id
127 end
127 end
128 end
128 end
General Comments 0
You need to be logged in to leave comments. Login now