Chris@441: # Redmine - project management software Chris@441: # Copyright (C) 2006-2011 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@0: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@0: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@119: require File.expand_path('../../test_helper', __FILE__) Chris@0: Chris@0: class IssuesTest < ActionController::IntegrationTest Chris@0: fixtures :projects, Chris@0: :users, Chris@0: :roles, Chris@0: :members, Chris@0: :trackers, Chris@0: :projects_trackers, Chris@0: :enabled_modules, Chris@0: :issue_statuses, Chris@0: :issues, Chris@0: :enumerations, Chris@0: :custom_fields, Chris@0: :custom_values, Chris@0: :custom_fields_trackers Chris@0: Chris@0: # create an issue Chris@0: def test_add_issue Chris@0: log_user('jsmith', 'jsmith') Chris@0: get 'projects/1/issues/new', :tracker_id => '1' Chris@0: assert_response :success Chris@0: assert_template 'issues/new' Chris@0: Chris@0: post 'projects/1/issues', :tracker_id => "1", Chris@0: :issue => { :start_date => "2006-12-26", Chris@0: :priority_id => "4", Chris@0: :subject => "new test issue", Chris@0: :category_id => "", Chris@0: :description => "new issue", Chris@0: :done_ratio => "0", Chris@0: :due_date => "", Chris@0: :assigned_to_id => "" }, Chris@0: :custom_fields => {'2' => 'Value for field 2'} Chris@0: # find created issue Chris@0: issue = Issue.find_by_subject("new test issue") Chris@0: assert_kind_of Issue, issue Chris@0: Chris@0: # check redirection Chris@0: assert_redirected_to :controller => 'issues', :action => 'show', :id => issue Chris@0: follow_redirect! Chris@0: assert_equal issue, assigns(:issue) Chris@0: Chris@0: # check issue attributes Chris@0: assert_equal 'jsmith', issue.author.login Chris@0: assert_equal 1, issue.project.id Chris@0: assert_equal 1, issue.status.id Chris@0: end Chris@0: Chris@0: # add then remove 2 attachments to an issue Chris@441: def test_issue_attachments Chris@0: log_user('jsmith', 'jsmith') Chris@0: set_tmp_attachments_directory Chris@0: chris@22: put 'issues/1', Chris@0: :notes => 'Some notes', Chris@0: :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}} chris@37: assert_redirected_to "/issues/1" Chris@0: Chris@0: # make sure attachment was saved Chris@0: attachment = Issue.find(1).attachments.find_by_filename("testfile.txt") Chris@0: assert_kind_of Attachment, attachment Chris@0: assert_equal Issue.find(1), attachment.container Chris@0: assert_equal 'This is an attachment', attachment.description Chris@0: # verify the size of the attachment stored in db Chris@0: #assert_equal file_data_1.length, attachment.filesize Chris@0: # verify that the attachment was written to disk Chris@0: assert File.exist?(attachment.diskfile) Chris@0: Chris@0: # remove the attachments Chris@0: Issue.find(1).attachments.each(&:destroy) Chris@0: assert_equal 0, Issue.find(1).attachments.length Chris@0: end Chris@0: Chris@0: def test_other_formats_links_on_get_index Chris@0: get '/projects/ecookbook/issues' Chris@0: Chris@0: %w(Atom PDF CSV).each do |format| Chris@0: assert_tag :a, :content => format, Chris@0: :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}", Chris@0: :rel => 'nofollow' } Chris@0: end Chris@0: end Chris@0: Chris@0: def test_other_formats_links_on_post_index_without_project_id_in_url Chris@0: post '/issues', :project_id => 'ecookbook' Chris@0: Chris@0: %w(Atom PDF CSV).each do |format| Chris@0: assert_tag :a, :content => format, Chris@0: :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}", Chris@0: :rel => 'nofollow' } Chris@0: end Chris@0: end Chris@0: Chris@0: def test_pagination_links_on_get_index Chris@0: Setting.per_page_options = '2' Chris@0: get '/projects/ecookbook/issues' Chris@0: Chris@0: assert_tag :a, :content => '2', Chris@0: :attributes => { :href => '/projects/ecookbook/issues?page=2' } Chris@0: Chris@0: end Chris@0: Chris@0: def test_pagination_links_on_post_index_without_project_id_in_url Chris@0: Setting.per_page_options = '2' Chris@0: post '/issues', :project_id => 'ecookbook' Chris@0: Chris@0: assert_tag :a, :content => '2', Chris@0: :attributes => { :href => '/projects/ecookbook/issues?page=2' } Chris@0: Chris@0: end Chris@441: Chris@441: def test_issue_with_user_custom_field Chris@441: @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all) Chris@441: Role.anonymous.add_permission! :add_issues, :edit_issues Chris@441: users = Project.find(1).users Chris@441: tester = users.first Chris@441: Chris@441: # Issue form Chris@441: get '/projects/ecookbook/issues/new' Chris@441: assert_response :success Chris@441: assert_tag :select, Chris@441: :attributes => {:name => "issue[custom_field_values][#{@field.id}]"}, Chris@441: :children => {:count => (users.size + 1)}, # +1 for blank value Chris@441: :child => { Chris@441: :tag => 'option', Chris@441: :attributes => {:value => tester.id.to_s}, Chris@441: :content => tester.name Chris@441: } Chris@441: Chris@441: # Create issue Chris@441: assert_difference 'Issue.count' do Chris@441: post '/projects/ecookbook/issues', Chris@441: :issue => { Chris@441: :tracker_id => '1', Chris@441: :priority_id => '4', Chris@441: :subject => 'Issue with user custom field', Chris@441: :custom_field_values => {@field.id.to_s => users.first.id.to_s} Chris@441: } Chris@441: end Chris@441: issue = Issue.first(:order => 'id DESC') Chris@441: assert_response 302 Chris@441: Chris@441: # Issue view Chris@441: follow_redirect! Chris@441: assert_tag :th, Chris@441: :content => /Tester/, Chris@441: :sibling => { Chris@441: :tag => 'td', Chris@441: :content => tester.name Chris@441: } Chris@441: assert_tag :select, Chris@441: :attributes => {:name => "issue[custom_field_values][#{@field.id}]"}, Chris@441: :children => {:count => (users.size + 1)}, # +1 for blank value Chris@441: :child => { Chris@441: :tag => 'option', Chris@441: :attributes => {:value => tester.id.to_s, :selected => 'selected'}, Chris@441: :content => tester.name Chris@441: } Chris@441: Chris@441: # Update issue Chris@441: new_tester = users[1] Chris@441: assert_difference 'Journal.count' do Chris@441: put "/issues/#{issue.id}", Chris@441: :notes => 'Updating custom field', Chris@441: :issue => { Chris@441: :custom_field_values => {@field.id.to_s => new_tester.id.to_s} Chris@441: } Chris@441: end Chris@441: assert_response 302 Chris@441: Chris@441: # Issue view Chris@441: follow_redirect! Chris@441: assert_tag :content => 'Tester', Chris@441: :ancestor => {:tag => 'ul', :attributes => {:class => /details/}}, Chris@441: :sibling => { Chris@441: :content => tester.name, Chris@441: :sibling => { Chris@441: :content => new_tester.name Chris@441: } Chris@441: } Chris@441: end Chris@0: end