Mercurial > hg > soundsoftware-site
diff test/integration/api_test/issues_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | dffacf8a6908 |
children |
line wrap: on
line diff
--- a/test/integration/api_test/issues_test.rb Mon Mar 17 08:57:04 2014 +0000 +++ b/test/integration/api_test/issues_test.rb Thu Sep 11 12:46:20 2014 +0100 @@ -1,5 +1,5 @@ # Redmine - project management software -# Copyright (C) 2006-2012 Jean-Philippe Lang +# Copyright (C) 2006-2014 Jean-Philippe Lang # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -17,7 +17,7 @@ require File.expand_path('../../../test_helper', __FILE__) -class ApiTest::IssuesTest < ActionController::IntegrationTest +class Redmine::ApiTest::IssuesTest < Redmine::ApiTest::Base fixtures :projects, :users, :roles, @@ -138,9 +138,9 @@ get '/issues.xml', {:set_filter => 1, :f => ['cf_1'], :op => {:cf_1 => '='}, :v => {:cf_1 => ['MySQL']}} - expected_ids = Issue.visible.all( - :include => :custom_values, - :conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id) + expected_ids = Issue.visible. + joins(:custom_values). + where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) assert_select 'issues > issue > id', :count => expected_ids.count do |ids| ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } end @@ -151,9 +151,9 @@ should "show only issues with the custom field value" do get '/issues.xml', { :cf_1 => 'MySQL' } - expected_ids = Issue.visible.all( - :include => :custom_values, - :conditions => {:custom_values => {:custom_field_id => 1, :value => 'MySQL'}}).map(&:id) + expected_ids = Issue.visible. + joins(:custom_values). + where(:custom_values => {:custom_field_id => 1, :value => 'MySQL'}).map(&:id) assert_select 'issues > issue > id', :count => expected_ids.count do |ids| ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } @@ -162,6 +162,29 @@ end end + def test_index_should_allow_timestamp_filtering + Issue.delete_all + Issue.generate!(:subject => '1').update_column(:updated_on, Time.parse("2014-01-02T10:25:00Z")) + Issue.generate!(:subject => '2').update_column(:updated_on, Time.parse("2014-01-02T12:13:00Z")) + + get '/issues.xml', + {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '<='}, + :v => {:updated_on => ['2014-01-02T12:00:00Z']}} + assert_select 'issues>issue', :count => 1 + assert_select 'issues>issue>subject', :text => '1' + + get '/issues.xml', + {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, + :v => {:updated_on => ['2014-01-02T12:00:00Z']}} + assert_select 'issues>issue', :count => 1 + assert_select 'issues>issue>subject', :text => '2' + + get '/issues.xml', + {:set_filter => 1, :f => ['updated_on'], :op => {:updated_on => '>='}, + :v => {:updated_on => ['2014-01-02T08:00:00Z']}} + assert_select 'issues>issue', :count => 2 + end + context "/index.json" do should_allow_api_authentication(:get, "/projects/private-child/issues.json") end @@ -170,7 +193,7 @@ should "show only issues with the status_id" do get '/issues.xml?status_id=5' - expected_ids = Issue.visible.all(:conditions => {:status_id => 5}).map(&:id) + expected_ids = Issue.visible.where(:status_id => 5).map(&:id) assert_select 'issues > issue > id', :count => expected_ids.count do |ids| ids.each { |id| assert expected_ids.delete(id.children.first.content.to_i) } @@ -453,6 +476,21 @@ end end + test "GET /issues/:id.xml?include=watchers should include watchers" do + Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) + + get '/issues/1.xml?include=watchers', {}, credentials('jsmith') + + assert_response :ok + assert_equal 'application/xml', response.content_type + assert_select 'issue' do + assert_select 'watchers', Issue.find(1).watchers.count + assert_select 'watchers' do + assert_select 'user[id=3]' + end + end + end + context "POST /issues.xml" do should_allow_api_authentication( :post, @@ -466,7 +504,7 @@ {:issue => {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3}}, credentials('jsmith') end - issue = Issue.first(:order => 'id DESC') + issue = Issue.order('id DESC').first assert_equal 1, issue.project_id assert_equal 2, issue.tracker_id assert_equal 3, issue.status_id @@ -478,6 +516,18 @@ end end + test "POST /issues.xml with watcher_user_ids should create issue with watchers" do + assert_difference('Issue.count') do + post '/issues.xml', + {:issue => {:project_id => 1, :subject => 'Watchers', + :tracker_id => 2, :status_id => 3, :watcher_user_ids => [3, 1]}}, credentials('jsmith') + assert_response :created + end + issue = Issue.order('id desc').first + assert_equal 2, issue.watchers.size + assert_equal [1, 3], issue.watcher_user_ids.sort + end + context "POST /issues.xml with failure" do should "have an errors tag" do assert_no_difference('Issue.count') do @@ -503,7 +553,7 @@ credentials('jsmith') end - issue = Issue.first(:order => 'id DESC') + issue = Issue.order('id DESC').first assert_equal 1, issue.project_id assert_equal 2, issue.tracker_id assert_equal 3, issue.status_id @@ -720,6 +770,30 @@ end end + test "POST /issues/:id/watchers.xml should add watcher" do + assert_difference 'Watcher.count' do + post '/issues/1/watchers.xml', {:user_id => 3}, credentials('jsmith') + + assert_response :ok + assert_equal '', response.body + end + watcher = Watcher.order('id desc').first + assert_equal Issue.find(1), watcher.watchable + assert_equal User.find(3), watcher.user + end + + test "DELETE /issues/:id/watchers/:user_id.xml should remove watcher" do + Watcher.create!(:user_id => 3, :watchable => Issue.find(1)) + + assert_difference 'Watcher.count', -1 do + delete '/issues/1/watchers/3.xml', {}, credentials('jsmith') + + assert_response :ok + assert_equal '', response.body + end + assert_equal false, Issue.find(1).watched_by?(User.find(3)) + end + def test_create_issue_with_uploaded_file set_tmp_attachments_directory # upload the file @@ -730,7 +804,7 @@ end xml = Hash.from_xml(response.body) token = xml['upload']['token'] - attachment = Attachment.first(:order => 'id DESC') + attachment = Attachment.order('id DESC').first # create the issue with the upload's token assert_difference 'Issue.count' do @@ -741,7 +815,7 @@ credentials('jsmith') assert_response :created end - issue = Issue.first(:order => 'id DESC') + issue = Issue.order('id DESC').first assert_equal 1, issue.attachments.count assert_equal attachment, issue.attachments.first @@ -776,7 +850,7 @@ end xml = Hash.from_xml(response.body) token = xml['upload']['token'] - attachment = Attachment.first(:order => 'id DESC') + attachment = Attachment.order('id DESC').first # update the issue with the upload's token assert_difference 'Journal.count' do