To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / .svn / pristine / 2d / 2d79f51bb3aabe1350946a7c8d7303968d415bb8.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (7.69 KB)

1 1296:038ba2d95de8 Chris
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18
require File.expand_path('../../test_helper', __FILE__)
19
20
class IssuesTest < ActionController::IntegrationTest
21
  fixtures :projects,
22
           :users,
23
           :roles,
24
           :members,
25
           :member_roles,
26
           :trackers,
27
           :projects_trackers,
28
           :enabled_modules,
29
           :issue_statuses,
30
           :issues,
31
           :enumerations,
32
           :custom_fields,
33
           :custom_values,
34
           :custom_fields_trackers
35
36
  # create an issue
37
  def test_add_issue
38
    log_user('jsmith', 'jsmith')
39
    get 'projects/1/issues/new', :tracker_id => '1'
40
    assert_response :success
41
    assert_template 'issues/new'
42
43
    post 'projects/1/issues', :tracker_id => "1",
44
                                 :issue => { :start_date => "2006-12-26",
45
                                             :priority_id => "4",
46
                                             :subject => "new test issue",
47
                                             :category_id => "",
48
                                             :description => "new issue",
49
                                             :done_ratio => "0",
50
                                             :due_date => "",
51
                                             :assigned_to_id => "" },
52
                                 :custom_fields => {'2' => 'Value for field 2'}
53
    # find created issue
54
    issue = Issue.find_by_subject("new test issue")
55
    assert_kind_of Issue, issue
56
57
    # check redirection
58
    assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
59
    follow_redirect!
60
    assert_equal issue, assigns(:issue)
61
62
    # check issue attributes
63
    assert_equal 'jsmith', issue.author.login
64
    assert_equal 1, issue.project.id
65
    assert_equal 1, issue.status.id
66
  end
67
68
  def test_update_issue_form
69
    log_user('jsmith', 'jsmith')
70
    post 'projects/ecookbook/issues/new', :issue => { :tracker_id => "2"}
71
    assert_response :success
72
    assert_tag 'select',
73
      :attributes => {:name => 'issue[tracker_id]'},
74
      :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}}
75
  end
76
77
  # add then remove 2 attachments to an issue
78
  def test_issue_attachments
79
    log_user('jsmith', 'jsmith')
80
    set_tmp_attachments_directory
81
82
    put 'issues/1',
83
         :notes => 'Some notes',
84
         :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
85
    assert_redirected_to "/issues/1"
86
87
    # make sure attachment was saved
88
    attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
89
    assert_kind_of Attachment, attachment
90
    assert_equal Issue.find(1), attachment.container
91
    assert_equal 'This is an attachment', attachment.description
92
    # verify the size of the attachment stored in db
93
    #assert_equal file_data_1.length, attachment.filesize
94
    # verify that the attachment was written to disk
95
    assert File.exist?(attachment.diskfile)
96
97
    # remove the attachments
98
    Issue.find(1).attachments.each(&:destroy)
99
    assert_equal 0, Issue.find(1).attachments.length
100
  end
101
102
  def test_other_formats_links_on_index
103
    get '/projects/ecookbook/issues'
104
105
    %w(Atom PDF CSV).each do |format|
106
      assert_tag :a, :content => format,
107
                     :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
108
                                      :rel => 'nofollow' }
109
    end
110
  end
111
112
  def test_other_formats_links_on_index_without_project_id_in_url
113
    get '/issues', :project_id => 'ecookbook'
114
115
    %w(Atom PDF CSV).each do |format|
116
      assert_tag :a, :content => format,
117
                     :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
118
                                      :rel => 'nofollow' }
119
    end
120
  end
121
122
  def test_pagination_links_on_index
123
    Setting.per_page_options = '2'
124
    get '/projects/ecookbook/issues'
125
126
    assert_tag :a, :content => '2',
127
                   :attributes => { :href => '/projects/ecookbook/issues?page=2' }
128
129
  end
130
131
  def test_pagination_links_on_index_without_project_id_in_url
132
    Setting.per_page_options = '2'
133
    get '/issues', :project_id => 'ecookbook'
134
135
    assert_tag :a, :content => '2',
136
                   :attributes => { :href => '/projects/ecookbook/issues?page=2' }
137
138
  end
139
140
  def test_issue_with_user_custom_field
141
    @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
142
    Role.anonymous.add_permission! :add_issues, :edit_issues
143
    users = Project.find(1).users
144
    tester = users.first
145
146
    # Issue form
147
    get '/projects/ecookbook/issues/new'
148
    assert_response :success
149
    assert_tag :select,
150
      :attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
151
      :children => {:count => (users.size + 1)}, # +1 for blank value
152
      :child => {
153
        :tag => 'option',
154
        :attributes => {:value => tester.id.to_s},
155
        :content => tester.name
156
      }
157
158
    # Create issue
159
    assert_difference 'Issue.count' do
160
      post '/projects/ecookbook/issues',
161
        :issue => {
162
          :tracker_id => '1',
163
          :priority_id => '4',
164
          :subject => 'Issue with user custom field',
165
          :custom_field_values => {@field.id.to_s => users.first.id.to_s}
166
        }
167
    end
168
    issue = Issue.first(:order => 'id DESC')
169
    assert_response 302
170
171
    # Issue view
172
    follow_redirect!
173
    assert_tag :th,
174
      :content => /Tester/,
175
      :sibling => {
176
        :tag => 'td',
177
        :content => tester.name
178
      }
179
    assert_tag :select,
180
      :attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
181
      :children => {:count => (users.size + 1)}, # +1 for blank value
182
      :child => {
183
        :tag => 'option',
184
        :attributes => {:value => tester.id.to_s, :selected => 'selected'},
185
        :content => tester.name
186
      }
187
188
    # Update issue
189
    new_tester = users[1]
190
    assert_difference 'Journal.count' do
191
      put "/issues/#{issue.id}",
192
        :notes => 'Updating custom field',
193
        :issue => {
194
          :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
195
        }
196
    end
197
    assert_response 302
198
199
    # Issue view
200
    follow_redirect!
201
    assert_tag :content => 'Tester',
202
      :ancestor => {:tag => 'ul', :attributes => {:class => /details/}},
203
      :sibling => {
204
        :content => tester.name,
205
        :sibling => {
206
          :content => new_tester.name
207
        }
208
      }
209
  end
210
211
  def test_update_using_invalid_http_verbs
212
    subject = 'Updated by an invalid http verb'
213
214
    get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
215
    assert_response 404
216
    assert_not_equal subject, Issue.find(1).subject
217
218
    post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
219
    assert_response 404
220
    assert_not_equal subject, Issue.find(1).subject
221
  end
222
223
  def test_get_watch_should_be_invalid
224
    assert_no_difference 'Watcher.count' do
225
      get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
226
      assert_response 404
227
    end
228
  end
229
end