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