diff options
-rw-r--r-- | app/models/issue.rb | 9 | ||||
-rw-r--r-- | test/integration/api_test/issues_test.rb | 10 |
2 files changed, 17 insertions, 2 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index d550616a9..e2699394b 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -502,8 +502,13 @@ class Issue < ActiveRecord::Base # Project and Tracker must be set before since new_statuses_allowed_to depends on it. if (p = attrs.delete('project_id')) && safe_attribute?('project_id') - if allowed_target_projects(user).where(:id => p.to_i).exists? - self.project_id = p + if p.is_a?(String) && !p.match(/^\d*$/) + p_id = Project.find_by_identifier(p).try(:id) + else + p_id = p.to_i + end + if allowed_target_projects(user).where(:id => p_id).exists? + self.project_id = p_id end if project_id_changed? && attrs['category_id'].to_s == category_id_was.to_s diff --git a/test/integration/api_test/issues_test.rb b/test/integration/api_test/issues_test.rb index 50119f4d1..077ae9601 100644 --- a/test/integration/api_test/issues_test.rb +++ b/test/integration/api_test/issues_test.rb @@ -488,6 +488,16 @@ JSON assert_equal 'API test', issue.subject end + test "POST /issues.json should accept project identifier as project_id" do + assert_difference('Issue.count') do + post '/issues.json', + {:issue => {:project_id => 'subproject1', :tracker_id => 2, :subject => 'Foo'}}, + credentials('jsmith') + + assert_response :created + end + end + test "POST /issues.json without tracker_id should accept custom fields" do field = IssueCustomField.generate!( :field_format => 'list', |