Revision 441:cbce1fd3b1b7 test/functional/.svn/text-base

View differences:

test/functional/.svn/text-base/activities_controller_test.rb.svn-base
8 8
    assert_response :success
9 9
    assert_template 'index'
10 10
    assert_not_nil assigns(:events_by_day)
11
    
12
    assert_tag :tag => "h3", 
11

  
12
    assert_tag :tag => "h3",
13 13
               :content => /#{2.days.ago.to_date.day}/,
14 14
               :sibling => { :tag => "dl",
15 15
                 :child => { :tag => "dt",
......
20 20
                 }
21 21
               }
22 22
  end
23
  
23

  
24 24
  def test_previous_project_index
25 25
    get :index, :id => 1, :from => 3.days.ago.to_date
26 26
    assert_response :success
27 27
    assert_template 'index'
28 28
    assert_not_nil assigns(:events_by_day)
29
               
30
    assert_tag :tag => "h3", 
29

  
30
    assert_tag :tag => "h3",
31 31
               :content => /#{3.day.ago.to_date.day}/,
32 32
               :sibling => { :tag => "dl",
33 33
                 :child => { :tag => "dt",
......
38 38
                 }
39 39
               }
40 40
  end
41
  
41

  
42 42
  def test_global_index
43 43
    get :index
44 44
    assert_response :success
45 45
    assert_template 'index'
46 46
    assert_not_nil assigns(:events_by_day)
47
    
48
    assert_tag :tag => "h3", 
47

  
48
    assert_tag :tag => "h3",
49 49
               :content => /#{5.day.ago.to_date.day}/,
50 50
               :sibling => { :tag => "dl",
51 51
                 :child => { :tag => "dt",
......
56 56
                 }
57 57
               }
58 58
  end
59
  
59

  
60 60
  def test_user_index
61 61
    get :index, :user_id => 2
62 62
    assert_response :success
63 63
    assert_template 'index'
64 64
    assert_not_nil assigns(:events_by_day)
65
    
66
    assert_tag :tag => "h3", 
65

  
66
    assert_tag :tag => "h3",
67 67
               :content => /#{3.day.ago.to_date.day}/,
68 68
               :sibling => { :tag => "dl",
69 69
                 :child => { :tag => "dt",
......
74 74
                 }
75 75
               }
76 76
  end
77
  
77

  
78 78
  def test_index_atom_feed
79 79
    get :index, :format => 'atom'
80 80
    assert_response :success
......
83 83
      :tag => 'link',
84 84
      :attributes => {:href => 'http://test.host/issues/11'}}
85 85
  end
86
  
87 86
end
test/functional/.svn/text-base/attachments_controller_test.rb.svn-base
7 7
# modify it under the terms of the GNU General Public License
8 8
# as published by the Free Software Foundation; either version 2
9 9
# of the License, or (at your option) any later version.
10
# 
10
#
11 11
# This program is distributed in the hope that it will be useful,
12 12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
# GNU General Public License for more details.
15
# 
15
#
16 16
# You should have received a copy of the GNU General Public License
17 17
# along with this program; if not, write to the Free Software
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
......
27 27
class AttachmentsControllerTest < ActionController::TestCase
28 28
  fixtures :users, :projects, :roles, :members, :member_roles, :enabled_modules, :issues, :trackers, :attachments,
29 29
           :versions, :wiki_pages, :wikis, :documents
30
  
30

  
31 31
  def setup
32 32
    @controller = AttachmentsController.new
33 33
    @request    = ActionController::TestRequest.new
......
35 35
    Attachment.storage_path = "#{RAILS_ROOT}/test/fixtures/files"
36 36
    User.current = nil
37 37
  end
38
  
38

  
39 39
  def test_show_diff
40 40
    get :show, :id => 14 # 060719210727_changeset_utf8.diff
41 41
    assert_response :success
42 42
    assert_template 'diff'
43 43
    assert_equal 'text/html', @response.content_type
44
    
44

  
45 45
    assert_tag 'th',
46 46
      :attributes => {:class => /filename/},
47 47
      :content => /issues_controller.rb\t\(révision 1484\)/
......
49 49
      :attributes => {:class => /line-code/},
50 50
      :content => /Demande créée avec succès/
51 51
  end
52
  
52

  
53 53
  def test_show_diff_should_strip_non_utf8_content
54 54
    get :show, :id => 5 # 060719210727_changeset_iso8859-1.diff
55 55
    assert_response :success
56 56
    assert_template 'diff'
57 57
    assert_equal 'text/html', @response.content_type
58
    
58

  
59 59
    assert_tag 'th',
60 60
      :attributes => {:class => /filename/},
61 61
      :content => /issues_controller.rb\t\(rvision 1484\)/
......
63 63
      :attributes => {:class => /line-code/},
64 64
      :content => /Demande cre avec succs/
65 65
  end
66
  
66

  
67 67
  def test_show_text_file
68 68
    get :show, :id => 4
69 69
    assert_response :success
70 70
    assert_template 'file'
71 71
    assert_equal 'text/html', @response.content_type
72 72
  end
73
  
73

  
74 74
  def test_show_text_file_should_send_if_too_big
75 75
    Setting.file_max_size_displayed = 512
76 76
    Attachment.find(4).update_attribute :filesize, 754.kilobyte
77
    
77

  
78 78
    get :show, :id => 4
79 79
    assert_response :success
80 80
    assert_equal 'application/x-ruby', @response.content_type
81 81
  end
82
  
82

  
83 83
  def test_show_other
84 84
    get :show, :id => 6
85 85
    assert_response :success
86 86
    assert_equal 'application/octet-stream', @response.content_type
87 87
  end
88
  
88

  
89
  def test_show_file_from_private_issue_without_permission
90
    get :show, :id => 15
91
    assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2F15'
92
  end
93

  
94
  def test_show_file_from_private_issue_with_permission
95
    @request.session[:user_id] = 2
96
    get :show, :id => 15
97
    assert_response :success
98
    assert_tag 'h2', :content => /private.diff/
99
  end
100

  
89 101
  def test_download_text_file
90 102
    get :download, :id => 4
91 103
    assert_response :success
92 104
    assert_equal 'application/x-ruby', @response.content_type
93 105
  end
94
  
106

  
95 107
  def test_download_should_assign_content_type_if_blank
96 108
    Attachment.find(4).update_attribute(:content_type, '')
97
    
109

  
98 110
    get :download, :id => 4
99 111
    assert_response :success
100 112
    assert_equal 'text/x-ruby', @response.content_type
101 113
  end
102
  
114

  
103 115
  def test_download_missing_file
104 116
    get :download, :id => 2
105 117
    assert_response 404
106 118
  end
107
  
119

  
108 120
  def test_anonymous_on_private_private
109 121
    get :download, :id => 7
110 122
    assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdownload%2F7'
111 123
  end
112
  
124

  
113 125
  def test_destroy_issue_attachment
114 126
    issue = Issue.find(3)
115 127
    @request.session[:user_id] = 2
116
    
128

  
117 129
    assert_difference 'issue.attachments.count', -1 do
118 130
      post :destroy, :id => 1
119 131
    end
......
125 137
    assert_equal '1', j.details.first.prop_key
126 138
    assert_equal 'error281.txt', j.details.first.old_value
127 139
  end
128
  
140

  
129 141
  def test_destroy_wiki_page_attachment
130 142
    @request.session[:user_id] = 2
131 143
    assert_difference 'Attachment.count', -1 do
......
133 145
      assert_response 302
134 146
    end
135 147
  end
136
  
148

  
137 149
  def test_destroy_project_attachment
138 150
    @request.session[:user_id] = 2
139 151
    assert_difference 'Attachment.count', -1 do
......
141 153
      assert_response 302
142 154
    end
143 155
  end
144
  
156

  
145 157
  def test_destroy_version_attachment
146 158
    @request.session[:user_id] = 2
147 159
    assert_difference 'Attachment.count', -1 do
......
149 161
      assert_response 302
150 162
    end
151 163
  end
152
  
164

  
153 165
  def test_destroy_without_permission
154 166
    post :destroy, :id => 3
155 167
    assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fattachments%2Fdestroy%2F3'
test/functional/.svn/text-base/auth_sources_controller_test.rb.svn-base
66 66
  end
67 67

  
68 68
  context "post :destroy" do
69
    setup do
70
      @auth_source = AuthSource.generate!(:name => 'TestEdit')
71
    end
72
    
69 73
    context "without users" do
70 74
      setup do
71
        @auth_source = AuthSource.generate!(:name => 'TestEdit')
72 75
        post :destroy, :id => @auth_source.id
73 76
      end
74 77

  
75 78
      should_respond_with :redirect
76 79
      should_redirect_to("index") {{:action => 'index'}}
77 80
      should_set_the_flash_to /deletion/i
78

  
79 81
    end
80 82
    
81
    should "be tested with users"
83
    context "with users" do
84
      setup do
85
        User.generate!(:auth_source => @auth_source)
86
        post :destroy, :id => @auth_source.id
87
      end
88
      
89
      should_respond_with :redirect
90
      should "not destroy the AuthSource" do
91
        assert AuthSource.find(@auth_source.id)
92
      end
93
    end
82 94
  end
83 95
end
test/functional/.svn/text-base/custom_fields_controller_test.rb.svn-base
1 1
# Redmine - project management software
2
# Copyright (C) 2006-2009  Jean-Philippe Lang
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 3
#
4 4
# This program is free software; you can redistribute it and/or
5 5
# modify it under the terms of the GNU General Public License
......
31 31
    @request.session[:user_id] = 1
32 32
  end
33 33
  
34
  def test_get_new_issue_custom_field
35
    get :new, :type => 'IssueCustomField'
36
    assert_response :success
37
    assert_template 'new'
38
    assert_tag :select,
39
      :attributes => {:name => 'custom_field[field_format]'},
40
      :child => {
41
        :tag => 'option',
42
        :attributes => {:value => 'user'},
43
        :content => 'User'
44
      }
45
    assert_tag :select,
46
      :attributes => {:name => 'custom_field[field_format]'},
47
      :child => {
48
        :tag => 'option',
49
        :attributes => {:value => 'version'},
50
        :content => 'Version'
51
      }
52
  end
53
  
54
  def test_get_new_with_invalid_custom_field_class_should_redirect_to_list
55
    get :new, :type => 'UnknownCustomField'
56
    assert_redirected_to '/custom_fields'
57
  end
58
  
34 59
  def test_post_new_list_custom_field
35 60
    assert_difference 'CustomField.count' do
36 61
      post :new, :type => "IssueCustomField",
......
53 78
    assert_equal ["0.1", "0.2"], field.possible_values
54 79
    assert_equal 1, field.trackers.size
55 80
  end
56
  
57
  def test_invalid_custom_field_class_should_redirect_to_list
58
    get :new, :type => 'UnknownCustomField'
59
    assert_redirected_to '/custom_fields'
60
  end
61 81
end
test/functional/.svn/text-base/documents_controller_test.rb.svn-base
1
# redMine - project management software
2
# Copyright (C) 2006-2007  Jean-Philippe Lang
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 3
#
4 4
# This program is free software; you can redistribute it and/or
5 5
# modify it under the terms of the GNU General Public License
6 6
# as published by the Free Software Foundation; either version 2
7 7
# of the License, or (at your option) any later version.
8
# 
8
#
9 9
# This program is distributed in the hope that it will be useful,
10 10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12
# GNU General Public License for more details.
13
# 
13
#
14 14
# You should have received a copy of the GNU General Public License
15 15
# along with this program; if not, write to the Free Software
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
......
23 23

  
24 24
class DocumentsControllerTest < ActionController::TestCase
25 25
  fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :documents, :enumerations
26
  
26

  
27 27
  def setup
28 28
    @controller = DocumentsController.new
29 29
    @request    = ActionController::TestRequest.new
30 30
    @response   = ActionController::TestResponse.new
31 31
    User.current = nil
32 32
  end
33
  
33

  
34 34
  def test_index
35 35
    # Sets a default category
36 36
    e = Enumeration.find_by_name('Technical documentation')
37 37
    e.update_attributes(:is_default => true)
38
    
38

  
39 39
    get :index, :project_id => 'ecookbook'
40 40
    assert_response :success
41 41
    assert_template 'index'
42 42
    assert_not_nil assigns(:grouped)
43
    
43

  
44 44
    # Default category selected in the new document form
45 45
    assert_tag :select, :attributes => {:name => 'document[category_id]'},
46 46
                        :child => {:tag => 'option', :attributes => {:selected => 'selected'},
47 47
                                                     :content => 'Technical documentation'}
48 48
  end
49
  
49

  
50 50
  def test_index_with_long_description
51 51
    # adds a long description to the first document
52 52
    doc = documents(:documents_001)
......
55 55

  
56 56
Vestibulum non velit mi. Aliquam scelerisque libero ut nulla fringilla a sollicitudin magna rhoncus.  Praesent a nunc lorem, ac porttitor eros. Sed ac diam nec neque interdum adipiscing quis quis justo. Donec arcu nunc, fringilla eu dictum at, venenatis ac sem. Vestibulum quis elit urna, ac mattis sapien. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
57 57
LOREM
58
    
58

  
59 59
    get :index, :project_id => 'ecookbook'
60 60
    assert_response :success
61 61
    assert_template 'index'
......
64 64
    assert_select '.wiki p', :text => (doc.description.split("\n").first + '...')
65 65
    assert_select '.wiki p', :text => Regexp.new(Regexp.escape("EndOfLineHere..."))
66 66
  end
67
  
67

  
68 68
  def test_new_with_one_attachment
69 69
    ActionMailer::Base.deliveries.clear
70 70
    Setting.notified_events << 'document_added'
71 71
    @request.session[:user_id] = 2
72 72
    set_tmp_attachments_directory
73
    
73

  
74 74
    post :new, :project_id => 'ecookbook',
75 75
               :document => { :title => 'DocumentsControllerTest#test_post_new',
76 76
                              :description => 'This is a new document',
77 77
                              :category_id => 2},
78 78
               :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
79
               
79

  
80 80
    assert_redirected_to '/projects/ecookbook/documents'
81
    
81

  
82 82
    document = Document.find_by_title('DocumentsControllerTest#test_post_new')
83 83
    assert_not_nil document
84 84
    assert_equal Enumeration.find(2), document.category
......
86 86
    assert_equal 'testfile.txt', document.attachments.first.filename
87 87
    assert_equal 1, ActionMailer::Base.deliveries.size
88 88
  end
89
  
89

  
90 90
  def test_destroy
91 91
    @request.session[:user_id] = 2
92 92
    post :destroy, :id => 1
test/functional/.svn/text-base/groups_controller_test.rb.svn-base
104 104
      post :destroy_membership, :id => 10, :membership_id => 6
105 105
    end
106 106
  end
107
  
108
  def test_autocomplete_for_user
109
    get :autocomplete_for_user, :id => 10, :q => 'mis'
110
    assert_response :success
111
    users = assigns(:users)
112
    assert_not_nil users
113
    assert users.any?
114
    assert !users.include?(Group.find(10).users.first)
115
  end
107 116
end
test/functional/.svn/text-base/issue_moves_controller_test.rb.svn-base
112 112
        assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
113 113
      end
114 114
    end
115

  
116
    should "allow adding a note when copying" do
117
      @request.session[:user_id] = 2
118
      assert_difference 'Issue.count', 1 do
119
        post :create, :ids => [1], :copy_options => {:copy => '1'}, :notes => 'Copying one issue', :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
120
      end
121
      
122
      issue = Issue.first(:order => 'id DESC')
123
      assert_equal 1, issue.journals.size
124
      journal = issue.journals.first
125
      assert_equal 0, journal.details.size
126
      assert_equal 'Copying one issue', journal.notes
127
    end
115 128
  end
116 129
  
117 130
  def test_copy_to_another_project_should_follow_when_needed
test/functional/.svn/text-base/issues_controller_test.rb.svn-base
1 1
# Redmine - project management software
2
# Copyright (C) 2006-2008  Jean-Philippe Lang
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 3
#
4 4
# This program is free software; you can redistribute it and/or
5 5
# modify it under the terms of the GNU General Public License
6 6
# as published by the Free Software Foundation; either version 2
7 7
# of the License, or (at your option) any later version.
8
# 
8
#
9 9
# This program is distributed in the hope that it will be useful,
10 10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12
# GNU General Public License for more details.
13
# 
13
#
14 14
# You should have received a copy of the GNU General Public License
15 15
# along with this program; if not, write to the Free Software
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
......
45 45
           :journals,
46 46
           :journal_details,
47 47
           :queries
48
  
48

  
49 49
  def setup
50 50
    @controller = IssuesController.new
51 51
    @request    = ActionController::TestRequest.new
52 52
    @response   = ActionController::TestResponse.new
53 53
    User.current = nil
54 54
  end
55
  
55

  
56 56
  def test_index
57 57
    Setting.default_language = 'en'
58
    
58

  
59 59
    get :index
60 60
    assert_response :success
61 61
    assert_template 'index.rhtml'
......
69 69
    # project column
70 70
    assert_tag :tag => 'th', :content => /Project/
71 71
  end
72
  
72

  
73 73
  def test_index_should_not_list_issues_when_module_disabled
74 74
    EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 75
    get :index
......
91 91
    assert_no_tag :tag => 'a', :content => /Can't print recipes/
92 92
    assert_tag :tag => 'a', :content => /Subproject issue/
93 93
  end
94
  
94

  
95
  def test_index_should_list_visible_issues_only
96
    get :index, :per_page => 100
97
    assert_response :success
98
    assert_not_nil assigns(:issues)
99
    assert_nil assigns(:issues).detect {|issue| !issue.visible?}
100
  end
101

  
95 102
  def test_index_with_project
96 103
    Setting.display_subprojects_issues = 0
97 104
    get :index, :project_id => 1
......
101 108
    assert_tag :tag => 'a', :content => /Can't print recipes/
102 109
    assert_no_tag :tag => 'a', :content => /Subproject issue/
103 110
  end
104
  
111

  
105 112
  def test_index_with_project_and_subprojects
106 113
    Setting.display_subprojects_issues = 1
107 114
    get :index, :project_id => 1
......
112 119
    assert_tag :tag => 'a', :content => /Subproject issue/
113 120
    assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
114 121
  end
115
  
122

  
116 123
  def test_index_with_project_and_subprojects_should_show_private_subprojects
117 124
    @request.session[:user_id] = 2
118 125
    Setting.display_subprojects_issues = 1
......
124 131
    assert_tag :tag => 'a', :content => /Subproject issue/
125 132
    assert_tag :tag => 'a', :content => /Issue of a private subproject/
126 133
  end
127
  
134

  
128 135
  def test_index_with_project_and_default_filter
129 136
    get :index, :project_id => 1, :set_filter => 1
130 137
    assert_response :success
131 138
    assert_template 'index.rhtml'
132 139
    assert_not_nil assigns(:issues)
133
    
140

  
134 141
    query = assigns(:query)
135 142
    assert_not_nil query
136 143
    # default filter
137 144
    assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
138 145
  end
139
  
146

  
140 147
  def test_index_with_project_and_filter
141
    get :index, :project_id => 1, :set_filter => 1, 
142
      :fields => ['tracker_id'],
143
      :operators => {'tracker_id' => '='},
144
      :values => {'tracker_id' => ['1']} 
148
    get :index, :project_id => 1, :set_filter => 1,
149
      :f => ['tracker_id'],
150
      :op => {'tracker_id' => '='},
151
      :v => {'tracker_id' => ['1']}
145 152
    assert_response :success
146 153
    assert_template 'index.rhtml'
147 154
    assert_not_nil assigns(:issues)
148
    
155

  
149 156
    query = assigns(:query)
150 157
    assert_not_nil query
151 158
    assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
152 159
  end
153
  
160

  
154 161
  def test_index_with_project_and_empty_filters
155 162
    get :index, :project_id => 1, :set_filter => 1, :fields => ['']
156 163
    assert_response :success
157 164
    assert_template 'index.rhtml'
158 165
    assert_not_nil assigns(:issues)
159
    
166

  
160 167
    query = assigns(:query)
161 168
    assert_not_nil query
162 169
    # no filter
163 170
    assert_equal({}, query.filters)
164 171
  end
165
  
172

  
166 173
  def test_index_with_query
167 174
    get :index, :project_id => 1, :query_id => 5
168 175
    assert_response :success
......
170 177
    assert_not_nil assigns(:issues)
171 178
    assert_nil assigns(:issue_count_by_group)
172 179
  end
173
  
180

  
174 181
  def test_index_with_query_grouped_by_tracker
175 182
    get :index, :project_id => 1, :query_id => 6
176 183
    assert_response :success
......
178 185
    assert_not_nil assigns(:issues)
179 186
    assert_not_nil assigns(:issue_count_by_group)
180 187
  end
181
  
188

  
182 189
  def test_index_with_query_grouped_by_list_custom_field
183 190
    get :index, :project_id => 1, :query_id => 9
184 191
    assert_response :success
......
186 193
    assert_not_nil assigns(:issues)
187 194
    assert_not_nil assigns(:issue_count_by_group)
188 195
  end
189
  
196

  
190 197
  def test_index_sort_by_field_not_included_in_columns
191 198
    Setting.issue_list_default_columns = %w(subject author)
192 199
    get :index, :sort => 'tracker'
193 200
  end
194
  
201

  
195 202
  def test_index_csv_with_project
196 203
    Setting.default_language = 'en'
197
    
204

  
198 205
    get :index, :format => 'csv'
199 206
    assert_response :success
200 207
    assert_not_nil assigns(:issues)
......
206 213
    assert_not_nil assigns(:issues)
207 214
    assert_equal 'text/csv', @response.content_type
208 215
  end
209
  
216

  
210 217
  def test_index_pdf
211 218
    get :index, :format => 'pdf'
212 219
    assert_response :success
213 220
    assert_not_nil assigns(:issues)
214 221
    assert_equal 'application/pdf', @response.content_type
215
    
222

  
216 223
    get :index, :project_id => 1, :format => 'pdf'
217 224
    assert_response :success
218 225
    assert_not_nil assigns(:issues)
219 226
    assert_equal 'application/pdf', @response.content_type
220
    
227

  
221 228
    get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
222 229
    assert_response :success
223 230
    assert_not_nil assigns(:issues)
224 231
    assert_equal 'application/pdf', @response.content_type
225 232
  end
226
  
233

  
227 234
  def test_index_pdf_with_query_grouped_by_list_custom_field
228 235
    get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
229 236
    assert_response :success
......
231 238
    assert_not_nil assigns(:issue_count_by_group)
232 239
    assert_equal 'application/pdf', @response.content_type
233 240
  end
234
  
241

  
235 242
  def test_index_sort
236 243
    get :index, :sort => 'tracker,id:desc'
237 244
    assert_response :success
238
    
245

  
239 246
    sort_params = @request.session['issues_index_sort']
240 247
    assert sort_params.is_a?(String)
241 248
    assert_equal 'tracker,id:desc', sort_params
242
    
249

  
243 250
    issues = assigns(:issues)
244 251
    assert_not_nil issues
245 252
    assert !issues.empty?
246 253
    assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
247 254
  end
248
  
255

  
249 256
  def test_index_with_columns
250 257
    columns = ['tracker', 'subject', 'assigned_to']
251
    get :index, :set_filter => 1, :query => { 'column_names' => columns}
258
    get :index, :set_filter => 1, :c => columns
252 259
    assert_response :success
253
    
260

  
254 261
    # query should use specified columns
255 262
    query = assigns(:query)
256 263
    assert_kind_of Query, query
257 264
    assert_equal columns, query.column_names.map(&:to_s)
258
    
265

  
259 266
    # columns should be stored in session
260 267
    assert_kind_of Hash, session[:query]
261 268
    assert_kind_of Array, session[:query][:column_names]
262 269
    assert_equal columns, session[:query][:column_names].map(&:to_s)
263 270
  end
264 271

  
272
  def test_index_with_custom_field_column
273
    columns = %w(tracker subject cf_2)
274
    get :index, :set_filter => 1, :c => columns
275
    assert_response :success
276

  
277
    # query should use specified columns
278
    query = assigns(:query)
279
    assert_kind_of Query, query
280
    assert_equal columns, query.column_names.map(&:to_s)
281

  
282
    assert_tag :td,
283
      :attributes => {:class => 'cf_2 string'},
284
      :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
285
  end
286

  
265 287
  def test_show_by_anonymous
266 288
    get :show, :id => 1
267 289
    assert_response :success
268 290
    assert_template 'show.rhtml'
269 291
    assert_not_nil assigns(:issue)
270 292
    assert_equal Issue.find(1), assigns(:issue)
271
    
293

  
272 294
    # anonymous role is allowed to add a note
273 295
    assert_tag :tag => 'form',
274 296
               :descendant => { :tag => 'fieldset',
275
                                :child => { :tag => 'legend', 
297
                                :child => { :tag => 'legend',
276 298
                                            :content => /Notes/ } }
277 299
  end
278
  
300

  
279 301
  def test_show_by_manager
280 302
    @request.session[:user_id] = 2
281 303
    get :show, :id => 1
282 304
    assert_response :success
283
    
305

  
284 306
    assert_tag :tag => 'a',
285 307
      :content => /Quote/
286
    
308

  
287 309
    assert_tag :tag => 'form',
288 310
               :descendant => { :tag => 'fieldset',
289
                                :child => { :tag => 'legend', 
311
                                :child => { :tag => 'legend',
290 312
                                            :content => /Change properties/ } },
291 313
               :descendant => { :tag => 'fieldset',
292
                                :child => { :tag => 'legend', 
314
                                :child => { :tag => 'legend',
293 315
                                            :content => /Log time/ } },
294 316
               :descendant => { :tag => 'fieldset',
295
                                :child => { :tag => 'legend', 
317
                                :child => { :tag => 'legend',
296 318
                                            :content => /Notes/ } }
297 319
  end
298
  
320

  
299 321
  def test_show_should_deny_anonymous_access_without_permission
300 322
    Role.anonymous.remove_permission!(:view_issues)
301 323
    get :show, :id => 1
302 324
    assert_response :redirect
303 325
  end
304
  
326

  
327
  def test_show_should_deny_anonymous_access_to_private_issue
328
    Issue.update_all(["is_private = ?", true], "id = 1")
329
    get :show, :id => 1
330
    assert_response :redirect
331
  end
332

  
305 333
  def test_show_should_deny_non_member_access_without_permission
306 334
    Role.non_member.remove_permission!(:view_issues)
307 335
    @request.session[:user_id] = 9
308 336
    get :show, :id => 1
309 337
    assert_response 403
310 338
  end
311
  
339

  
340
  def test_show_should_deny_non_member_access_to_private_issue
341
    Issue.update_all(["is_private = ?", true], "id = 1")
342
    @request.session[:user_id] = 9
343
    get :show, :id => 1
344
    assert_response 403
345
  end
346

  
312 347
  def test_show_should_deny_member_access_without_permission
313 348
    Role.find(1).remove_permission!(:view_issues)
314 349
    @request.session[:user_id] = 2
315 350
    get :show, :id => 1
316 351
    assert_response 403
317 352
  end
318
  
353

  
354
  def test_show_should_deny_member_access_to_private_issue_without_permission
355
    Issue.update_all(["is_private = ?", true], "id = 1")
356
    @request.session[:user_id] = 3
357
    get :show, :id => 1
358
    assert_response 403
359
  end
360

  
361
  def test_show_should_allow_author_access_to_private_issue
362
    Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
363
    @request.session[:user_id] = 3
364
    get :show, :id => 1
365
    assert_response :success
366
  end
367

  
368
  def test_show_should_allow_assignee_access_to_private_issue
369
    Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
370
    @request.session[:user_id] = 3
371
    get :show, :id => 1
372
    assert_response :success
373
  end
374

  
375
  def test_show_should_allow_member_access_to_private_issue_with_permission
376
    Issue.update_all(["is_private = ?", true], "id = 1")
377
    User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
378
    @request.session[:user_id] = 3
379
    get :show, :id => 1
380
    assert_response :success
381
  end
382

  
319 383
  def test_show_should_not_disclose_relations_to_invisible_issues
320 384
    Setting.cross_project_issue_relations = '1'
321 385
    IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
322 386
    # Relation to a private project issue
323 387
    IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
324
    
388

  
325 389
    get :show, :id => 1
326 390
    assert_response :success
327
    
391

  
328 392
    assert_tag :div, :attributes => { :id => 'relations' },
329 393
                     :descendant => { :tag => 'a', :content => /#2$/ }
330 394
    assert_no_tag :div, :attributes => { :id => 'relations' },
331 395
                        :descendant => { :tag => 'a', :content => /#4$/ }
332 396
  end
333
  
397

  
334 398
  def test_show_atom
335 399
    get :show, :id => 2, :format => 'atom'
336 400
    assert_response :success
......
338 402
    # Inline image
339 403
    assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
340 404
  end
341
  
405

  
342 406
  def test_show_export_to_pdf
343 407
    get :show, :id => 3, :format => 'pdf'
344 408
    assert_response :success
......
352 416
    get :new, :project_id => 1, :tracker_id => 1
353 417
    assert_response :success
354 418
    assert_template 'new'
355
    
419

  
356 420
    assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
357 421
                                                 :value => 'Default string' }
358 422
  end
......
362 426
    get :new, :project_id => 1
363 427
    assert_response :success
364 428
    assert_template 'new'
365
    
429

  
366 430
    issue = assigns(:issue)
367 431
    assert_not_nil issue
368 432
    assert_equal Project.find(1).trackers.first, issue.tracker
369 433
  end
370
  
434

  
371 435
  def test_get_new_with_no_default_status_should_display_an_error
372 436
    @request.session[:user_id] = 2
373 437
    IssueStatus.delete_all
374
    
438

  
375 439
    get :new, :project_id => 1
376 440
    assert_response 500
377 441
    assert_error_tag :content => /No default issue/
378 442
  end
379
  
443

  
380 444
  def test_get_new_with_no_tracker_should_display_an_error
381 445
    @request.session[:user_id] = 2
382 446
    Tracker.delete_all
383
    
447

  
384 448
    get :new, :project_id => 1
385 449
    assert_response 500
386 450
    assert_error_tag :content => /No tracker/
387 451
  end
388
  
452

  
389 453
  def test_update_new_form
390 454
    @request.session[:user_id] = 2
391 455
    xhr :post, :new, :project_id => 1,
392
                     :issue => {:tracker_id => 2, 
456
                     :issue => {:tracker_id => 2,
393 457
                                :subject => 'This is the test_new issue',
394 458
                                :description => 'This is the description',
395 459
                                :priority_id => 5}
396 460
    assert_response :success
397 461
    assert_template 'attributes'
398
    
462

  
399 463
    issue = assigns(:issue)
400 464
    assert_kind_of Issue, issue
401 465
    assert_equal 1, issue.project_id
402 466
    assert_equal 2, issue.tracker_id
403 467
    assert_equal 'This is the test_new issue', issue.subject
404 468
  end
405
  
469

  
406 470
  def test_post_create
407 471
    @request.session[:user_id] = 2
408 472
    assert_difference 'Issue.count' do
409
      post :create, :project_id => 1, 
473
      post :create, :project_id => 1,
410 474
                 :issue => {:tracker_id => 3,
411 475
                            :status_id => 2,
412 476
                            :subject => 'This is the test_new issue',
......
417 481
                            :custom_field_values => {'2' => 'Value for field 2'}}
418 482
    end
419 483
    assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
420
    
484

  
421 485
    issue = Issue.find_by_subject('This is the test_new issue')
422 486
    assert_not_nil issue
423 487
    assert_equal 2, issue.author_id
......
429 493
    assert_not_nil v
430 494
    assert_equal 'Value for field 2', v.value
431 495
  end
432
  
496

  
433 497
  def test_post_create_without_start_date
434 498
    @request.session[:user_id] = 2
435 499
    assert_difference 'Issue.count' do
436
      post :create, :project_id => 1, 
500
      post :create, :project_id => 1,
437 501
                 :issue => {:tracker_id => 3,
438 502
                            :status_id => 2,
439 503
                            :subject => 'This is the test_new issue',
......
444 508
                            :custom_field_values => {'2' => 'Value for field 2'}}
445 509
    end
446 510
    assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
447
    
511

  
448 512
    issue = Issue.find_by_subject('This is the test_new issue')
449 513
    assert_not_nil issue
450 514
    assert_nil issue.start_date
451 515
  end
452
  
516

  
453 517
  def test_post_create_and_continue
454 518
    @request.session[:user_id] = 2
455
    post :create, :project_id => 1, 
519
    post :create, :project_id => 1,
456 520
               :issue => {:tracker_id => 3,
457 521
                          :subject => 'This is first issue',
458 522
                          :priority_id => 5},
......
460 524
    assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook',
461 525
                         :issue => {:tracker_id => 3}
462 526
  end
463
  
527

  
464 528
  def test_post_create_without_custom_fields_param
465 529
    @request.session[:user_id] = 2
466 530
    assert_difference 'Issue.count' do
467
      post :create, :project_id => 1, 
531
      post :create, :project_id => 1,
468 532
                 :issue => {:tracker_id => 1,
469 533
                            :subject => 'This is the test_new issue',
470 534
                            :description => 'This is the description',
......
478 542
    field.update_attribute(:is_required, true)
479 543

  
480 544
    @request.session[:user_id] = 2
481
    post :create, :project_id => 1, 
545
    post :create, :project_id => 1,
482 546
               :issue => {:tracker_id => 1,
483 547
                          :subject => 'This is the test_new issue',
484 548
                          :description => 'This is the description',
......
489 553
    assert_not_nil issue
490 554
    assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
491 555
  end
492
  
556

  
493 557
  def test_post_create_with_watchers
494 558
    @request.session[:user_id] = 2
495 559
    ActionMailer::Base.deliveries.clear
496
    
560

  
497 561
    assert_difference 'Watcher.count', 2 do
498
      post :create, :project_id => 1, 
562
      post :create, :project_id => 1,
499 563
                 :issue => {:tracker_id => 1,
500 564
                            :subject => 'This is a new issue with watchers',
501 565
                            :description => 'This is the description',
......
505 569
    issue = Issue.find_by_subject('This is a new issue with watchers')
506 570
    assert_not_nil issue
507 571
    assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
508
    
572

  
509 573
    # Watchers added
510 574
    assert_equal [2, 3], issue.watcher_user_ids.sort
511 575
    assert issue.watched_by?(User.find(3))
......
514 578
    assert_kind_of TMail::Mail, mail
515 579
    assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
516 580
  end
517
  
581

  
518 582
  def test_post_create_subissue
519 583
    @request.session[:user_id] = 2
520
    
584

  
521 585
    assert_difference 'Issue.count' do
522
      post :create, :project_id => 1, 
586
      post :create, :project_id => 1,
523 587
                 :issue => {:tracker_id => 1,
524 588
                            :subject => 'This is a child issue',
525 589
                            :parent_issue_id => 2}
......
531 595

  
532 596
  def test_post_create_subissue_with_non_numeric_parent_id
533 597
    @request.session[:user_id] = 2
534
    
598

  
535 599
    assert_difference 'Issue.count' do
536
      post :create, :project_id => 1, 
600
      post :create, :project_id => 1,
537 601
                 :issue => {:tracker_id => 1,
538 602
                            :subject => 'This is a child issue',
539 603
                            :parent_issue_id => 'ABC'}
......
542 606
    assert_not_nil issue
543 607
    assert_nil issue.parent
544 608
  end
545
  
609

  
546 610
  def test_post_create_should_send_a_notification
547 611
    ActionMailer::Base.deliveries.clear
548 612
    @request.session[:user_id] = 2
549 613
    assert_difference 'Issue.count' do
550
      post :create, :project_id => 1, 
614
      post :create, :project_id => 1,
551 615
                 :issue => {:tracker_id => 3,
552 616
                            :subject => 'This is the test_new issue',
553 617
                            :description => 'This is the description',
......
556 620
                            :custom_field_values => {'2' => 'Value for field 2'}}
557 621
    end
558 622
    assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
559
    
623

  
560 624
    assert_equal 1, ActionMailer::Base.deliveries.size
561 625
  end
562
  
626

  
563 627
  def test_post_create_should_preserve_fields_values_on_validation_failure
564 628
    @request.session[:user_id] = 2
565
    post :create, :project_id => 1, 
629
    post :create, :project_id => 1,
566 630
               :issue => {:tracker_id => 1,
567 631
                          # empty subject
568 632
                          :subject => '',
......
571 635
                          :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
572 636
    assert_response :success
573 637
    assert_template 'new'
574
    
638

  
575 639
    assert_tag :textarea, :attributes => { :name => 'issue[description]' },
576 640
                          :content => 'This is a description'
577 641
    assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
578 642
                        :child => { :tag => 'option', :attributes => { :selected => 'selected',
579 643
                                                                       :value => '6' },
580
                                                      :content => 'High' }  
644
                                                      :content => 'High' }
581 645
    # Custom fields
582 646
    assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
583 647
                        :child => { :tag => 'option', :attributes => { :selected => 'selected',
584 648
                                                                       :value => 'Oracle' },
585
                                                      :content => 'Oracle' }  
649
                                                      :content => 'Oracle' }
586 650
    assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
587 651
                                        :value => 'Value for field 2'}
588 652
  end
589
  
653

  
590 654
  def test_post_create_should_ignore_non_safe_attributes
591 655
    @request.session[:user_id] = 2
592 656
    assert_nothing_raised do
593 657
      post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
594 658
    end
595 659
  end
596
  
660

  
597 661
  context "without workflow privilege" do
598 662
    setup do
599 663
      Workflow.delete_all(["role_id = ?", Role.anonymous.id])
600 664
      Role.anonymous.add_permission! :add_issues, :add_issue_notes
601 665
    end
602
    
666

  
603 667
    context "#new" do
604 668
      should "propose default status only" do
605 669
        get :new, :project_id => 1
......
610 674
          :children => {:count => 1},
611 675
          :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
612 676
      end
613
      
677

  
614 678
      should "accept default status" do
615 679
        assert_difference 'Issue.count' do
616
          post :create, :project_id => 1, 
680
          post :create, :project_id => 1,
617 681
                     :issue => {:tracker_id => 1,
618 682
                                :subject => 'This is an issue',
619 683
                                :status_id => 1}
......
621 685
        issue = Issue.last(:order => 'id')
622 686
        assert_equal IssueStatus.default, issue.status
623 687
      end
624
      
625
      should "accept default status" do
626
        assert_difference 'Issue.count' do
627
          post :create, :project_id => 1, 
628
                     :issue => {:tracker_id => 1,
629
                                :subject => 'This is an issue',
630
                                :status_id => 1}
631
        end
632
        issue = Issue.last(:order => 'id')
633
        assert_equal IssueStatus.default, issue.status
634
      end
635
      
688

  
636 689
      should "ignore unauthorized status" do
637 690
        assert_difference 'Issue.count' do
638
          post :create, :project_id => 1, 
691
          post :create, :project_id => 1,
639 692
                     :issue => {:tracker_id => 1,
640 693
                                :subject => 'This is an issue',
641 694
                                :status_id => 3}
......
644 697
        assert_equal IssueStatus.default, issue.status
645 698
      end
646 699
    end
647
    
700

  
648 701
    context "#update" do
649 702
      should "ignore status change" do
650 703
        assert_difference 'Journal.count' do
......
652 705
        end
653 706
        assert_equal 1, Issue.find(1).status_id
654 707
      end
655
      
708

  
656 709
      should "ignore attributes changes" do
657 710
        assert_difference 'Journal.count' do
658 711
          put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
......
663 716
      end
664 717
    end
665 718
  end
666
  
719

  
667 720
  context "with workflow privilege" do
668 721
    setup do
669 722
      Workflow.delete_all(["role_id = ?", Role.anonymous.id])
......
671 724
      Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
672 725
      Role.anonymous.add_permission! :add_issues, :add_issue_notes
673 726
    end
674
    
727

  
675 728
    context "#update" do
676 729
      should "accept authorized status" do
677 730
        assert_difference 'Journal.count' do
......
679 732
        end
680 733
        assert_equal 3, Issue.find(1).status_id
681 734
      end
682
      
735

  
683 736
      should "ignore unauthorized status" do
684 737
        assert_difference 'Journal.count' do
685 738
          put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
686 739
        end
687 740
        assert_equal 1, Issue.find(1).status_id
688 741
      end
689
      
742

  
690 743
      should "accept authorized attributes changes" do
691 744
        assert_difference 'Journal.count' do
692 745
          put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
......
694 747
        issue = Issue.find(1)
695 748
        assert_equal 2, issue.assigned_to_id
696 749
      end
697
      
750

  
698 751
      should "ignore unauthorized attributes changes" do
699 752
        assert_difference 'Journal.count' do
700 753
          put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
......
703 756
        assert_equal "Can't print recipes", issue.subject
704 757
      end
705 758
    end
706
    
759

  
707 760
    context "and :edit_issues permission" do
708 761
      setup do
709 762
        Role.anonymous.add_permission! :add_issues, :edit_issues
......
715 768
        end
716 769
        assert_equal 3, Issue.find(1).status_id
717 770
      end
718
      
771

  
719 772
      should "ignore unauthorized status" do
720 773
        assert_difference 'Journal.count' do
721 774
          put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
722 775
        end
723 776
        assert_equal 1, Issue.find(1).status_id
724 777
      end
725
      
778

  
726 779
      should "accept authorized attributes changes" do
727 780
        assert_difference 'Journal.count' do
728 781
          put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
......
733 786
      end
734 787
    end
735 788
  end
736
  
789

  
737 790
  def test_copy_issue
738 791
    @request.session[:user_id] = 2
739 792
    get :new, :project_id => 1, :copy_from => 1
......
742 795
    orig = Issue.find(1)
743 796
    assert_equal orig.subject, assigns(:issue).subject
744 797
  end
745
  
798

  
746 799
  def test_get_edit
747 800
    @request.session[:user_id] = 2
748 801
    get :edit, :id => 1
......
751 804
    assert_not_nil assigns(:issue)
752 805
    assert_equal Issue.find(1), assigns(:issue)
753 806
  end
754
  
807

  
755 808
  def test_get_edit_with_params
756 809
    @request.session[:user_id] = 2
757 810
    get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
758 811
        :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
759 812
    assert_response :success
760 813
    assert_template 'edit'
761
    
814

  
762 815
    issue = assigns(:issue)
763 816
    assert_not_nil issue
764
    
817

  
765 818
    assert_equal 5, issue.status_id
766 819
    assert_tag :select, :attributes => { :name => 'issue[status_id]' },
767
                        :child => { :tag => 'option', 
820
                        :child => { :tag => 'option',
768 821
                                    :content => 'Closed',
769 822
                                    :attributes => { :selected => 'selected' } }
770
                                    
823

  
771 824
    assert_equal 7, issue.priority_id
772 825
    assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
773
                        :child => { :tag => 'option', 
826
                        :child => { :tag => 'option',
774 827
                                    :content => 'Urgent',
775 828
                                    :attributes => { :selected => 'selected' } }
776 829

  
......
785 838
    @request.session[:user_id] = 2
786 839
    xhr :post, :new, :project_id => 1,
787 840
                             :id => 1,
788
                             :issue => {:tracker_id => 2, 
841
                             :issue => {:tracker_id => 2,
789 842
                                        :subject => 'This is the test_new issue',
790 843
                                        :description => 'This is the description',
791 844
                                        :priority_id => 5}
792 845
    assert_response :success
793 846
    assert_template 'attributes'
794
    
847

  
795 848
    issue = assigns(:issue)
796 849
    assert_kind_of Issue, issue
797 850
    assert_equal 1, issue.id
......
799 852
    assert_equal 2, issue.tracker_id
800 853
    assert_equal 'This is the test_new issue', issue.subject
801 854
  end
802
  
855

  
803 856
  def test_update_using_invalid_http_verbs
804 857
    @request.session[:user_id] = 2
805 858
    subject = 'Updated by an invalid http verb'
......
817 870
  def test_put_update_without_custom_fields_param
818 871
    @request.session[:user_id] = 2
819 872
    ActionMailer::Base.deliveries.clear
820
    
873

  
821 874
    issue = Issue.find(1)
822 875
    assert_equal '125', issue.custom_value_for(2).value
823 876
    old_subject = issue.subject
824 877
    new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
825
    
878

  
826 879
    assert_difference('Journal.count') do
827 880
      assert_difference('JournalDetail.count', 2) do
828 881
        put :update, :id => 1, :issue => {:subject => new_subject,
......
836 889
    assert_equal new_subject, issue.subject
837 890
    # Make sure custom fields were not cleared
838 891
    assert_equal '125', issue.custom_value_for(2).value
839
    
892

  
840 893
    mail = ActionMailer::Base.deliveries.last
841 894
    assert_kind_of TMail::Mail, mail
842 895
    assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
843 896
    assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
844 897
  end
845
  
898

  
846 899
  def test_put_update_with_custom_field_change
847 900
    @request.session[:user_id] = 2
848 901
    issue = Issue.find(1)
849 902
    assert_equal '125', issue.custom_value_for(2).value
850
    
903

  
851 904
    assert_difference('Journal.count') do
852 905
      assert_difference('JournalDetail.count', 3) do
853 906
        put :update, :id => 1, :issue => {:subject => 'Custom field change',
......
860 913
    assert_redirected_to :action => 'show', :id => '1'
861 914
    issue.reload
862 915
    assert_equal 'New custom value', issue.custom_value_for(2).value
863
    
916

  
864 917
    mail = ActionMailer::Base.deliveries.last
865 918
    assert_kind_of TMail::Mail, mail
866 919
    assert mail.body.include?("Searchable field changed from 125 to New custom value")
867 920
  end
868
  
921

  
869 922
  def test_put_update_with_status_and_assignee_change
870 923
    issue = Issue.find(1)
871 924
    assert_equal 1, issue.status_id
......
883 936
    j = Journal.find(:first, :order => 'id DESC')
884 937
    assert_equal 'Assigned to dlopper', j.notes
885 938
    assert_equal 2, j.details.size
886
    
939

  
887 940
    mail = ActionMailer::Base.deliveries.last
888 941
    assert mail.body.include?("Status changed from New to Assigned")
889 942
    # subject should contain the new status
890 943
    assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
891 944
  end
892
  
945

  
893 946
  def test_put_update_with_note_only
894 947
    notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
895 948
    # anonymous user
......
901 954
    assert_equal notes, j.notes
902 955
    assert_equal 0, j.details.size
903 956
    assert_equal User.anonymous, j.user
904
    
957

  
905 958
    mail = ActionMailer::Base.deliveries.last
906 959
    assert mail.body.include?(notes)
907 960
  end
908
  
961

  
909 962
  def test_put_update_with_note_and_spent_time
910 963
    @request.session[:user_id] = 2
911 964
    spent_hours_before = Issue.find(1).spent_hours
......
916 969
           :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
917 970
    end
918 971
    assert_redirected_to :action => 'show', :id => '1'
919
    
972

  
920 973
    issue = Issue.find(1)
921
    
974

  
922 975
    j = Journal.find(:first, :order => 'id DESC')
923 976
    assert_equal '2.5 hours added', j.notes
924 977
    assert_equal 0, j.details.size
925
    
978

  
926 979
    t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
927 980
    assert_not_nil t
928 981
    assert_equal 2.5, t.hours
929 982
    assert_equal spent_hours_before + 2.5, issue.spent_hours
930 983
  end
931
  
984

  
932 985
  def test_put_update_with_attachment_only
933 986
    set_tmp_attachments_directory
934
    
987

  
935 988
    # Delete all fixtured journals, a race condition can occur causing the wrong
936 989
    # journal to get fetched in the next find.
937 990
    Journal.delete_all
......
947 1000
    assert_equal 1, j.details.size
948 1001
    assert_equal 'testfile.txt', j.details.first.value
949 1002
    assert_equal User.anonymous, j.user
950
    
1003

  
951 1004
    mail = ActionMailer::Base.deliveries.last
952 1005
    assert mail.body.include?('testfile.txt')
953 1006
  end
954 1007

  
955 1008
  def test_put_update_with_attachment_that_fails_to_save
956 1009
    set_tmp_attachments_directory
957
    
1010

  
958 1011
    # Delete all fixtured journals, a race condition can occur causing the wrong
959 1012
    # journal to get fetched in the next find.
960 1013
    Journal.delete_all
961 1014

  
962 1015
    # Mock out the unsaved attachment
963 1016
    Attachment.any_instance.stubs(:create).returns(Attachment.new)
964
    
1017

  
965 1018
    # anonymous user
966 1019
    put :update,
967 1020
         :id => 1,
......
976 1029
    issue = Issue.find(1)
977 1030
    issue.journals.clear
978 1031
    ActionMailer::Base.deliveries.clear
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff