##// END OF EJS Templates
Use #assert_select instead of #assert_tag....
Jean-Philippe Lang -
r10836:3976d5e7408d
parent child
Show More
@@ -1,141 +1,141
1 <ul>
1 <ul>
2 <%= call_hook(:view_issues_context_menu_start, {:issues => @issues, :can => @can, :back => @back }) %>
2 <%= call_hook(:view_issues_context_menu_start, {:issues => @issues, :can => @can, :back => @back }) %>
3
3
4 <% if !@issue.nil? -%>
4 <% if !@issue.nil? -%>
5 <li><%= context_menu_link l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue},
5 <li><%= context_menu_link l(:button_edit), {:controller => 'issues', :action => 'edit', :id => @issue},
6 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
6 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
7 <% else %>
7 <% else %>
8 <li><%= context_menu_link l(:button_edit), {:controller => 'issues', :action => 'bulk_edit', :ids => @issue_ids},
8 <li><%= context_menu_link l(:button_edit), {:controller => 'issues', :action => 'bulk_edit', :ids => @issue_ids},
9 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
9 :class => 'icon-edit', :disabled => !@can[:edit] %></li>
10 <% end %>
10 <% end %>
11
11
12 <% if @allowed_statuses.present? %>
12 <% if @allowed_statuses.present? %>
13 <li class="folder">
13 <li class="folder">
14 <a href="#" class="submenu"><%= l(:field_status) %></a>
14 <a href="#" class="submenu"><%= l(:field_status) %></a>
15 <ul>
15 <ul>
16 <% @allowed_statuses.each do |s| -%>
16 <% @allowed_statuses.each do |s| -%>
17 <li><%= context_menu_link h(s.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {:status_id => s}, :back_url => @back}, :method => :post,
17 <li><%= context_menu_link h(s.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {:status_id => s}, :back_url => @back}, :method => :post,
18 :selected => (@issue && s == @issue.status), :disabled => !@can[:update] %></li>
18 :selected => (@issue && s == @issue.status), :disabled => !@can[:update] %></li>
19 <% end -%>
19 <% end -%>
20 </ul>
20 </ul>
21 </li>
21 </li>
22 <% end %>
22 <% end %>
23
23
24 <% unless @trackers.nil? %>
24 <% unless @trackers.nil? %>
25 <li class="folder">
25 <li class="folder">
26 <a href="#" class="submenu"><%= l(:field_tracker) %></a>
26 <a href="#" class="submenu"><%= l(:field_tracker) %></a>
27 <ul>
27 <ul>
28 <% @trackers.each do |t| -%>
28 <% @trackers.each do |t| -%>
29 <li><%= context_menu_link h(t.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'tracker_id' => t}, :back_url => @back}, :method => :post,
29 <li><%= context_menu_link h(t.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'tracker_id' => t}, :back_url => @back}, :method => :post,
30 :selected => (@issue && t == @issue.tracker), :disabled => !@can[:edit] %></li>
30 :selected => (@issue && t == @issue.tracker), :disabled => !@can[:edit] %></li>
31 <% end -%>
31 <% end -%>
32 </ul>
32 </ul>
33 </li>
33 </li>
34 <% end %>
34 <% end %>
35
35
36 <% if @safe_attributes.include?('priority_id') -%>
36 <% if @safe_attributes.include?('priority_id') -%>
37 <li class="folder">
37 <li class="folder">
38 <a href="#" class="submenu"><%= l(:field_priority) %></a>
38 <a href="#" class="submenu"><%= l(:field_priority) %></a>
39 <ul>
39 <ul>
40 <% @priorities.each do |p| -%>
40 <% @priorities.each do |p| -%>
41 <li><%= context_menu_link h(p.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'priority_id' => p}, :back_url => @back}, :method => :post,
41 <li><%= context_menu_link h(p.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'priority_id' => p}, :back_url => @back}, :method => :post,
42 :selected => (@issue && p == @issue.priority), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
42 :selected => (@issue && p == @issue.priority), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
43 <% end -%>
43 <% end -%>
44 </ul>
44 </ul>
45 </li>
45 </li>
46 <% end %>
46 <% end %>
47
47
48 <% if @safe_attributes.include?('fixed_version_id') && @versions.any? -%>
48 <% if @safe_attributes.include?('fixed_version_id') && @versions.any? -%>
49 <li class="folder">
49 <li class="folder">
50 <a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
50 <a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
51 <ul>
51 <ul>
52 <% @versions.sort.each do |v| -%>
52 <% @versions.sort.each do |v| -%>
53 <li><%= context_menu_link format_version_name(v), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'fixed_version_id' => v}, :back_url => @back}, :method => :post,
53 <li><%= context_menu_link format_version_name(v), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'fixed_version_id' => v}, :back_url => @back}, :method => :post,
54 :selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
54 :selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
55 <% end -%>
55 <% end -%>
56 <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'fixed_version_id' => 'none'}, :back_url => @back}, :method => :post,
56 <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'fixed_version_id' => 'none'}, :back_url => @back}, :method => :post,
57 :selected => (@issue && @issue.fixed_version.nil?), :disabled => !@can[:update] %></li>
57 :selected => (@issue && @issue.fixed_version.nil?), :disabled => !@can[:update] %></li>
58 </ul>
58 </ul>
59 </li>
59 </li>
60 <% end %>
60 <% end %>
61
61
62 <% if @safe_attributes.include?('assigned_to_id') && @assignables.present? -%>
62 <% if @safe_attributes.include?('assigned_to_id') && @assignables.present? -%>
63 <li class="folder">
63 <li class="folder">
64 <a href="#" class="submenu"><%= l(:field_assigned_to) %></a>
64 <a href="#" class="submenu"><%= l(:field_assigned_to) %></a>
65 <ul>
65 <ul>
66 <% if @assignables.include?(User.current) %>
66 <% if @assignables.include?(User.current) %>
67 <li><%= context_menu_link "<< #{l(:label_me)} >>", {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'assigned_to_id' => User.current}, :back_url => @back}, :method => :post,
67 <li><%= context_menu_link "<< #{l(:label_me)} >>", {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'assigned_to_id' => User.current}, :back_url => @back}, :method => :post,
68 :disabled => !@can[:update] %></li>
68 :disabled => !@can[:update] %></li>
69 <% end %>
69 <% end %>
70 <% @assignables.each do |u| -%>
70 <% @assignables.each do |u| -%>
71 <li><%= context_menu_link h(u.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'assigned_to_id' => u}, :back_url => @back}, :method => :post,
71 <li><%= context_menu_link h(u.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'assigned_to_id' => u}, :back_url => @back}, :method => :post,
72 :selected => (@issue && u == @issue.assigned_to), :disabled => !@can[:update] %></li>
72 :selected => (@issue && u == @issue.assigned_to), :disabled => !@can[:update] %></li>
73 <% end -%>
73 <% end -%>
74 <li><%= context_menu_link l(:label_nobody), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'assigned_to_id' => 'none'}, :back_url => @back}, :method => :post,
74 <li><%= context_menu_link l(:label_nobody), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'assigned_to_id' => 'none'}, :back_url => @back}, :method => :post,
75 :selected => (@issue && @issue.assigned_to.nil?), :disabled => !@can[:update] %></li>
75 :selected => (@issue && @issue.assigned_to.nil?), :disabled => !@can[:update] %></li>
76 </ul>
76 </ul>
77 </li>
77 </li>
78 <% end %>
78 <% end %>
79
79
80 <% if @safe_attributes.include?('category_id') && @project && @project.issue_categories.any? -%>
80 <% if @safe_attributes.include?('category_id') && @project && @project.issue_categories.any? -%>
81 <li class="folder">
81 <li class="folder">
82 <a href="#" class="submenu"><%= l(:field_category) %></a>
82 <a href="#" class="submenu"><%= l(:field_category) %></a>
83 <ul>
83 <ul>
84 <% @project.issue_categories.each do |u| -%>
84 <% @project.issue_categories.each do |u| -%>
85 <li><%= context_menu_link h(u.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'category_id' => u}, :back_url => @back}, :method => :post,
85 <li><%= context_menu_link h(u.name), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'category_id' => u}, :back_url => @back}, :method => :post,
86 :selected => (@issue && u == @issue.category), :disabled => !@can[:update] %></li>
86 :selected => (@issue && u == @issue.category), :disabled => !@can[:update] %></li>
87 <% end -%>
87 <% end -%>
88 <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'category_id' => 'none'}, :back_url => @back}, :method => :post,
88 <li><%= context_menu_link l(:label_none), {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'category_id' => 'none'}, :back_url => @back}, :method => :post,
89 :selected => (@issue && @issue.category.nil?), :disabled => !@can[:update] %></li>
89 :selected => (@issue && @issue.category.nil?), :disabled => !@can[:update] %></li>
90 </ul>
90 </ul>
91 </li>
91 </li>
92 <% end -%>
92 <% end -%>
93
93
94 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
94 <% if @safe_attributes.include?('done_ratio') && Issue.use_field_for_done_ratio? %>
95 <li class="folder">
95 <li class="folder">
96 <a href="#" class="submenu"><%= l(:field_done_ratio) %></a>
96 <a href="#" class="submenu"><%= l(:field_done_ratio) %></a>
97 <ul>
97 <ul>
98 <% (0..10).map{|x|x*10}.each do |p| -%>
98 <% (0..10).map{|x|x*10}.each do |p| -%>
99 <li><%= context_menu_link "#{p}%", {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'done_ratio' => p}, :back_url => @back}, :method => :post,
99 <li><%= context_menu_link "#{p}%", {:controller => 'issues', :action => 'bulk_update', :ids => @issue_ids, :issue => {'done_ratio' => p}, :back_url => @back}, :method => :post,
100 :selected => (@issue && p == @issue.done_ratio), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
100 :selected => (@issue && p == @issue.done_ratio), :disabled => (!@can[:edit] || @issues.detect {|i| !i.leaf?}) %></li>
101 <% end -%>
101 <% end -%>
102 </ul>
102 </ul>
103 </li>
103 </li>
104 <% end %>
104 <% end %>
105
105
106 <% @options_by_custom_field.each do |field, options| %>
106 <% @options_by_custom_field.each do |field, options| %>
107 <li class="folder">
107 <li class="folder cf_<%= field.id %>">
108 <a href="#" class="submenu"><%= h(field.name) %></a>
108 <a href="#" class="submenu"><%= h(field.name) %></a>
109 <ul>
109 <ul>
110 <% options.each do |text, value| %>
110 <% options.each do |text, value| %>
111 <li><%= bulk_update_custom_field_context_menu_link(field, text, value || text) %></li>
111 <li><%= bulk_update_custom_field_context_menu_link(field, text, value || text) %></li>
112 <% end %>
112 <% end %>
113 <% unless field.is_required? %>
113 <% unless field.is_required? %>
114 <li><%= bulk_update_custom_field_context_menu_link(field, l(:label_none), '') %></li>
114 <li><%= bulk_update_custom_field_context_menu_link(field, l(:label_none), '') %></li>
115 <% end %>
115 <% end %>
116 </ul>
116 </ul>
117 </li>
117 </li>
118 <% end %>
118 <% end %>
119
119
120 <% if !@issue.nil? %>
120 <% if !@issue.nil? %>
121 <% if @can[:log_time] -%>
121 <% if @can[:log_time] -%>
122 <li><%= context_menu_link l(:button_log_time), {:controller => 'timelog', :action => 'new', :issue_id => @issue},
122 <li><%= context_menu_link l(:button_log_time), {:controller => 'timelog', :action => 'new', :issue_id => @issue},
123 :class => 'icon-time-add' %></li>
123 :class => 'icon-time-add' %></li>
124 <% end %>
124 <% end %>
125 <% if User.current.logged? %>
125 <% if User.current.logged? %>
126 <li><%= watcher_link(@issue, User.current) %></li>
126 <li><%= watcher_link(@issue, User.current) %></li>
127 <% end %>
127 <% end %>
128 <% end %>
128 <% end %>
129
129
130 <% if @issue.present? %>
130 <% if @issue.present? %>
131 <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
131 <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'new', :project_id => @project, :copy_from => @issue},
132 :class => 'icon-copy', :disabled => !@can[:copy] %></li>
132 :class => 'icon-copy', :disabled => !@can[:copy] %></li>
133 <% else %>
133 <% else %>
134 <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'bulk_edit', :ids => @issue_ids, :copy => '1'},
134 <li><%= context_menu_link l(:button_copy), {:controller => 'issues', :action => 'bulk_edit', :ids => @issue_ids, :copy => '1'},
135 :class => 'icon-copy', :disabled => !@can[:move] %></li>
135 :class => 'icon-copy', :disabled => !@can[:move] %></li>
136 <% end %>
136 <% end %>
137 <li><%= context_menu_link l(:button_delete), issues_path(:ids => @issue_ids, :back_url => @back),
137 <li><%= context_menu_link l(:button_delete), issues_path(:ids => @issue_ids, :back_url => @back),
138 :method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon-del', :disabled => !@can[:delete] %></li>
138 :method => :delete, :data => {:confirm => issues_destroy_confirmation_message(@issues)}, :class => 'icon-del', :disabled => !@can[:delete] %></li>
139
139
140 <%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
140 <%= call_hook(:view_issues_context_menu_end, {:issues => @issues, :can => @can, :back => @back }) %>
141 </ul>
141 </ul>
@@ -1,260 +1,260
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 AccountControllerTest < ActionController::TestCase
20 class AccountControllerTest < ActionController::TestCase
21 fixtures :users, :roles
21 fixtures :users, :roles
22
22
23 def setup
23 def setup
24 User.current = nil
24 User.current = nil
25 end
25 end
26
26
27 def test_get_login
27 def test_get_login
28 get :login
28 get :login
29 assert_response :success
29 assert_response :success
30 assert_template 'login'
30 assert_template 'login'
31
31
32 assert_select 'input[name=username]'
32 assert_select 'input[name=username]'
33 assert_select 'input[name=password]'
33 assert_select 'input[name=password]'
34 end
34 end
35
35
36 def test_login_should_redirect_to_back_url_param
36 def test_login_should_redirect_to_back_url_param
37 # request.uri is "test.host" in test environment
37 # request.uri is "test.host" in test environment
38 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1'
38 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.host/issues/show/1'
39 assert_redirected_to '/issues/show/1'
39 assert_redirected_to '/issues/show/1'
40 end
40 end
41
41
42 def test_login_should_not_redirect_to_another_host
42 def test_login_should_not_redirect_to_another_host
43 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.foo/fake'
43 post :login, :username => 'jsmith', :password => 'jsmith', :back_url => 'http://test.foo/fake'
44 assert_redirected_to '/my/page'
44 assert_redirected_to '/my/page'
45 end
45 end
46
46
47 def test_login_with_wrong_password
47 def test_login_with_wrong_password
48 post :login, :username => 'admin', :password => 'bad'
48 post :login, :username => 'admin', :password => 'bad'
49 assert_response :success
49 assert_response :success
50 assert_template 'login'
50 assert_template 'login'
51
51
52 assert_select 'div.flash.error', :text => /Invalid user or password/
52 assert_select 'div.flash.error', :text => /Invalid user or password/
53 assert_select 'input[name=username][value=admin]'
53 assert_select 'input[name=username][value=admin]'
54 assert_select 'input[name=password]'
54 assert_select 'input[name=password]'
55 assert_select 'input[name=password][value]', 0
55 assert_select 'input[name=password][value]', 0
56 end
56 end
57
57
58 def test_login_should_rescue_auth_source_exception
58 def test_login_should_rescue_auth_source_exception
59 source = AuthSource.create!(:name => 'Test')
59 source = AuthSource.create!(:name => 'Test')
60 User.find(2).update_attribute :auth_source_id, source.id
60 User.find(2).update_attribute :auth_source_id, source.id
61 AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong"))
61 AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong"))
62
62
63 post :login, :username => 'jsmith', :password => 'jsmith'
63 post :login, :username => 'jsmith', :password => 'jsmith'
64 assert_response 500
64 assert_response 500
65 assert_error_tag :content => /Something wrong/
65 assert_error_tag :content => /Something wrong/
66 end
66 end
67
67
68 def test_login_should_reset_session
68 def test_login_should_reset_session
69 @controller.expects(:reset_session).once
69 @controller.expects(:reset_session).once
70
70
71 post :login, :username => 'jsmith', :password => 'jsmith'
71 post :login, :username => 'jsmith', :password => 'jsmith'
72 assert_response 302
72 assert_response 302
73 end
73 end
74
74
75 def test_logout
75 def test_logout
76 @request.session[:user_id] = 2
76 @request.session[:user_id] = 2
77 get :logout
77 get :logout
78 assert_redirected_to '/'
78 assert_redirected_to '/'
79 assert_nil @request.session[:user_id]
79 assert_nil @request.session[:user_id]
80 end
80 end
81
81
82 def test_logout_should_reset_session
82 def test_logout_should_reset_session
83 @controller.expects(:reset_session).once
83 @controller.expects(:reset_session).once
84
84
85 @request.session[:user_id] = 2
85 @request.session[:user_id] = 2
86 get :logout
86 get :logout
87 assert_response 302
87 assert_response 302
88 end
88 end
89
89
90 def test_get_register_with_registration_on
90 def test_get_register_with_registration_on
91 with_settings :self_registration => '3' do
91 with_settings :self_registration => '3' do
92 get :register
92 get :register
93 assert_response :success
93 assert_response :success
94 assert_template 'register'
94 assert_template 'register'
95 assert_not_nil assigns(:user)
95 assert_not_nil assigns(:user)
96
96
97 assert_tag 'input', :attributes => {:name => 'user[password]'}
97 assert_select 'input[name=?]', 'user[password]'
98 assert_tag 'input', :attributes => {:name => 'user[password_confirmation]'}
98 assert_select 'input[name=?]', 'user[password_confirmation]'
99 end
99 end
100 end
100 end
101
101
102 def test_get_register_should_detect_user_language
102 def test_get_register_should_detect_user_language
103 with_settings :self_registration => '3' do
103 with_settings :self_registration => '3' do
104 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
104 @request.env['HTTP_ACCEPT_LANGUAGE'] = 'fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3'
105 get :register
105 get :register
106 assert_response :success
106 assert_response :success
107 assert_not_nil assigns(:user)
107 assert_not_nil assigns(:user)
108 assert_equal 'fr', assigns(:user).language
108 assert_equal 'fr', assigns(:user).language
109 assert_select 'select[name=?]', 'user[language]' do
109 assert_select 'select[name=?]', 'user[language]' do
110 assert_select 'option[value=fr][selected=selected]'
110 assert_select 'option[value=fr][selected=selected]'
111 end
111 end
112 end
112 end
113 end
113 end
114
114
115 def test_get_register_with_registration_off_should_redirect
115 def test_get_register_with_registration_off_should_redirect
116 with_settings :self_registration => '0' do
116 with_settings :self_registration => '0' do
117 get :register
117 get :register
118 assert_redirected_to '/'
118 assert_redirected_to '/'
119 end
119 end
120 end
120 end
121
121
122 # See integration/account_test.rb for the full test
122 # See integration/account_test.rb for the full test
123 def test_post_register_with_registration_on
123 def test_post_register_with_registration_on
124 with_settings :self_registration => '3' do
124 with_settings :self_registration => '3' do
125 assert_difference 'User.count' do
125 assert_difference 'User.count' do
126 post :register, :user => {
126 post :register, :user => {
127 :login => 'register',
127 :login => 'register',
128 :password => 'secret123',
128 :password => 'secret123',
129 :password_confirmation => 'secret123',
129 :password_confirmation => 'secret123',
130 :firstname => 'John',
130 :firstname => 'John',
131 :lastname => 'Doe',
131 :lastname => 'Doe',
132 :mail => 'register@example.com'
132 :mail => 'register@example.com'
133 }
133 }
134 assert_redirected_to '/my/account'
134 assert_redirected_to '/my/account'
135 end
135 end
136 user = User.first(:order => 'id DESC')
136 user = User.first(:order => 'id DESC')
137 assert_equal 'register', user.login
137 assert_equal 'register', user.login
138 assert_equal 'John', user.firstname
138 assert_equal 'John', user.firstname
139 assert_equal 'Doe', user.lastname
139 assert_equal 'Doe', user.lastname
140 assert_equal 'register@example.com', user.mail
140 assert_equal 'register@example.com', user.mail
141 assert user.check_password?('secret123')
141 assert user.check_password?('secret123')
142 assert user.active?
142 assert user.active?
143 end
143 end
144 end
144 end
145
145
146 def test_post_register_with_registration_off_should_redirect
146 def test_post_register_with_registration_off_should_redirect
147 with_settings :self_registration => '0' do
147 with_settings :self_registration => '0' do
148 assert_no_difference 'User.count' do
148 assert_no_difference 'User.count' do
149 post :register, :user => {
149 post :register, :user => {
150 :login => 'register',
150 :login => 'register',
151 :password => 'test',
151 :password => 'test',
152 :password_confirmation => 'test',
152 :password_confirmation => 'test',
153 :firstname => 'John',
153 :firstname => 'John',
154 :lastname => 'Doe',
154 :lastname => 'Doe',
155 :mail => 'register@example.com'
155 :mail => 'register@example.com'
156 }
156 }
157 assert_redirected_to '/'
157 assert_redirected_to '/'
158 end
158 end
159 end
159 end
160 end
160 end
161
161
162 def test_get_lost_password_should_display_lost_password_form
162 def test_get_lost_password_should_display_lost_password_form
163 get :lost_password
163 get :lost_password
164 assert_response :success
164 assert_response :success
165 assert_select 'input[name=mail]'
165 assert_select 'input[name=mail]'
166 end
166 end
167
167
168 def test_lost_password_for_active_user_should_create_a_token
168 def test_lost_password_for_active_user_should_create_a_token
169 Token.delete_all
169 Token.delete_all
170 ActionMailer::Base.deliveries.clear
170 ActionMailer::Base.deliveries.clear
171 assert_difference 'ActionMailer::Base.deliveries.size' do
171 assert_difference 'ActionMailer::Base.deliveries.size' do
172 assert_difference 'Token.count' do
172 assert_difference 'Token.count' do
173 with_settings :host_name => 'mydomain.foo', :protocol => 'http' do
173 with_settings :host_name => 'mydomain.foo', :protocol => 'http' do
174 post :lost_password, :mail => 'JSmith@somenet.foo'
174 post :lost_password, :mail => 'JSmith@somenet.foo'
175 assert_redirected_to '/login'
175 assert_redirected_to '/login'
176 end
176 end
177 end
177 end
178 end
178 end
179
179
180 token = Token.order('id DESC').first
180 token = Token.order('id DESC').first
181 assert_equal User.find(2), token.user
181 assert_equal User.find(2), token.user
182 assert_equal 'recovery', token.action
182 assert_equal 'recovery', token.action
183
183
184 assert_select_email do
184 assert_select_email do
185 assert_select "a[href=?]", "http://mydomain.foo/account/lost_password?token=#{token.value}"
185 assert_select "a[href=?]", "http://mydomain.foo/account/lost_password?token=#{token.value}"
186 end
186 end
187 end
187 end
188
188
189 def test_lost_password_for_unknown_user_should_fail
189 def test_lost_password_for_unknown_user_should_fail
190 Token.delete_all
190 Token.delete_all
191 assert_no_difference 'Token.count' do
191 assert_no_difference 'Token.count' do
192 post :lost_password, :mail => 'invalid@somenet.foo'
192 post :lost_password, :mail => 'invalid@somenet.foo'
193 assert_response :success
193 assert_response :success
194 end
194 end
195 end
195 end
196
196
197 def test_lost_password_for_non_active_user_should_fail
197 def test_lost_password_for_non_active_user_should_fail
198 Token.delete_all
198 Token.delete_all
199 assert User.find(2).lock!
199 assert User.find(2).lock!
200
200
201 assert_no_difference 'Token.count' do
201 assert_no_difference 'Token.count' do
202 post :lost_password, :mail => 'JSmith@somenet.foo'
202 post :lost_password, :mail => 'JSmith@somenet.foo'
203 assert_response :success
203 assert_response :success
204 end
204 end
205 end
205 end
206
206
207 def test_get_lost_password_with_token_should_display_the_password_recovery_form
207 def test_get_lost_password_with_token_should_display_the_password_recovery_form
208 user = User.find(2)
208 user = User.find(2)
209 token = Token.create!(:action => 'recovery', :user => user)
209 token = Token.create!(:action => 'recovery', :user => user)
210
210
211 get :lost_password, :token => token.value
211 get :lost_password, :token => token.value
212 assert_response :success
212 assert_response :success
213 assert_template 'password_recovery'
213 assert_template 'password_recovery'
214
214
215 assert_select 'input[type=hidden][name=token][value=?]', token.value
215 assert_select 'input[type=hidden][name=token][value=?]', token.value
216 end
216 end
217
217
218 def test_get_lost_password_with_invalid_token_should_redirect
218 def test_get_lost_password_with_invalid_token_should_redirect
219 get :lost_password, :token => "abcdef"
219 get :lost_password, :token => "abcdef"
220 assert_redirected_to '/'
220 assert_redirected_to '/'
221 end
221 end
222
222
223 def test_post_lost_password_with_token_should_change_the_user_password
223 def test_post_lost_password_with_token_should_change_the_user_password
224 user = User.find(2)
224 user = User.find(2)
225 token = Token.create!(:action => 'recovery', :user => user)
225 token = Token.create!(:action => 'recovery', :user => user)
226
226
227 post :lost_password, :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123'
227 post :lost_password, :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123'
228 assert_redirected_to '/login'
228 assert_redirected_to '/login'
229 user.reload
229 user.reload
230 assert user.check_password?('newpass123')
230 assert user.check_password?('newpass123')
231 assert_nil Token.find_by_id(token.id), "Token was not deleted"
231 assert_nil Token.find_by_id(token.id), "Token was not deleted"
232 end
232 end
233
233
234 def test_post_lost_password_with_token_for_non_active_user_should_fail
234 def test_post_lost_password_with_token_for_non_active_user_should_fail
235 user = User.find(2)
235 user = User.find(2)
236 token = Token.create!(:action => 'recovery', :user => user)
236 token = Token.create!(:action => 'recovery', :user => user)
237 user.lock!
237 user.lock!
238
238
239 post :lost_password, :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123'
239 post :lost_password, :token => token.value, :new_password => 'newpass123', :new_password_confirmation => 'newpass123'
240 assert_redirected_to '/'
240 assert_redirected_to '/'
241 assert ! user.check_password?('newpass123')
241 assert ! user.check_password?('newpass123')
242 end
242 end
243
243
244 def test_post_lost_password_with_token_and_password_confirmation_failure_should_redisplay_the_form
244 def test_post_lost_password_with_token_and_password_confirmation_failure_should_redisplay_the_form
245 user = User.find(2)
245 user = User.find(2)
246 token = Token.create!(:action => 'recovery', :user => user)
246 token = Token.create!(:action => 'recovery', :user => user)
247
247
248 post :lost_password, :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'wrongpass'
248 post :lost_password, :token => token.value, :new_password => 'newpass', :new_password_confirmation => 'wrongpass'
249 assert_response :success
249 assert_response :success
250 assert_template 'password_recovery'
250 assert_template 'password_recovery'
251 assert_not_nil Token.find_by_id(token.id), "Token was deleted"
251 assert_not_nil Token.find_by_id(token.id), "Token was deleted"
252
252
253 assert_select 'input[type=hidden][name=token][value=?]', token.value
253 assert_select 'input[type=hidden][name=token][value=?]', token.value
254 end
254 end
255
255
256 def test_post_lost_password_with_invalid_token_should_redirect
256 def test_post_lost_password_with_invalid_token_should_redirect
257 post :lost_password, :token => "abcdef", :new_password => 'newpass', :new_password_confirmation => 'newpass'
257 post :lost_password, :token => "abcdef", :new_password => 'newpass', :new_password_confirmation => 'newpass'
258 assert_redirected_to '/'
258 assert_redirected_to '/'
259 end
259 end
260 end
260 end
@@ -1,183 +1,151
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 ActivitiesControllerTest < ActionController::TestCase
20 class ActivitiesControllerTest < ActionController::TestCase
21 fixtures :projects, :trackers, :issue_statuses, :issues,
21 fixtures :projects, :trackers, :issue_statuses, :issues,
22 :enumerations, :users, :issue_categories,
22 :enumerations, :users, :issue_categories,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :groups_users,
27 :groups_users,
28 :enabled_modules,
28 :enabled_modules,
29 :workflows,
29 :workflows,
30 :journals, :journal_details
30 :journals, :journal_details
31
31
32
32
33 def test_project_index
33 def test_project_index
34 get :index, :id => 1, :with_subprojects => 0
34 get :index, :id => 1, :with_subprojects => 0
35 assert_response :success
35 assert_response :success
36 assert_template 'index'
36 assert_template 'index'
37 assert_not_nil assigns(:events_by_day)
37 assert_not_nil assigns(:events_by_day)
38
38
39 assert_tag :tag => "h3",
39 assert_select 'h3', :text => /#{2.days.ago.to_date.day}/
40 :content => /#{2.days.ago.to_date.day}/,
40 assert_select 'dl dt.issue-edit a', :text => /(#{IssueStatus.find(2).name})/
41 :sibling => { :tag => "dl",
42 :child => { :tag => "dt",
43 :attributes => { :class => /issue-edit/ },
44 :child => { :tag => "a",
45 :content => /(#{IssueStatus.find(2).name})/,
46 }
47 }
48 }
49 end
41 end
50
42
51 def test_project_index_with_invalid_project_id_should_respond_404
43 def test_project_index_with_invalid_project_id_should_respond_404
52 get :index, :id => 299
44 get :index, :id => 299
53 assert_response 404
45 assert_response 404
54 end
46 end
55
47
56 def test_previous_project_index
48 def test_previous_project_index
57 get :index, :id => 1, :from => 3.days.ago.to_date
49 get :index, :id => 1, :from => 3.days.ago.to_date
58 assert_response :success
50 assert_response :success
59 assert_template 'index'
51 assert_template 'index'
60 assert_not_nil assigns(:events_by_day)
52 assert_not_nil assigns(:events_by_day)
61
53
62 assert_tag :tag => "h3",
54 assert_select 'h3', :text => /#{3.days.ago.to_date.day}/
63 :content => /#{3.day.ago.to_date.day}/,
55 assert_select 'dl dt.issue a', :text => /Can&#x27;t print recipes/
64 :sibling => { :tag => "dl",
65 :child => { :tag => "dt",
66 :attributes => { :class => /issue/ },
67 :child => { :tag => "a",
68 :content => /Can&#x27;t print recipes/,
69 }
70 }
71 }
72 end
56 end
73
57
74 def test_global_index
58 def test_global_index
75 @request.session[:user_id] = 1
59 @request.session[:user_id] = 1
76 get :index
60 get :index
77 assert_response :success
61 assert_response :success
78 assert_template 'index'
62 assert_template 'index'
79 assert_not_nil assigns(:events_by_day)
63 assert_not_nil assigns(:events_by_day)
80
64
81 i5 = Issue.find(5)
65 i5 = Issue.find(5)
82 d5 = User.find(1).time_to_date(i5.created_on)
66 d5 = User.find(1).time_to_date(i5.created_on)
83 assert_tag :tag => "h3",
67
84 :content => /#{d5.day}/,
68 assert_select 'h3', :text => /#{d5.day}/
85 :sibling => { :tag => "dl",
69 assert_select 'dl dt.issue a', :text => /Subproject issue/
86 :child => { :tag => "dt",
87 :attributes => { :class => /issue/ },
88 :child => { :tag => "a",
89 :content => /Subproject issue/,
90 }
91 }
92 }
93 end
70 end
94
71
95 def test_user_index
72 def test_user_index
96 @request.session[:user_id] = 1
73 @request.session[:user_id] = 1
97 get :index, :user_id => 2
74 get :index, :user_id => 2
98 assert_response :success
75 assert_response :success
99 assert_template 'index'
76 assert_template 'index'
100 assert_not_nil assigns(:events_by_day)
77 assert_not_nil assigns(:events_by_day)
101
78
102 assert_select 'h2 a[href=/users/2]', :text => 'John Smith'
79 assert_select 'h2 a[href=/users/2]', :text => 'John Smith'
103
80
104 i1 = Issue.find(1)
81 i1 = Issue.find(1)
105 d1 = User.find(1).time_to_date(i1.created_on)
82 d1 = User.find(1).time_to_date(i1.created_on)
106
83
107 assert_tag :tag => "h3",
84 assert_select 'h3', :text => /#{d1.day}/
108 :content => /#{d1.day}/,
85 assert_select 'dl dt.issue a', :text => /Can&#x27;t print recipes/
109 :sibling => { :tag => "dl",
110 :child => { :tag => "dt",
111 :attributes => { :class => /issue/ },
112 :child => { :tag => "a",
113 :content => /Can&#x27;t print recipes/,
114 }
115 }
116 }
117 end
86 end
118
87
119 def test_user_index_with_invalid_user_id_should_respond_404
88 def test_user_index_with_invalid_user_id_should_respond_404
120 get :index, :user_id => 299
89 get :index, :user_id => 299
121 assert_response 404
90 assert_response 404
122 end
91 end
123
92
124 def test_index_atom_feed
93 def test_index_atom_feed
125 get :index, :format => 'atom', :with_subprojects => 0
94 get :index, :format => 'atom', :with_subprojects => 0
126 assert_response :success
95 assert_response :success
127 assert_template 'common/feed'
96 assert_template 'common/feed'
128
97
129 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
98 assert_select 'feed' do
130 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
99 assert_select 'link[rel=self][href=?]', 'http://test.host/activity.atom?with_subprojects=0'
131 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
100 assert_select 'link[rel=alternate][href=?]', 'http://test.host/activity?with_subprojects=0'
132 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}
101 assert_select 'entry' do
133
102 assert_select 'link[href=?]', 'http://test.host/issues/11'
134 assert_tag :tag => 'entry', :child => {
103 end
135 :tag => 'link',
104 end
136 :attributes => {:href => 'http://test.host/issues/11'}}
137 end
105 end
138
106
139 def test_index_atom_feed_with_explicit_selection
107 def test_index_atom_feed_with_explicit_selection
140 get :index, :format => 'atom', :with_subprojects => 0,
108 get :index, :format => 'atom', :with_subprojects => 0,
141 :show_changesets => 1,
109 :show_changesets => 1,
142 :show_documents => 1,
110 :show_documents => 1,
143 :show_files => 1,
111 :show_files => 1,
144 :show_issues => 1,
112 :show_issues => 1,
145 :show_messages => 1,
113 :show_messages => 1,
146 :show_news => 1,
114 :show_news => 1,
147 :show_time_entries => 1,
115 :show_time_entries => 1,
148 :show_wiki_edits => 1
116 :show_wiki_edits => 1
149
117
150 assert_response :success
118 assert_response :success
151 assert_template 'common/feed'
119 assert_template 'common/feed'
152
120
153 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
121 assert_select 'feed' do
154 :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'}
122 assert_select 'link[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'
155 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
123 assert_select 'link[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'
156 :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'}
124 assert_select 'entry' do
157
125 assert_select 'link[href=?]', 'http://test.host/issues/11'
158 assert_tag :tag => 'entry', :child => {
126 end
159 :tag => 'link',
127 end
160 :attributes => {:href => 'http://test.host/issues/11'}}
161 end
128 end
162
129
163 def test_index_atom_feed_with_one_item_type
130 def test_index_atom_feed_with_one_item_type
164 get :index, :format => 'atom', :show_issues => '1'
131 get :index, :format => 'atom', :show_issues => '1'
165 assert_response :success
132 assert_response :success
166 assert_template 'common/feed'
133 assert_template 'common/feed'
167 assert_tag :tag => 'title', :content => /Issues/
134
135 assert_select 'title', :text => /Issues/
168 end
136 end
169
137
170 def test_index_should_show_private_notes_with_permission_only
138 def test_index_should_show_private_notes_with_permission_only
171 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
139 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Private notes with searchkeyword', :private_notes => true)
172 @request.session[:user_id] = 2
140 @request.session[:user_id] = 2
173
141
174 get :index
142 get :index
175 assert_response :success
143 assert_response :success
176 assert_include journal, assigns(:events_by_day).values.flatten
144 assert_include journal, assigns(:events_by_day).values.flatten
177
145
178 Role.find(1).remove_permission! :view_private_notes
146 Role.find(1).remove_permission! :view_private_notes
179 get :index
147 get :index
180 assert_response :success
148 assert_response :success
181 assert_not_include journal, assigns(:events_by_day).values.flatten
149 assert_not_include journal, assigns(:events_by_day).values.flatten
182 end
150 end
183 end
151 end
@@ -1,201 +1,202
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 BoardsControllerTest < ActionController::TestCase
20 class BoardsControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
22
22
23 def setup
23 def setup
24 User.current = nil
24 User.current = nil
25 end
25 end
26
26
27 def test_index
27 def test_index
28 get :index, :project_id => 1
28 get :index, :project_id => 1
29 assert_response :success
29 assert_response :success
30 assert_template 'index'
30 assert_template 'index'
31 assert_not_nil assigns(:boards)
31 assert_not_nil assigns(:boards)
32 assert_not_nil assigns(:project)
32 assert_not_nil assigns(:project)
33 end
33 end
34
34
35 def test_index_not_found
35 def test_index_not_found
36 get :index, :project_id => 97
36 get :index, :project_id => 97
37 assert_response 404
37 assert_response 404
38 end
38 end
39
39
40 def test_index_should_show_messages_if_only_one_board
40 def test_index_should_show_messages_if_only_one_board
41 Project.find(1).boards.slice(1..-1).each(&:destroy)
41 Project.find(1).boards.slice(1..-1).each(&:destroy)
42
42
43 get :index, :project_id => 1
43 get :index, :project_id => 1
44 assert_response :success
44 assert_response :success
45 assert_template 'show'
45 assert_template 'show'
46 assert_not_nil assigns(:topics)
46 assert_not_nil assigns(:topics)
47 end
47 end
48
48
49 def test_show
49 def test_show
50 get :show, :project_id => 1, :id => 1
50 get :show, :project_id => 1, :id => 1
51 assert_response :success
51 assert_response :success
52 assert_template 'show'
52 assert_template 'show'
53 assert_not_nil assigns(:board)
53 assert_not_nil assigns(:board)
54 assert_not_nil assigns(:project)
54 assert_not_nil assigns(:project)
55 assert_not_nil assigns(:topics)
55 assert_not_nil assigns(:topics)
56 end
56 end
57
57
58 def test_show_should_display_sticky_messages_first
58 def test_show_should_display_sticky_messages_first
59 Message.update_all(:sticky => 0)
59 Message.update_all(:sticky => 0)
60 Message.update_all({:sticky => 1}, {:id => 1})
60 Message.update_all({:sticky => 1}, {:id => 1})
61
61
62 get :show, :project_id => 1, :id => 1
62 get :show, :project_id => 1, :id => 1
63 assert_response :success
63 assert_response :success
64
64
65 topics = assigns(:topics)
65 topics = assigns(:topics)
66 assert_not_nil topics
66 assert_not_nil topics
67 assert topics.size > 1, "topics size was #{topics.size}"
67 assert topics.size > 1, "topics size was #{topics.size}"
68 assert topics.first.sticky?
68 assert topics.first.sticky?
69 assert topics.first.updated_on < topics.second.updated_on
69 assert topics.first.updated_on < topics.second.updated_on
70 end
70 end
71
71
72 def test_show_with_permission_should_display_the_new_message_form
72 def test_show_with_permission_should_display_the_new_message_form
73 @request.session[:user_id] = 2
73 @request.session[:user_id] = 2
74 get :show, :project_id => 1, :id => 1
74 get :show, :project_id => 1, :id => 1
75 assert_response :success
75 assert_response :success
76 assert_template 'show'
76 assert_template 'show'
77
77
78 assert_tag 'form', :attributes => {:id => 'message-form'}
78 assert_select 'form#message-form' do
79 assert_tag 'input', :attributes => {:name => 'message[subject]'}
79 assert_select 'input[name=?]', 'message[subject]'
80 end
80 end
81 end
81
82
82 def test_show_atom
83 def test_show_atom
83 get :show, :project_id => 1, :id => 1, :format => 'atom'
84 get :show, :project_id => 1, :id => 1, :format => 'atom'
84 assert_response :success
85 assert_response :success
85 assert_template 'common/feed'
86 assert_template 'common/feed'
86 assert_not_nil assigns(:board)
87 assert_not_nil assigns(:board)
87 assert_not_nil assigns(:project)
88 assert_not_nil assigns(:project)
88 assert_not_nil assigns(:messages)
89 assert_not_nil assigns(:messages)
89 end
90 end
90
91
91 def test_show_not_found
92 def test_show_not_found
92 get :index, :project_id => 1, :id => 97
93 get :index, :project_id => 1, :id => 97
93 assert_response 404
94 assert_response 404
94 end
95 end
95
96
96 def test_new
97 def test_new
97 @request.session[:user_id] = 2
98 @request.session[:user_id] = 2
98 get :new, :project_id => 1
99 get :new, :project_id => 1
99 assert_response :success
100 assert_response :success
100 assert_template 'new'
101 assert_template 'new'
101
102
102 assert_select 'select[name=?]', 'board[parent_id]' do
103 assert_select 'select[name=?]', 'board[parent_id]' do
103 assert_select 'option', (Project.find(1).boards.size + 1)
104 assert_select 'option', (Project.find(1).boards.size + 1)
104 assert_select 'option[value=]', :text => ''
105 assert_select 'option[value=]', :text => ''
105 assert_select 'option[value=1]', :text => 'Help'
106 assert_select 'option[value=1]', :text => 'Help'
106 end
107 end
107 end
108 end
108
109
109 def test_new_without_project_boards
110 def test_new_without_project_boards
110 Project.find(1).boards.delete_all
111 Project.find(1).boards.delete_all
111 @request.session[:user_id] = 2
112 @request.session[:user_id] = 2
112
113
113 get :new, :project_id => 1
114 get :new, :project_id => 1
114 assert_response :success
115 assert_response :success
115 assert_template 'new'
116 assert_template 'new'
116
117
117 assert_select 'select[name=?]', 'board[parent_id]', 0
118 assert_select 'select[name=?]', 'board[parent_id]', 0
118 end
119 end
119
120
120 def test_create
121 def test_create
121 @request.session[:user_id] = 2
122 @request.session[:user_id] = 2
122 assert_difference 'Board.count' do
123 assert_difference 'Board.count' do
123 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
124 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
124 end
125 end
125 assert_redirected_to '/projects/ecookbook/settings/boards'
126 assert_redirected_to '/projects/ecookbook/settings/boards'
126 board = Board.first(:order => 'id DESC')
127 board = Board.first(:order => 'id DESC')
127 assert_equal 'Testing', board.name
128 assert_equal 'Testing', board.name
128 assert_equal 'Testing board creation', board.description
129 assert_equal 'Testing board creation', board.description
129 end
130 end
130
131
131 def test_create_with_parent
132 def test_create_with_parent
132 @request.session[:user_id] = 2
133 @request.session[:user_id] = 2
133 assert_difference 'Board.count' do
134 assert_difference 'Board.count' do
134 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
135 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
135 end
136 end
136 assert_redirected_to '/projects/ecookbook/settings/boards'
137 assert_redirected_to '/projects/ecookbook/settings/boards'
137 board = Board.first(:order => 'id DESC')
138 board = Board.first(:order => 'id DESC')
138 assert_equal Board.find(2), board.parent
139 assert_equal Board.find(2), board.parent
139 end
140 end
140
141
141 def test_create_with_failure
142 def test_create_with_failure
142 @request.session[:user_id] = 2
143 @request.session[:user_id] = 2
143 assert_no_difference 'Board.count' do
144 assert_no_difference 'Board.count' do
144 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
145 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
145 end
146 end
146 assert_response :success
147 assert_response :success
147 assert_template 'new'
148 assert_template 'new'
148 end
149 end
149
150
150 def test_edit
151 def test_edit
151 @request.session[:user_id] = 2
152 @request.session[:user_id] = 2
152 get :edit, :project_id => 1, :id => 2
153 get :edit, :project_id => 1, :id => 2
153 assert_response :success
154 assert_response :success
154 assert_template 'edit'
155 assert_template 'edit'
155 end
156 end
156
157
157 def test_edit_with_parent
158 def test_edit_with_parent
158 board = Board.generate!(:project_id => 1, :parent_id => 2)
159 board = Board.generate!(:project_id => 1, :parent_id => 2)
159 @request.session[:user_id] = 2
160 @request.session[:user_id] = 2
160 get :edit, :project_id => 1, :id => board.id
161 get :edit, :project_id => 1, :id => board.id
161 assert_response :success
162 assert_response :success
162 assert_template 'edit'
163 assert_template 'edit'
163
164
164 assert_select 'select[name=?]', 'board[parent_id]' do
165 assert_select 'select[name=?]', 'board[parent_id]' do
165 assert_select 'option[value=2][selected=selected]'
166 assert_select 'option[value=2][selected=selected]'
166 end
167 end
167 end
168 end
168
169
169 def test_update
170 def test_update
170 @request.session[:user_id] = 2
171 @request.session[:user_id] = 2
171 assert_no_difference 'Board.count' do
172 assert_no_difference 'Board.count' do
172 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
173 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
173 end
174 end
174 assert_redirected_to '/projects/ecookbook/settings/boards'
175 assert_redirected_to '/projects/ecookbook/settings/boards'
175 assert_equal 'Testing', Board.find(2).name
176 assert_equal 'Testing', Board.find(2).name
176 end
177 end
177
178
178 def test_update_position
179 def test_update_position
179 @request.session[:user_id] = 2
180 @request.session[:user_id] = 2
180 put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
181 put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
181 assert_redirected_to '/projects/ecookbook/settings/boards'
182 assert_redirected_to '/projects/ecookbook/settings/boards'
182 board = Board.find(2)
183 board = Board.find(2)
183 assert_equal 1, board.position
184 assert_equal 1, board.position
184 end
185 end
185
186
186 def test_update_with_failure
187 def test_update_with_failure
187 @request.session[:user_id] = 2
188 @request.session[:user_id] = 2
188 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
189 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
189 assert_response :success
190 assert_response :success
190 assert_template 'edit'
191 assert_template 'edit'
191 end
192 end
192
193
193 def test_destroy
194 def test_destroy
194 @request.session[:user_id] = 2
195 @request.session[:user_id] = 2
195 assert_difference 'Board.count', -1 do
196 assert_difference 'Board.count', -1 do
196 delete :destroy, :project_id => 1, :id => 2
197 delete :destroy, :project_id => 1, :id => 2
197 end
198 end
198 assert_redirected_to '/projects/ecookbook/settings/boards'
199 assert_redirected_to '/projects/ecookbook/settings/boards'
199 assert_nil Board.find_by_id(2)
200 assert_nil Board.find_by_id(2)
200 end
201 end
201 end
202 end
@@ -1,97 +1,87
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 CalendarsControllerTest < ActionController::TestCase
20 class CalendarsControllerTest < ActionController::TestCase
21 fixtures :projects,
21 fixtures :projects,
22 :trackers,
22 :trackers,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :enabled_modules
27 :enabled_modules
28
28
29 def test_calendar
29 def test_calendar
30 get :show, :project_id => 1
30 get :show, :project_id => 1
31 assert_response :success
31 assert_response :success
32 assert_template 'calendar'
32 assert_template 'calendar'
33 assert_not_nil assigns(:calendar)
33 assert_not_nil assigns(:calendar)
34 end
34 end
35
35
36 def test_cross_project_calendar
36 def test_cross_project_calendar
37 get :show
37 get :show
38 assert_response :success
38 assert_response :success
39 assert_template 'calendar'
39 assert_template 'calendar'
40 assert_not_nil assigns(:calendar)
40 assert_not_nil assigns(:calendar)
41 end
41 end
42
42
43 context "GET :show" do
43 context "GET :show" do
44 should "run custom queries" do
44 should "run custom queries" do
45 @query = IssueQuery.create!(:name => 'Calendar', :is_public => true)
45 @query = IssueQuery.create!(:name => 'Calendar', :is_public => true)
46
46
47 get :show, :query_id => @query.id
47 get :show, :query_id => @query.id
48 assert_response :success
48 assert_response :success
49 end
49 end
50
50
51 end
51 end
52
52
53 def test_week_number_calculation
53 def test_week_number_calculation
54 Setting.start_of_week = 7
54 Setting.start_of_week = 7
55
55
56 get :show, :month => '1', :year => '2010'
56 get :show, :month => '1', :year => '2010'
57 assert_response :success
57 assert_response :success
58
58
59 assert_tag :tag => 'tr',
59 assert_select 'tr' do
60 :descendant => {:tag => 'td',
60 assert_select 'td.week-number', :text => '53'
61 :attributes => {:class => 'week-number'}, :content => '53'},
61 assert_select 'td.odd', :text => '27'
62 :descendant => {:tag => 'td',
62 assert_select 'td.even', :text => '2'
63 :attributes => {:class => 'odd'}, :content => '27'},
63 end
64 :descendant => {:tag => 'td',
65 :attributes => {:class => 'even'}, :content => '2'}
66
67 assert_tag :tag => 'tr',
68 :descendant => {:tag => 'td',
69 :attributes => {:class => 'week-number'}, :content => '1'},
70 :descendant => {:tag => 'td',
71 :attributes => {:class => 'odd'}, :content => '3'},
72 :descendant => {:tag => 'td',
73 :attributes => {:class => 'even'}, :content => '9'}
74
64
65 assert_select 'tr' do
66 assert_select 'td.week-number', :text => '1'
67 assert_select 'td.odd', :text => '3'
68 assert_select 'td.even', :text => '9'
69 end
75
70
76 Setting.start_of_week = 1
71 Setting.start_of_week = 1
77 get :show, :month => '1', :year => '2010'
72 get :show, :month => '1', :year => '2010'
78 assert_response :success
73 assert_response :success
79
74
80 assert_tag :tag => 'tr',
75 assert_select 'tr' do
81 :descendant => {:tag => 'td',
76 assert_select 'td.week-number', :text => '53'
82 :attributes => {:class => 'week-number'}, :content => '53'},
77 assert_select 'td.even', :text => '28'
83 :descendant => {:tag => 'td',
78 assert_select 'td.even', :text => '3'
84 :attributes => {:class => 'even'}, :content => '28'},
79 end
85 :descendant => {:tag => 'td',
86 :attributes => {:class => 'even'}, :content => '3'}
87
88 assert_tag :tag => 'tr',
89 :descendant => {:tag => 'td',
90 :attributes => {:class => 'week-number'}, :content => '1'},
91 :descendant => {:tag => 'td',
92 :attributes => {:class => 'even'}, :content => '4'},
93 :descendant => {:tag => 'td',
94 :attributes => {:class => 'even'}, :content => '10'}
95
80
81 assert_select 'tr' do
82 assert_select 'td.week-number', :text => '1'
83 assert_select 'td.even', :text => '4'
84 assert_select 'td.even', :text => '10'
85 end
96 end
86 end
97 end
87 end
@@ -1,280 +1,247
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 ContextMenusControllerTest < ActionController::TestCase
20 class ContextMenusControllerTest < ActionController::TestCase
21 fixtures :projects,
21 fixtures :projects,
22 :trackers,
22 :trackers,
23 :projects_trackers,
23 :projects_trackers,
24 :roles,
24 :roles,
25 :member_roles,
25 :member_roles,
26 :members,
26 :members,
27 :enabled_modules,
27 :enabled_modules,
28 :workflows,
28 :workflows,
29 :journals, :journal_details,
29 :journals, :journal_details,
30 :versions,
30 :versions,
31 :issues, :issue_statuses, :issue_categories,
31 :issues, :issue_statuses, :issue_categories,
32 :users,
32 :users,
33 :enumerations,
33 :enumerations,
34 :time_entries
34 :time_entries
35
35
36 def test_context_menu_one_issue
36 def test_context_menu_one_issue
37 @request.session[:user_id] = 2
37 @request.session[:user_id] = 2
38 get :issues, :ids => [1]
38 get :issues, :ids => [1]
39 assert_response :success
39 assert_response :success
40 assert_template 'context_menu'
40 assert_template 'context_menu'
41 assert_tag :tag => 'a', :content => 'Edit',
41
42 :attributes => { :href => '/issues/1/edit',
42 assert_select 'a.icon-edit[href=?]', '/issues/1/edit', :text => 'Edit'
43 :class => 'icon-edit' }
43 assert_select 'a.icon-copy[href=?]', '/projects/ecookbook/issues/1/copy', :text => 'Copy'
44 assert_tag :tag => 'a', :content => 'Closed',
44 assert_select 'a.icon-del[href=?]', '/issues?ids%5B%5D=1', :text => 'Delete'
45 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5',
45
46 :class => '' }
46 # Statuses
47 assert_tag :tag => 'a', :content => 'Immediate',
47 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5', :text => 'Closed'
48 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8',
48 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8', :text => 'Immediate'
49 :class => '' }
49 # No inactive priorities
50 assert_no_tag :tag => 'a', :content => 'Inactive Priority'
50 assert_select 'a', :text => /Inactive Priority/, :count => 0
51 # Versions
51 # Versions
52 assert_tag :tag => 'a', :content => '2.0',
52 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3', :text => '2.0'
53 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3',
53 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4', :text => 'eCookbook Subproject 1 - 2.0'
54 :class => '' }
54 # Assignees
55 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
55 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3', :text => 'Dave Lopper'
56 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4',
57 :class => '' }
58
59 assert_tag :tag => 'a', :content => 'Dave Lopper',
60 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3',
61 :class => '' }
62 assert_tag :tag => 'a', :content => 'Copy',
63 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
64 :class => 'icon-copy' }
65 assert_no_tag :tag => 'a', :content => 'Move'
66 assert_tag :tag => 'a', :content => 'Delete',
67 :attributes => { :href => '/issues?ids%5B%5D=1',
68 :class => 'icon-del' }
69 end
56 end
70
57
71 def test_context_menu_one_issue_by_anonymous
58 def test_context_menu_one_issue_by_anonymous
72 get :issues, :ids => [1]
59 get :issues, :ids => [1]
73 assert_response :success
60 assert_response :success
74 assert_template 'context_menu'
61 assert_template 'context_menu'
75 assert_tag :tag => 'a', :content => 'Delete',
62 assert_tag :tag => 'a', :content => 'Delete',
76 :attributes => { :href => '#',
63 :attributes => { :href => '#',
77 :class => 'icon-del disabled' }
64 :class => 'icon-del disabled' }
78 end
65 end
79
66
80 def test_context_menu_multiple_issues_of_same_project
67 def test_context_menu_multiple_issues_of_same_project
81 @request.session[:user_id] = 2
68 @request.session[:user_id] = 2
82 get :issues, :ids => [1, 2]
69 get :issues, :ids => [1, 2]
83 assert_response :success
70 assert_response :success
84 assert_template 'context_menu'
71 assert_template 'context_menu'
85 assert_not_nil assigns(:issues)
72 assert_not_nil assigns(:issues)
86 assert_equal [1, 2], assigns(:issues).map(&:id).sort
73 assert_equal [1, 2], assigns(:issues).map(&:id).sort
87
74
88 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
75 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
89 assert_tag :tag => 'a', :content => 'Edit',
76
90 :attributes => { :href => "/issues/bulk_edit?#{ids}",
77 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
91 :class => 'icon-edit' }
78 assert_select 'a.icon-copy[href=?]', "/issues/bulk_edit?copy=1&amp;#{ids}", :text => 'Copy'
92 assert_tag :tag => 'a', :content => 'Closed',
79 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
93 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
80
94 :class => '' }
81 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
95 assert_tag :tag => 'a', :content => 'Immediate',
82 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
96 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
83 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3", :text => 'Dave Lopper'
97 :class => '' }
98 assert_tag :tag => 'a', :content => 'Dave Lopper',
99 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3",
100 :class => '' }
101 assert_tag :tag => 'a', :content => 'Copy',
102 :attributes => { :href => "/issues/bulk_edit?copy=1&amp;#{ids}",
103 :class => 'icon-copy' }
104 assert_no_tag :tag => 'a', :content => 'Move'
105 assert_tag :tag => 'a', :content => 'Delete',
106 :attributes => { :href => "/issues?#{ids}",
107 :class => 'icon-del' }
108 end
84 end
109
85
110 def test_context_menu_multiple_issues_of_different_projects
86 def test_context_menu_multiple_issues_of_different_projects
111 @request.session[:user_id] = 2
87 @request.session[:user_id] = 2
112 get :issues, :ids => [1, 2, 6]
88 get :issues, :ids => [1, 2, 6]
113 assert_response :success
89 assert_response :success
114 assert_template 'context_menu'
90 assert_template 'context_menu'
115 assert_not_nil assigns(:issues)
91 assert_not_nil assigns(:issues)
116 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
92 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
117
93
118 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
94 ids = assigns(:issues).map(&:id).sort.map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
119 assert_tag :tag => 'a', :content => 'Edit',
95
120 :attributes => { :href => "/issues/bulk_edit?#{ids}",
96 assert_select 'a.icon-edit[href=?]', "/issues/bulk_edit?#{ids}", :text => 'Edit'
121 :class => 'icon-edit' }
97 assert_select 'a.icon-del[href=?]', "/issues?#{ids}", :text => 'Delete'
122 assert_tag :tag => 'a', :content => 'Closed',
98
123 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
99 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5", :text => 'Closed'
124 :class => '' }
100 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8", :text => 'Immediate'
125 assert_tag :tag => 'a', :content => 'Immediate',
101 assert_select 'a[href=?]', "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2", :text => 'John Smith'
126 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
127 :class => '' }
128 assert_tag :tag => 'a', :content => 'John Smith',
129 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2",
130 :class => '' }
131 assert_tag :tag => 'a', :content => 'Delete',
132 :attributes => { :href => "/issues?#{ids}",
133 :class => 'icon-del' }
134 end
102 end
135
103
136 def test_context_menu_should_include_list_custom_fields
104 def test_context_menu_should_include_list_custom_fields
137 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
105 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
138 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
106 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
139 @request.session[:user_id] = 2
107 @request.session[:user_id] = 2
140 get :issues, :ids => [1]
108 get :issues, :ids => [1]
141
109
142 assert_tag 'a',
110 assert_select "li.cf_#{field.id}" do
143 :content => 'List',
111 assert_select 'a[href=#]', :text => 'List'
144 :attributes => {:href => '#'},
112 assert_select 'ul' do
145 :sibling => {:tag => 'ul', :children => {:count => 3}}
113 assert_select 'a', 3
146
114 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo", :text => 'Foo'
147 assert_tag 'a',
115 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=", :text => 'none'
148 :content => 'Foo',
116 end
149 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo"}
117 end
150 assert_tag 'a',
151 :content => 'none',
152 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D="}
153 end
118 end
154
119
155 def test_context_menu_should_not_include_null_value_for_required_custom_fields
120 def test_context_menu_should_not_include_null_value_for_required_custom_fields
156 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
121 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
157 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
122 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
158 @request.session[:user_id] = 2
123 @request.session[:user_id] = 2
159 get :issues, :ids => [1, 2]
124 get :issues, :ids => [1, 2]
160
125
161 assert_tag 'a',
126 assert_select "li.cf_#{field.id}" do
162 :content => 'List',
127 assert_select 'a[href=#]', :text => 'List'
163 :attributes => {:href => '#'},
128 assert_select 'ul' do
164 :sibling => {:tag => 'ul', :children => {:count => 2}}
129 assert_select 'a', 2
130 assert_select 'a', :text => 'none', :count => 0
131 end
132 end
165 end
133 end
166
134
167 def test_context_menu_on_single_issue_should_select_current_custom_field_value
135 def test_context_menu_on_single_issue_should_select_current_custom_field_value
168 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
136 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
169 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
137 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
170 issue = Issue.find(1)
138 issue = Issue.find(1)
171 issue.custom_field_values = {field.id => 'Bar'}
139 issue.custom_field_values = {field.id => 'Bar'}
172 issue.save!
140 issue.save!
173 @request.session[:user_id] = 2
141 @request.session[:user_id] = 2
174 get :issues, :ids => [1]
142 get :issues, :ids => [1]
175
143
176 assert_tag 'a',
144 assert_select "li.cf_#{field.id}" do
177 :content => 'List',
145 assert_select 'a[href=#]', :text => 'List'
178 :attributes => {:href => '#'},
146 assert_select 'ul' do
179 :sibling => {:tag => 'ul', :children => {:count => 3}}
147 assert_select 'a', 3
180 assert_tag 'a',
148 assert_select 'a.icon-checked', :text => 'Bar'
181 :content => 'Bar',
149 end
182 :attributes => {:class => /icon-checked/}
150 end
183 end
151 end
184
152
185 def test_context_menu_should_include_bool_custom_fields
153 def test_context_menu_should_include_bool_custom_fields
186 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
154 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
187 :is_for_all => true, :tracker_ids => [1, 2, 3])
155 :is_for_all => true, :tracker_ids => [1, 2, 3])
188 @request.session[:user_id] = 2
156 @request.session[:user_id] = 2
189 get :issues, :ids => [1]
157 get :issues, :ids => [1]
190
158
191 assert_tag 'a',
159 assert_select "li.cf_#{field.id}" do
192 :content => 'Bool',
160 assert_select 'a[href=#]', :text => 'Bool'
193 :attributes => {:href => '#'},
161 assert_select 'ul' do
194 :sibling => {:tag => 'ul', :children => {:count => 3}}
162 assert_select 'a', 3
195
163 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=0", :text => 'No'
196 assert_tag 'a',
164 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1", :text => 'Yes'
197 :content => 'Yes',
165 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=", :text => 'none'
198 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1"}
166 end
167 end
199 end
168 end
200
169
201 def test_context_menu_should_include_user_custom_fields
170 def test_context_menu_should_include_user_custom_fields
202 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
171 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
203 :is_for_all => true, :tracker_ids => [1, 2, 3])
172 :is_for_all => true, :tracker_ids => [1, 2, 3])
204 @request.session[:user_id] = 2
173 @request.session[:user_id] = 2
205 get :issues, :ids => [1]
174 get :issues, :ids => [1]
206
175
207 assert_tag 'a',
176 assert_select "li.cf_#{field.id}" do
208 :content => 'User',
177 assert_select 'a[href=#]', :text => 'User'
209 :attributes => {:href => '#'},
178 assert_select 'ul' do
210 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).members.count + 1}}
179 assert_select 'a', Project.find(1).members.count + 1
211
180 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2", :text => 'John Smith'
212 assert_tag 'a',
181 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=", :text => 'none'
213 :content => 'John Smith',
182 end
214 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2"}
183 end
215 end
184 end
216
185
217 def test_context_menu_should_include_version_custom_fields
186 def test_context_menu_should_include_version_custom_fields
218 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
187 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
219 @request.session[:user_id] = 2
188 @request.session[:user_id] = 2
220 get :issues, :ids => [1]
189 get :issues, :ids => [1]
221
190
222 assert_tag 'a',
191 assert_select "li.cf_#{field.id}" do
223 :content => 'Version',
192 assert_select 'a[href=#]', :text => 'Version'
224 :attributes => {:href => '#'},
193 assert_select 'ul' do
225 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).shared_versions.count + 1}}
194 assert_select 'a', Project.find(1).shared_versions.count + 1
226
195 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3", :text => '2.0'
227 assert_tag 'a',
196 assert_select 'a[href=?]', "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=", :text => 'none'
228 :content => '2.0',
197 end
229 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3"}
198 end
230 end
199 end
231
200
232 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
201 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
233 @request.session[:user_id] = 2
202 @request.session[:user_id] = 2
234 get :issues, :ids => [1]
203 get :issues, :ids => [1]
235 assert_response :success
204 assert_response :success
236 assert_template 'context_menu'
205 assert_template 'context_menu'
237
206
238 assert_tag :tag => 'a', :content => / me /,
207 assert_select 'a[href=?]', '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2', :text => / me /
239 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2',
240 :class => '' }
241 end
208 end
242
209
243 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
210 def test_context_menu_should_propose_shared_versions_for_issues_from_different_projects
244 @request.session[:user_id] = 2
211 @request.session[:user_id] = 2
245 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
212 version = Version.create!(:name => 'Shared', :sharing => 'system', :project_id => 1)
246
213
247 get :issues, :ids => [1, 4]
214 get :issues, :ids => [1, 4]
248 assert_response :success
215 assert_response :success
249 assert_template 'context_menu'
216 assert_template 'context_menu'
250
217
251 assert_include version, assigns(:versions)
218 assert_include version, assigns(:versions)
252 assert_tag :tag => 'a', :content => 'eCookbook - Shared'
219 assert_select 'a', :text => 'eCookbook - Shared'
253 end
220 end
254
221
255 def test_context_menu_issue_visibility
222 def test_context_menu_issue_visibility
256 get :issues, :ids => [1, 4]
223 get :issues, :ids => [1, 4]
257 assert_response :success
224 assert_response :success
258 assert_template 'context_menu'
225 assert_template 'context_menu'
259 assert_equal [1], assigns(:issues).collect(&:id)
226 assert_equal [1], assigns(:issues).collect(&:id)
260 end
227 end
261
228
262 def test_time_entries_context_menu
229 def test_time_entries_context_menu
263 @request.session[:user_id] = 2
230 @request.session[:user_id] = 2
264 get :time_entries, :ids => [1, 2]
231 get :time_entries, :ids => [1, 2]
265 assert_response :success
232 assert_response :success
266 assert_template 'time_entries'
233 assert_template 'time_entries'
267 assert_tag 'a', :content => 'Edit'
234
268 assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
235 assert_select 'a:not(.disabled)', :text => 'Edit'
269 end
236 end
270
237
271 def test_time_entries_context_menu_without_edit_permission
238 def test_time_entries_context_menu_without_edit_permission
272 @request.session[:user_id] = 2
239 @request.session[:user_id] = 2
273 Role.find_by_name('Manager').remove_permission! :edit_time_entries
240 Role.find_by_name('Manager').remove_permission! :edit_time_entries
274
241
275 get :time_entries, :ids => [1, 2]
242 get :time_entries, :ids => [1, 2]
276 assert_response :success
243 assert_response :success
277 assert_template 'time_entries'
244 assert_template 'time_entries'
278 assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
245 assert_select 'a.disabled', :text => 'Edit'
279 end
246 end
280 end
247 end
General Comments 0
You need to be logged in to leave comments. Login now