"Fossies" - the Fresh Open Source Software Archive

Member "redmine-4.1.1/test/integration/api_test/projects_test.rb" (6 Apr 2020, 11159 Bytes) of package /linux/www/redmine-4.1.1.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "projects_test.rb": 4.1.0_vs_4.1.1.

    1 # frozen_string_literal: true
    2 
    3 # Redmine - project management software
    4 # Copyright (C) 2006-2019  Jean-Philippe Lang
    5 #
    6 # This program is free software; you can redistribute it and/or
    7 # modify it under the terms of the GNU General Public License
    8 # as published by the Free Software Foundation; either version 2
    9 # of the License, or (at your option) any later version.
   10 #
   11 # This program is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 #
   16 # You should have received a copy of the GNU General Public License
   17 # along with this program; if not, write to the Free Software
   18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   19 
   20 require File.expand_path('../../../test_helper', __FILE__)
   21 
   22 class Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
   23   fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
   24            :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
   25            :attachments, :custom_fields, :custom_values, :time_entries, :issue_categories
   26 
   27   def setup
   28     super
   29     set_tmp_attachments_directory
   30   end
   31 
   32   test "GET /projects.xml should return projects" do
   33     project = Project.find(1)
   34     project.inherit_members = '1'
   35     project.save!
   36 
   37     get '/projects.xml'
   38     assert_response :success
   39     assert_equal 'application/xml', @response.content_type
   40 
   41     assert_select 'projects>project:first-child' do
   42       assert_select '>id', :text => '1'
   43       assert_select '>status', :text => '1'
   44       assert_select '>is_public', :text => 'true'
   45       assert_select '>inherit_members', :text => 'true'
   46     end
   47   end
   48 
   49   test "GET /projects.json should return projects" do
   50     get '/projects.json'
   51     assert_response :success
   52     assert_equal 'application/json', @response.content_type
   53 
   54     json = ActiveSupport::JSON.decode(response.body)
   55     assert_kind_of Hash, json
   56     assert_kind_of Array, json['projects']
   57     assert_kind_of Hash, json['projects'].first
   58     assert json['projects'].first.has_key?('id')
   59     assert json['projects'].first.has_key?('inherit_members')
   60   end
   61 
   62   test "GET /projects.xml with include=issue_categories should return categories" do
   63     get '/projects.xml?include=issue_categories'
   64     assert_response :success
   65     assert_equal 'application/xml', @response.content_type
   66 
   67     assert_select 'issue_categories[type=array] issue_category[id="2"][name=Recipes]'
   68   end
   69 
   70   test "GET /projects.xml with include=trackers should return trackers" do
   71     get '/projects.xml?include=trackers'
   72     assert_response :success
   73     assert_equal 'application/xml', @response.content_type
   74 
   75     assert_select 'trackers[type=array] tracker[id="2"][name="Feature request"]'
   76   end
   77 
   78   test "GET /projects.xml with include=enabled_modules should return enabled modules" do
   79     get '/projects.xml?include=enabled_modules'
   80     assert_response :success
   81     assert_equal 'application/xml', @response.content_type
   82 
   83     assert_select 'enabled_modules[type=array] enabled_module[name=issue_tracking]'
   84   end
   85 
   86   test "GET /projects/:id.xml should return the project" do
   87     Project.find(1).update!(:inherit_members => '1')
   88 
   89     get '/projects/1.xml'
   90     assert_response :success
   91     assert_equal 'application/xml', @response.content_type
   92 
   93     assert_select 'project>id', :text => '1'
   94     assert_select 'project>status', :text => '1'
   95     assert_select 'project>is_public', :text => 'true'
   96     assert_select 'project>inherit_members', :text => 'true'
   97     assert_select 'custom_field[name="Development status"]', :text => 'Stable'
   98 
   99     assert_select 'trackers', 0
  100     assert_select 'issue_categories', 0
  101   end
  102 
  103   test "GET /projects/:id.json should return the project" do
  104     get '/projects/1.json'
  105 
  106     json = ActiveSupport::JSON.decode(response.body)
  107     assert_kind_of Hash, json
  108     assert_kind_of Hash, json['project']
  109     assert_equal 1, json['project']['id']
  110     assert_equal false, json['project']['inherit_members']
  111     assert_equal false, json['project'].has_key?('default_version')
  112     assert_equal false, json['project'].has_key?('default_assignee')
  113   end
  114 
  115   test "GET /projects/:id.xml with hidden custom fields should not display hidden custom fields" do
  116     ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
  117 
  118     get '/projects/1.xml'
  119     assert_response :success
  120     assert_equal 'application/xml', @response.content_type
  121 
  122     assert_select 'custom_field[name=?]', 'Development status', 0
  123   end
  124 
  125   test "GET /projects/:id.xml with include=issue_categories should return categories" do
  126     get '/projects/1.xml?include=issue_categories'
  127     assert_response :success
  128     assert_equal 'application/xml', @response.content_type
  129 
  130     assert_select 'issue_categories[type=array] issue_category[id="2"][name=Recipes]'
  131   end
  132 
  133   test "GET /projects/:id.xml with include=time_entry_activities should return activities" do
  134     get '/projects/1.xml?include=time_entry_activities'
  135     assert_response :success
  136     assert_equal 'application/xml', @response.content_type
  137 
  138     assert_select 'time_entry_activities[type=array] time_entry_activity[id="10"][name=Development]'
  139   end
  140 
  141   test "GET /projects/:id.xml with include=trackers should return trackers" do
  142     get '/projects/1.xml?include=trackers'
  143     assert_response :success
  144     assert_equal 'application/xml', @response.content_type
  145 
  146     assert_select 'trackers[type=array] tracker[id="2"][name="Feature request"]'
  147   end
  148 
  149   test "GET /projects/:id.xml with include=enabled_modules should return enabled modules" do
  150     get '/projects/1.xml?include=enabled_modules'
  151     assert_response :success
  152     assert_equal 'application/xml', @response.content_type
  153 
  154     assert_select 'enabled_modules[type=array] enabled_module[name=issue_tracking]'
  155   end
  156 
  157   def test_get_project_with_default_version_and_assignee
  158     user = User.find(3)
  159     version = Version.find(1)
  160     Project.find(1).update!(default_assigned_to_id: user.id, default_version_id: version.id)
  161 
  162     get '/projects/1.json'
  163 
  164     json = ActiveSupport::JSON.decode(response.body)
  165     assert_kind_of Hash, json
  166     assert_kind_of Hash, json['project']
  167     assert_equal 1, json['project']['id']
  168 
  169     assert json['project'].has_key?('default_assignee')
  170     assert_equal 2, json['project']['default_assignee'].length
  171     assert_equal user.id, json['project']['default_assignee']['id']
  172     assert_equal user.name, json['project']['default_assignee']['name']
  173 
  174     assert json['project'].has_key?('default_version')
  175     assert_equal 2, json['project']['default_version'].length
  176     assert_equal version.id, json['project']['default_version']['id']
  177     assert_equal version.name, json['project']['default_version']['name']
  178   end
  179 
  180   test "POST /projects.xml with valid parameters should create the project" do
  181     with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
  182       assert_difference('Project.count') do
  183         post '/projects.xml',
  184           :params => {:project => {:name => 'API test', :identifier => 'api-test'}},
  185           :headers => credentials('admin')
  186       end
  187     end
  188 
  189     project = Project.order('id DESC').first
  190     assert_equal 'API test', project.name
  191     assert_equal 'api-test', project.identifier
  192     assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
  193     assert_equal Tracker.all.size, project.trackers.size
  194 
  195     assert_response :created
  196     assert_equal 'application/xml', @response.content_type
  197     assert_select 'project id', :text => project.id.to_s
  198   end
  199 
  200   test "POST /projects.xml should accept enabled_module_names attribute" do
  201     assert_difference('Project.count') do
  202       post '/projects.xml',
  203         :params => {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
  204         :headers => credentials('admin')
  205     end
  206 
  207     project = Project.order('id DESC').first
  208     assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
  209   end
  210 
  211   test "POST /projects.xml should accept tracker_ids attribute" do
  212     assert_difference('Project.count') do
  213       post '/projects.xml',
  214         :params => {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}},
  215         :headers => credentials('admin')
  216     end
  217 
  218     project = Project.order('id DESC').first
  219     assert_equal [1, 3], project.trackers.map(&:id).sort
  220   end
  221 
  222   test "POST /projects.xml with invalid parameters should return errors" do
  223     assert_no_difference('Project.count') do
  224       post '/projects.xml',
  225         :params => {:project => {:name => 'API test'}},
  226         :headers => credentials('admin')
  227     end
  228 
  229     assert_response :unprocessable_entity
  230     assert_equal 'application/xml', @response.content_type
  231     assert_select 'errors error', :text => "Identifier cannot be blank"
  232   end
  233 
  234   test "PUT /projects/:id.xml with valid parameters should update the project" do
  235     assert_no_difference 'Project.count' do
  236       put '/projects/2.xml',
  237         :params => {:project => {:name => 'API update'}},
  238         :headers => credentials('jsmith')
  239     end
  240     assert_response :no_content
  241     assert_equal '', @response.body
  242     assert_nil @response.content_type
  243     project = Project.find(2)
  244     assert_equal 'API update', project.name
  245   end
  246 
  247   test "PUT /projects/:id.xml should accept enabled_module_names attribute" do
  248     assert_no_difference 'Project.count' do
  249       put '/projects/2.xml',
  250         :params => {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
  251         :headers => credentials('admin')
  252     end
  253     assert_response :no_content
  254     assert_equal '', @response.body
  255     project = Project.find(2)
  256     assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
  257   end
  258 
  259   test "PUT /projects/:id.xml should accept tracker_ids attribute" do
  260     assert_no_difference 'Project.count' do
  261       put '/projects/2.xml',
  262         :params => {:project => {:name => 'API update', :tracker_ids => [1, 3]}},
  263         :headers => credentials('admin')
  264     end
  265     assert_response :no_content
  266     assert_equal '', @response.body
  267     project = Project.find(2)
  268     assert_equal [1, 3], project.trackers.map(&:id).sort
  269   end
  270 
  271   test "PUT /projects/:id.xml with invalid parameters should return errors" do
  272     assert_no_difference('Project.count') do
  273       put '/projects/2.xml',
  274         :params => {:project => {:name => ''}},
  275         :headers => credentials('admin')
  276     end
  277 
  278     assert_response :unprocessable_entity
  279     assert_equal 'application/xml', @response.content_type
  280     assert_select 'errors error', :text => "Name cannot be blank"
  281   end
  282 
  283   test "DELETE /projects/:id.xml should delete the project" do
  284     assert_difference('Project.count',-1) do
  285       delete '/projects/2.xml', :headers => credentials('admin')
  286     end
  287     assert_response :no_content
  288     assert_equal '', @response.body
  289     assert_nil Project.find_by_id(2)
  290   end
  291 end